blob: a6b95b76622061644c64ec42e473e7c0e1b07ad7 [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>
Chuck Leverf0920752012-05-21 22:45:41 -040056
Trond Myklebust4ce79712005-06-22 17:16:21 +000057#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050058#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040059#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040060#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#define NFSDBG_FACILITY NFSDBG_XDR
63
64/* Mapping from NFS error code to "errno" error code. */
65#define errno_NFSERR_IO EIO
66
David Howells0a8ea432006-08-22 20:06:08 -040067static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
70#ifdef DEBUG
71#define NFS4_MAXTAGLEN 20
72#else
73#define NFS4_MAXTAGLEN 0
74#endif
75
Andy Adamson6c0195a2008-12-23 16:06:15 -050076/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040077 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040079#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050080#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040081#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
83#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84#define op_encode_hdr_maxsz (1)
85#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040086#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
87#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
89#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
91 (NFS4_FHSIZE >> 2))
92#define decode_putfh_maxsz (op_decode_hdr_maxsz)
93#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
94#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
95#define encode_getfh_maxsz (op_encode_hdr_maxsz)
96#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
97 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040098#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000099#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
101#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400102#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
103#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Andy Adamson88034c32012-05-23 05:02:34 -0400104/* We support only one layout type per file system */
105#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000106/* This is based on getfattr, which uses the most attributes: */
107#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400108 3 + 3 + 3 + nfs4_owner_maxsz + \
109 nfs4_group_maxsz + decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000110#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
111 nfs4_fattr_value_maxsz)
112#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400113#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
114 1 + 2 + 1 + \
115 nfs4_owner_maxsz + \
116 nfs4_group_maxsz + \
117 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#define encode_savefh_maxsz (op_encode_hdr_maxsz)
119#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400120#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
121#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200122#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400123/* The 5 accounts for the PNFS attributes, and assumes that at most three
124 * layout types will be returned.
125 */
126#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
127 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
129#define decode_renew_maxsz (op_decode_hdr_maxsz)
130#define encode_setclientid_maxsz \
131 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500132 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
133 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
134 1 /* sc_prog */ + \
135 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
136 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
137 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#define decode_setclientid_maxsz \
139 (op_decode_hdr_maxsz + \
140 2 + \
141 1024) /* large value for CLID_INUSE */
142#define encode_setclientid_confirm_maxsz \
143 (op_encode_hdr_maxsz + \
144 3 + (NFS4_VERIFIER_SIZE >> 2))
145#define decode_setclientid_confirm_maxsz \
146 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400147#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
148#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400149#define encode_share_access_maxsz \
150 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500151#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400152#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
153#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
154#define encode_open_maxsz (op_encode_hdr_maxsz + \
155 2 + encode_share_access_maxsz + 2 + \
156 open_owner_id_maxsz + \
157 encode_opentype_maxsz + \
158 encode_claim_null_maxsz)
159#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400160#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400161 decode_ace_maxsz)
162#define decode_change_info_maxsz (5)
163#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400164 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400165 decode_change_info_maxsz + 1 + \
166 nfs4_fattr_bitmap_maxsz + \
167 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400168#define encode_open_confirm_maxsz \
169 (op_encode_hdr_maxsz + \
170 encode_stateid_maxsz + 1)
171#define decode_open_confirm_maxsz \
172 (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174#define encode_open_downgrade_maxsz \
175 (op_encode_hdr_maxsz + \
176 encode_stateid_maxsz + 1 + \
177 encode_share_access_maxsz)
178#define decode_open_downgrade_maxsz \
179 (op_decode_hdr_maxsz + \
180 decode_stateid_maxsz)
181#define encode_close_maxsz (op_encode_hdr_maxsz + \
182 1 + encode_stateid_maxsz)
183#define decode_close_maxsz (op_decode_hdr_maxsz + \
184 decode_stateid_maxsz)
185#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
186 encode_stateid_maxsz + \
187 encode_attrs_maxsz)
188#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
189 nfs4_fattr_bitmap_maxsz)
190#define encode_read_maxsz (op_encode_hdr_maxsz + \
191 encode_stateid_maxsz + 3)
192#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
193#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
194 2 + encode_verifier_maxsz + 5)
195#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
196 decode_verifier_maxsz)
197#define encode_readlink_maxsz (op_encode_hdr_maxsz)
198#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
199#define encode_write_maxsz (op_encode_hdr_maxsz + \
200 encode_stateid_maxsz + 4)
201#define decode_write_maxsz (op_decode_hdr_maxsz + \
202 2 + decode_verifier_maxsz)
203#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
204#define decode_commit_maxsz (op_decode_hdr_maxsz + \
205 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206#define encode_remove_maxsz (op_encode_hdr_maxsz + \
207 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400208#define decode_remove_maxsz (op_decode_hdr_maxsz + \
209 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#define encode_rename_maxsz (op_encode_hdr_maxsz + \
211 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400212#define decode_rename_maxsz (op_decode_hdr_maxsz + \
213 decode_change_info_maxsz + \
214 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215#define encode_link_maxsz (op_encode_hdr_maxsz + \
216 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400217#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400218#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400219#define encode_lock_maxsz (op_encode_hdr_maxsz + \
220 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400221 1 + encode_stateid_maxsz + 1 + \
222 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400223#define decode_lock_denied_maxsz \
224 (8 + decode_lockowner_maxsz)
225#define decode_lock_maxsz (op_decode_hdr_maxsz + \
226 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400227#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
228 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400229#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
230 decode_lock_denied_maxsz)
231#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
232 encode_stateid_maxsz + \
233 4)
234#define decode_locku_maxsz (op_decode_hdr_maxsz + \
235 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400236#define encode_release_lockowner_maxsz \
237 (op_encode_hdr_maxsz + \
238 encode_lockowner_maxsz)
239#define decode_release_lockowner_maxsz \
240 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400241#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
242#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
244 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400245 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000246 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
248#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400249 1 + 2 + nfs4_name_maxsz + \
250 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400251#define decode_create_maxsz (op_decode_hdr_maxsz + \
252 decode_change_info_maxsz + \
253 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400254#define encode_statfs_maxsz (encode_getattr_maxsz)
255#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
257#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400258#define encode_getacl_maxsz (encode_getattr_maxsz)
259#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
260 nfs4_fattr_bitmap_maxsz + 1)
261#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
262 encode_stateid_maxsz + 3)
263#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400264#define encode_fs_locations_maxsz \
265 (encode_getattr_maxsz)
266#define decode_fs_locations_maxsz \
267 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000268#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400269#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 -0400270
271#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400272#define NFS4_MAX_MACHINE_NAME_LEN (64)
273
Benny Halevy99fe60d2009-04-01 09:22:29 -0400274#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
275 encode_verifier_maxsz + \
276 1 /* co_ownerid.len */ + \
277 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
278 1 /* flags */ + \
279 1 /* spa_how */ + \
280 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500281 1 /* implementation id array of size 1 */ + \
282 1 /* nii_domain */ + \
283 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
284 1 /* nii_name */ + \
285 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
286 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400287#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
288 2 /* eir_clientid */ + \
289 1 /* eir_sequenceid */ + \
290 1 /* eir_flags */ + \
291 1 /* spr_how */ + \
292 0 /* SP4_NONE (for now) */ + \
293 2 /* eir_server_owner.so_minor_id */ + \
294 /* eir_server_owner.so_major_id<> */ \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
296 /* eir_server_scope<> */ \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
298 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500299 1 /* nii_domain */ + \
300 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
301 1 /* nii_name */ + \
302 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
303 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400304#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
305#define decode_channel_attrs_maxsz (6 + \
306 1 /* ca_rdma_ird.len */ + \
307 1 /* ca_rdma_ird */)
308#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
309 2 /* csa_clientid */ + \
310 1 /* csa_sequence */ + \
311 1 /* csa_flags */ + \
312 encode_channel_attrs_maxsz + \
313 encode_channel_attrs_maxsz + \
314 1 /* csa_cb_program */ + \
315 1 /* csa_sec_parms.len (1) */ + \
316 1 /* cb_secflavor (AUTH_SYS) */ + \
317 1 /* stamp */ + \
318 1 /* machinename.len */ + \
319 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
320 1 /* uid */ + \
321 1 /* gid */ + \
322 1 /* gids.len (0) */)
323#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
324 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
325 1 /* csr_sequence */ + \
326 1 /* csr_flags */ + \
327 decode_channel_attrs_maxsz + \
328 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400329#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
330 /* bctsa_sessid */ \
331 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
332 1 /* bctsa_dir */ + \
333 1 /* bctsa_use_conn_in_rdma_mode */)
334#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
335 /* bctsr_sessid */ \
336 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
337 1 /* bctsr_dir */ + \
338 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400339#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
340#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400341#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
342 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
343#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
344 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500345#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
346#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400347#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
348 encode_verifier_maxsz)
349#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
350 2 /* nfs_cookie4 gdlr_cookie */ + \
351 decode_verifier_maxsz \
352 /* verifier4 gdlr_verifier */ + \
353 1 /* gdlr_deviceid_list count */ + \
354 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
355 NFS4_DEVICEID4_SIZE) \
356 /* gdlr_deviceid_list */ + \
357 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400358#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
359 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
360#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
361 1 /* layout type */ + \
362 1 /* opaque devaddr4 length */ + \
363 /* devaddr4 payload is read into page */ \
364 1 /* notification bitmap length */ + \
365 1 /* notification bitmap */)
366#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
367 encode_stateid_maxsz)
368#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
369 decode_stateid_maxsz + \
370 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000371#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
372 2 /* offset */ + \
373 2 /* length */ + \
374 1 /* reclaim */ + \
375 encode_stateid_maxsz + \
376 1 /* new offset (true) */ + \
377 2 /* last byte written */ + \
378 1 /* nt_timechanged (false) */ + \
379 1 /* layoutupdate4 layout type */ + \
380 1 /* NULL filelayout layoutupdate4 payload */)
381#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300382#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
383 encode_stateid_maxsz + \
384 1 /* FIXME: opaque lrf_body always empty at the moment */)
385#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
386 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400387#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
388#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400389#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
390 XDR_QUADLEN(NFS4_STATEID_SIZE))
391#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400392#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
393 XDR_QUADLEN(NFS4_STATEID_SIZE))
394#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400395#else /* CONFIG_NFS_V4_1 */
396#define encode_sequence_maxsz 0
397#define decode_sequence_maxsz 0
398#endif /* CONFIG_NFS_V4_1 */
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
401#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
402#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400403 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400405 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400407 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400409 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400411 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400413 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400415 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400417 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400419 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400421 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400423 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400425 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400429 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400430 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400434 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400435 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400439 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400443 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400445 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400446 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400447 encode_open_maxsz + \
448 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400449 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400452 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400453 decode_open_maxsz + \
454 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400455 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400456#define NFS4_enc_open_confirm_sz \
457 (compound_encode_hdr_maxsz + \
458 encode_putfh_maxsz + \
459 encode_open_confirm_maxsz)
460#define NFS4_dec_open_confirm_sz \
461 (compound_decode_hdr_maxsz + \
462 decode_putfh_maxsz + \
463 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400465 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400467 encode_open_maxsz + \
468 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400470 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 decode_open_maxsz + \
473 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#define NFS4_enc_open_downgrade_sz \
475 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400476 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400477 encode_putfh_maxsz + \
478 encode_open_downgrade_maxsz + \
479 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#define NFS4_dec_open_downgrade_sz \
481 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400482 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400483 decode_putfh_maxsz + \
484 decode_open_downgrade_maxsz + \
485 decode_getattr_maxsz)
486#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400487 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400488 encode_putfh_maxsz + \
489 encode_close_maxsz + \
490 encode_getattr_maxsz)
491#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400493 decode_putfh_maxsz + \
494 decode_close_maxsz + \
495 decode_getattr_maxsz)
496#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400497 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400498 encode_putfh_maxsz + \
499 encode_setattr_maxsz + \
500 encode_getattr_maxsz)
501#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400502 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400503 decode_putfh_maxsz + \
504 decode_setattr_maxsz + \
505 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400507 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 encode_putfh_maxsz + \
509 encode_fsinfo_maxsz)
510#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400511 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 decode_putfh_maxsz + \
513 decode_fsinfo_maxsz)
514#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
515 encode_renew_maxsz)
516#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
517 decode_renew_maxsz)
518#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
519 encode_setclientid_maxsz)
520#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
521 decode_setclientid_maxsz)
522#define NFS4_enc_setclientid_confirm_sz \
523 (compound_encode_hdr_maxsz + \
524 encode_setclientid_confirm_maxsz + \
525 encode_putrootfh_maxsz + \
526 encode_fsinfo_maxsz)
527#define NFS4_dec_setclientid_confirm_sz \
528 (compound_decode_hdr_maxsz + \
529 decode_setclientid_confirm_maxsz + \
530 decode_putrootfh_maxsz + \
531 decode_fsinfo_maxsz)
532#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400533 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400535 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400537 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400539 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400541 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400543 encode_lockt_maxsz)
544#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400545 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400546 decode_putfh_maxsz + \
547 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400549 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400551 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400553 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400555 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400556#define NFS4_enc_release_lockowner_sz \
557 (compound_encode_hdr_maxsz + \
558 encode_lockowner_maxsz)
559#define NFS4_dec_release_lockowner_sz \
560 (compound_decode_hdr_maxsz + \
561 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400563 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400565 encode_access_maxsz + \
566 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400570 decode_access_maxsz + \
571 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400573 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 encode_putfh_maxsz + \
575 encode_getattr_maxsz)
576#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400577 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 decode_putfh_maxsz + \
579 decode_getattr_maxsz)
580#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400581 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 encode_putfh_maxsz + \
583 encode_lookup_maxsz + \
584 encode_getattr_maxsz + \
585 encode_getfh_maxsz)
586#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400587 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400589 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 decode_getattr_maxsz + \
591 decode_getfh_maxsz)
592#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400593 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 encode_putrootfh_maxsz + \
595 encode_getattr_maxsz + \
596 encode_getfh_maxsz)
597#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 decode_putrootfh_maxsz + \
600 decode_getattr_maxsz + \
601 decode_getfh_maxsz)
602#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400603 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400605 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400607 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400609 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400611 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 encode_putfh_maxsz + \
613 encode_savefh_maxsz + \
614 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400615 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400617 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 decode_putfh_maxsz + \
619 decode_savefh_maxsz + \
620 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400621 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400623 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 encode_putfh_maxsz + \
625 encode_savefh_maxsz + \
626 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400627 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400628 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400629 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400631 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 decode_putfh_maxsz + \
633 decode_savefh_maxsz + \
634 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400635 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400636 decode_restorefh_maxsz + \
637 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400639 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 encode_putfh_maxsz + \
641 encode_symlink_maxsz + \
642 encode_getattr_maxsz + \
643 encode_getfh_maxsz)
644#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400645 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 decode_putfh_maxsz + \
647 decode_symlink_maxsz + \
648 decode_getattr_maxsz + \
649 decode_getfh_maxsz)
650#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400651 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 encode_putfh_maxsz + \
653 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400654 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400655 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400657 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 decode_putfh_maxsz + \
659 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400660 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400661 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 encode_putfh_maxsz + \
665 encode_getattr_maxsz)
666#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400667 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 decode_putfh_maxsz + \
669 decode_getattr_maxsz)
670#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400671 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400673 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400675 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400677 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400679 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800680 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_getattr_maxsz)
682#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400683 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800684 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 decode_getattr_maxsz)
686#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400687 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100689 encode_delegreturn_maxsz + \
690 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100693 decode_delegreturn_maxsz + \
694 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000695#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000697 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400698 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000699#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400700 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000701 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400702 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000703#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400704 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000705 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400706 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000707#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400708 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000709 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400710 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400711#define NFS4_enc_fs_locations_sz \
712 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400714 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400715 encode_lookup_maxsz + \
716 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400717#define NFS4_dec_fs_locations_sz \
718 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400719 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400720 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400721 decode_lookup_maxsz + \
722 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000723#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
724 encode_sequence_maxsz + \
725 encode_putfh_maxsz + \
726 encode_secinfo_maxsz)
727#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
728 decode_sequence_maxsz + \
729 decode_putfh_maxsz + \
730 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400731#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400732#define NFS4_enc_bind_conn_to_session_sz \
733 (compound_encode_hdr_maxsz + \
734 encode_bind_conn_to_session_maxsz)
735#define NFS4_dec_bind_conn_to_session_sz \
736 (compound_decode_hdr_maxsz + \
737 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400738#define NFS4_enc_exchange_id_sz \
739 (compound_encode_hdr_maxsz + \
740 encode_exchange_id_maxsz)
741#define NFS4_dec_exchange_id_sz \
742 (compound_decode_hdr_maxsz + \
743 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400744#define NFS4_enc_create_session_sz \
745 (compound_encode_hdr_maxsz + \
746 encode_create_session_maxsz)
747#define NFS4_dec_create_session_sz \
748 (compound_decode_hdr_maxsz + \
749 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400750#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
751 encode_destroy_session_maxsz)
752#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
753 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400754#define NFS4_enc_sequence_sz \
755 (compound_decode_hdr_maxsz + \
756 encode_sequence_maxsz)
757#define NFS4_dec_sequence_sz \
758 (compound_decode_hdr_maxsz + \
759 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400760#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
761 encode_sequence_maxsz + \
762 encode_putrootfh_maxsz + \
763 encode_fsinfo_maxsz)
764#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
765 decode_sequence_maxsz + \
766 decode_putrootfh_maxsz + \
767 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500768#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
769 encode_sequence_maxsz + \
770 encode_reclaim_complete_maxsz)
771#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
772 decode_sequence_maxsz + \
773 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400774#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
775 encode_sequence_maxsz + \
776 encode_putfh_maxsz + \
777 encode_getdevicelist_maxsz)
778#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
779 decode_sequence_maxsz + \
780 decode_putfh_maxsz + \
781 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400782#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
783 encode_sequence_maxsz +\
784 encode_getdeviceinfo_maxsz)
785#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
786 decode_sequence_maxsz + \
787 decode_getdeviceinfo_maxsz)
788#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
789 encode_sequence_maxsz + \
790 encode_putfh_maxsz + \
791 encode_layoutget_maxsz)
792#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
793 decode_sequence_maxsz + \
794 decode_putfh_maxsz + \
795 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000796#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
797 encode_sequence_maxsz +\
798 encode_putfh_maxsz + \
799 encode_layoutcommit_maxsz + \
800 encode_getattr_maxsz)
801#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_putfh_maxsz + \
804 decode_layoutcommit_maxsz + \
805 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300806#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
807 encode_sequence_maxsz + \
808 encode_putfh_maxsz + \
809 encode_layoutreturn_maxsz)
810#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
811 decode_sequence_maxsz + \
812 decode_putfh_maxsz + \
813 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400814#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
815 encode_sequence_maxsz + \
816 encode_putrootfh_maxsz +\
817 encode_secinfo_no_name_maxsz)
818#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
819 decode_sequence_maxsz + \
820 decode_putrootfh_maxsz + \
821 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400822#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
823 encode_sequence_maxsz + \
824 encode_test_stateid_maxsz)
825#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
826 decode_sequence_maxsz + \
827 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400828#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
829 encode_sequence_maxsz + \
830 encode_free_stateid_maxsz)
831#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
832 decode_sequence_maxsz + \
833 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500834
835const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
836 compound_encode_hdr_maxsz +
837 encode_sequence_maxsz +
838 encode_putfh_maxsz +
839 encode_getattr_maxsz) *
840 XDR_UNIT);
841
842const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
843 compound_decode_hdr_maxsz +
844 decode_sequence_maxsz +
845 decode_putfh_maxsz) *
846 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400847#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500849static unsigned short send_implementation_id = 1;
850
851module_param(send_implementation_id, ushort, 0644);
852MODULE_PARM_DESC(send_implementation_id,
853 "Send implementation ID with NFSv4.1 exchange_id");
854
Trond Myklebustbca79472009-03-11 14:10:26 -0400855static const umode_t nfs_type2fmt[] = {
856 [NF4BAD] = 0,
857 [NF4REG] = S_IFREG,
858 [NF4DIR] = S_IFDIR,
859 [NF4BLK] = S_IFBLK,
860 [NF4CHR] = S_IFCHR,
861 [NF4LNK] = S_IFLNK,
862 [NF4SOCK] = S_IFSOCK,
863 [NF4FIFO] = S_IFIFO,
864 [NF4ATTRDIR] = 0,
865 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866};
867
868struct compound_hdr {
869 int32_t status;
870 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500871 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 uint32_t taglen;
873 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400874 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400875 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876};
877
Benny Halevy13c65ce2009-08-14 17:19:25 +0300878static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
879{
880 __be32 *p = xdr_reserve_space(xdr, nbytes);
881 BUG_ON(!p);
882 return p;
883}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
Trond Myklebustcb17e552012-03-04 18:13:56 -0500885static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
886{
887 __be32 *p;
888
889 p = xdr_reserve_space(xdr, len);
890 xdr_encode_opaque_fixed(p, buf, len);
891}
892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
894{
Al Viro8687b632006-10-19 23:28:48 -0700895 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500897 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 xdr_encode_opaque(p, str, len);
899}
900
Trond Myklebust4ade9822012-03-04 18:13:57 -0500901static void encode_uint32(struct xdr_stream *xdr, u32 n)
902{
903 __be32 *p;
904
905 p = reserve_space(xdr, 4);
906 *p = cpu_to_be32(n);
907}
908
Trond Myklebustff2eb682012-03-05 11:40:12 -0500909static void encode_uint64(struct xdr_stream *xdr, u64 n)
910{
911 __be32 *p;
912
913 p = reserve_space(xdr, 8);
914 xdr_encode_hyper(p, n);
915}
916
Trond Myklebust4ade9822012-03-04 18:13:57 -0500917static void encode_nfs4_seqid(struct xdr_stream *xdr,
918 const struct nfs_seqid *seqid)
919{
920 encode_uint32(xdr, seqid->sequence->counter);
921}
922
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400923static void encode_compound_hdr(struct xdr_stream *xdr,
924 struct rpc_rqst *req,
925 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
Al Viro8687b632006-10-19 23:28:48 -0700927 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400928 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400929
930 /* initialize running count of expected bytes in reply.
931 * NOTE: the replied tag SHOULD be the same is the one sent,
932 * but this is not required as a MUST for the server to do so. */
933 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500936 encode_string(xdr, hdr->taglen, hdr->tag);
937 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300938 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500939 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300940 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500941}
942
Trond Myklebustab19b482012-03-04 18:13:57 -0500943static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
944 uint32_t replen,
945 struct compound_hdr *hdr)
946{
947 encode_uint32(xdr, op);
948 hdr->nops++;
949 hdr->replen += replen;
950}
951
Andy Adamsond0179312008-12-23 16:06:17 -0500952static void encode_nops(struct compound_hdr *hdr)
953{
Andy Adamsonfc931582009-04-01 09:22:31 -0400954 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500955 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956}
957
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500958static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
959{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500960 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500961}
962
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
964{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500965 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966}
967
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500968static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
970 char owner_name[IDMAP_NAMESZ];
971 char owner_group[IDMAP_NAMESZ];
972 int owner_namelen = 0;
973 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700974 __be32 *p;
975 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 int len;
977 uint32_t bmval0 = 0;
978 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 /*
981 * We reserve enough space to write the entire attribute buffer at once.
982 * In the worst-case, this would be
983 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
984 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000985 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 */
987 len = 16;
988
989 /* Sigh */
990 if (iap->ia_valid & ATTR_SIZE)
991 len += 8;
992 if (iap->ia_valid & ATTR_MODE)
993 len += 4;
994 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800995 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400997 dprintk("nfs: couldn't resolve uid %d to string\n",
998 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 /* XXX */
1000 strcpy(owner_name, "nobody");
1001 owner_namelen = sizeof("nobody") - 1;
1002 /* goto out; */
1003 }
1004 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1005 }
1006 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001007 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001009 dprintk("nfs: couldn't resolve gid %d to string\n",
1010 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 strcpy(owner_group, "nobody");
1012 owner_grouplen = sizeof("nobody") - 1;
1013 /* goto out; */
1014 }
1015 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1016 }
1017 if (iap->ia_valid & ATTR_ATIME_SET)
1018 len += 16;
1019 else if (iap->ia_valid & ATTR_ATIME)
1020 len += 4;
1021 if (iap->ia_valid & ATTR_MTIME_SET)
1022 len += 16;
1023 else if (iap->ia_valid & ATTR_MTIME)
1024 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001025 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
1027 /*
1028 * We write the bitmap length now, but leave the bitmap and the attribute
1029 * buffer length to be backfilled at the end of this routine.
1030 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001031 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 q = p;
1033 p += 3;
1034
1035 if (iap->ia_valid & ATTR_SIZE) {
1036 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001037 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 }
1039 if (iap->ia_valid & ATTR_MODE) {
1040 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001041 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 }
1043 if (iap->ia_valid & ATTR_UID) {
1044 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001045 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 }
1047 if (iap->ia_valid & ATTR_GID) {
1048 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001049 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 }
1051 if (iap->ia_valid & ATTR_ATIME_SET) {
1052 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001053 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1054 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001055 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1056 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
1058 else if (iap->ia_valid & ATTR_ATIME) {
1059 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001060 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 }
1062 if (iap->ia_valid & ATTR_MTIME_SET) {
1063 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001064 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1065 *p++ = cpu_to_be32(0);
1066 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1067 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
1069 else if (iap->ia_valid & ATTR_MTIME) {
1070 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001071 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001073
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 /*
1075 * Now we backfill the bitmap and the attribute buffer length.
1076 */
1077 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001078 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 len, ((char *)p - (char *)q) + 4);
1080 BUG();
1081 }
1082 len = (char *)p - (char *)q - 12;
1083 *q++ = htonl(bmval0);
1084 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001085 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001090static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001092 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1093 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001096static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097{
Trond Myklebustab19b482012-03-04 18:13:57 -05001098 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001099 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001100 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101}
1102
Fred Isaman0b7c0152012-04-20 14:47:39 -04001103static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
Al Viro8687b632006-10-19 23:28:48 -07001105 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001106
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001107 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1108 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001109 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001110 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111}
1112
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001113static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114{
Al Viro8687b632006-10-19 23:28:48 -07001115 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001116
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001117 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1118 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
1120 switch (create->ftype) {
1121 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001122 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001123 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001124 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 break;
1126
1127 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001128 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001129 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001130 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 break;
1132
1133 default:
1134 break;
1135 }
1136
Benny Halevy811652b2009-08-14 17:19:34 +03001137 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001138 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Andy Adamson05d564f2008-12-23 16:06:15 -05001143 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001145 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1146 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001147 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001148 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149}
1150
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001151static 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 -07001152{
Andy Adamson05d564f2008-12-23 16:06:15 -05001153 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001155 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1156 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001157 *p++ = cpu_to_be32(2);
1158 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001159 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
Fred Isamandae100c2011-07-30 20:52:37 -04001162static void
1163encode_getattr_three(struct xdr_stream *xdr,
1164 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1165 struct compound_hdr *hdr)
1166{
1167 __be32 *p;
1168
Trond Myklebustab19b482012-03-04 18:13:57 -05001169 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001170 if (bm2) {
1171 p = reserve_space(xdr, 16);
1172 *p++ = cpu_to_be32(3);
1173 *p++ = cpu_to_be32(bm0);
1174 *p++ = cpu_to_be32(bm1);
1175 *p = cpu_to_be32(bm2);
1176 } else if (bm1) {
1177 p = reserve_space(xdr, 12);
1178 *p++ = cpu_to_be32(2);
1179 *p++ = cpu_to_be32(bm0);
1180 *p = cpu_to_be32(bm1);
1181 } else {
1182 p = reserve_space(xdr, 8);
1183 *p++ = cpu_to_be32(1);
1184 *p = cpu_to_be32(bm0);
1185 }
Fred Isamandae100c2011-07-30 20:52:37 -04001186}
1187
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001188static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001190 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1191 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192}
1193
Andy Adamson88034c32012-05-23 05:02:34 -04001194static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
1195 struct compound_hdr *hdr)
1196{
1197 encode_getattr_three(xdr,
1198 bitmask[0] & nfs4_fattr_bitmap[0],
1199 bitmask[1] & nfs4_fattr_bitmap[1],
1200 bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD,
1201 hdr);
1202}
1203
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001204static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205{
Fred Isamandae100c2011-07-30 20:52:37 -04001206 encode_getattr_three(xdr,
1207 bitmask[0] & nfs4_fsinfo_bitmap[0],
1208 bitmask[1] & nfs4_fsinfo_bitmap[1],
1209 bitmask[2] & nfs4_fsinfo_bitmap[2],
1210 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211}
1212
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001213static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001214{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001215 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1216 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001217}
1218
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001219static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220{
Trond Myklebustab19b482012-03-04 18:13:57 -05001221 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222}
1223
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001224static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225{
Trond Myklebustab19b482012-03-04 18:13:57 -05001226 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001227 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001230static inline int nfs4_lock_type(struct file_lock *fl, int block)
1231{
1232 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1233 return block ? NFS4_READW_LT : NFS4_READ_LT;
1234 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1235}
1236
1237static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1238{
1239 if (fl->fl_end == OFFSET_MAX)
1240 return ~(uint64_t)0;
1241 return fl->fl_end - fl->fl_start + 1;
1242}
1243
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001244static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1245{
1246 __be32 *p;
1247
Trond Myklebustd035c362010-12-21 10:45:27 -05001248 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001249 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001250 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001251 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001252 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001253 xdr_encode_hyper(p, lowner->id);
1254}
1255
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256/*
1257 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1258 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1259 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001260static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
Al Viro8687b632006-10-19 23:28:48 -07001262 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001264 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1265 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001266 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1267 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001268 p = xdr_encode_hyper(p, args->fl->fl_start);
1269 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001270 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001271 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001272 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001273 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001274 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001275 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 }
1277 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001278 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001279 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281}
1282
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001283static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284{
Al Viro8687b632006-10-19 23:28:48 -07001285 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001287 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1288 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001289 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001290 p = xdr_encode_hyper(p, args->fl->fl_start);
1291 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001292 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293}
1294
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001295static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296{
Al Viro8687b632006-10-19 23:28:48 -07001297 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001299 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1300 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001301 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001302 encode_nfs4_stateid(xdr, args->stateid);
1303 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001304 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001305 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306}
1307
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001308static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1309{
Trond Myklebustab19b482012-03-04 18:13:57 -05001310 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001311 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001312}
1313
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001314static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
Trond Myklebustab19b482012-03-04 18:13:57 -05001316 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001317 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
1319
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001320static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321{
Al Viro8687b632006-10-19 23:28:48 -07001322 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Benny Halevy13c65ce2009-08-14 17:19:25 +03001324 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001325 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001326 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001327 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001328 break;
1329 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001330 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001331 break;
1332 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001333 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001334 break;
1335 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001336 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 }
Benny Halevy34558512009-08-14 17:19:30 +03001338 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339}
1340
1341static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1342{
Al Viro8687b632006-10-19 23:28:48 -07001343 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 /*
1345 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1346 * owner 4 = 32
1347 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001348 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001349 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001350 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001351 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001352 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001353 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001354 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001355 *p++ = cpu_to_be32(arg->id.uniquifier);
1356 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357}
1358
1359static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1360{
Al Viro8687b632006-10-19 23:28:48 -07001361 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001362 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Benny Halevy13c65ce2009-08-14 17:19:25 +03001364 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001366 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001367 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001368 encode_attrs(xdr, arg->u.attrs, arg->server);
1369 break;
1370 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001371 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001372 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001373 if (nfs4_has_persistent_session(clp)) {
1374 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1375 encode_attrs(xdr, arg->u.attrs, arg->server);
1376 } else {
1377 struct iattr dummy;
1378
1379 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1380 encode_nfs4_verifier(xdr, &arg->u.verifier);
1381 dummy.ia_valid = 0;
1382 encode_attrs(xdr, &dummy, arg->server);
1383 }
1384 } else {
1385 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1386 encode_nfs4_verifier(xdr, &arg->u.verifier);
1387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 }
1389}
1390
1391static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1392{
Al Viro8687b632006-10-19 23:28:48 -07001393 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Benny Halevy13c65ce2009-08-14 17:19:25 +03001395 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001397 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001398 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001399 break;
1400 default:
1401 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001402 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001403 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 }
1405}
1406
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001407static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408{
Al Viro8687b632006-10-19 23:28:48 -07001409 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Benny Halevy13c65ce2009-08-14 17:19:25 +03001411 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001413 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001414 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001415 break;
1416 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001417 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001418 break;
1419 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001420 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001421 break;
1422 default:
1423 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 }
1425}
1426
1427static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1428{
Al Viro8687b632006-10-19 23:28:48 -07001429 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Benny Halevy13c65ce2009-08-14 17:19:25 +03001431 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001432 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 encode_string(xdr, name->len, name->name);
1434}
1435
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001436static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437{
Al Viro8687b632006-10-19 23:28:48 -07001438 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Benny Halevy13c65ce2009-08-14 17:19:25 +03001440 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001441 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 encode_delegation_type(xdr, type);
1443}
1444
1445static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1446{
Al Viro8687b632006-10-19 23:28:48 -07001447 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001449 p = reserve_space(xdr, 4);
1450 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1451 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 encode_string(xdr, name->len, name->name);
1453}
1454
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001455static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456{
Trond Myklebustab19b482012-03-04 18:13:57 -05001457 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 encode_openhdr(xdr, arg);
1459 encode_opentype(xdr, arg);
1460 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001461 case NFS4_OPEN_CLAIM_NULL:
1462 encode_claim_null(xdr, arg->name);
1463 break;
1464 case NFS4_OPEN_CLAIM_PREVIOUS:
1465 encode_claim_previous(xdr, arg->u.delegation_type);
1466 break;
1467 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1468 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1469 break;
1470 default:
1471 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001475static 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 -07001476{
Trond Myklebustab19b482012-03-04 18:13:57 -05001477 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001478 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001479 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480}
1481
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001482static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483{
Trond Myklebustab19b482012-03-04 18:13:57 -05001484 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001485 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001486 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001487 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488}
1489
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001490static void
Andy Adamsond0179312008-12-23 16:06:17 -05001491encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492{
Trond Myklebustab19b482012-03-04 18:13:57 -05001493 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001494 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495}
1496
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001497static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
Trond Myklebustab19b482012-03-04 18:13:57 -05001499 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500}
1501
Trond Myklebust4fc87962012-03-08 17:42:01 -05001502static void encode_open_stateid(struct xdr_stream *xdr,
1503 const struct nfs_open_context *ctx,
1504 const struct nfs_lock_context *l_ctx,
1505 fmode_t fmode,
1506 int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 if (ctx->state != NULL) {
Trond Myklebust4fc87962012-03-08 17:42:01 -05001511 nfs4_select_rw_stateid(&stateid, ctx->state,
1512 fmode, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001513 if (zero_seqid)
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001514 stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001515 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001517 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518}
1519
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001520static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
Al Viro8687b632006-10-19 23:28:48 -07001522 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Trond Myklebustab19b482012-03-04 18:13:57 -05001524 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001525 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001526 FMODE_READ, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
Benny Halevy13c65ce2009-08-14 17:19:25 +03001528 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001529 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001530 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531}
1532
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001533static 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 -07001534{
Trond Myklebust28331a42011-04-27 13:47:52 -04001535 uint32_t attrs[2] = {
1536 FATTR4_WORD0_RDATTR_ERROR,
1537 FATTR4_WORD1_MOUNTED_ON_FILEID,
1538 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001539 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001540 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001542 if (readdir->plus) {
1543 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001544 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001545 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1546 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1547 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1548 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001549 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001550 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001551 /* Use mounted_on_fileid only if the server supports it */
1552 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1553 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001554
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001555 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001556 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001557 encode_nfs4_verifier(xdr, &readdir->verifier);
1558 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001559 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001560 *p++ = cpu_to_be32(readdir->count);
1561 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001562
Benny Halevye75bc1c2009-08-14 17:18:54 +03001563 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001564 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001565 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001566 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1567 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001568 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001569 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001570 attrs[0] & readdir->bitmask[0],
1571 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572}
1573
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001574static 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 -07001575{
Trond Myklebustab19b482012-03-04 18:13:57 -05001576 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001579static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
Trond Myklebustab19b482012-03-04 18:13:57 -05001581 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001582 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583}
1584
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001585static 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 -07001586{
Trond Myklebustab19b482012-03-04 18:13:57 -05001587 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001588 encode_string(xdr, oldname->len, oldname->name);
1589 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590}
1591
Chuck Leverbb4dae52012-03-01 17:01:48 -05001592static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1593 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001595 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001596 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597}
1598
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001599static void
Andy Adamsond0179312008-12-23 16:06:17 -05001600encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001601{
Trond Myklebustab19b482012-03-04 18:13:57 -05001602 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001603}
1604
Chuck Lever9f06c712010-12-14 14:59:18 +00001605static void
Andy Adamsond0179312008-12-23 16:06:17 -05001606encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001607{
Al Viro8687b632006-10-19 23:28:48 -07001608 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001609
Trond Myklebustab19b482012-03-04 18:13:57 -05001610 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001611 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001612 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001613 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001614 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001615 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001616 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001617 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001618 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001619}
1620
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001621static void
Andy Adamsond0179312008-12-23 16:06:17 -05001622encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623{
Trond Myklebustab19b482012-03-04 18:13:57 -05001624 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625}
1626
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001627static 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 -07001628{
Trond Myklebustab19b482012-03-04 18:13:57 -05001629 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001630 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001631 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001634static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635{
Al Viro8687b632006-10-19 23:28:48 -07001636 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
Trond Myklebust70019512012-03-04 20:49:32 -05001638 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001639 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
1641 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001642 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001643 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1645 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001646 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001647 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648}
1649
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001650static 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 -07001651{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001652 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1653 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001654 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001655 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
1657
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001658static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659{
Al Viro8687b632006-10-19 23:28:48 -07001660 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
Trond Myklebustab19b482012-03-04 18:13:57 -05001662 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001663 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001664 FMODE_WRITE, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
Benny Halevy13c65ce2009-08-14 17:19:25 +03001666 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001667 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001668 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001669 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
1671 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672}
1673
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001674static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
Trond Myklebustab19b482012-03-04 18:13:57 -05001676 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001677 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001679
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001680static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1681{
Trond Myklebustab19b482012-03-04 18:13:57 -05001682 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001683 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001684}
1685
Benny Halevy99fe60d2009-04-01 09:22:29 -04001686#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001687/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001688static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1689 struct nfs4_session *session,
1690 struct compound_hdr *hdr)
1691{
1692 __be32 *p;
1693
1694 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1695 decode_bind_conn_to_session_maxsz, hdr);
1696 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1697 p = xdr_reserve_space(xdr, 8);
1698 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1699 *p = 0; /* use_conn_in_rdma_mode = False */
1700}
1701
Benny Halevy99fe60d2009-04-01 09:22:29 -04001702static void encode_exchange_id(struct xdr_stream *xdr,
1703 struct nfs41_exchange_id_args *args,
1704 struct compound_hdr *hdr)
1705{
1706 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001707 char impl_name[NFS4_OPAQUE_LIMIT];
1708 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001709
Trond Myklebust70019512012-03-04 20:49:32 -05001710 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001711 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001712
1713 encode_string(xdr, args->id_len, args->id);
1714
Benny Halevy13c65ce2009-08-14 17:19:25 +03001715 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001716 *p++ = cpu_to_be32(args->flags);
1717 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001718
1719 if (send_implementation_id &&
1720 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1721 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1722 <= NFS4_OPAQUE_LIMIT + 1)
1723 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1724 utsname()->sysname, utsname()->release,
1725 utsname()->version, utsname()->machine);
1726
1727 if (len > 0) {
1728 *p = cpu_to_be32(1); /* implementation id array length=1 */
1729
1730 encode_string(xdr,
1731 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1732 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1733 encode_string(xdr, len, impl_name);
1734 /* just send zeros for nii_date - the date is in nii_name */
1735 p = reserve_space(xdr, 12);
1736 p = xdr_encode_hyper(p, 0);
1737 *p = cpu_to_be32(0);
1738 } else
1739 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001740}
Andy Adamsonfc931582009-04-01 09:22:31 -04001741
1742static void encode_create_session(struct xdr_stream *xdr,
1743 struct nfs41_create_session_args *args,
1744 struct compound_hdr *hdr)
1745{
1746 __be32 *p;
1747 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1748 uint32_t len;
1749 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001750 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001751 u32 max_resp_sz_cached;
1752
1753 /*
1754 * Assumes OPEN is the biggest non-idempotent compound.
1755 * 2 is the verifier.
1756 */
1757 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1758 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001759
Andy Adamsonfc931582009-04-01 09:22:31 -04001760 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1761 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001762
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001763 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1764 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001765 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001766 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1767 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001768
Andy Adamsonfc931582009-04-01 09:22:31 -04001769 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001770 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001771 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1772 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001773 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001774 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1775 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1776 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001777
1778 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001779 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001780 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1781 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1782 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1783 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1784 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1785 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001786
Benny Halevye75bc1c2009-08-14 17:18:54 +03001787 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001788 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001789 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001790
1791 /* authsys_parms rfc1831 */
Chuck Leverf0920752012-05-21 22:45:41 -04001792 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001793 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001794 *p++ = cpu_to_be32(0); /* UID */
1795 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001796 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001797}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001798
1799static void encode_destroy_session(struct xdr_stream *xdr,
1800 struct nfs4_session *session,
1801 struct compound_hdr *hdr)
1802{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001803 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1804 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001805}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001806
1807static void encode_reclaim_complete(struct xdr_stream *xdr,
1808 struct nfs41_reclaim_complete_args *args,
1809 struct compound_hdr *hdr)
1810{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001811 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1812 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001813}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001814#endif /* CONFIG_NFS_V4_1 */
1815
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001816static void encode_sequence(struct xdr_stream *xdr,
1817 const struct nfs4_sequence_args *args,
1818 struct compound_hdr *hdr)
1819{
1820#if defined(CONFIG_NFS_V4_1)
1821 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001822 struct nfs4_slot_table *tp;
1823 struct nfs4_slot *slot;
1824 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001825
1826 if (!session)
1827 return;
1828
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001829 tp = &session->fc_slot_table;
1830
1831 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1832 slot = tp->slots + args->sa_slotid;
1833
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001834 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001835
1836 /*
1837 * Sessionid + seqid + slotid + max slotid + cache_this
1838 */
1839 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1840 "max_slotid=%d cache_this=%d\n",
1841 __func__,
1842 ((u32 *)session->sess_id.data)[0],
1843 ((u32 *)session->sess_id.data)[1],
1844 ((u32 *)session->sess_id.data)[2],
1845 ((u32 *)session->sess_id.data)[3],
1846 slot->seq_nr, args->sa_slotid,
1847 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001848 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001849 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001850 *p++ = cpu_to_be32(slot->seq_nr);
1851 *p++ = cpu_to_be32(args->sa_slotid);
1852 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001853 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001854#endif /* CONFIG_NFS_V4_1 */
1855}
1856
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001857#ifdef CONFIG_NFS_V4_1
1858static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001859encode_getdevicelist(struct xdr_stream *xdr,
1860 const struct nfs4_getdevicelist_args *args,
1861 struct compound_hdr *hdr)
1862{
1863 __be32 *p;
1864 nfs4_verifier dummy = {
1865 .data = "dummmmmy",
1866 };
1867
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001868 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1869 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001870 *p++ = cpu_to_be32(args->layoutclass);
1871 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1872 xdr_encode_hyper(p, 0ULL); /* cookie */
1873 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001874}
1875
1876static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001877encode_getdeviceinfo(struct xdr_stream *xdr,
1878 const struct nfs4_getdeviceinfo_args *args,
1879 struct compound_hdr *hdr)
1880{
1881 __be32 *p;
1882
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001883 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1884 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001885 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1886 NFS4_DEVICEID4_SIZE);
1887 *p++ = cpu_to_be32(args->pdev->layout_type);
1888 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1889 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001890}
1891
1892static void
1893encode_layoutget(struct xdr_stream *xdr,
1894 const struct nfs4_layoutget_args *args,
1895 struct compound_hdr *hdr)
1896{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001897 __be32 *p;
1898
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001899 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1900 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001901 *p++ = cpu_to_be32(0); /* Signal layout available */
1902 *p++ = cpu_to_be32(args->type);
1903 *p++ = cpu_to_be32(args->range.iomode);
1904 p = xdr_encode_hyper(p, args->range.offset);
1905 p = xdr_encode_hyper(p, args->range.length);
1906 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001907 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001908 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001909
1910 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1911 __func__,
1912 args->type,
1913 args->range.iomode,
1914 (unsigned long)args->range.offset,
1915 (unsigned long)args->range.length,
1916 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001917}
Andy Adamson863a3c62011-03-23 13:27:54 +00001918
1919static int
1920encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001921 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001922 const struct nfs4_layoutcommit_args *args,
1923 struct compound_hdr *hdr)
1924{
1925 __be32 *p;
1926
1927 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1928 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1929
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001930 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1931 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001932 /* Only whole file layouts */
1933 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001934 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001935 *p = cpu_to_be32(0); /* reclaim */
1936 encode_nfs4_stateid(xdr, &args->stateid);
1937 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001938 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1939 p = xdr_encode_hyper(p, args->lastbytewritten);
1940 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1941 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001942
1943 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1944 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1945 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001946 else
1947 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001948
Andy Adamson863a3c62011-03-23 13:27:54 +00001949 return 0;
1950}
Benny Halevycbe82602011-05-22 19:52:37 +03001951
1952static void
1953encode_layoutreturn(struct xdr_stream *xdr,
1954 const struct nfs4_layoutreturn_args *args,
1955 struct compound_hdr *hdr)
1956{
1957 __be32 *p;
1958
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001959 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1960 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001961 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1962 *p++ = cpu_to_be32(args->layout_type);
1963 *p++ = cpu_to_be32(IOMODE_ANY);
1964 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001965 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001966 p = xdr_encode_hyper(p, 0);
1967 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1968 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001969 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001970 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001971 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1972 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1973 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001974 } else
1975 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001976}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001977
1978static int
1979encode_secinfo_no_name(struct xdr_stream *xdr,
1980 const struct nfs41_secinfo_no_name_args *args,
1981 struct compound_hdr *hdr)
1982{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001983 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1984 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001985 return 0;
1986}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001987
1988static void encode_test_stateid(struct xdr_stream *xdr,
1989 struct nfs41_test_stateid_args *args,
1990 struct compound_hdr *hdr)
1991{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001992 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1993 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001994 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04001995}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001996
1997static void encode_free_stateid(struct xdr_stream *xdr,
1998 struct nfs41_free_stateid_args *args,
1999 struct compound_hdr *hdr)
2000{
Trond Myklebustab19b482012-03-04 18:13:57 -05002001 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002002 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002003}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002004#endif /* CONFIG_NFS_V4_1 */
2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006/*
2007 * END OF "GENERIC" ENCODE ROUTINES.
2008 */
2009
Benny Halevy66cc0422009-04-01 09:22:10 -04002010static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2011{
2012#if defined(CONFIG_NFS_V4_1)
2013 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002014 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002015#endif /* CONFIG_NFS_V4_1 */
2016 return 0;
2017}
2018
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019/*
2020 * Encode an ACCESS request
2021 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002022static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2023 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002026 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
Chuck Lever9f06c712010-12-14 14:59:18 +00002029 encode_compound_hdr(xdr, req, &hdr);
2030 encode_sequence(xdr, &args->seq_args, &hdr);
2031 encode_putfh(xdr, args->fh, &hdr);
2032 encode_access(xdr, args->access, &hdr);
2033 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002034 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035}
2036
2037/*
2038 * Encode LOOKUP request
2039 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002040static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2041 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002044 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
Chuck Lever9f06c712010-12-14 14:59:18 +00002047 encode_compound_hdr(xdr, req, &hdr);
2048 encode_sequence(xdr, &args->seq_args, &hdr);
2049 encode_putfh(xdr, args->dir_fh, &hdr);
2050 encode_lookup(xdr, args->name, &hdr);
2051 encode_getfh(xdr, &hdr);
2052 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002053 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054}
2055
2056/*
2057 * Encode LOOKUP_ROOT request
2058 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002059static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2060 struct xdr_stream *xdr,
2061 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002064 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066
Chuck Lever9f06c712010-12-14 14:59:18 +00002067 encode_compound_hdr(xdr, req, &hdr);
2068 encode_sequence(xdr, &args->seq_args, &hdr);
2069 encode_putrootfh(xdr, &hdr);
2070 encode_getfh(xdr, &hdr);
2071 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002072 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073}
2074
2075/*
2076 * Encode REMOVE request
2077 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002078static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2079 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002082 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
Chuck Lever9f06c712010-12-14 14:59:18 +00002085 encode_compound_hdr(xdr, req, &hdr);
2086 encode_sequence(xdr, &args->seq_args, &hdr);
2087 encode_putfh(xdr, args->fh, &hdr);
2088 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002089 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090}
2091
2092/*
2093 * Encode RENAME request
2094 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002095static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2096 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002099 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Chuck Lever9f06c712010-12-14 14:59:18 +00002102 encode_compound_hdr(xdr, req, &hdr);
2103 encode_sequence(xdr, &args->seq_args, &hdr);
2104 encode_putfh(xdr, args->old_dir, &hdr);
2105 encode_savefh(xdr, &hdr);
2106 encode_putfh(xdr, args->new_dir, &hdr);
2107 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002108 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109}
2110
2111/*
2112 * Encode LINK request
2113 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002114static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2115 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002118 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120
Chuck Lever9f06c712010-12-14 14:59:18 +00002121 encode_compound_hdr(xdr, req, &hdr);
2122 encode_sequence(xdr, &args->seq_args, &hdr);
2123 encode_putfh(xdr, args->fh, &hdr);
2124 encode_savefh(xdr, &hdr);
2125 encode_putfh(xdr, args->dir_fh, &hdr);
2126 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002127 encode_restorefh(xdr, &hdr);
2128 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002129 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130}
2131
2132/*
2133 * Encode CREATE request
2134 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002135static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2136 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002139 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
Chuck Lever9f06c712010-12-14 14:59:18 +00002142 encode_compound_hdr(xdr, req, &hdr);
2143 encode_sequence(xdr, &args->seq_args, &hdr);
2144 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002145 encode_create(xdr, args, &hdr);
2146 encode_getfh(xdr, &hdr);
2147 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002148 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149}
2150
2151/*
2152 * Encode SYMLINK request
2153 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002154static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2155 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156{
Chuck Lever9f06c712010-12-14 14:59:18 +00002157 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158}
2159
2160/*
2161 * Encode GETATTR request
2162 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002163static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2164 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002167 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
Chuck Lever9f06c712010-12-14 14:59:18 +00002170 encode_compound_hdr(xdr, req, &hdr);
2171 encode_sequence(xdr, &args->seq_args, &hdr);
2172 encode_putfh(xdr, args->fh, &hdr);
2173 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002174 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175}
2176
2177/*
2178 * Encode a CLOSE request
2179 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002180static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2181 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182{
Andy Adamson05d564f2008-12-23 16:06:15 -05002183 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002184 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002185 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
Chuck Lever9f06c712010-12-14 14:59:18 +00002187 encode_compound_hdr(xdr, req, &hdr);
2188 encode_sequence(xdr, &args->seq_args, &hdr);
2189 encode_putfh(xdr, args->fh, &hdr);
2190 encode_close(xdr, args, &hdr);
2191 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002192 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193}
2194
2195/*
2196 * Encode an OPEN request
2197 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002198static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2199 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002202 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
Chuck Lever9f06c712010-12-14 14:59:18 +00002205 encode_compound_hdr(xdr, req, &hdr);
2206 encode_sequence(xdr, &args->seq_args, &hdr);
2207 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002208 encode_open(xdr, args, &hdr);
2209 encode_getfh(xdr, &hdr);
Andy Adamson88034c32012-05-23 05:02:34 -04002210 encode_getfattr_open(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002211 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212}
2213
2214/*
2215 * Encode an OPEN_CONFIRM request
2216 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002217static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2218 struct xdr_stream *xdr,
2219 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002222 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
Chuck Lever9f06c712010-12-14 14:59:18 +00002225 encode_compound_hdr(xdr, req, &hdr);
2226 encode_putfh(xdr, args->fh, &hdr);
2227 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002228 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229}
2230
2231/*
2232 * Encode an OPEN request with no attributes.
2233 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002234static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2235 struct xdr_stream *xdr,
2236 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002239 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
Chuck Lever9f06c712010-12-14 14:59:18 +00002242 encode_compound_hdr(xdr, req, &hdr);
2243 encode_sequence(xdr, &args->seq_args, &hdr);
2244 encode_putfh(xdr, args->fh, &hdr);
2245 encode_open(xdr, args, &hdr);
2246 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002247 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248}
2249
2250/*
2251 * Encode an OPEN_DOWNGRADE request
2252 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002253static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2254 struct xdr_stream *xdr,
2255 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002258 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
Chuck Lever9f06c712010-12-14 14:59:18 +00002261 encode_compound_hdr(xdr, req, &hdr);
2262 encode_sequence(xdr, &args->seq_args, &hdr);
2263 encode_putfh(xdr, args->fh, &hdr);
2264 encode_open_downgrade(xdr, args, &hdr);
2265 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002266 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267}
2268
2269/*
2270 * Encode a LOCK request
2271 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002272static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2273 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002276 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278
Chuck Lever9f06c712010-12-14 14:59:18 +00002279 encode_compound_hdr(xdr, req, &hdr);
2280 encode_sequence(xdr, &args->seq_args, &hdr);
2281 encode_putfh(xdr, args->fh, &hdr);
2282 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002283 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284}
2285
2286/*
2287 * Encode a LOCKT request
2288 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002289static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2290 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002293 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
Chuck Lever9f06c712010-12-14 14:59:18 +00002296 encode_compound_hdr(xdr, req, &hdr);
2297 encode_sequence(xdr, &args->seq_args, &hdr);
2298 encode_putfh(xdr, args->fh, &hdr);
2299 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002300 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301}
2302
2303/*
2304 * Encode a LOCKU request
2305 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002306static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2307 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002310 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
Chuck Lever9f06c712010-12-14 14:59:18 +00002313 encode_compound_hdr(xdr, req, &hdr);
2314 encode_sequence(xdr, &args->seq_args, &hdr);
2315 encode_putfh(xdr, args->fh, &hdr);
2316 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002317 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318}
2319
Chuck Lever9f06c712010-12-14 14:59:18 +00002320static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2321 struct xdr_stream *xdr,
2322 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002323{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002324 struct compound_hdr hdr = {
2325 .minorversion = 0,
2326 };
2327
Chuck Lever9f06c712010-12-14 14:59:18 +00002328 encode_compound_hdr(xdr, req, &hdr);
2329 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002330 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002331}
2332
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333/*
2334 * Encode a READLINK request
2335 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002336static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2337 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002340 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
Chuck Lever9f06c712010-12-14 14:59:18 +00002343 encode_compound_hdr(xdr, req, &hdr);
2344 encode_sequence(xdr, &args->seq_args, &hdr);
2345 encode_putfh(xdr, args->fh, &hdr);
2346 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002347
Benny Halevy28f56692009-04-01 09:22:09 -04002348 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002349 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002350 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351}
2352
2353/*
2354 * Encode a READDIR request
2355 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002356static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2357 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002360 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Chuck Lever9f06c712010-12-14 14:59:18 +00002363 encode_compound_hdr(xdr, req, &hdr);
2364 encode_sequence(xdr, &args->seq_args, &hdr);
2365 encode_putfh(xdr, args->fh, &hdr);
2366 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002367
Benny Halevy28f56692009-04-01 09:22:09 -04002368 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002369 args->pgbase, args->count);
2370 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002371 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002372 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002373 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374}
2375
2376/*
2377 * Encode a READ request
2378 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002379static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2380 struct nfs_readargs *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_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
Benny Halevy28f56692009-04-01 09:22:09 -04002391 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002393 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002394 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395}
2396
2397/*
2398 * Encode an SETATTR request
2399 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002400static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2401 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402{
Andy Adamson05d564f2008-12-23 16:06:15 -05002403 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002404 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002405 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
Chuck Lever9f06c712010-12-14 14:59:18 +00002407 encode_compound_hdr(xdr, req, &hdr);
2408 encode_sequence(xdr, &args->seq_args, &hdr);
2409 encode_putfh(xdr, args->fh, &hdr);
2410 encode_setattr(xdr, args, args->server, &hdr);
2411 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002412 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413}
2414
2415/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002416 * Encode a GETACL request
2417 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002418static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2419 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002420{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002421 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002422 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002423 };
Benny Halevy28f56692009-04-01 09:22:09 -04002424 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002425
Chuck Lever9f06c712010-12-14 14:59:18 +00002426 encode_compound_hdr(xdr, req, &hdr);
2427 encode_sequence(xdr, &args->seq_args, &hdr);
2428 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002429 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002430 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002431
Benny Halevy28f56692009-04-01 09:22:09 -04002432 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002433 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002434
Andy Adamsond0179312008-12-23 16:06:17 -05002435 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002436}
2437
2438/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 * Encode a WRITE request
2440 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002441static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2442 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002445 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447
Chuck Lever9f06c712010-12-14 14:59:18 +00002448 encode_compound_hdr(xdr, req, &hdr);
2449 encode_sequence(xdr, &args->seq_args, &hdr);
2450 encode_putfh(xdr, args->fh, &hdr);
2451 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002452 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002453 if (args->bitmask)
2454 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002455 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456}
2457
2458/*
2459 * a COMMIT request
2460 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002461static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002462 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002465 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467
Chuck Lever9f06c712010-12-14 14:59:18 +00002468 encode_compound_hdr(xdr, req, &hdr);
2469 encode_sequence(xdr, &args->seq_args, &hdr);
2470 encode_putfh(xdr, args->fh, &hdr);
2471 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002472 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473}
2474
2475/*
2476 * FSINFO request
2477 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002478static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2479 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002482 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484
Chuck Lever9f06c712010-12-14 14:59:18 +00002485 encode_compound_hdr(xdr, req, &hdr);
2486 encode_sequence(xdr, &args->seq_args, &hdr);
2487 encode_putfh(xdr, args->fh, &hdr);
2488 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002489 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490}
2491
2492/*
2493 * a PATHCONF request
2494 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002495static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2496 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002499 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
Chuck Lever9f06c712010-12-14 14:59:18 +00002502 encode_compound_hdr(xdr, req, &hdr);
2503 encode_sequence(xdr, &args->seq_args, &hdr);
2504 encode_putfh(xdr, args->fh, &hdr);
2505 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002506 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002507 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508}
2509
2510/*
2511 * a STATFS request
2512 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002513static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2514 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002517 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519
Chuck Lever9f06c712010-12-14 14:59:18 +00002520 encode_compound_hdr(xdr, req, &hdr);
2521 encode_sequence(xdr, &args->seq_args, &hdr);
2522 encode_putfh(xdr, args->fh, &hdr);
2523 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002524 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002525 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526}
2527
2528/*
2529 * GETATTR_BITMAP request
2530 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002531static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2532 struct xdr_stream *xdr,
2533 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002536 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538
Chuck Lever9f06c712010-12-14 14:59:18 +00002539 encode_compound_hdr(xdr, req, &hdr);
2540 encode_sequence(xdr, &args->seq_args, &hdr);
2541 encode_putfh(xdr, args->fhandle, &hdr);
2542 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002543 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002544 FATTR4_WORD0_LINK_SUPPORT|
2545 FATTR4_WORD0_SYMLINK_SUPPORT|
2546 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002547 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548}
2549
2550/*
2551 * a RENEW request
2552 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002553static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2554 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002557 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 };
2559
Chuck Lever9f06c712010-12-14 14:59:18 +00002560 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002561 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002562 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563}
2564
2565/*
2566 * a SETCLIENTID request
2567 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002568static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2569 struct xdr_stream *xdr,
2570 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002573 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 };
2575
Chuck Lever9f06c712010-12-14 14:59:18 +00002576 encode_compound_hdr(xdr, req, &hdr);
2577 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002578 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579}
2580
2581/*
2582 * a SETCLIENTID_CONFIRM request
2583 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002584static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2585 struct xdr_stream *xdr,
2586 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002589 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 };
Fred Isamandae100c2011-07-30 20:52:37 -04002591 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592
Chuck Lever9f06c712010-12-14 14:59:18 +00002593 encode_compound_hdr(xdr, req, &hdr);
2594 encode_setclientid_confirm(xdr, arg, &hdr);
2595 encode_putrootfh(xdr, &hdr);
2596 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002597 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598}
2599
2600/*
2601 * DELEGRETURN request
2602 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002603static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2604 struct xdr_stream *xdr,
2605 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002608 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610
Chuck Lever9f06c712010-12-14 14:59:18 +00002611 encode_compound_hdr(xdr, req, &hdr);
2612 encode_sequence(xdr, &args->seq_args, &hdr);
2613 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002614 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002615 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002616 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617}
2618
2619/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002620 * Encode FS_LOCATIONS request
2621 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002622static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2623 struct xdr_stream *xdr,
2624 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002625{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002626 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002627 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002628 };
Benny Halevy28f56692009-04-01 09:22:09 -04002629 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002630
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->dir_fh, &hdr);
2634 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002635 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002636 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002637
Benny Halevy28f56692009-04-01 09:22:09 -04002638 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002639 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002640 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002641}
2642
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002643/*
2644 * Encode SECINFO request
2645 */
2646static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2647 struct xdr_stream *xdr,
2648 struct nfs4_secinfo_arg *args)
2649{
2650 struct compound_hdr hdr = {
2651 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2652 };
2653
2654 encode_compound_hdr(xdr, req, &hdr);
2655 encode_sequence(xdr, &args->seq_args, &hdr);
2656 encode_putfh(xdr, args->dir_fh, &hdr);
2657 encode_secinfo(xdr, args->name, &hdr);
2658 encode_nops(&hdr);
2659}
2660
Benny Halevy99fe60d2009-04-01 09:22:29 -04002661#if defined(CONFIG_NFS_V4_1)
2662/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002663 * BIND_CONN_TO_SESSION request
2664 */
2665static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2666 struct xdr_stream *xdr,
2667 struct nfs_client *clp)
2668{
2669 struct compound_hdr hdr = {
2670 .minorversion = clp->cl_mvops->minor_version,
2671 };
2672
2673 encode_compound_hdr(xdr, req, &hdr);
2674 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2675 encode_nops(&hdr);
2676}
2677
2678/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002679 * EXCHANGE_ID request
2680 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002681static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2682 struct xdr_stream *xdr,
2683 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002684{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002685 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002686 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002687 };
2688
Chuck Lever9f06c712010-12-14 14:59:18 +00002689 encode_compound_hdr(xdr, req, &hdr);
2690 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002691 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002692}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002693
2694/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002695 * a CREATE_SESSION request
2696 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002697static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2698 struct xdr_stream *xdr,
2699 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002700{
Andy Adamsonfc931582009-04-01 09:22:31 -04002701 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002702 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002703 };
2704
Chuck Lever9f06c712010-12-14 14:59:18 +00002705 encode_compound_hdr(xdr, req, &hdr);
2706 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002707 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002708}
2709
2710/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002711 * a DESTROY_SESSION request
2712 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002713static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2714 struct xdr_stream *xdr,
2715 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002716{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002717 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002718 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002719 };
2720
Chuck Lever9f06c712010-12-14 14:59:18 +00002721 encode_compound_hdr(xdr, req, &hdr);
2722 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002723 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002724}
2725
2726/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002727 * a SEQUENCE request
2728 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002729static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2730 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002731{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002732 struct compound_hdr hdr = {
2733 .minorversion = nfs4_xdr_minorversion(args),
2734 };
2735
Chuck Lever9f06c712010-12-14 14:59:18 +00002736 encode_compound_hdr(xdr, req, &hdr);
2737 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002738 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002739}
2740
2741/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002742 * a GET_LEASE_TIME request
2743 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002744static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2745 struct xdr_stream *xdr,
2746 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002747{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002748 struct compound_hdr hdr = {
2749 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2750 };
Fred Isamandae100c2011-07-30 20:52:37 -04002751 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002752
Chuck Lever9f06c712010-12-14 14:59:18 +00002753 encode_compound_hdr(xdr, req, &hdr);
2754 encode_sequence(xdr, &args->la_seq_args, &hdr);
2755 encode_putrootfh(xdr, &hdr);
2756 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002757 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002758}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002759
2760/*
2761 * a RECLAIM_COMPLETE request
2762 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002763static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2764 struct xdr_stream *xdr,
2765 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002766{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002767 struct compound_hdr hdr = {
2768 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2769 };
2770
Chuck Lever9f06c712010-12-14 14:59:18 +00002771 encode_compound_hdr(xdr, req, &hdr);
2772 encode_sequence(xdr, &args->seq_args, &hdr);
2773 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002774 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002775}
2776
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002777/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002778 * Encode GETDEVICELIST request
2779 */
2780static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2781 struct xdr_stream *xdr,
2782 struct nfs4_getdevicelist_args *args)
2783{
2784 struct compound_hdr hdr = {
2785 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2786 };
2787
2788 encode_compound_hdr(xdr, req, &hdr);
2789 encode_sequence(xdr, &args->seq_args, &hdr);
2790 encode_putfh(xdr, args->fh, &hdr);
2791 encode_getdevicelist(xdr, args, &hdr);
2792 encode_nops(&hdr);
2793}
2794
2795/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002796 * Encode GETDEVICEINFO request
2797 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002798static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2799 struct xdr_stream *xdr,
2800 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002801{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002802 struct compound_hdr hdr = {
2803 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2804 };
2805
Chuck Lever9f06c712010-12-14 14:59:18 +00002806 encode_compound_hdr(xdr, req, &hdr);
2807 encode_sequence(xdr, &args->seq_args, &hdr);
2808 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002809
2810 /* set up reply kvec. Subtract notification bitmap max size (2)
2811 * so that notification bitmap is put in xdr_buf tail */
2812 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2813 args->pdev->pages, args->pdev->pgbase,
2814 args->pdev->pglen);
2815
2816 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002817}
2818
2819/*
2820 * Encode LAYOUTGET request
2821 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002822static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2823 struct xdr_stream *xdr,
2824 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002825{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002826 struct compound_hdr hdr = {
2827 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2828 };
2829
Chuck Lever9f06c712010-12-14 14:59:18 +00002830 encode_compound_hdr(xdr, req, &hdr);
2831 encode_sequence(xdr, &args->seq_args, &hdr);
2832 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2833 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002834
2835 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2836 args->layout.pages, 0, args->layout.pglen);
2837
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002838 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002839}
Andy Adamson863a3c62011-03-23 13:27:54 +00002840
2841/*
2842 * Encode LAYOUTCOMMIT request
2843 */
Benny Halevycbe82602011-05-22 19:52:37 +03002844static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2845 struct xdr_stream *xdr,
2846 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002847{
Benny Halevyac7db722011-05-22 19:53:48 +03002848 struct nfs4_layoutcommit_data *data =
2849 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002850 struct compound_hdr hdr = {
2851 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2852 };
2853
2854 encode_compound_hdr(xdr, req, &hdr);
2855 encode_sequence(xdr, &args->seq_args, &hdr);
2856 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002857 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002858 encode_getfattr(xdr, args->bitmask, &hdr);
2859 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002860}
2861
2862/*
2863 * Encode LAYOUTRETURN request
2864 */
2865static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2866 struct xdr_stream *xdr,
2867 struct nfs4_layoutreturn_args *args)
2868{
2869 struct compound_hdr hdr = {
2870 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2871 };
2872
2873 encode_compound_hdr(xdr, req, &hdr);
2874 encode_sequence(xdr, &args->seq_args, &hdr);
2875 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2876 encode_layoutreturn(xdr, args, &hdr);
2877 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002878}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002879
2880/*
2881 * Encode SECINFO_NO_NAME request
2882 */
2883static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2884 struct xdr_stream *xdr,
2885 struct nfs41_secinfo_no_name_args *args)
2886{
2887 struct compound_hdr hdr = {
2888 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2889 };
2890
2891 encode_compound_hdr(xdr, req, &hdr);
2892 encode_sequence(xdr, &args->seq_args, &hdr);
2893 encode_putrootfh(xdr, &hdr);
2894 encode_secinfo_no_name(xdr, args, &hdr);
2895 encode_nops(&hdr);
2896 return 0;
2897}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002898
2899/*
2900 * Encode TEST_STATEID request
2901 */
2902static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2903 struct xdr_stream *xdr,
2904 struct nfs41_test_stateid_args *args)
2905{
2906 struct compound_hdr hdr = {
2907 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2908 };
2909
2910 encode_compound_hdr(xdr, req, &hdr);
2911 encode_sequence(xdr, &args->seq_args, &hdr);
2912 encode_test_stateid(xdr, args, &hdr);
2913 encode_nops(&hdr);
2914}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002915
2916/*
2917 * Encode FREE_STATEID request
2918 */
2919static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2920 struct xdr_stream *xdr,
2921 struct nfs41_free_stateid_args *args)
2922{
2923 struct compound_hdr hdr = {
2924 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2925 };
2926
2927 encode_compound_hdr(xdr, req, &hdr);
2928 encode_sequence(xdr, &args->seq_args, &hdr);
2929 encode_free_stateid(xdr, args, &hdr);
2930 encode_nops(&hdr);
2931}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002932#endif /* CONFIG_NFS_V4_1 */
2933
Benny Halevy686841b2009-08-14 17:19:48 +03002934static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2935{
2936 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2937 "Remaining buffer length is %tu words.\n",
2938 func, xdr->end - xdr->p);
2939}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940
Trond Myklebust683b57b2006-06-09 09:34:22 -04002941static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942{
Al Viro8687b632006-10-19 23:28:48 -07002943 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944
Benny Halevyc0eae662009-08-14 17:20:14 +03002945 p = xdr_inline_decode(xdr, 4);
2946 if (unlikely(!p))
2947 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002948 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002949 p = xdr_inline_decode(xdr, *len);
2950 if (unlikely(!p))
2951 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 *string = (char *)p;
2953 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002954out_overflow:
2955 print_overflow_msg(__func__, xdr);
2956 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957}
2958
2959static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2960{
Al Viro8687b632006-10-19 23:28:48 -07002961 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962
Benny Halevyc0eae662009-08-14 17:20:14 +03002963 p = xdr_inline_decode(xdr, 8);
2964 if (unlikely(!p))
2965 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002966 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002967 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002968
Benny Halevyc0eae662009-08-14 17:20:14 +03002969 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2970 if (unlikely(!p))
2971 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 hdr->tag = (char *)p;
2973 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002974 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002975 if (unlikely(hdr->nops < 1))
2976 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002978out_overflow:
2979 print_overflow_msg(__func__, xdr);
2980 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981}
2982
2983static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2984{
Al Viro8687b632006-10-19 23:28:48 -07002985 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 uint32_t opnum;
2987 int32_t nfserr;
2988
Benny Halevyc0eae662009-08-14 17:20:14 +03002989 p = xdr_inline_decode(xdr, 8);
2990 if (unlikely(!p))
2991 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002992 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002994 dprintk("nfs: Server returned operation"
2995 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 opnum, expected);
2997 return -EIO;
2998 }
Benny Halevycccddf42009-08-14 17:20:19 +03002999 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003001 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003003out_overflow:
3004 print_overflow_msg(__func__, xdr);
3005 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006}
3007
3008/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003009static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010{
Al Viro8687b632006-10-19 23:28:48 -07003011 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003012 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 char *str;
3014
Benny Halevyc0eae662009-08-14 17:20:14 +03003015 p = xdr_inline_decode(xdr, 12);
3016 if (likely(p))
3017 return decode_opaque_inline(xdr, &strlen, &str);
3018 print_overflow_msg(__func__, xdr);
3019 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020}
3021
3022static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3023{
Al Viro8687b632006-10-19 23:28:48 -07003024 uint32_t bmlen;
3025 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026
Benny Halevyc0eae662009-08-14 17:20:14 +03003027 p = xdr_inline_decode(xdr, 4);
3028 if (unlikely(!p))
3029 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003030 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031
Fred Isamandae100c2011-07-30 20:52:37 -04003032 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003033 p = xdr_inline_decode(xdr, (bmlen << 2));
3034 if (unlikely(!p))
3035 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003037 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003038 if (bmlen > 1) {
3039 bitmap[1] = be32_to_cpup(p++);
3040 if (bmlen > 2)
3041 bitmap[2] = be32_to_cpup(p);
3042 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 }
3044 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003045out_overflow:
3046 print_overflow_msg(__func__, xdr);
3047 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048}
3049
Al Viro8687b632006-10-19 23:28:48 -07003050static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051{
Al Viro8687b632006-10-19 23:28:48 -07003052 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053
Benny Halevyc0eae662009-08-14 17:20:14 +03003054 p = xdr_inline_decode(xdr, 4);
3055 if (unlikely(!p))
3056 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003057 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 *savep = xdr->p;
3059 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003060out_overflow:
3061 print_overflow_msg(__func__, xdr);
3062 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063}
3064
3065static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3066{
3067 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003068 int ret;
3069 ret = decode_attr_bitmap(xdr, bitmask);
3070 if (unlikely(ret < 0))
3071 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3073 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003074 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3075 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3076 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 return 0;
3078}
3079
3080static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3081{
Al Viro8687b632006-10-19 23:28:48 -07003082 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003083 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084
3085 *type = 0;
3086 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3087 return -EIO;
3088 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003089 p = xdr_inline_decode(xdr, 4);
3090 if (unlikely(!p))
3091 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003092 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003094 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 return -EIO;
3096 }
3097 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003098 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003100 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003101 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003102out_overflow:
3103 print_overflow_msg(__func__, xdr);
3104 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105}
3106
Chuck Lever264e6352012-03-01 17:02:05 -05003107static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3108 uint32_t *bitmap, uint32_t *type)
3109{
3110 __be32 *p;
3111
3112 *type = 0;
3113 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3114 return -EIO;
3115 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3116 p = xdr_inline_decode(xdr, 4);
3117 if (unlikely(!p))
3118 goto out_overflow;
3119 *type = be32_to_cpup(p);
3120 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3121 }
3122 dprintk("%s: expire type=0x%x\n", __func__, *type);
3123 return 0;
3124out_overflow:
3125 print_overflow_msg(__func__, xdr);
3126 return -EIO;
3127}
3128
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3130{
Al Viro8687b632006-10-19 23:28:48 -07003131 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003132 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133
3134 *change = 0;
3135 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3136 return -EIO;
3137 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003138 p = xdr_inline_decode(xdr, 8);
3139 if (unlikely(!p))
3140 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003141 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003143 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003145 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003147 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003148out_overflow:
3149 print_overflow_msg(__func__, xdr);
3150 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151}
3152
3153static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3154{
Al Viro8687b632006-10-19 23:28:48 -07003155 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003156 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157
3158 *size = 0;
3159 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3160 return -EIO;
3161 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003162 p = xdr_inline_decode(xdr, 8);
3163 if (unlikely(!p))
3164 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003165 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003167 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003169 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003170 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003171out_overflow:
3172 print_overflow_msg(__func__, xdr);
3173 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174}
3175
3176static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3177{
Al Viro8687b632006-10-19 23:28:48 -07003178 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179
3180 *res = 0;
3181 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3182 return -EIO;
3183 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
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 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3189 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003190 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003192out_overflow:
3193 print_overflow_msg(__func__, xdr);
3194 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195}
3196
3197static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3198{
Al Viro8687b632006-10-19 23:28:48 -07003199 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200
3201 *res = 0;
3202 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3203 return -EIO;
3204 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003205 p = xdr_inline_decode(xdr, 4);
3206 if (unlikely(!p))
3207 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003208 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3210 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003211 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003213out_overflow:
3214 print_overflow_msg(__func__, xdr);
3215 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216}
3217
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003218static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219{
Al Viro8687b632006-10-19 23:28:48 -07003220 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003221 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222
3223 fsid->major = 0;
3224 fsid->minor = 0;
3225 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3226 return -EIO;
3227 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003228 p = xdr_inline_decode(xdr, 16);
3229 if (unlikely(!p))
3230 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003231 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003232 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003234 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003236 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 (unsigned long long)fsid->major,
3238 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003239 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003240out_overflow:
3241 print_overflow_msg(__func__, xdr);
3242 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243}
3244
3245static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3246{
Al Viro8687b632006-10-19 23:28:48 -07003247 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248
3249 *res = 60;
3250 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3251 return -EIO;
3252 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003253 p = xdr_inline_decode(xdr, 4);
3254 if (unlikely(!p))
3255 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003256 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3258 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003259 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003261out_overflow:
3262 print_overflow_msg(__func__, xdr);
3263 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264}
3265
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003266static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003267{
3268 __be32 *p;
3269
3270 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3271 return -EIO;
3272 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3273 p = xdr_inline_decode(xdr, 4);
3274 if (unlikely(!p))
3275 goto out_overflow;
3276 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003277 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003278 }
3279 return 0;
3280out_overflow:
3281 print_overflow_msg(__func__, xdr);
3282 return -EIO;
3283}
3284
3285static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3286{
3287 __be32 *p;
3288 int len;
3289
Trond Myklebust7ad07352010-10-23 15:34:20 -04003290 if (fh != NULL)
3291 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003292
3293 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3294 return -EIO;
3295 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3296 p = xdr_inline_decode(xdr, 4);
3297 if (unlikely(!p))
3298 goto out_overflow;
3299 len = be32_to_cpup(p);
3300 if (len > NFS4_FHSIZE)
3301 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003302 p = xdr_inline_decode(xdr, len);
3303 if (unlikely(!p))
3304 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003305 if (fh != NULL) {
3306 memcpy(fh->data, p, len);
3307 fh->size = len;
3308 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003309 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3310 }
3311 return 0;
3312out_overflow:
3313 print_overflow_msg(__func__, xdr);
3314 return -EIO;
3315}
3316
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3318{
Al Viro8687b632006-10-19 23:28:48 -07003319 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320
3321 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3322 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3323 return -EIO;
3324 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003325 p = xdr_inline_decode(xdr, 4);
3326 if (unlikely(!p))
3327 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003328 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3330 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003331 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003333out_overflow:
3334 print_overflow_msg(__func__, xdr);
3335 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336}
3337
3338static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3339{
Al Viro8687b632006-10-19 23:28:48 -07003340 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003341 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342
3343 *fileid = 0;
3344 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3345 return -EIO;
3346 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003347 p = xdr_inline_decode(xdr, 8);
3348 if (unlikely(!p))
3349 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003350 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003352 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003354 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003355 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003356out_overflow:
3357 print_overflow_msg(__func__, xdr);
3358 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359}
3360
Manoj Naik99baf622006-06-09 09:34:24 -04003361static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3362{
Al Viro8687b632006-10-19 23:28:48 -07003363 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003364 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003365
3366 *fileid = 0;
3367 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3368 return -EIO;
3369 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003370 p = xdr_inline_decode(xdr, 8);
3371 if (unlikely(!p))
3372 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003373 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003374 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003375 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003376 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003377 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003378 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003379out_overflow:
3380 print_overflow_msg(__func__, xdr);
3381 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003382}
3383
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3385{
Al Viro8687b632006-10-19 23:28:48 -07003386 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 int status = 0;
3388
3389 *res = 0;
3390 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3391 return -EIO;
3392 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003393 p = xdr_inline_decode(xdr, 8);
3394 if (unlikely(!p))
3395 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003396 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3398 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003399 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003401out_overflow:
3402 print_overflow_msg(__func__, xdr);
3403 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404}
3405
3406static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3407{
Al Viro8687b632006-10-19 23:28:48 -07003408 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 int status = 0;
3410
3411 *res = 0;
3412 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3413 return -EIO;
3414 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003415 p = xdr_inline_decode(xdr, 8);
3416 if (unlikely(!p))
3417 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003418 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3420 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003421 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003423out_overflow:
3424 print_overflow_msg(__func__, xdr);
3425 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426}
3427
3428static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3429{
Al Viro8687b632006-10-19 23:28:48 -07003430 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 int status = 0;
3432
3433 *res = 0;
3434 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3435 return -EIO;
3436 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003437 p = xdr_inline_decode(xdr, 8);
3438 if (unlikely(!p))
3439 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003440 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3442 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003443 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003445out_overflow:
3446 print_overflow_msg(__func__, xdr);
3447 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448}
3449
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003450static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3451{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003452 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003453 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003454 int status = 0;
3455
Benny Halevyc0eae662009-08-14 17:20:14 +03003456 p = xdr_inline_decode(xdr, 4);
3457 if (unlikely(!p))
3458 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003459 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003460 if (n == 0)
3461 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003462 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003463 path->ncomponents = 0;
3464 while (path->ncomponents < n) {
3465 struct nfs4_string *component = &path->components[path->ncomponents];
3466 status = decode_opaque_inline(xdr, &component->len, &component->data);
3467 if (unlikely(status != 0))
3468 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003469 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003470 pr_cont("%s%.*s ",
3471 (path->ncomponents != n ? "/ " : ""),
3472 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003473 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3474 path->ncomponents++;
3475 else {
3476 dprintk("cannot parse %d components in path\n", n);
3477 goto out_eio;
3478 }
3479 }
3480out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003481 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003482root_path:
3483/* a root pathname is sent as a zero component4 */
3484 path->ncomponents = 1;
3485 path->components[0].len=0;
3486 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003487 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003488 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003489out_eio:
3490 dprintk(" status %d", status);
3491 status = -EIO;
3492 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003493out_overflow:
3494 print_overflow_msg(__func__, xdr);
3495 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003496}
3497
3498static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003499{
3500 int n;
Al Viro8687b632006-10-19 23:28:48 -07003501 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003502 int status = -EIO;
3503
3504 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3505 goto out;
3506 status = 0;
3507 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3508 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003509 status = -EIO;
3510 /* Ignore borken servers that return unrequested attrs */
3511 if (unlikely(res == NULL))
3512 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003513 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003514 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003515 if (unlikely(status != 0))
3516 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003517 p = xdr_inline_decode(xdr, 4);
3518 if (unlikely(!p))
3519 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003520 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003521 if (n <= 0)
3522 goto out_eio;
3523 res->nlocations = 0;
3524 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003525 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003526 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003527
Benny Halevyc0eae662009-08-14 17:20:14 +03003528 p = xdr_inline_decode(xdr, 4);
3529 if (unlikely(!p))
3530 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003531 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003532
3533 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003534 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003535 while (loc->nservers < m) {
3536 struct nfs4_string *server = &loc->servers[loc->nservers];
3537 status = decode_opaque_inline(xdr, &server->len, &server->data);
3538 if (unlikely(status != 0))
3539 goto out_eio;
3540 dprintk("%s ", server->data);
3541 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3542 loc->nservers++;
3543 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003544 unsigned int i;
3545 dprintk("%s: using first %u of %u servers "
3546 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003547 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003548 NFS4_FS_LOCATION_MAXSERVERS,
3549 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003550 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003551 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003552 char *data;
3553 status = decode_opaque_inline(xdr, &len, &data);
3554 if (unlikely(status != 0))
3555 goto out_eio;
3556 }
3557 }
3558 }
3559 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003560 if (unlikely(status != 0))
3561 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003562 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003563 res->nlocations++;
3564 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003565 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003566 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003567out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003568 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003569 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003570out_overflow:
3571 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003572out_eio:
3573 status = -EIO;
3574 goto out;
3575}
3576
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3578{
Al Viro8687b632006-10-19 23:28:48 -07003579 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580 int status = 0;
3581
3582 *res = 0;
3583 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3584 return -EIO;
3585 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003586 p = xdr_inline_decode(xdr, 8);
3587 if (unlikely(!p))
3588 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003589 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3591 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003592 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003594out_overflow:
3595 print_overflow_msg(__func__, xdr);
3596 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597}
3598
3599static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3600{
Al Viro8687b632006-10-19 23:28:48 -07003601 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602 int status = 0;
3603
3604 *maxlink = 1;
3605 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3606 return -EIO;
3607 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003608 p = xdr_inline_decode(xdr, 4);
3609 if (unlikely(!p))
3610 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003611 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3613 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003614 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003616out_overflow:
3617 print_overflow_msg(__func__, xdr);
3618 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619}
3620
3621static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3622{
Al Viro8687b632006-10-19 23:28:48 -07003623 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 int status = 0;
3625
3626 *maxname = 1024;
3627 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3628 return -EIO;
3629 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003630 p = xdr_inline_decode(xdr, 4);
3631 if (unlikely(!p))
3632 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003633 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3635 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003636 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003638out_overflow:
3639 print_overflow_msg(__func__, xdr);
3640 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641}
3642
3643static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3644{
Al Viro8687b632006-10-19 23:28:48 -07003645 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 int status = 0;
3647
3648 *res = 1024;
3649 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3650 return -EIO;
3651 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3652 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003653 p = xdr_inline_decode(xdr, 8);
3654 if (unlikely(!p))
3655 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003656 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 if (maxread > 0x7FFFFFFF)
3658 maxread = 0x7FFFFFFF;
3659 *res = (uint32_t)maxread;
3660 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3661 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003662 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003664out_overflow:
3665 print_overflow_msg(__func__, xdr);
3666 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667}
3668
3669static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3670{
Al Viro8687b632006-10-19 23:28:48 -07003671 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 int status = 0;
3673
3674 *res = 1024;
3675 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3676 return -EIO;
3677 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3678 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003679 p = xdr_inline_decode(xdr, 8);
3680 if (unlikely(!p))
3681 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003682 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 if (maxwrite > 0x7FFFFFFF)
3684 maxwrite = 0x7FFFFFFF;
3685 *res = (uint32_t)maxwrite;
3686 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3687 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003688 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003690out_overflow:
3691 print_overflow_msg(__func__, xdr);
3692 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693}
3694
Trond Myklebustbca79472009-03-11 14:10:26 -04003695static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696{
Trond Myklebustbca79472009-03-11 14:10:26 -04003697 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003698 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003699 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700
3701 *mode = 0;
3702 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3703 return -EIO;
3704 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003705 p = xdr_inline_decode(xdr, 4);
3706 if (unlikely(!p))
3707 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003708 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003709 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003711 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003713 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003714 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003715out_overflow:
3716 print_overflow_msg(__func__, xdr);
3717 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718}
3719
3720static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3721{
Al Viro8687b632006-10-19 23:28:48 -07003722 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003723 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724
3725 *nlink = 1;
3726 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3727 return -EIO;
3728 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003729 p = xdr_inline_decode(xdr, 4);
3730 if (unlikely(!p))
3731 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003732 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003734 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003736 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003737 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003738out_overflow:
3739 print_overflow_msg(__func__, xdr);
3740 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741}
3742
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003743static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003744 const struct nfs_server *server, uint32_t *uid,
3745 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746{
Al Viro8687b632006-10-19 23:28:48 -07003747 uint32_t len;
3748 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003749 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750
3751 *uid = -2;
3752 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3753 return -EIO;
3754 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003755 p = xdr_inline_decode(xdr, 4);
3756 if (unlikely(!p))
3757 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003758 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003759 p = xdr_inline_decode(xdr, len);
3760 if (unlikely(!p))
3761 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003762 if (owner_name != NULL) {
3763 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3764 if (owner_name->data != NULL) {
3765 owner_name->len = len;
3766 ret = NFS_ATTR_FATTR_OWNER_NAME;
3767 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003768 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003769 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003770 ret = NFS_ATTR_FATTR_OWNER;
3771 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003773 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003775 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003776 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3778 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003779 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003780 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003781out_overflow:
3782 print_overflow_msg(__func__, xdr);
3783 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784}
3785
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003786static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003787 const struct nfs_server *server, uint32_t *gid,
3788 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789{
Al Viro8687b632006-10-19 23:28:48 -07003790 uint32_t len;
3791 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003792 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793
3794 *gid = -2;
3795 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3796 return -EIO;
3797 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003798 p = xdr_inline_decode(xdr, 4);
3799 if (unlikely(!p))
3800 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003801 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003802 p = xdr_inline_decode(xdr, len);
3803 if (unlikely(!p))
3804 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003805 if (group_name != NULL) {
3806 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3807 if (group_name->data != NULL) {
3808 group_name->len = len;
3809 ret = NFS_ATTR_FATTR_GROUP_NAME;
3810 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003811 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003812 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003813 ret = NFS_ATTR_FATTR_GROUP;
3814 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003816 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003818 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003819 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3821 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003822 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003823 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003824out_overflow:
3825 print_overflow_msg(__func__, xdr);
3826 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827}
3828
3829static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3830{
Al Viro8687b632006-10-19 23:28:48 -07003831 uint32_t major = 0, minor = 0;
3832 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003833 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834
3835 *rdev = MKDEV(0,0);
3836 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3837 return -EIO;
3838 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3839 dev_t tmp;
3840
Benny Halevyc0eae662009-08-14 17:20:14 +03003841 p = xdr_inline_decode(xdr, 8);
3842 if (unlikely(!p))
3843 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003844 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003845 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846 tmp = MKDEV(major, minor);
3847 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3848 *rdev = tmp;
3849 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003850 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003852 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003853 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003854out_overflow:
3855 print_overflow_msg(__func__, xdr);
3856 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857}
3858
3859static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3860{
Al Viro8687b632006-10-19 23:28:48 -07003861 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 int status = 0;
3863
3864 *res = 0;
3865 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3866 return -EIO;
3867 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003868 p = xdr_inline_decode(xdr, 8);
3869 if (unlikely(!p))
3870 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003871 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3873 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003874 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003876out_overflow:
3877 print_overflow_msg(__func__, xdr);
3878 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879}
3880
3881static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3882{
Al Viro8687b632006-10-19 23:28:48 -07003883 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 int status = 0;
3885
3886 *res = 0;
3887 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3888 return -EIO;
3889 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003890 p = xdr_inline_decode(xdr, 8);
3891 if (unlikely(!p))
3892 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003893 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3895 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003896 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003898out_overflow:
3899 print_overflow_msg(__func__, xdr);
3900 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901}
3902
3903static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3904{
Al Viro8687b632006-10-19 23:28:48 -07003905 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 int status = 0;
3907
3908 *res = 0;
3909 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3910 return -EIO;
3911 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003912 p = xdr_inline_decode(xdr, 8);
3913 if (unlikely(!p))
3914 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003915 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3917 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003918 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003920out_overflow:
3921 print_overflow_msg(__func__, xdr);
3922 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923}
3924
3925static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3926{
Al Viro8687b632006-10-19 23:28:48 -07003927 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003928 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929
3930 *used = 0;
3931 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3932 return -EIO;
3933 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003934 p = xdr_inline_decode(xdr, 8);
3935 if (unlikely(!p))
3936 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003937 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003939 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003941 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003943 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003944out_overflow:
3945 print_overflow_msg(__func__, xdr);
3946 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947}
3948
3949static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3950{
Al Viro8687b632006-10-19 23:28:48 -07003951 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 uint64_t sec;
3953 uint32_t nsec;
3954
Benny Halevyc0eae662009-08-14 17:20:14 +03003955 p = xdr_inline_decode(xdr, 12);
3956 if (unlikely(!p))
3957 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003958 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003959 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960 time->tv_sec = (time_t)sec;
3961 time->tv_nsec = (long)nsec;
3962 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003963out_overflow:
3964 print_overflow_msg(__func__, xdr);
3965 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966}
3967
3968static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3969{
3970 int status = 0;
3971
3972 time->tv_sec = 0;
3973 time->tv_nsec = 0;
3974 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3975 return -EIO;
3976 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3977 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003978 if (status == 0)
3979 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3981 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003982 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 return status;
3984}
3985
3986static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3987{
3988 int status = 0;
3989
3990 time->tv_sec = 0;
3991 time->tv_nsec = 0;
3992 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3993 return -EIO;
3994 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3995 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003996 if (status == 0)
3997 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3999 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004000 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 return status;
4002}
4003
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004004static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4005 struct timespec *time)
4006{
4007 int status = 0;
4008
4009 time->tv_sec = 0;
4010 time->tv_nsec = 0;
4011 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4012 return -EIO;
4013 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4014 status = decode_attr_time(xdr, time);
4015 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4016 }
4017 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4018 (long)time->tv_nsec);
4019 return status;
4020}
4021
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4023{
4024 int status = 0;
4025
4026 time->tv_sec = 0;
4027 time->tv_nsec = 0;
4028 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4029 return -EIO;
4030 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4031 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004032 if (status == 0)
4033 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4035 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004036 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 return status;
4038}
4039
Al Viro8687b632006-10-19 23:28:48 -07004040static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041{
4042 unsigned int attrwords = XDR_QUADLEN(attrlen);
4043 unsigned int nwords = xdr->p - savep;
4044
4045 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004046 dprintk("%s: server returned incorrect attribute length: "
4047 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004048 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 attrwords << 2,
4050 (attrwords < nwords) ? '<' : '>',
4051 nwords << 2);
4052 return -EIO;
4053 }
4054 return 0;
4055}
4056
4057static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4058{
Al Viro8687b632006-10-19 23:28:48 -07004059 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060
Benny Halevyc0eae662009-08-14 17:20:14 +03004061 p = xdr_inline_decode(xdr, 20);
4062 if (unlikely(!p))
4063 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004064 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004065 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004066 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004068out_overflow:
4069 print_overflow_msg(__func__, xdr);
4070 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071}
4072
4073static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4074{
Al Viro8687b632006-10-19 23:28:48 -07004075 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 uint32_t supp, acc;
4077 int status;
4078
4079 status = decode_op_hdr(xdr, OP_ACCESS);
4080 if (status)
4081 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004082 p = xdr_inline_decode(xdr, 8);
4083 if (unlikely(!p))
4084 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004085 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004086 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 access->supported = supp;
4088 access->access = acc;
4089 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004090out_overflow:
4091 print_overflow_msg(__func__, xdr);
4092 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093}
4094
Benny Halevy07d30432009-08-14 17:19:52 +03004095static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096{
Al Viro8687b632006-10-19 23:28:48 -07004097 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004098
4099 p = xdr_inline_decode(xdr, len);
4100 if (likely(p)) {
4101 memcpy(buf, p, len);
4102 return 0;
4103 }
4104 print_overflow_msg(__func__, xdr);
4105 return -EIO;
4106}
4107
4108static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4109{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004110 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111}
4112
4113static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4114{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115 int status;
4116
4117 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004118 if (status != -EIO)
4119 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004120 if (!status)
4121 status = decode_stateid(xdr, &res->stateid);
4122 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123}
4124
Benny Halevydb942bb2009-08-14 17:19:56 +03004125static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4126{
Chuck Levercd937102012-03-02 17:14:31 -05004127 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128}
4129
Fred Isaman0b7c0152012-04-20 14:47:39 -04004130static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 int status;
4133
4134 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004135 if (!status)
4136 status = decode_verifier(xdr, res->verf->verifier);
4137 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138}
4139
4140static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4141{
Al Viro8687b632006-10-19 23:28:48 -07004142 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 uint32_t bmlen;
4144 int status;
4145
4146 status = decode_op_hdr(xdr, OP_CREATE);
4147 if (status)
4148 return status;
4149 if ((status = decode_change_info(xdr, cinfo)))
4150 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004151 p = xdr_inline_decode(xdr, 4);
4152 if (unlikely(!p))
4153 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004154 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004155 p = xdr_inline_decode(xdr, bmlen << 2);
4156 if (likely(p))
4157 return 0;
4158out_overflow:
4159 print_overflow_msg(__func__, xdr);
4160 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161}
4162
4163static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4164{
Al Viro8687b632006-10-19 23:28:48 -07004165 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004166 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 int status;
4168
4169 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4170 goto xdr_error;
4171 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4172 goto xdr_error;
4173 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4174 goto xdr_error;
4175 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4176 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004177 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4178 &res->fh_expire_type)) != 0)
4179 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4181 goto xdr_error;
4182 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4183 goto xdr_error;
4184 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4185 goto xdr_error;
4186 status = verify_attr_len(xdr, savep, attrlen);
4187xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004188 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189 return status;
4190}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004191
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4193{
Al Viro8687b632006-10-19 23:28:48 -07004194 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004195 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004197
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4199 goto xdr_error;
4200 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4201 goto xdr_error;
4202 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4203 goto xdr_error;
4204
4205 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4206 goto xdr_error;
4207 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4208 goto xdr_error;
4209 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4210 goto xdr_error;
4211 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4212 goto xdr_error;
4213 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4214 goto xdr_error;
4215 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4216 goto xdr_error;
4217
4218 status = verify_attr_len(xdr, savep, attrlen);
4219xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004220 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221 return status;
4222}
4223
4224static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4225{
Al Viro8687b632006-10-19 23:28:48 -07004226 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004227 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004229
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4231 goto xdr_error;
4232 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4233 goto xdr_error;
4234 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4235 goto xdr_error;
4236
4237 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4238 goto xdr_error;
4239 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4240 goto xdr_error;
4241
4242 status = verify_attr_len(xdr, savep, attrlen);
4243xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004244 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 return status;
4246}
4247
Andy Adamson88034c32012-05-23 05:02:34 -04004248static int decode_threshold_hint(struct xdr_stream *xdr,
4249 uint32_t *bitmap,
4250 uint64_t *res,
4251 uint32_t hint_bit)
4252{
4253 __be32 *p;
4254
4255 *res = 0;
4256 if (likely(bitmap[0] & hint_bit)) {
4257 p = xdr_inline_decode(xdr, 8);
4258 if (unlikely(!p))
4259 goto out_overflow;
4260 xdr_decode_hyper(p, res);
4261 }
4262 return 0;
4263out_overflow:
4264 print_overflow_msg(__func__, xdr);
4265 return -EIO;
4266}
4267
4268static int decode_first_threshold_item4(struct xdr_stream *xdr,
4269 struct nfs4_threshold *res)
4270{
4271 __be32 *p, *savep;
4272 uint32_t bitmap[3] = {0,}, attrlen;
4273 int status;
4274
4275 /* layout type */
4276 p = xdr_inline_decode(xdr, 4);
4277 if (unlikely(!p)) {
4278 print_overflow_msg(__func__, xdr);
4279 return -EIO;
4280 }
4281 res->l_type = be32_to_cpup(p);
4282
4283 /* thi_hintset bitmap */
4284 status = decode_attr_bitmap(xdr, bitmap);
4285 if (status < 0)
4286 goto xdr_error;
4287
4288 /* thi_hintlist length */
4289 status = decode_attr_length(xdr, &attrlen, &savep);
4290 if (status < 0)
4291 goto xdr_error;
4292 /* thi_hintlist */
4293 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4294 if (status < 0)
4295 goto xdr_error;
4296 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4297 if (status < 0)
4298 goto xdr_error;
4299 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4300 THRESHOLD_RD_IO);
4301 if (status < 0)
4302 goto xdr_error;
4303 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4304 THRESHOLD_WR_IO);
4305 if (status < 0)
4306 goto xdr_error;
4307
4308 status = verify_attr_len(xdr, savep, attrlen);
4309 res->bm = bitmap[0];
4310
4311 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4312 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4313 res->wr_io_sz);
4314xdr_error:
4315 dprintk("%s ret=%d!\n", __func__, status);
4316 return status;
4317}
4318
4319/*
4320 * Thresholds on pNFS direct I/O vrs MDS I/O
4321 */
4322static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4323 uint32_t *bitmap,
4324 struct nfs4_threshold *res)
4325{
4326 __be32 *p;
4327 int status = 0;
4328 uint32_t num;
4329
4330 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4331 return -EIO;
4332 if (likely(bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD)) {
4333 p = xdr_inline_decode(xdr, 4);
4334 if (unlikely(!p))
4335 goto out_overflow;
4336 num = be32_to_cpup(p);
4337 if (num == 0)
4338 return 0;
4339 if (num > 1)
4340 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4341 "drivers per filesystem not supported\n",
4342 __func__);
4343
4344 status = decode_first_threshold_item4(xdr, res);
4345 }
4346 return status;
4347out_overflow:
4348 print_overflow_msg(__func__, xdr);
4349 return -EIO;
4350}
4351
Bryan Schumakerae42c702010-10-21 16:33:17 -04004352static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4353 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004354 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004355 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356{
Trond Myklebustbca79472009-03-11 14:10:26 -04004357 int status;
4358 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004359 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004360 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004362 status = decode_attr_type(xdr, bitmap, &type);
4363 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004365 fattr->mode = 0;
4366 if (status != 0) {
4367 fattr->mode |= nfs_type2fmt[type];
4368 fattr->valid |= status;
4369 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004371 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4372 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004374 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004375
4376 status = decode_attr_size(xdr, bitmap, &fattr->size);
4377 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004378 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004379 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004380
4381 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4382 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004384 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004385
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004386 err = 0;
4387 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004388 if (status < 0)
4389 goto xdr_error;
4390
4391 status = decode_attr_filehandle(xdr, bitmap, fh);
4392 if (status < 0)
4393 goto xdr_error;
4394
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004395 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4396 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004398 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004399
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004400 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004401 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004402 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004403 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004404
4405 status = decode_attr_mode(xdr, bitmap, &fmode);
4406 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004408 if (status != 0) {
4409 fattr->mode |= fmode;
4410 fattr->valid |= status;
4411 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004412
4413 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4414 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004416 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004417
Trond Myklebust6926afd2012-01-07 13:22:46 -05004418 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004419 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004421 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004422
Trond Myklebust6926afd2012-01-07 13:22:46 -05004423 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004424 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
4428 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4429 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 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_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4434 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004436 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004437
4438 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4439 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004441 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004442
4443 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4444 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004446 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004447
4448 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4449 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004451 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004452
Trond Myklebust28331a42011-04-27 13:47:52 -04004453 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004454 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004455 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004456 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004457
Andy Adamson88034c32012-05-23 05:02:34 -04004458 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4459 if (status < 0)
4460 goto xdr_error;
4461
Bryan Schumakerae42c702010-10-21 16:33:17 -04004462xdr_error:
4463 dprintk("%s: xdr returned %d\n", __func__, -status);
4464 return status;
4465}
4466
4467static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004468 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4469 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004470{
4471 __be32 *savep;
4472 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004473 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004474 int status;
4475
4476 status = decode_op_hdr(xdr, OP_GETATTR);
4477 if (status < 0)
4478 goto xdr_error;
4479
4480 status = decode_attr_bitmap(xdr, bitmap);
4481 if (status < 0)
4482 goto xdr_error;
4483
4484 status = decode_attr_length(xdr, &attrlen, &savep);
4485 if (status < 0)
4486 goto xdr_error;
4487
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004488 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004489 if (status < 0)
4490 goto xdr_error;
4491
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004492 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004494 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 return status;
4496}
4497
Bryan Schumakerae42c702010-10-21 16:33:17 -04004498static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004499 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004500{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004501 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004502}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503
Andy Adamson504913f2010-10-20 00:17:57 -04004504/*
4505 * Decode potentially multiple layout types. Currently we only support
4506 * one layout driver per file system.
4507 */
4508static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4509 uint32_t *layouttype)
4510{
4511 uint32_t *p;
4512 int num;
4513
4514 p = xdr_inline_decode(xdr, 4);
4515 if (unlikely(!p))
4516 goto out_overflow;
4517 num = be32_to_cpup(p);
4518
4519 /* pNFS is not supported by the underlying file system */
4520 if (num == 0) {
4521 *layouttype = 0;
4522 return 0;
4523 }
4524 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004525 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4526 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004527
4528 /* Decode and set first layout type, move xdr->p past unused types */
4529 p = xdr_inline_decode(xdr, num * 4);
4530 if (unlikely(!p))
4531 goto out_overflow;
4532 *layouttype = be32_to_cpup(p);
4533 return 0;
4534out_overflow:
4535 print_overflow_msg(__func__, xdr);
4536 return -EIO;
4537}
4538
4539/*
4540 * The type of file system exported.
4541 * Note we must ensure that layouttype is set in any non-error case.
4542 */
4543static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4544 uint32_t *layouttype)
4545{
4546 int status = 0;
4547
4548 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4549 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4550 return -EIO;
4551 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4552 status = decode_first_pnfs_layout_type(xdr, layouttype);
4553 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4554 } else
4555 *layouttype = 0;
4556 return status;
4557}
4558
Fred Isamandae100c2011-07-30 20:52:37 -04004559/*
4560 * The prefered block size for layout directed io
4561 */
4562static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4563 uint32_t *res)
4564{
4565 __be32 *p;
4566
4567 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4568 *res = 0;
4569 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4570 p = xdr_inline_decode(xdr, 4);
4571 if (unlikely(!p)) {
4572 print_overflow_msg(__func__, xdr);
4573 return -EIO;
4574 }
4575 *res = be32_to_cpup(p);
4576 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4577 }
4578 return 0;
4579}
4580
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4582{
Al Viro8687b632006-10-19 23:28:48 -07004583 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004584 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 int status;
4586
4587 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4588 goto xdr_error;
4589 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4590 goto xdr_error;
4591 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4592 goto xdr_error;
4593
4594 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4595
4596 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4597 goto xdr_error;
4598 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4599 goto xdr_error;
4600 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4601 goto xdr_error;
4602 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4603 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4604 goto xdr_error;
4605 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004606 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4607 if (status != 0)
4608 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004609 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4610 if (status != 0)
4611 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004612 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4613 if (status)
4614 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004615
4616 status = verify_attr_len(xdr, savep, attrlen);
4617xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004618 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619 return status;
4620}
4621
4622static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4623{
Al Viro8687b632006-10-19 23:28:48 -07004624 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625 uint32_t len;
4626 int status;
4627
Trond Myklebust99367812007-07-17 21:52:41 -04004628 /* Zero handle first to allow comparisons */
4629 memset(fh, 0, sizeof(*fh));
4630
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 status = decode_op_hdr(xdr, OP_GETFH);
4632 if (status)
4633 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634
Benny Halevyc0eae662009-08-14 17:20:14 +03004635 p = xdr_inline_decode(xdr, 4);
4636 if (unlikely(!p))
4637 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004638 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 if (len > NFS4_FHSIZE)
4640 return -EIO;
4641 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004642 p = xdr_inline_decode(xdr, len);
4643 if (unlikely(!p))
4644 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004645 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004647out_overflow:
4648 print_overflow_msg(__func__, xdr);
4649 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650}
4651
4652static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4653{
4654 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004655
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656 status = decode_op_hdr(xdr, OP_LINK);
4657 if (status)
4658 return status;
4659 return decode_change_info(xdr, cinfo);
4660}
4661
4662/*
4663 * We create the owner, so we know a proper owner.id length is 4.
4664 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004665static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004667 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004668 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004669 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004671 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004672 if (unlikely(!p))
4673 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004674 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004675 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004676 type = be32_to_cpup(p++); /* 4 byte read */
4677 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004678 fl->fl_start = (loff_t)offset;
4679 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4680 if (length == ~(uint64_t)0)
4681 fl->fl_end = OFFSET_MAX;
4682 fl->fl_type = F_WRLCK;
4683 if (type & 1)
4684 fl->fl_type = F_RDLCK;
4685 fl->fl_pid = 0;
4686 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004687 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4688 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4689 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004690 if (likely(p))
4691 return -NFS4ERR_DENIED;
4692out_overflow:
4693 print_overflow_msg(__func__, xdr);
4694 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695}
4696
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004697static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004699 int status;
4700
4701 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004702 if (status == -EIO)
4703 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004705 status = decode_stateid(xdr, &res->stateid);
4706 if (unlikely(status))
4707 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004709 status = decode_lock_denied(xdr, NULL);
4710 if (res->open_seqid != NULL)
4711 nfs_increment_open_seqid(status, res->open_seqid);
4712 nfs_increment_lock_seqid(status, res->lock_seqid);
4713out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714 return status;
4715}
4716
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004717static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718{
4719 int status;
4720 status = decode_op_hdr(xdr, OP_LOCKT);
4721 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004722 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 return status;
4724}
4725
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004726static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728 int status;
4729
4730 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004731 if (status != -EIO)
4732 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004733 if (status == 0)
4734 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 return status;
4736}
4737
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004738static int decode_release_lockowner(struct xdr_stream *xdr)
4739{
4740 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4741}
4742
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743static int decode_lookup(struct xdr_stream *xdr)
4744{
4745 return decode_op_hdr(xdr, OP_LOOKUP);
4746}
4747
4748/* This is too sick! */
4749static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4750{
Andy Adamson05d564f2008-12-23 16:06:15 -05004751 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752 uint32_t limit_type, nblocks, blocksize;
4753
Benny Halevyc0eae662009-08-14 17:20:14 +03004754 p = xdr_inline_decode(xdr, 12);
4755 if (unlikely(!p))
4756 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004757 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004758 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004759 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004760 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004761 break;
4762 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004763 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004764 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004765 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 }
4767 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004768out_overflow:
4769 print_overflow_msg(__func__, xdr);
4770 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771}
4772
4773static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4774{
Andy Adamson05d564f2008-12-23 16:06:15 -05004775 __be32 *p;
4776 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004777 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778
Benny Halevyc0eae662009-08-14 17:20:14 +03004779 p = xdr_inline_decode(xdr, 4);
4780 if (unlikely(!p))
4781 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004782 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4784 res->delegation_type = 0;
4785 return 0;
4786 }
Benny Halevy07d30432009-08-14 17:19:52 +03004787 status = decode_stateid(xdr, &res->delegation);
4788 if (unlikely(status))
4789 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004790 p = xdr_inline_decode(xdr, 4);
4791 if (unlikely(!p))
4792 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004793 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004794
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004796 case NFS4_OPEN_DELEGATE_READ:
4797 res->delegation_type = FMODE_READ;
4798 break;
4799 case NFS4_OPEN_DELEGATE_WRITE:
4800 res->delegation_type = FMODE_WRITE|FMODE_READ;
4801 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802 return -EIO;
4803 }
David Howells7539bba2006-08-22 20:06:09 -04004804 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004805out_overflow:
4806 print_overflow_msg(__func__, xdr);
4807 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808}
4809
4810static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4811{
Andy Adamson05d564f2008-12-23 16:06:15 -05004812 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004813 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004814 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815
Andy Adamson05d564f2008-12-23 16:06:15 -05004816 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004817 if (status != -EIO)
4818 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004819 if (!status)
4820 status = decode_stateid(xdr, &res->stateid);
4821 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004822 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004823
Andy Adamson05d564f2008-12-23 16:06:15 -05004824 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825
Benny Halevyc0eae662009-08-14 17:20:14 +03004826 p = xdr_inline_decode(xdr, 8);
4827 if (unlikely(!p))
4828 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004829 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004830 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004831 if (bmlen > 10)
4832 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833
Benny Halevyc0eae662009-08-14 17:20:14 +03004834 p = xdr_inline_decode(xdr, bmlen << 2);
4835 if (unlikely(!p))
4836 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004837 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4838 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004839 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004840 for (; i < NFS4_BITMAP_SIZE; i++)
4841 res->attrset[i] = 0;
4842
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843 return decode_delegation(xdr, res);
4844xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004845 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004847out_overflow:
4848 print_overflow_msg(__func__, xdr);
4849 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850}
4851
4852static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4853{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854 int status;
4855
Andy Adamson05d564f2008-12-23 16:06:15 -05004856 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004857 if (status != -EIO)
4858 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004859 if (!status)
4860 status = decode_stateid(xdr, &res->stateid);
4861 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862}
4863
4864static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4865{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866 int status;
4867
4868 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004869 if (status != -EIO)
4870 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004871 if (!status)
4872 status = decode_stateid(xdr, &res->stateid);
4873 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874}
4875
4876static int decode_putfh(struct xdr_stream *xdr)
4877{
4878 return decode_op_hdr(xdr, OP_PUTFH);
4879}
4880
4881static int decode_putrootfh(struct xdr_stream *xdr)
4882{
4883 return decode_op_hdr(xdr, OP_PUTROOTFH);
4884}
4885
4886static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4887{
4888 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004889 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 uint32_t count, eof, recvd, hdrlen;
4891 int status;
4892
4893 status = decode_op_hdr(xdr, OP_READ);
4894 if (status)
4895 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004896 p = xdr_inline_decode(xdr, 8);
4897 if (unlikely(!p))
4898 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004899 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004900 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004901 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902 recvd = req->rq_rcv_buf.len - hdrlen;
4903 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004904 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 "count %u > recvd %u\n", count, recvd);
4906 count = recvd;
4907 eof = 0;
4908 }
4909 xdr_read_pages(xdr, count);
4910 res->eof = eof;
4911 res->count = count;
4912 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004913out_overflow:
4914 print_overflow_msg(__func__, xdr);
4915 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916}
4917
4918static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4919{
4920 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004922 size_t hdrlen;
4923 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004924 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004925 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926
4927 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004928 if (!status)
4929 status = decode_verifier(xdr, readdir->verifier.data);
4930 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004931 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004932 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004933 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004934 __func__, verf[0], verf[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935
Benny Halevydb942bb2009-08-14 17:19:56 +03004936 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937 recvd = rcvbuf->len - hdrlen;
4938 if (pglen > recvd)
4939 pglen = recvd;
4940 xdr_read_pages(xdr, pglen);
4941
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004942
Trond Myklebustac396122010-11-15 20:26:22 -05004943 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944}
4945
4946static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4947{
4948 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4949 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004950 size_t hdrlen;
4951 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004952 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953 int status;
4954
4955 status = decode_op_hdr(xdr, OP_READLINK);
4956 if (status)
4957 return status;
4958
4959 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004960 p = xdr_inline_decode(xdr, 4);
4961 if (unlikely(!p))
4962 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004963 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004965 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966 return -ENAMETOOLONG;
4967 }
4968 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4969 recvd = req->rq_rcv_buf.len - hdrlen;
4970 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004971 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972 "count %u > recvd %u\n", len, recvd);
4973 return -EIO;
4974 }
4975 xdr_read_pages(xdr, len);
4976 /*
4977 * The XDR encode routine has set things up so that
4978 * the link text will be copied directly into the
4979 * buffer. We just have to do overflow-checking,
4980 * and and null-terminate the text (the VFS expects
4981 * null-termination).
4982 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004983 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004985out_overflow:
4986 print_overflow_msg(__func__, xdr);
4987 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988}
4989
4990static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4991{
4992 int status;
4993
4994 status = decode_op_hdr(xdr, OP_REMOVE);
4995 if (status)
4996 goto out;
4997 status = decode_change_info(xdr, cinfo);
4998out:
4999 return status;
5000}
5001
5002static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5003 struct nfs4_change_info *new_cinfo)
5004{
5005 int status;
5006
5007 status = decode_op_hdr(xdr, OP_RENAME);
5008 if (status)
5009 goto out;
5010 if ((status = decode_change_info(xdr, old_cinfo)))
5011 goto out;
5012 status = decode_change_info(xdr, new_cinfo);
5013out:
5014 return status;
5015}
5016
5017static int decode_renew(struct xdr_stream *xdr)
5018{
5019 return decode_op_hdr(xdr, OP_RENEW);
5020}
5021
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005022static int
5023decode_restorefh(struct xdr_stream *xdr)
5024{
5025 return decode_op_hdr(xdr, OP_RESTOREFH);
5026}
5027
J. Bruce Fields029d1052005-06-22 17:16:22 +00005028static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005029 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005030{
Andy Adamsonbf118a32011-12-07 11:55:27 -05005031 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005032 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005033 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005034 struct kvec *iov = req->rq_rcv_buf.head;
5035 int status;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005036 size_t page_len = xdr->buf->page_len;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005037
Andy Adamsonbf118a32011-12-07 11:55:27 -05005038 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005039 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5040 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005041
Andy Adamsonbf118a32011-12-07 11:55:27 -05005042 bm_p = xdr->p;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005043 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
5044 res->acl_data_offset <<= 2;
5045 /* Check if the acl data starts beyond the allocated buffer */
5046 if (res->acl_data_offset > page_len)
5047 return -ERANGE;
5048
J. Bruce Fields029d1052005-06-22 17:16:22 +00005049 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5050 goto out;
5051 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5052 goto out;
5053
5054 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5055 return -EIO;
5056 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04005057 size_t hdrlen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005058
Andy Adamsonbf118a32011-12-07 11:55:27 -05005059 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5060 * are stored with the acl data to handle the problem of
5061 * variable length bitmaps.*/
5062 xdr->p = bm_p;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005063
J. Bruce Fields029d1052005-06-22 17:16:22 +00005064 /* We ignore &savep and don't do consistency checks on
5065 * the attr length. Let userspace figure it out.... */
5066 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005067 attrlen += res->acl_data_offset;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005068 if (attrlen > page_len) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05005069 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
5070 /* getxattr interface called with a NULL buf */
5071 res->acl_len = attrlen;
5072 goto out;
5073 }
Sachin Prabhu5794d212012-04-17 14:36:40 +01005074 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
Sachin Prabhu5a006892012-04-17 14:35:39 +01005075 attrlen, page_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005076 return -EINVAL;
5077 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04005078 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05005079 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005080 } else
5081 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005082
5083out:
5084 return status;
5085}
5086
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087static int
5088decode_savefh(struct xdr_stream *xdr)
5089{
5090 return decode_op_hdr(xdr, OP_SAVEFH);
5091}
5092
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005093static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094{
Al Viro8687b632006-10-19 23:28:48 -07005095 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096 uint32_t bmlen;
5097 int status;
5098
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099 status = decode_op_hdr(xdr, OP_SETATTR);
5100 if (status)
5101 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005102 p = xdr_inline_decode(xdr, 4);
5103 if (unlikely(!p))
5104 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005105 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005106 p = xdr_inline_decode(xdr, bmlen << 2);
5107 if (likely(p))
5108 return 0;
5109out_overflow:
5110 print_overflow_msg(__func__, xdr);
5111 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112}
5113
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005114static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
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 opnum;
5118 int32_t nfserr;
5119
Benny Halevyc0eae662009-08-14 17:20:14 +03005120 p = xdr_inline_decode(xdr, 8);
5121 if (unlikely(!p))
5122 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005123 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005125 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005126 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127 return -EIO;
5128 }
Benny Halevycccddf42009-08-14 17:20:19 +03005129 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005131 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5132 if (unlikely(!p))
5133 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005134 p = xdr_decode_hyper(p, &res->clientid);
5135 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 } else if (nfserr == NFSERR_CLID_INUSE) {
5137 uint32_t len;
5138
5139 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005140 p = xdr_inline_decode(xdr, 4);
5141 if (unlikely(!p))
5142 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005143 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005144 p = xdr_inline_decode(xdr, len);
5145 if (unlikely(!p))
5146 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147
5148 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005149 p = xdr_inline_decode(xdr, 4);
5150 if (unlikely(!p))
5151 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005152 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005153 p = xdr_inline_decode(xdr, len);
5154 if (unlikely(!p))
5155 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156 return -NFSERR_CLID_INUSE;
5157 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005158 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159
5160 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005161out_overflow:
5162 print_overflow_msg(__func__, xdr);
5163 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164}
5165
5166static int decode_setclientid_confirm(struct xdr_stream *xdr)
5167{
5168 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5169}
5170
5171static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5172{
Al Viro8687b632006-10-19 23:28:48 -07005173 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174 int status;
5175
5176 status = decode_op_hdr(xdr, OP_WRITE);
5177 if (status)
5178 return status;
5179
Benny Halevyc0eae662009-08-14 17:20:14 +03005180 p = xdr_inline_decode(xdr, 16);
5181 if (unlikely(!p))
5182 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005183 res->count = be32_to_cpup(p++);
5184 res->verf->committed = be32_to_cpup(p++);
Chuck Levercd937102012-03-02 17:14:31 -05005185 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005187out_overflow:
5188 print_overflow_msg(__func__, xdr);
5189 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190}
5191
5192static int decode_delegreturn(struct xdr_stream *xdr)
5193{
5194 return decode_op_hdr(xdr, OP_DELEGRETURN);
5195}
5196
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005197static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5198{
5199 __be32 *p;
5200
5201 p = xdr_inline_decode(xdr, 4);
5202 if (unlikely(!p))
5203 goto out_overflow;
5204 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5205 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5206 goto out_err;
5207
5208 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5209 if (unlikely(!p))
5210 goto out_overflow;
5211 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5212
5213 p = xdr_inline_decode(xdr, 8);
5214 if (unlikely(!p))
5215 goto out_overflow;
5216 flavor->gss.qop4 = be32_to_cpup(p++);
5217 flavor->gss.service = be32_to_cpup(p);
5218
5219 return 0;
5220
5221out_overflow:
5222 print_overflow_msg(__func__, xdr);
5223 return -EIO;
5224out_err:
5225 return -EINVAL;
5226}
5227
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005228static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005229{
5230 struct nfs4_secinfo_flavor *sec_flavor;
5231 int status;
5232 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005233 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005234
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005235 p = xdr_inline_decode(xdr, 4);
5236 if (unlikely(!p))
5237 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005238
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005239 res->flavors->num_flavors = 0;
5240 num_flavors = be32_to_cpup(p);
5241
5242 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005243 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005244 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005245 break;
5246
5247 p = xdr_inline_decode(xdr, 4);
5248 if (unlikely(!p))
5249 goto out_overflow;
5250 sec_flavor->flavor = be32_to_cpup(p);
5251
5252 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005253 status = decode_secinfo_gss(xdr, sec_flavor);
5254 if (status)
5255 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005256 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005257 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005258 }
5259
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005260 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005261out:
5262 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005263out_overflow:
5264 print_overflow_msg(__func__, xdr);
5265 return -EIO;
5266}
5267
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005268static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5269{
5270 int status = decode_op_hdr(xdr, OP_SECINFO);
5271 if (status)
5272 return status;
5273 return decode_secinfo_common(xdr, res);
5274}
5275
Benny Halevy99fe60d2009-04-01 09:22:29 -04005276#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005277static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5278{
5279 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5280 if (status)
5281 return status;
5282 return decode_secinfo_common(xdr, res);
5283}
5284
Benny Halevy99fe60d2009-04-01 09:22:29 -04005285static int decode_exchange_id(struct xdr_stream *xdr,
5286 struct nfs41_exchange_id_res *res)
5287{
5288 __be32 *p;
5289 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005290 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005291 int status;
5292 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005293 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005294
5295 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5296 if (status)
5297 return status;
5298
Benny Halevyc0eae662009-08-14 17:20:14 +03005299 p = xdr_inline_decode(xdr, 8);
5300 if (unlikely(!p))
5301 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005302 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005303 p = xdr_inline_decode(xdr, 12);
5304 if (unlikely(!p))
5305 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005306 clp->cl_seqid = be32_to_cpup(p++);
5307 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005308
5309 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005310 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005311 if (dummy != SP4_NONE)
5312 return -EIO;
5313
Chuck Leveracdeb692012-05-21 22:46:16 -04005314 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005315 p = xdr_inline_decode(xdr, 8);
5316 if (unlikely(!p))
5317 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005318 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005319
Chuck Leveracdeb692012-05-21 22:46:16 -04005320 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005321 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5322 if (unlikely(status))
5323 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005324 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5325 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005326 memcpy(res->server_owner->major_id, dummy_str, dummy);
5327 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005328
Chuck Leveracdeb692012-05-21 22:46:16 -04005329 /* server_scope4 */
5330 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5331 if (unlikely(status))
5332 return status;
5333 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5334 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005335 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5336 res->server_scope->server_scope_sz = dummy;
5337
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005338 /* Implementation Id */
5339 p = xdr_inline_decode(xdr, 4);
5340 if (unlikely(!p))
5341 goto out_overflow;
5342 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005343
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005344 if (impl_id_count) {
5345 /* nii_domain */
5346 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5347 if (unlikely(status))
5348 return status;
5349 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5350 return -EIO;
5351 memcpy(res->impl_id->domain, dummy_str, dummy);
5352
5353 /* nii_name */
5354 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5355 if (unlikely(status))
5356 return status;
5357 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5358 return -EIO;
5359 memcpy(res->impl_id->name, dummy_str, dummy);
5360
5361 /* nii_date */
5362 p = xdr_inline_decode(xdr, 12);
5363 if (unlikely(!p))
5364 goto out_overflow;
5365 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5366 res->impl_id->date.nseconds = be32_to_cpup(p);
5367
5368 /* if there's more than one entry, ignore the rest */
5369 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005370 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005371out_overflow:
5372 print_overflow_msg(__func__, xdr);
5373 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005374}
Andy Adamsonfc931582009-04-01 09:22:31 -04005375
5376static int decode_chan_attrs(struct xdr_stream *xdr,
5377 struct nfs4_channel_attrs *attrs)
5378{
5379 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005380 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005381
Benny Halevyc0eae662009-08-14 17:20:14 +03005382 p = xdr_inline_decode(xdr, 28);
5383 if (unlikely(!p))
5384 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005385 val = be32_to_cpup(p++); /* headerpadsz */
5386 if (val)
5387 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005388 attrs->max_rqst_sz = be32_to_cpup(p++);
5389 attrs->max_resp_sz = be32_to_cpup(p++);
5390 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5391 attrs->max_ops = be32_to_cpup(p++);
5392 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005393 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005394 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005395 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5396 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005397 return -EINVAL;
5398 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005399 if (nr_attrs == 1) {
5400 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5401 if (unlikely(!p))
5402 goto out_overflow;
5403 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005404 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005405out_overflow:
5406 print_overflow_msg(__func__, xdr);
5407 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005408}
5409
Benny Halevye78291e2009-08-14 17:20:00 +03005410static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5411{
5412 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005413}
5414
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005415static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5416 struct nfs41_bind_conn_to_session_res *res)
5417{
5418 __be32 *p;
5419 int status;
5420
5421 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5422 if (!status)
5423 status = decode_sessionid(xdr, &res->session->sess_id);
5424 if (unlikely(status))
5425 return status;
5426
5427 /* dir flags, rdma mode bool */
5428 p = xdr_inline_decode(xdr, 8);
5429 if (unlikely(!p))
5430 goto out_overflow;
5431
5432 res->dir = be32_to_cpup(p++);
5433 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5434 return -EIO;
5435 if (be32_to_cpup(p) == 0)
5436 res->use_conn_in_rdma_mode = false;
5437 else
5438 res->use_conn_in_rdma_mode = true;
5439
5440 return 0;
5441out_overflow:
5442 print_overflow_msg(__func__, xdr);
5443 return -EIO;
5444}
5445
Andy Adamsonfc931582009-04-01 09:22:31 -04005446static int decode_create_session(struct xdr_stream *xdr,
5447 struct nfs41_create_session_res *res)
5448{
5449 __be32 *p;
5450 int status;
5451 struct nfs_client *clp = res->client;
5452 struct nfs4_session *session = clp->cl_session;
5453
5454 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005455 if (!status)
5456 status = decode_sessionid(xdr, &session->sess_id);
5457 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005458 return status;
5459
Andy Adamsonfc931582009-04-01 09:22:31 -04005460 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005461 p = xdr_inline_decode(xdr, 8);
5462 if (unlikely(!p))
5463 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005464 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005465 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005466
5467 /* Channel attributes */
5468 status = decode_chan_attrs(xdr, &session->fc_attrs);
5469 if (!status)
5470 status = decode_chan_attrs(xdr, &session->bc_attrs);
5471 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005472out_overflow:
5473 print_overflow_msg(__func__, xdr);
5474 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005475}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005476
5477static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5478{
5479 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5480}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005481
5482static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5483{
5484 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5485}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005486#endif /* CONFIG_NFS_V4_1 */
5487
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005488static int decode_sequence(struct xdr_stream *xdr,
5489 struct nfs4_sequence_res *res,
5490 struct rpc_rqst *rqstp)
5491{
5492#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005493 struct nfs4_sessionid id;
5494 u32 dummy;
5495 int status;
5496 __be32 *p;
5497
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005498 if (!res->sr_session)
5499 return 0;
5500
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005501 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005502 if (!status)
5503 status = decode_sessionid(xdr, &id);
5504 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005505 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005506
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005507 /*
5508 * If the server returns different values for sessionID, slotID or
5509 * sequence number, the server is looney tunes.
5510 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005511 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005512
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005513 if (memcmp(id.data, res->sr_session->sess_id.data,
5514 NFS4_MAX_SESSIONID_LEN)) {
5515 dprintk("%s Invalid session id\n", __func__);
5516 goto out_err;
5517 }
Benny Halevye78291e2009-08-14 17:20:00 +03005518
Benny Halevyc0eae662009-08-14 17:20:14 +03005519 p = xdr_inline_decode(xdr, 20);
5520 if (unlikely(!p))
5521 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005522
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005523 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005524 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005525 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005526 dprintk("%s Invalid sequence number\n", __func__);
5527 goto out_err;
5528 }
5529 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005530 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005531 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005532 dprintk("%s Invalid slot id\n", __func__);
5533 goto out_err;
5534 }
5535 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005536 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005537 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005538 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005539 /* result flags */
5540 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005541 status = 0;
5542out_err:
5543 res->sr_status = status;
5544 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005545out_overflow:
5546 print_overflow_msg(__func__, xdr);
5547 status = -EIO;
5548 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005549#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005550 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005551#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005552}
5553
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005554#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005555/*
5556 * TODO: Need to handle case when EOF != true;
5557 */
5558static int decode_getdevicelist(struct xdr_stream *xdr,
5559 struct pnfs_devicelist *res)
5560{
5561 __be32 *p;
5562 int status, i;
5563 struct nfs_writeverf verftemp;
5564
5565 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5566 if (status)
5567 return status;
5568
5569 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5570 if (unlikely(!p))
5571 goto out_overflow;
5572
5573 /* TODO: Skip cookie for now */
5574 p += 2;
5575
5576 /* Read verifier */
Chuck Levercd937102012-03-02 17:14:31 -05005577 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005578
5579 res->num_devs = be32_to_cpup(p);
5580
5581 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5582
5583 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005584 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005585 __func__, res->num_devs);
5586 return -EIO;
5587 }
5588
5589 p = xdr_inline_decode(xdr,
5590 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5591 if (unlikely(!p))
5592 goto out_overflow;
5593 for (i = 0; i < res->num_devs; i++)
5594 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5595 NFS4_DEVICEID4_SIZE);
5596 res->eof = be32_to_cpup(p);
5597 return 0;
5598out_overflow:
5599 print_overflow_msg(__func__, xdr);
5600 return -EIO;
5601}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005602
5603static int decode_getdeviceinfo(struct xdr_stream *xdr,
5604 struct pnfs_device *pdev)
5605{
5606 __be32 *p;
5607 uint32_t len, type;
5608 int status;
5609
5610 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5611 if (status) {
5612 if (status == -ETOOSMALL) {
5613 p = xdr_inline_decode(xdr, 4);
5614 if (unlikely(!p))
5615 goto out_overflow;
5616 pdev->mincount = be32_to_cpup(p);
5617 dprintk("%s: Min count too small. mincnt = %u\n",
5618 __func__, pdev->mincount);
5619 }
5620 return status;
5621 }
5622
5623 p = xdr_inline_decode(xdr, 8);
5624 if (unlikely(!p))
5625 goto out_overflow;
5626 type = be32_to_cpup(p++);
5627 if (type != pdev->layout_type) {
5628 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5629 __func__, pdev->layout_type, type);
5630 return -EINVAL;
5631 }
5632 /*
5633 * Get the length of the opaque device_addr4. xdr_read_pages places
5634 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5635 * and places the remaining xdr data in xdr_buf->tail
5636 */
5637 pdev->mincount = be32_to_cpup(p);
5638 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5639
5640 /* Parse notification bitmap, verifying that it is zero. */
5641 p = xdr_inline_decode(xdr, 4);
5642 if (unlikely(!p))
5643 goto out_overflow;
5644 len = be32_to_cpup(p);
5645 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005646 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005647
5648 p = xdr_inline_decode(xdr, 4 * len);
5649 if (unlikely(!p))
5650 goto out_overflow;
5651 for (i = 0; i < len; i++, p++) {
5652 if (be32_to_cpup(p)) {
5653 dprintk("%s: notifications not supported\n",
5654 __func__);
5655 return -EIO;
5656 }
5657 }
5658 }
5659 return 0;
5660out_overflow:
5661 print_overflow_msg(__func__, xdr);
5662 return -EIO;
5663}
5664
5665static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5666 struct nfs4_layoutget_res *res)
5667{
5668 __be32 *p;
5669 int status;
5670 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005671 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5672 struct kvec *iov = rcvbuf->head;
5673 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005674
5675 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5676 if (status)
5677 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005678 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005679 if (unlikely(!p))
5680 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005681 res->return_on_close = be32_to_cpup(p);
5682 decode_stateid(xdr, &res->stateid);
5683 p = xdr_inline_decode(xdr, 4);
5684 if (unlikely(!p))
5685 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005686 layout_count = be32_to_cpup(p);
5687 if (!layout_count) {
5688 dprintk("%s: server responded with empty layout array\n",
5689 __func__);
5690 return -EINVAL;
5691 }
5692
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005693 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005694 if (unlikely(!p))
5695 goto out_overflow;
5696 p = xdr_decode_hyper(p, &res->range.offset);
5697 p = xdr_decode_hyper(p, &res->range.length);
5698 res->range.iomode = be32_to_cpup(p++);
5699 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005700 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005701
5702 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5703 __func__,
5704 (unsigned long)res->range.offset,
5705 (unsigned long)res->range.length,
5706 res->range.iomode,
5707 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005708 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005709
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005710 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5711 recvd = req->rq_rcv_buf.len - hdrlen;
5712 if (res->layoutp->len > recvd) {
5713 dprintk("NFS: server cheating in layoutget reply: "
5714 "layout len %u > recvd %u\n",
5715 res->layoutp->len, recvd);
5716 return -EINVAL;
5717 }
5718
5719 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005720
5721 if (layout_count > 1) {
5722 /* We only handle a length one array at the moment. Any
5723 * further entries are just ignored. Note that this means
5724 * the client may see a response that is less than the
5725 * minimum it requested.
5726 */
5727 dprintk("%s: server responded with %d layouts, dropping tail\n",
5728 __func__, layout_count);
5729 }
5730
5731 return 0;
5732out_overflow:
5733 print_overflow_msg(__func__, xdr);
5734 return -EIO;
5735}
Andy Adamson863a3c62011-03-23 13:27:54 +00005736
Benny Halevycbe82602011-05-22 19:52:37 +03005737static int decode_layoutreturn(struct xdr_stream *xdr,
5738 struct nfs4_layoutreturn_res *res)
5739{
5740 __be32 *p;
5741 int status;
5742
5743 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5744 if (status)
5745 return status;
5746 p = xdr_inline_decode(xdr, 4);
5747 if (unlikely(!p))
5748 goto out_overflow;
5749 res->lrs_present = be32_to_cpup(p);
5750 if (res->lrs_present)
5751 status = decode_stateid(xdr, &res->stateid);
5752 return status;
5753out_overflow:
5754 print_overflow_msg(__func__, xdr);
5755 return -EIO;
5756}
5757
Andy Adamson863a3c62011-03-23 13:27:54 +00005758static int decode_layoutcommit(struct xdr_stream *xdr,
5759 struct rpc_rqst *req,
5760 struct nfs4_layoutcommit_res *res)
5761{
5762 __be32 *p;
5763 __u32 sizechanged;
5764 int status;
5765
5766 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005767 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005768 if (status)
5769 return status;
5770
5771 p = xdr_inline_decode(xdr, 4);
5772 if (unlikely(!p))
5773 goto out_overflow;
5774 sizechanged = be32_to_cpup(p);
5775
5776 if (sizechanged) {
5777 /* throw away new size */
5778 p = xdr_inline_decode(xdr, 8);
5779 if (unlikely(!p))
5780 goto out_overflow;
5781 }
5782 return 0;
5783out_overflow:
5784 print_overflow_msg(__func__, xdr);
5785 return -EIO;
5786}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005787
5788static int decode_test_stateid(struct xdr_stream *xdr,
5789 struct nfs41_test_stateid_res *res)
5790{
5791 __be32 *p;
5792 int status;
5793 int num_res;
5794
5795 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5796 if (status)
5797 return status;
5798
5799 p = xdr_inline_decode(xdr, 4);
5800 if (unlikely(!p))
5801 goto out_overflow;
5802 num_res = be32_to_cpup(p++);
5803 if (num_res != 1)
5804 goto out;
5805
5806 p = xdr_inline_decode(xdr, 4);
5807 if (unlikely(!p))
5808 goto out_overflow;
5809 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005810
5811 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005812out_overflow:
5813 print_overflow_msg(__func__, xdr);
5814out:
5815 return -EIO;
5816}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005817
5818static int decode_free_stateid(struct xdr_stream *xdr,
5819 struct nfs41_free_stateid_res *res)
5820{
5821 __be32 *p;
5822 int status;
5823
5824 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5825 if (status)
5826 return status;
5827
5828 p = xdr_inline_decode(xdr, 4);
5829 if (unlikely(!p))
5830 goto out_overflow;
5831 res->status = be32_to_cpup(p++);
5832 return res->status;
5833out_overflow:
5834 print_overflow_msg(__func__, xdr);
5835 return -EIO;
5836}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005837#endif /* CONFIG_NFS_V4_1 */
5838
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839/*
Benny Halevy49c25592008-12-23 16:06:16 -05005840 * END OF "GENERIC" DECODE ROUTINES.
5841 */
5842
5843/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844 * Decode OPEN_DOWNGRADE response
5845 */
Chuck Leverbf269552010-12-14 14:59:29 +00005846static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5847 struct xdr_stream *xdr,
5848 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005849{
Andy Adamson05d564f2008-12-23 16:06:15 -05005850 struct compound_hdr hdr;
5851 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852
Chuck Leverbf269552010-12-14 14:59:29 +00005853 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005854 if (status)
5855 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005856 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005857 if (status)
5858 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005859 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005860 if (status)
5861 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005862 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005863 if (status != 0)
5864 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005865 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005866out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005867 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868}
5869
5870/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005871 * Decode ACCESS response
5872 */
Chuck Leverbf269552010-12-14 14:59:29 +00005873static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5874 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005875{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005876 struct compound_hdr hdr;
5877 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005878
Chuck Leverbf269552010-12-14 14:59:29 +00005879 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005880 if (status)
5881 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005882 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005883 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005884 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005885 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005886 if (status != 0)
5887 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005888 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005889 if (status != 0)
5890 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005891 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892out:
5893 return status;
5894}
5895
5896/*
5897 * Decode LOOKUP response
5898 */
Chuck Leverbf269552010-12-14 14:59:29 +00005899static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5900 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005901{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005902 struct compound_hdr hdr;
5903 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005904
Chuck Leverbf269552010-12-14 14:59:29 +00005905 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005906 if (status)
5907 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005908 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005909 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005910 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005911 status = decode_putfh(xdr);
5912 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005913 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005914 status = decode_lookup(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)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005919 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005920 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005921out:
5922 return status;
5923}
5924
5925/*
5926 * Decode LOOKUP_ROOT response
5927 */
Chuck Leverbf269552010-12-14 14:59:29 +00005928static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5929 struct xdr_stream *xdr,
5930 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932 struct compound_hdr hdr;
5933 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005934
Chuck Leverbf269552010-12-14 14:59:29 +00005935 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005936 if (status)
5937 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005938 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005939 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005941 status = decode_putrootfh(xdr);
5942 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005943 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005944 status = decode_getfh(xdr, res->fh);
5945 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005946 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947out:
5948 return status;
5949}
5950
5951/*
5952 * Decode REMOVE response
5953 */
Chuck Leverbf269552010-12-14 14:59:29 +00005954static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5955 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005957 struct compound_hdr hdr;
5958 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005959
Chuck Leverbf269552010-12-14 14:59:29 +00005960 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005961 if (status)
5962 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005963 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005964 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005965 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005966 status = decode_putfh(xdr);
5967 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005968 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970out:
5971 return status;
5972}
5973
5974/*
5975 * Decode RENAME response
5976 */
Chuck Leverbf269552010-12-14 14:59:29 +00005977static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5978 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005980 struct compound_hdr hdr;
5981 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005982
Chuck Leverbf269552010-12-14 14:59:29 +00005983 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005984 if (status)
5985 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005986 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005987 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005988 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005989 status = decode_putfh(xdr);
5990 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005991 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005992 status = decode_savefh(xdr);
5993 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005994 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005995 status = decode_putfh(xdr);
5996 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005998 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999out:
6000 return status;
6001}
6002
6003/*
6004 * Decode LINK response
6005 */
Chuck Leverbf269552010-12-14 14:59:29 +00006006static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6007 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006009 struct compound_hdr hdr;
6010 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006011
Chuck Leverbf269552010-12-14 14:59:29 +00006012 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006013 if (status)
6014 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006015 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006016 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006017 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006018 status = decode_putfh(xdr);
6019 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006021 status = decode_savefh(xdr);
6022 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006023 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006024 status = decode_putfh(xdr);
6025 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006026 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006027 status = decode_link(xdr, &res->cinfo);
6028 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006029 goto out;
6030 /*
6031 * Note order: OP_LINK leaves the directory as the current
6032 * filehandle.
6033 */
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_restorefh(xdr);
6035 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006036 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006037 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006038out:
6039 return status;
6040}
6041
6042/*
6043 * Decode CREATE response
6044 */
Chuck Leverbf269552010-12-14 14:59:29 +00006045static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6046 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006048 struct compound_hdr hdr;
6049 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006050
Chuck Leverbf269552010-12-14 14:59:29 +00006051 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006052 if (status)
6053 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006054 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006055 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006057 status = decode_putfh(xdr);
6058 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006059 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006060 status = decode_create(xdr, &res->dir_cinfo);
6061 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006063 status = decode_getfh(xdr, res->fh);
6064 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065 goto out;
Trond Myklebust7c317fc2012-04-27 13:48:18 -04006066 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067out:
6068 return status;
6069}
6070
6071/*
6072 * Decode SYMLINK response
6073 */
Chuck Leverbf269552010-12-14 14:59:29 +00006074static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6075 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006076{
Chuck Leverbf269552010-12-14 14:59:29 +00006077 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078}
6079
6080/*
6081 * Decode GETATTR response
6082 */
Chuck Leverbf269552010-12-14 14:59:29 +00006083static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6084 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086 struct compound_hdr hdr;
6087 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006088
Chuck Leverbf269552010-12-14 14:59:29 +00006089 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090 if (status)
6091 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006092 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006093 if (status)
6094 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006095 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096 if (status)
6097 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006098 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099out:
6100 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101}
6102
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006103/*
6104 * Encode an SETACL request
6105 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006106static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6107 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006108{
Andy Adamson05d564f2008-12-23 16:06:15 -05006109 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006110 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006111 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006112
Chuck Lever9f06c712010-12-14 14:59:18 +00006113 encode_compound_hdr(xdr, req, &hdr);
6114 encode_sequence(xdr, &args->seq_args, &hdr);
6115 encode_putfh(xdr, args->fh, &hdr);
6116 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006117 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006118}
Andy Adamson05d564f2008-12-23 16:06:15 -05006119
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006120/*
6121 * Decode SETACL response
6122 */
6123static int
Chuck Leverbf269552010-12-14 14:59:29 +00006124nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006125 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006126{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006127 struct compound_hdr hdr;
6128 int status;
6129
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006131 if (status)
6132 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006134 if (status)
6135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006137 if (status)
6138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006140out:
6141 return status;
6142}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143
6144/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006145 * Decode GETACL response
6146 */
6147static int
Chuck Leverbf269552010-12-14 14:59:29 +00006148nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006149 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006150{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006151 struct compound_hdr hdr;
6152 int status;
6153
Trond Myklebust331818f2012-02-03 18:30:53 -05006154 if (res->acl_scratch != NULL) {
6155 void *p = page_address(res->acl_scratch);
6156 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6157 }
Chuck Leverbf269552010-12-14 14:59:29 +00006158 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006159 if (status)
6160 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006161 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006162 if (status)
6163 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006164 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006165 if (status)
6166 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006167 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006168
6169out:
6170 return status;
6171}
6172
6173/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174 * Decode CLOSE response
6175 */
Chuck Leverbf269552010-12-14 14:59:29 +00006176static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6177 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006178{
Andy Adamson05d564f2008-12-23 16:06:15 -05006179 struct compound_hdr hdr;
6180 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006183 if (status)
6184 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006186 if (status)
6187 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006188 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006189 if (status)
6190 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006191 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006192 if (status != 0)
6193 goto out;
6194 /*
6195 * Note: Server may do delete on close for this file
6196 * in which case the getattr call will fail with
6197 * an ESTALE error. Shouldn't be a problem,
6198 * though, since fattr->valid will remain unset.
6199 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006200 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006202 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203}
6204
6205/*
6206 * Decode OPEN response
6207 */
Chuck Leverbf269552010-12-14 14:59:29 +00006208static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6209 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210{
Andy Adamson05d564f2008-12-23 16:06:15 -05006211 struct compound_hdr hdr;
6212 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006213
Chuck Leverbf269552010-12-14 14:59:29 +00006214 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006215 if (status)
6216 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006217 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006218 if (status)
6219 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006220 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006221 if (status)
6222 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006223 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006224 if (status)
6225 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006226 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227 goto out;
Trond Myklebust90ff0c52012-04-27 13:48:18 -04006228 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006230 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006231}
6232
6233/*
6234 * Decode OPEN_CONFIRM response
6235 */
Chuck Leverbf269552010-12-14 14:59:29 +00006236static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6237 struct xdr_stream *xdr,
6238 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239{
Andy Adamson05d564f2008-12-23 16:06:15 -05006240 struct compound_hdr hdr;
6241 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242
Chuck Leverbf269552010-12-14 14:59:29 +00006243 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006244 if (status)
6245 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006246 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006247 if (status)
6248 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006251 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006252}
6253
6254/*
6255 * Decode OPEN response
6256 */
Chuck Leverbf269552010-12-14 14:59:29 +00006257static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6258 struct xdr_stream *xdr,
6259 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260{
Andy Adamson05d564f2008-12-23 16:06:15 -05006261 struct compound_hdr hdr;
6262 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263
Chuck Leverbf269552010-12-14 14:59:29 +00006264 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006265 if (status)
6266 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006267 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006268 if (status)
6269 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006270 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006271 if (status)
6272 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006273 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006274 if (status)
6275 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006276 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006278 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006279}
6280
6281/*
6282 * Decode SETATTR response
6283 */
Chuck Leverbf269552010-12-14 14:59:29 +00006284static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6285 struct xdr_stream *xdr,
6286 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287{
Andy Adamson05d564f2008-12-23 16:06:15 -05006288 struct compound_hdr hdr;
6289 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290
Chuck Leverbf269552010-12-14 14:59:29 +00006291 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006292 if (status)
6293 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006294 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006295 if (status)
6296 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006297 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006298 if (status)
6299 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006300 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006301 if (status)
6302 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006303 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006304out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006305 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306}
6307
6308/*
6309 * Decode LOCK response
6310 */
Chuck Leverbf269552010-12-14 14:59:29 +00006311static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6312 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006313{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006314 struct compound_hdr hdr;
6315 int status;
6316
Chuck Leverbf269552010-12-14 14:59:29 +00006317 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318 if (status)
6319 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006320 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006321 if (status)
6322 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006323 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 if (status)
6325 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006326 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327out:
6328 return status;
6329}
6330
6331/*
6332 * Decode LOCKT response
6333 */
Chuck Leverbf269552010-12-14 14:59:29 +00006334static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6335 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006336{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337 struct compound_hdr hdr;
6338 int status;
6339
Chuck Leverbf269552010-12-14 14:59:29 +00006340 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341 if (status)
6342 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006343 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006344 if (status)
6345 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006346 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006347 if (status)
6348 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006349 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350out:
6351 return status;
6352}
6353
6354/*
6355 * Decode LOCKU response
6356 */
Chuck Leverbf269552010-12-14 14:59:29 +00006357static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6358 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006360 struct compound_hdr hdr;
6361 int status;
6362
Chuck Leverbf269552010-12-14 14:59:29 +00006363 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364 if (status)
6365 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006366 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006367 if (status)
6368 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006369 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006370 if (status)
6371 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006372 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373out:
6374 return status;
6375}
6376
Chuck Leverbf269552010-12-14 14:59:29 +00006377static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6378 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006379{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006380 struct compound_hdr hdr;
6381 int status;
6382
Chuck Leverbf269552010-12-14 14:59:29 +00006383 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006384 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006386 return status;
6387}
6388
Linus Torvalds1da177e2005-04-16 15:20:36 -07006389/*
6390 * Decode READLINK response
6391 */
Chuck Leverbf269552010-12-14 14:59:29 +00006392static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6393 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006394 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006395{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396 struct compound_hdr hdr;
6397 int status;
6398
Chuck Leverbf269552010-12-14 14:59:29 +00006399 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400 if (status)
6401 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006402 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006403 if (status)
6404 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006405 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406 if (status)
6407 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006408 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006409out:
6410 return status;
6411}
6412
6413/*
6414 * Decode READDIR response
6415 */
Chuck Leverbf269552010-12-14 14:59:29 +00006416static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6417 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006418{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006419 struct compound_hdr hdr;
6420 int status;
6421
Chuck Leverbf269552010-12-14 14:59:29 +00006422 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006423 if (status)
6424 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006425 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006426 if (status)
6427 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006428 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429 if (status)
6430 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006431 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006432out:
6433 return status;
6434}
6435
6436/*
6437 * Decode Read response
6438 */
Chuck Leverbf269552010-12-14 14:59:29 +00006439static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6440 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006441{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442 struct compound_hdr hdr;
6443 int status;
6444
Chuck Leverbf269552010-12-14 14:59:29 +00006445 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006446 if (status)
6447 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006449 if (status)
6450 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006451 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006452 if (status)
6453 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006454 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006455 if (!status)
6456 status = res->count;
6457out:
6458 return status;
6459}
6460
6461/*
6462 * Decode WRITE response
6463 */
Chuck Leverbf269552010-12-14 14:59:29 +00006464static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6465 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467 struct compound_hdr hdr;
6468 int status;
6469
Chuck Leverbf269552010-12-14 14:59:29 +00006470 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 if (status)
6472 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006473 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006474 if (status)
6475 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006476 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477 if (status)
6478 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006479 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006480 if (status)
6481 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006482 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006483 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484 if (!status)
6485 status = res->count;
6486out:
6487 return status;
6488}
6489
6490/*
6491 * Decode COMMIT response
6492 */
Chuck Leverbf269552010-12-14 14:59:29 +00006493static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006494 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496 struct compound_hdr hdr;
6497 int status;
6498
Chuck Leverbf269552010-12-14 14:59:29 +00006499 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006500 if (status)
6501 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006502 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006503 if (status)
6504 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006505 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506 if (status)
6507 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006508 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006509out:
6510 return status;
6511}
6512
6513/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006514 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515 */
Chuck Leverbf269552010-12-14 14:59:29 +00006516static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006517 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519 struct compound_hdr hdr;
6520 int status;
6521
Chuck Leverbf269552010-12-14 14:59:29 +00006522 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006523 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006524 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006525 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006528 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 return status;
6530}
6531
6532/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006533 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006534 */
Chuck Leverbf269552010-12-14 14:59:29 +00006535static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006536 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006538 struct compound_hdr hdr;
6539 int status;
6540
Chuck Leverbf269552010-12-14 14:59:29 +00006541 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006542 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006543 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006544 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006545 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006546 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006547 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 return status;
6549}
6550
6551/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006552 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553 */
Chuck Leverbf269552010-12-14 14:59:29 +00006554static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006555 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006557 struct compound_hdr hdr;
6558 int status;
6559
Chuck Leverbf269552010-12-14 14:59:29 +00006560 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006561 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006562 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006563 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006566 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567 return status;
6568}
6569
6570/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006571 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572 */
Chuck Leverbf269552010-12-14 14:59:29 +00006573static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6574 struct xdr_stream *xdr,
6575 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006576{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577 struct compound_hdr hdr;
6578 int status;
6579
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006581 if (status)
6582 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006584 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006586 status = decode_putfh(xdr);
6587 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006588 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006589 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590out:
6591 return status;
6592}
6593
6594/*
6595 * Decode RENEW response
6596 */
Chuck Leverbf269552010-12-14 14:59:29 +00006597static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6598 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006600 struct compound_hdr hdr;
6601 int status;
6602
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006605 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 return status;
6607}
6608
6609/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006610 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611 */
Chuck Leverbf269552010-12-14 14:59:29 +00006612static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6613 struct xdr_stream *xdr,
6614 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616 struct compound_hdr hdr;
6617 int status;
6618
Chuck Leverbf269552010-12-14 14:59:29 +00006619 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622 return status;
6623}
6624
6625/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006626 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627 */
Chuck Leverbf269552010-12-14 14:59:29 +00006628static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6629 struct xdr_stream *xdr,
6630 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006632 struct compound_hdr hdr;
6633 int status;
6634
Chuck Leverbf269552010-12-14 14:59:29 +00006635 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006637 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006639 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006641 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642 return status;
6643}
6644
6645/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006646 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647 */
Chuck Leverbf269552010-12-14 14:59:29 +00006648static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6649 struct xdr_stream *xdr,
6650 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006651{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006652 struct compound_hdr hdr;
6653 int status;
6654
Chuck Leverbf269552010-12-14 14:59:29 +00006655 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006656 if (status)
6657 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006658 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006659 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006660 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006661 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006662 if (status != 0)
6663 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006664 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006665 if (status != 0)
6666 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006667 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006668out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669 return status;
6670}
6671
Trond Myklebust683b57b2006-06-09 09:34:22 -04006672/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006673 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006674 */
Chuck Leverbf269552010-12-14 14:59:29 +00006675static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6676 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006677 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006678{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006679 struct compound_hdr hdr;
6680 int status;
6681
Chuck Leverbf269552010-12-14 14:59:29 +00006682 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006683 if (status)
6684 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006685 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006686 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006687 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_putfh(xdr);
6689 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006691 status = decode_lookup(xdr);
6692 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006693 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006694 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006695 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6696 NULL, res->fs_locations,
6697 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006698out:
6699 return status;
6700}
6701
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006702/*
6703 * Decode SECINFO response
6704 */
6705static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6706 struct xdr_stream *xdr,
6707 struct nfs4_secinfo_res *res)
6708{
6709 struct compound_hdr hdr;
6710 int status;
6711
6712 status = decode_compound_hdr(xdr, &hdr);
6713 if (status)
6714 goto out;
6715 status = decode_sequence(xdr, &res->seq_res, rqstp);
6716 if (status)
6717 goto out;
6718 status = decode_putfh(xdr);
6719 if (status)
6720 goto out;
6721 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006722out:
6723 return status;
6724}
6725
Benny Halevy99fe60d2009-04-01 09:22:29 -04006726#if defined(CONFIG_NFS_V4_1)
6727/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006728 * Decode BIND_CONN_TO_SESSION response
6729 */
6730static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6731 struct xdr_stream *xdr,
6732 void *res)
6733{
6734 struct compound_hdr hdr;
6735 int status;
6736
6737 status = decode_compound_hdr(xdr, &hdr);
6738 if (!status)
6739 status = decode_bind_conn_to_session(xdr, res);
6740 return status;
6741}
6742
6743/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006744 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006745 */
Chuck Leverbf269552010-12-14 14:59:29 +00006746static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6747 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006748 void *res)
6749{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006750 struct compound_hdr hdr;
6751 int status;
6752
Chuck Leverbf269552010-12-14 14:59:29 +00006753 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006754 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006755 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006756 return status;
6757}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006758
6759/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006760 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006761 */
Chuck Leverbf269552010-12-14 14:59:29 +00006762static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6763 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006764 struct nfs41_create_session_res *res)
6765{
Andy Adamsonfc931582009-04-01 09:22:31 -04006766 struct compound_hdr hdr;
6767 int status;
6768
Chuck Leverbf269552010-12-14 14:59:29 +00006769 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006770 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006771 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006772 return status;
6773}
6774
6775/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006776 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006777 */
Chuck Leverbf269552010-12-14 14:59:29 +00006778static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6779 struct xdr_stream *xdr,
6780 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006781{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006782 struct compound_hdr hdr;
6783 int status;
6784
Chuck Leverbf269552010-12-14 14:59:29 +00006785 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006786 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006788 return status;
6789}
6790
6791/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006792 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006793 */
Chuck Leverbf269552010-12-14 14:59:29 +00006794static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6795 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006796 struct nfs4_sequence_res *res)
6797{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006798 struct compound_hdr hdr;
6799 int status;
6800
Chuck Leverbf269552010-12-14 14:59:29 +00006801 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006802 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006803 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006804 return status;
6805}
6806
6807/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006808 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006809 */
Chuck Leverbf269552010-12-14 14:59:29 +00006810static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6811 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006812 struct nfs4_get_lease_time_res *res)
6813{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006814 struct compound_hdr hdr;
6815 int status;
6816
Chuck Leverbf269552010-12-14 14:59:29 +00006817 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006818 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006819 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006820 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006821 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006822 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006823 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006824 return status;
6825}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006826
6827/*
6828 * Decode RECLAIM_COMPLETE response
6829 */
Chuck Leverbf269552010-12-14 14:59:29 +00006830static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6831 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006832 struct nfs41_reclaim_complete_res *res)
6833{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006834 struct compound_hdr hdr;
6835 int status;
6836
Chuck Leverbf269552010-12-14 14:59:29 +00006837 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006838 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006839 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006840 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006841 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006842 return status;
6843}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006844
6845/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006846 * Decode GETDEVICELIST response
6847 */
6848static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6849 struct xdr_stream *xdr,
6850 struct nfs4_getdevicelist_res *res)
6851{
6852 struct compound_hdr hdr;
6853 int status;
6854
6855 dprintk("encoding getdevicelist!\n");
6856
6857 status = decode_compound_hdr(xdr, &hdr);
6858 if (status != 0)
6859 goto out;
6860 status = decode_sequence(xdr, &res->seq_res, rqstp);
6861 if (status != 0)
6862 goto out;
6863 status = decode_putfh(xdr);
6864 if (status != 0)
6865 goto out;
6866 status = decode_getdevicelist(xdr, res->devlist);
6867out:
6868 return status;
6869}
6870
6871/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006872 * Decode GETDEVINFO response
6873 */
Chuck Leverbf269552010-12-14 14:59:29 +00006874static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6875 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006876 struct nfs4_getdeviceinfo_res *res)
6877{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006878 struct compound_hdr hdr;
6879 int status;
6880
Chuck Leverbf269552010-12-14 14:59:29 +00006881 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006882 if (status != 0)
6883 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006884 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006885 if (status != 0)
6886 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006887 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006888out:
6889 return status;
6890}
6891
6892/*
6893 * Decode LAYOUTGET response
6894 */
Chuck Leverbf269552010-12-14 14:59:29 +00006895static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6896 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006897 struct nfs4_layoutget_res *res)
6898{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006899 struct compound_hdr hdr;
6900 int status;
6901
Chuck Leverbf269552010-12-14 14:59:29 +00006902 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006903 if (status)
6904 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006905 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006906 if (status)
6907 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006908 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006909 if (status)
6910 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006911 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006912out:
6913 return status;
6914}
Andy Adamson863a3c62011-03-23 13:27:54 +00006915
6916/*
Benny Halevycbe82602011-05-22 19:52:37 +03006917 * Decode LAYOUTRETURN response
6918 */
6919static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6920 struct xdr_stream *xdr,
6921 struct nfs4_layoutreturn_res *res)
6922{
6923 struct compound_hdr hdr;
6924 int status;
6925
6926 status = decode_compound_hdr(xdr, &hdr);
6927 if (status)
6928 goto out;
6929 status = decode_sequence(xdr, &res->seq_res, rqstp);
6930 if (status)
6931 goto out;
6932 status = decode_putfh(xdr);
6933 if (status)
6934 goto out;
6935 status = decode_layoutreturn(xdr, res);
6936out:
6937 return status;
6938}
6939
6940/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006941 * Decode LAYOUTCOMMIT response
6942 */
6943static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6944 struct xdr_stream *xdr,
6945 struct nfs4_layoutcommit_res *res)
6946{
6947 struct compound_hdr hdr;
6948 int status;
6949
6950 status = decode_compound_hdr(xdr, &hdr);
6951 if (status)
6952 goto out;
6953 status = decode_sequence(xdr, &res->seq_res, rqstp);
6954 if (status)
6955 goto out;
6956 status = decode_putfh(xdr);
6957 if (status)
6958 goto out;
6959 status = decode_layoutcommit(xdr, rqstp, res);
6960 if (status)
6961 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006962 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006963out:
6964 return status;
6965}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006966
6967/*
6968 * Decode SECINFO_NO_NAME response
6969 */
6970static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6971 struct xdr_stream *xdr,
6972 struct nfs4_secinfo_res *res)
6973{
6974 struct compound_hdr hdr;
6975 int status;
6976
6977 status = decode_compound_hdr(xdr, &hdr);
6978 if (status)
6979 goto out;
6980 status = decode_sequence(xdr, &res->seq_res, rqstp);
6981 if (status)
6982 goto out;
6983 status = decode_putrootfh(xdr);
6984 if (status)
6985 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04006986 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006987out:
6988 return status;
6989}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006990
6991/*
6992 * Decode TEST_STATEID response
6993 */
6994static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6995 struct xdr_stream *xdr,
6996 struct nfs41_test_stateid_res *res)
6997{
6998 struct compound_hdr hdr;
6999 int status;
7000
7001 status = decode_compound_hdr(xdr, &hdr);
7002 if (status)
7003 goto out;
7004 status = decode_sequence(xdr, &res->seq_res, rqstp);
7005 if (status)
7006 goto out;
7007 status = decode_test_stateid(xdr, res);
7008out:
7009 return status;
7010}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007011
7012/*
7013 * Decode FREE_STATEID response
7014 */
7015static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7016 struct xdr_stream *xdr,
7017 struct nfs41_free_stateid_res *res)
7018{
7019 struct compound_hdr hdr;
7020 int status;
7021
7022 status = decode_compound_hdr(xdr, &hdr);
7023 if (status)
7024 goto out;
7025 status = decode_sequence(xdr, &res->seq_res, rqstp);
7026 if (status)
7027 goto out;
7028 status = decode_free_stateid(xdr, res);
7029out:
7030 return status;
7031}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007032#endif /* CONFIG_NFS_V4_1 */
7033
Chuck Lever573c4e12010-12-14 14:58:11 +00007034/**
7035 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7036 * the local page cache.
7037 * @xdr: XDR stream where entry resides
7038 * @entry: buffer to fill in with entry data
7039 * @plus: boolean indicating whether this should be a readdirplus entry
7040 *
7041 * Returns zero if successful, otherwise a negative errno value is
7042 * returned.
7043 *
7044 * This function is not invoked during READDIR reply decoding, but
7045 * rather whenever an application invokes the getdents(2) system call
7046 * on a directory already in our cache.
7047 */
7048int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7049 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007050{
Fred Isamandae100c2011-07-30 20:52:37 -04007051 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007052 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007053 __be32 *p = xdr_inline_decode(xdr, 4);
7054 if (unlikely(!p))
7055 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007056 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007057 p = xdr_inline_decode(xdr, 4);
7058 if (unlikely(!p))
7059 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007060 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007061 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007062 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007063 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007064 }
7065
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007066 p = xdr_inline_decode(xdr, 12);
7067 if (unlikely(!p))
7068 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007069 entry->prev_cookie = entry->cookie;
7070 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007071 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007072
Trond Myklebust9af8c222010-10-24 11:52:55 -04007073 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007074 if (unlikely(!p))
7075 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007076 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007077
7078 /*
7079 * In case the server doesn't return an inode number,
7080 * we fake one here. (We don't use inode number 0,
7081 * since glibc seems to choke on it...)
7082 */
7083 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007084 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007085
Trond Myklebust9af8c222010-10-24 11:52:55 -04007086 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007087 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007088
7089 if (decode_attr_length(xdr, &len, &p) < 0)
7090 goto out_overflow;
7091
Chuck Lever573c4e12010-12-14 14:58:11 +00007092 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007093 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007094 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007095 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7096 entry->ino = entry->fattr->mounted_on_fileid;
7097 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007098 entry->ino = entry->fattr->fileid;
7099
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007100 entry->d_type = DT_UNKNOWN;
7101 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7102 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7103
Chuck Lever573c4e12010-12-14 14:58:11 +00007104 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007105
7106out_overflow:
7107 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007108 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007109}
7110
7111/*
7112 * We need to translate between nfs status return values and
7113 * the local errno values which may not be the same.
7114 */
7115static struct {
7116 int stat;
7117 int errno;
7118} nfs_errtbl[] = {
7119 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007120 { NFS4ERR_PERM, -EPERM },
7121 { NFS4ERR_NOENT, -ENOENT },
7122 { NFS4ERR_IO, -errno_NFSERR_IO},
7123 { NFS4ERR_NXIO, -ENXIO },
7124 { NFS4ERR_ACCESS, -EACCES },
7125 { NFS4ERR_EXIST, -EEXIST },
7126 { NFS4ERR_XDEV, -EXDEV },
7127 { NFS4ERR_NOTDIR, -ENOTDIR },
7128 { NFS4ERR_ISDIR, -EISDIR },
7129 { NFS4ERR_INVAL, -EINVAL },
7130 { NFS4ERR_FBIG, -EFBIG },
7131 { NFS4ERR_NOSPC, -ENOSPC },
7132 { NFS4ERR_ROFS, -EROFS },
7133 { NFS4ERR_MLINK, -EMLINK },
7134 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7135 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7136 { NFS4ERR_DQUOT, -EDQUOT },
7137 { NFS4ERR_STALE, -ESTALE },
7138 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007139 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7140 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7141 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007142 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007143 { NFS4ERR_BADTYPE, -EBADTYPE },
7144 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007145 { NFS4ERR_SYMLINK, -ELOOP },
7146 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7147 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007148 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007149};
7150
7151/*
7152 * Convert an NFS error code to a local one.
7153 * This one is used jointly by NFSv2 and NFSv3.
7154 */
7155static int
David Howells0a8ea432006-08-22 20:06:08 -04007156nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007157{
7158 int i;
7159 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7160 if (nfs_errtbl[i].stat == stat)
7161 return nfs_errtbl[i].errno;
7162 }
7163 if (stat <= 10000 || stat > 10100) {
7164 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007165 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007166 }
7167 /* If we cannot translate the error, the recovery routines should
7168 * handle it.
7169 * Note: remaining NFSv4 error codes have values > 10000, so should
7170 * not conflict with native Linux error codes.
7171 */
Benny Halevy856dff32008-03-31 17:39:06 +03007172 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007173}
7174
Linus Torvalds1da177e2005-04-16 15:20:36 -07007175#define PROC(proc, argtype, restype) \
7176[NFSPROC4_CLNT_##proc] = { \
7177 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007178 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007179 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007180 .p_arglen = NFS4_##argtype##_sz, \
7181 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007182 .p_statidx = NFSPROC4_CLNT_##proc, \
7183 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007184}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007185
7186struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007187 PROC(READ, enc_read, dec_read),
7188 PROC(WRITE, enc_write, dec_write),
7189 PROC(COMMIT, enc_commit, dec_commit),
7190 PROC(OPEN, enc_open, dec_open),
7191 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7192 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7193 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7194 PROC(CLOSE, enc_close, dec_close),
7195 PROC(SETATTR, enc_setattr, dec_setattr),
7196 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7197 PROC(RENEW, enc_renew, dec_renew),
7198 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7199 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7200 PROC(LOCK, enc_lock, dec_lock),
7201 PROC(LOCKT, enc_lockt, dec_lockt),
7202 PROC(LOCKU, enc_locku, dec_locku),
7203 PROC(ACCESS, enc_access, dec_access),
7204 PROC(GETATTR, enc_getattr, dec_getattr),
7205 PROC(LOOKUP, enc_lookup, dec_lookup),
7206 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7207 PROC(REMOVE, enc_remove, dec_remove),
7208 PROC(RENAME, enc_rename, dec_rename),
7209 PROC(LINK, enc_link, dec_link),
7210 PROC(SYMLINK, enc_symlink, dec_symlink),
7211 PROC(CREATE, enc_create, dec_create),
7212 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7213 PROC(STATFS, enc_statfs, dec_statfs),
7214 PROC(READLINK, enc_readlink, dec_readlink),
7215 PROC(READDIR, enc_readdir, dec_readdir),
7216 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7217 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7218 PROC(GETACL, enc_getacl, dec_getacl),
7219 PROC(SETACL, enc_setacl, dec_setacl),
7220 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7221 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007222 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007223#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007224 PROC(BIND_CONN_TO_SESSION,
7225 enc_bind_conn_to_session, dec_bind_conn_to_session),
Chuck Lever7d93bd712010-12-14 14:57:42 +00007226 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7227 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7228 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7229 PROC(SEQUENCE, enc_sequence, dec_sequence),
7230 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7231 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7232 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7233 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007234 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007235 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007236 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007237 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007238 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007239 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007240#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007241};
7242
Trond Myklebusta613fa12012-01-20 13:53:56 -05007243const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007244 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007245 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007246 .procs = nfs4_procedures
7247};
7248
7249/*
7250 * Local variables:
7251 * c-basic-offset: 8
7252 * End:
7253 */