blob: af11e8b5d367622a5381a4e20d7edf148c598ba1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040058#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define NFSDBG_FACILITY NFSDBG_XDR
61
62/* Mapping from NFS error code to "errno" error code. */
63#define errno_NFSERR_IO EIO
64
David Howells0a8ea432006-08-22 20:06:08 -040065static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
68#ifdef DEBUG
69#define NFS4_MAXTAGLEN 20
70#else
71#define NFS4_MAXTAGLEN 0
72#endif
73
Andy Adamson6c0195a2008-12-23 16:06:15 -050074/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040075 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 */
Trond Myklebustd035c362010-12-21 10:45:27 -050077#define open_owner_id_maxsz (1 + 1 + 4)
78#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040079#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
81#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
82#define op_encode_hdr_maxsz (1)
83#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040084#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
85#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
86#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
87#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
89 (NFS4_FHSIZE >> 2))
90#define decode_putfh_maxsz (op_decode_hdr_maxsz)
91#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
92#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
93#define encode_getfh_maxsz (op_encode_hdr_maxsz)
94#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
95 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040096#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000097#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
99#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
101#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102/* This is based on getfattr, which uses the most attributes: */
103#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000105#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
106 nfs4_fattr_value_maxsz)
107#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400108#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 1 + 2 + 1 + \
110 nfs4_owner_maxsz + \
111 nfs4_group_maxsz + \
112 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define encode_savefh_maxsz (op_encode_hdr_maxsz)
114#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400115#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
116#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200117#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400118/* The 5 accounts for the PNFS attributes, and assumes that at most three
119 * layout types will be returned.
120 */
121#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
122 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
124#define decode_renew_maxsz (op_decode_hdr_maxsz)
125#define encode_setclientid_maxsz \
126 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500127 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
128 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
129 1 /* sc_prog */ + \
130 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
131 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
132 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define decode_setclientid_maxsz \
134 (op_decode_hdr_maxsz + \
135 2 + \
136 1024) /* large value for CLID_INUSE */
137#define encode_setclientid_confirm_maxsz \
138 (op_encode_hdr_maxsz + \
139 3 + (NFS4_VERIFIER_SIZE >> 2))
140#define decode_setclientid_confirm_maxsz \
141 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400142#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
143#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400144#define encode_share_access_maxsz \
145 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500146#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400147#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
148#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
149#define encode_open_maxsz (op_encode_hdr_maxsz + \
150 2 + encode_share_access_maxsz + 2 + \
151 open_owner_id_maxsz + \
152 encode_opentype_maxsz + \
153 encode_claim_null_maxsz)
154#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400156 decode_ace_maxsz)
157#define decode_change_info_maxsz (5)
158#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400159 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400160 decode_change_info_maxsz + 1 + \
161 nfs4_fattr_bitmap_maxsz + \
162 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400163#define encode_open_confirm_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1)
166#define decode_open_confirm_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_open_downgrade_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1 + \
172 encode_share_access_maxsz)
173#define decode_open_downgrade_maxsz \
174 (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz)
176#define encode_close_maxsz (op_encode_hdr_maxsz + \
177 1 + encode_stateid_maxsz)
178#define decode_close_maxsz (op_decode_hdr_maxsz + \
179 decode_stateid_maxsz)
180#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + \
182 encode_attrs_maxsz)
183#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
184 nfs4_fattr_bitmap_maxsz)
185#define encode_read_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 3)
187#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
188#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
189 2 + encode_verifier_maxsz + 5)
190#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
192#define encode_readlink_maxsz (op_encode_hdr_maxsz)
193#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
194#define encode_write_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 4)
196#define decode_write_maxsz (op_decode_hdr_maxsz + \
197 2 + decode_verifier_maxsz)
198#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
199#define decode_commit_maxsz (op_decode_hdr_maxsz + \
200 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#define encode_remove_maxsz (op_encode_hdr_maxsz + \
202 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400203#define decode_remove_maxsz (op_decode_hdr_maxsz + \
204 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#define encode_rename_maxsz (op_encode_hdr_maxsz + \
206 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400207#define decode_rename_maxsz (op_decode_hdr_maxsz + \
208 decode_change_info_maxsz + \
209 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define encode_link_maxsz (op_encode_hdr_maxsz + \
211 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400212#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400213#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400214#define encode_lock_maxsz (op_encode_hdr_maxsz + \
215 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216 1 + encode_stateid_maxsz + 1 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lock_denied_maxsz \
219 (8 + decode_lockowner_maxsz)
220#define decode_lock_maxsz (op_decode_hdr_maxsz + \
221 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400222#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
223 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
225 decode_lock_denied_maxsz)
226#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
227 encode_stateid_maxsz + \
228 4)
229#define decode_locku_maxsz (op_decode_hdr_maxsz + \
230 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400231#define encode_release_lockowner_maxsz \
232 (op_encode_hdr_maxsz + \
233 encode_lockowner_maxsz)
234#define decode_release_lockowner_maxsz \
235 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
237#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
239 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400240 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000241 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
243#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400244 1 + 2 + nfs4_name_maxsz + \
245 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400246#define decode_create_maxsz (op_decode_hdr_maxsz + \
247 decode_change_info_maxsz + \
248 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400249#define encode_statfs_maxsz (encode_getattr_maxsz)
250#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
252#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400253#define encode_getacl_maxsz (encode_getattr_maxsz)
254#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
255 nfs4_fattr_bitmap_maxsz + 1)
256#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
257 encode_stateid_maxsz + 3)
258#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400259#define encode_fs_locations_maxsz \
260 (encode_getattr_maxsz)
261#define decode_fs_locations_maxsz \
262 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000263#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400264#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400265
266#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400267#define NFS4_MAX_MACHINE_NAME_LEN (64)
268
Benny Halevy99fe60d2009-04-01 09:22:29 -0400269#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
270 encode_verifier_maxsz + \
271 1 /* co_ownerid.len */ + \
272 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
273 1 /* flags */ + \
274 1 /* spa_how */ + \
275 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500276 1 /* implementation id array of size 1 */ + \
277 1 /* nii_domain */ + \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
279 1 /* nii_name */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400282#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
283 2 /* eir_clientid */ + \
284 1 /* eir_sequenceid */ + \
285 1 /* eir_flags */ + \
286 1 /* spr_how */ + \
287 0 /* SP4_NONE (for now) */ + \
288 2 /* eir_server_owner.so_minor_id */ + \
289 /* eir_server_owner.so_major_id<> */ \
290 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
291 /* eir_server_scope<> */ \
292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
293 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500294 1 /* nii_domain */ + \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
296 1 /* nii_name */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400299#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
300#define decode_channel_attrs_maxsz (6 + \
301 1 /* ca_rdma_ird.len */ + \
302 1 /* ca_rdma_ird */)
303#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
304 2 /* csa_clientid */ + \
305 1 /* csa_sequence */ + \
306 1 /* csa_flags */ + \
307 encode_channel_attrs_maxsz + \
308 encode_channel_attrs_maxsz + \
309 1 /* csa_cb_program */ + \
310 1 /* csa_sec_parms.len (1) */ + \
311 1 /* cb_secflavor (AUTH_SYS) */ + \
312 1 /* stamp */ + \
313 1 /* machinename.len */ + \
314 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
315 1 /* uid */ + \
316 1 /* gid */ + \
317 1 /* gids.len (0) */)
318#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
319 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
320 1 /* csr_sequence */ + \
321 1 /* csr_flags */ + \
322 decode_channel_attrs_maxsz + \
323 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400324#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
325#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400326#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
327 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
328#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
329 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500330#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
331#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400332#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
333 encode_verifier_maxsz)
334#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
335 2 /* nfs_cookie4 gdlr_cookie */ + \
336 decode_verifier_maxsz \
337 /* verifier4 gdlr_verifier */ + \
338 1 /* gdlr_deviceid_list count */ + \
339 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
340 NFS4_DEVICEID4_SIZE) \
341 /* gdlr_deviceid_list */ + \
342 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400343#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
344 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
345#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
346 1 /* layout type */ + \
347 1 /* opaque devaddr4 length */ + \
348 /* devaddr4 payload is read into page */ \
349 1 /* notification bitmap length */ + \
350 1 /* notification bitmap */)
351#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
352 encode_stateid_maxsz)
353#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
354 decode_stateid_maxsz + \
355 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000356#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
357 2 /* offset */ + \
358 2 /* length */ + \
359 1 /* reclaim */ + \
360 encode_stateid_maxsz + \
361 1 /* new offset (true) */ + \
362 2 /* last byte written */ + \
363 1 /* nt_timechanged (false) */ + \
364 1 /* layoutupdate4 layout type */ + \
365 1 /* NULL filelayout layoutupdate4 payload */)
366#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300367#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
368 encode_stateid_maxsz + \
369 1 /* FIXME: opaque lrf_body always empty at the moment */)
370#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
371 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400372#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
373#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400374#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
375 XDR_QUADLEN(NFS4_STATEID_SIZE))
376#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400377#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
378 XDR_QUADLEN(NFS4_STATEID_SIZE))
379#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400380#else /* CONFIG_NFS_V4_1 */
381#define encode_sequence_maxsz 0
382#define decode_sequence_maxsz 0
383#endif /* CONFIG_NFS_V4_1 */
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
386#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
387#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400390 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400392 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400394 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400398 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400402 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400404 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400406 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400415 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400420 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400425 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400429 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400430 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400433 encode_putfh_maxsz + \
434 encode_savefh_maxsz + \
435 encode_open_maxsz + \
436 encode_getfh_maxsz + \
437 encode_getattr_maxsz + \
438 encode_restorefh_maxsz + \
439 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400442 decode_putfh_maxsz + \
443 decode_savefh_maxsz + \
444 decode_open_maxsz + \
445 decode_getfh_maxsz + \
446 decode_getattr_maxsz + \
447 decode_restorefh_maxsz + \
448 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400449#define NFS4_enc_open_confirm_sz \
450 (compound_encode_hdr_maxsz + \
451 encode_putfh_maxsz + \
452 encode_open_confirm_maxsz)
453#define NFS4_dec_open_confirm_sz \
454 (compound_decode_hdr_maxsz + \
455 decode_putfh_maxsz + \
456 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400460 encode_open_maxsz + \
461 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 decode_open_maxsz + \
466 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_enc_open_downgrade_sz \
468 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 encode_putfh_maxsz + \
471 encode_open_downgrade_maxsz + \
472 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_dec_open_downgrade_sz \
474 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400476 decode_putfh_maxsz + \
477 decode_open_downgrade_maxsz + \
478 decode_getattr_maxsz)
479#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400480 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400481 encode_putfh_maxsz + \
482 encode_close_maxsz + \
483 encode_getattr_maxsz)
484#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 decode_putfh_maxsz + \
487 decode_close_maxsz + \
488 decode_getattr_maxsz)
489#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400491 encode_putfh_maxsz + \
492 encode_setattr_maxsz + \
493 encode_getattr_maxsz)
494#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400495 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400496 decode_putfh_maxsz + \
497 decode_setattr_maxsz + \
498 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 encode_putfh_maxsz + \
502 encode_fsinfo_maxsz)
503#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 decode_putfh_maxsz + \
506 decode_fsinfo_maxsz)
507#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
508 encode_renew_maxsz)
509#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
510 decode_renew_maxsz)
511#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
512 encode_setclientid_maxsz)
513#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
514 decode_setclientid_maxsz)
515#define NFS4_enc_setclientid_confirm_sz \
516 (compound_encode_hdr_maxsz + \
517 encode_setclientid_confirm_maxsz + \
518 encode_putrootfh_maxsz + \
519 encode_fsinfo_maxsz)
520#define NFS4_dec_setclientid_confirm_sz \
521 (compound_decode_hdr_maxsz + \
522 decode_setclientid_confirm_maxsz + \
523 decode_putrootfh_maxsz + \
524 decode_fsinfo_maxsz)
525#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400526 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400528 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400532 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400536 encode_lockt_maxsz)
537#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400539 decode_putfh_maxsz + \
540 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400544 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400548 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400549#define NFS4_enc_release_lockowner_sz \
550 (compound_encode_hdr_maxsz + \
551 encode_lockowner_maxsz)
552#define NFS4_dec_release_lockowner_sz \
553 (compound_decode_hdr_maxsz + \
554 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400558 encode_access_maxsz + \
559 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400561 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400563 decode_access_maxsz + \
564 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 encode_putfh_maxsz + \
568 encode_getattr_maxsz)
569#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 decode_putfh_maxsz + \
572 decode_getattr_maxsz)
573#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 encode_putfh_maxsz + \
576 encode_lookup_maxsz + \
577 encode_getattr_maxsz + \
578 encode_getfh_maxsz)
579#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400582 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_getattr_maxsz + \
584 decode_getfh_maxsz)
585#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 encode_putrootfh_maxsz + \
588 encode_getattr_maxsz + \
589 encode_getfh_maxsz)
590#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 decode_putrootfh_maxsz + \
593 decode_getattr_maxsz + \
594 decode_getfh_maxsz)
595#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400598 encode_remove_maxsz + \
599 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400603 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400604 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_putfh_maxsz + \
608 encode_savefh_maxsz + \
609 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400610 encode_rename_maxsz + \
611 encode_getattr_maxsz + \
612 encode_restorefh_maxsz + \
613 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400615 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 decode_putfh_maxsz + \
617 decode_savefh_maxsz + \
618 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400619 decode_rename_maxsz + \
620 decode_getattr_maxsz + \
621 decode_restorefh_maxsz + \
622 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_putfh_maxsz + \
626 encode_savefh_maxsz + \
627 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400628 encode_link_maxsz + \
629 decode_getattr_maxsz + \
630 encode_restorefh_maxsz + \
631 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400633 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 decode_putfh_maxsz + \
635 decode_savefh_maxsz + \
636 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400637 decode_link_maxsz + \
638 decode_getattr_maxsz + \
639 decode_restorefh_maxsz + \
640 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
644 encode_symlink_maxsz + \
645 encode_getattr_maxsz + \
646 encode_getfh_maxsz)
647#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 decode_putfh_maxsz + \
650 decode_symlink_maxsz + \
651 decode_getattr_maxsz + \
652 decode_getfh_maxsz)
653#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400656 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400658 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400660 encode_restorefh_maxsz + \
661 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400665 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400667 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400669 decode_restorefh_maxsz + \
670 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
674 encode_getattr_maxsz)
675#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_getattr_maxsz)
679#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400686 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800689 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 encode_getattr_maxsz)
691#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800693 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 decode_getattr_maxsz)
695#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100698 encode_delegreturn_maxsz + \
699 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100702 decode_delegreturn_maxsz + \
703 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000706 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000708#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000710 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400711 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000714 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000716#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000718 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400720#define NFS4_enc_fs_locations_sz \
721 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400723 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400724 encode_lookup_maxsz + \
725 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400726#define NFS4_dec_fs_locations_sz \
727 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400729 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400730 decode_lookup_maxsz + \
731 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000732#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
733 encode_sequence_maxsz + \
734 encode_putfh_maxsz + \
735 encode_secinfo_maxsz)
736#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
737 decode_sequence_maxsz + \
738 decode_putfh_maxsz + \
739 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400740#if defined(CONFIG_NFS_V4_1)
741#define NFS4_enc_exchange_id_sz \
742 (compound_encode_hdr_maxsz + \
743 encode_exchange_id_maxsz)
744#define NFS4_dec_exchange_id_sz \
745 (compound_decode_hdr_maxsz + \
746 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400747#define NFS4_enc_create_session_sz \
748 (compound_encode_hdr_maxsz + \
749 encode_create_session_maxsz)
750#define NFS4_dec_create_session_sz \
751 (compound_decode_hdr_maxsz + \
752 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400753#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
754 encode_destroy_session_maxsz)
755#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
756 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400757#define NFS4_enc_sequence_sz \
758 (compound_decode_hdr_maxsz + \
759 encode_sequence_maxsz)
760#define NFS4_dec_sequence_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400763#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
764 encode_sequence_maxsz + \
765 encode_putrootfh_maxsz + \
766 encode_fsinfo_maxsz)
767#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
768 decode_sequence_maxsz + \
769 decode_putrootfh_maxsz + \
770 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500771#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
772 encode_sequence_maxsz + \
773 encode_reclaim_complete_maxsz)
774#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
775 decode_sequence_maxsz + \
776 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400777#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz + \
779 encode_putfh_maxsz + \
780 encode_getdevicelist_maxsz)
781#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
782 decode_sequence_maxsz + \
783 decode_putfh_maxsz + \
784 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400785#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
786 encode_sequence_maxsz +\
787 encode_getdeviceinfo_maxsz)
788#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
789 decode_sequence_maxsz + \
790 decode_getdeviceinfo_maxsz)
791#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_putfh_maxsz + \
794 encode_layoutget_maxsz)
795#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz + \
797 decode_putfh_maxsz + \
798 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000799#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
800 encode_sequence_maxsz +\
801 encode_putfh_maxsz + \
802 encode_layoutcommit_maxsz + \
803 encode_getattr_maxsz)
804#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz + \
806 decode_putfh_maxsz + \
807 decode_layoutcommit_maxsz + \
808 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300809#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz + \
811 encode_putfh_maxsz + \
812 encode_layoutreturn_maxsz)
813#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
814 decode_sequence_maxsz + \
815 decode_putfh_maxsz + \
816 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400817#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz + \
819 encode_putrootfh_maxsz +\
820 encode_secinfo_no_name_maxsz)
821#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_putrootfh_maxsz + \
824 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400825#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz + \
827 encode_test_stateid_maxsz)
828#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400831#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
832 encode_sequence_maxsz + \
833 encode_free_stateid_maxsz)
834#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
835 decode_sequence_maxsz + \
836 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500837
838const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
839 compound_encode_hdr_maxsz +
840 encode_sequence_maxsz +
841 encode_putfh_maxsz +
842 encode_getattr_maxsz) *
843 XDR_UNIT);
844
845const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
846 compound_decode_hdr_maxsz +
847 decode_sequence_maxsz +
848 decode_putfh_maxsz) *
849 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400850#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500852static unsigned short send_implementation_id = 1;
853
854module_param(send_implementation_id, ushort, 0644);
855MODULE_PARM_DESC(send_implementation_id,
856 "Send implementation ID with NFSv4.1 exchange_id");
857
Trond Myklebustbca79472009-03-11 14:10:26 -0400858static const umode_t nfs_type2fmt[] = {
859 [NF4BAD] = 0,
860 [NF4REG] = S_IFREG,
861 [NF4DIR] = S_IFDIR,
862 [NF4BLK] = S_IFBLK,
863 [NF4CHR] = S_IFCHR,
864 [NF4LNK] = S_IFLNK,
865 [NF4SOCK] = S_IFSOCK,
866 [NF4FIFO] = S_IFIFO,
867 [NF4ATTRDIR] = 0,
868 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869};
870
871struct compound_hdr {
872 int32_t status;
873 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500874 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 uint32_t taglen;
876 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400877 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400878 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879};
880
Benny Halevy13c65ce2009-08-14 17:19:25 +0300881static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
882{
883 __be32 *p = xdr_reserve_space(xdr, nbytes);
884 BUG_ON(!p);
885 return p;
886}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
889{
Al Viro8687b632006-10-19 23:28:48 -0700890 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
892 p = xdr_reserve_space(xdr, 4 + len);
893 BUG_ON(p == NULL);
894 xdr_encode_opaque(p, str, len);
895}
896
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400897static void encode_compound_hdr(struct xdr_stream *xdr,
898 struct rpc_rqst *req,
899 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
Al Viro8687b632006-10-19 23:28:48 -0700901 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400902 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400903
904 /* initialize running count of expected bytes in reply.
905 * NOTE: the replied tag SHOULD be the same is the one sent,
906 * but this is not required as a MUST for the server to do so. */
907 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300910 p = reserve_space(xdr, 4 + hdr->taglen + 8);
911 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300912 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500913 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300914 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500915}
916
917static void encode_nops(struct compound_hdr *hdr)
918{
Andy Adamsonfc931582009-04-01 09:22:31 -0400919 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500920 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921}
922
923static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
924{
Al Viro8687b632006-10-19 23:28:48 -0700925 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
928 BUG_ON(p == NULL);
929 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
930}
931
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500932static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
934 char owner_name[IDMAP_NAMESZ];
935 char owner_group[IDMAP_NAMESZ];
936 int owner_namelen = 0;
937 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700938 __be32 *p;
939 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 int len;
941 uint32_t bmval0 = 0;
942 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
944 /*
945 * We reserve enough space to write the entire attribute buffer at once.
946 * In the worst-case, this would be
947 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
948 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000949 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 */
951 len = 16;
952
953 /* Sigh */
954 if (iap->ia_valid & ATTR_SIZE)
955 len += 8;
956 if (iap->ia_valid & ATTR_MODE)
957 len += 4;
958 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800959 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400961 dprintk("nfs: couldn't resolve uid %d to string\n",
962 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 /* XXX */
964 strcpy(owner_name, "nobody");
965 owner_namelen = sizeof("nobody") - 1;
966 /* goto out; */
967 }
968 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
969 }
970 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800971 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400973 dprintk("nfs: couldn't resolve gid %d to string\n",
974 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 strcpy(owner_group, "nobody");
976 owner_grouplen = sizeof("nobody") - 1;
977 /* goto out; */
978 }
979 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
980 }
981 if (iap->ia_valid & ATTR_ATIME_SET)
982 len += 16;
983 else if (iap->ia_valid & ATTR_ATIME)
984 len += 4;
985 if (iap->ia_valid & ATTR_MTIME_SET)
986 len += 16;
987 else if (iap->ia_valid & ATTR_MTIME)
988 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300989 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
991 /*
992 * We write the bitmap length now, but leave the bitmap and the attribute
993 * buffer length to be backfilled at the end of this routine.
994 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300995 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 q = p;
997 p += 3;
998
999 if (iap->ia_valid & ATTR_SIZE) {
1000 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001001 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 }
1003 if (iap->ia_valid & ATTR_MODE) {
1004 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001005 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 }
1007 if (iap->ia_valid & ATTR_UID) {
1008 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001009 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 }
1011 if (iap->ia_valid & ATTR_GID) {
1012 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001013 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 }
1015 if (iap->ia_valid & ATTR_ATIME_SET) {
1016 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001017 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1018 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001019 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1020 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 }
1022 else if (iap->ia_valid & ATTR_ATIME) {
1023 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001024 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 }
1026 if (iap->ia_valid & ATTR_MTIME_SET) {
1027 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001028 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1029 *p++ = cpu_to_be32(0);
1030 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1031 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 }
1033 else if (iap->ia_valid & ATTR_MTIME) {
1034 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001035 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001037
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 /*
1039 * Now we backfill the bitmap and the attribute buffer length.
1040 */
1041 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001042 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 len, ((char *)p - (char *)q) + 4);
1044 BUG();
1045 }
1046 len = (char *)p - (char *)q - 12;
1047 *q++ = htonl(bmval0);
1048 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001049 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052}
1053
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001054static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055{
Al Viro8687b632006-10-19 23:28:48 -07001056 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Benny Halevy13c65ce2009-08-14 17:19:25 +03001058 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001059 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001060 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001061 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001062 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063}
1064
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001065static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
Al Viro8687b632006-10-19 23:28:48 -07001067 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
Benny Halevy13c65ce2009-08-14 17:19:25 +03001069 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001070 *p++ = cpu_to_be32(OP_CLOSE);
1071 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001072 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001073 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001074 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075}
1076
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001077static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
Al Viro8687b632006-10-19 23:28:48 -07001079 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001080
Benny Halevy13c65ce2009-08-14 17:19:25 +03001081 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001082 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001083 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001084 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001085 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001086 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087}
1088
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001089static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090{
Al Viro8687b632006-10-19 23:28:48 -07001091 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001092
Benny Halevy13c65ce2009-08-14 17:19:25 +03001093 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001094 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001095 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 switch (create->ftype) {
1098 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001099 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001100 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001101 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 break;
1103
1104 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001105 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001106 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001107 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 break;
1109
1110 default:
1111 break;
1112 }
1113
Benny Halevy811652b2009-08-14 17:19:34 +03001114 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001115 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001116 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001118 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119}
1120
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001121static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
Andy Adamson05d564f2008-12-23 16:06:15 -05001123 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Benny Halevy13c65ce2009-08-14 17:19:25 +03001125 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001126 *p++ = cpu_to_be32(OP_GETATTR);
1127 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001128 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001129 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001130 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131}
1132
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001133static 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 -07001134{
Andy Adamson05d564f2008-12-23 16:06:15 -05001135 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Benny Halevy13c65ce2009-08-14 17:19:25 +03001137 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001138 *p++ = cpu_to_be32(OP_GETATTR);
1139 *p++ = cpu_to_be32(2);
1140 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001141 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001142 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001143 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
Fred Isamandae100c2011-07-30 20:52:37 -04001146static void
1147encode_getattr_three(struct xdr_stream *xdr,
1148 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1149 struct compound_hdr *hdr)
1150{
1151 __be32 *p;
1152
1153 p = reserve_space(xdr, 4);
1154 *p = cpu_to_be32(OP_GETATTR);
1155 if (bm2) {
1156 p = reserve_space(xdr, 16);
1157 *p++ = cpu_to_be32(3);
1158 *p++ = cpu_to_be32(bm0);
1159 *p++ = cpu_to_be32(bm1);
1160 *p = cpu_to_be32(bm2);
1161 } else if (bm1) {
1162 p = reserve_space(xdr, 12);
1163 *p++ = cpu_to_be32(2);
1164 *p++ = cpu_to_be32(bm0);
1165 *p = cpu_to_be32(bm1);
1166 } else {
1167 p = reserve_space(xdr, 8);
1168 *p++ = cpu_to_be32(1);
1169 *p = cpu_to_be32(bm0);
1170 }
1171 hdr->nops++;
1172 hdr->replen += decode_getattr_maxsz;
1173}
1174
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001175static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001177 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1178 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179}
1180
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001181static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182{
Fred Isamandae100c2011-07-30 20:52:37 -04001183 encode_getattr_three(xdr,
1184 bitmask[0] & nfs4_fsinfo_bitmap[0],
1185 bitmask[1] & nfs4_fsinfo_bitmap[1],
1186 bitmask[2] & nfs4_fsinfo_bitmap[2],
1187 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188}
1189
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001190static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001191{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001192 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1193 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001194}
1195
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001196static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197{
Al Viro8687b632006-10-19 23:28:48 -07001198 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Benny Halevy13c65ce2009-08-14 17:19:25 +03001200 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001201 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001202 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001203 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204}
1205
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001206static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207{
Al Viro8687b632006-10-19 23:28:48 -07001208 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Benny Halevy13c65ce2009-08-14 17:19:25 +03001210 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001211 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001212 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001213 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001214 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001217static inline int nfs4_lock_type(struct file_lock *fl, int block)
1218{
1219 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1220 return block ? NFS4_READW_LT : NFS4_READ_LT;
1221 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1222}
1223
1224static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1225{
1226 if (fl->fl_end == OFFSET_MAX)
1227 return ~(uint64_t)0;
1228 return fl->fl_end - fl->fl_start + 1;
1229}
1230
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001231static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1232{
1233 __be32 *p;
1234
Trond Myklebustd035c362010-12-21 10:45:27 -05001235 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001236 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001237 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001238 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001239 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001240 xdr_encode_hyper(p, lowner->id);
1241}
1242
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243/*
1244 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1245 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1246 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001247static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248{
Al Viro8687b632006-10-19 23:28:48 -07001249 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Benny Halevy13c65ce2009-08-14 17:19:25 +03001251 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001252 *p++ = cpu_to_be32(OP_LOCK);
1253 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1254 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001255 p = xdr_encode_hyper(p, args->fl->fl_start);
1256 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001257 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001258 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001259 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001260 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001261 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001262 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001263 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 }
1265 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001266 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001267 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001268 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 }
Andy Adamsond0179312008-12-23 16:06:17 -05001270 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001271 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272}
1273
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001274static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275{
Al Viro8687b632006-10-19 23:28:48 -07001276 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001278 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001279 *p++ = cpu_to_be32(OP_LOCKT);
1280 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001281 p = xdr_encode_hyper(p, args->fl->fl_start);
1282 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001283 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001284 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001285 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286}
1287
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001288static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
Al Viro8687b632006-10-19 23:28:48 -07001290 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Benny Halevy13c65ce2009-08-14 17:19:25 +03001292 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001293 *p++ = cpu_to_be32(OP_LOCKU);
1294 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1295 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001296 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001297 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001298 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001299 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001300 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301}
1302
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001303static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1304{
1305 __be32 *p;
1306
1307 p = reserve_space(xdr, 4);
1308 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1309 encode_lockowner(xdr, lowner);
1310 hdr->nops++;
1311 hdr->replen += decode_release_lockowner_maxsz;
1312}
1313
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001314static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
1316 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001317 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Benny Halevy13c65ce2009-08-14 17:19:25 +03001319 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001320 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001321 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001322 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001323 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324}
1325
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001326static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
Al Viro8687b632006-10-19 23:28:48 -07001328 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Benny Halevy13c65ce2009-08-14 17:19:25 +03001330 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001331 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001332 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001333 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001334 break;
1335 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001336 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001337 break;
1338 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001339 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001340 break;
1341 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001342 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 }
Benny Halevy34558512009-08-14 17:19:30 +03001344 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345}
1346
1347static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1348{
Al Viro8687b632006-10-19 23:28:48 -07001349 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 /*
1351 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1352 * owner 4 = 32
1353 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001354 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001355 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001356 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001357 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001358 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001359 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001360 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001361 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001362 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001363 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364}
1365
1366static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1367{
Al Viro8687b632006-10-19 23:28:48 -07001368 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001369 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Benny Halevy13c65ce2009-08-14 17:19:25 +03001371 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001373 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001374 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001375 encode_attrs(xdr, arg->u.attrs, arg->server);
1376 break;
1377 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001378 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001379 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001380 if (nfs4_has_persistent_session(clp)) {
1381 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1382 encode_attrs(xdr, arg->u.attrs, arg->server);
1383 } else {
1384 struct iattr dummy;
1385
1386 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1387 encode_nfs4_verifier(xdr, &arg->u.verifier);
1388 dummy.ia_valid = 0;
1389 encode_attrs(xdr, &dummy, arg->server);
1390 }
1391 } else {
1392 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1393 encode_nfs4_verifier(xdr, &arg->u.verifier);
1394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 }
1396}
1397
1398static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1399{
Al Viro8687b632006-10-19 23:28:48 -07001400 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
Benny Halevy13c65ce2009-08-14 17:19:25 +03001402 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001404 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001405 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001406 break;
1407 default:
1408 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001409 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001410 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 }
1412}
1413
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001414static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415{
Al Viro8687b632006-10-19 23:28:48 -07001416 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Benny Halevy13c65ce2009-08-14 17:19:25 +03001418 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001420 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001421 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001422 break;
1423 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001424 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001425 break;
1426 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001427 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001428 break;
1429 default:
1430 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 }
1432}
1433
1434static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1435{
Al Viro8687b632006-10-19 23:28:48 -07001436 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Benny Halevy13c65ce2009-08-14 17:19:25 +03001438 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001439 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 encode_string(xdr, name->len, name->name);
1441}
1442
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001443static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
Al Viro8687b632006-10-19 23:28:48 -07001445 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Benny Halevy13c65ce2009-08-14 17:19:25 +03001447 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001448 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 encode_delegation_type(xdr, type);
1450}
1451
1452static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1453{
Al Viro8687b632006-10-19 23:28:48 -07001454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Benny Halevy13c65ce2009-08-14 17:19:25 +03001456 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001457 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001458 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 encode_string(xdr, name->len, name->name);
1460}
1461
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001462static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463{
1464 encode_openhdr(xdr, arg);
1465 encode_opentype(xdr, arg);
1466 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001467 case NFS4_OPEN_CLAIM_NULL:
1468 encode_claim_null(xdr, arg->name);
1469 break;
1470 case NFS4_OPEN_CLAIM_PREVIOUS:
1471 encode_claim_previous(xdr, arg->u.delegation_type);
1472 break;
1473 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1474 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1475 break;
1476 default:
1477 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 }
Andy Adamsond0179312008-12-23 16:06:17 -05001479 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001480 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481}
1482
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001483static 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 -07001484{
Al Viro8687b632006-10-19 23:28:48 -07001485 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
Benny Halevy13c65ce2009-08-14 17:19:25 +03001487 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001488 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001489 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001490 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001491 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001492 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493}
1494
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001495static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496{
Al Viro8687b632006-10-19 23:28:48 -07001497 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Benny Halevy13c65ce2009-08-14 17:19:25 +03001499 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001500 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001501 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001502 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001503 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001504 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001505 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506}
1507
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001508static void
Andy Adamsond0179312008-12-23 16:06:17 -05001509encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510{
1511 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001512 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
Benny Halevy13c65ce2009-08-14 17:19:25 +03001514 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001515 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001516 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001517 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001518 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
1520
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001521static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522{
Andy Adamson05d564f2008-12-23 16:06:15 -05001523 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001524
Benny Halevy13c65ce2009-08-14 17:19:25 +03001525 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001526 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001527 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001528 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529}
1530
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001531static 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 -07001532{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001534 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Benny Halevy13c65ce2009-08-14 17:19:25 +03001536 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001538 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001539 if (zero_seqid)
1540 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001541 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 } else
Benny Halevy34558512009-08-14 17:19:30 +03001543 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544}
1545
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001546static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547{
Al Viro8687b632006-10-19 23:28:48 -07001548 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Benny Halevy13c65ce2009-08-14 17:19:25 +03001550 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001551 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001553 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001554 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Benny Halevy13c65ce2009-08-14 17:19:25 +03001556 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001557 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001558 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001559 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001560 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
1562
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001563static 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 -07001564{
Trond Myklebust28331a42011-04-27 13:47:52 -04001565 uint32_t attrs[2] = {
1566 FATTR4_WORD0_RDATTR_ERROR,
1567 FATTR4_WORD1_MOUNTED_ON_FILEID,
1568 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001569 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001570 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001572 if (readdir->plus) {
1573 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001574 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001575 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1576 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1577 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1578 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001579 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001580 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001581 /* Use mounted_on_fileid only if the server supports it */
1582 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1583 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001584
Benny Halevy13c65ce2009-08-14 17:19:25 +03001585 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001586 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001587 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001588 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001589 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001590 *p++ = cpu_to_be32(readdir->count);
1591 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001592
Benny Halevye75bc1c2009-08-14 17:18:54 +03001593 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001594 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001595 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001596 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001597 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1598 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001599 (unsigned long long)readdir->cookie,
1600 ((u32 *)readdir->verifier.data)[0],
1601 ((u32 *)readdir->verifier.data)[1],
1602 attrs[0] & readdir->bitmask[0],
1603 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604}
1605
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001606static 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 -07001607{
Al Viro8687b632006-10-19 23:28:48 -07001608 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
Benny Halevy13c65ce2009-08-14 17:19:25 +03001610 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001611 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001612 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001613 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614}
1615
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001616static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617{
Al Viro8687b632006-10-19 23:28:48 -07001618 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
Benny Halevy13c65ce2009-08-14 17:19:25 +03001620 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001621 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001622 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001623 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001624 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625}
1626
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001627static 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 -07001628{
Al Viro8687b632006-10-19 23:28:48 -07001629 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
Benny Halevy811652b2009-08-14 17:19:34 +03001631 p = reserve_space(xdr, 4);
1632 *p = cpu_to_be32(OP_RENAME);
1633 encode_string(xdr, oldname->len, oldname->name);
1634 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001635 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001636 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637}
1638
Chuck Leverbb4dae52012-03-01 17:01:48 -05001639static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1640 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641{
Al Viro8687b632006-10-19 23:28:48 -07001642 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
Benny Halevy13c65ce2009-08-14 17:19:25 +03001644 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001645 *p++ = cpu_to_be32(OP_RENEW);
Chuck Leverbb4dae52012-03-01 17:01:48 -05001646 xdr_encode_hyper(p, clid);
Andy Adamsond0179312008-12-23 16:06:17 -05001647 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001648 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001651static void
Andy Adamsond0179312008-12-23 16:06:17 -05001652encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001653{
Al Viro8687b632006-10-19 23:28:48 -07001654 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001655
Benny Halevy13c65ce2009-08-14 17:19:25 +03001656 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001657 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001658 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001659 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001660}
1661
Chuck Lever9f06c712010-12-14 14:59:18 +00001662static void
Andy Adamsond0179312008-12-23 16:06:17 -05001663encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001664{
Al Viro8687b632006-10-19 23:28:48 -07001665 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001666
Benny Halevy13c65ce2009-08-14 17:19:25 +03001667 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001668 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001669 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001670 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001671 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001672 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001673 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001674 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001675 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001676 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001677 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001678 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001679}
1680
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001681static void
Andy Adamsond0179312008-12-23 16:06:17 -05001682encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683{
Al Viro8687b632006-10-19 23:28:48 -07001684 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Benny Halevy13c65ce2009-08-14 17:19:25 +03001686 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001687 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001688 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001689 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690}
1691
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001692static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693{
Al Viro8687b632006-10-19 23:28:48 -07001694 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001695
Benny Halevy13c65ce2009-08-14 17:19:25 +03001696 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001697 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001698 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001699 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001700 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001701 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702}
1703
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001704static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705{
Al Viro8687b632006-10-19 23:28:48 -07001706 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Benny Halevy13c65ce2009-08-14 17:19:25 +03001708 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001709 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001710 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001713 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001714 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1716 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001717 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001718 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001719 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001720 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721}
1722
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001723static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724{
Andy Adamson05d564f2008-12-23 16:06:15 -05001725 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
Benny Halevy13c65ce2009-08-14 17:19:25 +03001727 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001728 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001729 p = xdr_encode_hyper(p, arg->clientid);
1730 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001731 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001732 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733}
1734
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001735static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736{
Al Viro8687b632006-10-19 23:28:48 -07001737 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
Benny Halevy13c65ce2009-08-14 17:19:25 +03001739 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001740 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001742 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001743 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
Benny Halevy13c65ce2009-08-14 17:19:25 +03001745 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001746 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001747 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001748 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
1750 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001751 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001752 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753}
1754
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001755static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756{
Al Viro8687b632006-10-19 23:28:48 -07001757 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
Benny Halevy13c65ce2009-08-14 17:19:25 +03001759 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
Benny Halevye75bc1c2009-08-14 17:18:54 +03001761 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001762 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001763 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001764 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001766
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001767static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1768{
1769 int len = name->len;
1770 __be32 *p;
1771
1772 p = reserve_space(xdr, 8 + len);
1773 *p++ = cpu_to_be32(OP_SECINFO);
1774 xdr_encode_opaque(p, name->name, len);
1775 hdr->nops++;
1776 hdr->replen += decode_secinfo_maxsz;
1777}
1778
Benny Halevy99fe60d2009-04-01 09:22:29 -04001779#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001780/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001781static void encode_exchange_id(struct xdr_stream *xdr,
1782 struct nfs41_exchange_id_args *args,
1783 struct compound_hdr *hdr)
1784{
1785 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001786 char impl_name[NFS4_OPAQUE_LIMIT];
1787 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001788
Benny Halevy13c65ce2009-08-14 17:19:25 +03001789 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001790 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001791 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001792
1793 encode_string(xdr, args->id_len, args->id);
1794
Benny Halevy13c65ce2009-08-14 17:19:25 +03001795 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001796 *p++ = cpu_to_be32(args->flags);
1797 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001798
1799 if (send_implementation_id &&
1800 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1801 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1802 <= NFS4_OPAQUE_LIMIT + 1)
1803 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1804 utsname()->sysname, utsname()->release,
1805 utsname()->version, utsname()->machine);
1806
1807 if (len > 0) {
1808 *p = cpu_to_be32(1); /* implementation id array length=1 */
1809
1810 encode_string(xdr,
1811 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1812 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1813 encode_string(xdr, len, impl_name);
1814 /* just send zeros for nii_date - the date is in nii_name */
1815 p = reserve_space(xdr, 12);
1816 p = xdr_encode_hyper(p, 0);
1817 *p = cpu_to_be32(0);
1818 } else
1819 *p = cpu_to_be32(0); /* implementation id array length=0 */
1820
Benny Halevy99fe60d2009-04-01 09:22:29 -04001821 hdr->nops++;
1822 hdr->replen += decode_exchange_id_maxsz;
1823}
Andy Adamsonfc931582009-04-01 09:22:31 -04001824
1825static void encode_create_session(struct xdr_stream *xdr,
1826 struct nfs41_create_session_args *args,
1827 struct compound_hdr *hdr)
1828{
1829 __be32 *p;
1830 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1831 uint32_t len;
1832 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001833 u32 max_resp_sz_cached;
1834
1835 /*
1836 * Assumes OPEN is the biggest non-idempotent compound.
1837 * 2 is the verifier.
1838 */
1839 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1840 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001841
Andy Adamsonfc931582009-04-01 09:22:31 -04001842 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1843 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001844
Benny Halevy13c65ce2009-08-14 17:19:25 +03001845 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001846 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001847 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001848 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1849 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001850
Andy Adamsonfc931582009-04-01 09:22:31 -04001851 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001852 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001853 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1854 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001855 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001856 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1857 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1858 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001859
1860 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001861 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001862 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1863 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1864 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1865 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1866 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1867 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001868
Benny Halevye75bc1c2009-08-14 17:18:54 +03001869 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001870 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001871 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001872
1873 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001874 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001875 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001876 *p++ = cpu_to_be32(0); /* UID */
1877 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001878 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001879 hdr->nops++;
1880 hdr->replen += decode_create_session_maxsz;
1881}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001882
1883static void encode_destroy_session(struct xdr_stream *xdr,
1884 struct nfs4_session *session,
1885 struct compound_hdr *hdr)
1886{
1887 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001888 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001889 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001890 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001891 hdr->nops++;
1892 hdr->replen += decode_destroy_session_maxsz;
1893}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001894
1895static void encode_reclaim_complete(struct xdr_stream *xdr,
1896 struct nfs41_reclaim_complete_args *args,
1897 struct compound_hdr *hdr)
1898{
1899 __be32 *p;
1900
1901 p = reserve_space(xdr, 8);
1902 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1903 *p++ = cpu_to_be32(args->one_fs);
1904 hdr->nops++;
1905 hdr->replen += decode_reclaim_complete_maxsz;
1906}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001907#endif /* CONFIG_NFS_V4_1 */
1908
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001909static void encode_sequence(struct xdr_stream *xdr,
1910 const struct nfs4_sequence_args *args,
1911 struct compound_hdr *hdr)
1912{
1913#if defined(CONFIG_NFS_V4_1)
1914 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001915 struct nfs4_slot_table *tp;
1916 struct nfs4_slot *slot;
1917 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001918
1919 if (!session)
1920 return;
1921
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001922 tp = &session->fc_slot_table;
1923
1924 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1925 slot = tp->slots + args->sa_slotid;
1926
Benny Halevy13c65ce2009-08-14 17:19:25 +03001927 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001928 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001929
1930 /*
1931 * Sessionid + seqid + slotid + max slotid + cache_this
1932 */
1933 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1934 "max_slotid=%d cache_this=%d\n",
1935 __func__,
1936 ((u32 *)session->sess_id.data)[0],
1937 ((u32 *)session->sess_id.data)[1],
1938 ((u32 *)session->sess_id.data)[2],
1939 ((u32 *)session->sess_id.data)[3],
1940 slot->seq_nr, args->sa_slotid,
1941 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001942 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001943 *p++ = cpu_to_be32(slot->seq_nr);
1944 *p++ = cpu_to_be32(args->sa_slotid);
1945 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001946 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001947 hdr->nops++;
1948 hdr->replen += decode_sequence_maxsz;
1949#endif /* CONFIG_NFS_V4_1 */
1950}
1951
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001952#ifdef CONFIG_NFS_V4_1
1953static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001954encode_getdevicelist(struct xdr_stream *xdr,
1955 const struct nfs4_getdevicelist_args *args,
1956 struct compound_hdr *hdr)
1957{
1958 __be32 *p;
1959 nfs4_verifier dummy = {
1960 .data = "dummmmmy",
1961 };
1962
1963 p = reserve_space(xdr, 20);
1964 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1965 *p++ = cpu_to_be32(args->layoutclass);
1966 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1967 xdr_encode_hyper(p, 0ULL); /* cookie */
1968 encode_nfs4_verifier(xdr, &dummy);
1969 hdr->nops++;
1970 hdr->replen += decode_getdevicelist_maxsz;
1971}
1972
1973static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001974encode_getdeviceinfo(struct xdr_stream *xdr,
1975 const struct nfs4_getdeviceinfo_args *args,
1976 struct compound_hdr *hdr)
1977{
1978 __be32 *p;
1979
1980 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1981 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1982 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1983 NFS4_DEVICEID4_SIZE);
1984 *p++ = cpu_to_be32(args->pdev->layout_type);
1985 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1986 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1987 hdr->nops++;
1988 hdr->replen += decode_getdeviceinfo_maxsz;
1989}
1990
1991static void
1992encode_layoutget(struct xdr_stream *xdr,
1993 const struct nfs4_layoutget_args *args,
1994 struct compound_hdr *hdr)
1995{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001996 __be32 *p;
1997
1998 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1999 *p++ = cpu_to_be32(OP_LAYOUTGET);
2000 *p++ = cpu_to_be32(0); /* Signal layout available */
2001 *p++ = cpu_to_be32(args->type);
2002 *p++ = cpu_to_be32(args->range.iomode);
2003 p = xdr_encode_hyper(p, args->range.offset);
2004 p = xdr_encode_hyper(p, args->range.length);
2005 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00002006 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002007 *p = cpu_to_be32(args->maxcount);
2008
2009 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
2010 __func__,
2011 args->type,
2012 args->range.iomode,
2013 (unsigned long)args->range.offset,
2014 (unsigned long)args->range.length,
2015 args->maxcount);
2016 hdr->nops++;
2017 hdr->replen += decode_layoutget_maxsz;
2018}
Andy Adamson863a3c62011-03-23 13:27:54 +00002019
2020static int
2021encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03002022 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00002023 const struct nfs4_layoutcommit_args *args,
2024 struct compound_hdr *hdr)
2025{
2026 __be32 *p;
2027
2028 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2029 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2030
Benny Halevyac7db722011-05-22 19:53:48 +03002031 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
Andy Adamson863a3c62011-03-23 13:27:54 +00002032 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
2033 /* Only whole file layouts */
2034 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002035 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Andy Adamson863a3c62011-03-23 13:27:54 +00002036 *p++ = cpu_to_be32(0); /* reclaim */
2037 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
2038 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2039 p = xdr_encode_hyper(p, args->lastbytewritten);
2040 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2041 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002042
2043 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2044 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2045 NFS_I(inode)->layout, xdr, args);
2046 else {
2047 p = reserve_space(xdr, 4);
2048 *p = cpu_to_be32(0); /* no layout-type payload */
2049 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002050
2051 hdr->nops++;
2052 hdr->replen += decode_layoutcommit_maxsz;
2053 return 0;
2054}
Benny Halevycbe82602011-05-22 19:52:37 +03002055
2056static void
2057encode_layoutreturn(struct xdr_stream *xdr,
2058 const struct nfs4_layoutreturn_args *args,
2059 struct compound_hdr *hdr)
2060{
2061 __be32 *p;
2062
2063 p = reserve_space(xdr, 20);
2064 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
2065 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2066 *p++ = cpu_to_be32(args->layout_type);
2067 *p++ = cpu_to_be32(IOMODE_ANY);
2068 *p = cpu_to_be32(RETURN_FILE);
2069 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
2070 p = xdr_encode_hyper(p, 0);
2071 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2072 spin_lock(&args->inode->i_lock);
2073 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2074 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002075 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2076 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2077 NFS_I(args->inode)->layout, xdr, args);
2078 } else {
2079 p = reserve_space(xdr, 4);
2080 *p = cpu_to_be32(0);
2081 }
Benny Halevycbe82602011-05-22 19:52:37 +03002082 hdr->nops++;
2083 hdr->replen += decode_layoutreturn_maxsz;
2084}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002085
2086static int
2087encode_secinfo_no_name(struct xdr_stream *xdr,
2088 const struct nfs41_secinfo_no_name_args *args,
2089 struct compound_hdr *hdr)
2090{
2091 __be32 *p;
2092 p = reserve_space(xdr, 8);
2093 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2094 *p++ = cpu_to_be32(args->style);
2095 hdr->nops++;
2096 hdr->replen += decode_secinfo_no_name_maxsz;
2097 return 0;
2098}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002099
2100static void encode_test_stateid(struct xdr_stream *xdr,
2101 struct nfs41_test_stateid_args *args,
2102 struct compound_hdr *hdr)
2103{
2104 __be32 *p;
2105
2106 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
2107 *p++ = cpu_to_be32(OP_TEST_STATEID);
2108 *p++ = cpu_to_be32(1);
2109 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2110 hdr->nops++;
2111 hdr->replen += decode_test_stateid_maxsz;
2112}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002113
2114static void encode_free_stateid(struct xdr_stream *xdr,
2115 struct nfs41_free_stateid_args *args,
2116 struct compound_hdr *hdr)
2117{
2118 __be32 *p;
2119 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2120 *p++ = cpu_to_be32(OP_FREE_STATEID);
2121 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2122 hdr->nops++;
2123 hdr->replen += decode_free_stateid_maxsz;
2124}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002125#endif /* CONFIG_NFS_V4_1 */
2126
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127/*
2128 * END OF "GENERIC" ENCODE ROUTINES.
2129 */
2130
Benny Halevy66cc0422009-04-01 09:22:10 -04002131static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2132{
2133#if defined(CONFIG_NFS_V4_1)
2134 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002135 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002136#endif /* CONFIG_NFS_V4_1 */
2137 return 0;
2138}
2139
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140/*
2141 * Encode an ACCESS request
2142 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002143static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2144 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002147 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
Chuck Lever9f06c712010-12-14 14:59:18 +00002150 encode_compound_hdr(xdr, req, &hdr);
2151 encode_sequence(xdr, &args->seq_args, &hdr);
2152 encode_putfh(xdr, args->fh, &hdr);
2153 encode_access(xdr, args->access, &hdr);
2154 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002155 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156}
2157
2158/*
2159 * Encode LOOKUP request
2160 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002161static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2162 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002165 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
Chuck Lever9f06c712010-12-14 14:59:18 +00002168 encode_compound_hdr(xdr, req, &hdr);
2169 encode_sequence(xdr, &args->seq_args, &hdr);
2170 encode_putfh(xdr, args->dir_fh, &hdr);
2171 encode_lookup(xdr, args->name, &hdr);
2172 encode_getfh(xdr, &hdr);
2173 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002174 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175}
2176
2177/*
2178 * Encode LOOKUP_ROOT request
2179 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002180static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2181 struct xdr_stream *xdr,
2182 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002185 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
Chuck Lever9f06c712010-12-14 14:59:18 +00002188 encode_compound_hdr(xdr, req, &hdr);
2189 encode_sequence(xdr, &args->seq_args, &hdr);
2190 encode_putrootfh(xdr, &hdr);
2191 encode_getfh(xdr, &hdr);
2192 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002193 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194}
2195
2196/*
2197 * Encode REMOVE request
2198 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002199static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2200 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002203 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205
Chuck Lever9f06c712010-12-14 14:59:18 +00002206 encode_compound_hdr(xdr, req, &hdr);
2207 encode_sequence(xdr, &args->seq_args, &hdr);
2208 encode_putfh(xdr, args->fh, &hdr);
2209 encode_remove(xdr, &args->name, &hdr);
2210 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002211 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212}
2213
2214/*
2215 * Encode RENAME request
2216 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002217static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2218 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002221 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
Chuck Lever9f06c712010-12-14 14:59:18 +00002224 encode_compound_hdr(xdr, req, &hdr);
2225 encode_sequence(xdr, &args->seq_args, &hdr);
2226 encode_putfh(xdr, args->old_dir, &hdr);
2227 encode_savefh(xdr, &hdr);
2228 encode_putfh(xdr, args->new_dir, &hdr);
2229 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2230 encode_getfattr(xdr, args->bitmask, &hdr);
2231 encode_restorefh(xdr, &hdr);
2232 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002233 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234}
2235
2236/*
2237 * Encode LINK request
2238 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002239static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2240 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002243 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
Chuck Lever9f06c712010-12-14 14:59:18 +00002246 encode_compound_hdr(xdr, req, &hdr);
2247 encode_sequence(xdr, &args->seq_args, &hdr);
2248 encode_putfh(xdr, args->fh, &hdr);
2249 encode_savefh(xdr, &hdr);
2250 encode_putfh(xdr, args->dir_fh, &hdr);
2251 encode_link(xdr, args->name, &hdr);
2252 encode_getfattr(xdr, args->bitmask, &hdr);
2253 encode_restorefh(xdr, &hdr);
2254 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002255 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256}
2257
2258/*
2259 * Encode CREATE request
2260 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002261static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2262 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002265 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
Chuck Lever9f06c712010-12-14 14:59:18 +00002268 encode_compound_hdr(xdr, req, &hdr);
2269 encode_sequence(xdr, &args->seq_args, &hdr);
2270 encode_putfh(xdr, args->dir_fh, &hdr);
2271 encode_savefh(xdr, &hdr);
2272 encode_create(xdr, args, &hdr);
2273 encode_getfh(xdr, &hdr);
2274 encode_getfattr(xdr, args->bitmask, &hdr);
2275 encode_restorefh(xdr, &hdr);
2276 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002277 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278}
2279
2280/*
2281 * Encode SYMLINK request
2282 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002283static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2284 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285{
Chuck Lever9f06c712010-12-14 14:59:18 +00002286 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287}
2288
2289/*
2290 * Encode GETATTR request
2291 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002292static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2293 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002296 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Chuck Lever9f06c712010-12-14 14:59:18 +00002299 encode_compound_hdr(xdr, req, &hdr);
2300 encode_sequence(xdr, &args->seq_args, &hdr);
2301 encode_putfh(xdr, args->fh, &hdr);
2302 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002303 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304}
2305
2306/*
2307 * Encode a CLOSE request
2308 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002309static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2310 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311{
Andy Adamson05d564f2008-12-23 16:06:15 -05002312 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002313 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002314 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Chuck Lever9f06c712010-12-14 14:59:18 +00002316 encode_compound_hdr(xdr, req, &hdr);
2317 encode_sequence(xdr, &args->seq_args, &hdr);
2318 encode_putfh(xdr, args->fh, &hdr);
2319 encode_close(xdr, args, &hdr);
2320 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002321 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322}
2323
2324/*
2325 * Encode an OPEN request
2326 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002327static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2328 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002331 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
Chuck Lever9f06c712010-12-14 14:59:18 +00002334 encode_compound_hdr(xdr, req, &hdr);
2335 encode_sequence(xdr, &args->seq_args, &hdr);
2336 encode_putfh(xdr, args->fh, &hdr);
2337 encode_savefh(xdr, &hdr);
2338 encode_open(xdr, args, &hdr);
2339 encode_getfh(xdr, &hdr);
2340 encode_getfattr(xdr, args->bitmask, &hdr);
2341 encode_restorefh(xdr, &hdr);
Trond Myklebust6926afd2012-01-07 13:22:46 -05002342 encode_getfattr(xdr, args->dir_bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002343 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344}
2345
2346/*
2347 * Encode an OPEN_CONFIRM request
2348 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002349static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2350 struct xdr_stream *xdr,
2351 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002354 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
Chuck Lever9f06c712010-12-14 14:59:18 +00002357 encode_compound_hdr(xdr, req, &hdr);
2358 encode_putfh(xdr, args->fh, &hdr);
2359 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002360 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361}
2362
2363/*
2364 * Encode an OPEN request with no attributes.
2365 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002366static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2367 struct xdr_stream *xdr,
2368 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002371 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
Chuck Lever9f06c712010-12-14 14:59:18 +00002374 encode_compound_hdr(xdr, req, &hdr);
2375 encode_sequence(xdr, &args->seq_args, &hdr);
2376 encode_putfh(xdr, args->fh, &hdr);
2377 encode_open(xdr, args, &hdr);
2378 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002379 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380}
2381
2382/*
2383 * Encode an OPEN_DOWNGRADE request
2384 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002385static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2386 struct xdr_stream *xdr,
2387 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002390 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
Chuck Lever9f06c712010-12-14 14:59:18 +00002393 encode_compound_hdr(xdr, req, &hdr);
2394 encode_sequence(xdr, &args->seq_args, &hdr);
2395 encode_putfh(xdr, args->fh, &hdr);
2396 encode_open_downgrade(xdr, args, &hdr);
2397 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002398 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399}
2400
2401/*
2402 * Encode a LOCK request
2403 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002404static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2405 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002408 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
Chuck Lever9f06c712010-12-14 14:59:18 +00002411 encode_compound_hdr(xdr, req, &hdr);
2412 encode_sequence(xdr, &args->seq_args, &hdr);
2413 encode_putfh(xdr, args->fh, &hdr);
2414 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002415 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416}
2417
2418/*
2419 * Encode a LOCKT request
2420 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002421static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2422 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002425 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Chuck Lever9f06c712010-12-14 14:59:18 +00002428 encode_compound_hdr(xdr, req, &hdr);
2429 encode_sequence(xdr, &args->seq_args, &hdr);
2430 encode_putfh(xdr, args->fh, &hdr);
2431 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002432 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433}
2434
2435/*
2436 * Encode a LOCKU request
2437 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002438static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2439 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002442 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
Chuck Lever9f06c712010-12-14 14:59:18 +00002445 encode_compound_hdr(xdr, req, &hdr);
2446 encode_sequence(xdr, &args->seq_args, &hdr);
2447 encode_putfh(xdr, args->fh, &hdr);
2448 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002449 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450}
2451
Chuck Lever9f06c712010-12-14 14:59:18 +00002452static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2453 struct xdr_stream *xdr,
2454 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002455{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002456 struct compound_hdr hdr = {
2457 .minorversion = 0,
2458 };
2459
Chuck Lever9f06c712010-12-14 14:59:18 +00002460 encode_compound_hdr(xdr, req, &hdr);
2461 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002462 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002463}
2464
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465/*
2466 * Encode a READLINK request
2467 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002468static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2469 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002472 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
Chuck Lever9f06c712010-12-14 14:59:18 +00002475 encode_compound_hdr(xdr, req, &hdr);
2476 encode_sequence(xdr, &args->seq_args, &hdr);
2477 encode_putfh(xdr, args->fh, &hdr);
2478 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002479
Benny Halevy28f56692009-04-01 09:22:09 -04002480 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002481 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002482 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483}
2484
2485/*
2486 * Encode a READDIR request
2487 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002488static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2489 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002492 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494
Chuck Lever9f06c712010-12-14 14:59:18 +00002495 encode_compound_hdr(xdr, req, &hdr);
2496 encode_sequence(xdr, &args->seq_args, &hdr);
2497 encode_putfh(xdr, args->fh, &hdr);
2498 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002499
Benny Halevy28f56692009-04-01 09:22:09 -04002500 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002501 args->pgbase, args->count);
2502 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002503 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002504 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002505 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506}
2507
2508/*
2509 * Encode a READ request
2510 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002511static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2512 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002515 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
Chuck Lever9f06c712010-12-14 14:59:18 +00002518 encode_compound_hdr(xdr, req, &hdr);
2519 encode_sequence(xdr, &args->seq_args, &hdr);
2520 encode_putfh(xdr, args->fh, &hdr);
2521 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522
Benny Halevy28f56692009-04-01 09:22:09 -04002523 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002525 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002526 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527}
2528
2529/*
2530 * Encode an SETATTR request
2531 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002532static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2533 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534{
Andy Adamson05d564f2008-12-23 16:06:15 -05002535 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002536 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002537 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538
Chuck Lever9f06c712010-12-14 14:59:18 +00002539 encode_compound_hdr(xdr, req, &hdr);
2540 encode_sequence(xdr, &args->seq_args, &hdr);
2541 encode_putfh(xdr, args->fh, &hdr);
2542 encode_setattr(xdr, args, args->server, &hdr);
2543 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002544 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545}
2546
2547/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002548 * Encode a GETACL request
2549 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002550static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2551 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002552{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002553 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002554 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002555 };
Benny Halevy28f56692009-04-01 09:22:09 -04002556 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002557
Chuck Lever9f06c712010-12-14 14:59:18 +00002558 encode_compound_hdr(xdr, req, &hdr);
2559 encode_sequence(xdr, &args->seq_args, &hdr);
2560 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002561 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002562 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002563
Benny Halevy28f56692009-04-01 09:22:09 -04002564 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002565 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002566
Andy Adamsond0179312008-12-23 16:06:17 -05002567 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002568}
2569
2570/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 * Encode a WRITE request
2572 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002573static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2574 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002577 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579
Chuck Lever9f06c712010-12-14 14:59:18 +00002580 encode_compound_hdr(xdr, req, &hdr);
2581 encode_sequence(xdr, &args->seq_args, &hdr);
2582 encode_putfh(xdr, args->fh, &hdr);
2583 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002584 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002585 if (args->bitmask)
2586 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002587 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588}
2589
2590/*
2591 * a COMMIT request
2592 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002593static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2594 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002597 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
Chuck Lever9f06c712010-12-14 14:59:18 +00002600 encode_compound_hdr(xdr, req, &hdr);
2601 encode_sequence(xdr, &args->seq_args, &hdr);
2602 encode_putfh(xdr, args->fh, &hdr);
2603 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002604 if (args->bitmask)
2605 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002606 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607}
2608
2609/*
2610 * FSINFO request
2611 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002612static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2613 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002616 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618
Chuck Lever9f06c712010-12-14 14:59:18 +00002619 encode_compound_hdr(xdr, req, &hdr);
2620 encode_sequence(xdr, &args->seq_args, &hdr);
2621 encode_putfh(xdr, args->fh, &hdr);
2622 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002623 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624}
2625
2626/*
2627 * a PATHCONF request
2628 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002629static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2630 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002633 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
Chuck Lever9f06c712010-12-14 14:59:18 +00002636 encode_compound_hdr(xdr, req, &hdr);
2637 encode_sequence(xdr, &args->seq_args, &hdr);
2638 encode_putfh(xdr, args->fh, &hdr);
2639 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002640 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002641 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642}
2643
2644/*
2645 * a STATFS request
2646 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002647static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2648 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002651 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653
Chuck Lever9f06c712010-12-14 14:59:18 +00002654 encode_compound_hdr(xdr, req, &hdr);
2655 encode_sequence(xdr, &args->seq_args, &hdr);
2656 encode_putfh(xdr, args->fh, &hdr);
2657 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002658 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002659 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660}
2661
2662/*
2663 * GETATTR_BITMAP request
2664 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002665static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2666 struct xdr_stream *xdr,
2667 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002670 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672
Chuck Lever9f06c712010-12-14 14:59:18 +00002673 encode_compound_hdr(xdr, req, &hdr);
2674 encode_sequence(xdr, &args->seq_args, &hdr);
2675 encode_putfh(xdr, args->fhandle, &hdr);
2676 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002677 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002678 FATTR4_WORD0_LINK_SUPPORT|
2679 FATTR4_WORD0_SYMLINK_SUPPORT|
2680 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002681 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682}
2683
2684/*
2685 * a RENEW request
2686 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002687static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2688 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002691 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 };
2693
Chuck Lever9f06c712010-12-14 14:59:18 +00002694 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002695 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002696 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697}
2698
2699/*
2700 * a SETCLIENTID request
2701 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002702static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2703 struct xdr_stream *xdr,
2704 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002707 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 };
2709
Chuck Lever9f06c712010-12-14 14:59:18 +00002710 encode_compound_hdr(xdr, req, &hdr);
2711 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002712 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713}
2714
2715/*
2716 * a SETCLIENTID_CONFIRM request
2717 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002718static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2719 struct xdr_stream *xdr,
2720 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002723 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 };
Fred Isamandae100c2011-07-30 20:52:37 -04002725 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726
Chuck Lever9f06c712010-12-14 14:59:18 +00002727 encode_compound_hdr(xdr, req, &hdr);
2728 encode_setclientid_confirm(xdr, arg, &hdr);
2729 encode_putrootfh(xdr, &hdr);
2730 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002731 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732}
2733
2734/*
2735 * DELEGRETURN request
2736 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002737static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2738 struct xdr_stream *xdr,
2739 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002742 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744
Chuck Lever9f06c712010-12-14 14:59:18 +00002745 encode_compound_hdr(xdr, req, &hdr);
2746 encode_sequence(xdr, &args->seq_args, &hdr);
2747 encode_putfh(xdr, args->fhandle, &hdr);
2748 encode_delegreturn(xdr, args->stateid, &hdr);
2749 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002750 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751}
2752
2753/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002754 * Encode FS_LOCATIONS request
2755 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002756static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2757 struct xdr_stream *xdr,
2758 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002759{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002760 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002761 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002762 };
Benny Halevy28f56692009-04-01 09:22:09 -04002763 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002764
Chuck Lever9f06c712010-12-14 14:59:18 +00002765 encode_compound_hdr(xdr, req, &hdr);
2766 encode_sequence(xdr, &args->seq_args, &hdr);
2767 encode_putfh(xdr, args->dir_fh, &hdr);
2768 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002769 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002770 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002771
Benny Halevy28f56692009-04-01 09:22:09 -04002772 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002773 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002774 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002775}
2776
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002777/*
2778 * Encode SECINFO request
2779 */
2780static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2781 struct xdr_stream *xdr,
2782 struct nfs4_secinfo_arg *args)
2783{
2784 struct compound_hdr hdr = {
2785 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2786 };
2787
2788 encode_compound_hdr(xdr, req, &hdr);
2789 encode_sequence(xdr, &args->seq_args, &hdr);
2790 encode_putfh(xdr, args->dir_fh, &hdr);
2791 encode_secinfo(xdr, args->name, &hdr);
2792 encode_nops(&hdr);
2793}
2794
Benny Halevy99fe60d2009-04-01 09:22:29 -04002795#if defined(CONFIG_NFS_V4_1)
2796/*
2797 * EXCHANGE_ID request
2798 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002799static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2800 struct xdr_stream *xdr,
2801 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002802{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002803 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002804 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002805 };
2806
Chuck Lever9f06c712010-12-14 14:59:18 +00002807 encode_compound_hdr(xdr, req, &hdr);
2808 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002809 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002810}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002811
2812/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002813 * a CREATE_SESSION request
2814 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002815static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2816 struct xdr_stream *xdr,
2817 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002818{
Andy Adamsonfc931582009-04-01 09:22:31 -04002819 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002820 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002821 };
2822
Chuck Lever9f06c712010-12-14 14:59:18 +00002823 encode_compound_hdr(xdr, req, &hdr);
2824 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002825 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002826}
2827
2828/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002829 * a DESTROY_SESSION request
2830 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002831static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2832 struct xdr_stream *xdr,
2833 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002834{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002835 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002836 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002837 };
2838
Chuck Lever9f06c712010-12-14 14:59:18 +00002839 encode_compound_hdr(xdr, req, &hdr);
2840 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002841 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002842}
2843
2844/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002845 * a SEQUENCE request
2846 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002847static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2848 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002849{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002850 struct compound_hdr hdr = {
2851 .minorversion = nfs4_xdr_minorversion(args),
2852 };
2853
Chuck Lever9f06c712010-12-14 14:59:18 +00002854 encode_compound_hdr(xdr, req, &hdr);
2855 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002856 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002857}
2858
2859/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002860 * a GET_LEASE_TIME request
2861 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002862static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2863 struct xdr_stream *xdr,
2864 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002865{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002866 struct compound_hdr hdr = {
2867 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2868 };
Fred Isamandae100c2011-07-30 20:52:37 -04002869 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002870
Chuck Lever9f06c712010-12-14 14:59:18 +00002871 encode_compound_hdr(xdr, req, &hdr);
2872 encode_sequence(xdr, &args->la_seq_args, &hdr);
2873 encode_putrootfh(xdr, &hdr);
2874 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002875 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002876}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002877
2878/*
2879 * a RECLAIM_COMPLETE request
2880 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002881static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2882 struct xdr_stream *xdr,
2883 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002884{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002885 struct compound_hdr hdr = {
2886 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2887 };
2888
Chuck Lever9f06c712010-12-14 14:59:18 +00002889 encode_compound_hdr(xdr, req, &hdr);
2890 encode_sequence(xdr, &args->seq_args, &hdr);
2891 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002892 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002893}
2894
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002895/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002896 * Encode GETDEVICELIST request
2897 */
2898static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2899 struct xdr_stream *xdr,
2900 struct nfs4_getdevicelist_args *args)
2901{
2902 struct compound_hdr hdr = {
2903 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2904 };
2905
2906 encode_compound_hdr(xdr, req, &hdr);
2907 encode_sequence(xdr, &args->seq_args, &hdr);
2908 encode_putfh(xdr, args->fh, &hdr);
2909 encode_getdevicelist(xdr, args, &hdr);
2910 encode_nops(&hdr);
2911}
2912
2913/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002914 * Encode GETDEVICEINFO request
2915 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002916static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2917 struct xdr_stream *xdr,
2918 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002919{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002920 struct compound_hdr hdr = {
2921 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2922 };
2923
Chuck Lever9f06c712010-12-14 14:59:18 +00002924 encode_compound_hdr(xdr, req, &hdr);
2925 encode_sequence(xdr, &args->seq_args, &hdr);
2926 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002927
2928 /* set up reply kvec. Subtract notification bitmap max size (2)
2929 * so that notification bitmap is put in xdr_buf tail */
2930 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2931 args->pdev->pages, args->pdev->pgbase,
2932 args->pdev->pglen);
2933
2934 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002935}
2936
2937/*
2938 * Encode LAYOUTGET request
2939 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002940static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2941 struct xdr_stream *xdr,
2942 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002943{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002944 struct compound_hdr hdr = {
2945 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2946 };
2947
Chuck Lever9f06c712010-12-14 14:59:18 +00002948 encode_compound_hdr(xdr, req, &hdr);
2949 encode_sequence(xdr, &args->seq_args, &hdr);
2950 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2951 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002952
2953 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2954 args->layout.pages, 0, args->layout.pglen);
2955
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002956 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002957}
Andy Adamson863a3c62011-03-23 13:27:54 +00002958
2959/*
2960 * Encode LAYOUTCOMMIT request
2961 */
Benny Halevycbe82602011-05-22 19:52:37 +03002962static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2963 struct xdr_stream *xdr,
2964 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002965{
Benny Halevyac7db722011-05-22 19:53:48 +03002966 struct nfs4_layoutcommit_data *data =
2967 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002968 struct compound_hdr hdr = {
2969 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2970 };
2971
2972 encode_compound_hdr(xdr, req, &hdr);
2973 encode_sequence(xdr, &args->seq_args, &hdr);
2974 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002975 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002976 encode_getfattr(xdr, args->bitmask, &hdr);
2977 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002978}
2979
2980/*
2981 * Encode LAYOUTRETURN request
2982 */
2983static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2984 struct xdr_stream *xdr,
2985 struct nfs4_layoutreturn_args *args)
2986{
2987 struct compound_hdr hdr = {
2988 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2989 };
2990
2991 encode_compound_hdr(xdr, req, &hdr);
2992 encode_sequence(xdr, &args->seq_args, &hdr);
2993 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2994 encode_layoutreturn(xdr, args, &hdr);
2995 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002996}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002997
2998/*
2999 * Encode SECINFO_NO_NAME request
3000 */
3001static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3002 struct xdr_stream *xdr,
3003 struct nfs41_secinfo_no_name_args *args)
3004{
3005 struct compound_hdr hdr = {
3006 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3007 };
3008
3009 encode_compound_hdr(xdr, req, &hdr);
3010 encode_sequence(xdr, &args->seq_args, &hdr);
3011 encode_putrootfh(xdr, &hdr);
3012 encode_secinfo_no_name(xdr, args, &hdr);
3013 encode_nops(&hdr);
3014 return 0;
3015}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003016
3017/*
3018 * Encode TEST_STATEID request
3019 */
3020static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3021 struct xdr_stream *xdr,
3022 struct nfs41_test_stateid_args *args)
3023{
3024 struct compound_hdr hdr = {
3025 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3026 };
3027
3028 encode_compound_hdr(xdr, req, &hdr);
3029 encode_sequence(xdr, &args->seq_args, &hdr);
3030 encode_test_stateid(xdr, args, &hdr);
3031 encode_nops(&hdr);
3032}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003033
3034/*
3035 * Encode FREE_STATEID request
3036 */
3037static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3038 struct xdr_stream *xdr,
3039 struct nfs41_free_stateid_args *args)
3040{
3041 struct compound_hdr hdr = {
3042 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3043 };
3044
3045 encode_compound_hdr(xdr, req, &hdr);
3046 encode_sequence(xdr, &args->seq_args, &hdr);
3047 encode_free_stateid(xdr, args, &hdr);
3048 encode_nops(&hdr);
3049}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003050#endif /* CONFIG_NFS_V4_1 */
3051
Benny Halevy686841b2009-08-14 17:19:48 +03003052static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3053{
3054 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3055 "Remaining buffer length is %tu words.\n",
3056 func, xdr->end - xdr->p);
3057}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
Trond Myklebust683b57b2006-06-09 09:34:22 -04003059static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060{
Al Viro8687b632006-10-19 23:28:48 -07003061 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
Benny Halevyc0eae662009-08-14 17:20:14 +03003063 p = xdr_inline_decode(xdr, 4);
3064 if (unlikely(!p))
3065 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003066 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003067 p = xdr_inline_decode(xdr, *len);
3068 if (unlikely(!p))
3069 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 *string = (char *)p;
3071 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003072out_overflow:
3073 print_overflow_msg(__func__, xdr);
3074 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075}
3076
3077static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3078{
Al Viro8687b632006-10-19 23:28:48 -07003079 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080
Benny Halevyc0eae662009-08-14 17:20:14 +03003081 p = xdr_inline_decode(xdr, 8);
3082 if (unlikely(!p))
3083 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003084 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003085 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003086
Benny Halevyc0eae662009-08-14 17:20:14 +03003087 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3088 if (unlikely(!p))
3089 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 hdr->tag = (char *)p;
3091 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003092 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003093 if (unlikely(hdr->nops < 1))
3094 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003096out_overflow:
3097 print_overflow_msg(__func__, xdr);
3098 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099}
3100
3101static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3102{
Al Viro8687b632006-10-19 23:28:48 -07003103 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 uint32_t opnum;
3105 int32_t nfserr;
3106
Benny Halevyc0eae662009-08-14 17:20:14 +03003107 p = xdr_inline_decode(xdr, 8);
3108 if (unlikely(!p))
3109 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003110 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003112 dprintk("nfs: Server returned operation"
3113 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 opnum, expected);
3115 return -EIO;
3116 }
Benny Halevycccddf42009-08-14 17:20:19 +03003117 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003119 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003121out_overflow:
3122 print_overflow_msg(__func__, xdr);
3123 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124}
3125
3126/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003127static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128{
Al Viro8687b632006-10-19 23:28:48 -07003129 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003130 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 char *str;
3132
Benny Halevyc0eae662009-08-14 17:20:14 +03003133 p = xdr_inline_decode(xdr, 12);
3134 if (likely(p))
3135 return decode_opaque_inline(xdr, &strlen, &str);
3136 print_overflow_msg(__func__, xdr);
3137 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138}
3139
3140static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3141{
Al Viro8687b632006-10-19 23:28:48 -07003142 uint32_t bmlen;
3143 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144
Benny Halevyc0eae662009-08-14 17:20:14 +03003145 p = xdr_inline_decode(xdr, 4);
3146 if (unlikely(!p))
3147 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003148 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149
Fred Isamandae100c2011-07-30 20:52:37 -04003150 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003151 p = xdr_inline_decode(xdr, (bmlen << 2));
3152 if (unlikely(!p))
3153 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003155 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003156 if (bmlen > 1) {
3157 bitmap[1] = be32_to_cpup(p++);
3158 if (bmlen > 2)
3159 bitmap[2] = be32_to_cpup(p);
3160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 }
3162 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003163out_overflow:
3164 print_overflow_msg(__func__, xdr);
3165 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166}
3167
Al Viro8687b632006-10-19 23:28:48 -07003168static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169{
Al Viro8687b632006-10-19 23:28:48 -07003170 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171
Benny Halevyc0eae662009-08-14 17:20:14 +03003172 p = xdr_inline_decode(xdr, 4);
3173 if (unlikely(!p))
3174 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003175 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 *savep = xdr->p;
3177 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003178out_overflow:
3179 print_overflow_msg(__func__, xdr);
3180 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181}
3182
3183static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3184{
3185 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003186 int ret;
3187 ret = decode_attr_bitmap(xdr, bitmask);
3188 if (unlikely(ret < 0))
3189 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3191 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003192 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3193 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3194 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 return 0;
3196}
3197
3198static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3199{
Al Viro8687b632006-10-19 23:28:48 -07003200 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003201 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202
3203 *type = 0;
3204 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3205 return -EIO;
3206 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003207 p = xdr_inline_decode(xdr, 4);
3208 if (unlikely(!p))
3209 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003210 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003212 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 return -EIO;
3214 }
3215 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003216 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003218 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003219 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003220out_overflow:
3221 print_overflow_msg(__func__, xdr);
3222 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223}
3224
Chuck Lever264e6352012-03-01 17:02:05 -05003225static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3226 uint32_t *bitmap, uint32_t *type)
3227{
3228 __be32 *p;
3229
3230 *type = 0;
3231 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3232 return -EIO;
3233 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3234 p = xdr_inline_decode(xdr, 4);
3235 if (unlikely(!p))
3236 goto out_overflow;
3237 *type = be32_to_cpup(p);
3238 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3239 }
3240 dprintk("%s: expire type=0x%x\n", __func__, *type);
3241 return 0;
3242out_overflow:
3243 print_overflow_msg(__func__, xdr);
3244 return -EIO;
3245}
3246
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3248{
Al Viro8687b632006-10-19 23:28:48 -07003249 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003250 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251
3252 *change = 0;
3253 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3254 return -EIO;
3255 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003256 p = xdr_inline_decode(xdr, 8);
3257 if (unlikely(!p))
3258 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003259 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003261 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003263 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003265 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003266out_overflow:
3267 print_overflow_msg(__func__, xdr);
3268 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269}
3270
3271static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3272{
Al Viro8687b632006-10-19 23:28:48 -07003273 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003274 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275
3276 *size = 0;
3277 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3278 return -EIO;
3279 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003280 p = xdr_inline_decode(xdr, 8);
3281 if (unlikely(!p))
3282 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003283 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003285 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003287 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003288 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003289out_overflow:
3290 print_overflow_msg(__func__, xdr);
3291 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292}
3293
3294static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3295{
Al Viro8687b632006-10-19 23:28:48 -07003296 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297
3298 *res = 0;
3299 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3300 return -EIO;
3301 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003302 p = xdr_inline_decode(xdr, 4);
3303 if (unlikely(!p))
3304 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003305 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3307 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003308 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003310out_overflow:
3311 print_overflow_msg(__func__, xdr);
3312 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313}
3314
3315static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3316{
Al Viro8687b632006-10-19 23:28:48 -07003317 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
3319 *res = 0;
3320 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3321 return -EIO;
3322 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003323 p = xdr_inline_decode(xdr, 4);
3324 if (unlikely(!p))
3325 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003326 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3328 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003329 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003331out_overflow:
3332 print_overflow_msg(__func__, xdr);
3333 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334}
3335
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003336static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337{
Al Viro8687b632006-10-19 23:28:48 -07003338 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003339 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340
3341 fsid->major = 0;
3342 fsid->minor = 0;
3343 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3344 return -EIO;
3345 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003346 p = xdr_inline_decode(xdr, 16);
3347 if (unlikely(!p))
3348 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003349 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003350 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003352 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003354 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 (unsigned long long)fsid->major,
3356 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003357 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003358out_overflow:
3359 print_overflow_msg(__func__, xdr);
3360 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361}
3362
3363static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3364{
Al Viro8687b632006-10-19 23:28:48 -07003365 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366
3367 *res = 60;
3368 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3369 return -EIO;
3370 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003371 p = xdr_inline_decode(xdr, 4);
3372 if (unlikely(!p))
3373 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003374 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3376 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003377 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003379out_overflow:
3380 print_overflow_msg(__func__, xdr);
3381 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382}
3383
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003384static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003385{
3386 __be32 *p;
3387
3388 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3389 return -EIO;
3390 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3391 p = xdr_inline_decode(xdr, 4);
3392 if (unlikely(!p))
3393 goto out_overflow;
3394 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003395 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003396 }
3397 return 0;
3398out_overflow:
3399 print_overflow_msg(__func__, xdr);
3400 return -EIO;
3401}
3402
3403static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3404{
3405 __be32 *p;
3406 int len;
3407
Trond Myklebust7ad07352010-10-23 15:34:20 -04003408 if (fh != NULL)
3409 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003410
3411 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3412 return -EIO;
3413 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3414 p = xdr_inline_decode(xdr, 4);
3415 if (unlikely(!p))
3416 goto out_overflow;
3417 len = be32_to_cpup(p);
3418 if (len > NFS4_FHSIZE)
3419 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003420 p = xdr_inline_decode(xdr, len);
3421 if (unlikely(!p))
3422 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003423 if (fh != NULL) {
3424 memcpy(fh->data, p, len);
3425 fh->size = len;
3426 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003427 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3428 }
3429 return 0;
3430out_overflow:
3431 print_overflow_msg(__func__, xdr);
3432 return -EIO;
3433}
3434
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3436{
Al Viro8687b632006-10-19 23:28:48 -07003437 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438
3439 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3440 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3441 return -EIO;
3442 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003443 p = xdr_inline_decode(xdr, 4);
3444 if (unlikely(!p))
3445 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003446 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3448 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003449 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003451out_overflow:
3452 print_overflow_msg(__func__, xdr);
3453 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454}
3455
3456static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3457{
Al Viro8687b632006-10-19 23:28:48 -07003458 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003459 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460
3461 *fileid = 0;
3462 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3463 return -EIO;
3464 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003465 p = xdr_inline_decode(xdr, 8);
3466 if (unlikely(!p))
3467 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003468 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003470 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003472 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003473 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003474out_overflow:
3475 print_overflow_msg(__func__, xdr);
3476 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477}
3478
Manoj Naik99baf622006-06-09 09:34:24 -04003479static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3480{
Al Viro8687b632006-10-19 23:28:48 -07003481 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003482 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003483
3484 *fileid = 0;
3485 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3486 return -EIO;
3487 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003488 p = xdr_inline_decode(xdr, 8);
3489 if (unlikely(!p))
3490 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003491 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003492 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003493 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003494 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003495 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003496 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003497out_overflow:
3498 print_overflow_msg(__func__, xdr);
3499 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003500}
3501
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3503{
Al Viro8687b632006-10-19 23:28:48 -07003504 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 int status = 0;
3506
3507 *res = 0;
3508 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3509 return -EIO;
3510 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003511 p = xdr_inline_decode(xdr, 8);
3512 if (unlikely(!p))
3513 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003514 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3516 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003517 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003519out_overflow:
3520 print_overflow_msg(__func__, xdr);
3521 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522}
3523
3524static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3525{
Al Viro8687b632006-10-19 23:28:48 -07003526 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 int status = 0;
3528
3529 *res = 0;
3530 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3531 return -EIO;
3532 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003533 p = xdr_inline_decode(xdr, 8);
3534 if (unlikely(!p))
3535 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003536 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3538 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003539 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003541out_overflow:
3542 print_overflow_msg(__func__, xdr);
3543 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544}
3545
3546static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3547{
Al Viro8687b632006-10-19 23:28:48 -07003548 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 int status = 0;
3550
3551 *res = 0;
3552 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3553 return -EIO;
3554 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003555 p = xdr_inline_decode(xdr, 8);
3556 if (unlikely(!p))
3557 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003558 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3560 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003561 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003563out_overflow:
3564 print_overflow_msg(__func__, xdr);
3565 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566}
3567
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003568static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3569{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003570 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003571 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003572 int status = 0;
3573
Benny Halevyc0eae662009-08-14 17:20:14 +03003574 p = xdr_inline_decode(xdr, 4);
3575 if (unlikely(!p))
3576 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003577 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003578 if (n == 0)
3579 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003580 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003581 path->ncomponents = 0;
3582 while (path->ncomponents < n) {
3583 struct nfs4_string *component = &path->components[path->ncomponents];
3584 status = decode_opaque_inline(xdr, &component->len, &component->data);
3585 if (unlikely(status != 0))
3586 goto out_eio;
Chuck Lever02a29762012-03-01 17:00:31 -05003587 if (unlikely(nfs_debug & NFSDBG_XDR))
3588 pr_cont("%s%.*s ",
3589 (path->ncomponents != n ? "/ " : ""),
3590 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003591 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3592 path->ncomponents++;
3593 else {
3594 dprintk("cannot parse %d components in path\n", n);
3595 goto out_eio;
3596 }
3597 }
3598out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003599 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003600root_path:
3601/* a root pathname is sent as a zero component4 */
3602 path->ncomponents = 1;
3603 path->components[0].len=0;
3604 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003605 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003606 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003607out_eio:
3608 dprintk(" status %d", status);
3609 status = -EIO;
3610 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003611out_overflow:
3612 print_overflow_msg(__func__, xdr);
3613 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003614}
3615
3616static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003617{
3618 int n;
Al Viro8687b632006-10-19 23:28:48 -07003619 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003620 int status = -EIO;
3621
3622 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3623 goto out;
3624 status = 0;
3625 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3626 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003627 status = -EIO;
3628 /* Ignore borken servers that return unrequested attrs */
3629 if (unlikely(res == NULL))
3630 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003631 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003632 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003633 if (unlikely(status != 0))
3634 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003635 p = xdr_inline_decode(xdr, 4);
3636 if (unlikely(!p))
3637 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003638 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003639 if (n <= 0)
3640 goto out_eio;
3641 res->nlocations = 0;
3642 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003643 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003644 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003645
Benny Halevyc0eae662009-08-14 17:20:14 +03003646 p = xdr_inline_decode(xdr, 4);
3647 if (unlikely(!p))
3648 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003649 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003650
3651 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003652 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003653 while (loc->nservers < m) {
3654 struct nfs4_string *server = &loc->servers[loc->nservers];
3655 status = decode_opaque_inline(xdr, &server->len, &server->data);
3656 if (unlikely(status != 0))
3657 goto out_eio;
3658 dprintk("%s ", server->data);
3659 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3660 loc->nservers++;
3661 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003662 unsigned int i;
3663 dprintk("%s: using first %u of %u servers "
3664 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003665 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003666 NFS4_FS_LOCATION_MAXSERVERS,
3667 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003668 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003669 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003670 char *data;
3671 status = decode_opaque_inline(xdr, &len, &data);
3672 if (unlikely(status != 0))
3673 goto out_eio;
3674 }
3675 }
3676 }
3677 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003678 if (unlikely(status != 0))
3679 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003680 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003681 res->nlocations++;
3682 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003683 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003684 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003685out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003686 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003687 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003688out_overflow:
3689 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003690out_eio:
3691 status = -EIO;
3692 goto out;
3693}
3694
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3696{
Al Viro8687b632006-10-19 23:28:48 -07003697 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 int status = 0;
3699
3700 *res = 0;
3701 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3702 return -EIO;
3703 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003704 p = xdr_inline_decode(xdr, 8);
3705 if (unlikely(!p))
3706 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003707 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3709 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003710 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003712out_overflow:
3713 print_overflow_msg(__func__, xdr);
3714 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715}
3716
3717static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3718{
Al Viro8687b632006-10-19 23:28:48 -07003719 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 int status = 0;
3721
3722 *maxlink = 1;
3723 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3724 return -EIO;
3725 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003726 p = xdr_inline_decode(xdr, 4);
3727 if (unlikely(!p))
3728 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003729 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3731 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003732 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003734out_overflow:
3735 print_overflow_msg(__func__, xdr);
3736 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737}
3738
3739static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3740{
Al Viro8687b632006-10-19 23:28:48 -07003741 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 int status = 0;
3743
3744 *maxname = 1024;
3745 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3746 return -EIO;
3747 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003748 p = xdr_inline_decode(xdr, 4);
3749 if (unlikely(!p))
3750 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003751 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3753 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003754 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003756out_overflow:
3757 print_overflow_msg(__func__, xdr);
3758 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759}
3760
3761static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3762{
Al Viro8687b632006-10-19 23:28:48 -07003763 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764 int status = 0;
3765
3766 *res = 1024;
3767 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3768 return -EIO;
3769 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3770 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003771 p = xdr_inline_decode(xdr, 8);
3772 if (unlikely(!p))
3773 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003774 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 if (maxread > 0x7FFFFFFF)
3776 maxread = 0x7FFFFFFF;
3777 *res = (uint32_t)maxread;
3778 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3779 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003780 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003782out_overflow:
3783 print_overflow_msg(__func__, xdr);
3784 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785}
3786
3787static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3788{
Al Viro8687b632006-10-19 23:28:48 -07003789 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 int status = 0;
3791
3792 *res = 1024;
3793 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3794 return -EIO;
3795 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3796 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003797 p = xdr_inline_decode(xdr, 8);
3798 if (unlikely(!p))
3799 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003800 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 if (maxwrite > 0x7FFFFFFF)
3802 maxwrite = 0x7FFFFFFF;
3803 *res = (uint32_t)maxwrite;
3804 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3805 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003806 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003808out_overflow:
3809 print_overflow_msg(__func__, xdr);
3810 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811}
3812
Trond Myklebustbca79472009-03-11 14:10:26 -04003813static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814{
Trond Myklebustbca79472009-03-11 14:10:26 -04003815 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003816 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003817 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818
3819 *mode = 0;
3820 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3821 return -EIO;
3822 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003823 p = xdr_inline_decode(xdr, 4);
3824 if (unlikely(!p))
3825 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003826 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003827 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003829 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003831 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003832 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003833out_overflow:
3834 print_overflow_msg(__func__, xdr);
3835 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836}
3837
3838static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3839{
Al Viro8687b632006-10-19 23:28:48 -07003840 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003841 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842
3843 *nlink = 1;
3844 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3845 return -EIO;
3846 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003847 p = xdr_inline_decode(xdr, 4);
3848 if (unlikely(!p))
3849 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003850 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003852 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003854 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003855 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003856out_overflow:
3857 print_overflow_msg(__func__, xdr);
3858 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859}
3860
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003861static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003862 const struct nfs_server *server, uint32_t *uid,
3863 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864{
Al Viro8687b632006-10-19 23:28:48 -07003865 uint32_t len;
3866 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003867 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868
3869 *uid = -2;
3870 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3871 return -EIO;
3872 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003873 p = xdr_inline_decode(xdr, 4);
3874 if (unlikely(!p))
3875 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003876 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003877 p = xdr_inline_decode(xdr, len);
3878 if (unlikely(!p))
3879 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003880 if (owner_name != NULL) {
3881 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3882 if (owner_name->data != NULL) {
3883 owner_name->len = len;
3884 ret = NFS_ATTR_FATTR_OWNER_NAME;
3885 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003886 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003887 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003888 ret = NFS_ATTR_FATTR_OWNER;
3889 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003891 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003893 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003894 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3896 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003897 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003898 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003899out_overflow:
3900 print_overflow_msg(__func__, xdr);
3901 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902}
3903
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003904static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003905 const struct nfs_server *server, uint32_t *gid,
3906 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907{
Al Viro8687b632006-10-19 23:28:48 -07003908 uint32_t len;
3909 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003910 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911
3912 *gid = -2;
3913 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3914 return -EIO;
3915 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003916 p = xdr_inline_decode(xdr, 4);
3917 if (unlikely(!p))
3918 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003919 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003920 p = xdr_inline_decode(xdr, len);
3921 if (unlikely(!p))
3922 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003923 if (group_name != NULL) {
3924 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3925 if (group_name->data != NULL) {
3926 group_name->len = len;
3927 ret = NFS_ATTR_FATTR_GROUP_NAME;
3928 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003929 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003930 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003931 ret = NFS_ATTR_FATTR_GROUP;
3932 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003934 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003936 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003937 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3939 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003940 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003941 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003942out_overflow:
3943 print_overflow_msg(__func__, xdr);
3944 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945}
3946
3947static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3948{
Al Viro8687b632006-10-19 23:28:48 -07003949 uint32_t major = 0, minor = 0;
3950 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003951 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952
3953 *rdev = MKDEV(0,0);
3954 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3955 return -EIO;
3956 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3957 dev_t tmp;
3958
Benny Halevyc0eae662009-08-14 17:20:14 +03003959 p = xdr_inline_decode(xdr, 8);
3960 if (unlikely(!p))
3961 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003962 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003963 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 tmp = MKDEV(major, minor);
3965 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3966 *rdev = tmp;
3967 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003968 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003970 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003971 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003972out_overflow:
3973 print_overflow_msg(__func__, xdr);
3974 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975}
3976
3977static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3978{
Al Viro8687b632006-10-19 23:28:48 -07003979 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 int status = 0;
3981
3982 *res = 0;
3983 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3984 return -EIO;
3985 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003986 p = xdr_inline_decode(xdr, 8);
3987 if (unlikely(!p))
3988 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003989 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3991 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003992 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003994out_overflow:
3995 print_overflow_msg(__func__, xdr);
3996 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997}
3998
3999static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4000{
Al Viro8687b632006-10-19 23:28:48 -07004001 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 int status = 0;
4003
4004 *res = 0;
4005 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4006 return -EIO;
4007 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004008 p = xdr_inline_decode(xdr, 8);
4009 if (unlikely(!p))
4010 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004011 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4013 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004014 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004016out_overflow:
4017 print_overflow_msg(__func__, xdr);
4018 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019}
4020
4021static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4022{
Al Viro8687b632006-10-19 23:28:48 -07004023 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 int status = 0;
4025
4026 *res = 0;
4027 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4028 return -EIO;
4029 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004030 p = xdr_inline_decode(xdr, 8);
4031 if (unlikely(!p))
4032 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004033 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4035 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004036 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004038out_overflow:
4039 print_overflow_msg(__func__, xdr);
4040 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041}
4042
4043static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4044{
Al Viro8687b632006-10-19 23:28:48 -07004045 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004046 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047
4048 *used = 0;
4049 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4050 return -EIO;
4051 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004052 p = xdr_inline_decode(xdr, 8);
4053 if (unlikely(!p))
4054 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004055 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004057 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004059 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004061 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004062out_overflow:
4063 print_overflow_msg(__func__, xdr);
4064 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065}
4066
4067static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4068{
Al Viro8687b632006-10-19 23:28:48 -07004069 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 uint64_t sec;
4071 uint32_t nsec;
4072
Benny Halevyc0eae662009-08-14 17:20:14 +03004073 p = xdr_inline_decode(xdr, 12);
4074 if (unlikely(!p))
4075 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004076 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004077 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078 time->tv_sec = (time_t)sec;
4079 time->tv_nsec = (long)nsec;
4080 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004081out_overflow:
4082 print_overflow_msg(__func__, xdr);
4083 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084}
4085
4086static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4087{
4088 int status = 0;
4089
4090 time->tv_sec = 0;
4091 time->tv_nsec = 0;
4092 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4093 return -EIO;
4094 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4095 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004096 if (status == 0)
4097 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4099 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004100 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101 return status;
4102}
4103
4104static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4105{
4106 int status = 0;
4107
4108 time->tv_sec = 0;
4109 time->tv_nsec = 0;
4110 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4111 return -EIO;
4112 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4113 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004114 if (status == 0)
4115 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4117 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004118 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119 return status;
4120}
4121
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004122static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4123 struct timespec *time)
4124{
4125 int status = 0;
4126
4127 time->tv_sec = 0;
4128 time->tv_nsec = 0;
4129 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4130 return -EIO;
4131 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4132 status = decode_attr_time(xdr, time);
4133 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4134 }
4135 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4136 (long)time->tv_nsec);
4137 return status;
4138}
4139
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4141{
4142 int status = 0;
4143
4144 time->tv_sec = 0;
4145 time->tv_nsec = 0;
4146 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4147 return -EIO;
4148 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4149 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004150 if (status == 0)
4151 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4153 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004154 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155 return status;
4156}
4157
Al Viro8687b632006-10-19 23:28:48 -07004158static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159{
4160 unsigned int attrwords = XDR_QUADLEN(attrlen);
4161 unsigned int nwords = xdr->p - savep;
4162
4163 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004164 dprintk("%s: server returned incorrect attribute length: "
4165 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004166 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 attrwords << 2,
4168 (attrwords < nwords) ? '<' : '>',
4169 nwords << 2);
4170 return -EIO;
4171 }
4172 return 0;
4173}
4174
4175static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4176{
Al Viro8687b632006-10-19 23:28:48 -07004177 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178
Benny Halevyc0eae662009-08-14 17:20:14 +03004179 p = xdr_inline_decode(xdr, 20);
4180 if (unlikely(!p))
4181 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004182 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004183 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004184 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004186out_overflow:
4187 print_overflow_msg(__func__, xdr);
4188 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189}
4190
4191static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4192{
Al Viro8687b632006-10-19 23:28:48 -07004193 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 uint32_t supp, acc;
4195 int status;
4196
4197 status = decode_op_hdr(xdr, OP_ACCESS);
4198 if (status)
4199 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004200 p = xdr_inline_decode(xdr, 8);
4201 if (unlikely(!p))
4202 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004203 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004204 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 access->supported = supp;
4206 access->access = acc;
4207 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004208out_overflow:
4209 print_overflow_msg(__func__, xdr);
4210 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211}
4212
Benny Halevy07d30432009-08-14 17:19:52 +03004213static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214{
Al Viro8687b632006-10-19 23:28:48 -07004215 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004216
4217 p = xdr_inline_decode(xdr, len);
4218 if (likely(p)) {
4219 memcpy(buf, p, len);
4220 return 0;
4221 }
4222 print_overflow_msg(__func__, xdr);
4223 return -EIO;
4224}
4225
4226static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4227{
4228 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229}
4230
4231static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4232{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233 int status;
4234
4235 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004236 if (status != -EIO)
4237 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004238 if (!status)
4239 status = decode_stateid(xdr, &res->stateid);
4240 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241}
4242
Benny Halevydb942bb2009-08-14 17:19:56 +03004243static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4244{
4245 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246}
4247
4248static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4249{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 int status;
4251
4252 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004253 if (!status)
4254 status = decode_verifier(xdr, res->verf->verifier);
4255 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256}
4257
4258static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4259{
Al Viro8687b632006-10-19 23:28:48 -07004260 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261 uint32_t bmlen;
4262 int status;
4263
4264 status = decode_op_hdr(xdr, OP_CREATE);
4265 if (status)
4266 return status;
4267 if ((status = decode_change_info(xdr, cinfo)))
4268 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004269 p = xdr_inline_decode(xdr, 4);
4270 if (unlikely(!p))
4271 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004272 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004273 p = xdr_inline_decode(xdr, bmlen << 2);
4274 if (likely(p))
4275 return 0;
4276out_overflow:
4277 print_overflow_msg(__func__, xdr);
4278 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279}
4280
4281static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4282{
Al Viro8687b632006-10-19 23:28:48 -07004283 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004284 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285 int status;
4286
4287 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4288 goto xdr_error;
4289 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4290 goto xdr_error;
4291 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4292 goto xdr_error;
4293 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4294 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004295 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4296 &res->fh_expire_type)) != 0)
4297 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4299 goto xdr_error;
4300 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4301 goto xdr_error;
4302 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4303 goto xdr_error;
4304 status = verify_attr_len(xdr, savep, attrlen);
4305xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004306 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 return status;
4308}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004309
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4311{
Al Viro8687b632006-10-19 23:28:48 -07004312 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004313 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004315
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4317 goto xdr_error;
4318 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4319 goto xdr_error;
4320 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4321 goto xdr_error;
4322
4323 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4324 goto xdr_error;
4325 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4326 goto xdr_error;
4327 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4328 goto xdr_error;
4329 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4330 goto xdr_error;
4331 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4332 goto xdr_error;
4333 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4334 goto xdr_error;
4335
4336 status = verify_attr_len(xdr, savep, attrlen);
4337xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004338 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339 return status;
4340}
4341
4342static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4343{
Al Viro8687b632006-10-19 23:28:48 -07004344 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004345 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004347
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4349 goto xdr_error;
4350 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4351 goto xdr_error;
4352 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4353 goto xdr_error;
4354
4355 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4356 goto xdr_error;
4357 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4358 goto xdr_error;
4359
4360 status = verify_attr_len(xdr, savep, attrlen);
4361xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004362 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363 return status;
4364}
4365
Bryan Schumakerae42c702010-10-21 16:33:17 -04004366static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4367 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004368 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004369 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370{
Trond Myklebustbca79472009-03-11 14:10:26 -04004371 int status;
4372 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004373 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004374 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004376 status = decode_attr_type(xdr, bitmap, &type);
4377 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004379 fattr->mode = 0;
4380 if (status != 0) {
4381 fattr->mode |= nfs_type2fmt[type];
4382 fattr->valid |= status;
4383 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004385 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4386 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004388 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004389
4390 status = decode_attr_size(xdr, bitmap, &fattr->size);
4391 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004393 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004394
4395 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4396 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004398 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004399
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004400 err = 0;
4401 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004402 if (status < 0)
4403 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004404 if (err == -NFS4ERR_WRONGSEC)
4405 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004406
4407 status = decode_attr_filehandle(xdr, bitmap, fh);
4408 if (status < 0)
4409 goto xdr_error;
4410
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004411 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4412 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004414 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004415
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004416 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004417 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004418 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004419 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004420
4421 status = decode_attr_mode(xdr, bitmap, &fmode);
4422 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004424 if (status != 0) {
4425 fattr->mode |= fmode;
4426 fattr->valid |= status;
4427 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004428
4429 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4430 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004432 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004433
Trond Myklebust6926afd2012-01-07 13:22:46 -05004434 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004435 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004437 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004438
Trond Myklebust6926afd2012-01-07 13:22:46 -05004439 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004440 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004442 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004443
4444 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4445 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004447 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004448
4449 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4450 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004451 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004452 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004453
4454 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4455 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004456 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004457 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004458
4459 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4460 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004462 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004463
4464 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4465 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004467 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004468
Trond Myklebust28331a42011-04-27 13:47:52 -04004469 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004470 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004471 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004472 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004473
Bryan Schumakerae42c702010-10-21 16:33:17 -04004474xdr_error:
4475 dprintk("%s: xdr returned %d\n", __func__, -status);
4476 return status;
4477}
4478
4479static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004480 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4481 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004482{
4483 __be32 *savep;
4484 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004485 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004486 int status;
4487
4488 status = decode_op_hdr(xdr, OP_GETATTR);
4489 if (status < 0)
4490 goto xdr_error;
4491
4492 status = decode_attr_bitmap(xdr, bitmap);
4493 if (status < 0)
4494 goto xdr_error;
4495
4496 status = decode_attr_length(xdr, &attrlen, &savep);
4497 if (status < 0)
4498 goto xdr_error;
4499
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004500 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004501 if (status < 0)
4502 goto xdr_error;
4503
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004504 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004506 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 return status;
4508}
4509
Bryan Schumakerae42c702010-10-21 16:33:17 -04004510static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004511 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004512{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004513 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004514}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515
Andy Adamson504913f2010-10-20 00:17:57 -04004516/*
4517 * Decode potentially multiple layout types. Currently we only support
4518 * one layout driver per file system.
4519 */
4520static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4521 uint32_t *layouttype)
4522{
4523 uint32_t *p;
4524 int num;
4525
4526 p = xdr_inline_decode(xdr, 4);
4527 if (unlikely(!p))
4528 goto out_overflow;
4529 num = be32_to_cpup(p);
4530
4531 /* pNFS is not supported by the underlying file system */
4532 if (num == 0) {
4533 *layouttype = 0;
4534 return 0;
4535 }
4536 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004537 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4538 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004539
4540 /* Decode and set first layout type, move xdr->p past unused types */
4541 p = xdr_inline_decode(xdr, num * 4);
4542 if (unlikely(!p))
4543 goto out_overflow;
4544 *layouttype = be32_to_cpup(p);
4545 return 0;
4546out_overflow:
4547 print_overflow_msg(__func__, xdr);
4548 return -EIO;
4549}
4550
4551/*
4552 * The type of file system exported.
4553 * Note we must ensure that layouttype is set in any non-error case.
4554 */
4555static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4556 uint32_t *layouttype)
4557{
4558 int status = 0;
4559
4560 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4561 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4562 return -EIO;
4563 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4564 status = decode_first_pnfs_layout_type(xdr, layouttype);
4565 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4566 } else
4567 *layouttype = 0;
4568 return status;
4569}
4570
Fred Isamandae100c2011-07-30 20:52:37 -04004571/*
4572 * The prefered block size for layout directed io
4573 */
4574static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4575 uint32_t *res)
4576{
4577 __be32 *p;
4578
4579 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4580 *res = 0;
4581 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4582 p = xdr_inline_decode(xdr, 4);
4583 if (unlikely(!p)) {
4584 print_overflow_msg(__func__, xdr);
4585 return -EIO;
4586 }
4587 *res = be32_to_cpup(p);
4588 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4589 }
4590 return 0;
4591}
4592
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4594{
Al Viro8687b632006-10-19 23:28:48 -07004595 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004596 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597 int status;
4598
4599 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4600 goto xdr_error;
4601 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4602 goto xdr_error;
4603 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4604 goto xdr_error;
4605
4606 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4607
4608 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4609 goto xdr_error;
4610 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4611 goto xdr_error;
4612 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4613 goto xdr_error;
4614 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4615 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4616 goto xdr_error;
4617 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004618 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4619 if (status != 0)
4620 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004621 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4622 if (status != 0)
4623 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004624 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4625 if (status)
4626 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627
4628 status = verify_attr_len(xdr, savep, attrlen);
4629xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004630 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 return status;
4632}
4633
4634static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4635{
Al Viro8687b632006-10-19 23:28:48 -07004636 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637 uint32_t len;
4638 int status;
4639
Trond Myklebust99367812007-07-17 21:52:41 -04004640 /* Zero handle first to allow comparisons */
4641 memset(fh, 0, sizeof(*fh));
4642
Linus Torvalds1da177e2005-04-16 15:20:36 -07004643 status = decode_op_hdr(xdr, OP_GETFH);
4644 if (status)
4645 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646
Benny Halevyc0eae662009-08-14 17:20:14 +03004647 p = xdr_inline_decode(xdr, 4);
4648 if (unlikely(!p))
4649 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004650 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 if (len > NFS4_FHSIZE)
4652 return -EIO;
4653 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004654 p = xdr_inline_decode(xdr, len);
4655 if (unlikely(!p))
4656 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004657 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004659out_overflow:
4660 print_overflow_msg(__func__, xdr);
4661 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662}
4663
4664static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4665{
4666 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004667
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668 status = decode_op_hdr(xdr, OP_LINK);
4669 if (status)
4670 return status;
4671 return decode_change_info(xdr, cinfo);
4672}
4673
4674/*
4675 * We create the owner, so we know a proper owner.id length is 4.
4676 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004677static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004679 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004680 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004681 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004683 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004684 if (unlikely(!p))
4685 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004686 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004687 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004688 type = be32_to_cpup(p++); /* 4 byte read */
4689 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004690 fl->fl_start = (loff_t)offset;
4691 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4692 if (length == ~(uint64_t)0)
4693 fl->fl_end = OFFSET_MAX;
4694 fl->fl_type = F_WRLCK;
4695 if (type & 1)
4696 fl->fl_type = F_RDLCK;
4697 fl->fl_pid = 0;
4698 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004699 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4700 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4701 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004702 if (likely(p))
4703 return -NFS4ERR_DENIED;
4704out_overflow:
4705 print_overflow_msg(__func__, xdr);
4706 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707}
4708
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004709static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004710{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 int status;
4712
4713 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004714 if (status == -EIO)
4715 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004717 status = decode_stateid(xdr, &res->stateid);
4718 if (unlikely(status))
4719 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004721 status = decode_lock_denied(xdr, NULL);
4722 if (res->open_seqid != NULL)
4723 nfs_increment_open_seqid(status, res->open_seqid);
4724 nfs_increment_lock_seqid(status, res->lock_seqid);
4725out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726 return status;
4727}
4728
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004729static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730{
4731 int status;
4732 status = decode_op_hdr(xdr, OP_LOCKT);
4733 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004734 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 return status;
4736}
4737
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004738static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 int status;
4741
4742 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004743 if (status != -EIO)
4744 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004745 if (status == 0)
4746 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747 return status;
4748}
4749
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004750static int decode_release_lockowner(struct xdr_stream *xdr)
4751{
4752 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4753}
4754
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755static int decode_lookup(struct xdr_stream *xdr)
4756{
4757 return decode_op_hdr(xdr, OP_LOOKUP);
4758}
4759
4760/* This is too sick! */
4761static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4762{
Andy Adamson05d564f2008-12-23 16:06:15 -05004763 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764 uint32_t limit_type, nblocks, blocksize;
4765
Benny Halevyc0eae662009-08-14 17:20:14 +03004766 p = xdr_inline_decode(xdr, 12);
4767 if (unlikely(!p))
4768 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004769 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004771 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004772 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004773 break;
4774 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004775 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004776 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004777 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 }
4779 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004780out_overflow:
4781 print_overflow_msg(__func__, xdr);
4782 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783}
4784
4785static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4786{
Andy Adamson05d564f2008-12-23 16:06:15 -05004787 __be32 *p;
4788 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004789 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790
Benny Halevyc0eae662009-08-14 17:20:14 +03004791 p = xdr_inline_decode(xdr, 4);
4792 if (unlikely(!p))
4793 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004794 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4796 res->delegation_type = 0;
4797 return 0;
4798 }
Benny Halevy07d30432009-08-14 17:19:52 +03004799 status = decode_stateid(xdr, &res->delegation);
4800 if (unlikely(status))
4801 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004802 p = xdr_inline_decode(xdr, 4);
4803 if (unlikely(!p))
4804 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004805 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004806
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004808 case NFS4_OPEN_DELEGATE_READ:
4809 res->delegation_type = FMODE_READ;
4810 break;
4811 case NFS4_OPEN_DELEGATE_WRITE:
4812 res->delegation_type = FMODE_WRITE|FMODE_READ;
4813 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 return -EIO;
4815 }
David Howells7539bba2006-08-22 20:06:09 -04004816 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004817out_overflow:
4818 print_overflow_msg(__func__, xdr);
4819 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820}
4821
4822static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4823{
Andy Adamson05d564f2008-12-23 16:06:15 -05004824 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004825 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004826 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827
Andy Adamson05d564f2008-12-23 16:06:15 -05004828 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004829 if (status != -EIO)
4830 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004831 if (!status)
4832 status = decode_stateid(xdr, &res->stateid);
4833 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004834 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835
Andy Adamson05d564f2008-12-23 16:06:15 -05004836 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837
Benny Halevyc0eae662009-08-14 17:20:14 +03004838 p = xdr_inline_decode(xdr, 8);
4839 if (unlikely(!p))
4840 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004841 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004842 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004843 if (bmlen > 10)
4844 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845
Benny Halevyc0eae662009-08-14 17:20:14 +03004846 p = xdr_inline_decode(xdr, bmlen << 2);
4847 if (unlikely(!p))
4848 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004849 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4850 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004851 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004852 for (; i < NFS4_BITMAP_SIZE; i++)
4853 res->attrset[i] = 0;
4854
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 return decode_delegation(xdr, res);
4856xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004857 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004859out_overflow:
4860 print_overflow_msg(__func__, xdr);
4861 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862}
4863
4864static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4865{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866 int status;
4867
Andy Adamson05d564f2008-12-23 16:06:15 -05004868 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004869 if (status != -EIO)
4870 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004871 if (!status)
4872 status = decode_stateid(xdr, &res->stateid);
4873 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874}
4875
4876static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4877{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 int status;
4879
4880 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004881 if (status != -EIO)
4882 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004883 if (!status)
4884 status = decode_stateid(xdr, &res->stateid);
4885 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886}
4887
4888static int decode_putfh(struct xdr_stream *xdr)
4889{
4890 return decode_op_hdr(xdr, OP_PUTFH);
4891}
4892
4893static int decode_putrootfh(struct xdr_stream *xdr)
4894{
4895 return decode_op_hdr(xdr, OP_PUTROOTFH);
4896}
4897
4898static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4899{
4900 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004901 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902 uint32_t count, eof, recvd, hdrlen;
4903 int status;
4904
4905 status = decode_op_hdr(xdr, OP_READ);
4906 if (status)
4907 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004908 p = xdr_inline_decode(xdr, 8);
4909 if (unlikely(!p))
4910 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004911 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004912 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004913 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914 recvd = req->rq_rcv_buf.len - hdrlen;
4915 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004916 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917 "count %u > recvd %u\n", count, recvd);
4918 count = recvd;
4919 eof = 0;
4920 }
4921 xdr_read_pages(xdr, count);
4922 res->eof = eof;
4923 res->count = count;
4924 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004925out_overflow:
4926 print_overflow_msg(__func__, xdr);
4927 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928}
4929
4930static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4931{
4932 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004934 size_t hdrlen;
4935 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004936 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937
4938 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004939 if (!status)
4940 status = decode_verifier(xdr, readdir->verifier.data);
4941 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004943 dprintk("%s: verifier = %08x:%08x\n",
4944 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004945 ((u32 *)readdir->verifier.data)[0],
4946 ((u32 *)readdir->verifier.data)[1]);
4947
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948
Benny Halevydb942bb2009-08-14 17:19:56 +03004949 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950 recvd = rcvbuf->len - hdrlen;
4951 if (pglen > recvd)
4952 pglen = recvd;
4953 xdr_read_pages(xdr, pglen);
4954
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004955
Trond Myklebustac396122010-11-15 20:26:22 -05004956 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957}
4958
4959static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4960{
4961 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4962 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004963 size_t hdrlen;
4964 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004965 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966 int status;
4967
4968 status = decode_op_hdr(xdr, OP_READLINK);
4969 if (status)
4970 return status;
4971
4972 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004973 p = xdr_inline_decode(xdr, 4);
4974 if (unlikely(!p))
4975 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004976 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004978 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 return -ENAMETOOLONG;
4980 }
4981 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4982 recvd = req->rq_rcv_buf.len - hdrlen;
4983 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004984 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 "count %u > recvd %u\n", len, recvd);
4986 return -EIO;
4987 }
4988 xdr_read_pages(xdr, len);
4989 /*
4990 * The XDR encode routine has set things up so that
4991 * the link text will be copied directly into the
4992 * buffer. We just have to do overflow-checking,
4993 * and and null-terminate the text (the VFS expects
4994 * null-termination).
4995 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004996 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004998out_overflow:
4999 print_overflow_msg(__func__, xdr);
5000 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001}
5002
5003static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5004{
5005 int status;
5006
5007 status = decode_op_hdr(xdr, OP_REMOVE);
5008 if (status)
5009 goto out;
5010 status = decode_change_info(xdr, cinfo);
5011out:
5012 return status;
5013}
5014
5015static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5016 struct nfs4_change_info *new_cinfo)
5017{
5018 int status;
5019
5020 status = decode_op_hdr(xdr, OP_RENAME);
5021 if (status)
5022 goto out;
5023 if ((status = decode_change_info(xdr, old_cinfo)))
5024 goto out;
5025 status = decode_change_info(xdr, new_cinfo);
5026out:
5027 return status;
5028}
5029
5030static int decode_renew(struct xdr_stream *xdr)
5031{
5032 return decode_op_hdr(xdr, OP_RENEW);
5033}
5034
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005035static int
5036decode_restorefh(struct xdr_stream *xdr)
5037{
5038 return decode_op_hdr(xdr, OP_RESTOREFH);
5039}
5040
J. Bruce Fields029d1052005-06-22 17:16:22 +00005041static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005042 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005043{
Andy Adamsonbf118a32011-12-07 11:55:27 -05005044 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005045 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005046 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005047 struct kvec *iov = req->rq_rcv_buf.head;
5048 int status;
5049
Andy Adamsonbf118a32011-12-07 11:55:27 -05005050 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005051 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5052 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005053 bm_p = xdr->p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005054 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5055 goto out;
5056 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5057 goto out;
5058
5059 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5060 return -EIO;
5061 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04005062 size_t hdrlen;
5063 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005064
Andy Adamsonbf118a32011-12-07 11:55:27 -05005065 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5066 * are stored with the acl data to handle the problem of
5067 * variable length bitmaps.*/
5068 xdr->p = bm_p;
5069 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
5070 res->acl_data_offset <<= 2;
5071
J. Bruce Fields029d1052005-06-22 17:16:22 +00005072 /* We ignore &savep and don't do consistency checks on
5073 * the attr length. Let userspace figure it out.... */
5074 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005075 attrlen += res->acl_data_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005076 recvd = req->rq_rcv_buf.len - hdrlen;
5077 if (attrlen > recvd) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05005078 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5079 /* getxattr interface called with a NULL buf */
5080 res->acl_len = attrlen;
5081 goto out;
5082 }
5083 dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
J. Bruce Fields029d1052005-06-22 17:16:22 +00005084 attrlen, recvd);
5085 return -EINVAL;
5086 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04005087 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05005088 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005089 } else
5090 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005091
5092out:
5093 return status;
5094}
5095
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096static int
5097decode_savefh(struct xdr_stream *xdr)
5098{
5099 return decode_op_hdr(xdr, OP_SAVEFH);
5100}
5101
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005102static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103{
Al Viro8687b632006-10-19 23:28:48 -07005104 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005105 uint32_t bmlen;
5106 int status;
5107
Linus Torvalds1da177e2005-04-16 15:20:36 -07005108 status = decode_op_hdr(xdr, OP_SETATTR);
5109 if (status)
5110 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005111 p = xdr_inline_decode(xdr, 4);
5112 if (unlikely(!p))
5113 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005114 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005115 p = xdr_inline_decode(xdr, bmlen << 2);
5116 if (likely(p))
5117 return 0;
5118out_overflow:
5119 print_overflow_msg(__func__, xdr);
5120 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005121}
5122
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005123static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124{
Al Viro8687b632006-10-19 23:28:48 -07005125 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005126 uint32_t opnum;
5127 int32_t nfserr;
5128
Benny Halevyc0eae662009-08-14 17:20:14 +03005129 p = xdr_inline_decode(xdr, 8);
5130 if (unlikely(!p))
5131 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005132 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005134 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005135 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 return -EIO;
5137 }
Benny Halevycccddf42009-08-14 17:20:19 +03005138 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005140 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5141 if (unlikely(!p))
5142 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005143 p = xdr_decode_hyper(p, &res->clientid);
5144 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145 } else if (nfserr == NFSERR_CLID_INUSE) {
5146 uint32_t len;
5147
5148 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005149 p = xdr_inline_decode(xdr, 4);
5150 if (unlikely(!p))
5151 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005152 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005153 p = xdr_inline_decode(xdr, len);
5154 if (unlikely(!p))
5155 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156
5157 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005158 p = xdr_inline_decode(xdr, 4);
5159 if (unlikely(!p))
5160 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005161 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005162 p = xdr_inline_decode(xdr, len);
5163 if (unlikely(!p))
5164 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165 return -NFSERR_CLID_INUSE;
5166 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005167 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168
5169 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005170out_overflow:
5171 print_overflow_msg(__func__, xdr);
5172 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173}
5174
5175static int decode_setclientid_confirm(struct xdr_stream *xdr)
5176{
5177 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5178}
5179
5180static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5181{
Al Viro8687b632006-10-19 23:28:48 -07005182 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005183 int status;
5184
5185 status = decode_op_hdr(xdr, OP_WRITE);
5186 if (status)
5187 return status;
5188
Benny Halevyc0eae662009-08-14 17:20:14 +03005189 p = xdr_inline_decode(xdr, 16);
5190 if (unlikely(!p))
5191 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005192 res->count = be32_to_cpup(p++);
5193 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03005194 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005196out_overflow:
5197 print_overflow_msg(__func__, xdr);
5198 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199}
5200
5201static int decode_delegreturn(struct xdr_stream *xdr)
5202{
5203 return decode_op_hdr(xdr, OP_DELEGRETURN);
5204}
5205
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005206static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5207{
5208 __be32 *p;
5209
5210 p = xdr_inline_decode(xdr, 4);
5211 if (unlikely(!p))
5212 goto out_overflow;
5213 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5214 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5215 goto out_err;
5216
5217 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5218 if (unlikely(!p))
5219 goto out_overflow;
5220 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5221
5222 p = xdr_inline_decode(xdr, 8);
5223 if (unlikely(!p))
5224 goto out_overflow;
5225 flavor->gss.qop4 = be32_to_cpup(p++);
5226 flavor->gss.service = be32_to_cpup(p);
5227
5228 return 0;
5229
5230out_overflow:
5231 print_overflow_msg(__func__, xdr);
5232 return -EIO;
5233out_err:
5234 return -EINVAL;
5235}
5236
5237static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5238{
5239 struct nfs4_secinfo_flavor *sec_flavor;
5240 int status;
5241 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005242 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005243
5244 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005245 if (status)
5246 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005247 p = xdr_inline_decode(xdr, 4);
5248 if (unlikely(!p))
5249 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005250
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005251 res->flavors->num_flavors = 0;
5252 num_flavors = be32_to_cpup(p);
5253
5254 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005255 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005256 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005257 break;
5258
5259 p = xdr_inline_decode(xdr, 4);
5260 if (unlikely(!p))
5261 goto out_overflow;
5262 sec_flavor->flavor = be32_to_cpup(p);
5263
5264 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005265 status = decode_secinfo_gss(xdr, sec_flavor);
5266 if (status)
5267 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005268 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005269 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005270 }
5271
Bryan Schumaker613e9012011-04-27 15:28:44 -04005272out:
5273 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005274out_overflow:
5275 print_overflow_msg(__func__, xdr);
5276 return -EIO;
5277}
5278
Benny Halevy99fe60d2009-04-01 09:22:29 -04005279#if defined(CONFIG_NFS_V4_1)
5280static int decode_exchange_id(struct xdr_stream *xdr,
5281 struct nfs41_exchange_id_res *res)
5282{
5283 __be32 *p;
5284 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005285 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005286 int status;
5287 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005288 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005289
5290 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5291 if (status)
5292 return status;
5293
Benny Halevyc0eae662009-08-14 17:20:14 +03005294 p = xdr_inline_decode(xdr, 8);
5295 if (unlikely(!p))
5296 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005297 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005298 p = xdr_inline_decode(xdr, 12);
5299 if (unlikely(!p))
5300 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005301 clp->cl_seqid = be32_to_cpup(p++);
5302 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005303
5304 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005305 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005306 if (dummy != SP4_NONE)
5307 return -EIO;
5308
5309 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005310 p = xdr_inline_decode(xdr, 8);
5311 if (unlikely(!p))
5312 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005313
5314 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005315 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5316 if (unlikely(status))
5317 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005318
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005319 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005320 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5321 if (unlikely(status))
5322 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005323
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005324 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5325 return -EIO;
5326
5327 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5328 res->server_scope->server_scope_sz = dummy;
5329
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005330 /* Implementation Id */
5331 p = xdr_inline_decode(xdr, 4);
5332 if (unlikely(!p))
5333 goto out_overflow;
5334 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005335
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005336 if (impl_id_count) {
5337 /* nii_domain */
5338 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5339 if (unlikely(status))
5340 return status;
5341 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5342 return -EIO;
5343 memcpy(res->impl_id->domain, dummy_str, dummy);
5344
5345 /* nii_name */
5346 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5347 if (unlikely(status))
5348 return status;
5349 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5350 return -EIO;
5351 memcpy(res->impl_id->name, dummy_str, dummy);
5352
5353 /* nii_date */
5354 p = xdr_inline_decode(xdr, 12);
5355 if (unlikely(!p))
5356 goto out_overflow;
5357 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5358 res->impl_id->date.nseconds = be32_to_cpup(p);
5359
5360 /* if there's more than one entry, ignore the rest */
5361 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005362 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005363out_overflow:
5364 print_overflow_msg(__func__, xdr);
5365 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005366}
Andy Adamsonfc931582009-04-01 09:22:31 -04005367
5368static int decode_chan_attrs(struct xdr_stream *xdr,
5369 struct nfs4_channel_attrs *attrs)
5370{
5371 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005372 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005373
Benny Halevyc0eae662009-08-14 17:20:14 +03005374 p = xdr_inline_decode(xdr, 28);
5375 if (unlikely(!p))
5376 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005377 val = be32_to_cpup(p++); /* headerpadsz */
5378 if (val)
5379 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005380 attrs->max_rqst_sz = be32_to_cpup(p++);
5381 attrs->max_resp_sz = be32_to_cpup(p++);
5382 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5383 attrs->max_ops = be32_to_cpup(p++);
5384 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005385 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005386 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005387 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5388 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005389 return -EINVAL;
5390 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005391 if (nr_attrs == 1) {
5392 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5393 if (unlikely(!p))
5394 goto out_overflow;
5395 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005396 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005397out_overflow:
5398 print_overflow_msg(__func__, xdr);
5399 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005400}
5401
Benny Halevye78291e2009-08-14 17:20:00 +03005402static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5403{
5404 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005405}
5406
5407static int decode_create_session(struct xdr_stream *xdr,
5408 struct nfs41_create_session_res *res)
5409{
5410 __be32 *p;
5411 int status;
5412 struct nfs_client *clp = res->client;
5413 struct nfs4_session *session = clp->cl_session;
5414
5415 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005416 if (!status)
5417 status = decode_sessionid(xdr, &session->sess_id);
5418 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005419 return status;
5420
Andy Adamsonfc931582009-04-01 09:22:31 -04005421 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005422 p = xdr_inline_decode(xdr, 8);
5423 if (unlikely(!p))
5424 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005425 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005426 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005427
5428 /* Channel attributes */
5429 status = decode_chan_attrs(xdr, &session->fc_attrs);
5430 if (!status)
5431 status = decode_chan_attrs(xdr, &session->bc_attrs);
5432 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005433out_overflow:
5434 print_overflow_msg(__func__, xdr);
5435 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005436}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005437
5438static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5439{
5440 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5441}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005442
5443static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5444{
5445 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5446}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005447#endif /* CONFIG_NFS_V4_1 */
5448
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005449static int decode_sequence(struct xdr_stream *xdr,
5450 struct nfs4_sequence_res *res,
5451 struct rpc_rqst *rqstp)
5452{
5453#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005454 struct nfs4_sessionid id;
5455 u32 dummy;
5456 int status;
5457 __be32 *p;
5458
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005459 if (!res->sr_session)
5460 return 0;
5461
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005462 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005463 if (!status)
5464 status = decode_sessionid(xdr, &id);
5465 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005466 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005467
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005468 /*
5469 * If the server returns different values for sessionID, slotID or
5470 * sequence number, the server is looney tunes.
5471 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005472 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005473
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005474 if (memcmp(id.data, res->sr_session->sess_id.data,
5475 NFS4_MAX_SESSIONID_LEN)) {
5476 dprintk("%s Invalid session id\n", __func__);
5477 goto out_err;
5478 }
Benny Halevye78291e2009-08-14 17:20:00 +03005479
Benny Halevyc0eae662009-08-14 17:20:14 +03005480 p = xdr_inline_decode(xdr, 20);
5481 if (unlikely(!p))
5482 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005483
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005484 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005485 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005486 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005487 dprintk("%s Invalid sequence number\n", __func__);
5488 goto out_err;
5489 }
5490 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005491 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005492 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005493 dprintk("%s Invalid slot id\n", __func__);
5494 goto out_err;
5495 }
5496 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005497 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005498 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005499 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005500 /* result flags */
5501 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005502 status = 0;
5503out_err:
5504 res->sr_status = status;
5505 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005506out_overflow:
5507 print_overflow_msg(__func__, xdr);
5508 status = -EIO;
5509 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005510#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005511 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005512#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005513}
5514
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005515#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005516/*
5517 * TODO: Need to handle case when EOF != true;
5518 */
5519static int decode_getdevicelist(struct xdr_stream *xdr,
5520 struct pnfs_devicelist *res)
5521{
5522 __be32 *p;
5523 int status, i;
5524 struct nfs_writeverf verftemp;
5525
5526 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5527 if (status)
5528 return status;
5529
5530 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5531 if (unlikely(!p))
5532 goto out_overflow;
5533
5534 /* TODO: Skip cookie for now */
5535 p += 2;
5536
5537 /* Read verifier */
5538 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5539
5540 res->num_devs = be32_to_cpup(p);
5541
5542 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5543
5544 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005545 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005546 __func__, res->num_devs);
5547 return -EIO;
5548 }
5549
5550 p = xdr_inline_decode(xdr,
5551 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5552 if (unlikely(!p))
5553 goto out_overflow;
5554 for (i = 0; i < res->num_devs; i++)
5555 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5556 NFS4_DEVICEID4_SIZE);
5557 res->eof = be32_to_cpup(p);
5558 return 0;
5559out_overflow:
5560 print_overflow_msg(__func__, xdr);
5561 return -EIO;
5562}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005563
5564static int decode_getdeviceinfo(struct xdr_stream *xdr,
5565 struct pnfs_device *pdev)
5566{
5567 __be32 *p;
5568 uint32_t len, type;
5569 int status;
5570
5571 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5572 if (status) {
5573 if (status == -ETOOSMALL) {
5574 p = xdr_inline_decode(xdr, 4);
5575 if (unlikely(!p))
5576 goto out_overflow;
5577 pdev->mincount = be32_to_cpup(p);
5578 dprintk("%s: Min count too small. mincnt = %u\n",
5579 __func__, pdev->mincount);
5580 }
5581 return status;
5582 }
5583
5584 p = xdr_inline_decode(xdr, 8);
5585 if (unlikely(!p))
5586 goto out_overflow;
5587 type = be32_to_cpup(p++);
5588 if (type != pdev->layout_type) {
5589 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5590 __func__, pdev->layout_type, type);
5591 return -EINVAL;
5592 }
5593 /*
5594 * Get the length of the opaque device_addr4. xdr_read_pages places
5595 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5596 * and places the remaining xdr data in xdr_buf->tail
5597 */
5598 pdev->mincount = be32_to_cpup(p);
5599 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5600
5601 /* Parse notification bitmap, verifying that it is zero. */
5602 p = xdr_inline_decode(xdr, 4);
5603 if (unlikely(!p))
5604 goto out_overflow;
5605 len = be32_to_cpup(p);
5606 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005607 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005608
5609 p = xdr_inline_decode(xdr, 4 * len);
5610 if (unlikely(!p))
5611 goto out_overflow;
5612 for (i = 0; i < len; i++, p++) {
5613 if (be32_to_cpup(p)) {
5614 dprintk("%s: notifications not supported\n",
5615 __func__);
5616 return -EIO;
5617 }
5618 }
5619 }
5620 return 0;
5621out_overflow:
5622 print_overflow_msg(__func__, xdr);
5623 return -EIO;
5624}
5625
5626static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5627 struct nfs4_layoutget_res *res)
5628{
5629 __be32 *p;
5630 int status;
5631 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005632 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5633 struct kvec *iov = rcvbuf->head;
5634 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005635
5636 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5637 if (status)
5638 return status;
5639 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5640 if (unlikely(!p))
5641 goto out_overflow;
5642 res->return_on_close = be32_to_cpup(p++);
5643 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5644 layout_count = be32_to_cpup(p);
5645 if (!layout_count) {
5646 dprintk("%s: server responded with empty layout array\n",
5647 __func__);
5648 return -EINVAL;
5649 }
5650
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005651 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005652 if (unlikely(!p))
5653 goto out_overflow;
5654 p = xdr_decode_hyper(p, &res->range.offset);
5655 p = xdr_decode_hyper(p, &res->range.length);
5656 res->range.iomode = be32_to_cpup(p++);
5657 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005658 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005659
5660 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5661 __func__,
5662 (unsigned long)res->range.offset,
5663 (unsigned long)res->range.length,
5664 res->range.iomode,
5665 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005666 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005667
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005668 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5669 recvd = req->rq_rcv_buf.len - hdrlen;
5670 if (res->layoutp->len > recvd) {
5671 dprintk("NFS: server cheating in layoutget reply: "
5672 "layout len %u > recvd %u\n",
5673 res->layoutp->len, recvd);
5674 return -EINVAL;
5675 }
5676
5677 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005678
5679 if (layout_count > 1) {
5680 /* We only handle a length one array at the moment. Any
5681 * further entries are just ignored. Note that this means
5682 * the client may see a response that is less than the
5683 * minimum it requested.
5684 */
5685 dprintk("%s: server responded with %d layouts, dropping tail\n",
5686 __func__, layout_count);
5687 }
5688
5689 return 0;
5690out_overflow:
5691 print_overflow_msg(__func__, xdr);
5692 return -EIO;
5693}
Andy Adamson863a3c62011-03-23 13:27:54 +00005694
Benny Halevycbe82602011-05-22 19:52:37 +03005695static int decode_layoutreturn(struct xdr_stream *xdr,
5696 struct nfs4_layoutreturn_res *res)
5697{
5698 __be32 *p;
5699 int status;
5700
5701 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5702 if (status)
5703 return status;
5704 p = xdr_inline_decode(xdr, 4);
5705 if (unlikely(!p))
5706 goto out_overflow;
5707 res->lrs_present = be32_to_cpup(p);
5708 if (res->lrs_present)
5709 status = decode_stateid(xdr, &res->stateid);
5710 return status;
5711out_overflow:
5712 print_overflow_msg(__func__, xdr);
5713 return -EIO;
5714}
5715
Andy Adamson863a3c62011-03-23 13:27:54 +00005716static int decode_layoutcommit(struct xdr_stream *xdr,
5717 struct rpc_rqst *req,
5718 struct nfs4_layoutcommit_res *res)
5719{
5720 __be32 *p;
5721 __u32 sizechanged;
5722 int status;
5723
5724 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005725 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005726 if (status)
5727 return status;
5728
5729 p = xdr_inline_decode(xdr, 4);
5730 if (unlikely(!p))
5731 goto out_overflow;
5732 sizechanged = be32_to_cpup(p);
5733
5734 if (sizechanged) {
5735 /* throw away new size */
5736 p = xdr_inline_decode(xdr, 8);
5737 if (unlikely(!p))
5738 goto out_overflow;
5739 }
5740 return 0;
5741out_overflow:
5742 print_overflow_msg(__func__, xdr);
5743 return -EIO;
5744}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005745
5746static int decode_test_stateid(struct xdr_stream *xdr,
5747 struct nfs41_test_stateid_res *res)
5748{
5749 __be32 *p;
5750 int status;
5751 int num_res;
5752
5753 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5754 if (status)
5755 return status;
5756
5757 p = xdr_inline_decode(xdr, 4);
5758 if (unlikely(!p))
5759 goto out_overflow;
5760 num_res = be32_to_cpup(p++);
5761 if (num_res != 1)
5762 goto out;
5763
5764 p = xdr_inline_decode(xdr, 4);
5765 if (unlikely(!p))
5766 goto out_overflow;
5767 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005768
5769 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005770out_overflow:
5771 print_overflow_msg(__func__, xdr);
5772out:
5773 return -EIO;
5774}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005775
5776static int decode_free_stateid(struct xdr_stream *xdr,
5777 struct nfs41_free_stateid_res *res)
5778{
5779 __be32 *p;
5780 int status;
5781
5782 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5783 if (status)
5784 return status;
5785
5786 p = xdr_inline_decode(xdr, 4);
5787 if (unlikely(!p))
5788 goto out_overflow;
5789 res->status = be32_to_cpup(p++);
5790 return res->status;
5791out_overflow:
5792 print_overflow_msg(__func__, xdr);
5793 return -EIO;
5794}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005795#endif /* CONFIG_NFS_V4_1 */
5796
Linus Torvalds1da177e2005-04-16 15:20:36 -07005797/*
Benny Halevy49c25592008-12-23 16:06:16 -05005798 * END OF "GENERIC" DECODE ROUTINES.
5799 */
5800
5801/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005802 * Decode OPEN_DOWNGRADE response
5803 */
Chuck Leverbf269552010-12-14 14:59:29 +00005804static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5805 struct xdr_stream *xdr,
5806 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005807{
Andy Adamson05d564f2008-12-23 16:06:15 -05005808 struct compound_hdr hdr;
5809 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005810
Chuck Leverbf269552010-12-14 14:59:29 +00005811 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005812 if (status)
5813 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005814 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005815 if (status)
5816 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005817 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005818 if (status)
5819 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005820 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005821 if (status != 0)
5822 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005823 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005825 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005826}
5827
5828/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829 * Decode ACCESS response
5830 */
Chuck Leverbf269552010-12-14 14:59:29 +00005831static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5832 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005833{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834 struct compound_hdr hdr;
5835 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005836
Chuck Leverbf269552010-12-14 14:59:29 +00005837 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005838 if (status)
5839 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005840 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005841 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005843 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005844 if (status != 0)
5845 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005846 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005847 if (status != 0)
5848 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005849 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850out:
5851 return status;
5852}
5853
5854/*
5855 * Decode LOOKUP response
5856 */
Chuck Leverbf269552010-12-14 14:59:29 +00005857static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5858 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005860 struct compound_hdr hdr;
5861 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005862
Chuck Leverbf269552010-12-14 14:59:29 +00005863 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005864 if (status)
5865 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005866 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005867 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005869 status = decode_putfh(xdr);
5870 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005871 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005872 status = decode_lookup(xdr);
5873 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005874 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005875 status = decode_getfh(xdr, res->fh);
5876 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005878 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879out:
5880 return status;
5881}
5882
5883/*
5884 * Decode LOOKUP_ROOT response
5885 */
Chuck Leverbf269552010-12-14 14:59:29 +00005886static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5887 struct xdr_stream *xdr,
5888 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005889{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005890 struct compound_hdr hdr;
5891 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005892
Chuck Leverbf269552010-12-14 14:59:29 +00005893 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005894 if (status)
5895 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005896 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005897 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005898 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005899 status = decode_putrootfh(xdr);
5900 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005901 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005902 status = decode_getfh(xdr, res->fh);
5903 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005904 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905out:
5906 return status;
5907}
5908
5909/*
5910 * Decode REMOVE response
5911 */
Chuck Leverbf269552010-12-14 14:59:29 +00005912static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5913 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005914{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005915 struct compound_hdr hdr;
5916 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005917
Chuck Leverbf269552010-12-14 14:59:29 +00005918 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005919 if (status)
5920 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005921 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005922 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005923 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005924 status = decode_putfh(xdr);
5925 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005926 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005927 status = decode_remove(xdr, &res->cinfo);
5928 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005929 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005930 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931out:
5932 return status;
5933}
5934
5935/*
5936 * Decode RENAME response
5937 */
Chuck Leverbf269552010-12-14 14:59:29 +00005938static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5939 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005941 struct compound_hdr hdr;
5942 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005943
Chuck Leverbf269552010-12-14 14:59:29 +00005944 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005945 if (status)
5946 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005947 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005948 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005950 status = decode_putfh(xdr);
5951 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005952 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005953 status = decode_savefh(xdr);
5954 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005955 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005956 status = decode_putfh(xdr);
5957 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005958 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005959 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5960 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005961 goto out;
5962 /* Current FH is target directory */
Trond Myklebust6926afd2012-01-07 13:22:46 -05005963 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005964 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005965 status = decode_restorefh(xdr);
5966 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005967 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005968 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969out:
5970 return status;
5971}
5972
5973/*
5974 * Decode LINK response
5975 */
Chuck Leverbf269552010-12-14 14:59:29 +00005976static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5977 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005978{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979 struct compound_hdr hdr;
5980 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005981
Chuck Leverbf269552010-12-14 14:59:29 +00005982 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005983 if (status)
5984 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005985 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005986 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005988 status = decode_putfh(xdr);
5989 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005990 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005991 status = decode_savefh(xdr);
5992 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005993 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005994 status = decode_putfh(xdr);
5995 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005996 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005997 status = decode_link(xdr, &res->cinfo);
5998 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005999 goto out;
6000 /*
6001 * Note order: OP_LINK leaves the directory as the current
6002 * filehandle.
6003 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006004 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006005 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006006 status = decode_restorefh(xdr);
6007 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006008 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006009 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010out:
6011 return status;
6012}
6013
6014/*
6015 * Decode CREATE response
6016 */
Chuck Leverbf269552010-12-14 14:59:29 +00006017static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6018 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020 struct compound_hdr hdr;
6021 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006022
Chuck Leverbf269552010-12-14 14:59:29 +00006023 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006024 if (status)
6025 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006026 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006027 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006028 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006029 status = decode_putfh(xdr);
6030 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006031 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006032 status = decode_savefh(xdr);
6033 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006034 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006035 status = decode_create(xdr, &res->dir_cinfo);
6036 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006038 status = decode_getfh(xdr, res->fh);
6039 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006040 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006041 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006042 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006043 status = decode_restorefh(xdr);
6044 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006045 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006046 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047out:
6048 return status;
6049}
6050
6051/*
6052 * Decode SYMLINK response
6053 */
Chuck Leverbf269552010-12-14 14:59:29 +00006054static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6055 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056{
Chuck Leverbf269552010-12-14 14:59:29 +00006057 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058}
6059
6060/*
6061 * Decode GETATTR response
6062 */
Chuck Leverbf269552010-12-14 14:59:29 +00006063static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6064 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006066 struct compound_hdr hdr;
6067 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006068
Chuck Leverbf269552010-12-14 14:59:29 +00006069 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 if (status)
6071 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006072 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006073 if (status)
6074 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006075 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006076 if (status)
6077 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006078 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079out:
6080 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081}
6082
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006083/*
6084 * Encode an SETACL request
6085 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006086static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6087 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006088{
Andy Adamson05d564f2008-12-23 16:06:15 -05006089 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006090 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006091 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006092
Chuck Lever9f06c712010-12-14 14:59:18 +00006093 encode_compound_hdr(xdr, req, &hdr);
6094 encode_sequence(xdr, &args->seq_args, &hdr);
6095 encode_putfh(xdr, args->fh, &hdr);
6096 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006097 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006098}
Andy Adamson05d564f2008-12-23 16:06:15 -05006099
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006100/*
6101 * Decode SETACL response
6102 */
6103static int
Chuck Leverbf269552010-12-14 14:59:29 +00006104nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006105 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006106{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006107 struct compound_hdr hdr;
6108 int status;
6109
Chuck Leverbf269552010-12-14 14:59:29 +00006110 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006111 if (status)
6112 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006113 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006114 if (status)
6115 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006116 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006117 if (status)
6118 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006119 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006120out:
6121 return status;
6122}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123
6124/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006125 * Decode GETACL response
6126 */
6127static int
Chuck Leverbf269552010-12-14 14:59:29 +00006128nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006129 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006130{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006131 struct compound_hdr hdr;
6132 int status;
6133
Trond Myklebust331818f2012-02-03 18:30:53 -05006134 if (res->acl_scratch != NULL) {
6135 void *p = page_address(res->acl_scratch);
6136 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6137 }
Chuck Leverbf269552010-12-14 14:59:29 +00006138 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006139 if (status)
6140 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006141 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006142 if (status)
6143 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006144 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006145 if (status)
6146 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006147 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006148
6149out:
6150 return status;
6151}
6152
6153/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006154 * Decode CLOSE response
6155 */
Chuck Leverbf269552010-12-14 14:59:29 +00006156static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6157 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158{
Andy Adamson05d564f2008-12-23 16:06:15 -05006159 struct compound_hdr hdr;
6160 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161
Chuck Leverbf269552010-12-14 14:59:29 +00006162 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006163 if (status)
6164 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006166 if (status)
6167 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006168 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006169 if (status)
6170 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006171 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006172 if (status != 0)
6173 goto out;
6174 /*
6175 * Note: Server may do delete on close for this file
6176 * in which case the getattr call will fail with
6177 * an ESTALE error. Shouldn't be a problem,
6178 * though, since fattr->valid will remain unset.
6179 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006180 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006182 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183}
6184
6185/*
6186 * Decode OPEN response
6187 */
Chuck Leverbf269552010-12-14 14:59:29 +00006188static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6189 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190{
Andy Adamson05d564f2008-12-23 16:06:15 -05006191 struct compound_hdr hdr;
6192 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193
Chuck Leverbf269552010-12-14 14:59:29 +00006194 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006195 if (status)
6196 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006197 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006198 if (status)
6199 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006200 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006201 if (status)
6202 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006203 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006204 if (status)
6205 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006206 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006207 if (status)
6208 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006209 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006211 if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006212 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006213 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006214 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006215 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006217 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218}
6219
6220/*
6221 * Decode OPEN_CONFIRM response
6222 */
Chuck Leverbf269552010-12-14 14:59:29 +00006223static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6224 struct xdr_stream *xdr,
6225 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226{
Andy Adamson05d564f2008-12-23 16:06:15 -05006227 struct compound_hdr hdr;
6228 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229
Chuck Leverbf269552010-12-14 14:59:29 +00006230 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006231 if (status)
6232 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006233 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006234 if (status)
6235 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006236 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006238 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239}
6240
6241/*
6242 * Decode OPEN response
6243 */
Chuck Leverbf269552010-12-14 14:59:29 +00006244static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6245 struct xdr_stream *xdr,
6246 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006247{
Andy Adamson05d564f2008-12-23 16:06:15 -05006248 struct compound_hdr hdr;
6249 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250
Chuck Leverbf269552010-12-14 14:59:29 +00006251 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006252 if (status)
6253 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006254 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006255 if (status)
6256 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006257 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006258 if (status)
6259 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006260 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006261 if (status)
6262 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006263 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006264out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006265 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266}
6267
6268/*
6269 * Decode SETATTR response
6270 */
Chuck Leverbf269552010-12-14 14:59:29 +00006271static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6272 struct xdr_stream *xdr,
6273 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006274{
Andy Adamson05d564f2008-12-23 16:06:15 -05006275 struct compound_hdr hdr;
6276 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277
Chuck Leverbf269552010-12-14 14:59:29 +00006278 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006279 if (status)
6280 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006281 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006282 if (status)
6283 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006285 if (status)
6286 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006287 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006288 if (status)
6289 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006290 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006291out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006292 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006293}
6294
6295/*
6296 * Decode LOCK response
6297 */
Chuck Leverbf269552010-12-14 14:59:29 +00006298static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6299 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006301 struct compound_hdr hdr;
6302 int status;
6303
Chuck Leverbf269552010-12-14 14:59:29 +00006304 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305 if (status)
6306 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006308 if (status)
6309 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311 if (status)
6312 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006314out:
6315 return status;
6316}
6317
6318/*
6319 * Decode LOCKT response
6320 */
Chuck Leverbf269552010-12-14 14:59:29 +00006321static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6322 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 struct compound_hdr hdr;
6325 int status;
6326
Chuck Leverbf269552010-12-14 14:59:29 +00006327 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328 if (status)
6329 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006330 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006331 if (status)
6332 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006333 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334 if (status)
6335 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006336 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337out:
6338 return status;
6339}
6340
6341/*
6342 * Decode LOCKU response
6343 */
Chuck Leverbf269552010-12-14 14:59:29 +00006344static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6345 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006346{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006347 struct compound_hdr hdr;
6348 int status;
6349
Chuck Leverbf269552010-12-14 14:59:29 +00006350 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006351 if (status)
6352 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006353 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006354 if (status)
6355 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006356 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357 if (status)
6358 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006359 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006360out:
6361 return status;
6362}
6363
Chuck Leverbf269552010-12-14 14:59:29 +00006364static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6365 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006366{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006367 struct compound_hdr hdr;
6368 int status;
6369
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006371 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006372 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006373 return status;
6374}
6375
Linus Torvalds1da177e2005-04-16 15:20:36 -07006376/*
6377 * Decode READLINK response
6378 */
Chuck Leverbf269552010-12-14 14:59:29 +00006379static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6380 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006381 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006382{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006383 struct compound_hdr hdr;
6384 int status;
6385
Chuck Leverbf269552010-12-14 14:59:29 +00006386 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387 if (status)
6388 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006389 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006390 if (status)
6391 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006392 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006393 if (status)
6394 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006395 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396out:
6397 return status;
6398}
6399
6400/*
6401 * Decode READDIR response
6402 */
Chuck Leverbf269552010-12-14 14:59:29 +00006403static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6404 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406 struct compound_hdr hdr;
6407 int status;
6408
Chuck Leverbf269552010-12-14 14:59:29 +00006409 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410 if (status)
6411 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006412 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006413 if (status)
6414 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006415 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416 if (status)
6417 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006418 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006419out:
6420 return status;
6421}
6422
6423/*
6424 * Decode Read response
6425 */
Chuck Leverbf269552010-12-14 14:59:29 +00006426static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6427 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006428{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429 struct compound_hdr hdr;
6430 int status;
6431
Chuck Leverbf269552010-12-14 14:59:29 +00006432 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433 if (status)
6434 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006435 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006436 if (status)
6437 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006438 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439 if (status)
6440 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006441 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442 if (!status)
6443 status = res->count;
6444out:
6445 return status;
6446}
6447
6448/*
6449 * Decode WRITE response
6450 */
Chuck Leverbf269552010-12-14 14:59:29 +00006451static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6452 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 struct compound_hdr hdr;
6455 int status;
6456
Chuck Leverbf269552010-12-14 14:59:29 +00006457 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458 if (status)
6459 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006460 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006461 if (status)
6462 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006463 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464 if (status)
6465 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006466 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006467 if (status)
6468 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006469 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006470 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 if (!status)
6472 status = res->count;
6473out:
6474 return status;
6475}
6476
6477/*
6478 * Decode COMMIT response
6479 */
Chuck Leverbf269552010-12-14 14:59:29 +00006480static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6481 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483 struct compound_hdr hdr;
6484 int status;
6485
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487 if (status)
6488 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006489 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006490 if (status)
6491 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493 if (status)
6494 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006495 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006496 if (status)
6497 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006498 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006499 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006500out:
6501 return status;
6502}
6503
6504/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006505 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506 */
Chuck Leverbf269552010-12-14 14:59:29 +00006507static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006508 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006509{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510 struct compound_hdr hdr;
6511 int status;
6512
Chuck Leverbf269552010-12-14 14:59:29 +00006513 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006514 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006515 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006516 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006517 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006519 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520 return status;
6521}
6522
6523/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006524 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525 */
Chuck Leverbf269552010-12-14 14:59:29 +00006526static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006527 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006528{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 struct compound_hdr hdr;
6530 int status;
6531
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006534 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006535 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006536 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006538 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539 return status;
6540}
6541
6542/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006543 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544 */
Chuck Leverbf269552010-12-14 14:59:29 +00006545static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006546 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 struct compound_hdr hdr;
6549 int status;
6550
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006553 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006554 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006557 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006558 return status;
6559}
6560
6561/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006562 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006563 */
Chuck Leverbf269552010-12-14 14:59:29 +00006564static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6565 struct xdr_stream *xdr,
6566 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568 struct compound_hdr hdr;
6569 int status;
6570
Chuck Leverbf269552010-12-14 14:59:29 +00006571 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006572 if (status)
6573 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006574 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006575 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006576 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006577 status = decode_putfh(xdr);
6578 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006581out:
6582 return status;
6583}
6584
6585/*
6586 * Decode RENEW response
6587 */
Chuck Leverbf269552010-12-14 14:59:29 +00006588static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6589 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006591 struct compound_hdr hdr;
6592 int status;
6593
Chuck Leverbf269552010-12-14 14:59:29 +00006594 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006596 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597 return status;
6598}
6599
6600/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006601 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006602 */
Chuck Leverbf269552010-12-14 14:59:29 +00006603static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6604 struct xdr_stream *xdr,
6605 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607 struct compound_hdr hdr;
6608 int status;
6609
Chuck Leverbf269552010-12-14 14:59:29 +00006610 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006612 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613 return status;
6614}
6615
6616/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006617 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006618 */
Chuck Leverbf269552010-12-14 14:59:29 +00006619static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6620 struct xdr_stream *xdr,
6621 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006623 struct compound_hdr hdr;
6624 int status;
6625
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006628 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006630 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006632 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633 return status;
6634}
6635
6636/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006637 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638 */
Chuck Leverbf269552010-12-14 14:59:29 +00006639static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6640 struct xdr_stream *xdr,
6641 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643 struct compound_hdr hdr;
6644 int status;
6645
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006647 if (status)
6648 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006649 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006650 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006651 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006652 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006653 if (status != 0)
6654 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006655 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006656 if (status != 0)
6657 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006658 decode_getfattr(xdr, res->fattr, res->server);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006659out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660 return status;
6661}
6662
Trond Myklebust683b57b2006-06-09 09:34:22 -04006663/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006664 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006665 */
Chuck Leverbf269552010-12-14 14:59:29 +00006666static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6667 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006668 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006669{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006670 struct compound_hdr hdr;
6671 int status;
6672
Chuck Leverbf269552010-12-14 14:59:29 +00006673 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006674 if (status)
6675 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006676 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006677 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006678 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006679 status = decode_putfh(xdr);
6680 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006681 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006682 status = decode_lookup(xdr);
6683 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006684 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006685 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006686 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6687 NULL, res->fs_locations,
6688 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006689out:
6690 return status;
6691}
6692
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006693/*
6694 * Decode SECINFO response
6695 */
6696static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6697 struct xdr_stream *xdr,
6698 struct nfs4_secinfo_res *res)
6699{
6700 struct compound_hdr hdr;
6701 int status;
6702
6703 status = decode_compound_hdr(xdr, &hdr);
6704 if (status)
6705 goto out;
6706 status = decode_sequence(xdr, &res->seq_res, rqstp);
6707 if (status)
6708 goto out;
6709 status = decode_putfh(xdr);
6710 if (status)
6711 goto out;
6712 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006713out:
6714 return status;
6715}
6716
Benny Halevy99fe60d2009-04-01 09:22:29 -04006717#if defined(CONFIG_NFS_V4_1)
6718/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006719 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006720 */
Chuck Leverbf269552010-12-14 14:59:29 +00006721static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6722 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006723 void *res)
6724{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006725 struct compound_hdr hdr;
6726 int status;
6727
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006729 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006730 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006731 return status;
6732}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006733
6734/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006735 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006736 */
Chuck Leverbf269552010-12-14 14:59:29 +00006737static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6738 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006739 struct nfs41_create_session_res *res)
6740{
Andy Adamsonfc931582009-04-01 09:22:31 -04006741 struct compound_hdr hdr;
6742 int status;
6743
Chuck Leverbf269552010-12-14 14:59:29 +00006744 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006745 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006746 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006747 return status;
6748}
6749
6750/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006751 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006752 */
Chuck Leverbf269552010-12-14 14:59:29 +00006753static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6754 struct xdr_stream *xdr,
6755 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006756{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006757 struct compound_hdr hdr;
6758 int status;
6759
Chuck Leverbf269552010-12-14 14:59:29 +00006760 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006761 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006762 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006763 return status;
6764}
6765
6766/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006767 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006768 */
Chuck Leverbf269552010-12-14 14:59:29 +00006769static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6770 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006771 struct nfs4_sequence_res *res)
6772{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006773 struct compound_hdr hdr;
6774 int status;
6775
Chuck Leverbf269552010-12-14 14:59:29 +00006776 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006777 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006778 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006779 return status;
6780}
6781
6782/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006783 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006784 */
Chuck Leverbf269552010-12-14 14:59:29 +00006785static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6786 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006787 struct nfs4_get_lease_time_res *res)
6788{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006789 struct compound_hdr hdr;
6790 int status;
6791
Chuck Leverbf269552010-12-14 14:59:29 +00006792 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006793 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006794 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006795 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006796 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006797 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006798 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006799 return status;
6800}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006801
6802/*
6803 * Decode RECLAIM_COMPLETE response
6804 */
Chuck Leverbf269552010-12-14 14:59:29 +00006805static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6806 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006807 struct nfs41_reclaim_complete_res *res)
6808{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006809 struct compound_hdr hdr;
6810 int status;
6811
Chuck Leverbf269552010-12-14 14:59:29 +00006812 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006813 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006814 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006815 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006816 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006817 return status;
6818}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006819
6820/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006821 * Decode GETDEVICELIST response
6822 */
6823static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6824 struct xdr_stream *xdr,
6825 struct nfs4_getdevicelist_res *res)
6826{
6827 struct compound_hdr hdr;
6828 int status;
6829
6830 dprintk("encoding getdevicelist!\n");
6831
6832 status = decode_compound_hdr(xdr, &hdr);
6833 if (status != 0)
6834 goto out;
6835 status = decode_sequence(xdr, &res->seq_res, rqstp);
6836 if (status != 0)
6837 goto out;
6838 status = decode_putfh(xdr);
6839 if (status != 0)
6840 goto out;
6841 status = decode_getdevicelist(xdr, res->devlist);
6842out:
6843 return status;
6844}
6845
6846/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006847 * Decode GETDEVINFO response
6848 */
Chuck Leverbf269552010-12-14 14:59:29 +00006849static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6850 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006851 struct nfs4_getdeviceinfo_res *res)
6852{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006853 struct compound_hdr hdr;
6854 int status;
6855
Chuck Leverbf269552010-12-14 14:59:29 +00006856 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006857 if (status != 0)
6858 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006859 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006860 if (status != 0)
6861 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006862 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006863out:
6864 return status;
6865}
6866
6867/*
6868 * Decode LAYOUTGET response
6869 */
Chuck Leverbf269552010-12-14 14:59:29 +00006870static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6871 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006872 struct nfs4_layoutget_res *res)
6873{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006874 struct compound_hdr hdr;
6875 int status;
6876
Chuck Leverbf269552010-12-14 14:59:29 +00006877 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006878 if (status)
6879 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006880 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006881 if (status)
6882 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006883 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006884 if (status)
6885 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006886 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006887out:
6888 return status;
6889}
Andy Adamson863a3c62011-03-23 13:27:54 +00006890
6891/*
Benny Halevycbe82602011-05-22 19:52:37 +03006892 * Decode LAYOUTRETURN response
6893 */
6894static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6895 struct xdr_stream *xdr,
6896 struct nfs4_layoutreturn_res *res)
6897{
6898 struct compound_hdr hdr;
6899 int status;
6900
6901 status = decode_compound_hdr(xdr, &hdr);
6902 if (status)
6903 goto out;
6904 status = decode_sequence(xdr, &res->seq_res, rqstp);
6905 if (status)
6906 goto out;
6907 status = decode_putfh(xdr);
6908 if (status)
6909 goto out;
6910 status = decode_layoutreturn(xdr, res);
6911out:
6912 return status;
6913}
6914
6915/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006916 * Decode LAYOUTCOMMIT response
6917 */
6918static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6919 struct xdr_stream *xdr,
6920 struct nfs4_layoutcommit_res *res)
6921{
6922 struct compound_hdr hdr;
6923 int status;
6924
6925 status = decode_compound_hdr(xdr, &hdr);
6926 if (status)
6927 goto out;
6928 status = decode_sequence(xdr, &res->seq_res, rqstp);
6929 if (status)
6930 goto out;
6931 status = decode_putfh(xdr);
6932 if (status)
6933 goto out;
6934 status = decode_layoutcommit(xdr, rqstp, res);
6935 if (status)
6936 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006937 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006938out:
6939 return status;
6940}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006941
6942/*
6943 * Decode SECINFO_NO_NAME response
6944 */
6945static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6946 struct xdr_stream *xdr,
6947 struct nfs4_secinfo_res *res)
6948{
6949 struct compound_hdr hdr;
6950 int status;
6951
6952 status = decode_compound_hdr(xdr, &hdr);
6953 if (status)
6954 goto out;
6955 status = decode_sequence(xdr, &res->seq_res, rqstp);
6956 if (status)
6957 goto out;
6958 status = decode_putrootfh(xdr);
6959 if (status)
6960 goto out;
6961 status = decode_secinfo(xdr, res);
6962out:
6963 return status;
6964}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006965
6966/*
6967 * Decode TEST_STATEID response
6968 */
6969static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6970 struct xdr_stream *xdr,
6971 struct nfs41_test_stateid_res *res)
6972{
6973 struct compound_hdr hdr;
6974 int status;
6975
6976 status = decode_compound_hdr(xdr, &hdr);
6977 if (status)
6978 goto out;
6979 status = decode_sequence(xdr, &res->seq_res, rqstp);
6980 if (status)
6981 goto out;
6982 status = decode_test_stateid(xdr, res);
6983out:
6984 return status;
6985}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006986
6987/*
6988 * Decode FREE_STATEID response
6989 */
6990static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6991 struct xdr_stream *xdr,
6992 struct nfs41_free_stateid_res *res)
6993{
6994 struct compound_hdr hdr;
6995 int status;
6996
6997 status = decode_compound_hdr(xdr, &hdr);
6998 if (status)
6999 goto out;
7000 status = decode_sequence(xdr, &res->seq_res, rqstp);
7001 if (status)
7002 goto out;
7003 status = decode_free_stateid(xdr, res);
7004out:
7005 return status;
7006}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007007#endif /* CONFIG_NFS_V4_1 */
7008
Chuck Lever573c4e12010-12-14 14:58:11 +00007009/**
7010 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7011 * the local page cache.
7012 * @xdr: XDR stream where entry resides
7013 * @entry: buffer to fill in with entry data
7014 * @plus: boolean indicating whether this should be a readdirplus entry
7015 *
7016 * Returns zero if successful, otherwise a negative errno value is
7017 * returned.
7018 *
7019 * This function is not invoked during READDIR reply decoding, but
7020 * rather whenever an application invokes the getdents(2) system call
7021 * on a directory already in our cache.
7022 */
7023int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7024 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007025{
Fred Isamandae100c2011-07-30 20:52:37 -04007026 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007027 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007028 __be32 *p = xdr_inline_decode(xdr, 4);
7029 if (unlikely(!p))
7030 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007031 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007032 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)
Chuck Lever573c4e12010-12-14 14:58:11 +00007036 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007037 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007038 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007039 }
7040
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007041 p = xdr_inline_decode(xdr, 12);
7042 if (unlikely(!p))
7043 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007044 entry->prev_cookie = entry->cookie;
7045 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007046 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007047
Trond Myklebust9af8c222010-10-24 11:52:55 -04007048 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007049 if (unlikely(!p))
7050 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007051 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007052
7053 /*
7054 * In case the server doesn't return an inode number,
7055 * we fake one here. (We don't use inode number 0,
7056 * since glibc seems to choke on it...)
7057 */
7058 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007059 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007060
Trond Myklebust9af8c222010-10-24 11:52:55 -04007061 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007062 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007063
7064 if (decode_attr_length(xdr, &len, &p) < 0)
7065 goto out_overflow;
7066
Chuck Lever573c4e12010-12-14 14:58:11 +00007067 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007068 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007069 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007070 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7071 entry->ino = entry->fattr->mounted_on_fileid;
7072 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007073 entry->ino = entry->fattr->fileid;
7074
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007075 entry->d_type = DT_UNKNOWN;
7076 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7077 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7078
Chuck Lever573c4e12010-12-14 14:58:11 +00007079 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007080
7081out_overflow:
7082 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007083 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007084}
7085
7086/*
7087 * We need to translate between nfs status return values and
7088 * the local errno values which may not be the same.
7089 */
7090static struct {
7091 int stat;
7092 int errno;
7093} nfs_errtbl[] = {
7094 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007095 { NFS4ERR_PERM, -EPERM },
7096 { NFS4ERR_NOENT, -ENOENT },
7097 { NFS4ERR_IO, -errno_NFSERR_IO},
7098 { NFS4ERR_NXIO, -ENXIO },
7099 { NFS4ERR_ACCESS, -EACCES },
7100 { NFS4ERR_EXIST, -EEXIST },
7101 { NFS4ERR_XDEV, -EXDEV },
7102 { NFS4ERR_NOTDIR, -ENOTDIR },
7103 { NFS4ERR_ISDIR, -EISDIR },
7104 { NFS4ERR_INVAL, -EINVAL },
7105 { NFS4ERR_FBIG, -EFBIG },
7106 { NFS4ERR_NOSPC, -ENOSPC },
7107 { NFS4ERR_ROFS, -EROFS },
7108 { NFS4ERR_MLINK, -EMLINK },
7109 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7110 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7111 { NFS4ERR_DQUOT, -EDQUOT },
7112 { NFS4ERR_STALE, -ESTALE },
7113 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007114 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7115 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7116 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007117 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007118 { NFS4ERR_BADTYPE, -EBADTYPE },
7119 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007120 { NFS4ERR_SYMLINK, -ELOOP },
7121 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7122 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007123 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007124};
7125
7126/*
7127 * Convert an NFS error code to a local one.
7128 * This one is used jointly by NFSv2 and NFSv3.
7129 */
7130static int
David Howells0a8ea432006-08-22 20:06:08 -04007131nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007132{
7133 int i;
7134 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7135 if (nfs_errtbl[i].stat == stat)
7136 return nfs_errtbl[i].errno;
7137 }
7138 if (stat <= 10000 || stat > 10100) {
7139 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007140 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007141 }
7142 /* If we cannot translate the error, the recovery routines should
7143 * handle it.
7144 * Note: remaining NFSv4 error codes have values > 10000, so should
7145 * not conflict with native Linux error codes.
7146 */
Benny Halevy856dff32008-03-31 17:39:06 +03007147 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007148}
7149
Linus Torvalds1da177e2005-04-16 15:20:36 -07007150#define PROC(proc, argtype, restype) \
7151[NFSPROC4_CLNT_##proc] = { \
7152 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007153 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007154 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007155 .p_arglen = NFS4_##argtype##_sz, \
7156 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007157 .p_statidx = NFSPROC4_CLNT_##proc, \
7158 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007159}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007160
7161struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007162 PROC(READ, enc_read, dec_read),
7163 PROC(WRITE, enc_write, dec_write),
7164 PROC(COMMIT, enc_commit, dec_commit),
7165 PROC(OPEN, enc_open, dec_open),
7166 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7167 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7168 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7169 PROC(CLOSE, enc_close, dec_close),
7170 PROC(SETATTR, enc_setattr, dec_setattr),
7171 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7172 PROC(RENEW, enc_renew, dec_renew),
7173 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7174 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7175 PROC(LOCK, enc_lock, dec_lock),
7176 PROC(LOCKT, enc_lockt, dec_lockt),
7177 PROC(LOCKU, enc_locku, dec_locku),
7178 PROC(ACCESS, enc_access, dec_access),
7179 PROC(GETATTR, enc_getattr, dec_getattr),
7180 PROC(LOOKUP, enc_lookup, dec_lookup),
7181 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7182 PROC(REMOVE, enc_remove, dec_remove),
7183 PROC(RENAME, enc_rename, dec_rename),
7184 PROC(LINK, enc_link, dec_link),
7185 PROC(SYMLINK, enc_symlink, dec_symlink),
7186 PROC(CREATE, enc_create, dec_create),
7187 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7188 PROC(STATFS, enc_statfs, dec_statfs),
7189 PROC(READLINK, enc_readlink, dec_readlink),
7190 PROC(READDIR, enc_readdir, dec_readdir),
7191 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7192 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7193 PROC(GETACL, enc_getacl, dec_getacl),
7194 PROC(SETACL, enc_setacl, dec_setacl),
7195 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7196 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007197 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007198#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007199 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7200 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7201 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7202 PROC(SEQUENCE, enc_sequence, dec_sequence),
7203 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7204 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7205 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7206 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007207 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007208 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007209 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007210 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007211 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007212 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007213#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007214};
7215
Trond Myklebusta613fa12012-01-20 13:53:56 -05007216const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007217 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007218 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007219 .procs = nfs4_procedures
7220};
7221
7222/*
7223 * Local variables:
7224 * c-basic-offset: 8
7225 * End:
7226 */