blob: c03ba77679ad124b271614518f2d5d7fb848609d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040058#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#define NFSDBG_FACILITY NFSDBG_XDR
61
62/* Mapping from NFS error code to "errno" error code. */
63#define errno_NFSERR_IO EIO
64
David Howells0a8ea432006-08-22 20:06:08 -040065static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
68#ifdef DEBUG
69#define NFS4_MAXTAGLEN 20
70#else
71#define NFS4_MAXTAGLEN 0
72#endif
73
Andy Adamson6c0195a2008-12-23 16:06:15 -050074/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040075 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 */
Trond Myklebustd035c362010-12-21 10:45:27 -050077#define open_owner_id_maxsz (1 + 1 + 4)
78#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040079#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
81#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
82#define op_encode_hdr_maxsz (1)
83#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040084#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
85#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
86#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
87#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
89 (NFS4_FHSIZE >> 2))
90#define decode_putfh_maxsz (op_decode_hdr_maxsz)
91#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
92#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
93#define encode_getfh_maxsz (op_encode_hdr_maxsz)
94#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
95 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040096#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000097#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
99#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
101#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102/* This is based on getfattr, which uses the most attributes: */
103#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000105#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
106 nfs4_fattr_value_maxsz)
107#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400108#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
109 1 + 2 + 1 + \
110 nfs4_owner_maxsz + \
111 nfs4_group_maxsz + \
112 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define encode_savefh_maxsz (op_encode_hdr_maxsz)
114#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400115#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
116#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200117#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400118/* The 5 accounts for the PNFS attributes, and assumes that at most three
119 * layout types will be returned.
120 */
121#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
122 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
124#define decode_renew_maxsz (op_decode_hdr_maxsz)
125#define encode_setclientid_maxsz \
126 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500127 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
128 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
129 1 /* sc_prog */ + \
130 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
131 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
132 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define decode_setclientid_maxsz \
134 (op_decode_hdr_maxsz + \
135 2 + \
136 1024) /* large value for CLID_INUSE */
137#define encode_setclientid_confirm_maxsz \
138 (op_encode_hdr_maxsz + \
139 3 + (NFS4_VERIFIER_SIZE >> 2))
140#define decode_setclientid_confirm_maxsz \
141 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400142#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
143#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400144#define encode_share_access_maxsz \
145 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500146#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400147#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
148#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
149#define encode_open_maxsz (op_encode_hdr_maxsz + \
150 2 + encode_share_access_maxsz + 2 + \
151 open_owner_id_maxsz + \
152 encode_opentype_maxsz + \
153 encode_claim_null_maxsz)
154#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400156 decode_ace_maxsz)
157#define decode_change_info_maxsz (5)
158#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400159 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400160 decode_change_info_maxsz + 1 + \
161 nfs4_fattr_bitmap_maxsz + \
162 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400163#define encode_open_confirm_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1)
166#define decode_open_confirm_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_open_downgrade_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1 + \
172 encode_share_access_maxsz)
173#define decode_open_downgrade_maxsz \
174 (op_decode_hdr_maxsz + \
175 decode_stateid_maxsz)
176#define encode_close_maxsz (op_encode_hdr_maxsz + \
177 1 + encode_stateid_maxsz)
178#define decode_close_maxsz (op_decode_hdr_maxsz + \
179 decode_stateid_maxsz)
180#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
181 encode_stateid_maxsz + \
182 encode_attrs_maxsz)
183#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
184 nfs4_fattr_bitmap_maxsz)
185#define encode_read_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + 3)
187#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
188#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
189 2 + encode_verifier_maxsz + 5)
190#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
191 decode_verifier_maxsz)
192#define encode_readlink_maxsz (op_encode_hdr_maxsz)
193#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
194#define encode_write_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 4)
196#define decode_write_maxsz (op_decode_hdr_maxsz + \
197 2 + decode_verifier_maxsz)
198#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
199#define decode_commit_maxsz (op_decode_hdr_maxsz + \
200 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201#define encode_remove_maxsz (op_encode_hdr_maxsz + \
202 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400203#define decode_remove_maxsz (op_decode_hdr_maxsz + \
204 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#define encode_rename_maxsz (op_encode_hdr_maxsz + \
206 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400207#define decode_rename_maxsz (op_decode_hdr_maxsz + \
208 decode_change_info_maxsz + \
209 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define encode_link_maxsz (op_encode_hdr_maxsz + \
211 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400212#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400213#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400214#define encode_lock_maxsz (op_encode_hdr_maxsz + \
215 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216 1 + encode_stateid_maxsz + 1 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lock_denied_maxsz \
219 (8 + decode_lockowner_maxsz)
220#define decode_lock_maxsz (op_decode_hdr_maxsz + \
221 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400222#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
223 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
225 decode_lock_denied_maxsz)
226#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
227 encode_stateid_maxsz + \
228 4)
229#define decode_locku_maxsz (op_decode_hdr_maxsz + \
230 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400231#define encode_release_lockowner_maxsz \
232 (op_encode_hdr_maxsz + \
233 encode_lockowner_maxsz)
234#define decode_release_lockowner_maxsz \
235 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
237#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
239 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400240 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000241 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
243#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400244 1 + 2 + nfs4_name_maxsz + \
245 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400246#define decode_create_maxsz (op_decode_hdr_maxsz + \
247 decode_change_info_maxsz + \
248 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400249#define encode_statfs_maxsz (encode_getattr_maxsz)
250#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
252#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400253#define encode_getacl_maxsz (encode_getattr_maxsz)
254#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
255 nfs4_fattr_bitmap_maxsz + 1)
256#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
257 encode_stateid_maxsz + 3)
258#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400259#define encode_fs_locations_maxsz \
260 (encode_getattr_maxsz)
261#define decode_fs_locations_maxsz \
262 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000263#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400264#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400265
266#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400267#define NFS4_MAX_MACHINE_NAME_LEN (64)
268
Benny Halevy99fe60d2009-04-01 09:22:29 -0400269#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
270 encode_verifier_maxsz + \
271 1 /* co_ownerid.len */ + \
272 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
273 1 /* flags */ + \
274 1 /* spa_how */ + \
275 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500276 1 /* implementation id array of size 1 */ + \
277 1 /* nii_domain */ + \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
279 1 /* nii_name */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400282#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
283 2 /* eir_clientid */ + \
284 1 /* eir_sequenceid */ + \
285 1 /* eir_flags */ + \
286 1 /* spr_how */ + \
287 0 /* SP4_NONE (for now) */ + \
288 2 /* eir_server_owner.so_minor_id */ + \
289 /* eir_server_owner.so_major_id<> */ \
290 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
291 /* eir_server_scope<> */ \
292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
293 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500294 1 /* nii_domain */ + \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
296 1 /* nii_name */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400299#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
300#define decode_channel_attrs_maxsz (6 + \
301 1 /* ca_rdma_ird.len */ + \
302 1 /* ca_rdma_ird */)
303#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
304 2 /* csa_clientid */ + \
305 1 /* csa_sequence */ + \
306 1 /* csa_flags */ + \
307 encode_channel_attrs_maxsz + \
308 encode_channel_attrs_maxsz + \
309 1 /* csa_cb_program */ + \
310 1 /* csa_sec_parms.len (1) */ + \
311 1 /* cb_secflavor (AUTH_SYS) */ + \
312 1 /* stamp */ + \
313 1 /* machinename.len */ + \
314 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
315 1 /* uid */ + \
316 1 /* gid */ + \
317 1 /* gids.len (0) */)
318#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
319 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
320 1 /* csr_sequence */ + \
321 1 /* csr_flags */ + \
322 decode_channel_attrs_maxsz + \
323 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400324#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
325#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400326#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
327 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
328#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
329 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500330#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
331#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400332#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
333 encode_verifier_maxsz)
334#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
335 2 /* nfs_cookie4 gdlr_cookie */ + \
336 decode_verifier_maxsz \
337 /* verifier4 gdlr_verifier */ + \
338 1 /* gdlr_deviceid_list count */ + \
339 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
340 NFS4_DEVICEID4_SIZE) \
341 /* gdlr_deviceid_list */ + \
342 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400343#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
344 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
345#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
346 1 /* layout type */ + \
347 1 /* opaque devaddr4 length */ + \
348 /* devaddr4 payload is read into page */ \
349 1 /* notification bitmap length */ + \
350 1 /* notification bitmap */)
351#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
352 encode_stateid_maxsz)
353#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
354 decode_stateid_maxsz + \
355 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000356#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
357 2 /* offset */ + \
358 2 /* length */ + \
359 1 /* reclaim */ + \
360 encode_stateid_maxsz + \
361 1 /* new offset (true) */ + \
362 2 /* last byte written */ + \
363 1 /* nt_timechanged (false) */ + \
364 1 /* layoutupdate4 layout type */ + \
365 1 /* NULL filelayout layoutupdate4 payload */)
366#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300367#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
368 encode_stateid_maxsz + \
369 1 /* FIXME: opaque lrf_body always empty at the moment */)
370#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
371 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400372#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
373#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400374#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
375 XDR_QUADLEN(NFS4_STATEID_SIZE))
376#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400377#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
378 XDR_QUADLEN(NFS4_STATEID_SIZE))
379#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400380#else /* CONFIG_NFS_V4_1 */
381#define encode_sequence_maxsz 0
382#define decode_sequence_maxsz 0
383#endif /* CONFIG_NFS_V4_1 */
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
386#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
387#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400390 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400392 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400394 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400396 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400398 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400402 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400404 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400406 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400415 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400420 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400425 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400429 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400430 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400433 encode_putfh_maxsz + \
434 encode_savefh_maxsz + \
435 encode_open_maxsz + \
436 encode_getfh_maxsz + \
437 encode_getattr_maxsz + \
438 encode_restorefh_maxsz + \
439 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400442 decode_putfh_maxsz + \
443 decode_savefh_maxsz + \
444 decode_open_maxsz + \
445 decode_getfh_maxsz + \
446 decode_getattr_maxsz + \
447 decode_restorefh_maxsz + \
448 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400449#define NFS4_enc_open_confirm_sz \
450 (compound_encode_hdr_maxsz + \
451 encode_putfh_maxsz + \
452 encode_open_confirm_maxsz)
453#define NFS4_dec_open_confirm_sz \
454 (compound_decode_hdr_maxsz + \
455 decode_putfh_maxsz + \
456 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400460 encode_open_maxsz + \
461 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 decode_open_maxsz + \
466 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_enc_open_downgrade_sz \
468 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 encode_putfh_maxsz + \
471 encode_open_downgrade_maxsz + \
472 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_dec_open_downgrade_sz \
474 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400476 decode_putfh_maxsz + \
477 decode_open_downgrade_maxsz + \
478 decode_getattr_maxsz)
479#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400480 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400481 encode_putfh_maxsz + \
482 encode_close_maxsz + \
483 encode_getattr_maxsz)
484#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 decode_putfh_maxsz + \
487 decode_close_maxsz + \
488 decode_getattr_maxsz)
489#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400491 encode_putfh_maxsz + \
492 encode_setattr_maxsz + \
493 encode_getattr_maxsz)
494#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400495 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400496 decode_putfh_maxsz + \
497 decode_setattr_maxsz + \
498 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 encode_putfh_maxsz + \
502 encode_fsinfo_maxsz)
503#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 decode_putfh_maxsz + \
506 decode_fsinfo_maxsz)
507#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
508 encode_renew_maxsz)
509#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
510 decode_renew_maxsz)
511#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
512 encode_setclientid_maxsz)
513#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
514 decode_setclientid_maxsz)
515#define NFS4_enc_setclientid_confirm_sz \
516 (compound_encode_hdr_maxsz + \
517 encode_setclientid_confirm_maxsz + \
518 encode_putrootfh_maxsz + \
519 encode_fsinfo_maxsz)
520#define NFS4_dec_setclientid_confirm_sz \
521 (compound_decode_hdr_maxsz + \
522 decode_setclientid_confirm_maxsz + \
523 decode_putrootfh_maxsz + \
524 decode_fsinfo_maxsz)
525#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400526 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400528 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400532 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400536 encode_lockt_maxsz)
537#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400539 decode_putfh_maxsz + \
540 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400544 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400548 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400549#define NFS4_enc_release_lockowner_sz \
550 (compound_encode_hdr_maxsz + \
551 encode_lockowner_maxsz)
552#define NFS4_dec_release_lockowner_sz \
553 (compound_decode_hdr_maxsz + \
554 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400558 encode_access_maxsz + \
559 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400561 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400563 decode_access_maxsz + \
564 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 encode_putfh_maxsz + \
568 encode_getattr_maxsz)
569#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 decode_putfh_maxsz + \
572 decode_getattr_maxsz)
573#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 encode_putfh_maxsz + \
576 encode_lookup_maxsz + \
577 encode_getattr_maxsz + \
578 encode_getfh_maxsz)
579#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400582 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_getattr_maxsz + \
584 decode_getfh_maxsz)
585#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 encode_putrootfh_maxsz + \
588 encode_getattr_maxsz + \
589 encode_getfh_maxsz)
590#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 decode_putrootfh_maxsz + \
593 decode_getattr_maxsz + \
594 decode_getfh_maxsz)
595#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400598 encode_remove_maxsz + \
599 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400603 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400604 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_putfh_maxsz + \
608 encode_savefh_maxsz + \
609 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400610 encode_rename_maxsz + \
611 encode_getattr_maxsz + \
612 encode_restorefh_maxsz + \
613 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400615 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 decode_putfh_maxsz + \
617 decode_savefh_maxsz + \
618 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400619 decode_rename_maxsz + \
620 decode_getattr_maxsz + \
621 decode_restorefh_maxsz + \
622 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_putfh_maxsz + \
626 encode_savefh_maxsz + \
627 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400628 encode_link_maxsz + \
629 decode_getattr_maxsz + \
630 encode_restorefh_maxsz + \
631 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400633 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 decode_putfh_maxsz + \
635 decode_savefh_maxsz + \
636 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400637 decode_link_maxsz + \
638 decode_getattr_maxsz + \
639 decode_restorefh_maxsz + \
640 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
644 encode_symlink_maxsz + \
645 encode_getattr_maxsz + \
646 encode_getfh_maxsz)
647#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 decode_putfh_maxsz + \
650 decode_symlink_maxsz + \
651 decode_getattr_maxsz + \
652 decode_getfh_maxsz)
653#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400656 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400658 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400660 encode_restorefh_maxsz + \
661 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400665 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400667 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400669 decode_restorefh_maxsz + \
670 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
674 encode_getattr_maxsz)
675#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_getattr_maxsz)
679#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400686 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800689 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 encode_getattr_maxsz)
691#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800693 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 decode_getattr_maxsz)
695#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100698 encode_delegreturn_maxsz + \
699 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100702 decode_delegreturn_maxsz + \
703 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000706 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000708#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000710 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400711 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000714 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000716#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000718 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400720#define NFS4_enc_fs_locations_sz \
721 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400723 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400724 encode_lookup_maxsz + \
725 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400726#define NFS4_dec_fs_locations_sz \
727 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400729 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400730 decode_lookup_maxsz + \
731 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000732#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
733 encode_sequence_maxsz + \
734 encode_putfh_maxsz + \
735 encode_secinfo_maxsz)
736#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
737 decode_sequence_maxsz + \
738 decode_putfh_maxsz + \
739 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400740#if defined(CONFIG_NFS_V4_1)
741#define NFS4_enc_exchange_id_sz \
742 (compound_encode_hdr_maxsz + \
743 encode_exchange_id_maxsz)
744#define NFS4_dec_exchange_id_sz \
745 (compound_decode_hdr_maxsz + \
746 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400747#define NFS4_enc_create_session_sz \
748 (compound_encode_hdr_maxsz + \
749 encode_create_session_maxsz)
750#define NFS4_dec_create_session_sz \
751 (compound_decode_hdr_maxsz + \
752 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400753#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
754 encode_destroy_session_maxsz)
755#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
756 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400757#define NFS4_enc_sequence_sz \
758 (compound_decode_hdr_maxsz + \
759 encode_sequence_maxsz)
760#define NFS4_dec_sequence_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400763#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
764 encode_sequence_maxsz + \
765 encode_putrootfh_maxsz + \
766 encode_fsinfo_maxsz)
767#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
768 decode_sequence_maxsz + \
769 decode_putrootfh_maxsz + \
770 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500771#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
772 encode_sequence_maxsz + \
773 encode_reclaim_complete_maxsz)
774#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
775 decode_sequence_maxsz + \
776 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400777#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz + \
779 encode_putfh_maxsz + \
780 encode_getdevicelist_maxsz)
781#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
782 decode_sequence_maxsz + \
783 decode_putfh_maxsz + \
784 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400785#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
786 encode_sequence_maxsz +\
787 encode_getdeviceinfo_maxsz)
788#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
789 decode_sequence_maxsz + \
790 decode_getdeviceinfo_maxsz)
791#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_putfh_maxsz + \
794 encode_layoutget_maxsz)
795#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
796 decode_sequence_maxsz + \
797 decode_putfh_maxsz + \
798 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000799#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
800 encode_sequence_maxsz +\
801 encode_putfh_maxsz + \
802 encode_layoutcommit_maxsz + \
803 encode_getattr_maxsz)
804#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
805 decode_sequence_maxsz + \
806 decode_putfh_maxsz + \
807 decode_layoutcommit_maxsz + \
808 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300809#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz + \
811 encode_putfh_maxsz + \
812 encode_layoutreturn_maxsz)
813#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
814 decode_sequence_maxsz + \
815 decode_putfh_maxsz + \
816 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400817#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz + \
819 encode_putrootfh_maxsz +\
820 encode_secinfo_no_name_maxsz)
821#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_putrootfh_maxsz + \
824 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400825#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz + \
827 encode_test_stateid_maxsz)
828#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400831#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
832 encode_sequence_maxsz + \
833 encode_free_stateid_maxsz)
834#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
835 decode_sequence_maxsz + \
836 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500837
838const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
839 compound_encode_hdr_maxsz +
840 encode_sequence_maxsz +
841 encode_putfh_maxsz +
842 encode_getattr_maxsz) *
843 XDR_UNIT);
844
845const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
846 compound_decode_hdr_maxsz +
847 decode_sequence_maxsz +
848 decode_putfh_maxsz) *
849 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400850#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500852static unsigned short send_implementation_id = 1;
853
854module_param(send_implementation_id, ushort, 0644);
855MODULE_PARM_DESC(send_implementation_id,
856 "Send implementation ID with NFSv4.1 exchange_id");
857
Trond Myklebustbca79472009-03-11 14:10:26 -0400858static const umode_t nfs_type2fmt[] = {
859 [NF4BAD] = 0,
860 [NF4REG] = S_IFREG,
861 [NF4DIR] = S_IFDIR,
862 [NF4BLK] = S_IFBLK,
863 [NF4CHR] = S_IFCHR,
864 [NF4LNK] = S_IFLNK,
865 [NF4SOCK] = S_IFSOCK,
866 [NF4FIFO] = S_IFIFO,
867 [NF4ATTRDIR] = 0,
868 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869};
870
871struct compound_hdr {
872 int32_t status;
873 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500874 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 uint32_t taglen;
876 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400877 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400878 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879};
880
Benny Halevy13c65ce2009-08-14 17:19:25 +0300881static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
882{
883 __be32 *p = xdr_reserve_space(xdr, nbytes);
884 BUG_ON(!p);
885 return p;
886}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Trond Myklebustcb17e552012-03-04 18:13:56 -0500888static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
889{
890 __be32 *p;
891
892 p = xdr_reserve_space(xdr, len);
893 xdr_encode_opaque_fixed(p, buf, len);
894}
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
897{
Al Viro8687b632006-10-19 23:28:48 -0700898 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
900 p = xdr_reserve_space(xdr, 4 + len);
901 BUG_ON(p == NULL);
902 xdr_encode_opaque(p, str, len);
903}
904
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400905static void encode_compound_hdr(struct xdr_stream *xdr,
906 struct rpc_rqst *req,
907 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
Al Viro8687b632006-10-19 23:28:48 -0700909 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400910 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400911
912 /* initialize running count of expected bytes in reply.
913 * NOTE: the replied tag SHOULD be the same is the one sent,
914 * but this is not required as a MUST for the server to do so. */
915 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300918 p = reserve_space(xdr, 4 + hdr->taglen + 8);
919 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300920 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500921 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300922 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500923}
924
925static void encode_nops(struct compound_hdr *hdr)
926{
Andy Adamsonfc931582009-04-01 09:22:31 -0400927 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500928 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
930
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500931static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
932{
933 encode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
934}
935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
937{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500938 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939}
940
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500941static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942{
943 char owner_name[IDMAP_NAMESZ];
944 char owner_group[IDMAP_NAMESZ];
945 int owner_namelen = 0;
946 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700947 __be32 *p;
948 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 int len;
950 uint32_t bmval0 = 0;
951 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
953 /*
954 * We reserve enough space to write the entire attribute buffer at once.
955 * In the worst-case, this would be
956 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
957 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000958 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 */
960 len = 16;
961
962 /* Sigh */
963 if (iap->ia_valid & ATTR_SIZE)
964 len += 8;
965 if (iap->ia_valid & ATTR_MODE)
966 len += 4;
967 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800968 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400970 dprintk("nfs: couldn't resolve uid %d to string\n",
971 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 /* XXX */
973 strcpy(owner_name, "nobody");
974 owner_namelen = sizeof("nobody") - 1;
975 /* goto out; */
976 }
977 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
978 }
979 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800980 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400982 dprintk("nfs: couldn't resolve gid %d to string\n",
983 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 strcpy(owner_group, "nobody");
985 owner_grouplen = sizeof("nobody") - 1;
986 /* goto out; */
987 }
988 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
989 }
990 if (iap->ia_valid & ATTR_ATIME_SET)
991 len += 16;
992 else if (iap->ia_valid & ATTR_ATIME)
993 len += 4;
994 if (iap->ia_valid & ATTR_MTIME_SET)
995 len += 16;
996 else if (iap->ia_valid & ATTR_MTIME)
997 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300998 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
1000 /*
1001 * We write the bitmap length now, but leave the bitmap and the attribute
1002 * buffer length to be backfilled at the end of this routine.
1003 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001004 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 q = p;
1006 p += 3;
1007
1008 if (iap->ia_valid & ATTR_SIZE) {
1009 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001010 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
1012 if (iap->ia_valid & ATTR_MODE) {
1013 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001014 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 }
1016 if (iap->ia_valid & ATTR_UID) {
1017 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001018 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 }
1020 if (iap->ia_valid & ATTR_GID) {
1021 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001022 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
1024 if (iap->ia_valid & ATTR_ATIME_SET) {
1025 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001026 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1027 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001028 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1029 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031 else if (iap->ia_valid & ATTR_ATIME) {
1032 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001033 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 }
1035 if (iap->ia_valid & ATTR_MTIME_SET) {
1036 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001037 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1038 *p++ = cpu_to_be32(0);
1039 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1040 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 }
1042 else if (iap->ia_valid & ATTR_MTIME) {
1043 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001044 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 /*
1048 * Now we backfill the bitmap and the attribute buffer length.
1049 */
1050 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001051 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 len, ((char *)p - (char *)q) + 4);
1053 BUG();
1054 }
1055 len = (char *)p - (char *)q - 12;
1056 *q++ = htonl(bmval0);
1057 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001058 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061}
1062
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001063static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
Al Viro8687b632006-10-19 23:28:48 -07001065 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Benny Halevy13c65ce2009-08-14 17:19:25 +03001067 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001068 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001069 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001070 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001071 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072}
1073
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001074static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
Al Viro8687b632006-10-19 23:28:48 -07001076 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001078 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001079 *p++ = cpu_to_be32(OP_CLOSE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001080 *p = cpu_to_be32(arg->seqid->sequence->counter);
1081 encode_nfs4_stateid(xdr, arg->stateid);
Andy Adamsond0179312008-12-23 16:06:17 -05001082 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001083 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084}
1085
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001086static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087{
Al Viro8687b632006-10-19 23:28:48 -07001088 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001089
Benny Halevy13c65ce2009-08-14 17:19:25 +03001090 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001091 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001092 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001093 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001094 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001095 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096}
1097
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001098static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099{
Al Viro8687b632006-10-19 23:28:48 -07001100 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001101
Benny Halevy13c65ce2009-08-14 17:19:25 +03001102 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001103 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001104 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
1106 switch (create->ftype) {
1107 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001108 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001109 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001110 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 break;
1112
1113 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001114 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001115 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001116 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 break;
1118
1119 default:
1120 break;
1121 }
1122
Benny Halevy811652b2009-08-14 17:19:34 +03001123 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001124 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001125 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001127 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001130static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131{
Andy Adamson05d564f2008-12-23 16:06:15 -05001132 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Benny Halevy13c65ce2009-08-14 17:19:25 +03001134 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001135 *p++ = cpu_to_be32(OP_GETATTR);
1136 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001137 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001138 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001139 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140}
1141
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001142static 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 -07001143{
Andy Adamson05d564f2008-12-23 16:06:15 -05001144 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
Benny Halevy13c65ce2009-08-14 17:19:25 +03001146 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001147 *p++ = cpu_to_be32(OP_GETATTR);
1148 *p++ = cpu_to_be32(2);
1149 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001150 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001151 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001152 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153}
1154
Fred Isamandae100c2011-07-30 20:52:37 -04001155static void
1156encode_getattr_three(struct xdr_stream *xdr,
1157 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1158 struct compound_hdr *hdr)
1159{
1160 __be32 *p;
1161
1162 p = reserve_space(xdr, 4);
1163 *p = cpu_to_be32(OP_GETATTR);
1164 if (bm2) {
1165 p = reserve_space(xdr, 16);
1166 *p++ = cpu_to_be32(3);
1167 *p++ = cpu_to_be32(bm0);
1168 *p++ = cpu_to_be32(bm1);
1169 *p = cpu_to_be32(bm2);
1170 } else if (bm1) {
1171 p = reserve_space(xdr, 12);
1172 *p++ = cpu_to_be32(2);
1173 *p++ = cpu_to_be32(bm0);
1174 *p = cpu_to_be32(bm1);
1175 } else {
1176 p = reserve_space(xdr, 8);
1177 *p++ = cpu_to_be32(1);
1178 *p = cpu_to_be32(bm0);
1179 }
1180 hdr->nops++;
1181 hdr->replen += decode_getattr_maxsz;
1182}
1183
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001184static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001186 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1187 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188}
1189
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001190static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191{
Fred Isamandae100c2011-07-30 20:52:37 -04001192 encode_getattr_three(xdr,
1193 bitmask[0] & nfs4_fsinfo_bitmap[0],
1194 bitmask[1] & nfs4_fsinfo_bitmap[1],
1195 bitmask[2] & nfs4_fsinfo_bitmap[2],
1196 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197}
1198
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001199static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001200{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001201 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1202 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001203}
1204
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001205static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206{
Al Viro8687b632006-10-19 23:28:48 -07001207 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Benny Halevy13c65ce2009-08-14 17:19:25 +03001209 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001210 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001211 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001212 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213}
1214
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001215static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216{
Al Viro8687b632006-10-19 23:28:48 -07001217 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
Benny Halevy13c65ce2009-08-14 17:19:25 +03001219 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001220 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001221 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001222 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001223 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224}
1225
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001226static inline int nfs4_lock_type(struct file_lock *fl, int block)
1227{
1228 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1229 return block ? NFS4_READW_LT : NFS4_READ_LT;
1230 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1231}
1232
1233static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1234{
1235 if (fl->fl_end == OFFSET_MAX)
1236 return ~(uint64_t)0;
1237 return fl->fl_end - fl->fl_start + 1;
1238}
1239
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001240static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1241{
1242 __be32 *p;
1243
Trond Myklebustd035c362010-12-21 10:45:27 -05001244 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001245 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001246 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001247 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001248 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001249 xdr_encode_hyper(p, lowner->id);
1250}
1251
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252/*
1253 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1254 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1255 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001256static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
Al Viro8687b632006-10-19 23:28:48 -07001258 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Benny Halevy13c65ce2009-08-14 17:19:25 +03001260 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001261 *p++ = cpu_to_be32(OP_LOCK);
1262 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1263 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001264 p = xdr_encode_hyper(p, args->fl->fl_start);
1265 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001266 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001267 if (args->new_lock_owner){
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001268 p = reserve_space(xdr, 4);
1269 *p = cpu_to_be32(args->open_seqid->sequence->counter);
1270 encode_nfs4_stateid(xdr, args->open_stateid);
1271 p = reserve_space(xdr, 4);
1272 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001273 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 }
1275 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001276 encode_nfs4_stateid(xdr, args->lock_stateid);
1277 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001278 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 }
Andy Adamsond0179312008-12-23 16:06:17 -05001280 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001281 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282}
1283
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001284static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285{
Al Viro8687b632006-10-19 23:28:48 -07001286 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001288 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001289 *p++ = cpu_to_be32(OP_LOCKT);
1290 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001291 p = xdr_encode_hyper(p, args->fl->fl_start);
1292 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001293 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001294 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001295 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296}
1297
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001298static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
Al Viro8687b632006-10-19 23:28:48 -07001300 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001302 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001303 *p++ = cpu_to_be32(OP_LOCKU);
1304 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001305 *p = cpu_to_be32(args->seqid->sequence->counter);
1306 encode_nfs4_stateid(xdr, args->stateid);
1307 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001308 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001309 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001310 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001311 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312}
1313
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001314static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1315{
1316 __be32 *p;
1317
1318 p = reserve_space(xdr, 4);
1319 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1320 encode_lockowner(xdr, lowner);
1321 hdr->nops++;
1322 hdr->replen += decode_release_lockowner_maxsz;
1323}
1324
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001325static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
1327 int len = name->len;
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 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001331 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001332 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001333 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001334 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335}
1336
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001337static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338{
Al Viro8687b632006-10-19 23:28:48 -07001339 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Benny Halevy13c65ce2009-08-14 17:19:25 +03001341 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001342 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001343 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001344 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001345 break;
1346 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001347 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001348 break;
1349 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001350 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001351 break;
1352 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001353 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 }
Benny Halevy34558512009-08-14 17:19:30 +03001355 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356}
1357
1358static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1359{
Al Viro8687b632006-10-19 23:28:48 -07001360 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 /*
1362 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1363 * owner 4 = 32
1364 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001365 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001366 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001367 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001368 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001369 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001370 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001371 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001372 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001373 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001374 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375}
1376
1377static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1378{
Al Viro8687b632006-10-19 23:28:48 -07001379 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001380 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
Benny Halevy13c65ce2009-08-14 17:19:25 +03001382 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001384 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001385 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001386 encode_attrs(xdr, arg->u.attrs, arg->server);
1387 break;
1388 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001389 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001390 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001391 if (nfs4_has_persistent_session(clp)) {
1392 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1393 encode_attrs(xdr, arg->u.attrs, arg->server);
1394 } else {
1395 struct iattr dummy;
1396
1397 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1398 encode_nfs4_verifier(xdr, &arg->u.verifier);
1399 dummy.ia_valid = 0;
1400 encode_attrs(xdr, &dummy, arg->server);
1401 }
1402 } else {
1403 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1404 encode_nfs4_verifier(xdr, &arg->u.verifier);
1405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 }
1407}
1408
1409static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1410{
Al Viro8687b632006-10-19 23:28:48 -07001411 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
Benny Halevy13c65ce2009-08-14 17:19:25 +03001413 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001415 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001416 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001417 break;
1418 default:
1419 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001420 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001421 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 }
1423}
1424
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001425static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426{
Al Viro8687b632006-10-19 23:28:48 -07001427 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Benny Halevy13c65ce2009-08-14 17:19:25 +03001429 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001431 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001432 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001433 break;
1434 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001435 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001436 break;
1437 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001438 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001439 break;
1440 default:
1441 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 }
1443}
1444
1445static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1446{
Al Viro8687b632006-10-19 23:28:48 -07001447 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Benny Halevy13c65ce2009-08-14 17:19:25 +03001449 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001450 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 encode_string(xdr, name->len, name->name);
1452}
1453
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001454static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455{
Al Viro8687b632006-10-19 23:28:48 -07001456 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Benny Halevy13c65ce2009-08-14 17:19:25 +03001458 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001459 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 encode_delegation_type(xdr, type);
1461}
1462
1463static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1464{
Al Viro8687b632006-10-19 23:28:48 -07001465 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001467 p = reserve_space(xdr, 4);
1468 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1469 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 encode_string(xdr, name->len, name->name);
1471}
1472
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001473static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
1475 encode_openhdr(xdr, arg);
1476 encode_opentype(xdr, arg);
1477 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001478 case NFS4_OPEN_CLAIM_NULL:
1479 encode_claim_null(xdr, arg->name);
1480 break;
1481 case NFS4_OPEN_CLAIM_PREVIOUS:
1482 encode_claim_previous(xdr, arg->u.delegation_type);
1483 break;
1484 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1485 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1486 break;
1487 default:
1488 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 }
Andy Adamsond0179312008-12-23 16:06:17 -05001490 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001491 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492}
1493
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001494static 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 -07001495{
Al Viro8687b632006-10-19 23:28:48 -07001496 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001498 p = reserve_space(xdr, 4);
1499 *p = cpu_to_be32(OP_OPEN_CONFIRM);
1500 encode_nfs4_stateid(xdr, arg->stateid);
1501 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001502 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001503 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001504 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Al Viro8687b632006-10-19 23:28:48 -07001509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001511 p = reserve_space(xdr, 4);
1512 *p = cpu_to_be32(OP_OPEN_DOWNGRADE);
1513 encode_nfs4_stateid(xdr, arg->stateid);
1514 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001515 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001516 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001517 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001518 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519}
1520
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001521static void
Andy Adamsond0179312008-12-23 16:06:17 -05001522encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
1524 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001525 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Benny Halevy13c65ce2009-08-14 17:19:25 +03001527 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001528 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001529 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001530 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001531 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532}
1533
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001534static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535{
Andy Adamson05d564f2008-12-23 16:06:15 -05001536 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001537
Benny Halevy13c65ce2009-08-14 17:19:25 +03001538 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001539 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001540 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001541 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542}
1543
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001544static 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 -07001545{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001549 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001550 if (zero_seqid)
1551 stateid.stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001552 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001554 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555}
1556
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001557static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558{
Al Viro8687b632006-10-19 23:28:48 -07001559 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Benny Halevy13c65ce2009-08-14 17:19:25 +03001561 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001562 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001564 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001565 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Benny Halevy13c65ce2009-08-14 17:19:25 +03001567 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001568 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001569 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001570 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001571 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572}
1573
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001574static 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 -07001575{
Trond Myklebust28331a42011-04-27 13:47:52 -04001576 uint32_t attrs[2] = {
1577 FATTR4_WORD0_RDATTR_ERROR,
1578 FATTR4_WORD1_MOUNTED_ON_FILEID,
1579 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001580 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001581 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001583 if (readdir->plus) {
1584 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001585 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001586 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1587 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1588 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1589 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001590 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001591 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001592 /* Use mounted_on_fileid only if the server supports it */
1593 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1594 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001595
Benny Halevy13c65ce2009-08-14 17:19:25 +03001596 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001597 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001598 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001599 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001600 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001601 *p++ = cpu_to_be32(readdir->count);
1602 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001603
Benny Halevye75bc1c2009-08-14 17:18:54 +03001604 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001605 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001606 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001607 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001608 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1609 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001610 (unsigned long long)readdir->cookie,
1611 ((u32 *)readdir->verifier.data)[0],
1612 ((u32 *)readdir->verifier.data)[1],
1613 attrs[0] & readdir->bitmask[0],
1614 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
1616
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001617static 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 -07001618{
Al Viro8687b632006-10-19 23:28:48 -07001619 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Benny Halevy13c65ce2009-08-14 17:19:25 +03001621 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001622 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001623 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001624 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625}
1626
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001627static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, 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 Halevy13c65ce2009-08-14 17:19:25 +03001631 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001632 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001633 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001634 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001635 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636}
1637
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001638static 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 -07001639{
Al Viro8687b632006-10-19 23:28:48 -07001640 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
Benny Halevy811652b2009-08-14 17:19:34 +03001642 p = reserve_space(xdr, 4);
1643 *p = cpu_to_be32(OP_RENAME);
1644 encode_string(xdr, oldname->len, oldname->name);
1645 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001646 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001647 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648}
1649
Chuck Leverbb4dae52012-03-01 17:01:48 -05001650static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1651 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
Al Viro8687b632006-10-19 23:28:48 -07001653 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
Benny Halevy13c65ce2009-08-14 17:19:25 +03001655 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001656 *p++ = cpu_to_be32(OP_RENEW);
Chuck Leverbb4dae52012-03-01 17:01:48 -05001657 xdr_encode_hyper(p, clid);
Andy Adamsond0179312008-12-23 16:06:17 -05001658 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001659 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660}
1661
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001662static void
Andy Adamsond0179312008-12-23 16:06:17 -05001663encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001664{
Al Viro8687b632006-10-19 23:28:48 -07001665 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001666
Benny Halevy13c65ce2009-08-14 17:19:25 +03001667 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001668 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001669 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001670 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001671}
1672
Chuck Lever9f06c712010-12-14 14:59:18 +00001673static void
Andy Adamsond0179312008-12-23 16:06:17 -05001674encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001675{
Al Viro8687b632006-10-19 23:28:48 -07001676 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001677
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001678 p = reserve_space(xdr, 4);
1679 *p = cpu_to_be32(OP_SETATTR);
1680 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001681 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001682 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001683 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001684 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001685 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001686 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001687 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001688 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001689 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001690}
1691
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001692static void
Andy Adamsond0179312008-12-23 16:06:17 -05001693encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
Al Viro8687b632006-10-19 23:28:48 -07001695 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
Benny Halevy13c65ce2009-08-14 17:19:25 +03001697 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001698 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001699 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001700 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001703static 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 -07001704{
Al Viro8687b632006-10-19 23:28:48 -07001705 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001706
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001707 p = reserve_space(xdr, 4);
1708 *p = cpu_to_be32(OP_SETATTR);
1709 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsond0179312008-12-23 16:06:17 -05001710 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001711 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001712 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713}
1714
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001715static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
Al Viro8687b632006-10-19 23:28:48 -07001717 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
Benny Halevy13c65ce2009-08-14 17:19:25 +03001719 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001720 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001721 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
1723 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001724 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001725 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1727 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001728 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001729 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001730 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001731 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
1733
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001734static 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 -07001735{
Andy Adamson05d564f2008-12-23 16:06:15 -05001736 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
Benny Halevy13c65ce2009-08-14 17:19:25 +03001738 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001739 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001740 p = xdr_encode_hyper(p, arg->clientid);
1741 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001742 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001743 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744}
1745
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001746static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747{
Al Viro8687b632006-10-19 23:28:48 -07001748 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
Benny Halevy13c65ce2009-08-14 17:19:25 +03001750 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001751 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001753 encode_open_stateid(xdr, args->context, args->lock_context,
Andy Adamson89d1ea62011-03-01 01:34:09 +00001754 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
Benny Halevy13c65ce2009-08-14 17:19:25 +03001756 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001757 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001758 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001759 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
1761 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001762 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001763 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764}
1765
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001766static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767{
Al Viro8687b632006-10-19 23:28:48 -07001768 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001770 p = reserve_space(xdr, 4);
1771 *p = cpu_to_be32(OP_DELEGRETURN);
1772 encode_nfs4_stateid(xdr, stateid);
Andy Adamsond0179312008-12-23 16:06:17 -05001773 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001774 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001776
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001777static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1778{
1779 int len = name->len;
1780 __be32 *p;
1781
1782 p = reserve_space(xdr, 8 + len);
1783 *p++ = cpu_to_be32(OP_SECINFO);
1784 xdr_encode_opaque(p, name->name, len);
1785 hdr->nops++;
1786 hdr->replen += decode_secinfo_maxsz;
1787}
1788
Benny Halevy99fe60d2009-04-01 09:22:29 -04001789#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001790/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001791static void encode_exchange_id(struct xdr_stream *xdr,
1792 struct nfs41_exchange_id_args *args,
1793 struct compound_hdr *hdr)
1794{
1795 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001796 char impl_name[NFS4_OPAQUE_LIMIT];
1797 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001798
Benny Halevy13c65ce2009-08-14 17:19:25 +03001799 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001800 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001801 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001802
1803 encode_string(xdr, args->id_len, args->id);
1804
Benny Halevy13c65ce2009-08-14 17:19:25 +03001805 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001806 *p++ = cpu_to_be32(args->flags);
1807 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001808
1809 if (send_implementation_id &&
1810 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1811 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1812 <= NFS4_OPAQUE_LIMIT + 1)
1813 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1814 utsname()->sysname, utsname()->release,
1815 utsname()->version, utsname()->machine);
1816
1817 if (len > 0) {
1818 *p = cpu_to_be32(1); /* implementation id array length=1 */
1819
1820 encode_string(xdr,
1821 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1822 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1823 encode_string(xdr, len, impl_name);
1824 /* just send zeros for nii_date - the date is in nii_name */
1825 p = reserve_space(xdr, 12);
1826 p = xdr_encode_hyper(p, 0);
1827 *p = cpu_to_be32(0);
1828 } else
1829 *p = cpu_to_be32(0); /* implementation id array length=0 */
1830
Benny Halevy99fe60d2009-04-01 09:22:29 -04001831 hdr->nops++;
1832 hdr->replen += decode_exchange_id_maxsz;
1833}
Andy Adamsonfc931582009-04-01 09:22:31 -04001834
1835static void encode_create_session(struct xdr_stream *xdr,
1836 struct nfs41_create_session_args *args,
1837 struct compound_hdr *hdr)
1838{
1839 __be32 *p;
1840 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1841 uint32_t len;
1842 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001843 u32 max_resp_sz_cached;
1844
1845 /*
1846 * Assumes OPEN is the biggest non-idempotent compound.
1847 * 2 is the verifier.
1848 */
1849 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1850 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001851
Andy Adamsonfc931582009-04-01 09:22:31 -04001852 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1853 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001854
Benny Halevy13c65ce2009-08-14 17:19:25 +03001855 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001856 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001857 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001858 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1859 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001860
Andy Adamsonfc931582009-04-01 09:22:31 -04001861 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001862 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001863 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1864 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001865 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001866 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1867 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1868 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001869
1870 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001871 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001872 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1873 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1874 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1875 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1876 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1877 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001878
Benny Halevye75bc1c2009-08-14 17:18:54 +03001879 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001880 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001881 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001882
1883 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001884 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001885 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001886 *p++ = cpu_to_be32(0); /* UID */
1887 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001888 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001889 hdr->nops++;
1890 hdr->replen += decode_create_session_maxsz;
1891}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001892
1893static void encode_destroy_session(struct xdr_stream *xdr,
1894 struct nfs4_session *session,
1895 struct compound_hdr *hdr)
1896{
1897 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001898 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001899 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001900 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001901 hdr->nops++;
1902 hdr->replen += decode_destroy_session_maxsz;
1903}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001904
1905static void encode_reclaim_complete(struct xdr_stream *xdr,
1906 struct nfs41_reclaim_complete_args *args,
1907 struct compound_hdr *hdr)
1908{
1909 __be32 *p;
1910
1911 p = reserve_space(xdr, 8);
1912 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1913 *p++ = cpu_to_be32(args->one_fs);
1914 hdr->nops++;
1915 hdr->replen += decode_reclaim_complete_maxsz;
1916}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001917#endif /* CONFIG_NFS_V4_1 */
1918
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001919static void encode_sequence(struct xdr_stream *xdr,
1920 const struct nfs4_sequence_args *args,
1921 struct compound_hdr *hdr)
1922{
1923#if defined(CONFIG_NFS_V4_1)
1924 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001925 struct nfs4_slot_table *tp;
1926 struct nfs4_slot *slot;
1927 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001928
1929 if (!session)
1930 return;
1931
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001932 tp = &session->fc_slot_table;
1933
1934 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1935 slot = tp->slots + args->sa_slotid;
1936
Benny Halevy13c65ce2009-08-14 17:19:25 +03001937 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001938 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001939
1940 /*
1941 * Sessionid + seqid + slotid + max slotid + cache_this
1942 */
1943 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1944 "max_slotid=%d cache_this=%d\n",
1945 __func__,
1946 ((u32 *)session->sess_id.data)[0],
1947 ((u32 *)session->sess_id.data)[1],
1948 ((u32 *)session->sess_id.data)[2],
1949 ((u32 *)session->sess_id.data)[3],
1950 slot->seq_nr, args->sa_slotid,
1951 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001952 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001953 *p++ = cpu_to_be32(slot->seq_nr);
1954 *p++ = cpu_to_be32(args->sa_slotid);
1955 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001956 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001957 hdr->nops++;
1958 hdr->replen += decode_sequence_maxsz;
1959#endif /* CONFIG_NFS_V4_1 */
1960}
1961
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001962#ifdef CONFIG_NFS_V4_1
1963static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001964encode_getdevicelist(struct xdr_stream *xdr,
1965 const struct nfs4_getdevicelist_args *args,
1966 struct compound_hdr *hdr)
1967{
1968 __be32 *p;
1969 nfs4_verifier dummy = {
1970 .data = "dummmmmy",
1971 };
1972
1973 p = reserve_space(xdr, 20);
1974 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1975 *p++ = cpu_to_be32(args->layoutclass);
1976 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1977 xdr_encode_hyper(p, 0ULL); /* cookie */
1978 encode_nfs4_verifier(xdr, &dummy);
1979 hdr->nops++;
1980 hdr->replen += decode_getdevicelist_maxsz;
1981}
1982
1983static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001984encode_getdeviceinfo(struct xdr_stream *xdr,
1985 const struct nfs4_getdeviceinfo_args *args,
1986 struct compound_hdr *hdr)
1987{
1988 __be32 *p;
1989
1990 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1991 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1992 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1993 NFS4_DEVICEID4_SIZE);
1994 *p++ = cpu_to_be32(args->pdev->layout_type);
1995 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1996 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1997 hdr->nops++;
1998 hdr->replen += decode_getdeviceinfo_maxsz;
1999}
2000
2001static void
2002encode_layoutget(struct xdr_stream *xdr,
2003 const struct nfs4_layoutget_args *args,
2004 struct compound_hdr *hdr)
2005{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002006 __be32 *p;
2007
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002008 p = reserve_space(xdr, 40);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002009 *p++ = cpu_to_be32(OP_LAYOUTGET);
2010 *p++ = cpu_to_be32(0); /* Signal layout available */
2011 *p++ = cpu_to_be32(args->type);
2012 *p++ = cpu_to_be32(args->range.iomode);
2013 p = xdr_encode_hyper(p, args->range.offset);
2014 p = xdr_encode_hyper(p, args->range.length);
2015 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002016 encode_nfs4_stateid(xdr, &args->stateid);
2017 p = reserve_space(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002018 *p = cpu_to_be32(args->maxcount);
2019
2020 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
2021 __func__,
2022 args->type,
2023 args->range.iomode,
2024 (unsigned long)args->range.offset,
2025 (unsigned long)args->range.length,
2026 args->maxcount);
2027 hdr->nops++;
2028 hdr->replen += decode_layoutget_maxsz;
2029}
Andy Adamson863a3c62011-03-23 13:27:54 +00002030
2031static int
2032encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03002033 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00002034 const struct nfs4_layoutcommit_args *args,
2035 struct compound_hdr *hdr)
2036{
2037 __be32 *p;
2038
2039 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2040 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2041
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002042 p = reserve_space(xdr, 24);
Andy Adamson863a3c62011-03-23 13:27:54 +00002043 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
2044 /* Only whole file layouts */
2045 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002046 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002047 *p = cpu_to_be32(0); /* reclaim */
2048 encode_nfs4_stateid(xdr, &args->stateid);
2049 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00002050 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2051 p = xdr_encode_hyper(p, args->lastbytewritten);
2052 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2053 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002054
2055 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2056 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2057 NFS_I(inode)->layout, xdr, args);
2058 else {
2059 p = reserve_space(xdr, 4);
2060 *p = cpu_to_be32(0); /* no layout-type payload */
2061 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002062
2063 hdr->nops++;
2064 hdr->replen += decode_layoutcommit_maxsz;
2065 return 0;
2066}
Benny Halevycbe82602011-05-22 19:52:37 +03002067
2068static void
2069encode_layoutreturn(struct xdr_stream *xdr,
2070 const struct nfs4_layoutreturn_args *args,
2071 struct compound_hdr *hdr)
2072{
2073 __be32 *p;
2074
2075 p = reserve_space(xdr, 20);
2076 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
2077 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2078 *p++ = cpu_to_be32(args->layout_type);
2079 *p++ = cpu_to_be32(IOMODE_ANY);
2080 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002081 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002082 p = xdr_encode_hyper(p, 0);
2083 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2084 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002085 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002086 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002087 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2088 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2089 NFS_I(args->inode)->layout, xdr, args);
2090 } else {
2091 p = reserve_space(xdr, 4);
2092 *p = cpu_to_be32(0);
2093 }
Benny Halevycbe82602011-05-22 19:52:37 +03002094 hdr->nops++;
2095 hdr->replen += decode_layoutreturn_maxsz;
2096}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002097
2098static int
2099encode_secinfo_no_name(struct xdr_stream *xdr,
2100 const struct nfs41_secinfo_no_name_args *args,
2101 struct compound_hdr *hdr)
2102{
2103 __be32 *p;
2104 p = reserve_space(xdr, 8);
2105 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2106 *p++ = cpu_to_be32(args->style);
2107 hdr->nops++;
2108 hdr->replen += decode_secinfo_no_name_maxsz;
2109 return 0;
2110}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002111
2112static void encode_test_stateid(struct xdr_stream *xdr,
2113 struct nfs41_test_stateid_args *args,
2114 struct compound_hdr *hdr)
2115{
2116 __be32 *p;
2117
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002118 p = reserve_space(xdr, 8);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002119 *p++ = cpu_to_be32(OP_TEST_STATEID);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002120 *p = cpu_to_be32(1);
2121 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002122 hdr->nops++;
2123 hdr->replen += decode_test_stateid_maxsz;
2124}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002125
2126static void encode_free_stateid(struct xdr_stream *xdr,
2127 struct nfs41_free_stateid_args *args,
2128 struct compound_hdr *hdr)
2129{
2130 __be32 *p;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002131 p = reserve_space(xdr, 4);
2132 *p = cpu_to_be32(OP_FREE_STATEID);
2133 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002134 hdr->nops++;
2135 hdr->replen += decode_free_stateid_maxsz;
2136}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002137#endif /* CONFIG_NFS_V4_1 */
2138
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139/*
2140 * END OF "GENERIC" ENCODE ROUTINES.
2141 */
2142
Benny Halevy66cc0422009-04-01 09:22:10 -04002143static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2144{
2145#if defined(CONFIG_NFS_V4_1)
2146 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002147 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002148#endif /* CONFIG_NFS_V4_1 */
2149 return 0;
2150}
2151
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152/*
2153 * Encode an ACCESS request
2154 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002155static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2156 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002159 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
Chuck Lever9f06c712010-12-14 14:59:18 +00002162 encode_compound_hdr(xdr, req, &hdr);
2163 encode_sequence(xdr, &args->seq_args, &hdr);
2164 encode_putfh(xdr, args->fh, &hdr);
2165 encode_access(xdr, args->access, &hdr);
2166 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002167 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168}
2169
2170/*
2171 * Encode LOOKUP request
2172 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002173static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2174 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002177 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
Chuck Lever9f06c712010-12-14 14:59:18 +00002180 encode_compound_hdr(xdr, req, &hdr);
2181 encode_sequence(xdr, &args->seq_args, &hdr);
2182 encode_putfh(xdr, args->dir_fh, &hdr);
2183 encode_lookup(xdr, args->name, &hdr);
2184 encode_getfh(xdr, &hdr);
2185 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002186 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187}
2188
2189/*
2190 * Encode LOOKUP_ROOT request
2191 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002192static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2193 struct xdr_stream *xdr,
2194 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002197 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
Chuck Lever9f06c712010-12-14 14:59:18 +00002200 encode_compound_hdr(xdr, req, &hdr);
2201 encode_sequence(xdr, &args->seq_args, &hdr);
2202 encode_putrootfh(xdr, &hdr);
2203 encode_getfh(xdr, &hdr);
2204 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002205 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206}
2207
2208/*
2209 * Encode REMOVE request
2210 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002211static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2212 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002215 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
Chuck Lever9f06c712010-12-14 14:59:18 +00002218 encode_compound_hdr(xdr, req, &hdr);
2219 encode_sequence(xdr, &args->seq_args, &hdr);
2220 encode_putfh(xdr, args->fh, &hdr);
2221 encode_remove(xdr, &args->name, &hdr);
2222 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002223 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224}
2225
2226/*
2227 * Encode RENAME request
2228 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002229static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2230 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002233 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
Chuck Lever9f06c712010-12-14 14:59:18 +00002236 encode_compound_hdr(xdr, req, &hdr);
2237 encode_sequence(xdr, &args->seq_args, &hdr);
2238 encode_putfh(xdr, args->old_dir, &hdr);
2239 encode_savefh(xdr, &hdr);
2240 encode_putfh(xdr, args->new_dir, &hdr);
2241 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2242 encode_getfattr(xdr, args->bitmask, &hdr);
2243 encode_restorefh(xdr, &hdr);
2244 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002245 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246}
2247
2248/*
2249 * Encode LINK request
2250 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002251static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2252 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002255 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
Chuck Lever9f06c712010-12-14 14:59:18 +00002258 encode_compound_hdr(xdr, req, &hdr);
2259 encode_sequence(xdr, &args->seq_args, &hdr);
2260 encode_putfh(xdr, args->fh, &hdr);
2261 encode_savefh(xdr, &hdr);
2262 encode_putfh(xdr, args->dir_fh, &hdr);
2263 encode_link(xdr, args->name, &hdr);
2264 encode_getfattr(xdr, args->bitmask, &hdr);
2265 encode_restorefh(xdr, &hdr);
2266 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002267 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268}
2269
2270/*
2271 * Encode CREATE request
2272 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002273static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2274 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002277 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
Chuck Lever9f06c712010-12-14 14:59:18 +00002280 encode_compound_hdr(xdr, req, &hdr);
2281 encode_sequence(xdr, &args->seq_args, &hdr);
2282 encode_putfh(xdr, args->dir_fh, &hdr);
2283 encode_savefh(xdr, &hdr);
2284 encode_create(xdr, args, &hdr);
2285 encode_getfh(xdr, &hdr);
2286 encode_getfattr(xdr, args->bitmask, &hdr);
2287 encode_restorefh(xdr, &hdr);
2288 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002289 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290}
2291
2292/*
2293 * Encode SYMLINK request
2294 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002295static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2296 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297{
Chuck Lever9f06c712010-12-14 14:59:18 +00002298 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299}
2300
2301/*
2302 * Encode GETATTR request
2303 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002304static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2305 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002308 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Chuck Lever9f06c712010-12-14 14:59:18 +00002311 encode_compound_hdr(xdr, req, &hdr);
2312 encode_sequence(xdr, &args->seq_args, &hdr);
2313 encode_putfh(xdr, args->fh, &hdr);
2314 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002315 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316}
2317
2318/*
2319 * Encode a CLOSE request
2320 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002321static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2322 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323{
Andy Adamson05d564f2008-12-23 16:06:15 -05002324 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002325 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002326 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
Chuck Lever9f06c712010-12-14 14:59:18 +00002328 encode_compound_hdr(xdr, req, &hdr);
2329 encode_sequence(xdr, &args->seq_args, &hdr);
2330 encode_putfh(xdr, args->fh, &hdr);
2331 encode_close(xdr, args, &hdr);
2332 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002333 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334}
2335
2336/*
2337 * Encode an OPEN request
2338 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002339static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2340 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002343 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
Chuck Lever9f06c712010-12-14 14:59:18 +00002346 encode_compound_hdr(xdr, req, &hdr);
2347 encode_sequence(xdr, &args->seq_args, &hdr);
2348 encode_putfh(xdr, args->fh, &hdr);
2349 encode_savefh(xdr, &hdr);
2350 encode_open(xdr, args, &hdr);
2351 encode_getfh(xdr, &hdr);
2352 encode_getfattr(xdr, args->bitmask, &hdr);
2353 encode_restorefh(xdr, &hdr);
Trond Myklebust6926afd12012-01-07 13:22:46 -05002354 encode_getfattr(xdr, args->dir_bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002355 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356}
2357
2358/*
2359 * Encode an OPEN_CONFIRM request
2360 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002361static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2362 struct xdr_stream *xdr,
2363 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002366 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
Chuck Lever9f06c712010-12-14 14:59:18 +00002369 encode_compound_hdr(xdr, req, &hdr);
2370 encode_putfh(xdr, args->fh, &hdr);
2371 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002372 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373}
2374
2375/*
2376 * Encode an OPEN request with no attributes.
2377 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002378static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2379 struct xdr_stream *xdr,
2380 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002383 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
Chuck Lever9f06c712010-12-14 14:59:18 +00002386 encode_compound_hdr(xdr, req, &hdr);
2387 encode_sequence(xdr, &args->seq_args, &hdr);
2388 encode_putfh(xdr, args->fh, &hdr);
2389 encode_open(xdr, args, &hdr);
2390 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002391 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392}
2393
2394/*
2395 * Encode an OPEN_DOWNGRADE request
2396 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002397static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2398 struct xdr_stream *xdr,
2399 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002402 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
Chuck Lever9f06c712010-12-14 14:59:18 +00002405 encode_compound_hdr(xdr, req, &hdr);
2406 encode_sequence(xdr, &args->seq_args, &hdr);
2407 encode_putfh(xdr, args->fh, &hdr);
2408 encode_open_downgrade(xdr, args, &hdr);
2409 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002410 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411}
2412
2413/*
2414 * Encode a LOCK request
2415 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002416static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2417 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002420 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422
Chuck Lever9f06c712010-12-14 14:59:18 +00002423 encode_compound_hdr(xdr, req, &hdr);
2424 encode_sequence(xdr, &args->seq_args, &hdr);
2425 encode_putfh(xdr, args->fh, &hdr);
2426 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002427 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428}
2429
2430/*
2431 * Encode a LOCKT request
2432 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002433static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2434 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002437 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439
Chuck Lever9f06c712010-12-14 14:59:18 +00002440 encode_compound_hdr(xdr, req, &hdr);
2441 encode_sequence(xdr, &args->seq_args, &hdr);
2442 encode_putfh(xdr, args->fh, &hdr);
2443 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002444 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445}
2446
2447/*
2448 * Encode a LOCKU request
2449 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002450static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2451 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002454 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Chuck Lever9f06c712010-12-14 14:59:18 +00002457 encode_compound_hdr(xdr, req, &hdr);
2458 encode_sequence(xdr, &args->seq_args, &hdr);
2459 encode_putfh(xdr, args->fh, &hdr);
2460 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002461 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462}
2463
Chuck Lever9f06c712010-12-14 14:59:18 +00002464static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2465 struct xdr_stream *xdr,
2466 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002467{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002468 struct compound_hdr hdr = {
2469 .minorversion = 0,
2470 };
2471
Chuck Lever9f06c712010-12-14 14:59:18 +00002472 encode_compound_hdr(xdr, req, &hdr);
2473 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002474 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002475}
2476
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477/*
2478 * Encode a READLINK request
2479 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002480static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2481 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002484 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
Chuck Lever9f06c712010-12-14 14:59:18 +00002487 encode_compound_hdr(xdr, req, &hdr);
2488 encode_sequence(xdr, &args->seq_args, &hdr);
2489 encode_putfh(xdr, args->fh, &hdr);
2490 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002491
Benny Halevy28f56692009-04-01 09:22:09 -04002492 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002493 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002494 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495}
2496
2497/*
2498 * Encode a READDIR request
2499 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002500static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2501 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002504 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506
Chuck Lever9f06c712010-12-14 14:59:18 +00002507 encode_compound_hdr(xdr, req, &hdr);
2508 encode_sequence(xdr, &args->seq_args, &hdr);
2509 encode_putfh(xdr, args->fh, &hdr);
2510 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002511
Benny Halevy28f56692009-04-01 09:22:09 -04002512 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002513 args->pgbase, args->count);
2514 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002515 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002516 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002517 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518}
2519
2520/*
2521 * Encode a READ request
2522 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002523static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2524 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002527 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529
Chuck Lever9f06c712010-12-14 14:59:18 +00002530 encode_compound_hdr(xdr, req, &hdr);
2531 encode_sequence(xdr, &args->seq_args, &hdr);
2532 encode_putfh(xdr, args->fh, &hdr);
2533 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
Benny Halevy28f56692009-04-01 09:22:09 -04002535 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002537 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002538 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539}
2540
2541/*
2542 * Encode an SETATTR request
2543 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002544static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2545 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546{
Andy Adamson05d564f2008-12-23 16:06:15 -05002547 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002548 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002549 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
Chuck Lever9f06c712010-12-14 14:59:18 +00002551 encode_compound_hdr(xdr, req, &hdr);
2552 encode_sequence(xdr, &args->seq_args, &hdr);
2553 encode_putfh(xdr, args->fh, &hdr);
2554 encode_setattr(xdr, args, args->server, &hdr);
2555 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002556 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557}
2558
2559/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002560 * Encode a GETACL request
2561 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002562static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2563 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002564{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002565 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002566 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002567 };
Benny Halevy28f56692009-04-01 09:22:09 -04002568 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002569
Chuck Lever9f06c712010-12-14 14:59:18 +00002570 encode_compound_hdr(xdr, req, &hdr);
2571 encode_sequence(xdr, &args->seq_args, &hdr);
2572 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002573 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002574 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002575
Benny Halevy28f56692009-04-01 09:22:09 -04002576 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002577 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002578
Andy Adamsond0179312008-12-23 16:06:17 -05002579 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002580}
2581
2582/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 * Encode a WRITE request
2584 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002585static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2586 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002589 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591
Chuck Lever9f06c712010-12-14 14:59:18 +00002592 encode_compound_hdr(xdr, req, &hdr);
2593 encode_sequence(xdr, &args->seq_args, &hdr);
2594 encode_putfh(xdr, args->fh, &hdr);
2595 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002596 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002597 if (args->bitmask)
2598 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002599 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600}
2601
2602/*
2603 * a COMMIT request
2604 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002605static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2606 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002609 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611
Chuck Lever9f06c712010-12-14 14:59:18 +00002612 encode_compound_hdr(xdr, req, &hdr);
2613 encode_sequence(xdr, &args->seq_args, &hdr);
2614 encode_putfh(xdr, args->fh, &hdr);
2615 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002616 if (args->bitmask)
2617 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002618 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619}
2620
2621/*
2622 * FSINFO request
2623 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002624static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2625 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002628 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
Chuck Lever9f06c712010-12-14 14:59:18 +00002631 encode_compound_hdr(xdr, req, &hdr);
2632 encode_sequence(xdr, &args->seq_args, &hdr);
2633 encode_putfh(xdr, args->fh, &hdr);
2634 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002635 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636}
2637
2638/*
2639 * a PATHCONF request
2640 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002641static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2642 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002645 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
Chuck Lever9f06c712010-12-14 14:59:18 +00002648 encode_compound_hdr(xdr, req, &hdr);
2649 encode_sequence(xdr, &args->seq_args, &hdr);
2650 encode_putfh(xdr, args->fh, &hdr);
2651 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002652 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002653 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654}
2655
2656/*
2657 * a STATFS request
2658 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002659static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2660 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002663 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
Chuck Lever9f06c712010-12-14 14:59:18 +00002666 encode_compound_hdr(xdr, req, &hdr);
2667 encode_sequence(xdr, &args->seq_args, &hdr);
2668 encode_putfh(xdr, args->fh, &hdr);
2669 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002670 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002671 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672}
2673
2674/*
2675 * GETATTR_BITMAP request
2676 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002677static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2678 struct xdr_stream *xdr,
2679 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002682 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
Chuck Lever9f06c712010-12-14 14:59:18 +00002685 encode_compound_hdr(xdr, req, &hdr);
2686 encode_sequence(xdr, &args->seq_args, &hdr);
2687 encode_putfh(xdr, args->fhandle, &hdr);
2688 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002689 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002690 FATTR4_WORD0_LINK_SUPPORT|
2691 FATTR4_WORD0_SYMLINK_SUPPORT|
2692 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002693 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694}
2695
2696/*
2697 * a RENEW request
2698 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002699static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2700 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002703 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 };
2705
Chuck Lever9f06c712010-12-14 14:59:18 +00002706 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002707 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002708 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709}
2710
2711/*
2712 * a SETCLIENTID request
2713 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002714static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2715 struct xdr_stream *xdr,
2716 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002719 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 };
2721
Chuck Lever9f06c712010-12-14 14:59:18 +00002722 encode_compound_hdr(xdr, req, &hdr);
2723 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002724 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725}
2726
2727/*
2728 * a SETCLIENTID_CONFIRM request
2729 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002730static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2731 struct xdr_stream *xdr,
2732 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002735 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 };
Fred Isamandae100c2011-07-30 20:52:37 -04002737 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738
Chuck Lever9f06c712010-12-14 14:59:18 +00002739 encode_compound_hdr(xdr, req, &hdr);
2740 encode_setclientid_confirm(xdr, arg, &hdr);
2741 encode_putrootfh(xdr, &hdr);
2742 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002743 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744}
2745
2746/*
2747 * DELEGRETURN request
2748 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002749static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2750 struct xdr_stream *xdr,
2751 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002754 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756
Chuck Lever9f06c712010-12-14 14:59:18 +00002757 encode_compound_hdr(xdr, req, &hdr);
2758 encode_sequence(xdr, &args->seq_args, &hdr);
2759 encode_putfh(xdr, args->fhandle, &hdr);
2760 encode_delegreturn(xdr, args->stateid, &hdr);
2761 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002762 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763}
2764
2765/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002766 * Encode FS_LOCATIONS request
2767 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002768static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2769 struct xdr_stream *xdr,
2770 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002771{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002772 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002773 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002774 };
Benny Halevy28f56692009-04-01 09:22:09 -04002775 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002776
Chuck Lever9f06c712010-12-14 14:59:18 +00002777 encode_compound_hdr(xdr, req, &hdr);
2778 encode_sequence(xdr, &args->seq_args, &hdr);
2779 encode_putfh(xdr, args->dir_fh, &hdr);
2780 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002781 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002782 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002783
Benny Halevy28f56692009-04-01 09:22:09 -04002784 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002785 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002786 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002787}
2788
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002789/*
2790 * Encode SECINFO request
2791 */
2792static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2793 struct xdr_stream *xdr,
2794 struct nfs4_secinfo_arg *args)
2795{
2796 struct compound_hdr hdr = {
2797 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2798 };
2799
2800 encode_compound_hdr(xdr, req, &hdr);
2801 encode_sequence(xdr, &args->seq_args, &hdr);
2802 encode_putfh(xdr, args->dir_fh, &hdr);
2803 encode_secinfo(xdr, args->name, &hdr);
2804 encode_nops(&hdr);
2805}
2806
Benny Halevy99fe60d2009-04-01 09:22:29 -04002807#if defined(CONFIG_NFS_V4_1)
2808/*
2809 * EXCHANGE_ID request
2810 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002811static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2812 struct xdr_stream *xdr,
2813 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002814{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002815 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002816 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002817 };
2818
Chuck Lever9f06c712010-12-14 14:59:18 +00002819 encode_compound_hdr(xdr, req, &hdr);
2820 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002821 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002822}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002823
2824/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002825 * a CREATE_SESSION request
2826 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002827static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2828 struct xdr_stream *xdr,
2829 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002830{
Andy Adamsonfc931582009-04-01 09:22:31 -04002831 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002832 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002833 };
2834
Chuck Lever9f06c712010-12-14 14:59:18 +00002835 encode_compound_hdr(xdr, req, &hdr);
2836 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002837 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002838}
2839
2840/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002841 * a DESTROY_SESSION request
2842 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002843static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2844 struct xdr_stream *xdr,
2845 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002846{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002847 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002848 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002849 };
2850
Chuck Lever9f06c712010-12-14 14:59:18 +00002851 encode_compound_hdr(xdr, req, &hdr);
2852 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002853 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002854}
2855
2856/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002857 * a SEQUENCE request
2858 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002859static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2860 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002861{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002862 struct compound_hdr hdr = {
2863 .minorversion = nfs4_xdr_minorversion(args),
2864 };
2865
Chuck Lever9f06c712010-12-14 14:59:18 +00002866 encode_compound_hdr(xdr, req, &hdr);
2867 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002868 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002869}
2870
2871/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002872 * a GET_LEASE_TIME request
2873 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002874static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2875 struct xdr_stream *xdr,
2876 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002877{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002878 struct compound_hdr hdr = {
2879 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2880 };
Fred Isamandae100c2011-07-30 20:52:37 -04002881 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002882
Chuck Lever9f06c712010-12-14 14:59:18 +00002883 encode_compound_hdr(xdr, req, &hdr);
2884 encode_sequence(xdr, &args->la_seq_args, &hdr);
2885 encode_putrootfh(xdr, &hdr);
2886 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002887 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002888}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002889
2890/*
2891 * a RECLAIM_COMPLETE request
2892 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002893static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2894 struct xdr_stream *xdr,
2895 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002896{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002897 struct compound_hdr hdr = {
2898 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2899 };
2900
Chuck Lever9f06c712010-12-14 14:59:18 +00002901 encode_compound_hdr(xdr, req, &hdr);
2902 encode_sequence(xdr, &args->seq_args, &hdr);
2903 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002904 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002905}
2906
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002907/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002908 * Encode GETDEVICELIST request
2909 */
2910static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2911 struct xdr_stream *xdr,
2912 struct nfs4_getdevicelist_args *args)
2913{
2914 struct compound_hdr hdr = {
2915 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2916 };
2917
2918 encode_compound_hdr(xdr, req, &hdr);
2919 encode_sequence(xdr, &args->seq_args, &hdr);
2920 encode_putfh(xdr, args->fh, &hdr);
2921 encode_getdevicelist(xdr, args, &hdr);
2922 encode_nops(&hdr);
2923}
2924
2925/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002926 * Encode GETDEVICEINFO request
2927 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002928static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2929 struct xdr_stream *xdr,
2930 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002931{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002932 struct compound_hdr hdr = {
2933 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2934 };
2935
Chuck Lever9f06c712010-12-14 14:59:18 +00002936 encode_compound_hdr(xdr, req, &hdr);
2937 encode_sequence(xdr, &args->seq_args, &hdr);
2938 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002939
2940 /* set up reply kvec. Subtract notification bitmap max size (2)
2941 * so that notification bitmap is put in xdr_buf tail */
2942 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2943 args->pdev->pages, args->pdev->pgbase,
2944 args->pdev->pglen);
2945
2946 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002947}
2948
2949/*
2950 * Encode LAYOUTGET request
2951 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002952static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2953 struct xdr_stream *xdr,
2954 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002955{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002956 struct compound_hdr hdr = {
2957 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2958 };
2959
Chuck Lever9f06c712010-12-14 14:59:18 +00002960 encode_compound_hdr(xdr, req, &hdr);
2961 encode_sequence(xdr, &args->seq_args, &hdr);
2962 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2963 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002964
2965 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2966 args->layout.pages, 0, args->layout.pglen);
2967
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002968 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002969}
Andy Adamson863a3c62011-03-23 13:27:54 +00002970
2971/*
2972 * Encode LAYOUTCOMMIT request
2973 */
Benny Halevycbe82602011-05-22 19:52:37 +03002974static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2975 struct xdr_stream *xdr,
2976 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002977{
Benny Halevyac7db722011-05-22 19:53:48 +03002978 struct nfs4_layoutcommit_data *data =
2979 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002980 struct compound_hdr hdr = {
2981 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2982 };
2983
2984 encode_compound_hdr(xdr, req, &hdr);
2985 encode_sequence(xdr, &args->seq_args, &hdr);
2986 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002987 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002988 encode_getfattr(xdr, args->bitmask, &hdr);
2989 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002990}
2991
2992/*
2993 * Encode LAYOUTRETURN request
2994 */
2995static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2996 struct xdr_stream *xdr,
2997 struct nfs4_layoutreturn_args *args)
2998{
2999 struct compound_hdr hdr = {
3000 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3001 };
3002
3003 encode_compound_hdr(xdr, req, &hdr);
3004 encode_sequence(xdr, &args->seq_args, &hdr);
3005 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3006 encode_layoutreturn(xdr, args, &hdr);
3007 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003008}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003009
3010/*
3011 * Encode SECINFO_NO_NAME request
3012 */
3013static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3014 struct xdr_stream *xdr,
3015 struct nfs41_secinfo_no_name_args *args)
3016{
3017 struct compound_hdr hdr = {
3018 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3019 };
3020
3021 encode_compound_hdr(xdr, req, &hdr);
3022 encode_sequence(xdr, &args->seq_args, &hdr);
3023 encode_putrootfh(xdr, &hdr);
3024 encode_secinfo_no_name(xdr, args, &hdr);
3025 encode_nops(&hdr);
3026 return 0;
3027}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003028
3029/*
3030 * Encode TEST_STATEID request
3031 */
3032static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3033 struct xdr_stream *xdr,
3034 struct nfs41_test_stateid_args *args)
3035{
3036 struct compound_hdr hdr = {
3037 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3038 };
3039
3040 encode_compound_hdr(xdr, req, &hdr);
3041 encode_sequence(xdr, &args->seq_args, &hdr);
3042 encode_test_stateid(xdr, args, &hdr);
3043 encode_nops(&hdr);
3044}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003045
3046/*
3047 * Encode FREE_STATEID request
3048 */
3049static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3050 struct xdr_stream *xdr,
3051 struct nfs41_free_stateid_args *args)
3052{
3053 struct compound_hdr hdr = {
3054 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3055 };
3056
3057 encode_compound_hdr(xdr, req, &hdr);
3058 encode_sequence(xdr, &args->seq_args, &hdr);
3059 encode_free_stateid(xdr, args, &hdr);
3060 encode_nops(&hdr);
3061}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003062#endif /* CONFIG_NFS_V4_1 */
3063
Benny Halevy686841b2009-08-14 17:19:48 +03003064static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3065{
3066 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3067 "Remaining buffer length is %tu words.\n",
3068 func, xdr->end - xdr->p);
3069}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070
Trond Myklebust683b57b2006-06-09 09:34:22 -04003071static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072{
Al Viro8687b632006-10-19 23:28:48 -07003073 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074
Benny Halevyc0eae662009-08-14 17:20:14 +03003075 p = xdr_inline_decode(xdr, 4);
3076 if (unlikely(!p))
3077 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003078 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003079 p = xdr_inline_decode(xdr, *len);
3080 if (unlikely(!p))
3081 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 *string = (char *)p;
3083 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003084out_overflow:
3085 print_overflow_msg(__func__, xdr);
3086 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087}
3088
3089static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3090{
Al Viro8687b632006-10-19 23:28:48 -07003091 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092
Benny Halevyc0eae662009-08-14 17:20:14 +03003093 p = xdr_inline_decode(xdr, 8);
3094 if (unlikely(!p))
3095 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003096 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003097 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003098
Benny Halevyc0eae662009-08-14 17:20:14 +03003099 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3100 if (unlikely(!p))
3101 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 hdr->tag = (char *)p;
3103 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003104 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003105 if (unlikely(hdr->nops < 1))
3106 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003108out_overflow:
3109 print_overflow_msg(__func__, xdr);
3110 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111}
3112
3113static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3114{
Al Viro8687b632006-10-19 23:28:48 -07003115 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 uint32_t opnum;
3117 int32_t nfserr;
3118
Benny Halevyc0eae662009-08-14 17:20:14 +03003119 p = xdr_inline_decode(xdr, 8);
3120 if (unlikely(!p))
3121 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003122 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003124 dprintk("nfs: Server returned operation"
3125 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 opnum, expected);
3127 return -EIO;
3128 }
Benny Halevycccddf42009-08-14 17:20:19 +03003129 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003131 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003133out_overflow:
3134 print_overflow_msg(__func__, xdr);
3135 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136}
3137
3138/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003139static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140{
Al Viro8687b632006-10-19 23:28:48 -07003141 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003142 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 char *str;
3144
Benny Halevyc0eae662009-08-14 17:20:14 +03003145 p = xdr_inline_decode(xdr, 12);
3146 if (likely(p))
3147 return decode_opaque_inline(xdr, &strlen, &str);
3148 print_overflow_msg(__func__, xdr);
3149 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150}
3151
3152static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3153{
Al Viro8687b632006-10-19 23:28:48 -07003154 uint32_t bmlen;
3155 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156
Benny Halevyc0eae662009-08-14 17:20:14 +03003157 p = xdr_inline_decode(xdr, 4);
3158 if (unlikely(!p))
3159 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003160 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161
Fred Isamandae100c2011-07-30 20:52:37 -04003162 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003163 p = xdr_inline_decode(xdr, (bmlen << 2));
3164 if (unlikely(!p))
3165 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003167 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003168 if (bmlen > 1) {
3169 bitmap[1] = be32_to_cpup(p++);
3170 if (bmlen > 2)
3171 bitmap[2] = be32_to_cpup(p);
3172 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 }
3174 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003175out_overflow:
3176 print_overflow_msg(__func__, xdr);
3177 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178}
3179
Al Viro8687b632006-10-19 23:28:48 -07003180static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181{
Al Viro8687b632006-10-19 23:28:48 -07003182 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183
Benny Halevyc0eae662009-08-14 17:20:14 +03003184 p = xdr_inline_decode(xdr, 4);
3185 if (unlikely(!p))
3186 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003187 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 *savep = xdr->p;
3189 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003190out_overflow:
3191 print_overflow_msg(__func__, xdr);
3192 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193}
3194
3195static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3196{
3197 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003198 int ret;
3199 ret = decode_attr_bitmap(xdr, bitmask);
3200 if (unlikely(ret < 0))
3201 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3203 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003204 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3205 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3206 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 return 0;
3208}
3209
3210static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3211{
Al Viro8687b632006-10-19 23:28:48 -07003212 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003213 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214
3215 *type = 0;
3216 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3217 return -EIO;
3218 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003219 p = xdr_inline_decode(xdr, 4);
3220 if (unlikely(!p))
3221 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003222 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003224 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 return -EIO;
3226 }
3227 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003228 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003230 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003231 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003232out_overflow:
3233 print_overflow_msg(__func__, xdr);
3234 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235}
3236
Chuck Lever264e6352012-03-01 17:02:05 -05003237static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3238 uint32_t *bitmap, uint32_t *type)
3239{
3240 __be32 *p;
3241
3242 *type = 0;
3243 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3244 return -EIO;
3245 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3246 p = xdr_inline_decode(xdr, 4);
3247 if (unlikely(!p))
3248 goto out_overflow;
3249 *type = be32_to_cpup(p);
3250 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3251 }
3252 dprintk("%s: expire type=0x%x\n", __func__, *type);
3253 return 0;
3254out_overflow:
3255 print_overflow_msg(__func__, xdr);
3256 return -EIO;
3257}
3258
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3260{
Al Viro8687b632006-10-19 23:28:48 -07003261 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003262 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263
3264 *change = 0;
3265 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3266 return -EIO;
3267 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003268 p = xdr_inline_decode(xdr, 8);
3269 if (unlikely(!p))
3270 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003271 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003273 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003275 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003277 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003278out_overflow:
3279 print_overflow_msg(__func__, xdr);
3280 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281}
3282
3283static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3284{
Al Viro8687b632006-10-19 23:28:48 -07003285 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003286 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287
3288 *size = 0;
3289 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3290 return -EIO;
3291 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003292 p = xdr_inline_decode(xdr, 8);
3293 if (unlikely(!p))
3294 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003295 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003297 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003299 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003300 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003301out_overflow:
3302 print_overflow_msg(__func__, xdr);
3303 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304}
3305
3306static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3307{
Al Viro8687b632006-10-19 23:28:48 -07003308 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309
3310 *res = 0;
3311 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3312 return -EIO;
3313 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003314 p = xdr_inline_decode(xdr, 4);
3315 if (unlikely(!p))
3316 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003317 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3319 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003320 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003322out_overflow:
3323 print_overflow_msg(__func__, xdr);
3324 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325}
3326
3327static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3328{
Al Viro8687b632006-10-19 23:28:48 -07003329 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330
3331 *res = 0;
3332 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3333 return -EIO;
3334 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003335 p = xdr_inline_decode(xdr, 4);
3336 if (unlikely(!p))
3337 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003338 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3340 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003341 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003343out_overflow:
3344 print_overflow_msg(__func__, xdr);
3345 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346}
3347
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003348static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349{
Al Viro8687b632006-10-19 23:28:48 -07003350 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003351 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352
3353 fsid->major = 0;
3354 fsid->minor = 0;
3355 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3356 return -EIO;
3357 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003358 p = xdr_inline_decode(xdr, 16);
3359 if (unlikely(!p))
3360 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003361 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003362 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003364 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003366 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 (unsigned long long)fsid->major,
3368 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003369 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003370out_overflow:
3371 print_overflow_msg(__func__, xdr);
3372 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373}
3374
3375static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3376{
Al Viro8687b632006-10-19 23:28:48 -07003377 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
3379 *res = 60;
3380 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3381 return -EIO;
3382 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003383 p = xdr_inline_decode(xdr, 4);
3384 if (unlikely(!p))
3385 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003386 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3388 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003389 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003391out_overflow:
3392 print_overflow_msg(__func__, xdr);
3393 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394}
3395
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003396static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003397{
3398 __be32 *p;
3399
3400 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3401 return -EIO;
3402 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3403 p = xdr_inline_decode(xdr, 4);
3404 if (unlikely(!p))
3405 goto out_overflow;
3406 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003407 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003408 }
3409 return 0;
3410out_overflow:
3411 print_overflow_msg(__func__, xdr);
3412 return -EIO;
3413}
3414
3415static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3416{
3417 __be32 *p;
3418 int len;
3419
Trond Myklebust7ad07352010-10-23 15:34:20 -04003420 if (fh != NULL)
3421 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003422
3423 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3424 return -EIO;
3425 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3426 p = xdr_inline_decode(xdr, 4);
3427 if (unlikely(!p))
3428 goto out_overflow;
3429 len = be32_to_cpup(p);
3430 if (len > NFS4_FHSIZE)
3431 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003432 p = xdr_inline_decode(xdr, len);
3433 if (unlikely(!p))
3434 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003435 if (fh != NULL) {
3436 memcpy(fh->data, p, len);
3437 fh->size = len;
3438 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003439 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3440 }
3441 return 0;
3442out_overflow:
3443 print_overflow_msg(__func__, xdr);
3444 return -EIO;
3445}
3446
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3448{
Al Viro8687b632006-10-19 23:28:48 -07003449 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450
3451 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3452 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3453 return -EIO;
3454 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003455 p = xdr_inline_decode(xdr, 4);
3456 if (unlikely(!p))
3457 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003458 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3460 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003461 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003463out_overflow:
3464 print_overflow_msg(__func__, xdr);
3465 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466}
3467
3468static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3469{
Al Viro8687b632006-10-19 23:28:48 -07003470 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003471 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
3473 *fileid = 0;
3474 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3475 return -EIO;
3476 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003477 p = xdr_inline_decode(xdr, 8);
3478 if (unlikely(!p))
3479 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003480 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003482 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003484 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003485 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003486out_overflow:
3487 print_overflow_msg(__func__, xdr);
3488 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489}
3490
Manoj Naik99baf622006-06-09 09:34:24 -04003491static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3492{
Al Viro8687b632006-10-19 23:28:48 -07003493 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003494 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003495
3496 *fileid = 0;
3497 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3498 return -EIO;
3499 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003500 p = xdr_inline_decode(xdr, 8);
3501 if (unlikely(!p))
3502 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003503 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003504 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003505 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003506 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003507 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003508 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003509out_overflow:
3510 print_overflow_msg(__func__, xdr);
3511 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003512}
3513
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3515{
Al Viro8687b632006-10-19 23:28:48 -07003516 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 int status = 0;
3518
3519 *res = 0;
3520 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3521 return -EIO;
3522 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003523 p = xdr_inline_decode(xdr, 8);
3524 if (unlikely(!p))
3525 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003526 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3528 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003529 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003531out_overflow:
3532 print_overflow_msg(__func__, xdr);
3533 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534}
3535
3536static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3537{
Al Viro8687b632006-10-19 23:28:48 -07003538 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 int status = 0;
3540
3541 *res = 0;
3542 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3543 return -EIO;
3544 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003545 p = xdr_inline_decode(xdr, 8);
3546 if (unlikely(!p))
3547 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003548 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3550 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003551 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003553out_overflow:
3554 print_overflow_msg(__func__, xdr);
3555 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556}
3557
3558static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3559{
Al Viro8687b632006-10-19 23:28:48 -07003560 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561 int status = 0;
3562
3563 *res = 0;
3564 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3565 return -EIO;
3566 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003567 p = xdr_inline_decode(xdr, 8);
3568 if (unlikely(!p))
3569 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003570 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3572 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003573 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003575out_overflow:
3576 print_overflow_msg(__func__, xdr);
3577 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578}
3579
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003580static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3581{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003582 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003583 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003584 int status = 0;
3585
Benny Halevyc0eae662009-08-14 17:20:14 +03003586 p = xdr_inline_decode(xdr, 4);
3587 if (unlikely(!p))
3588 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003589 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003590 if (n == 0)
3591 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003592 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003593 path->ncomponents = 0;
3594 while (path->ncomponents < n) {
3595 struct nfs4_string *component = &path->components[path->ncomponents];
3596 status = decode_opaque_inline(xdr, &component->len, &component->data);
3597 if (unlikely(status != 0))
3598 goto out_eio;
Chuck Lever02a29762012-03-01 17:00:31 -05003599 if (unlikely(nfs_debug & NFSDBG_XDR))
3600 pr_cont("%s%.*s ",
3601 (path->ncomponents != n ? "/ " : ""),
3602 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003603 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3604 path->ncomponents++;
3605 else {
3606 dprintk("cannot parse %d components in path\n", n);
3607 goto out_eio;
3608 }
3609 }
3610out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003611 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003612root_path:
3613/* a root pathname is sent as a zero component4 */
3614 path->ncomponents = 1;
3615 path->components[0].len=0;
3616 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003617 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003618 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003619out_eio:
3620 dprintk(" status %d", status);
3621 status = -EIO;
3622 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003623out_overflow:
3624 print_overflow_msg(__func__, xdr);
3625 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003626}
3627
3628static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003629{
3630 int n;
Al Viro8687b632006-10-19 23:28:48 -07003631 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003632 int status = -EIO;
3633
3634 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3635 goto out;
3636 status = 0;
3637 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3638 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003639 status = -EIO;
3640 /* Ignore borken servers that return unrequested attrs */
3641 if (unlikely(res == NULL))
3642 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003643 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003644 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003645 if (unlikely(status != 0))
3646 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003647 p = xdr_inline_decode(xdr, 4);
3648 if (unlikely(!p))
3649 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003650 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003651 if (n <= 0)
3652 goto out_eio;
3653 res->nlocations = 0;
3654 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003655 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003656 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003657
Benny Halevyc0eae662009-08-14 17:20:14 +03003658 p = xdr_inline_decode(xdr, 4);
3659 if (unlikely(!p))
3660 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003661 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003662
3663 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003664 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003665 while (loc->nservers < m) {
3666 struct nfs4_string *server = &loc->servers[loc->nservers];
3667 status = decode_opaque_inline(xdr, &server->len, &server->data);
3668 if (unlikely(status != 0))
3669 goto out_eio;
3670 dprintk("%s ", server->data);
3671 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3672 loc->nservers++;
3673 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003674 unsigned int i;
3675 dprintk("%s: using first %u of %u servers "
3676 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003677 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003678 NFS4_FS_LOCATION_MAXSERVERS,
3679 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003680 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003681 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003682 char *data;
3683 status = decode_opaque_inline(xdr, &len, &data);
3684 if (unlikely(status != 0))
3685 goto out_eio;
3686 }
3687 }
3688 }
3689 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003690 if (unlikely(status != 0))
3691 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003692 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003693 res->nlocations++;
3694 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003695 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003696 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003697out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003698 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003699 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003700out_overflow:
3701 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003702out_eio:
3703 status = -EIO;
3704 goto out;
3705}
3706
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3708{
Al Viro8687b632006-10-19 23:28:48 -07003709 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 int status = 0;
3711
3712 *res = 0;
3713 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3714 return -EIO;
3715 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003716 p = xdr_inline_decode(xdr, 8);
3717 if (unlikely(!p))
3718 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003719 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3721 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003722 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003724out_overflow:
3725 print_overflow_msg(__func__, xdr);
3726 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727}
3728
3729static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3730{
Al Viro8687b632006-10-19 23:28:48 -07003731 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 int status = 0;
3733
3734 *maxlink = 1;
3735 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3736 return -EIO;
3737 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003738 p = xdr_inline_decode(xdr, 4);
3739 if (unlikely(!p))
3740 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003741 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3743 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003744 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003746out_overflow:
3747 print_overflow_msg(__func__, xdr);
3748 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749}
3750
3751static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3752{
Al Viro8687b632006-10-19 23:28:48 -07003753 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 int status = 0;
3755
3756 *maxname = 1024;
3757 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3758 return -EIO;
3759 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003760 p = xdr_inline_decode(xdr, 4);
3761 if (unlikely(!p))
3762 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003763 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3765 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003766 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003768out_overflow:
3769 print_overflow_msg(__func__, xdr);
3770 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771}
3772
3773static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3774{
Al Viro8687b632006-10-19 23:28:48 -07003775 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 int status = 0;
3777
3778 *res = 1024;
3779 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3780 return -EIO;
3781 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3782 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003783 p = xdr_inline_decode(xdr, 8);
3784 if (unlikely(!p))
3785 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003786 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 if (maxread > 0x7FFFFFFF)
3788 maxread = 0x7FFFFFFF;
3789 *res = (uint32_t)maxread;
3790 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3791 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003792 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003794out_overflow:
3795 print_overflow_msg(__func__, xdr);
3796 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797}
3798
3799static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3800{
Al Viro8687b632006-10-19 23:28:48 -07003801 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 int status = 0;
3803
3804 *res = 1024;
3805 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3806 return -EIO;
3807 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3808 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003809 p = xdr_inline_decode(xdr, 8);
3810 if (unlikely(!p))
3811 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003812 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 if (maxwrite > 0x7FFFFFFF)
3814 maxwrite = 0x7FFFFFFF;
3815 *res = (uint32_t)maxwrite;
3816 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3817 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003818 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003820out_overflow:
3821 print_overflow_msg(__func__, xdr);
3822 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823}
3824
Trond Myklebustbca79472009-03-11 14:10:26 -04003825static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826{
Trond Myklebustbca79472009-03-11 14:10:26 -04003827 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003828 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003829 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830
3831 *mode = 0;
3832 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3833 return -EIO;
3834 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003835 p = xdr_inline_decode(xdr, 4);
3836 if (unlikely(!p))
3837 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003838 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003839 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003841 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003843 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003844 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003845out_overflow:
3846 print_overflow_msg(__func__, xdr);
3847 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848}
3849
3850static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3851{
Al Viro8687b632006-10-19 23:28:48 -07003852 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003853 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854
3855 *nlink = 1;
3856 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3857 return -EIO;
3858 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003859 p = xdr_inline_decode(xdr, 4);
3860 if (unlikely(!p))
3861 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003862 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003864 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003866 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003867 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003868out_overflow:
3869 print_overflow_msg(__func__, xdr);
3870 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871}
3872
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003873static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003874 const struct nfs_server *server, uint32_t *uid,
3875 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876{
Al Viro8687b632006-10-19 23:28:48 -07003877 uint32_t len;
3878 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003879 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880
3881 *uid = -2;
3882 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3883 return -EIO;
3884 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003885 p = xdr_inline_decode(xdr, 4);
3886 if (unlikely(!p))
3887 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003888 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003889 p = xdr_inline_decode(xdr, len);
3890 if (unlikely(!p))
3891 goto out_overflow;
Trond Myklebust6926afd12012-01-07 13:22:46 -05003892 if (owner_name != NULL) {
3893 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3894 if (owner_name->data != NULL) {
3895 owner_name->len = len;
3896 ret = NFS_ATTR_FATTR_OWNER_NAME;
3897 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003898 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003899 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003900 ret = NFS_ATTR_FATTR_OWNER;
3901 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003903 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003905 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003906 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3908 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003909 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003910 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003911out_overflow:
3912 print_overflow_msg(__func__, xdr);
3913 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914}
3915
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003916static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003917 const struct nfs_server *server, uint32_t *gid,
3918 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919{
Al Viro8687b632006-10-19 23:28:48 -07003920 uint32_t len;
3921 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003922 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923
3924 *gid = -2;
3925 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3926 return -EIO;
3927 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003928 p = xdr_inline_decode(xdr, 4);
3929 if (unlikely(!p))
3930 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003931 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003932 p = xdr_inline_decode(xdr, len);
3933 if (unlikely(!p))
3934 goto out_overflow;
Trond Myklebust6926afd12012-01-07 13:22:46 -05003935 if (group_name != NULL) {
3936 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3937 if (group_name->data != NULL) {
3938 group_name->len = len;
3939 ret = NFS_ATTR_FATTR_GROUP_NAME;
3940 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003941 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003942 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003943 ret = NFS_ATTR_FATTR_GROUP;
3944 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003946 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003948 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003949 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3951 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003952 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003953 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003954out_overflow:
3955 print_overflow_msg(__func__, xdr);
3956 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957}
3958
3959static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3960{
Al Viro8687b632006-10-19 23:28:48 -07003961 uint32_t major = 0, minor = 0;
3962 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003963 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964
3965 *rdev = MKDEV(0,0);
3966 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3967 return -EIO;
3968 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3969 dev_t tmp;
3970
Benny Halevyc0eae662009-08-14 17:20:14 +03003971 p = xdr_inline_decode(xdr, 8);
3972 if (unlikely(!p))
3973 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003974 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003975 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 tmp = MKDEV(major, minor);
3977 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3978 *rdev = tmp;
3979 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003980 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003982 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003983 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003984out_overflow:
3985 print_overflow_msg(__func__, xdr);
3986 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987}
3988
3989static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3990{
Al Viro8687b632006-10-19 23:28:48 -07003991 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 int status = 0;
3993
3994 *res = 0;
3995 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3996 return -EIO;
3997 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003998 p = xdr_inline_decode(xdr, 8);
3999 if (unlikely(!p))
4000 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004001 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4003 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004004 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004006out_overflow:
4007 print_overflow_msg(__func__, xdr);
4008 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009}
4010
4011static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4012{
Al Viro8687b632006-10-19 23:28:48 -07004013 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 int status = 0;
4015
4016 *res = 0;
4017 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4018 return -EIO;
4019 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004020 p = xdr_inline_decode(xdr, 8);
4021 if (unlikely(!p))
4022 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004023 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4025 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004026 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004028out_overflow:
4029 print_overflow_msg(__func__, xdr);
4030 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031}
4032
4033static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4034{
Al Viro8687b632006-10-19 23:28:48 -07004035 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 int status = 0;
4037
4038 *res = 0;
4039 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4040 return -EIO;
4041 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004042 p = xdr_inline_decode(xdr, 8);
4043 if (unlikely(!p))
4044 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004045 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4047 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004048 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004050out_overflow:
4051 print_overflow_msg(__func__, xdr);
4052 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053}
4054
4055static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4056{
Al Viro8687b632006-10-19 23:28:48 -07004057 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004058 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059
4060 *used = 0;
4061 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4062 return -EIO;
4063 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004064 p = xdr_inline_decode(xdr, 8);
4065 if (unlikely(!p))
4066 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004067 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004069 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004071 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004073 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004074out_overflow:
4075 print_overflow_msg(__func__, xdr);
4076 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077}
4078
4079static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4080{
Al Viro8687b632006-10-19 23:28:48 -07004081 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 uint64_t sec;
4083 uint32_t nsec;
4084
Benny Halevyc0eae662009-08-14 17:20:14 +03004085 p = xdr_inline_decode(xdr, 12);
4086 if (unlikely(!p))
4087 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004088 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004089 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 time->tv_sec = (time_t)sec;
4091 time->tv_nsec = (long)nsec;
4092 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004093out_overflow:
4094 print_overflow_msg(__func__, xdr);
4095 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096}
4097
4098static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4099{
4100 int status = 0;
4101
4102 time->tv_sec = 0;
4103 time->tv_nsec = 0;
4104 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4105 return -EIO;
4106 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4107 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004108 if (status == 0)
4109 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4111 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004112 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 return status;
4114}
4115
4116static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4117{
4118 int status = 0;
4119
4120 time->tv_sec = 0;
4121 time->tv_nsec = 0;
4122 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4123 return -EIO;
4124 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4125 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004126 if (status == 0)
4127 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4129 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004130 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 return status;
4132}
4133
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004134static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4135 struct timespec *time)
4136{
4137 int status = 0;
4138
4139 time->tv_sec = 0;
4140 time->tv_nsec = 0;
4141 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4142 return -EIO;
4143 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4144 status = decode_attr_time(xdr, time);
4145 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4146 }
4147 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4148 (long)time->tv_nsec);
4149 return status;
4150}
4151
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4153{
4154 int status = 0;
4155
4156 time->tv_sec = 0;
4157 time->tv_nsec = 0;
4158 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4159 return -EIO;
4160 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4161 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004162 if (status == 0)
4163 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4165 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004166 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 return status;
4168}
4169
Al Viro8687b632006-10-19 23:28:48 -07004170static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171{
4172 unsigned int attrwords = XDR_QUADLEN(attrlen);
4173 unsigned int nwords = xdr->p - savep;
4174
4175 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004176 dprintk("%s: server returned incorrect attribute length: "
4177 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004178 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 attrwords << 2,
4180 (attrwords < nwords) ? '<' : '>',
4181 nwords << 2);
4182 return -EIO;
4183 }
4184 return 0;
4185}
4186
4187static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4188{
Al Viro8687b632006-10-19 23:28:48 -07004189 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190
Benny Halevyc0eae662009-08-14 17:20:14 +03004191 p = xdr_inline_decode(xdr, 20);
4192 if (unlikely(!p))
4193 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004194 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004195 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004196 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004198out_overflow:
4199 print_overflow_msg(__func__, xdr);
4200 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201}
4202
4203static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4204{
Al Viro8687b632006-10-19 23:28:48 -07004205 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 uint32_t supp, acc;
4207 int status;
4208
4209 status = decode_op_hdr(xdr, OP_ACCESS);
4210 if (status)
4211 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004212 p = xdr_inline_decode(xdr, 8);
4213 if (unlikely(!p))
4214 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004215 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004216 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 access->supported = supp;
4218 access->access = acc;
4219 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004220out_overflow:
4221 print_overflow_msg(__func__, xdr);
4222 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223}
4224
Benny Halevy07d30432009-08-14 17:19:52 +03004225static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226{
Al Viro8687b632006-10-19 23:28:48 -07004227 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004228
4229 p = xdr_inline_decode(xdr, len);
4230 if (likely(p)) {
4231 memcpy(buf, p, len);
4232 return 0;
4233 }
4234 print_overflow_msg(__func__, xdr);
4235 return -EIO;
4236}
4237
4238static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4239{
4240 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241}
4242
4243static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4244{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 int status;
4246
4247 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004248 if (status != -EIO)
4249 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004250 if (!status)
4251 status = decode_stateid(xdr, &res->stateid);
4252 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253}
4254
Benny Halevydb942bb2009-08-14 17:19:56 +03004255static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4256{
4257 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258}
4259
4260static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4261{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262 int status;
4263
4264 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004265 if (!status)
4266 status = decode_verifier(xdr, res->verf->verifier);
4267 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268}
4269
4270static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4271{
Al Viro8687b632006-10-19 23:28:48 -07004272 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 uint32_t bmlen;
4274 int status;
4275
4276 status = decode_op_hdr(xdr, OP_CREATE);
4277 if (status)
4278 return status;
4279 if ((status = decode_change_info(xdr, cinfo)))
4280 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004281 p = xdr_inline_decode(xdr, 4);
4282 if (unlikely(!p))
4283 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004284 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004285 p = xdr_inline_decode(xdr, bmlen << 2);
4286 if (likely(p))
4287 return 0;
4288out_overflow:
4289 print_overflow_msg(__func__, xdr);
4290 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291}
4292
4293static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4294{
Al Viro8687b632006-10-19 23:28:48 -07004295 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004296 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 int status;
4298
4299 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4300 goto xdr_error;
4301 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4302 goto xdr_error;
4303 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4304 goto xdr_error;
4305 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4306 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004307 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4308 &res->fh_expire_type)) != 0)
4309 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4311 goto xdr_error;
4312 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4313 goto xdr_error;
4314 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4315 goto xdr_error;
4316 status = verify_attr_len(xdr, savep, attrlen);
4317xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004318 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319 return status;
4320}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004321
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4323{
Al Viro8687b632006-10-19 23:28:48 -07004324 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004325 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004327
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4329 goto xdr_error;
4330 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4331 goto xdr_error;
4332 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4333 goto xdr_error;
4334
4335 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4336 goto xdr_error;
4337 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4338 goto xdr_error;
4339 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4340 goto xdr_error;
4341 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4342 goto xdr_error;
4343 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4344 goto xdr_error;
4345 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4346 goto xdr_error;
4347
4348 status = verify_attr_len(xdr, savep, attrlen);
4349xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004350 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351 return status;
4352}
4353
4354static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4355{
Al Viro8687b632006-10-19 23:28:48 -07004356 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004357 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004359
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4361 goto xdr_error;
4362 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4363 goto xdr_error;
4364 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4365 goto xdr_error;
4366
4367 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4368 goto xdr_error;
4369 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4370 goto xdr_error;
4371
4372 status = verify_attr_len(xdr, savep, attrlen);
4373xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004374 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375 return status;
4376}
4377
Bryan Schumakerae42c702010-10-21 16:33:17 -04004378static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4379 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004380 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004381 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382{
Trond Myklebustbca79472009-03-11 14:10:26 -04004383 int status;
4384 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004385 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004386 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004388 status = decode_attr_type(xdr, bitmap, &type);
4389 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004391 fattr->mode = 0;
4392 if (status != 0) {
4393 fattr->mode |= nfs_type2fmt[type];
4394 fattr->valid |= status;
4395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004397 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4398 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004400 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004401
4402 status = decode_attr_size(xdr, bitmap, &fattr->size);
4403 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004405 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004406
4407 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4408 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004410 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004411
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004412 err = 0;
4413 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004414 if (status < 0)
4415 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004416 if (err == -NFS4ERR_WRONGSEC)
4417 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004418
4419 status = decode_attr_filehandle(xdr, bitmap, fh);
4420 if (status < 0)
4421 goto xdr_error;
4422
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004423 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4424 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004426 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004427
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004428 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004429 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004430 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004431 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004432
4433 status = decode_attr_mode(xdr, bitmap, &fmode);
4434 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004436 if (status != 0) {
4437 fattr->mode |= fmode;
4438 fattr->valid |= status;
4439 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004440
4441 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4442 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004444 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004445
Trond Myklebust6926afd12012-01-07 13:22:46 -05004446 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004447 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004449 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004450
Trond Myklebust6926afd12012-01-07 13:22:46 -05004451 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004452 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004454 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004455
4456 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4457 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004459 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004460
4461 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4462 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004464 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004465
4466 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4467 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004469 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004470
4471 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4472 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004474 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004475
4476 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4477 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004479 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004480
Trond Myklebust28331a42011-04-27 13:47:52 -04004481 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004482 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004483 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004484 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004485
Bryan Schumakerae42c702010-10-21 16:33:17 -04004486xdr_error:
4487 dprintk("%s: xdr returned %d\n", __func__, -status);
4488 return status;
4489}
4490
4491static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004492 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4493 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004494{
4495 __be32 *savep;
4496 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004497 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004498 int status;
4499
4500 status = decode_op_hdr(xdr, OP_GETATTR);
4501 if (status < 0)
4502 goto xdr_error;
4503
4504 status = decode_attr_bitmap(xdr, bitmap);
4505 if (status < 0)
4506 goto xdr_error;
4507
4508 status = decode_attr_length(xdr, &attrlen, &savep);
4509 if (status < 0)
4510 goto xdr_error;
4511
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004512 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004513 if (status < 0)
4514 goto xdr_error;
4515
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004516 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004518 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 return status;
4520}
4521
Bryan Schumakerae42c702010-10-21 16:33:17 -04004522static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004523 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004524{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004525 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004526}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527
Andy Adamson504913f2010-10-20 00:17:57 -04004528/*
4529 * Decode potentially multiple layout types. Currently we only support
4530 * one layout driver per file system.
4531 */
4532static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4533 uint32_t *layouttype)
4534{
4535 uint32_t *p;
4536 int num;
4537
4538 p = xdr_inline_decode(xdr, 4);
4539 if (unlikely(!p))
4540 goto out_overflow;
4541 num = be32_to_cpup(p);
4542
4543 /* pNFS is not supported by the underlying file system */
4544 if (num == 0) {
4545 *layouttype = 0;
4546 return 0;
4547 }
4548 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004549 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4550 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004551
4552 /* Decode and set first layout type, move xdr->p past unused types */
4553 p = xdr_inline_decode(xdr, num * 4);
4554 if (unlikely(!p))
4555 goto out_overflow;
4556 *layouttype = be32_to_cpup(p);
4557 return 0;
4558out_overflow:
4559 print_overflow_msg(__func__, xdr);
4560 return -EIO;
4561}
4562
4563/*
4564 * The type of file system exported.
4565 * Note we must ensure that layouttype is set in any non-error case.
4566 */
4567static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4568 uint32_t *layouttype)
4569{
4570 int status = 0;
4571
4572 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4573 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4574 return -EIO;
4575 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4576 status = decode_first_pnfs_layout_type(xdr, layouttype);
4577 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4578 } else
4579 *layouttype = 0;
4580 return status;
4581}
4582
Fred Isamandae100c2011-07-30 20:52:37 -04004583/*
4584 * The prefered block size for layout directed io
4585 */
4586static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4587 uint32_t *res)
4588{
4589 __be32 *p;
4590
4591 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4592 *res = 0;
4593 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4594 p = xdr_inline_decode(xdr, 4);
4595 if (unlikely(!p)) {
4596 print_overflow_msg(__func__, xdr);
4597 return -EIO;
4598 }
4599 *res = be32_to_cpup(p);
4600 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4601 }
4602 return 0;
4603}
4604
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4606{
Al Viro8687b632006-10-19 23:28:48 -07004607 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004608 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004609 int status;
4610
4611 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4612 goto xdr_error;
4613 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4614 goto xdr_error;
4615 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4616 goto xdr_error;
4617
4618 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4619
4620 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4621 goto xdr_error;
4622 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4623 goto xdr_error;
4624 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4625 goto xdr_error;
4626 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4627 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4628 goto xdr_error;
4629 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004630 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4631 if (status != 0)
4632 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004633 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4634 if (status != 0)
4635 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004636 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4637 if (status)
4638 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639
4640 status = verify_attr_len(xdr, savep, attrlen);
4641xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004642 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004643 return status;
4644}
4645
4646static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4647{
Al Viro8687b632006-10-19 23:28:48 -07004648 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649 uint32_t len;
4650 int status;
4651
Trond Myklebust99367812007-07-17 21:52:41 -04004652 /* Zero handle first to allow comparisons */
4653 memset(fh, 0, sizeof(*fh));
4654
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 status = decode_op_hdr(xdr, OP_GETFH);
4656 if (status)
4657 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658
Benny Halevyc0eae662009-08-14 17:20:14 +03004659 p = xdr_inline_decode(xdr, 4);
4660 if (unlikely(!p))
4661 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004662 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004663 if (len > NFS4_FHSIZE)
4664 return -EIO;
4665 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004666 p = xdr_inline_decode(xdr, len);
4667 if (unlikely(!p))
4668 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004669 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004671out_overflow:
4672 print_overflow_msg(__func__, xdr);
4673 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674}
4675
4676static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4677{
4678 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004679
Linus Torvalds1da177e2005-04-16 15:20:36 -07004680 status = decode_op_hdr(xdr, OP_LINK);
4681 if (status)
4682 return status;
4683 return decode_change_info(xdr, cinfo);
4684}
4685
4686/*
4687 * We create the owner, so we know a proper owner.id length is 4.
4688 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004689static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004691 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004692 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004693 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004694
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004695 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004696 if (unlikely(!p))
4697 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004698 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004699 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004700 type = be32_to_cpup(p++); /* 4 byte read */
4701 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004702 fl->fl_start = (loff_t)offset;
4703 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4704 if (length == ~(uint64_t)0)
4705 fl->fl_end = OFFSET_MAX;
4706 fl->fl_type = F_WRLCK;
4707 if (type & 1)
4708 fl->fl_type = F_RDLCK;
4709 fl->fl_pid = 0;
4710 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004711 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4712 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4713 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004714 if (likely(p))
4715 return -NFS4ERR_DENIED;
4716out_overflow:
4717 print_overflow_msg(__func__, xdr);
4718 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719}
4720
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004721static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 int status;
4724
4725 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004726 if (status == -EIO)
4727 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004729 status = decode_stateid(xdr, &res->stateid);
4730 if (unlikely(status))
4731 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004733 status = decode_lock_denied(xdr, NULL);
4734 if (res->open_seqid != NULL)
4735 nfs_increment_open_seqid(status, res->open_seqid);
4736 nfs_increment_lock_seqid(status, res->lock_seqid);
4737out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004738 return status;
4739}
4740
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004741static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742{
4743 int status;
4744 status = decode_op_hdr(xdr, OP_LOCKT);
4745 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004746 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747 return status;
4748}
4749
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004750static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752 int status;
4753
4754 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004755 if (status != -EIO)
4756 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004757 if (status == 0)
4758 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759 return status;
4760}
4761
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004762static int decode_release_lockowner(struct xdr_stream *xdr)
4763{
4764 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4765}
4766
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767static int decode_lookup(struct xdr_stream *xdr)
4768{
4769 return decode_op_hdr(xdr, OP_LOOKUP);
4770}
4771
4772/* This is too sick! */
4773static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4774{
Andy Adamson05d564f2008-12-23 16:06:15 -05004775 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776 uint32_t limit_type, nblocks, blocksize;
4777
Benny Halevyc0eae662009-08-14 17:20:14 +03004778 p = xdr_inline_decode(xdr, 12);
4779 if (unlikely(!p))
4780 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004781 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004783 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004784 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004785 break;
4786 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004787 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004788 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004789 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790 }
4791 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004792out_overflow:
4793 print_overflow_msg(__func__, xdr);
4794 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795}
4796
4797static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4798{
Andy Adamson05d564f2008-12-23 16:06:15 -05004799 __be32 *p;
4800 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004801 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802
Benny Halevyc0eae662009-08-14 17:20:14 +03004803 p = xdr_inline_decode(xdr, 4);
4804 if (unlikely(!p))
4805 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004806 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4808 res->delegation_type = 0;
4809 return 0;
4810 }
Benny Halevy07d30432009-08-14 17:19:52 +03004811 status = decode_stateid(xdr, &res->delegation);
4812 if (unlikely(status))
4813 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004814 p = xdr_inline_decode(xdr, 4);
4815 if (unlikely(!p))
4816 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004817 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004818
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004820 case NFS4_OPEN_DELEGATE_READ:
4821 res->delegation_type = FMODE_READ;
4822 break;
4823 case NFS4_OPEN_DELEGATE_WRITE:
4824 res->delegation_type = FMODE_WRITE|FMODE_READ;
4825 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826 return -EIO;
4827 }
David Howells7539bba2006-08-22 20:06:09 -04004828 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004829out_overflow:
4830 print_overflow_msg(__func__, xdr);
4831 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832}
4833
4834static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4835{
Andy Adamson05d564f2008-12-23 16:06:15 -05004836 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004837 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004838 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839
Andy Adamson05d564f2008-12-23 16:06:15 -05004840 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004841 if (status != -EIO)
4842 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004843 if (!status)
4844 status = decode_stateid(xdr, &res->stateid);
4845 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004846 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847
Andy Adamson05d564f2008-12-23 16:06:15 -05004848 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849
Benny Halevyc0eae662009-08-14 17:20:14 +03004850 p = xdr_inline_decode(xdr, 8);
4851 if (unlikely(!p))
4852 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004853 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004854 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004855 if (bmlen > 10)
4856 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857
Benny Halevyc0eae662009-08-14 17:20:14 +03004858 p = xdr_inline_decode(xdr, bmlen << 2);
4859 if (unlikely(!p))
4860 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004861 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4862 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004863 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004864 for (; i < NFS4_BITMAP_SIZE; i++)
4865 res->attrset[i] = 0;
4866
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 return decode_delegation(xdr, res);
4868xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004869 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004871out_overflow:
4872 print_overflow_msg(__func__, xdr);
4873 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874}
4875
4876static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4877{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 int status;
4879
Andy Adamson05d564f2008-12-23 16:06:15 -05004880 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
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_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4889{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 int status;
4891
4892 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004893 if (status != -EIO)
4894 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004895 if (!status)
4896 status = decode_stateid(xdr, &res->stateid);
4897 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898}
4899
4900static int decode_putfh(struct xdr_stream *xdr)
4901{
4902 return decode_op_hdr(xdr, OP_PUTFH);
4903}
4904
4905static int decode_putrootfh(struct xdr_stream *xdr)
4906{
4907 return decode_op_hdr(xdr, OP_PUTROOTFH);
4908}
4909
4910static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4911{
4912 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004913 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914 uint32_t count, eof, recvd, hdrlen;
4915 int status;
4916
4917 status = decode_op_hdr(xdr, OP_READ);
4918 if (status)
4919 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004920 p = xdr_inline_decode(xdr, 8);
4921 if (unlikely(!p))
4922 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004923 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004924 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004925 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926 recvd = req->rq_rcv_buf.len - hdrlen;
4927 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004928 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004929 "count %u > recvd %u\n", count, recvd);
4930 count = recvd;
4931 eof = 0;
4932 }
4933 xdr_read_pages(xdr, count);
4934 res->eof = eof;
4935 res->count = count;
4936 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004937out_overflow:
4938 print_overflow_msg(__func__, xdr);
4939 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004940}
4941
4942static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4943{
4944 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004946 size_t hdrlen;
4947 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004948 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004949
4950 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004951 if (!status)
4952 status = decode_verifier(xdr, readdir->verifier.data);
4953 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004955 dprintk("%s: verifier = %08x:%08x\n",
4956 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004957 ((u32 *)readdir->verifier.data)[0],
4958 ((u32 *)readdir->verifier.data)[1]);
4959
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960
Benny Halevydb942bb2009-08-14 17:19:56 +03004961 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962 recvd = rcvbuf->len - hdrlen;
4963 if (pglen > recvd)
4964 pglen = recvd;
4965 xdr_read_pages(xdr, pglen);
4966
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004967
Trond Myklebustac396122010-11-15 20:26:22 -05004968 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969}
4970
4971static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4972{
4973 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4974 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004975 size_t hdrlen;
4976 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004977 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978 int status;
4979
4980 status = decode_op_hdr(xdr, OP_READLINK);
4981 if (status)
4982 return status;
4983
4984 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004985 p = xdr_inline_decode(xdr, 4);
4986 if (unlikely(!p))
4987 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004988 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004990 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991 return -ENAMETOOLONG;
4992 }
4993 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4994 recvd = req->rq_rcv_buf.len - hdrlen;
4995 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004996 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997 "count %u > recvd %u\n", len, recvd);
4998 return -EIO;
4999 }
5000 xdr_read_pages(xdr, len);
5001 /*
5002 * The XDR encode routine has set things up so that
5003 * the link text will be copied directly into the
5004 * buffer. We just have to do overflow-checking,
5005 * and and null-terminate the text (the VFS expects
5006 * null-termination).
5007 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005008 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005010out_overflow:
5011 print_overflow_msg(__func__, xdr);
5012 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013}
5014
5015static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5016{
5017 int status;
5018
5019 status = decode_op_hdr(xdr, OP_REMOVE);
5020 if (status)
5021 goto out;
5022 status = decode_change_info(xdr, cinfo);
5023out:
5024 return status;
5025}
5026
5027static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5028 struct nfs4_change_info *new_cinfo)
5029{
5030 int status;
5031
5032 status = decode_op_hdr(xdr, OP_RENAME);
5033 if (status)
5034 goto out;
5035 if ((status = decode_change_info(xdr, old_cinfo)))
5036 goto out;
5037 status = decode_change_info(xdr, new_cinfo);
5038out:
5039 return status;
5040}
5041
5042static int decode_renew(struct xdr_stream *xdr)
5043{
5044 return decode_op_hdr(xdr, OP_RENEW);
5045}
5046
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005047static int
5048decode_restorefh(struct xdr_stream *xdr)
5049{
5050 return decode_op_hdr(xdr, OP_RESTOREFH);
5051}
5052
J. Bruce Fields029d1052005-06-22 17:16:22 +00005053static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005054 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005055{
Andy Adamsonbf118a32011-12-07 11:55:27 -05005056 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005057 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005058 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005059 struct kvec *iov = req->rq_rcv_buf.head;
5060 int status;
5061
Andy Adamsonbf118a32011-12-07 11:55:27 -05005062 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005063 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5064 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005065 bm_p = xdr->p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005066 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5067 goto out;
5068 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5069 goto out;
5070
5071 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5072 return -EIO;
5073 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04005074 size_t hdrlen;
5075 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005076
Andy Adamsonbf118a32011-12-07 11:55:27 -05005077 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5078 * are stored with the acl data to handle the problem of
5079 * variable length bitmaps.*/
5080 xdr->p = bm_p;
5081 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
5082 res->acl_data_offset <<= 2;
5083
J. Bruce Fields029d1052005-06-22 17:16:22 +00005084 /* We ignore &savep and don't do consistency checks on
5085 * the attr length. Let userspace figure it out.... */
5086 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005087 attrlen += res->acl_data_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005088 recvd = req->rq_rcv_buf.len - hdrlen;
5089 if (attrlen > recvd) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05005090 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5091 /* getxattr interface called with a NULL buf */
5092 res->acl_len = attrlen;
5093 goto out;
5094 }
5095 dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
J. Bruce Fields029d1052005-06-22 17:16:22 +00005096 attrlen, recvd);
5097 return -EINVAL;
5098 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04005099 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05005100 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005101 } else
5102 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005103
5104out:
5105 return status;
5106}
5107
Linus Torvalds1da177e2005-04-16 15:20:36 -07005108static int
5109decode_savefh(struct xdr_stream *xdr)
5110{
5111 return decode_op_hdr(xdr, OP_SAVEFH);
5112}
5113
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005114static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115{
Al Viro8687b632006-10-19 23:28:48 -07005116 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117 uint32_t bmlen;
5118 int status;
5119
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120 status = decode_op_hdr(xdr, OP_SETATTR);
5121 if (status)
5122 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005123 p = xdr_inline_decode(xdr, 4);
5124 if (unlikely(!p))
5125 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005126 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005127 p = xdr_inline_decode(xdr, bmlen << 2);
5128 if (likely(p))
5129 return 0;
5130out_overflow:
5131 print_overflow_msg(__func__, xdr);
5132 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133}
5134
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005135static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136{
Al Viro8687b632006-10-19 23:28:48 -07005137 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005138 uint32_t opnum;
5139 int32_t nfserr;
5140
Benny Halevyc0eae662009-08-14 17:20:14 +03005141 p = xdr_inline_decode(xdr, 8);
5142 if (unlikely(!p))
5143 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005144 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005146 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005147 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148 return -EIO;
5149 }
Benny Halevycccddf42009-08-14 17:20:19 +03005150 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005152 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5153 if (unlikely(!p))
5154 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005155 p = xdr_decode_hyper(p, &res->clientid);
5156 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 } else if (nfserr == NFSERR_CLID_INUSE) {
5158 uint32_t len;
5159
5160 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005161 p = xdr_inline_decode(xdr, 4);
5162 if (unlikely(!p))
5163 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005164 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005165 p = xdr_inline_decode(xdr, len);
5166 if (unlikely(!p))
5167 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168
5169 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005170 p = xdr_inline_decode(xdr, 4);
5171 if (unlikely(!p))
5172 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005173 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005174 p = xdr_inline_decode(xdr, len);
5175 if (unlikely(!p))
5176 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177 return -NFSERR_CLID_INUSE;
5178 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005179 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005180
5181 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005182out_overflow:
5183 print_overflow_msg(__func__, xdr);
5184 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185}
5186
5187static int decode_setclientid_confirm(struct xdr_stream *xdr)
5188{
5189 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5190}
5191
5192static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5193{
Al Viro8687b632006-10-19 23:28:48 -07005194 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195 int status;
5196
5197 status = decode_op_hdr(xdr, OP_WRITE);
5198 if (status)
5199 return status;
5200
Benny Halevyc0eae662009-08-14 17:20:14 +03005201 p = xdr_inline_decode(xdr, 16);
5202 if (unlikely(!p))
5203 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005204 res->count = be32_to_cpup(p++);
5205 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03005206 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005208out_overflow:
5209 print_overflow_msg(__func__, xdr);
5210 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211}
5212
5213static int decode_delegreturn(struct xdr_stream *xdr)
5214{
5215 return decode_op_hdr(xdr, OP_DELEGRETURN);
5216}
5217
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005218static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5219{
5220 __be32 *p;
5221
5222 p = xdr_inline_decode(xdr, 4);
5223 if (unlikely(!p))
5224 goto out_overflow;
5225 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5226 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5227 goto out_err;
5228
5229 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5230 if (unlikely(!p))
5231 goto out_overflow;
5232 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5233
5234 p = xdr_inline_decode(xdr, 8);
5235 if (unlikely(!p))
5236 goto out_overflow;
5237 flavor->gss.qop4 = be32_to_cpup(p++);
5238 flavor->gss.service = be32_to_cpup(p);
5239
5240 return 0;
5241
5242out_overflow:
5243 print_overflow_msg(__func__, xdr);
5244 return -EIO;
5245out_err:
5246 return -EINVAL;
5247}
5248
5249static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5250{
5251 struct nfs4_secinfo_flavor *sec_flavor;
5252 int status;
5253 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005254 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005255
5256 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005257 if (status)
5258 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005259 p = xdr_inline_decode(xdr, 4);
5260 if (unlikely(!p))
5261 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005262
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005263 res->flavors->num_flavors = 0;
5264 num_flavors = be32_to_cpup(p);
5265
5266 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005267 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005268 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005269 break;
5270
5271 p = xdr_inline_decode(xdr, 4);
5272 if (unlikely(!p))
5273 goto out_overflow;
5274 sec_flavor->flavor = be32_to_cpup(p);
5275
5276 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005277 status = decode_secinfo_gss(xdr, sec_flavor);
5278 if (status)
5279 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005280 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005281 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005282 }
5283
Bryan Schumaker613e9012011-04-27 15:28:44 -04005284out:
5285 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005286out_overflow:
5287 print_overflow_msg(__func__, xdr);
5288 return -EIO;
5289}
5290
Benny Halevy99fe60d2009-04-01 09:22:29 -04005291#if defined(CONFIG_NFS_V4_1)
5292static int decode_exchange_id(struct xdr_stream *xdr,
5293 struct nfs41_exchange_id_res *res)
5294{
5295 __be32 *p;
5296 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005297 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005298 int status;
5299 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005300 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005301
5302 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5303 if (status)
5304 return status;
5305
Benny Halevyc0eae662009-08-14 17:20:14 +03005306 p = xdr_inline_decode(xdr, 8);
5307 if (unlikely(!p))
5308 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005309 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005310 p = xdr_inline_decode(xdr, 12);
5311 if (unlikely(!p))
5312 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005313 clp->cl_seqid = be32_to_cpup(p++);
5314 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005315
5316 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005317 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005318 if (dummy != SP4_NONE)
5319 return -EIO;
5320
5321 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005322 p = xdr_inline_decode(xdr, 8);
5323 if (unlikely(!p))
5324 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005325
5326 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005327 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5328 if (unlikely(status))
5329 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005330
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005331 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005332 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5333 if (unlikely(status))
5334 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005335
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005336 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5337 return -EIO;
5338
5339 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5340 res->server_scope->server_scope_sz = dummy;
5341
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005342 /* Implementation Id */
5343 p = xdr_inline_decode(xdr, 4);
5344 if (unlikely(!p))
5345 goto out_overflow;
5346 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005347
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005348 if (impl_id_count) {
5349 /* nii_domain */
5350 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5351 if (unlikely(status))
5352 return status;
5353 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5354 return -EIO;
5355 memcpy(res->impl_id->domain, dummy_str, dummy);
5356
5357 /* nii_name */
5358 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5359 if (unlikely(status))
5360 return status;
5361 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5362 return -EIO;
5363 memcpy(res->impl_id->name, dummy_str, dummy);
5364
5365 /* nii_date */
5366 p = xdr_inline_decode(xdr, 12);
5367 if (unlikely(!p))
5368 goto out_overflow;
5369 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5370 res->impl_id->date.nseconds = be32_to_cpup(p);
5371
5372 /* if there's more than one entry, ignore the rest */
5373 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005374 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005375out_overflow:
5376 print_overflow_msg(__func__, xdr);
5377 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005378}
Andy Adamsonfc931582009-04-01 09:22:31 -04005379
5380static int decode_chan_attrs(struct xdr_stream *xdr,
5381 struct nfs4_channel_attrs *attrs)
5382{
5383 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005384 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005385
Benny Halevyc0eae662009-08-14 17:20:14 +03005386 p = xdr_inline_decode(xdr, 28);
5387 if (unlikely(!p))
5388 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005389 val = be32_to_cpup(p++); /* headerpadsz */
5390 if (val)
5391 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005392 attrs->max_rqst_sz = be32_to_cpup(p++);
5393 attrs->max_resp_sz = be32_to_cpup(p++);
5394 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5395 attrs->max_ops = be32_to_cpup(p++);
5396 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005397 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005398 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005399 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5400 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005401 return -EINVAL;
5402 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005403 if (nr_attrs == 1) {
5404 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5405 if (unlikely(!p))
5406 goto out_overflow;
5407 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005408 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005409out_overflow:
5410 print_overflow_msg(__func__, xdr);
5411 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005412}
5413
Benny Halevye78291e2009-08-14 17:20:00 +03005414static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5415{
5416 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005417}
5418
5419static int decode_create_session(struct xdr_stream *xdr,
5420 struct nfs41_create_session_res *res)
5421{
5422 __be32 *p;
5423 int status;
5424 struct nfs_client *clp = res->client;
5425 struct nfs4_session *session = clp->cl_session;
5426
5427 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005428 if (!status)
5429 status = decode_sessionid(xdr, &session->sess_id);
5430 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005431 return status;
5432
Andy Adamsonfc931582009-04-01 09:22:31 -04005433 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005434 p = xdr_inline_decode(xdr, 8);
5435 if (unlikely(!p))
5436 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005437 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005438 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005439
5440 /* Channel attributes */
5441 status = decode_chan_attrs(xdr, &session->fc_attrs);
5442 if (!status)
5443 status = decode_chan_attrs(xdr, &session->bc_attrs);
5444 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005445out_overflow:
5446 print_overflow_msg(__func__, xdr);
5447 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005448}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005449
5450static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5451{
5452 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5453}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005454
5455static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5456{
5457 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5458}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005459#endif /* CONFIG_NFS_V4_1 */
5460
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005461static int decode_sequence(struct xdr_stream *xdr,
5462 struct nfs4_sequence_res *res,
5463 struct rpc_rqst *rqstp)
5464{
5465#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005466 struct nfs4_sessionid id;
5467 u32 dummy;
5468 int status;
5469 __be32 *p;
5470
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005471 if (!res->sr_session)
5472 return 0;
5473
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005474 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005475 if (!status)
5476 status = decode_sessionid(xdr, &id);
5477 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005478 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005479
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005480 /*
5481 * If the server returns different values for sessionID, slotID or
5482 * sequence number, the server is looney tunes.
5483 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005484 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005485
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005486 if (memcmp(id.data, res->sr_session->sess_id.data,
5487 NFS4_MAX_SESSIONID_LEN)) {
5488 dprintk("%s Invalid session id\n", __func__);
5489 goto out_err;
5490 }
Benny Halevye78291e2009-08-14 17:20:00 +03005491
Benny Halevyc0eae662009-08-14 17:20:14 +03005492 p = xdr_inline_decode(xdr, 20);
5493 if (unlikely(!p))
5494 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005495
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005496 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005497 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005498 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005499 dprintk("%s Invalid sequence number\n", __func__);
5500 goto out_err;
5501 }
5502 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005503 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005504 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005505 dprintk("%s Invalid slot id\n", __func__);
5506 goto out_err;
5507 }
5508 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005509 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005510 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005511 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005512 /* result flags */
5513 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005514 status = 0;
5515out_err:
5516 res->sr_status = status;
5517 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005518out_overflow:
5519 print_overflow_msg(__func__, xdr);
5520 status = -EIO;
5521 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005522#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005523 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005524#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005525}
5526
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005527#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005528/*
5529 * TODO: Need to handle case when EOF != true;
5530 */
5531static int decode_getdevicelist(struct xdr_stream *xdr,
5532 struct pnfs_devicelist *res)
5533{
5534 __be32 *p;
5535 int status, i;
5536 struct nfs_writeverf verftemp;
5537
5538 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5539 if (status)
5540 return status;
5541
5542 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5543 if (unlikely(!p))
5544 goto out_overflow;
5545
5546 /* TODO: Skip cookie for now */
5547 p += 2;
5548
5549 /* Read verifier */
5550 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5551
5552 res->num_devs = be32_to_cpup(p);
5553
5554 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5555
5556 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005557 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005558 __func__, res->num_devs);
5559 return -EIO;
5560 }
5561
5562 p = xdr_inline_decode(xdr,
5563 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5564 if (unlikely(!p))
5565 goto out_overflow;
5566 for (i = 0; i < res->num_devs; i++)
5567 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5568 NFS4_DEVICEID4_SIZE);
5569 res->eof = be32_to_cpup(p);
5570 return 0;
5571out_overflow:
5572 print_overflow_msg(__func__, xdr);
5573 return -EIO;
5574}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005575
5576static int decode_getdeviceinfo(struct xdr_stream *xdr,
5577 struct pnfs_device *pdev)
5578{
5579 __be32 *p;
5580 uint32_t len, type;
5581 int status;
5582
5583 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5584 if (status) {
5585 if (status == -ETOOSMALL) {
5586 p = xdr_inline_decode(xdr, 4);
5587 if (unlikely(!p))
5588 goto out_overflow;
5589 pdev->mincount = be32_to_cpup(p);
5590 dprintk("%s: Min count too small. mincnt = %u\n",
5591 __func__, pdev->mincount);
5592 }
5593 return status;
5594 }
5595
5596 p = xdr_inline_decode(xdr, 8);
5597 if (unlikely(!p))
5598 goto out_overflow;
5599 type = be32_to_cpup(p++);
5600 if (type != pdev->layout_type) {
5601 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5602 __func__, pdev->layout_type, type);
5603 return -EINVAL;
5604 }
5605 /*
5606 * Get the length of the opaque device_addr4. xdr_read_pages places
5607 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5608 * and places the remaining xdr data in xdr_buf->tail
5609 */
5610 pdev->mincount = be32_to_cpup(p);
5611 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5612
5613 /* Parse notification bitmap, verifying that it is zero. */
5614 p = xdr_inline_decode(xdr, 4);
5615 if (unlikely(!p))
5616 goto out_overflow;
5617 len = be32_to_cpup(p);
5618 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005619 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005620
5621 p = xdr_inline_decode(xdr, 4 * len);
5622 if (unlikely(!p))
5623 goto out_overflow;
5624 for (i = 0; i < len; i++, p++) {
5625 if (be32_to_cpup(p)) {
5626 dprintk("%s: notifications not supported\n",
5627 __func__);
5628 return -EIO;
5629 }
5630 }
5631 }
5632 return 0;
5633out_overflow:
5634 print_overflow_msg(__func__, xdr);
5635 return -EIO;
5636}
5637
5638static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5639 struct nfs4_layoutget_res *res)
5640{
5641 __be32 *p;
5642 int status;
5643 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005644 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5645 struct kvec *iov = rcvbuf->head;
5646 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005647
5648 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5649 if (status)
5650 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005651 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005652 if (unlikely(!p))
5653 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005654 res->return_on_close = be32_to_cpup(p);
5655 decode_stateid(xdr, &res->stateid);
5656 p = xdr_inline_decode(xdr, 4);
5657 if (unlikely(!p))
5658 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005659 layout_count = be32_to_cpup(p);
5660 if (!layout_count) {
5661 dprintk("%s: server responded with empty layout array\n",
5662 __func__);
5663 return -EINVAL;
5664 }
5665
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005666 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005667 if (unlikely(!p))
5668 goto out_overflow;
5669 p = xdr_decode_hyper(p, &res->range.offset);
5670 p = xdr_decode_hyper(p, &res->range.length);
5671 res->range.iomode = be32_to_cpup(p++);
5672 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005673 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005674
5675 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5676 __func__,
5677 (unsigned long)res->range.offset,
5678 (unsigned long)res->range.length,
5679 res->range.iomode,
5680 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005681 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005682
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005683 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5684 recvd = req->rq_rcv_buf.len - hdrlen;
5685 if (res->layoutp->len > recvd) {
5686 dprintk("NFS: server cheating in layoutget reply: "
5687 "layout len %u > recvd %u\n",
5688 res->layoutp->len, recvd);
5689 return -EINVAL;
5690 }
5691
5692 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005693
5694 if (layout_count > 1) {
5695 /* We only handle a length one array at the moment. Any
5696 * further entries are just ignored. Note that this means
5697 * the client may see a response that is less than the
5698 * minimum it requested.
5699 */
5700 dprintk("%s: server responded with %d layouts, dropping tail\n",
5701 __func__, layout_count);
5702 }
5703
5704 return 0;
5705out_overflow:
5706 print_overflow_msg(__func__, xdr);
5707 return -EIO;
5708}
Andy Adamson863a3c62011-03-23 13:27:54 +00005709
Benny Halevycbe82602011-05-22 19:52:37 +03005710static int decode_layoutreturn(struct xdr_stream *xdr,
5711 struct nfs4_layoutreturn_res *res)
5712{
5713 __be32 *p;
5714 int status;
5715
5716 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5717 if (status)
5718 return status;
5719 p = xdr_inline_decode(xdr, 4);
5720 if (unlikely(!p))
5721 goto out_overflow;
5722 res->lrs_present = be32_to_cpup(p);
5723 if (res->lrs_present)
5724 status = decode_stateid(xdr, &res->stateid);
5725 return status;
5726out_overflow:
5727 print_overflow_msg(__func__, xdr);
5728 return -EIO;
5729}
5730
Andy Adamson863a3c62011-03-23 13:27:54 +00005731static int decode_layoutcommit(struct xdr_stream *xdr,
5732 struct rpc_rqst *req,
5733 struct nfs4_layoutcommit_res *res)
5734{
5735 __be32 *p;
5736 __u32 sizechanged;
5737 int status;
5738
5739 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005740 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005741 if (status)
5742 return status;
5743
5744 p = xdr_inline_decode(xdr, 4);
5745 if (unlikely(!p))
5746 goto out_overflow;
5747 sizechanged = be32_to_cpup(p);
5748
5749 if (sizechanged) {
5750 /* throw away new size */
5751 p = xdr_inline_decode(xdr, 8);
5752 if (unlikely(!p))
5753 goto out_overflow;
5754 }
5755 return 0;
5756out_overflow:
5757 print_overflow_msg(__func__, xdr);
5758 return -EIO;
5759}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005760
5761static int decode_test_stateid(struct xdr_stream *xdr,
5762 struct nfs41_test_stateid_res *res)
5763{
5764 __be32 *p;
5765 int status;
5766 int num_res;
5767
5768 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5769 if (status)
5770 return status;
5771
5772 p = xdr_inline_decode(xdr, 4);
5773 if (unlikely(!p))
5774 goto out_overflow;
5775 num_res = be32_to_cpup(p++);
5776 if (num_res != 1)
5777 goto out;
5778
5779 p = xdr_inline_decode(xdr, 4);
5780 if (unlikely(!p))
5781 goto out_overflow;
5782 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005783
5784 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005785out_overflow:
5786 print_overflow_msg(__func__, xdr);
5787out:
5788 return -EIO;
5789}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005790
5791static int decode_free_stateid(struct xdr_stream *xdr,
5792 struct nfs41_free_stateid_res *res)
5793{
5794 __be32 *p;
5795 int status;
5796
5797 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5798 if (status)
5799 return status;
5800
5801 p = xdr_inline_decode(xdr, 4);
5802 if (unlikely(!p))
5803 goto out_overflow;
5804 res->status = be32_to_cpup(p++);
5805 return res->status;
5806out_overflow:
5807 print_overflow_msg(__func__, xdr);
5808 return -EIO;
5809}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005810#endif /* CONFIG_NFS_V4_1 */
5811
Linus Torvalds1da177e2005-04-16 15:20:36 -07005812/*
Benny Halevy49c25592008-12-23 16:06:16 -05005813 * END OF "GENERIC" DECODE ROUTINES.
5814 */
5815
5816/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005817 * Decode OPEN_DOWNGRADE response
5818 */
Chuck Leverbf269552010-12-14 14:59:29 +00005819static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5820 struct xdr_stream *xdr,
5821 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005822{
Andy Adamson05d564f2008-12-23 16:06:15 -05005823 struct compound_hdr hdr;
5824 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825
Chuck Leverbf269552010-12-14 14:59:29 +00005826 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005827 if (status)
5828 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005829 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005830 if (status)
5831 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005832 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005833 if (status)
5834 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005835 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005836 if (status != 0)
5837 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005838 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005840 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005841}
5842
5843/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844 * Decode ACCESS response
5845 */
Chuck Leverbf269552010-12-14 14:59:29 +00005846static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5847 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005849 struct compound_hdr hdr;
5850 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005851
Chuck Leverbf269552010-12-14 14:59:29 +00005852 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005853 if (status)
5854 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005855 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005856 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005858 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005859 if (status != 0)
5860 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005861 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005862 if (status != 0)
5863 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005864 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865out:
5866 return status;
5867}
5868
5869/*
5870 * Decode LOOKUP response
5871 */
Chuck Leverbf269552010-12-14 14:59:29 +00005872static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5873 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005874{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005875 struct compound_hdr hdr;
5876 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005877
Chuck Leverbf269552010-12-14 14:59:29 +00005878 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005879 if (status)
5880 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005881 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005882 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005883 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005884 status = decode_putfh(xdr);
5885 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005886 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005887 status = decode_lookup(xdr);
5888 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005889 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005890 status = decode_getfh(xdr, res->fh);
5891 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005893 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894out:
5895 return status;
5896}
5897
5898/*
5899 * Decode LOOKUP_ROOT response
5900 */
Chuck Leverbf269552010-12-14 14:59:29 +00005901static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5902 struct xdr_stream *xdr,
5903 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005904{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905 struct compound_hdr hdr;
5906 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005907
Chuck Leverbf269552010-12-14 14:59:29 +00005908 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005909 if (status)
5910 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005911 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005912 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005913 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005914 status = decode_putrootfh(xdr);
5915 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005916 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005917 status = decode_getfh(xdr, res->fh);
5918 if (status == 0)
Trond Myklebust6926afd12012-01-07 13:22:46 -05005919 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005920out:
5921 return status;
5922}
5923
5924/*
5925 * Decode REMOVE response
5926 */
Chuck Leverbf269552010-12-14 14:59:29 +00005927static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5928 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005930 struct compound_hdr hdr;
5931 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005932
Chuck Leverbf269552010-12-14 14:59:29 +00005933 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005934 if (status)
5935 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005936 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005937 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005938 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005939 status = decode_putfh(xdr);
5940 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005941 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005942 status = decode_remove(xdr, &res->cinfo);
5943 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005944 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005945 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005946out:
5947 return status;
5948}
5949
5950/*
5951 * Decode RENAME response
5952 */
Chuck Leverbf269552010-12-14 14:59:29 +00005953static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5954 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005955{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956 struct compound_hdr hdr;
5957 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005958
Chuck Leverbf269552010-12-14 14:59:29 +00005959 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005960 if (status)
5961 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005962 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005963 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005964 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005965 status = decode_putfh(xdr);
5966 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005968 status = decode_savefh(xdr);
5969 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005971 status = decode_putfh(xdr);
5972 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005973 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005974 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5975 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005976 goto out;
5977 /* Current FH is target directory */
Trond Myklebust6926afd12012-01-07 13:22:46 -05005978 if (decode_getfattr(xdr, res->new_fattr, res->server))
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005979 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005980 status = decode_restorefh(xdr);
5981 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005982 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005983 decode_getfattr(xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984out:
5985 return status;
5986}
5987
5988/*
5989 * Decode LINK response
5990 */
Chuck Leverbf269552010-12-14 14:59:29 +00005991static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5992 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005993{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005994 struct compound_hdr hdr;
5995 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005996
Chuck Leverbf269552010-12-14 14:59:29 +00005997 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005998 if (status)
5999 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006000 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006001 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006003 status = decode_putfh(xdr);
6004 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006005 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006006 status = decode_savefh(xdr);
6007 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006009 status = decode_putfh(xdr);
6010 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006012 status = decode_link(xdr, &res->cinfo);
6013 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006014 goto out;
6015 /*
6016 * Note order: OP_LINK leaves the directory as the current
6017 * filehandle.
6018 */
Trond Myklebust6926afd12012-01-07 13:22:46 -05006019 if (decode_getfattr(xdr, res->dir_attr, res->server))
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006020 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006021 status = decode_restorefh(xdr);
6022 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006023 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006024 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006025out:
6026 return status;
6027}
6028
6029/*
6030 * Decode CREATE response
6031 */
Chuck Leverbf269552010-12-14 14:59:29 +00006032static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6033 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006035 struct compound_hdr hdr;
6036 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006037
Chuck Leverbf269552010-12-14 14:59:29 +00006038 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006039 if (status)
6040 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006041 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006042 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006044 status = decode_putfh(xdr);
6045 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006047 status = decode_savefh(xdr);
6048 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006049 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006050 status = decode_create(xdr, &res->dir_cinfo);
6051 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006053 status = decode_getfh(xdr, res->fh);
6054 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006056 if (decode_getfattr(xdr, res->fattr, res->server))
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006057 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006058 status = decode_restorefh(xdr);
6059 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006060 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006061 decode_getfattr(xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062out:
6063 return status;
6064}
6065
6066/*
6067 * Decode SYMLINK response
6068 */
Chuck Leverbf269552010-12-14 14:59:29 +00006069static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6070 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071{
Chuck Leverbf269552010-12-14 14:59:29 +00006072 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073}
6074
6075/*
6076 * Decode GETATTR response
6077 */
Chuck Leverbf269552010-12-14 14:59:29 +00006078static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6079 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006080{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081 struct compound_hdr hdr;
6082 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006083
Chuck Leverbf269552010-12-14 14:59:29 +00006084 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085 if (status)
6086 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006087 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006088 if (status)
6089 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006090 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006091 if (status)
6092 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006093 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094out:
6095 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096}
6097
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006098/*
6099 * Encode an SETACL request
6100 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006101static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6102 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006103{
Andy Adamson05d564f2008-12-23 16:06:15 -05006104 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006105 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006106 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006107
Chuck Lever9f06c712010-12-14 14:59:18 +00006108 encode_compound_hdr(xdr, req, &hdr);
6109 encode_sequence(xdr, &args->seq_args, &hdr);
6110 encode_putfh(xdr, args->fh, &hdr);
6111 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006112 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006113}
Andy Adamson05d564f2008-12-23 16:06:15 -05006114
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006115/*
6116 * Decode SETACL response
6117 */
6118static int
Chuck Leverbf269552010-12-14 14:59:29 +00006119nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006120 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006121{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006122 struct compound_hdr hdr;
6123 int status;
6124
Chuck Leverbf269552010-12-14 14:59:29 +00006125 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006126 if (status)
6127 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006128 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006129 if (status)
6130 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006131 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006132 if (status)
6133 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006134 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006135out:
6136 return status;
6137}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006138
6139/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006140 * Decode GETACL response
6141 */
6142static int
Chuck Leverbf269552010-12-14 14:59:29 +00006143nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006144 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006145{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006146 struct compound_hdr hdr;
6147 int status;
6148
Trond Myklebust331818f2012-02-03 18:30:53 -05006149 if (res->acl_scratch != NULL) {
6150 void *p = page_address(res->acl_scratch);
6151 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6152 }
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006154 if (status)
6155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006157 if (status)
6158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006160 if (status)
6161 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006162 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006163
6164out:
6165 return status;
6166}
6167
6168/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169 * Decode CLOSE response
6170 */
Chuck Leverbf269552010-12-14 14:59:29 +00006171static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6172 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173{
Andy Adamson05d564f2008-12-23 16:06:15 -05006174 struct compound_hdr hdr;
6175 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006176
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006178 if (status)
6179 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006180 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006181 if (status)
6182 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006183 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006184 if (status)
6185 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006186 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006187 if (status != 0)
6188 goto out;
6189 /*
6190 * Note: Server may do delete on close for this file
6191 * in which case the getattr call will fail with
6192 * an ESTALE error. Shouldn't be a problem,
6193 * though, since fattr->valid will remain unset.
6194 */
Trond Myklebust6926afd12012-01-07 13:22:46 -05006195 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006197 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198}
6199
6200/*
6201 * Decode OPEN response
6202 */
Chuck Leverbf269552010-12-14 14:59:29 +00006203static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6204 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205{
Andy Adamson05d564f2008-12-23 16:06:15 -05006206 struct compound_hdr hdr;
6207 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208
Chuck Leverbf269552010-12-14 14:59:29 +00006209 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006210 if (status)
6211 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006213 if (status)
6214 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006215 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006216 if (status)
6217 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006218 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006219 if (status)
6220 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006221 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006222 if (status)
6223 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006224 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006226 if (decode_getfattr(xdr, res->f_attr, res->server) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006227 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006228 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006229 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006230 decode_getfattr(xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006231out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006232 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233}
6234
6235/*
6236 * Decode OPEN_CONFIRM response
6237 */
Chuck Leverbf269552010-12-14 14:59:29 +00006238static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6239 struct xdr_stream *xdr,
6240 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241{
Andy Adamson05d564f2008-12-23 16:06:15 -05006242 struct compound_hdr hdr;
6243 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006244
Chuck Leverbf269552010-12-14 14:59:29 +00006245 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006246 if (status)
6247 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006248 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006249 if (status)
6250 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006251 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006252out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006253 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006254}
6255
6256/*
6257 * Decode OPEN response
6258 */
Chuck Leverbf269552010-12-14 14:59:29 +00006259static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6260 struct xdr_stream *xdr,
6261 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262{
Andy Adamson05d564f2008-12-23 16:06:15 -05006263 struct compound_hdr hdr;
6264 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265
Chuck Leverbf269552010-12-14 14:59:29 +00006266 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006267 if (status)
6268 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006269 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006270 if (status)
6271 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006272 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006273 if (status)
6274 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006276 if (status)
6277 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006278 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006279out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006280 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281}
6282
6283/*
6284 * Decode SETATTR response
6285 */
Chuck Leverbf269552010-12-14 14:59:29 +00006286static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6287 struct xdr_stream *xdr,
6288 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289{
Andy Adamson05d564f2008-12-23 16:06:15 -05006290 struct compound_hdr hdr;
6291 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006292
Chuck Leverbf269552010-12-14 14:59:29 +00006293 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006294 if (status)
6295 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006296 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006297 if (status)
6298 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006299 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006300 if (status)
6301 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006302 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006303 if (status)
6304 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006305 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006307 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006308}
6309
6310/*
6311 * Decode LOCK response
6312 */
Chuck Leverbf269552010-12-14 14:59:29 +00006313static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6314 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006315{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006316 struct compound_hdr hdr;
6317 int status;
6318
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006320 if (status)
6321 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006322 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006323 if (status)
6324 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006326 if (status)
6327 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329out:
6330 return status;
6331}
6332
6333/*
6334 * Decode LOCKT response
6335 */
Chuck Leverbf269552010-12-14 14:59:29 +00006336static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6337 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006338{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339 struct compound_hdr hdr;
6340 int status;
6341
Chuck Leverbf269552010-12-14 14:59:29 +00006342 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006343 if (status)
6344 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006345 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006346 if (status)
6347 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006348 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349 if (status)
6350 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006351 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352out:
6353 return status;
6354}
6355
6356/*
6357 * Decode LOCKU response
6358 */
Chuck Leverbf269552010-12-14 14:59:29 +00006359static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6360 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 struct compound_hdr hdr;
6363 int status;
6364
Chuck Leverbf269552010-12-14 14:59:29 +00006365 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006366 if (status)
6367 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006369 if (status)
6370 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006371 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372 if (status)
6373 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006374 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375out:
6376 return status;
6377}
6378
Chuck Leverbf269552010-12-14 14:59:29 +00006379static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6380 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006381{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006382 struct compound_hdr hdr;
6383 int status;
6384
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006386 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006387 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006388 return status;
6389}
6390
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391/*
6392 * Decode READLINK response
6393 */
Chuck Leverbf269552010-12-14 14:59:29 +00006394static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6395 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006396 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006397{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398 struct compound_hdr hdr;
6399 int status;
6400
Chuck Leverbf269552010-12-14 14:59:29 +00006401 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402 if (status)
6403 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006404 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006405 if (status)
6406 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006407 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408 if (status)
6409 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411out:
6412 return status;
6413}
6414
6415/*
6416 * Decode READDIR response
6417 */
Chuck Leverbf269552010-12-14 14:59:29 +00006418static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6419 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421 struct compound_hdr hdr;
6422 int status;
6423
Chuck Leverbf269552010-12-14 14:59:29 +00006424 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006425 if (status)
6426 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006427 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006428 if (status)
6429 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006430 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 if (status)
6432 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006434out:
6435 return status;
6436}
6437
6438/*
6439 * Decode Read response
6440 */
Chuck Leverbf269552010-12-14 14:59:29 +00006441static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6442 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 struct compound_hdr hdr;
6445 int status;
6446
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448 if (status)
6449 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006450 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006451 if (status)
6452 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006453 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 if (status)
6455 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006456 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457 if (!status)
6458 status = res->count;
6459out:
6460 return status;
6461}
6462
6463/*
6464 * Decode WRITE response
6465 */
Chuck Leverbf269552010-12-14 14:59:29 +00006466static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6467 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006469 struct compound_hdr hdr;
6470 int status;
6471
Chuck Leverbf269552010-12-14 14:59:29 +00006472 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006473 if (status)
6474 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006475 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006476 if (status)
6477 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006478 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479 if (status)
6480 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006481 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006482 if (status)
6483 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006484 if (res->fattr)
Trond Myklebust6926afd12012-01-07 13:22:46 -05006485 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486 if (!status)
6487 status = res->count;
6488out:
6489 return status;
6490}
6491
6492/*
6493 * Decode COMMIT response
6494 */
Chuck Leverbf269552010-12-14 14:59:29 +00006495static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6496 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498 struct compound_hdr hdr;
6499 int status;
6500
Chuck Leverbf269552010-12-14 14:59:29 +00006501 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502 if (status)
6503 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006504 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006505 if (status)
6506 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006507 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 if (status)
6509 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006510 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006511 if (status)
6512 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006513 if (res->fattr)
Trond Myklebust6926afd12012-01-07 13:22:46 -05006514 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515out:
6516 return status;
6517}
6518
6519/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006520 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006521 */
Chuck Leverbf269552010-12-14 14:59:29 +00006522static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006523 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525 struct compound_hdr hdr;
6526 int status;
6527
Chuck Leverbf269552010-12-14 14:59:29 +00006528 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006530 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006531 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006534 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535 return status;
6536}
6537
6538/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006539 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006540 */
Chuck Leverbf269552010-12-14 14:59:29 +00006541static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006542 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544 struct compound_hdr hdr;
6545 int status;
6546
Chuck Leverbf269552010-12-14 14:59:29 +00006547 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006550 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006553 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554 return status;
6555}
6556
6557/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006558 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 */
Chuck Leverbf269552010-12-14 14:59:29 +00006560static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006561 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006563 struct compound_hdr hdr;
6564 int status;
6565
Chuck Leverbf269552010-12-14 14:59:29 +00006566 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006568 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006569 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006570 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006571 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006572 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573 return status;
6574}
6575
6576/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006577 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578 */
Chuck Leverbf269552010-12-14 14:59:29 +00006579static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6580 struct xdr_stream *xdr,
6581 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006582{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583 struct compound_hdr hdr;
6584 int status;
6585
Chuck Leverbf269552010-12-14 14:59:29 +00006586 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006587 if (status)
6588 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006589 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006590 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006591 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006592 status = decode_putfh(xdr);
6593 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006594 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006595 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006596out:
6597 return status;
6598}
6599
6600/*
6601 * Decode RENEW response
6602 */
Chuck Leverbf269552010-12-14 14:59:29 +00006603static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6604 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006605{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 struct compound_hdr hdr;
6607 int status;
6608
Chuck Leverbf269552010-12-14 14:59:29 +00006609 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006610 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006611 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006612 return status;
6613}
6614
6615/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006616 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617 */
Chuck Leverbf269552010-12-14 14:59:29 +00006618static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6619 struct xdr_stream *xdr,
6620 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006621{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622 struct compound_hdr hdr;
6623 int status;
6624
Chuck Leverbf269552010-12-14 14:59:29 +00006625 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006626 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006627 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006628 return status;
6629}
6630
6631/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006632 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633 */
Chuck Leverbf269552010-12-14 14:59:29 +00006634static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6635 struct xdr_stream *xdr,
6636 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006637{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638 struct compound_hdr hdr;
6639 int status;
6640
Chuck Leverbf269552010-12-14 14:59:29 +00006641 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006643 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006645 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006646 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006648 return status;
6649}
6650
6651/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006652 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 */
Chuck Leverbf269552010-12-14 14:59:29 +00006654static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6655 struct xdr_stream *xdr,
6656 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006657{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006658 struct compound_hdr hdr;
6659 int status;
6660
Chuck Leverbf269552010-12-14 14:59:29 +00006661 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006662 if (status)
6663 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006664 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006665 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006666 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006668 if (status != 0)
6669 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006670 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006671 if (status != 0)
6672 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006673 decode_getfattr(xdr, res->fattr, res->server);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006674out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675 return status;
6676}
6677
Trond Myklebust683b57b2006-06-09 09:34:22 -04006678/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006679 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006680 */
Chuck Leverbf269552010-12-14 14:59:29 +00006681static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6682 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006683 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006684{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006685 struct compound_hdr hdr;
6686 int status;
6687
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006689 if (status)
6690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006691 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006692 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006693 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006694 status = decode_putfh(xdr);
6695 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006696 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006697 status = decode_lookup(xdr);
6698 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006699 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006700 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006701 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6702 NULL, res->fs_locations,
6703 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006704out:
6705 return status;
6706}
6707
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006708/*
6709 * Decode SECINFO response
6710 */
6711static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6712 struct xdr_stream *xdr,
6713 struct nfs4_secinfo_res *res)
6714{
6715 struct compound_hdr hdr;
6716 int status;
6717
6718 status = decode_compound_hdr(xdr, &hdr);
6719 if (status)
6720 goto out;
6721 status = decode_sequence(xdr, &res->seq_res, rqstp);
6722 if (status)
6723 goto out;
6724 status = decode_putfh(xdr);
6725 if (status)
6726 goto out;
6727 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006728out:
6729 return status;
6730}
6731
Benny Halevy99fe60d2009-04-01 09:22:29 -04006732#if defined(CONFIG_NFS_V4_1)
6733/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006734 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006735 */
Chuck Leverbf269552010-12-14 14:59:29 +00006736static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6737 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006738 void *res)
6739{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006740 struct compound_hdr hdr;
6741 int status;
6742
Chuck Leverbf269552010-12-14 14:59:29 +00006743 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006744 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006745 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006746 return status;
6747}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006748
6749/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006750 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006751 */
Chuck Leverbf269552010-12-14 14:59:29 +00006752static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6753 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006754 struct nfs41_create_session_res *res)
6755{
Andy Adamsonfc931582009-04-01 09:22:31 -04006756 struct compound_hdr hdr;
6757 int status;
6758
Chuck Leverbf269552010-12-14 14:59:29 +00006759 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006760 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006761 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006762 return status;
6763}
6764
6765/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006766 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006767 */
Chuck Leverbf269552010-12-14 14:59:29 +00006768static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6769 struct xdr_stream *xdr,
6770 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006771{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006772 struct compound_hdr hdr;
6773 int status;
6774
Chuck Leverbf269552010-12-14 14:59:29 +00006775 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006776 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006777 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006778 return status;
6779}
6780
6781/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006782 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006783 */
Chuck Leverbf269552010-12-14 14:59:29 +00006784static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6785 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006786 struct nfs4_sequence_res *res)
6787{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006788 struct compound_hdr hdr;
6789 int status;
6790
Chuck Leverbf269552010-12-14 14:59:29 +00006791 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006792 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006793 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006794 return status;
6795}
6796
6797/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006798 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006799 */
Chuck Leverbf269552010-12-14 14:59:29 +00006800static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6801 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006802 struct nfs4_get_lease_time_res *res)
6803{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006804 struct compound_hdr hdr;
6805 int status;
6806
Chuck Leverbf269552010-12-14 14:59:29 +00006807 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006808 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006809 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006810 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006811 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006812 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006813 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006814 return status;
6815}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006816
6817/*
6818 * Decode RECLAIM_COMPLETE response
6819 */
Chuck Leverbf269552010-12-14 14:59:29 +00006820static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6821 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006822 struct nfs41_reclaim_complete_res *res)
6823{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006824 struct compound_hdr hdr;
6825 int status;
6826
Chuck Leverbf269552010-12-14 14:59:29 +00006827 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006828 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006829 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006830 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006831 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006832 return status;
6833}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006834
6835/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006836 * Decode GETDEVICELIST response
6837 */
6838static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6839 struct xdr_stream *xdr,
6840 struct nfs4_getdevicelist_res *res)
6841{
6842 struct compound_hdr hdr;
6843 int status;
6844
6845 dprintk("encoding getdevicelist!\n");
6846
6847 status = decode_compound_hdr(xdr, &hdr);
6848 if (status != 0)
6849 goto out;
6850 status = decode_sequence(xdr, &res->seq_res, rqstp);
6851 if (status != 0)
6852 goto out;
6853 status = decode_putfh(xdr);
6854 if (status != 0)
6855 goto out;
6856 status = decode_getdevicelist(xdr, res->devlist);
6857out:
6858 return status;
6859}
6860
6861/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006862 * Decode GETDEVINFO response
6863 */
Chuck Leverbf269552010-12-14 14:59:29 +00006864static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6865 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006866 struct nfs4_getdeviceinfo_res *res)
6867{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006868 struct compound_hdr hdr;
6869 int status;
6870
Chuck Leverbf269552010-12-14 14:59:29 +00006871 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006872 if (status != 0)
6873 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006874 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006875 if (status != 0)
6876 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006877 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006878out:
6879 return status;
6880}
6881
6882/*
6883 * Decode LAYOUTGET response
6884 */
Chuck Leverbf269552010-12-14 14:59:29 +00006885static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6886 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006887 struct nfs4_layoutget_res *res)
6888{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006889 struct compound_hdr hdr;
6890 int status;
6891
Chuck Leverbf269552010-12-14 14:59:29 +00006892 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006893 if (status)
6894 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006895 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006896 if (status)
6897 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006898 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006899 if (status)
6900 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006901 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006902out:
6903 return status;
6904}
Andy Adamson863a3c62011-03-23 13:27:54 +00006905
6906/*
Benny Halevycbe82602011-05-22 19:52:37 +03006907 * Decode LAYOUTRETURN response
6908 */
6909static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6910 struct xdr_stream *xdr,
6911 struct nfs4_layoutreturn_res *res)
6912{
6913 struct compound_hdr hdr;
6914 int status;
6915
6916 status = decode_compound_hdr(xdr, &hdr);
6917 if (status)
6918 goto out;
6919 status = decode_sequence(xdr, &res->seq_res, rqstp);
6920 if (status)
6921 goto out;
6922 status = decode_putfh(xdr);
6923 if (status)
6924 goto out;
6925 status = decode_layoutreturn(xdr, res);
6926out:
6927 return status;
6928}
6929
6930/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006931 * Decode LAYOUTCOMMIT response
6932 */
6933static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6934 struct xdr_stream *xdr,
6935 struct nfs4_layoutcommit_res *res)
6936{
6937 struct compound_hdr hdr;
6938 int status;
6939
6940 status = decode_compound_hdr(xdr, &hdr);
6941 if (status)
6942 goto out;
6943 status = decode_sequence(xdr, &res->seq_res, rqstp);
6944 if (status)
6945 goto out;
6946 status = decode_putfh(xdr);
6947 if (status)
6948 goto out;
6949 status = decode_layoutcommit(xdr, rqstp, res);
6950 if (status)
6951 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006952 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006953out:
6954 return status;
6955}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006956
6957/*
6958 * Decode SECINFO_NO_NAME response
6959 */
6960static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6961 struct xdr_stream *xdr,
6962 struct nfs4_secinfo_res *res)
6963{
6964 struct compound_hdr hdr;
6965 int status;
6966
6967 status = decode_compound_hdr(xdr, &hdr);
6968 if (status)
6969 goto out;
6970 status = decode_sequence(xdr, &res->seq_res, rqstp);
6971 if (status)
6972 goto out;
6973 status = decode_putrootfh(xdr);
6974 if (status)
6975 goto out;
6976 status = decode_secinfo(xdr, res);
6977out:
6978 return status;
6979}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006980
6981/*
6982 * Decode TEST_STATEID response
6983 */
6984static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6985 struct xdr_stream *xdr,
6986 struct nfs41_test_stateid_res *res)
6987{
6988 struct compound_hdr hdr;
6989 int status;
6990
6991 status = decode_compound_hdr(xdr, &hdr);
6992 if (status)
6993 goto out;
6994 status = decode_sequence(xdr, &res->seq_res, rqstp);
6995 if (status)
6996 goto out;
6997 status = decode_test_stateid(xdr, res);
6998out:
6999 return status;
7000}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007001
7002/*
7003 * Decode FREE_STATEID response
7004 */
7005static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7006 struct xdr_stream *xdr,
7007 struct nfs41_free_stateid_res *res)
7008{
7009 struct compound_hdr hdr;
7010 int status;
7011
7012 status = decode_compound_hdr(xdr, &hdr);
7013 if (status)
7014 goto out;
7015 status = decode_sequence(xdr, &res->seq_res, rqstp);
7016 if (status)
7017 goto out;
7018 status = decode_free_stateid(xdr, res);
7019out:
7020 return status;
7021}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007022#endif /* CONFIG_NFS_V4_1 */
7023
Chuck Lever573c4e12010-12-14 14:58:11 +00007024/**
7025 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7026 * the local page cache.
7027 * @xdr: XDR stream where entry resides
7028 * @entry: buffer to fill in with entry data
7029 * @plus: boolean indicating whether this should be a readdirplus entry
7030 *
7031 * Returns zero if successful, otherwise a negative errno value is
7032 * returned.
7033 *
7034 * This function is not invoked during READDIR reply decoding, but
7035 * rather whenever an application invokes the getdents(2) system call
7036 * on a directory already in our cache.
7037 */
7038int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7039 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007040{
Fred Isamandae100c2011-07-30 20:52:37 -04007041 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007042 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007043 __be32 *p = xdr_inline_decode(xdr, 4);
7044 if (unlikely(!p))
7045 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007046 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007047 p = xdr_inline_decode(xdr, 4);
7048 if (unlikely(!p))
7049 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007050 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007051 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007052 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007053 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007054 }
7055
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007056 p = xdr_inline_decode(xdr, 12);
7057 if (unlikely(!p))
7058 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007059 entry->prev_cookie = entry->cookie;
7060 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007061 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007062
Trond Myklebust9af8c222010-10-24 11:52:55 -04007063 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007064 if (unlikely(!p))
7065 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007066 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007067
7068 /*
7069 * In case the server doesn't return an inode number,
7070 * we fake one here. (We don't use inode number 0,
7071 * since glibc seems to choke on it...)
7072 */
7073 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007074 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007075
Trond Myklebust9af8c222010-10-24 11:52:55 -04007076 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007077 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007078
7079 if (decode_attr_length(xdr, &len, &p) < 0)
7080 goto out_overflow;
7081
Chuck Lever573c4e12010-12-14 14:58:11 +00007082 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007083 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007084 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007085 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7086 entry->ino = entry->fattr->mounted_on_fileid;
7087 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007088 entry->ino = entry->fattr->fileid;
7089
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007090 entry->d_type = DT_UNKNOWN;
7091 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7092 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7093
Chuck Lever573c4e12010-12-14 14:58:11 +00007094 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007095
7096out_overflow:
7097 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007098 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007099}
7100
7101/*
7102 * We need to translate between nfs status return values and
7103 * the local errno values which may not be the same.
7104 */
7105static struct {
7106 int stat;
7107 int errno;
7108} nfs_errtbl[] = {
7109 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007110 { NFS4ERR_PERM, -EPERM },
7111 { NFS4ERR_NOENT, -ENOENT },
7112 { NFS4ERR_IO, -errno_NFSERR_IO},
7113 { NFS4ERR_NXIO, -ENXIO },
7114 { NFS4ERR_ACCESS, -EACCES },
7115 { NFS4ERR_EXIST, -EEXIST },
7116 { NFS4ERR_XDEV, -EXDEV },
7117 { NFS4ERR_NOTDIR, -ENOTDIR },
7118 { NFS4ERR_ISDIR, -EISDIR },
7119 { NFS4ERR_INVAL, -EINVAL },
7120 { NFS4ERR_FBIG, -EFBIG },
7121 { NFS4ERR_NOSPC, -ENOSPC },
7122 { NFS4ERR_ROFS, -EROFS },
7123 { NFS4ERR_MLINK, -EMLINK },
7124 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7125 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7126 { NFS4ERR_DQUOT, -EDQUOT },
7127 { NFS4ERR_STALE, -ESTALE },
7128 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007129 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7130 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7131 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007132 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007133 { NFS4ERR_BADTYPE, -EBADTYPE },
7134 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007135 { NFS4ERR_SYMLINK, -ELOOP },
7136 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7137 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007138 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007139};
7140
7141/*
7142 * Convert an NFS error code to a local one.
7143 * This one is used jointly by NFSv2 and NFSv3.
7144 */
7145static int
David Howells0a8ea432006-08-22 20:06:08 -04007146nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007147{
7148 int i;
7149 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7150 if (nfs_errtbl[i].stat == stat)
7151 return nfs_errtbl[i].errno;
7152 }
7153 if (stat <= 10000 || stat > 10100) {
7154 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007155 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007156 }
7157 /* If we cannot translate the error, the recovery routines should
7158 * handle it.
7159 * Note: remaining NFSv4 error codes have values > 10000, so should
7160 * not conflict with native Linux error codes.
7161 */
Benny Halevy856dff32008-03-31 17:39:06 +03007162 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007163}
7164
Linus Torvalds1da177e2005-04-16 15:20:36 -07007165#define PROC(proc, argtype, restype) \
7166[NFSPROC4_CLNT_##proc] = { \
7167 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007168 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007169 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007170 .p_arglen = NFS4_##argtype##_sz, \
7171 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007172 .p_statidx = NFSPROC4_CLNT_##proc, \
7173 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007174}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007175
7176struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007177 PROC(READ, enc_read, dec_read),
7178 PROC(WRITE, enc_write, dec_write),
7179 PROC(COMMIT, enc_commit, dec_commit),
7180 PROC(OPEN, enc_open, dec_open),
7181 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7182 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7183 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7184 PROC(CLOSE, enc_close, dec_close),
7185 PROC(SETATTR, enc_setattr, dec_setattr),
7186 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7187 PROC(RENEW, enc_renew, dec_renew),
7188 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7189 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7190 PROC(LOCK, enc_lock, dec_lock),
7191 PROC(LOCKT, enc_lockt, dec_lockt),
7192 PROC(LOCKU, enc_locku, dec_locku),
7193 PROC(ACCESS, enc_access, dec_access),
7194 PROC(GETATTR, enc_getattr, dec_getattr),
7195 PROC(LOOKUP, enc_lookup, dec_lookup),
7196 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7197 PROC(REMOVE, enc_remove, dec_remove),
7198 PROC(RENAME, enc_rename, dec_rename),
7199 PROC(LINK, enc_link, dec_link),
7200 PROC(SYMLINK, enc_symlink, dec_symlink),
7201 PROC(CREATE, enc_create, dec_create),
7202 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7203 PROC(STATFS, enc_statfs, dec_statfs),
7204 PROC(READLINK, enc_readlink, dec_readlink),
7205 PROC(READDIR, enc_readdir, dec_readdir),
7206 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7207 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7208 PROC(GETACL, enc_getacl, dec_getacl),
7209 PROC(SETACL, enc_setacl, dec_setacl),
7210 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7211 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007212 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007213#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007214 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7215 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7216 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7217 PROC(SEQUENCE, enc_sequence, dec_sequence),
7218 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7219 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7220 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7221 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007222 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007223 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007224 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007225 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007226 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007227 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007228#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007229};
7230
Trond Myklebusta613fa12012-01-20 13:53:56 -05007231const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007232 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007233 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007234 .procs = nfs4_procedures
7235};
7236
7237/*
7238 * Local variables:
7239 * c-basic-offset: 8
7240 * End:
7241 */