blob: 27cc76d88f9a430ebf403822aad98370c105528a [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"
Trond Myklebust76e697b2012-11-26 14:20:49 -050059#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040060#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040061#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#define NFSDBG_FACILITY NFSDBG_XDR
64
65/* Mapping from NFS error code to "errno" error code. */
66#define errno_NFSERR_IO EIO
67
David Howells0a8ea432006-08-22 20:06:08 -040068static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
71#ifdef DEBUG
72#define NFS4_MAXTAGLEN 20
73#else
74#define NFS4_MAXTAGLEN 0
75#endif
76
Andy Adamson6c0195a2008-12-23 16:06:15 -050077/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040078 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040080#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050081#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85#define op_encode_hdr_maxsz (1)
86#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040087#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
92 (NFS4_FHSIZE >> 2))
93#define decode_putfh_maxsz (op_decode_hdr_maxsz)
94#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96#define encode_getfh_maxsz (op_encode_hdr_maxsz)
97#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040099#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000100#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400103#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Andy Adamson88034c32012-05-23 05:02:34 -0400105/* We support only one layout type per file system */
106#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000107/* This is based on getfattr, which uses the most attributes: */
108#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400109 3 + 3 + 3 + nfs4_owner_maxsz + \
110 nfs4_group_maxsz + decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000111#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
112 nfs4_fattr_value_maxsz)
113#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400114#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
115 1 + 2 + 1 + \
116 nfs4_owner_maxsz + \
117 nfs4_group_maxsz + \
118 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#define encode_savefh_maxsz (op_encode_hdr_maxsz)
120#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400121#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
122#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200123#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400124/* The 5 accounts for the PNFS attributes, and assumes that at most three
125 * layout types will be returned.
126 */
127#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
128 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
130#define decode_renew_maxsz (op_decode_hdr_maxsz)
131#define encode_setclientid_maxsz \
132 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500133 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
134 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
135 1 /* sc_prog */ + \
136 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
137 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
138 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#define decode_setclientid_maxsz \
140 (op_decode_hdr_maxsz + \
141 2 + \
142 1024) /* large value for CLID_INUSE */
143#define encode_setclientid_confirm_maxsz \
144 (op_encode_hdr_maxsz + \
145 3 + (NFS4_VERIFIER_SIZE >> 2))
146#define decode_setclientid_confirm_maxsz \
147 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400148#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
149#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400150#define encode_share_access_maxsz \
151 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500152#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400153#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
154#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
155#define encode_open_maxsz (op_encode_hdr_maxsz + \
156 2 + encode_share_access_maxsz + 2 + \
157 open_owner_id_maxsz + \
158 encode_opentype_maxsz + \
159 encode_claim_null_maxsz)
160#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400161#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400162 decode_ace_maxsz)
163#define decode_change_info_maxsz (5)
164#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400165 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400166 decode_change_info_maxsz + 1 + \
167 nfs4_fattr_bitmap_maxsz + \
168 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400169#define encode_open_confirm_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1)
172#define decode_open_confirm_maxsz \
173 (op_decode_hdr_maxsz + \
174 decode_stateid_maxsz)
175#define encode_open_downgrade_maxsz \
176 (op_encode_hdr_maxsz + \
177 encode_stateid_maxsz + 1 + \
178 encode_share_access_maxsz)
179#define decode_open_downgrade_maxsz \
180 (op_decode_hdr_maxsz + \
181 decode_stateid_maxsz)
182#define encode_close_maxsz (op_encode_hdr_maxsz + \
183 1 + encode_stateid_maxsz)
184#define decode_close_maxsz (op_decode_hdr_maxsz + \
185 decode_stateid_maxsz)
186#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + \
188 encode_attrs_maxsz)
189#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
190 nfs4_fattr_bitmap_maxsz)
191#define encode_read_maxsz (op_encode_hdr_maxsz + \
192 encode_stateid_maxsz + 3)
193#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
194#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
195 2 + encode_verifier_maxsz + 5)
196#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
197 decode_verifier_maxsz)
198#define encode_readlink_maxsz (op_encode_hdr_maxsz)
199#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
200#define encode_write_maxsz (op_encode_hdr_maxsz + \
201 encode_stateid_maxsz + 4)
202#define decode_write_maxsz (op_decode_hdr_maxsz + \
203 2 + decode_verifier_maxsz)
204#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
205#define decode_commit_maxsz (op_decode_hdr_maxsz + \
206 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#define encode_remove_maxsz (op_encode_hdr_maxsz + \
208 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400209#define decode_remove_maxsz (op_decode_hdr_maxsz + \
210 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211#define encode_rename_maxsz (op_encode_hdr_maxsz + \
212 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400213#define decode_rename_maxsz (op_decode_hdr_maxsz + \
214 decode_change_info_maxsz + \
215 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#define encode_link_maxsz (op_encode_hdr_maxsz + \
217 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400218#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400219#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400220#define encode_lock_maxsz (op_encode_hdr_maxsz + \
221 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400222 1 + encode_stateid_maxsz + 1 + \
223 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define decode_lock_denied_maxsz \
225 (8 + decode_lockowner_maxsz)
226#define decode_lock_maxsz (op_decode_hdr_maxsz + \
227 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400228#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
229 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400230#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
231 decode_lock_denied_maxsz)
232#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
233 encode_stateid_maxsz + \
234 4)
235#define decode_locku_maxsz (op_decode_hdr_maxsz + \
236 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400237#define encode_release_lockowner_maxsz \
238 (op_encode_hdr_maxsz + \
239 encode_lockowner_maxsz)
240#define decode_release_lockowner_maxsz \
241 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400242#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
243#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
245 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400246 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000247 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
249#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400250 1 + 2 + nfs4_name_maxsz + \
251 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400252#define decode_create_maxsz (op_decode_hdr_maxsz + \
253 decode_change_info_maxsz + \
254 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400255#define encode_statfs_maxsz (encode_getattr_maxsz)
256#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
258#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400259#define encode_getacl_maxsz (encode_getattr_maxsz)
260#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
261 nfs4_fattr_bitmap_maxsz + 1)
262#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
263 encode_stateid_maxsz + 3)
264#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400265#define encode_fs_locations_maxsz \
266 (encode_getattr_maxsz)
267#define decode_fs_locations_maxsz \
268 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000269#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400270#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 -0400271
272#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400273#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500274#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
275 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400276
Benny Halevy99fe60d2009-04-01 09:22:29 -0400277#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
278 encode_verifier_maxsz + \
279 1 /* co_ownerid.len */ + \
280 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
281 1 /* flags */ + \
282 1 /* spa_how */ + \
283 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500284 1 /* implementation id array of size 1 */ + \
285 1 /* nii_domain */ + \
286 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
287 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500288 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500289 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400290#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
291 2 /* eir_clientid */ + \
292 1 /* eir_sequenceid */ + \
293 1 /* eir_flags */ + \
294 1 /* spr_how */ + \
295 0 /* SP4_NONE (for now) */ + \
296 2 /* eir_server_owner.so_minor_id */ + \
297 /* eir_server_owner.so_major_id<> */ \
298 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
299 /* eir_server_scope<> */ \
300 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
301 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500302 1 /* nii_domain */ + \
303 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
304 1 /* nii_name */ + \
305 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
306 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400307#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
308#define decode_channel_attrs_maxsz (6 + \
309 1 /* ca_rdma_ird.len */ + \
310 1 /* ca_rdma_ird */)
311#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
312 2 /* csa_clientid */ + \
313 1 /* csa_sequence */ + \
314 1 /* csa_flags */ + \
315 encode_channel_attrs_maxsz + \
316 encode_channel_attrs_maxsz + \
317 1 /* csa_cb_program */ + \
318 1 /* csa_sec_parms.len (1) */ + \
319 1 /* cb_secflavor (AUTH_SYS) */ + \
320 1 /* stamp */ + \
321 1 /* machinename.len */ + \
322 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
323 1 /* uid */ + \
324 1 /* gid */ + \
325 1 /* gids.len (0) */)
326#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
327 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
328 1 /* csr_sequence */ + \
329 1 /* csr_flags */ + \
330 decode_channel_attrs_maxsz + \
331 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400332#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
333 /* bctsa_sessid */ \
334 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
335 1 /* bctsa_dir */ + \
336 1 /* bctsa_use_conn_in_rdma_mode */)
337#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
338 /* bctsr_sessid */ \
339 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
340 1 /* bctsr_dir */ + \
341 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400342#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
343#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400344#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
345#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400346#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
347 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
348#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
349 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500350#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
351#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400352#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
353 encode_verifier_maxsz)
354#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
355 2 /* nfs_cookie4 gdlr_cookie */ + \
356 decode_verifier_maxsz \
357 /* verifier4 gdlr_verifier */ + \
358 1 /* gdlr_deviceid_list count */ + \
359 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
360 NFS4_DEVICEID4_SIZE) \
361 /* gdlr_deviceid_list */ + \
362 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400363#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
364 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
365#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
366 1 /* layout type */ + \
367 1 /* opaque devaddr4 length */ + \
368 /* devaddr4 payload is read into page */ \
369 1 /* notification bitmap length */ + \
370 1 /* notification bitmap */)
371#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
372 encode_stateid_maxsz)
373#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
374 decode_stateid_maxsz + \
375 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000376#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
377 2 /* offset */ + \
378 2 /* length */ + \
379 1 /* reclaim */ + \
380 encode_stateid_maxsz + \
381 1 /* new offset (true) */ + \
382 2 /* last byte written */ + \
383 1 /* nt_timechanged (false) */ + \
384 1 /* layoutupdate4 layout type */ + \
385 1 /* NULL filelayout layoutupdate4 payload */)
386#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300387#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
388 encode_stateid_maxsz + \
389 1 /* FIXME: opaque lrf_body always empty at the moment */)
390#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
391 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400392#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
393#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400394#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
395 XDR_QUADLEN(NFS4_STATEID_SIZE))
396#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400397#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
398 XDR_QUADLEN(NFS4_STATEID_SIZE))
399#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400#else /* CONFIG_NFS_V4_1 */
401#define encode_sequence_maxsz 0
402#define decode_sequence_maxsz 0
403#endif /* CONFIG_NFS_V4_1 */
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
406#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
407#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400416 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400418 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400420 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400422 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400424 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400426 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400430 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400434 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400435 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400439 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400440 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400444 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400448 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400450 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400451 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400452 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400453 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400454 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400455 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400457 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400458 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400459 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400460 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400461 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400462 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400463#define NFS4_enc_open_confirm_sz \
464 (compound_encode_hdr_maxsz + \
465 encode_putfh_maxsz + \
466 encode_open_confirm_maxsz)
467#define NFS4_dec_open_confirm_sz \
468 (compound_decode_hdr_maxsz + \
469 decode_putfh_maxsz + \
470 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400472 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400474 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400475 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400478 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400480 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400481 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400482 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#define NFS4_enc_open_downgrade_sz \
484 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 encode_putfh_maxsz + \
487 encode_open_downgrade_maxsz + \
488 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489#define NFS4_dec_open_downgrade_sz \
490 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400491 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400492 decode_putfh_maxsz + \
493 decode_open_downgrade_maxsz + \
494 decode_getattr_maxsz)
495#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400497 encode_putfh_maxsz + \
498 encode_close_maxsz + \
499 encode_getattr_maxsz)
500#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400501 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400502 decode_putfh_maxsz + \
503 decode_close_maxsz + \
504 decode_getattr_maxsz)
505#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400506 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400507 encode_putfh_maxsz + \
508 encode_setattr_maxsz + \
509 encode_getattr_maxsz)
510#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400511 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400512 decode_putfh_maxsz + \
513 decode_setattr_maxsz + \
514 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400516 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 encode_putfh_maxsz + \
518 encode_fsinfo_maxsz)
519#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 decode_putfh_maxsz + \
522 decode_fsinfo_maxsz)
523#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
524 encode_renew_maxsz)
525#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
526 decode_renew_maxsz)
527#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
528 encode_setclientid_maxsz)
529#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
530 decode_setclientid_maxsz)
531#define NFS4_enc_setclientid_confirm_sz \
532 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400533 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534#define NFS4_dec_setclientid_confirm_sz \
535 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400536 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400540 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400544 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400548 encode_lockt_maxsz)
549#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400551 decode_putfh_maxsz + \
552 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400554 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400556 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400560 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400561#define NFS4_enc_release_lockowner_sz \
562 (compound_encode_hdr_maxsz + \
563 encode_lockowner_maxsz)
564#define NFS4_dec_release_lockowner_sz \
565 (compound_decode_hdr_maxsz + \
566 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400570 encode_access_maxsz + \
571 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400573 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400575 decode_access_maxsz + \
576 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400578 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 encode_putfh_maxsz + \
580 encode_getattr_maxsz)
581#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_putfh_maxsz + \
584 decode_getattr_maxsz)
585#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 encode_putfh_maxsz + \
588 encode_lookup_maxsz + \
589 encode_getattr_maxsz + \
590 encode_getfh_maxsz)
591#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400594 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 decode_getattr_maxsz + \
596 decode_getfh_maxsz)
597#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 encode_putrootfh_maxsz + \
600 encode_getattr_maxsz + \
601 encode_getfh_maxsz)
602#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400603 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 decode_putrootfh_maxsz + \
605 decode_getattr_maxsz + \
606 decode_getfh_maxsz)
607#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400608 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400610 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400612 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400614 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 encode_putfh_maxsz + \
618 encode_savefh_maxsz + \
619 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400620 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 decode_putfh_maxsz + \
624 decode_savefh_maxsz + \
625 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400626 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400628 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 encode_putfh_maxsz + \
630 encode_savefh_maxsz + \
631 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400632 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400633 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400634 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 decode_putfh_maxsz + \
638 decode_savefh_maxsz + \
639 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400640 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400641 decode_restorefh_maxsz + \
642 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400644 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 encode_putfh_maxsz + \
646 encode_symlink_maxsz + \
647 encode_getattr_maxsz + \
648 encode_getfh_maxsz)
649#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_putfh_maxsz + \
652 decode_symlink_maxsz + \
653 decode_getattr_maxsz + \
654 decode_getfh_maxsz)
655#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400656 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 encode_putfh_maxsz + \
658 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400659 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400660 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400662 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 decode_putfh_maxsz + \
664 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400665 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400666 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 encode_putfh_maxsz + \
670 encode_getattr_maxsz)
671#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 decode_putfh_maxsz + \
674 decode_getattr_maxsz)
675#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400678 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800685 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 encode_getattr_maxsz)
687#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800689 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 decode_getattr_maxsz)
691#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100694 encode_delegreturn_maxsz + \
695 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400697 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100698 decode_delegreturn_maxsz + \
699 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000700#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000702 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400703 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000706 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000708#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000710 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400711 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000714 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400716#define NFS4_enc_fs_locations_sz \
717 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400718 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400719 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400720 encode_lookup_maxsz + \
721 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400722#define NFS4_dec_fs_locations_sz \
723 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400724 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400725 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400726 decode_lookup_maxsz + \
727 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000728#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
729 encode_sequence_maxsz + \
730 encode_putfh_maxsz + \
731 encode_secinfo_maxsz)
732#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
733 decode_sequence_maxsz + \
734 decode_putfh_maxsz + \
735 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400736#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400737#define NFS4_enc_bind_conn_to_session_sz \
738 (compound_encode_hdr_maxsz + \
739 encode_bind_conn_to_session_maxsz)
740#define NFS4_dec_bind_conn_to_session_sz \
741 (compound_decode_hdr_maxsz + \
742 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400743#define NFS4_enc_exchange_id_sz \
744 (compound_encode_hdr_maxsz + \
745 encode_exchange_id_maxsz)
746#define NFS4_dec_exchange_id_sz \
747 (compound_decode_hdr_maxsz + \
748 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400749#define NFS4_enc_create_session_sz \
750 (compound_encode_hdr_maxsz + \
751 encode_create_session_maxsz)
752#define NFS4_dec_create_session_sz \
753 (compound_decode_hdr_maxsz + \
754 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400755#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
756 encode_destroy_session_maxsz)
757#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
758 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400759#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
760 encode_destroy_clientid_maxsz)
761#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
762 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400763#define NFS4_enc_sequence_sz \
764 (compound_decode_hdr_maxsz + \
765 encode_sequence_maxsz)
766#define NFS4_dec_sequence_sz \
767 (compound_decode_hdr_maxsz + \
768 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400769#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
770 encode_sequence_maxsz + \
771 encode_putrootfh_maxsz + \
772 encode_fsinfo_maxsz)
773#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
774 decode_sequence_maxsz + \
775 decode_putrootfh_maxsz + \
776 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500777#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz + \
779 encode_reclaim_complete_maxsz)
780#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
781 decode_sequence_maxsz + \
782 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400783#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
784 encode_sequence_maxsz + \
785 encode_putfh_maxsz + \
786 encode_getdevicelist_maxsz)
787#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
788 decode_sequence_maxsz + \
789 decode_putfh_maxsz + \
790 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400791#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz +\
793 encode_getdeviceinfo_maxsz)
794#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
795 decode_sequence_maxsz + \
796 decode_getdeviceinfo_maxsz)
797#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_putfh_maxsz + \
800 encode_layoutget_maxsz)
801#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_putfh_maxsz + \
804 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000805#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz +\
807 encode_putfh_maxsz + \
808 encode_layoutcommit_maxsz + \
809 encode_getattr_maxsz)
810#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
811 decode_sequence_maxsz + \
812 decode_putfh_maxsz + \
813 decode_layoutcommit_maxsz + \
814 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300815#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
816 encode_sequence_maxsz + \
817 encode_putfh_maxsz + \
818 encode_layoutreturn_maxsz)
819#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
820 decode_sequence_maxsz + \
821 decode_putfh_maxsz + \
822 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400823#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
824 encode_sequence_maxsz + \
825 encode_putrootfh_maxsz +\
826 encode_secinfo_no_name_maxsz)
827#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
828 decode_sequence_maxsz + \
829 decode_putrootfh_maxsz + \
830 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400831#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
832 encode_sequence_maxsz + \
833 encode_test_stateid_maxsz)
834#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
835 decode_sequence_maxsz + \
836 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400837#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
838 encode_sequence_maxsz + \
839 encode_free_stateid_maxsz)
840#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
841 decode_sequence_maxsz + \
842 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500843
844const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
845 compound_encode_hdr_maxsz +
846 encode_sequence_maxsz +
847 encode_putfh_maxsz +
848 encode_getattr_maxsz) *
849 XDR_UNIT);
850
851const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
852 compound_decode_hdr_maxsz +
853 decode_sequence_maxsz +
854 decode_putfh_maxsz) *
855 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400856
857const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
858 compound_decode_hdr_maxsz +
859 decode_sequence_maxsz) *
860 XDR_UNIT);
861EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400862#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
Trond Myklebustbca79472009-03-11 14:10:26 -0400864static const umode_t nfs_type2fmt[] = {
865 [NF4BAD] = 0,
866 [NF4REG] = S_IFREG,
867 [NF4DIR] = S_IFDIR,
868 [NF4BLK] = S_IFBLK,
869 [NF4CHR] = S_IFCHR,
870 [NF4LNK] = S_IFLNK,
871 [NF4SOCK] = S_IFSOCK,
872 [NF4FIFO] = S_IFIFO,
873 [NF4ATTRDIR] = 0,
874 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875};
876
877struct compound_hdr {
878 int32_t status;
879 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500880 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 uint32_t taglen;
882 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400883 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400884 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885};
886
Benny Halevy13c65ce2009-08-14 17:19:25 +0300887static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
888{
889 __be32 *p = xdr_reserve_space(xdr, nbytes);
890 BUG_ON(!p);
891 return p;
892}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Trond Myklebustcb17e552012-03-04 18:13:56 -0500894static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
895{
896 __be32 *p;
897
898 p = xdr_reserve_space(xdr, len);
899 xdr_encode_opaque_fixed(p, buf, len);
900}
901
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
903{
Al Viro8687b632006-10-19 23:28:48 -0700904 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500906 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 xdr_encode_opaque(p, str, len);
908}
909
Trond Myklebust4ade9822012-03-04 18:13:57 -0500910static void encode_uint32(struct xdr_stream *xdr, u32 n)
911{
912 __be32 *p;
913
914 p = reserve_space(xdr, 4);
915 *p = cpu_to_be32(n);
916}
917
Trond Myklebustff2eb682012-03-05 11:40:12 -0500918static void encode_uint64(struct xdr_stream *xdr, u64 n)
919{
920 __be32 *p;
921
922 p = reserve_space(xdr, 8);
923 xdr_encode_hyper(p, n);
924}
925
Trond Myklebust4ade9822012-03-04 18:13:57 -0500926static void encode_nfs4_seqid(struct xdr_stream *xdr,
927 const struct nfs_seqid *seqid)
928{
929 encode_uint32(xdr, seqid->sequence->counter);
930}
931
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400932static void encode_compound_hdr(struct xdr_stream *xdr,
933 struct rpc_rqst *req,
934 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935{
Al Viro8687b632006-10-19 23:28:48 -0700936 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400937 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400938
939 /* initialize running count of expected bytes in reply.
940 * NOTE: the replied tag SHOULD be the same is the one sent,
941 * but this is not required as a MUST for the server to do so. */
942 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Trond Myklebust7fc38842012-10-15 11:51:21 -0400944 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500945 encode_string(xdr, hdr->taglen, hdr->tag);
946 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300947 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500948 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300949 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500950}
951
Trond Myklebustab19b482012-03-04 18:13:57 -0500952static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
953 uint32_t replen,
954 struct compound_hdr *hdr)
955{
956 encode_uint32(xdr, op);
957 hdr->nops++;
958 hdr->replen += replen;
959}
960
Andy Adamsond0179312008-12-23 16:06:17 -0500961static void encode_nops(struct compound_hdr *hdr)
962{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400963 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500964 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965}
966
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500967static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
968{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500969 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500970}
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
973{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500974 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975}
976
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500977static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
979 char owner_name[IDMAP_NAMESZ];
980 char owner_group[IDMAP_NAMESZ];
981 int owner_namelen = 0;
982 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700983 __be32 *p;
984 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 int len;
986 uint32_t bmval0 = 0;
987 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
989 /*
990 * We reserve enough space to write the entire attribute buffer at once.
991 * In the worst-case, this would be
992 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
993 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000994 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 */
996 len = 16;
997
998 /* Sigh */
999 if (iap->ia_valid & ATTR_SIZE)
1000 len += 8;
1001 if (iap->ia_valid & ATTR_MODE)
1002 len += 4;
1003 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001004 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001006 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001007 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 /* XXX */
1009 strcpy(owner_name, "nobody");
1010 owner_namelen = sizeof("nobody") - 1;
1011 /* goto out; */
1012 }
1013 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1014 }
1015 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001016 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001018 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001019 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 strcpy(owner_group, "nobody");
1021 owner_grouplen = sizeof("nobody") - 1;
1022 /* goto out; */
1023 }
1024 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1025 }
1026 if (iap->ia_valid & ATTR_ATIME_SET)
1027 len += 16;
1028 else if (iap->ia_valid & ATTR_ATIME)
1029 len += 4;
1030 if (iap->ia_valid & ATTR_MTIME_SET)
1031 len += 16;
1032 else if (iap->ia_valid & ATTR_MTIME)
1033 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001034 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
1036 /*
1037 * We write the bitmap length now, but leave the bitmap and the attribute
1038 * buffer length to be backfilled at the end of this routine.
1039 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001040 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 q = p;
1042 p += 3;
1043
1044 if (iap->ia_valid & ATTR_SIZE) {
1045 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001046 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 }
1048 if (iap->ia_valid & ATTR_MODE) {
1049 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001050 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 }
1052 if (iap->ia_valid & ATTR_UID) {
1053 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001054 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 }
1056 if (iap->ia_valid & ATTR_GID) {
1057 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001058 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 }
1060 if (iap->ia_valid & ATTR_ATIME_SET) {
1061 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001062 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Bryan Schumaker042ad0b2013-04-19 16:09:37 -04001063 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001064 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 }
1066 else if (iap->ia_valid & ATTR_ATIME) {
1067 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001068 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 }
1070 if (iap->ia_valid & ATTR_MTIME_SET) {
1071 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001072 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Bryan Schumaker042ad0b2013-04-19 16:09:37 -04001073 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001074 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
1076 else if (iap->ia_valid & ATTR_MTIME) {
1077 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001078 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001080
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 /*
1082 * Now we backfill the bitmap and the attribute buffer length.
1083 */
1084 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001085 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 len, ((char *)p - (char *)q) + 4);
1087 BUG();
1088 }
1089 len = (char *)p - (char *)q - 12;
1090 *q++ = htonl(bmval0);
1091 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001092 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095}
1096
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001097static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001099 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1100 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101}
1102
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001103static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
Trond Myklebustab19b482012-03-04 18:13:57 -05001105 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001106 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001107 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108}
1109
Fred Isaman0b7c0152012-04-20 14:47:39 -04001110static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
Al Viro8687b632006-10-19 23:28:48 -07001112 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001113
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001114 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1115 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001116 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001117 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001120static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
Al Viro8687b632006-10-19 23:28:48 -07001122 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001123
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001124 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1125 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
1127 switch (create->ftype) {
1128 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001129 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001130 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001131 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 break;
1133
1134 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001135 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001136 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001137 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 break;
1139
1140 default:
1141 break;
1142 }
1143
Benny Halevy811652b2009-08-14 17:19:34 +03001144 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001145 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001148static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Andy Adamson05d564f2008-12-23 16:06:15 -05001150 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001152 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1153 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001154 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001155 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156}
1157
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001158static 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 -07001159{
Andy Adamson05d564f2008-12-23 16:06:15 -05001160 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001162 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1163 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001164 *p++ = cpu_to_be32(2);
1165 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001166 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167}
1168
Fred Isamandae100c2011-07-30 20:52:37 -04001169static void
1170encode_getattr_three(struct xdr_stream *xdr,
1171 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1172 struct compound_hdr *hdr)
1173{
1174 __be32 *p;
1175
Trond Myklebustab19b482012-03-04 18:13:57 -05001176 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001177 if (bm2) {
1178 p = reserve_space(xdr, 16);
1179 *p++ = cpu_to_be32(3);
1180 *p++ = cpu_to_be32(bm0);
1181 *p++ = cpu_to_be32(bm1);
1182 *p = cpu_to_be32(bm2);
1183 } else if (bm1) {
1184 p = reserve_space(xdr, 12);
1185 *p++ = cpu_to_be32(2);
1186 *p++ = cpu_to_be32(bm0);
1187 *p = cpu_to_be32(bm1);
1188 } else {
1189 p = reserve_space(xdr, 8);
1190 *p++ = cpu_to_be32(1);
1191 *p = cpu_to_be32(bm0);
1192 }
Fred Isamandae100c2011-07-30 20:52:37 -04001193}
1194
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001195static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001197 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1198 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199}
1200
Andy Adamson88034c32012-05-23 05:02:34 -04001201static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001202 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001203 struct compound_hdr *hdr)
1204{
1205 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001206 bitmask[0] & open_bitmap[0],
1207 bitmask[1] & open_bitmap[1],
1208 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001209 hdr);
1210}
1211
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001212static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
Fred Isamandae100c2011-07-30 20:52:37 -04001214 encode_getattr_three(xdr,
1215 bitmask[0] & nfs4_fsinfo_bitmap[0],
1216 bitmask[1] & nfs4_fsinfo_bitmap[1],
1217 bitmask[2] & nfs4_fsinfo_bitmap[2],
1218 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219}
1220
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001221static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001222{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001223 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1224 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001225}
1226
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001227static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228{
Trond Myklebustab19b482012-03-04 18:13:57 -05001229 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230}
1231
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001232static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
Trond Myklebustab19b482012-03-04 18:13:57 -05001234 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001235 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236}
1237
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001238static inline int nfs4_lock_type(struct file_lock *fl, int block)
1239{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001240 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001241 return block ? NFS4_READW_LT : NFS4_READ_LT;
1242 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1243}
1244
1245static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1246{
1247 if (fl->fl_end == OFFSET_MAX)
1248 return ~(uint64_t)0;
1249 return fl->fl_end - fl->fl_start + 1;
1250}
1251
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001252static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1253{
1254 __be32 *p;
1255
Trond Myklebustd035c362010-12-21 10:45:27 -05001256 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001257 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001258 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001259 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001260 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001261 xdr_encode_hyper(p, lowner->id);
1262}
1263
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264/*
1265 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1266 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1267 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001268static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269{
Al Viro8687b632006-10-19 23:28:48 -07001270 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001272 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1273 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001274 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1275 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001276 p = xdr_encode_hyper(p, args->fl->fl_start);
1277 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001278 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001279 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001280 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001281 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001282 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001283 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 }
1285 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001286 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001287 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289}
1290
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001291static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
Al Viro8687b632006-10-19 23:28:48 -07001293 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001295 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1296 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001297 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001298 p = xdr_encode_hyper(p, args->fl->fl_start);
1299 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001300 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301}
1302
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001303static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304{
Al Viro8687b632006-10-19 23:28:48 -07001305 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001307 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1308 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001309 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001310 encode_nfs4_stateid(xdr, args->stateid);
1311 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001312 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001313 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314}
1315
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001316static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1317{
Trond Myklebustab19b482012-03-04 18:13:57 -05001318 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001319 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001320}
1321
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001322static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323{
Trond Myklebustab19b482012-03-04 18:13:57 -05001324 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001325 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001328static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329{
Al Viro8687b632006-10-19 23:28:48 -07001330 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Benny Halevy13c65ce2009-08-14 17:19:25 +03001332 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001333 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001334 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001335 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001336 break;
1337 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001338 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001339 break;
1340 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001341 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001342 break;
1343 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001344 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 }
Benny Halevy34558512009-08-14 17:19:30 +03001346 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
1349static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1350{
Al Viro8687b632006-10-19 23:28:48 -07001351 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 /*
1353 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1354 * owner 4 = 32
1355 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001356 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001357 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001358 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001359 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001360 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001361 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001362 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001363 *p++ = cpu_to_be32(arg->id.uniquifier);
1364 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365}
1366
1367static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1368{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001369 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001370 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Benny Halevy13c65ce2009-08-14 17:19:25 +03001372 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001373 switch(arg->createmode) {
1374 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001375 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001376 encode_attrs(xdr, arg->u.attrs, arg->server);
1377 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001378 case NFS4_CREATE_GUARDED:
1379 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1380 encode_attrs(xdr, arg->u.attrs, arg->server);
1381 break;
1382 case NFS4_CREATE_EXCLUSIVE:
1383 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1384 encode_nfs4_verifier(xdr, &arg->u.verifier);
1385 break;
1386 case NFS4_CREATE_EXCLUSIVE4_1:
1387 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1388 encode_nfs4_verifier(xdr, &arg->u.verifier);
1389 dummy.ia_valid = 0;
1390 encode_attrs(xdr, &dummy, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 }
1392}
1393
1394static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1395{
Al Viro8687b632006-10-19 23:28:48 -07001396 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Benny Halevy13c65ce2009-08-14 17:19:25 +03001398 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001400 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001401 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001402 break;
1403 default:
Benny Halevy34558512009-08-14 17:19:30 +03001404 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001405 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 }
1407}
1408
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001409static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410{
Al Viro8687b632006-10-19 23:28:48 -07001411 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
Benny Halevy13c65ce2009-08-14 17:19:25 +03001413 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001415 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001416 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001417 break;
1418 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001419 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001420 break;
1421 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001422 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001423 break;
1424 default:
1425 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 }
1427}
1428
1429static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1430{
Al Viro8687b632006-10-19 23:28:48 -07001431 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Benny Halevy13c65ce2009-08-14 17:19:25 +03001433 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001434 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 encode_string(xdr, name->len, name->name);
1436}
1437
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001438static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
Al Viro8687b632006-10-19 23:28:48 -07001440 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Benny Halevy13c65ce2009-08-14 17:19:25 +03001442 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001443 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 encode_delegation_type(xdr, type);
1445}
1446
1447static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1448{
Al Viro8687b632006-10-19 23:28:48 -07001449 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001451 p = reserve_space(xdr, 4);
1452 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1453 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 encode_string(xdr, name->len, name->name);
1455}
1456
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001457static inline void encode_claim_fh(struct xdr_stream *xdr)
1458{
1459 __be32 *p;
1460
1461 p = reserve_space(xdr, 4);
1462 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1463}
1464
1465static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1466{
1467 __be32 *p;
1468
1469 p = reserve_space(xdr, 4);
1470 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1471 encode_nfs4_stateid(xdr, stateid);
1472}
1473
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001474static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475{
Trond Myklebustab19b482012-03-04 18:13:57 -05001476 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 encode_openhdr(xdr, arg);
1478 encode_opentype(xdr, arg);
1479 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001480 case NFS4_OPEN_CLAIM_NULL:
1481 encode_claim_null(xdr, arg->name);
1482 break;
1483 case NFS4_OPEN_CLAIM_PREVIOUS:
1484 encode_claim_previous(xdr, arg->u.delegation_type);
1485 break;
1486 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1487 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1488 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001489 case NFS4_OPEN_CLAIM_FH:
1490 encode_claim_fh(xdr);
1491 break;
1492 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1493 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1494 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001495 default:
1496 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498}
1499
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001500static 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 -07001501{
Trond Myklebustab19b482012-03-04 18:13:57 -05001502 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001503 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001504 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Trond Myklebustab19b482012-03-04 18:13:57 -05001509 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001510 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001511 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001512 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513}
1514
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001515static void
Andy Adamsond0179312008-12-23 16:06:17 -05001516encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517{
Trond Myklebustab19b482012-03-04 18:13:57 -05001518 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001519 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520}
1521
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001522static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
Trond Myklebustab19b482012-03-04 18:13:57 -05001524 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
1526
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001527static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
Al Viro8687b632006-10-19 23:28:48 -07001529 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
Trond Myklebustab19b482012-03-04 18:13:57 -05001531 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001532 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Benny Halevy13c65ce2009-08-14 17:19:25 +03001534 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001535 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001536 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537}
1538
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001539static 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 -07001540{
Trond Myklebust28331a42011-04-27 13:47:52 -04001541 uint32_t attrs[2] = {
1542 FATTR4_WORD0_RDATTR_ERROR,
1543 FATTR4_WORD1_MOUNTED_ON_FILEID,
1544 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001545 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001546 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001548 if (readdir->plus) {
1549 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001550 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001551 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1552 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1553 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1554 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001555 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001556 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001557 /* Use mounted_on_fileid only if the server supports it */
1558 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1559 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001560
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001561 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001562 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001563 encode_nfs4_verifier(xdr, &readdir->verifier);
1564 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001565 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001566 *p++ = cpu_to_be32(readdir->count);
1567 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001568
Benny Halevye75bc1c2009-08-14 17:18:54 +03001569 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001570 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001571 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001572 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1573 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001574 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001575 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001576 attrs[0] & readdir->bitmask[0],
1577 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578}
1579
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001580static 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 -07001581{
Trond Myklebustab19b482012-03-04 18:13:57 -05001582 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583}
1584
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001585static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, 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_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001588 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589}
1590
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001591static 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 -07001592{
Trond Myklebustab19b482012-03-04 18:13:57 -05001593 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001594 encode_string(xdr, oldname->len, oldname->name);
1595 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596}
1597
Chuck Leverbb4dae52012-03-01 17:01:48 -05001598static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1599 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001601 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001602 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603}
1604
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001605static void
Andy Adamsond0179312008-12-23 16:06:17 -05001606encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001607{
Trond Myklebustab19b482012-03-04 18:13:57 -05001608 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001609}
1610
Chuck Lever9f06c712010-12-14 14:59:18 +00001611static void
Andy Adamsond0179312008-12-23 16:06:17 -05001612encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001613{
Al Viro8687b632006-10-19 23:28:48 -07001614 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001615
Trond Myklebustab19b482012-03-04 18:13:57 -05001616 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001617 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001618 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001619 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001620 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001621 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001622 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001623 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001624}
1625
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001626static void
Andy Adamsond0179312008-12-23 16:06:17 -05001627encode_savefh(struct xdr_stream *xdr, 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_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630}
1631
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001632static 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 -07001633{
Trond Myklebustab19b482012-03-04 18:13:57 -05001634 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001635 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001636 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637}
1638
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001639static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640{
Al Viro8687b632006-10-19 23:28:48 -07001641 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642
Trond Myklebust70019512012-03-04 20:49:32 -05001643 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001644 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
1646 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001647 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001648 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1650 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001651 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001652 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
1654
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001655static 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 -07001656{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001657 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1658 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001659 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001660 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661}
1662
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001663static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664{
Al Viro8687b632006-10-19 23:28:48 -07001665 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
Trond Myklebustab19b482012-03-04 18:13:57 -05001667 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001668 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
Benny Halevy13c65ce2009-08-14 17:19:25 +03001670 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001671 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001672 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001673 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
1675 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676}
1677
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001678static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679{
Trond Myklebustab19b482012-03-04 18:13:57 -05001680 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001681 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001683
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001684static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1685{
Trond Myklebustab19b482012-03-04 18:13:57 -05001686 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001687 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001688}
1689
Benny Halevy99fe60d2009-04-01 09:22:29 -04001690#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001691/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001692static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1693 struct nfs4_session *session,
1694 struct compound_hdr *hdr)
1695{
1696 __be32 *p;
1697
1698 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1699 decode_bind_conn_to_session_maxsz, hdr);
1700 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1701 p = xdr_reserve_space(xdr, 8);
1702 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1703 *p = 0; /* use_conn_in_rdma_mode = False */
1704}
1705
Benny Halevy99fe60d2009-04-01 09:22:29 -04001706static void encode_exchange_id(struct xdr_stream *xdr,
1707 struct nfs41_exchange_id_args *args,
1708 struct compound_hdr *hdr)
1709{
1710 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001711 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001712 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001713
Trond Myklebust70019512012-03-04 20:49:32 -05001714 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001715 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001716
1717 encode_string(xdr, args->id_len, args->id);
1718
Benny Halevy13c65ce2009-08-14 17:19:25 +03001719 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001720 *p++ = cpu_to_be32(args->flags);
1721 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001722
1723 if (send_implementation_id &&
1724 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1725 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001726 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001727 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1728 utsname()->sysname, utsname()->release,
1729 utsname()->version, utsname()->machine);
1730
1731 if (len > 0) {
1732 *p = cpu_to_be32(1); /* implementation id array length=1 */
1733
1734 encode_string(xdr,
1735 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1736 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1737 encode_string(xdr, len, impl_name);
1738 /* just send zeros for nii_date - the date is in nii_name */
1739 p = reserve_space(xdr, 12);
1740 p = xdr_encode_hyper(p, 0);
1741 *p = cpu_to_be32(0);
1742 } else
1743 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001744}
Andy Adamsonfc931582009-04-01 09:22:31 -04001745
1746static void encode_create_session(struct xdr_stream *xdr,
1747 struct nfs41_create_session_args *args,
1748 struct compound_hdr *hdr)
1749{
1750 __be32 *p;
1751 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1752 uint32_t len;
1753 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001754 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001755 u32 max_resp_sz_cached;
1756
1757 /*
1758 * Assumes OPEN is the biggest non-idempotent compound.
1759 * 2 is the verifier.
1760 */
1761 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1762 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001763
Andy Adamsonfc931582009-04-01 09:22:31 -04001764 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1765 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001766
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001767 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1768 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001769 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001770 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1771 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001772
Andy Adamsonfc931582009-04-01 09:22:31 -04001773 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001774 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001775 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1776 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001777 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001778 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1779 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1780 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001781
1782 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001783 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001784 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1785 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1786 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1787 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1788 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1789 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001790
Benny Halevye75bc1c2009-08-14 17:18:54 +03001791 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001792 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001793 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001794
1795 /* authsys_parms rfc1831 */
Chuck Leverf0920752012-05-21 22:45:41 -04001796 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001797 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001798 *p++ = cpu_to_be32(0); /* UID */
1799 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001800 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001801}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001802
1803static void encode_destroy_session(struct xdr_stream *xdr,
1804 struct nfs4_session *session,
1805 struct compound_hdr *hdr)
1806{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001807 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1808 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001809}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001810
Trond Myklebust66245532012-05-25 17:18:09 -04001811static void encode_destroy_clientid(struct xdr_stream *xdr,
1812 uint64_t clientid,
1813 struct compound_hdr *hdr)
1814{
1815 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1816 encode_uint64(xdr, clientid);
1817}
1818
Ricardo Labiaga180197532009-12-05 16:08:40 -05001819static void encode_reclaim_complete(struct xdr_stream *xdr,
1820 struct nfs41_reclaim_complete_args *args,
1821 struct compound_hdr *hdr)
1822{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001823 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1824 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001825}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001826#endif /* CONFIG_NFS_V4_1 */
1827
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001828static void encode_sequence(struct xdr_stream *xdr,
1829 const struct nfs4_sequence_args *args,
1830 struct compound_hdr *hdr)
1831{
1832#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001833 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001834 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001835 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001836 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001837
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001838 if (slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001839 return;
1840
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001841 tp = slot->table;
1842 session = tp->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001843
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001844 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001845
1846 /*
1847 * Sessionid + seqid + slotid + max slotid + cache_this
1848 */
1849 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1850 "max_slotid=%d cache_this=%d\n",
1851 __func__,
1852 ((u32 *)session->sess_id.data)[0],
1853 ((u32 *)session->sess_id.data)[1],
1854 ((u32 *)session->sess_id.data)[2],
1855 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001856 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001857 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001858 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001859 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001860 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001861 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001862 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001863 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001864#endif /* CONFIG_NFS_V4_1 */
1865}
1866
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001867#ifdef CONFIG_NFS_V4_1
1868static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001869encode_getdevicelist(struct xdr_stream *xdr,
1870 const struct nfs4_getdevicelist_args *args,
1871 struct compound_hdr *hdr)
1872{
1873 __be32 *p;
1874 nfs4_verifier dummy = {
1875 .data = "dummmmmy",
1876 };
1877
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001878 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1879 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001880 *p++ = cpu_to_be32(args->layoutclass);
1881 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1882 xdr_encode_hyper(p, 0ULL); /* cookie */
1883 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001884}
1885
1886static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001887encode_getdeviceinfo(struct xdr_stream *xdr,
1888 const struct nfs4_getdeviceinfo_args *args,
1889 struct compound_hdr *hdr)
1890{
1891 __be32 *p;
1892
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001893 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1894 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001895 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1896 NFS4_DEVICEID4_SIZE);
1897 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001898 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001899 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001900}
1901
1902static void
1903encode_layoutget(struct xdr_stream *xdr,
1904 const struct nfs4_layoutget_args *args,
1905 struct compound_hdr *hdr)
1906{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001907 __be32 *p;
1908
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001909 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1910 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001911 *p++ = cpu_to_be32(0); /* Signal layout available */
1912 *p++ = cpu_to_be32(args->type);
1913 *p++ = cpu_to_be32(args->range.iomode);
1914 p = xdr_encode_hyper(p, args->range.offset);
1915 p = xdr_encode_hyper(p, args->range.length);
1916 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001917 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001918 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001919
1920 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1921 __func__,
1922 args->type,
1923 args->range.iomode,
1924 (unsigned long)args->range.offset,
1925 (unsigned long)args->range.length,
1926 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001927}
Andy Adamson863a3c62011-03-23 13:27:54 +00001928
1929static int
1930encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001931 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001932 const struct nfs4_layoutcommit_args *args,
1933 struct compound_hdr *hdr)
1934{
1935 __be32 *p;
1936
1937 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1938 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1939
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001940 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1941 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001942 /* Only whole file layouts */
1943 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001944 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001945 *p = cpu_to_be32(0); /* reclaim */
1946 encode_nfs4_stateid(xdr, &args->stateid);
1947 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001948 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1949 p = xdr_encode_hyper(p, args->lastbytewritten);
1950 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1951 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001952
1953 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1954 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1955 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001956 else
1957 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001958
Andy Adamson863a3c62011-03-23 13:27:54 +00001959 return 0;
1960}
Benny Halevycbe82602011-05-22 19:52:37 +03001961
1962static void
1963encode_layoutreturn(struct xdr_stream *xdr,
1964 const struct nfs4_layoutreturn_args *args,
1965 struct compound_hdr *hdr)
1966{
1967 __be32 *p;
1968
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001969 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1970 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001971 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1972 *p++ = cpu_to_be32(args->layout_type);
1973 *p++ = cpu_to_be32(IOMODE_ANY);
1974 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001975 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001976 p = xdr_encode_hyper(p, 0);
1977 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1978 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001979 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001980 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001981 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1982 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1983 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001984 } else
1985 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001986}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001987
1988static int
1989encode_secinfo_no_name(struct xdr_stream *xdr,
1990 const struct nfs41_secinfo_no_name_args *args,
1991 struct compound_hdr *hdr)
1992{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001993 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1994 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001995 return 0;
1996}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001997
1998static void encode_test_stateid(struct xdr_stream *xdr,
1999 struct nfs41_test_stateid_args *args,
2000 struct compound_hdr *hdr)
2001{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002002 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2003 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002004 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002005}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002006
2007static void encode_free_stateid(struct xdr_stream *xdr,
2008 struct nfs41_free_stateid_args *args,
2009 struct compound_hdr *hdr)
2010{
Trond Myklebustab19b482012-03-04 18:13:57 -05002011 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002012 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002013}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002014#endif /* CONFIG_NFS_V4_1 */
2015
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016/*
2017 * END OF "GENERIC" ENCODE ROUTINES.
2018 */
2019
Benny Halevy66cc0422009-04-01 09:22:10 -04002020static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2021{
2022#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05002023
2024 if (args->sa_slot)
2025 return args->sa_slot->table->session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002026#endif /* CONFIG_NFS_V4_1 */
2027 return 0;
2028}
2029
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030/*
2031 * Encode an ACCESS request
2032 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002033static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2034 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002037 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039
Chuck Lever9f06c712010-12-14 14:59:18 +00002040 encode_compound_hdr(xdr, req, &hdr);
2041 encode_sequence(xdr, &args->seq_args, &hdr);
2042 encode_putfh(xdr, args->fh, &hdr);
2043 encode_access(xdr, args->access, &hdr);
2044 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002045 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046}
2047
2048/*
2049 * Encode LOOKUP request
2050 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002051static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2052 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002055 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
Chuck Lever9f06c712010-12-14 14:59:18 +00002058 encode_compound_hdr(xdr, req, &hdr);
2059 encode_sequence(xdr, &args->seq_args, &hdr);
2060 encode_putfh(xdr, args->dir_fh, &hdr);
2061 encode_lookup(xdr, args->name, &hdr);
2062 encode_getfh(xdr, &hdr);
2063 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002064 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065}
2066
2067/*
2068 * Encode LOOKUP_ROOT request
2069 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002070static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2071 struct xdr_stream *xdr,
2072 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002075 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
Chuck Lever9f06c712010-12-14 14:59:18 +00002078 encode_compound_hdr(xdr, req, &hdr);
2079 encode_sequence(xdr, &args->seq_args, &hdr);
2080 encode_putrootfh(xdr, &hdr);
2081 encode_getfh(xdr, &hdr);
2082 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002083 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084}
2085
2086/*
2087 * Encode REMOVE request
2088 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002089static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2090 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002093 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
Chuck Lever9f06c712010-12-14 14:59:18 +00002096 encode_compound_hdr(xdr, req, &hdr);
2097 encode_sequence(xdr, &args->seq_args, &hdr);
2098 encode_putfh(xdr, args->fh, &hdr);
2099 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002100 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101}
2102
2103/*
2104 * Encode RENAME request
2105 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002106static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2107 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002110 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
Chuck Lever9f06c712010-12-14 14:59:18 +00002113 encode_compound_hdr(xdr, req, &hdr);
2114 encode_sequence(xdr, &args->seq_args, &hdr);
2115 encode_putfh(xdr, args->old_dir, &hdr);
2116 encode_savefh(xdr, &hdr);
2117 encode_putfh(xdr, args->new_dir, &hdr);
2118 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002119 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120}
2121
2122/*
2123 * Encode LINK request
2124 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002125static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2126 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002129 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131
Chuck Lever9f06c712010-12-14 14:59:18 +00002132 encode_compound_hdr(xdr, req, &hdr);
2133 encode_sequence(xdr, &args->seq_args, &hdr);
2134 encode_putfh(xdr, args->fh, &hdr);
2135 encode_savefh(xdr, &hdr);
2136 encode_putfh(xdr, args->dir_fh, &hdr);
2137 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002138 encode_restorefh(xdr, &hdr);
2139 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002140 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141}
2142
2143/*
2144 * Encode CREATE request
2145 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002146static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2147 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002150 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
Chuck Lever9f06c712010-12-14 14:59:18 +00002153 encode_compound_hdr(xdr, req, &hdr);
2154 encode_sequence(xdr, &args->seq_args, &hdr);
2155 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002156 encode_create(xdr, args, &hdr);
2157 encode_getfh(xdr, &hdr);
2158 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002159 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160}
2161
2162/*
2163 * Encode SYMLINK request
2164 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002165static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2166 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167{
Chuck Lever9f06c712010-12-14 14:59:18 +00002168 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169}
2170
2171/*
2172 * Encode GETATTR request
2173 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002174static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2175 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002178 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180
Chuck Lever9f06c712010-12-14 14:59:18 +00002181 encode_compound_hdr(xdr, req, &hdr);
2182 encode_sequence(xdr, &args->seq_args, &hdr);
2183 encode_putfh(xdr, args->fh, &hdr);
2184 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002185 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
2188/*
2189 * Encode a CLOSE request
2190 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002191static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2192 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
Andy Adamson05d564f2008-12-23 16:06:15 -05002194 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002195 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002196 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
Chuck Lever9f06c712010-12-14 14:59:18 +00002198 encode_compound_hdr(xdr, req, &hdr);
2199 encode_sequence(xdr, &args->seq_args, &hdr);
2200 encode_putfh(xdr, args->fh, &hdr);
2201 encode_close(xdr, args, &hdr);
2202 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002203 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204}
2205
2206/*
2207 * Encode an OPEN request
2208 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002209static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2210 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002213 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
Chuck Lever9f06c712010-12-14 14:59:18 +00002216 encode_compound_hdr(xdr, req, &hdr);
2217 encode_sequence(xdr, &args->seq_args, &hdr);
2218 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002219 encode_open(xdr, args, &hdr);
2220 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002221 if (args->access)
2222 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002223 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002224 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225}
2226
2227/*
2228 * Encode an OPEN_CONFIRM request
2229 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002230static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2231 struct xdr_stream *xdr,
2232 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002235 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237
Chuck Lever9f06c712010-12-14 14:59:18 +00002238 encode_compound_hdr(xdr, req, &hdr);
2239 encode_putfh(xdr, args->fh, &hdr);
2240 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002241 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242}
2243
2244/*
2245 * Encode an OPEN request with no attributes.
2246 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002247static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2248 struct xdr_stream *xdr,
2249 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002252 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
Chuck Lever9f06c712010-12-14 14:59:18 +00002255 encode_compound_hdr(xdr, req, &hdr);
2256 encode_sequence(xdr, &args->seq_args, &hdr);
2257 encode_putfh(xdr, args->fh, &hdr);
2258 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002259 if (args->access)
2260 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002261 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002262 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263}
2264
2265/*
2266 * Encode an OPEN_DOWNGRADE request
2267 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002268static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2269 struct xdr_stream *xdr,
2270 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002273 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
Chuck Lever9f06c712010-12-14 14:59:18 +00002276 encode_compound_hdr(xdr, req, &hdr);
2277 encode_sequence(xdr, &args->seq_args, &hdr);
2278 encode_putfh(xdr, args->fh, &hdr);
2279 encode_open_downgrade(xdr, args, &hdr);
2280 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002281 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282}
2283
2284/*
2285 * Encode a LOCK request
2286 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002287static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2288 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002291 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293
Chuck Lever9f06c712010-12-14 14:59:18 +00002294 encode_compound_hdr(xdr, req, &hdr);
2295 encode_sequence(xdr, &args->seq_args, &hdr);
2296 encode_putfh(xdr, args->fh, &hdr);
2297 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002298 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299}
2300
2301/*
2302 * Encode a LOCKT request
2303 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002304static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2305 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002308 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Chuck Lever9f06c712010-12-14 14:59:18 +00002311 encode_compound_hdr(xdr, req, &hdr);
2312 encode_sequence(xdr, &args->seq_args, &hdr);
2313 encode_putfh(xdr, args->fh, &hdr);
2314 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002315 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316}
2317
2318/*
2319 * Encode a LOCKU request
2320 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002321static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2322 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002325 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
Chuck Lever9f06c712010-12-14 14:59:18 +00002328 encode_compound_hdr(xdr, req, &hdr);
2329 encode_sequence(xdr, &args->seq_args, &hdr);
2330 encode_putfh(xdr, args->fh, &hdr);
2331 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002332 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333}
2334
Chuck Lever9f06c712010-12-14 14:59:18 +00002335static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2336 struct xdr_stream *xdr,
2337 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002338{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002339 struct compound_hdr hdr = {
2340 .minorversion = 0,
2341 };
2342
Chuck Lever9f06c712010-12-14 14:59:18 +00002343 encode_compound_hdr(xdr, req, &hdr);
2344 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002345 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002346}
2347
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348/*
2349 * Encode a READLINK request
2350 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002351static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2352 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002355 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
Chuck Lever9f06c712010-12-14 14:59:18 +00002358 encode_compound_hdr(xdr, req, &hdr);
2359 encode_sequence(xdr, &args->seq_args, &hdr);
2360 encode_putfh(xdr, args->fh, &hdr);
2361 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002362
Benny Halevy28f56692009-04-01 09:22:09 -04002363 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002364 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002365 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366}
2367
2368/*
2369 * Encode a READDIR request
2370 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002371static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2372 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002375 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377
Chuck Lever9f06c712010-12-14 14:59:18 +00002378 encode_compound_hdr(xdr, req, &hdr);
2379 encode_sequence(xdr, &args->seq_args, &hdr);
2380 encode_putfh(xdr, args->fh, &hdr);
2381 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002382
Benny Halevy28f56692009-04-01 09:22:09 -04002383 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002384 args->pgbase, args->count);
2385 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002386 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002387 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002388 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389}
2390
2391/*
2392 * Encode a READ request
2393 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002394static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2395 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002398 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
Chuck Lever9f06c712010-12-14 14:59:18 +00002401 encode_compound_hdr(xdr, req, &hdr);
2402 encode_sequence(xdr, &args->seq_args, &hdr);
2403 encode_putfh(xdr, args->fh, &hdr);
2404 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
Benny Halevy28f56692009-04-01 09:22:09 -04002406 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002408 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002409 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410}
2411
2412/*
2413 * Encode an SETATTR request
2414 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002415static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2416 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417{
Andy Adamson05d564f2008-12-23 16:06:15 -05002418 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002419 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002420 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421
Chuck Lever9f06c712010-12-14 14:59:18 +00002422 encode_compound_hdr(xdr, req, &hdr);
2423 encode_sequence(xdr, &args->seq_args, &hdr);
2424 encode_putfh(xdr, args->fh, &hdr);
2425 encode_setattr(xdr, args, args->server, &hdr);
2426 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002427 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428}
2429
2430/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002431 * Encode a GETACL request
2432 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002433static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2434 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002435{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002436 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002437 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002438 };
Benny Halevy28f56692009-04-01 09:22:09 -04002439 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002440
Chuck Lever9f06c712010-12-14 14:59:18 +00002441 encode_compound_hdr(xdr, req, &hdr);
2442 encode_sequence(xdr, &args->seq_args, &hdr);
2443 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002444 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002445 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002446
Benny Halevy28f56692009-04-01 09:22:09 -04002447 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002448 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002449
Andy Adamsond0179312008-12-23 16:06:17 -05002450 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002451}
2452
2453/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 * Encode a WRITE request
2455 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002456static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2457 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002460 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462
Chuck Lever9f06c712010-12-14 14:59:18 +00002463 encode_compound_hdr(xdr, req, &hdr);
2464 encode_sequence(xdr, &args->seq_args, &hdr);
2465 encode_putfh(xdr, args->fh, &hdr);
2466 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002467 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002468 if (args->bitmask)
2469 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002470 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471}
2472
2473/*
2474 * a COMMIT request
2475 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002476static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002477 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002480 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482
Chuck Lever9f06c712010-12-14 14:59:18 +00002483 encode_compound_hdr(xdr, req, &hdr);
2484 encode_sequence(xdr, &args->seq_args, &hdr);
2485 encode_putfh(xdr, args->fh, &hdr);
2486 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002487 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488}
2489
2490/*
2491 * FSINFO request
2492 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002493static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2494 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002497 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499
Chuck Lever9f06c712010-12-14 14:59:18 +00002500 encode_compound_hdr(xdr, req, &hdr);
2501 encode_sequence(xdr, &args->seq_args, &hdr);
2502 encode_putfh(xdr, args->fh, &hdr);
2503 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002504 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505}
2506
2507/*
2508 * a PATHCONF request
2509 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002510static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2511 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002514 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516
Chuck Lever9f06c712010-12-14 14:59:18 +00002517 encode_compound_hdr(xdr, req, &hdr);
2518 encode_sequence(xdr, &args->seq_args, &hdr);
2519 encode_putfh(xdr, args->fh, &hdr);
2520 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002521 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002522 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523}
2524
2525/*
2526 * a STATFS request
2527 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002528static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2529 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002532 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
Chuck Lever9f06c712010-12-14 14:59:18 +00002535 encode_compound_hdr(xdr, req, &hdr);
2536 encode_sequence(xdr, &args->seq_args, &hdr);
2537 encode_putfh(xdr, args->fh, &hdr);
2538 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002539 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002540 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541}
2542
2543/*
2544 * GETATTR_BITMAP request
2545 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002546static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2547 struct xdr_stream *xdr,
2548 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002551 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
Chuck Lever9f06c712010-12-14 14:59:18 +00002554 encode_compound_hdr(xdr, req, &hdr);
2555 encode_sequence(xdr, &args->seq_args, &hdr);
2556 encode_putfh(xdr, args->fhandle, &hdr);
2557 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002558 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002559 FATTR4_WORD0_LINK_SUPPORT|
2560 FATTR4_WORD0_SYMLINK_SUPPORT|
2561 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002562 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563}
2564
2565/*
2566 * a RENEW request
2567 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002568static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2569 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002572 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 };
2574
Chuck Lever9f06c712010-12-14 14:59:18 +00002575 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002576 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002577 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578}
2579
2580/*
2581 * a SETCLIENTID request
2582 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002583static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2584 struct xdr_stream *xdr,
2585 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002588 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 };
2590
Chuck Lever9f06c712010-12-14 14:59:18 +00002591 encode_compound_hdr(xdr, req, &hdr);
2592 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002593 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594}
2595
2596/*
2597 * a SETCLIENTID_CONFIRM request
2598 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002599static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2600 struct xdr_stream *xdr,
2601 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002604 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606
Chuck Lever9f06c712010-12-14 14:59:18 +00002607 encode_compound_hdr(xdr, req, &hdr);
2608 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002609 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610}
2611
2612/*
2613 * DELEGRETURN request
2614 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002615static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2616 struct xdr_stream *xdr,
2617 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002620 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622
Chuck Lever9f06c712010-12-14 14:59:18 +00002623 encode_compound_hdr(xdr, req, &hdr);
2624 encode_sequence(xdr, &args->seq_args, &hdr);
2625 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002626 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002627 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002628 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629}
2630
2631/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002632 * Encode FS_LOCATIONS request
2633 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002634static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2635 struct xdr_stream *xdr,
2636 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002637{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002638 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002639 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002640 };
Benny Halevy28f56692009-04-01 09:22:09 -04002641 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002642
Chuck Lever9f06c712010-12-14 14:59:18 +00002643 encode_compound_hdr(xdr, req, &hdr);
2644 encode_sequence(xdr, &args->seq_args, &hdr);
2645 encode_putfh(xdr, args->dir_fh, &hdr);
2646 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002647 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002648 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002649
Benny Halevy28f56692009-04-01 09:22:09 -04002650 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002651 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002652 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002653}
2654
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002655/*
2656 * Encode SECINFO request
2657 */
2658static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2659 struct xdr_stream *xdr,
2660 struct nfs4_secinfo_arg *args)
2661{
2662 struct compound_hdr hdr = {
2663 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2664 };
2665
2666 encode_compound_hdr(xdr, req, &hdr);
2667 encode_sequence(xdr, &args->seq_args, &hdr);
2668 encode_putfh(xdr, args->dir_fh, &hdr);
2669 encode_secinfo(xdr, args->name, &hdr);
2670 encode_nops(&hdr);
2671}
2672
Benny Halevy99fe60d2009-04-01 09:22:29 -04002673#if defined(CONFIG_NFS_V4_1)
2674/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002675 * BIND_CONN_TO_SESSION request
2676 */
2677static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2678 struct xdr_stream *xdr,
2679 struct nfs_client *clp)
2680{
2681 struct compound_hdr hdr = {
2682 .minorversion = clp->cl_mvops->minor_version,
2683 };
2684
2685 encode_compound_hdr(xdr, req, &hdr);
2686 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2687 encode_nops(&hdr);
2688}
2689
2690/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002691 * EXCHANGE_ID request
2692 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002693static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2694 struct xdr_stream *xdr,
2695 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002696{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002697 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002698 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002699 };
2700
Chuck Lever9f06c712010-12-14 14:59:18 +00002701 encode_compound_hdr(xdr, req, &hdr);
2702 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002703 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002704}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002705
2706/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002707 * a CREATE_SESSION request
2708 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002709static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2710 struct xdr_stream *xdr,
2711 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002712{
Andy Adamsonfc931582009-04-01 09:22:31 -04002713 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002714 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002715 };
2716
Chuck Lever9f06c712010-12-14 14:59:18 +00002717 encode_compound_hdr(xdr, req, &hdr);
2718 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002719 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002720}
2721
2722/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002723 * a DESTROY_SESSION request
2724 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002725static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2726 struct xdr_stream *xdr,
2727 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002728{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002729 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002730 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002731 };
2732
Chuck Lever9f06c712010-12-14 14:59:18 +00002733 encode_compound_hdr(xdr, req, &hdr);
2734 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002735 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002736}
2737
2738/*
Trond Myklebust66245532012-05-25 17:18:09 -04002739 * a DESTROY_CLIENTID request
2740 */
2741static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2742 struct xdr_stream *xdr,
2743 struct nfs_client *clp)
2744{
2745 struct compound_hdr hdr = {
2746 .minorversion = clp->cl_mvops->minor_version,
2747 };
2748
2749 encode_compound_hdr(xdr, req, &hdr);
2750 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2751 encode_nops(&hdr);
2752}
2753
2754/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002755 * a SEQUENCE request
2756 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002757static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2758 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002759{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002760 struct compound_hdr hdr = {
2761 .minorversion = nfs4_xdr_minorversion(args),
2762 };
2763
Chuck Lever9f06c712010-12-14 14:59:18 +00002764 encode_compound_hdr(xdr, req, &hdr);
2765 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002766 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002767}
2768
2769/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002770 * a GET_LEASE_TIME request
2771 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002772static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2773 struct xdr_stream *xdr,
2774 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002775{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002776 struct compound_hdr hdr = {
2777 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2778 };
Fred Isamandae100c2011-07-30 20:52:37 -04002779 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002780
Chuck Lever9f06c712010-12-14 14:59:18 +00002781 encode_compound_hdr(xdr, req, &hdr);
2782 encode_sequence(xdr, &args->la_seq_args, &hdr);
2783 encode_putrootfh(xdr, &hdr);
2784 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002785 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002786}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002787
2788/*
2789 * a RECLAIM_COMPLETE request
2790 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002791static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2792 struct xdr_stream *xdr,
2793 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002794{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002795 struct compound_hdr hdr = {
2796 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2797 };
2798
Chuck Lever9f06c712010-12-14 14:59:18 +00002799 encode_compound_hdr(xdr, req, &hdr);
2800 encode_sequence(xdr, &args->seq_args, &hdr);
2801 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002802 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002803}
2804
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002805/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002806 * Encode GETDEVICELIST request
2807 */
2808static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2809 struct xdr_stream *xdr,
2810 struct nfs4_getdevicelist_args *args)
2811{
2812 struct compound_hdr hdr = {
2813 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2814 };
2815
2816 encode_compound_hdr(xdr, req, &hdr);
2817 encode_sequence(xdr, &args->seq_args, &hdr);
2818 encode_putfh(xdr, args->fh, &hdr);
2819 encode_getdevicelist(xdr, args, &hdr);
2820 encode_nops(&hdr);
2821}
2822
2823/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002824 * Encode GETDEVICEINFO request
2825 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002826static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2827 struct xdr_stream *xdr,
2828 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002829{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002830 struct compound_hdr hdr = {
2831 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2832 };
2833
Chuck Lever9f06c712010-12-14 14:59:18 +00002834 encode_compound_hdr(xdr, req, &hdr);
2835 encode_sequence(xdr, &args->seq_args, &hdr);
2836 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002837
2838 /* set up reply kvec. Subtract notification bitmap max size (2)
2839 * so that notification bitmap is put in xdr_buf tail */
2840 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2841 args->pdev->pages, args->pdev->pgbase,
2842 args->pdev->pglen);
2843
2844 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002845}
2846
2847/*
2848 * Encode LAYOUTGET request
2849 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002850static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2851 struct xdr_stream *xdr,
2852 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002853{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002854 struct compound_hdr hdr = {
2855 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2856 };
2857
Chuck Lever9f06c712010-12-14 14:59:18 +00002858 encode_compound_hdr(xdr, req, &hdr);
2859 encode_sequence(xdr, &args->seq_args, &hdr);
2860 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2861 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002862
2863 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2864 args->layout.pages, 0, args->layout.pglen);
2865
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002866 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002867}
Andy Adamson863a3c62011-03-23 13:27:54 +00002868
2869/*
2870 * Encode LAYOUTCOMMIT request
2871 */
Benny Halevycbe82602011-05-22 19:52:37 +03002872static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2873 struct xdr_stream *xdr,
2874 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002875{
Benny Halevyac7db722011-05-22 19:53:48 +03002876 struct nfs4_layoutcommit_data *data =
2877 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002878 struct compound_hdr hdr = {
2879 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2880 };
2881
2882 encode_compound_hdr(xdr, req, &hdr);
2883 encode_sequence(xdr, &args->seq_args, &hdr);
2884 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002885 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002886 encode_getfattr(xdr, args->bitmask, &hdr);
2887 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002888}
2889
2890/*
2891 * Encode LAYOUTRETURN request
2892 */
2893static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2894 struct xdr_stream *xdr,
2895 struct nfs4_layoutreturn_args *args)
2896{
2897 struct compound_hdr hdr = {
2898 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2899 };
2900
2901 encode_compound_hdr(xdr, req, &hdr);
2902 encode_sequence(xdr, &args->seq_args, &hdr);
2903 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2904 encode_layoutreturn(xdr, args, &hdr);
2905 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002906}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002907
2908/*
2909 * Encode SECINFO_NO_NAME request
2910 */
2911static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2912 struct xdr_stream *xdr,
2913 struct nfs41_secinfo_no_name_args *args)
2914{
2915 struct compound_hdr hdr = {
2916 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2917 };
2918
2919 encode_compound_hdr(xdr, req, &hdr);
2920 encode_sequence(xdr, &args->seq_args, &hdr);
2921 encode_putrootfh(xdr, &hdr);
2922 encode_secinfo_no_name(xdr, args, &hdr);
2923 encode_nops(&hdr);
2924 return 0;
2925}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002926
2927/*
2928 * Encode TEST_STATEID request
2929 */
2930static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2931 struct xdr_stream *xdr,
2932 struct nfs41_test_stateid_args *args)
2933{
2934 struct compound_hdr hdr = {
2935 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2936 };
2937
2938 encode_compound_hdr(xdr, req, &hdr);
2939 encode_sequence(xdr, &args->seq_args, &hdr);
2940 encode_test_stateid(xdr, args, &hdr);
2941 encode_nops(&hdr);
2942}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002943
2944/*
2945 * Encode FREE_STATEID request
2946 */
2947static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2948 struct xdr_stream *xdr,
2949 struct nfs41_free_stateid_args *args)
2950{
2951 struct compound_hdr hdr = {
2952 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2953 };
2954
2955 encode_compound_hdr(xdr, req, &hdr);
2956 encode_sequence(xdr, &args->seq_args, &hdr);
2957 encode_free_stateid(xdr, args, &hdr);
2958 encode_nops(&hdr);
2959}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002960#endif /* CONFIG_NFS_V4_1 */
2961
Benny Halevy686841b2009-08-14 17:19:48 +03002962static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2963{
2964 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2965 "Remaining buffer length is %tu words.\n",
2966 func, xdr->end - xdr->p);
2967}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
Trond Myklebust683b57b2006-06-09 09:34:22 -04002969static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970{
Al Viro8687b632006-10-19 23:28:48 -07002971 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972
Benny Halevyc0eae662009-08-14 17:20:14 +03002973 p = xdr_inline_decode(xdr, 4);
2974 if (unlikely(!p))
2975 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002976 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002977 p = xdr_inline_decode(xdr, *len);
2978 if (unlikely(!p))
2979 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 *string = (char *)p;
2981 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002982out_overflow:
2983 print_overflow_msg(__func__, xdr);
2984 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985}
2986
2987static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2988{
Al Viro8687b632006-10-19 23:28:48 -07002989 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
Benny Halevyc0eae662009-08-14 17:20:14 +03002991 p = xdr_inline_decode(xdr, 8);
2992 if (unlikely(!p))
2993 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002994 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002995 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002996
Benny Halevyc0eae662009-08-14 17:20:14 +03002997 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2998 if (unlikely(!p))
2999 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 hdr->tag = (char *)p;
3001 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003002 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003003 if (unlikely(hdr->nops < 1))
3004 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003006out_overflow:
3007 print_overflow_msg(__func__, xdr);
3008 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009}
3010
3011static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3012{
Al Viro8687b632006-10-19 23:28:48 -07003013 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 uint32_t opnum;
3015 int32_t nfserr;
3016
Benny Halevyc0eae662009-08-14 17:20:14 +03003017 p = xdr_inline_decode(xdr, 8);
3018 if (unlikely(!p))
3019 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003020 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003022 dprintk("nfs: Server returned operation"
3023 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 opnum, expected);
3025 return -EIO;
3026 }
Benny Halevycccddf42009-08-14 17:20:19 +03003027 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003029 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003031out_overflow:
3032 print_overflow_msg(__func__, xdr);
3033 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034}
3035
3036/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003037static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038{
Al Viro8687b632006-10-19 23:28:48 -07003039 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003040 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 char *str;
3042
Benny Halevyc0eae662009-08-14 17:20:14 +03003043 p = xdr_inline_decode(xdr, 12);
3044 if (likely(p))
3045 return decode_opaque_inline(xdr, &strlen, &str);
3046 print_overflow_msg(__func__, xdr);
3047 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048}
3049
3050static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3051{
Al Viro8687b632006-10-19 23:28:48 -07003052 uint32_t bmlen;
3053 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054
Benny Halevyc0eae662009-08-14 17:20:14 +03003055 p = xdr_inline_decode(xdr, 4);
3056 if (unlikely(!p))
3057 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003058 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059
Fred Isamandae100c2011-07-30 20:52:37 -04003060 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003061 p = xdr_inline_decode(xdr, (bmlen << 2));
3062 if (unlikely(!p))
3063 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003065 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003066 if (bmlen > 1) {
3067 bitmap[1] = be32_to_cpup(p++);
3068 if (bmlen > 2)
3069 bitmap[2] = be32_to_cpup(p);
3070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 }
3072 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003073out_overflow:
3074 print_overflow_msg(__func__, xdr);
3075 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076}
3077
Trond Myklebust256e48b2012-06-21 11:18:13 -04003078static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079{
Al Viro8687b632006-10-19 23:28:48 -07003080 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081
Benny Halevyc0eae662009-08-14 17:20:14 +03003082 p = xdr_inline_decode(xdr, 4);
3083 if (unlikely(!p))
3084 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003085 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003086 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003088out_overflow:
3089 print_overflow_msg(__func__, xdr);
3090 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091}
3092
3093static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3094{
3095 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003096 int ret;
3097 ret = decode_attr_bitmap(xdr, bitmask);
3098 if (unlikely(ret < 0))
3099 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3101 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003102 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3103 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3104 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 return 0;
3106}
3107
3108static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3109{
Al Viro8687b632006-10-19 23:28:48 -07003110 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003111 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112
3113 *type = 0;
3114 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3115 return -EIO;
3116 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003117 p = xdr_inline_decode(xdr, 4);
3118 if (unlikely(!p))
3119 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003120 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003122 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 return -EIO;
3124 }
3125 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003126 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003128 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003129 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003130out_overflow:
3131 print_overflow_msg(__func__, xdr);
3132 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133}
3134
Chuck Lever264e6352012-03-01 17:02:05 -05003135static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3136 uint32_t *bitmap, uint32_t *type)
3137{
3138 __be32 *p;
3139
3140 *type = 0;
3141 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3142 return -EIO;
3143 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3144 p = xdr_inline_decode(xdr, 4);
3145 if (unlikely(!p))
3146 goto out_overflow;
3147 *type = be32_to_cpup(p);
3148 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3149 }
3150 dprintk("%s: expire type=0x%x\n", __func__, *type);
3151 return 0;
3152out_overflow:
3153 print_overflow_msg(__func__, xdr);
3154 return -EIO;
3155}
3156
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3158{
Al Viro8687b632006-10-19 23:28:48 -07003159 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003160 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161
3162 *change = 0;
3163 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3164 return -EIO;
3165 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003166 p = xdr_inline_decode(xdr, 8);
3167 if (unlikely(!p))
3168 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003169 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003171 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003173 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003175 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003176out_overflow:
3177 print_overflow_msg(__func__, xdr);
3178 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179}
3180
3181static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3182{
Al Viro8687b632006-10-19 23:28:48 -07003183 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003184 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
3186 *size = 0;
3187 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3188 return -EIO;
3189 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003190 p = xdr_inline_decode(xdr, 8);
3191 if (unlikely(!p))
3192 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003193 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003195 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003197 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003198 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003199out_overflow:
3200 print_overflow_msg(__func__, xdr);
3201 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202}
3203
3204static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3205{
Al Viro8687b632006-10-19 23:28:48 -07003206 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207
3208 *res = 0;
3209 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3210 return -EIO;
3211 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003212 p = xdr_inline_decode(xdr, 4);
3213 if (unlikely(!p))
3214 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003215 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3217 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003218 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003220out_overflow:
3221 print_overflow_msg(__func__, xdr);
3222 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223}
3224
3225static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3226{
Al Viro8687b632006-10-19 23:28:48 -07003227 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228
3229 *res = 0;
3230 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3231 return -EIO;
3232 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003233 p = xdr_inline_decode(xdr, 4);
3234 if (unlikely(!p))
3235 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003236 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3238 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003239 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003241out_overflow:
3242 print_overflow_msg(__func__, xdr);
3243 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244}
3245
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003246static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247{
Al Viro8687b632006-10-19 23:28:48 -07003248 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003249 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250
3251 fsid->major = 0;
3252 fsid->minor = 0;
3253 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3254 return -EIO;
3255 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003256 p = xdr_inline_decode(xdr, 16);
3257 if (unlikely(!p))
3258 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003259 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003260 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003262 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003264 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 (unsigned long long)fsid->major,
3266 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003267 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003268out_overflow:
3269 print_overflow_msg(__func__, xdr);
3270 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271}
3272
3273static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3274{
Al Viro8687b632006-10-19 23:28:48 -07003275 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276
3277 *res = 60;
3278 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3279 return -EIO;
3280 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003281 p = xdr_inline_decode(xdr, 4);
3282 if (unlikely(!p))
3283 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003284 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3286 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003287 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003289out_overflow:
3290 print_overflow_msg(__func__, xdr);
3291 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292}
3293
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003294static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003295{
3296 __be32 *p;
3297
3298 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3299 return -EIO;
3300 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3301 p = xdr_inline_decode(xdr, 4);
3302 if (unlikely(!p))
3303 goto out_overflow;
3304 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003305 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003306 }
3307 return 0;
3308out_overflow:
3309 print_overflow_msg(__func__, xdr);
3310 return -EIO;
3311}
3312
3313static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3314{
3315 __be32 *p;
3316 int len;
3317
Trond Myklebust7ad07352010-10-23 15:34:20 -04003318 if (fh != NULL)
3319 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003320
3321 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3322 return -EIO;
3323 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3324 p = xdr_inline_decode(xdr, 4);
3325 if (unlikely(!p))
3326 goto out_overflow;
3327 len = be32_to_cpup(p);
3328 if (len > NFS4_FHSIZE)
3329 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003330 p = xdr_inline_decode(xdr, len);
3331 if (unlikely(!p))
3332 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003333 if (fh != NULL) {
3334 memcpy(fh->data, p, len);
3335 fh->size = len;
3336 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003337 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3338 }
3339 return 0;
3340out_overflow:
3341 print_overflow_msg(__func__, xdr);
3342 return -EIO;
3343}
3344
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3346{
Al Viro8687b632006-10-19 23:28:48 -07003347 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348
3349 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3350 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3351 return -EIO;
3352 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003353 p = xdr_inline_decode(xdr, 4);
3354 if (unlikely(!p))
3355 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003356 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3358 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003359 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003361out_overflow:
3362 print_overflow_msg(__func__, xdr);
3363 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364}
3365
3366static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3367{
Al Viro8687b632006-10-19 23:28:48 -07003368 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003369 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370
3371 *fileid = 0;
3372 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3373 return -EIO;
3374 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003375 p = xdr_inline_decode(xdr, 8);
3376 if (unlikely(!p))
3377 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003378 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003380 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003382 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003383 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003384out_overflow:
3385 print_overflow_msg(__func__, xdr);
3386 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387}
3388
Manoj Naik99baf622006-06-09 09:34:24 -04003389static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3390{
Al Viro8687b632006-10-19 23:28:48 -07003391 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003392 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003393
3394 *fileid = 0;
3395 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3396 return -EIO;
3397 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003398 p = xdr_inline_decode(xdr, 8);
3399 if (unlikely(!p))
3400 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003401 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003402 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003403 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003404 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003405 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003406 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003407out_overflow:
3408 print_overflow_msg(__func__, xdr);
3409 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003410}
3411
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3413{
Al Viro8687b632006-10-19 23:28:48 -07003414 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 int status = 0;
3416
3417 *res = 0;
3418 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3419 return -EIO;
3420 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003421 p = xdr_inline_decode(xdr, 8);
3422 if (unlikely(!p))
3423 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003424 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3426 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003427 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003429out_overflow:
3430 print_overflow_msg(__func__, xdr);
3431 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432}
3433
3434static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3435{
Al Viro8687b632006-10-19 23:28:48 -07003436 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 int status = 0;
3438
3439 *res = 0;
3440 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3441 return -EIO;
3442 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003443 p = xdr_inline_decode(xdr, 8);
3444 if (unlikely(!p))
3445 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003446 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3448 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003449 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003451out_overflow:
3452 print_overflow_msg(__func__, xdr);
3453 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454}
3455
3456static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3457{
Al Viro8687b632006-10-19 23:28:48 -07003458 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 int status = 0;
3460
3461 *res = 0;
3462 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3463 return -EIO;
3464 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003465 p = xdr_inline_decode(xdr, 8);
3466 if (unlikely(!p))
3467 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003468 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3470 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003471 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003473out_overflow:
3474 print_overflow_msg(__func__, xdr);
3475 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476}
3477
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003478static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3479{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003480 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003481 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003482 int status = 0;
3483
Benny Halevyc0eae662009-08-14 17:20:14 +03003484 p = xdr_inline_decode(xdr, 4);
3485 if (unlikely(!p))
3486 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003487 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003488 if (n == 0)
3489 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003490 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003491 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3492 dprintk("cannot parse %d components in path\n", n);
3493 goto out_eio;
3494 }
3495 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003496 struct nfs4_string *component = &path->components[path->ncomponents];
3497 status = decode_opaque_inline(xdr, &component->len, &component->data);
3498 if (unlikely(status != 0))
3499 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003500 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003501 pr_cont("%s%.*s ",
3502 (path->ncomponents != n ? "/ " : ""),
3503 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003504 }
3505out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003506 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003507root_path:
3508/* a root pathname is sent as a zero component4 */
3509 path->ncomponents = 1;
3510 path->components[0].len=0;
3511 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003512 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003513 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003514out_eio:
3515 dprintk(" status %d", status);
3516 status = -EIO;
3517 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003518out_overflow:
3519 print_overflow_msg(__func__, xdr);
3520 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003521}
3522
3523static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003524{
3525 int n;
Al Viro8687b632006-10-19 23:28:48 -07003526 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003527 int status = -EIO;
3528
3529 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3530 goto out;
3531 status = 0;
3532 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3533 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003534 status = -EIO;
3535 /* Ignore borken servers that return unrequested attrs */
3536 if (unlikely(res == NULL))
3537 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003538 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003539 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003540 if (unlikely(status != 0))
3541 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003542 p = xdr_inline_decode(xdr, 4);
3543 if (unlikely(!p))
3544 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003545 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003546 if (n <= 0)
3547 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003548 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003549 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003550 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003551
Trond Myklebust809b4262013-03-27 11:54:45 -04003552 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3553 break;
3554 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003555 p = xdr_inline_decode(xdr, 4);
3556 if (unlikely(!p))
3557 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003558 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003559
Chuck Lever02a29762012-03-01 17:00:31 -05003560 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003561 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3562 struct nfs4_string *server;
3563
3564 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003565 unsigned int i;
3566 dprintk("%s: using first %u of %u servers "
3567 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003568 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003569 NFS4_FS_LOCATION_MAXSERVERS,
3570 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003571 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003572 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003573 char *data;
3574 status = decode_opaque_inline(xdr, &len, &data);
3575 if (unlikely(status != 0))
3576 goto out_eio;
3577 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003578 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003579 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003580 server = &loc->servers[loc->nservers];
3581 status = decode_opaque_inline(xdr, &server->len, &server->data);
3582 if (unlikely(status != 0))
3583 goto out_eio;
3584 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003585 }
3586 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003587 if (unlikely(status != 0))
3588 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003589 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003590 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003591 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003592out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003593 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003594 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003595out_overflow:
3596 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003597out_eio:
3598 status = -EIO;
3599 goto out;
3600}
3601
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3603{
Al Viro8687b632006-10-19 23:28:48 -07003604 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 int status = 0;
3606
3607 *res = 0;
3608 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3609 return -EIO;
3610 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003611 p = xdr_inline_decode(xdr, 8);
3612 if (unlikely(!p))
3613 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003614 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3616 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003617 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003619out_overflow:
3620 print_overflow_msg(__func__, xdr);
3621 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622}
3623
3624static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3625{
Al Viro8687b632006-10-19 23:28:48 -07003626 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 int status = 0;
3628
3629 *maxlink = 1;
3630 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3631 return -EIO;
3632 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003633 p = xdr_inline_decode(xdr, 4);
3634 if (unlikely(!p))
3635 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003636 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3638 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003639 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003641out_overflow:
3642 print_overflow_msg(__func__, xdr);
3643 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644}
3645
3646static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3647{
Al Viro8687b632006-10-19 23:28:48 -07003648 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649 int status = 0;
3650
3651 *maxname = 1024;
3652 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3653 return -EIO;
3654 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003655 p = xdr_inline_decode(xdr, 4);
3656 if (unlikely(!p))
3657 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003658 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3660 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003661 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003663out_overflow:
3664 print_overflow_msg(__func__, xdr);
3665 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666}
3667
3668static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3669{
Al Viro8687b632006-10-19 23:28:48 -07003670 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 int status = 0;
3672
3673 *res = 1024;
3674 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3675 return -EIO;
3676 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3677 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003678 p = xdr_inline_decode(xdr, 8);
3679 if (unlikely(!p))
3680 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003681 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 if (maxread > 0x7FFFFFFF)
3683 maxread = 0x7FFFFFFF;
3684 *res = (uint32_t)maxread;
3685 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3686 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003687 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003689out_overflow:
3690 print_overflow_msg(__func__, xdr);
3691 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692}
3693
3694static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3695{
Al Viro8687b632006-10-19 23:28:48 -07003696 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 int status = 0;
3698
3699 *res = 1024;
3700 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3701 return -EIO;
3702 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3703 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003704 p = xdr_inline_decode(xdr, 8);
3705 if (unlikely(!p))
3706 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003707 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 if (maxwrite > 0x7FFFFFFF)
3709 maxwrite = 0x7FFFFFFF;
3710 *res = (uint32_t)maxwrite;
3711 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3712 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003713 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 return status;
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
Trond Myklebustbca79472009-03-11 14:10:26 -04003720static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721{
Trond Myklebustbca79472009-03-11 14:10:26 -04003722 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003723 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003724 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725
3726 *mode = 0;
3727 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3728 return -EIO;
3729 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003730 p = xdr_inline_decode(xdr, 4);
3731 if (unlikely(!p))
3732 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003733 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003734 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003736 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003738 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003739 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003740out_overflow:
3741 print_overflow_msg(__func__, xdr);
3742 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743}
3744
3745static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3746{
Al Viro8687b632006-10-19 23:28:48 -07003747 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003748 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749
3750 *nlink = 1;
3751 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3752 return -EIO;
3753 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003754 p = xdr_inline_decode(xdr, 4);
3755 if (unlikely(!p))
3756 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003757 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003759 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003761 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003762 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003763out_overflow:
3764 print_overflow_msg(__func__, xdr);
3765 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766}
3767
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003768static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003769 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003770 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771{
Al Viro8687b632006-10-19 23:28:48 -07003772 uint32_t len;
3773 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003774 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775
Eric W. Biedermane5782072013-02-01 14:22:02 -08003776 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3778 return -EIO;
3779 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003780 p = xdr_inline_decode(xdr, 4);
3781 if (unlikely(!p))
3782 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003783 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003784 p = xdr_inline_decode(xdr, len);
3785 if (unlikely(!p))
3786 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003787 if (owner_name != NULL) {
3788 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3789 if (owner_name->data != NULL) {
3790 owner_name->len = len;
3791 ret = NFS_ATTR_FATTR_OWNER_NAME;
3792 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003793 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003794 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003795 ret = NFS_ATTR_FATTR_OWNER;
3796 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003798 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003800 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003801 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3803 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003804 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003805 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003806out_overflow:
3807 print_overflow_msg(__func__, xdr);
3808 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809}
3810
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003811static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003812 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003813 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814{
Al Viro8687b632006-10-19 23:28:48 -07003815 uint32_t len;
3816 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003817 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818
Eric W. Biedermane5782072013-02-01 14:22:02 -08003819 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3821 return -EIO;
3822 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003823 p = xdr_inline_decode(xdr, 4);
3824 if (unlikely(!p))
3825 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003826 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003827 p = xdr_inline_decode(xdr, len);
3828 if (unlikely(!p))
3829 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003830 if (group_name != NULL) {
3831 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3832 if (group_name->data != NULL) {
3833 group_name->len = len;
3834 ret = NFS_ATTR_FATTR_GROUP_NAME;
3835 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003836 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003837 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003838 ret = NFS_ATTR_FATTR_GROUP;
3839 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003841 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003843 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003844 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3846 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003847 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003848 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003849out_overflow:
3850 print_overflow_msg(__func__, xdr);
3851 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852}
3853
3854static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3855{
Al Viro8687b632006-10-19 23:28:48 -07003856 uint32_t major = 0, minor = 0;
3857 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003858 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859
3860 *rdev = MKDEV(0,0);
3861 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3862 return -EIO;
3863 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3864 dev_t tmp;
3865
Benny Halevyc0eae662009-08-14 17:20:14 +03003866 p = xdr_inline_decode(xdr, 8);
3867 if (unlikely(!p))
3868 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003869 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003870 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 tmp = MKDEV(major, minor);
3872 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3873 *rdev = tmp;
3874 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003875 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003877 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003878 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003879out_overflow:
3880 print_overflow_msg(__func__, xdr);
3881 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882}
3883
3884static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3885{
Al Viro8687b632006-10-19 23:28:48 -07003886 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 int status = 0;
3888
3889 *res = 0;
3890 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3891 return -EIO;
3892 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003893 p = xdr_inline_decode(xdr, 8);
3894 if (unlikely(!p))
3895 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003896 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3898 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003899 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003901out_overflow:
3902 print_overflow_msg(__func__, xdr);
3903 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904}
3905
3906static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3907{
Al Viro8687b632006-10-19 23:28:48 -07003908 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 int status = 0;
3910
3911 *res = 0;
3912 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3913 return -EIO;
3914 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003915 p = xdr_inline_decode(xdr, 8);
3916 if (unlikely(!p))
3917 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003918 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3920 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003921 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003923out_overflow:
3924 print_overflow_msg(__func__, xdr);
3925 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926}
3927
3928static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3929{
Al Viro8687b632006-10-19 23:28:48 -07003930 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 int status = 0;
3932
3933 *res = 0;
3934 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3935 return -EIO;
3936 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003937 p = xdr_inline_decode(xdr, 8);
3938 if (unlikely(!p))
3939 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003940 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3942 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003943 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003945out_overflow:
3946 print_overflow_msg(__func__, xdr);
3947 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948}
3949
3950static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3951{
Al Viro8687b632006-10-19 23:28:48 -07003952 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003953 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954
3955 *used = 0;
3956 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3957 return -EIO;
3958 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003959 p = xdr_inline_decode(xdr, 8);
3960 if (unlikely(!p))
3961 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003962 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003964 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003966 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003968 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003969out_overflow:
3970 print_overflow_msg(__func__, xdr);
3971 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972}
3973
3974static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3975{
Al Viro8687b632006-10-19 23:28:48 -07003976 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977 uint64_t sec;
3978 uint32_t nsec;
3979
Benny Halevyc0eae662009-08-14 17:20:14 +03003980 p = xdr_inline_decode(xdr, 12);
3981 if (unlikely(!p))
3982 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003983 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003984 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 time->tv_sec = (time_t)sec;
3986 time->tv_nsec = (long)nsec;
3987 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003988out_overflow:
3989 print_overflow_msg(__func__, xdr);
3990 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991}
3992
3993static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3994{
3995 int status = 0;
3996
3997 time->tv_sec = 0;
3998 time->tv_nsec = 0;
3999 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4000 return -EIO;
4001 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4002 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004003 if (status == 0)
4004 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4006 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004007 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 return status;
4009}
4010
4011static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4012{
4013 int status = 0;
4014
4015 time->tv_sec = 0;
4016 time->tv_nsec = 0;
4017 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4018 return -EIO;
4019 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4020 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004021 if (status == 0)
4022 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4024 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004025 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026 return status;
4027}
4028
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004029static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4030 struct timespec *time)
4031{
4032 int status = 0;
4033
4034 time->tv_sec = 0;
4035 time->tv_nsec = 0;
4036 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4037 return -EIO;
4038 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4039 status = decode_attr_time(xdr, time);
4040 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4041 }
4042 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4043 (long)time->tv_nsec);
4044 return status;
4045}
4046
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4048{
4049 int status = 0;
4050
4051 time->tv_sec = 0;
4052 time->tv_nsec = 0;
4053 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4054 return -EIO;
4055 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4056 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004057 if (status == 0)
4058 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4060 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004061 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 return status;
4063}
4064
Trond Myklebust256e48b2012-06-21 11:18:13 -04004065static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066{
4067 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004068 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069
4070 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004071 dprintk("%s: server returned incorrect attribute length: "
4072 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004073 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 attrwords << 2,
4075 (attrwords < nwords) ? '<' : '>',
4076 nwords << 2);
4077 return -EIO;
4078 }
4079 return 0;
4080}
4081
4082static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4083{
Al Viro8687b632006-10-19 23:28:48 -07004084 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085
Benny Halevyc0eae662009-08-14 17:20:14 +03004086 p = xdr_inline_decode(xdr, 20);
4087 if (unlikely(!p))
4088 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004089 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004090 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004091 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004093out_overflow:
4094 print_overflow_msg(__func__, xdr);
4095 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096}
4097
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004098static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099{
Al Viro8687b632006-10-19 23:28:48 -07004100 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101 uint32_t supp, acc;
4102 int status;
4103
4104 status = decode_op_hdr(xdr, OP_ACCESS);
4105 if (status)
4106 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004107 p = xdr_inline_decode(xdr, 8);
4108 if (unlikely(!p))
4109 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004110 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004111 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004112 *supported = supp;
4113 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004115out_overflow:
4116 print_overflow_msg(__func__, xdr);
4117 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118}
4119
Benny Halevy07d30432009-08-14 17:19:52 +03004120static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121{
Al Viro8687b632006-10-19 23:28:48 -07004122 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004123
4124 p = xdr_inline_decode(xdr, len);
4125 if (likely(p)) {
4126 memcpy(buf, p, len);
4127 return 0;
4128 }
4129 print_overflow_msg(__func__, xdr);
4130 return -EIO;
4131}
4132
4133static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4134{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004135 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136}
4137
4138static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4139{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 int status;
4141
4142 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004143 if (status != -EIO)
4144 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004145 if (!status)
4146 status = decode_stateid(xdr, &res->stateid);
4147 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148}
4149
Benny Halevydb942bb2009-08-14 17:19:56 +03004150static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4151{
Chuck Levercd937102012-03-02 17:14:31 -05004152 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153}
4154
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004155static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4156{
4157 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4158}
4159
Fred Isaman0b7c0152012-04-20 14:47:39 -04004160static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162 int status;
4163
4164 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004165 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004166 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004167 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168}
4169
4170static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4171{
Al Viro8687b632006-10-19 23:28:48 -07004172 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 uint32_t bmlen;
4174 int status;
4175
4176 status = decode_op_hdr(xdr, OP_CREATE);
4177 if (status)
4178 return status;
4179 if ((status = decode_change_info(xdr, cinfo)))
4180 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004181 p = xdr_inline_decode(xdr, 4);
4182 if (unlikely(!p))
4183 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004184 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004185 p = xdr_inline_decode(xdr, bmlen << 2);
4186 if (likely(p))
4187 return 0;
4188out_overflow:
4189 print_overflow_msg(__func__, xdr);
4190 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191}
4192
4193static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4194{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004195 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004196 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197 int status;
4198
4199 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4200 goto xdr_error;
4201 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4202 goto xdr_error;
4203 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4204 goto xdr_error;
4205 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4206 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004207 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4208 &res->fh_expire_type)) != 0)
4209 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4211 goto xdr_error;
4212 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4213 goto xdr_error;
4214 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4215 goto xdr_error;
4216 status = verify_attr_len(xdr, savep, attrlen);
4217xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004218 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 return status;
4220}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004221
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4223{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004224 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004225 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004227
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4229 goto xdr_error;
4230 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4231 goto xdr_error;
4232 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4233 goto xdr_error;
4234
4235 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4236 goto xdr_error;
4237 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4238 goto xdr_error;
4239 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4240 goto xdr_error;
4241 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4242 goto xdr_error;
4243 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4244 goto xdr_error;
4245 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4246 goto xdr_error;
4247
4248 status = verify_attr_len(xdr, savep, attrlen);
4249xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004250 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251 return status;
4252}
4253
4254static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4255{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004256 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004257 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004259
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4261 goto xdr_error;
4262 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4263 goto xdr_error;
4264 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4265 goto xdr_error;
4266
4267 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4268 goto xdr_error;
4269 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4270 goto xdr_error;
4271
4272 status = verify_attr_len(xdr, savep, attrlen);
4273xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004274 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 return status;
4276}
4277
Andy Adamson88034c32012-05-23 05:02:34 -04004278static int decode_threshold_hint(struct xdr_stream *xdr,
4279 uint32_t *bitmap,
4280 uint64_t *res,
4281 uint32_t hint_bit)
4282{
4283 __be32 *p;
4284
4285 *res = 0;
4286 if (likely(bitmap[0] & hint_bit)) {
4287 p = xdr_inline_decode(xdr, 8);
4288 if (unlikely(!p))
4289 goto out_overflow;
4290 xdr_decode_hyper(p, res);
4291 }
4292 return 0;
4293out_overflow:
4294 print_overflow_msg(__func__, xdr);
4295 return -EIO;
4296}
4297
4298static int decode_first_threshold_item4(struct xdr_stream *xdr,
4299 struct nfs4_threshold *res)
4300{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004301 __be32 *p;
4302 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004303 uint32_t bitmap[3] = {0,}, attrlen;
4304 int status;
4305
4306 /* layout type */
4307 p = xdr_inline_decode(xdr, 4);
4308 if (unlikely(!p)) {
4309 print_overflow_msg(__func__, xdr);
4310 return -EIO;
4311 }
4312 res->l_type = be32_to_cpup(p);
4313
4314 /* thi_hintset bitmap */
4315 status = decode_attr_bitmap(xdr, bitmap);
4316 if (status < 0)
4317 goto xdr_error;
4318
4319 /* thi_hintlist length */
4320 status = decode_attr_length(xdr, &attrlen, &savep);
4321 if (status < 0)
4322 goto xdr_error;
4323 /* thi_hintlist */
4324 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4325 if (status < 0)
4326 goto xdr_error;
4327 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4328 if (status < 0)
4329 goto xdr_error;
4330 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4331 THRESHOLD_RD_IO);
4332 if (status < 0)
4333 goto xdr_error;
4334 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4335 THRESHOLD_WR_IO);
4336 if (status < 0)
4337 goto xdr_error;
4338
4339 status = verify_attr_len(xdr, savep, attrlen);
4340 res->bm = bitmap[0];
4341
4342 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4343 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4344 res->wr_io_sz);
4345xdr_error:
4346 dprintk("%s ret=%d!\n", __func__, status);
4347 return status;
4348}
4349
4350/*
4351 * Thresholds on pNFS direct I/O vrs MDS I/O
4352 */
4353static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4354 uint32_t *bitmap,
4355 struct nfs4_threshold *res)
4356{
4357 __be32 *p;
4358 int status = 0;
4359 uint32_t num;
4360
4361 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4362 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004363 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004364 /* Did the server return an unrequested attribute? */
4365 if (unlikely(res == NULL))
4366 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004367 p = xdr_inline_decode(xdr, 4);
4368 if (unlikely(!p))
4369 goto out_overflow;
4370 num = be32_to_cpup(p);
4371 if (num == 0)
4372 return 0;
4373 if (num > 1)
4374 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4375 "drivers per filesystem not supported\n",
4376 __func__);
4377
4378 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004379 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004380 }
4381 return status;
4382out_overflow:
4383 print_overflow_msg(__func__, xdr);
4384 return -EIO;
4385}
4386
Bryan Schumakerae42c702010-10-21 16:33:17 -04004387static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4388 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004389 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004390 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004391{
Trond Myklebustbca79472009-03-11 14:10:26 -04004392 int status;
4393 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004394 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004395 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004397 status = decode_attr_type(xdr, bitmap, &type);
4398 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004400 fattr->mode = 0;
4401 if (status != 0) {
4402 fattr->mode |= nfs_type2fmt[type];
4403 fattr->valid |= status;
4404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004406 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4407 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004409 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004410
4411 status = decode_attr_size(xdr, bitmap, &fattr->size);
4412 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004414 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004415
4416 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4417 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004419 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004420
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004421 err = 0;
4422 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004423 if (status < 0)
4424 goto xdr_error;
4425
4426 status = decode_attr_filehandle(xdr, bitmap, fh);
4427 if (status < 0)
4428 goto xdr_error;
4429
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004430 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4431 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004432 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004433 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004434
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004435 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004436 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004437 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004438 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004439
4440 status = decode_attr_mode(xdr, bitmap, &fmode);
4441 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004443 if (status != 0) {
4444 fattr->mode |= fmode;
4445 fattr->valid |= status;
4446 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004447
4448 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
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 Myklebust6926afd2012-01-07 13:22:46 -05004453 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004454 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004456 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004457
Trond Myklebust6926afd2012-01-07 13:22:46 -05004458 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004459 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004461 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004462
4463 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4464 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004466 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004467
4468 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4469 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004471 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004472
4473 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4474 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004476 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004477
4478 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4479 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004481 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004482
4483 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4484 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004486 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004487
Trond Myklebust28331a42011-04-27 13:47:52 -04004488 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004489 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004490 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004491 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004492
Andy Adamson88034c32012-05-23 05:02:34 -04004493 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4494 if (status < 0)
4495 goto xdr_error;
4496
Bryan Schumakerae42c702010-10-21 16:33:17 -04004497xdr_error:
4498 dprintk("%s: xdr returned %d\n", __func__, -status);
4499 return status;
4500}
4501
4502static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004503 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4504 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004505{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004506 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004507 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004508 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004509 int status;
4510
4511 status = decode_op_hdr(xdr, OP_GETATTR);
4512 if (status < 0)
4513 goto xdr_error;
4514
4515 status = decode_attr_bitmap(xdr, bitmap);
4516 if (status < 0)
4517 goto xdr_error;
4518
4519 status = decode_attr_length(xdr, &attrlen, &savep);
4520 if (status < 0)
4521 goto xdr_error;
4522
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004523 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004524 if (status < 0)
4525 goto xdr_error;
4526
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004527 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004529 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530 return status;
4531}
4532
Bryan Schumakerae42c702010-10-21 16:33:17 -04004533static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004534 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004535{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004536 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004537}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538
Andy Adamson504913f2010-10-20 00:17:57 -04004539/*
4540 * Decode potentially multiple layout types. Currently we only support
4541 * one layout driver per file system.
4542 */
4543static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4544 uint32_t *layouttype)
4545{
4546 uint32_t *p;
4547 int num;
4548
4549 p = xdr_inline_decode(xdr, 4);
4550 if (unlikely(!p))
4551 goto out_overflow;
4552 num = be32_to_cpup(p);
4553
4554 /* pNFS is not supported by the underlying file system */
4555 if (num == 0) {
4556 *layouttype = 0;
4557 return 0;
4558 }
4559 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004560 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4561 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004562
4563 /* Decode and set first layout type, move xdr->p past unused types */
4564 p = xdr_inline_decode(xdr, num * 4);
4565 if (unlikely(!p))
4566 goto out_overflow;
4567 *layouttype = be32_to_cpup(p);
4568 return 0;
4569out_overflow:
4570 print_overflow_msg(__func__, xdr);
4571 return -EIO;
4572}
4573
4574/*
4575 * The type of file system exported.
4576 * Note we must ensure that layouttype is set in any non-error case.
4577 */
4578static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4579 uint32_t *layouttype)
4580{
4581 int status = 0;
4582
4583 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4584 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4585 return -EIO;
4586 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4587 status = decode_first_pnfs_layout_type(xdr, layouttype);
4588 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4589 } else
4590 *layouttype = 0;
4591 return status;
4592}
4593
Fred Isamandae100c2011-07-30 20:52:37 -04004594/*
4595 * The prefered block size for layout directed io
4596 */
4597static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4598 uint32_t *res)
4599{
4600 __be32 *p;
4601
4602 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4603 *res = 0;
4604 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4605 p = xdr_inline_decode(xdr, 4);
4606 if (unlikely(!p)) {
4607 print_overflow_msg(__func__, xdr);
4608 return -EIO;
4609 }
4610 *res = be32_to_cpup(p);
4611 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4612 }
4613 return 0;
4614}
4615
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4617{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004618 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004619 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620 int status;
4621
4622 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4623 goto xdr_error;
4624 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4625 goto xdr_error;
4626 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4627 goto xdr_error;
4628
4629 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4630
4631 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4632 goto xdr_error;
4633 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4634 goto xdr_error;
4635 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4636 goto xdr_error;
4637 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4638 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4639 goto xdr_error;
4640 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004641 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4642 if (status != 0)
4643 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004644 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4645 if (status != 0)
4646 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004647 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4648 if (status)
4649 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650
4651 status = verify_attr_len(xdr, savep, attrlen);
4652xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004653 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 return status;
4655}
4656
4657static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4658{
Al Viro8687b632006-10-19 23:28:48 -07004659 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 uint32_t len;
4661 int status;
4662
Trond Myklebust99367812007-07-17 21:52:41 -04004663 /* Zero handle first to allow comparisons */
4664 memset(fh, 0, sizeof(*fh));
4665
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666 status = decode_op_hdr(xdr, OP_GETFH);
4667 if (status)
4668 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669
Benny Halevyc0eae662009-08-14 17:20:14 +03004670 p = xdr_inline_decode(xdr, 4);
4671 if (unlikely(!p))
4672 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004673 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 if (len > NFS4_FHSIZE)
4675 return -EIO;
4676 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004677 p = xdr_inline_decode(xdr, len);
4678 if (unlikely(!p))
4679 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004680 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004681 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004682out_overflow:
4683 print_overflow_msg(__func__, xdr);
4684 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685}
4686
4687static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4688{
4689 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004690
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691 status = decode_op_hdr(xdr, OP_LINK);
4692 if (status)
4693 return status;
4694 return decode_change_info(xdr, cinfo);
4695}
4696
4697/*
4698 * We create the owner, so we know a proper owner.id length is 4.
4699 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004700static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004702 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004703 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004704 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004706 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004707 if (unlikely(!p))
4708 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004709 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004710 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004711 type = be32_to_cpup(p++); /* 4 byte read */
4712 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004713 fl->fl_start = (loff_t)offset;
4714 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4715 if (length == ~(uint64_t)0)
4716 fl->fl_end = OFFSET_MAX;
4717 fl->fl_type = F_WRLCK;
4718 if (type & 1)
4719 fl->fl_type = F_RDLCK;
4720 fl->fl_pid = 0;
4721 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004722 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4723 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4724 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004725 if (likely(p))
4726 return -NFS4ERR_DENIED;
4727out_overflow:
4728 print_overflow_msg(__func__, xdr);
4729 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730}
4731
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004732static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734 int status;
4735
4736 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004737 if (status == -EIO)
4738 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004740 status = decode_stateid(xdr, &res->stateid);
4741 if (unlikely(status))
4742 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004744 status = decode_lock_denied(xdr, NULL);
4745 if (res->open_seqid != NULL)
4746 nfs_increment_open_seqid(status, res->open_seqid);
4747 nfs_increment_lock_seqid(status, res->lock_seqid);
4748out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 return status;
4750}
4751
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004752static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753{
4754 int status;
4755 status = decode_op_hdr(xdr, OP_LOCKT);
4756 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004757 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004758 return status;
4759}
4760
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004761static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763 int status;
4764
4765 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004766 if (status != -EIO)
4767 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004768 if (status == 0)
4769 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 return status;
4771}
4772
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004773static int decode_release_lockowner(struct xdr_stream *xdr)
4774{
4775 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4776}
4777
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778static int decode_lookup(struct xdr_stream *xdr)
4779{
4780 return decode_op_hdr(xdr, OP_LOOKUP);
4781}
4782
4783/* This is too sick! */
4784static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4785{
Andy Adamson05d564f2008-12-23 16:06:15 -05004786 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 uint32_t limit_type, nblocks, blocksize;
4788
Benny Halevyc0eae662009-08-14 17:20:14 +03004789 p = xdr_inline_decode(xdr, 12);
4790 if (unlikely(!p))
4791 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004792 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004794 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004795 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004796 break;
4797 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004798 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004799 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004800 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801 }
4802 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004803out_overflow:
4804 print_overflow_msg(__func__, xdr);
4805 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806}
4807
4808static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4809{
Andy Adamson05d564f2008-12-23 16:06:15 -05004810 __be32 *p;
4811 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004812 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813
Benny Halevyc0eae662009-08-14 17:20:14 +03004814 p = xdr_inline_decode(xdr, 4);
4815 if (unlikely(!p))
4816 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004817 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4819 res->delegation_type = 0;
4820 return 0;
4821 }
Benny Halevy07d30432009-08-14 17:19:52 +03004822 status = decode_stateid(xdr, &res->delegation);
4823 if (unlikely(status))
4824 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004825 p = xdr_inline_decode(xdr, 4);
4826 if (unlikely(!p))
4827 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004828 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004829
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004831 case NFS4_OPEN_DELEGATE_READ:
4832 res->delegation_type = FMODE_READ;
4833 break;
4834 case NFS4_OPEN_DELEGATE_WRITE:
4835 res->delegation_type = FMODE_WRITE|FMODE_READ;
4836 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837 return -EIO;
4838 }
David Howells7539bba2006-08-22 20:06:09 -04004839 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004840out_overflow:
4841 print_overflow_msg(__func__, xdr);
4842 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843}
4844
4845static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4846{
Andy Adamson05d564f2008-12-23 16:06:15 -05004847 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004848 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004849 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850
Andy Adamson05d564f2008-12-23 16:06:15 -05004851 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004852 if (status != -EIO)
4853 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004854 if (!status)
4855 status = decode_stateid(xdr, &res->stateid);
4856 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004857 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858
Andy Adamson05d564f2008-12-23 16:06:15 -05004859 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860
Benny Halevyc0eae662009-08-14 17:20:14 +03004861 p = xdr_inline_decode(xdr, 8);
4862 if (unlikely(!p))
4863 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004864 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004865 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004866 if (bmlen > 10)
4867 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868
Benny Halevyc0eae662009-08-14 17:20:14 +03004869 p = xdr_inline_decode(xdr, bmlen << 2);
4870 if (unlikely(!p))
4871 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004872 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4873 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004874 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004875 for (; i < NFS4_BITMAP_SIZE; i++)
4876 res->attrset[i] = 0;
4877
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 return decode_delegation(xdr, res);
4879xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004880 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004882out_overflow:
4883 print_overflow_msg(__func__, xdr);
4884 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885}
4886
4887static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4888{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 int status;
4890
Andy Adamson05d564f2008-12-23 16:06:15 -05004891 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004892 if (status != -EIO)
4893 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004894 if (!status)
4895 status = decode_stateid(xdr, &res->stateid);
4896 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897}
4898
4899static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4900{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 int status;
4902
4903 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004904 if (status != -EIO)
4905 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004906 if (!status)
4907 status = decode_stateid(xdr, &res->stateid);
4908 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004909}
4910
4911static int decode_putfh(struct xdr_stream *xdr)
4912{
4913 return decode_op_hdr(xdr, OP_PUTFH);
4914}
4915
4916static int decode_putrootfh(struct xdr_stream *xdr)
4917{
4918 return decode_op_hdr(xdr, OP_PUTROOTFH);
4919}
4920
4921static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4922{
Al Viro8687b632006-10-19 23:28:48 -07004923 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04004924 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925 int status;
4926
4927 status = decode_op_hdr(xdr, OP_READ);
4928 if (status)
4929 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004930 p = xdr_inline_decode(xdr, 8);
4931 if (unlikely(!p))
4932 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004933 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004934 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04004935 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004937 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938 "count %u > recvd %u\n", count, recvd);
4939 count = recvd;
4940 eof = 0;
4941 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942 res->eof = eof;
4943 res->count = count;
4944 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004945out_overflow:
4946 print_overflow_msg(__func__, xdr);
4947 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948}
4949
4950static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4951{
Chuck Leverbcecff72007-10-26 13:32:03 -04004952 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004953 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954
4955 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004956 if (!status)
4957 status = decode_verifier(xdr, readdir->verifier.data);
4958 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004960 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004961 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004962 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04004963 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964}
4965
4966static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4967{
4968 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04004969 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004970 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 int status;
4972
4973 status = decode_op_hdr(xdr, OP_READLINK);
4974 if (status)
4975 return status;
4976
4977 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004978 p = xdr_inline_decode(xdr, 4);
4979 if (unlikely(!p))
4980 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004981 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004983 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984 return -ENAMETOOLONG;
4985 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04004986 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004988 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989 "count %u > recvd %u\n", len, recvd);
4990 return -EIO;
4991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992 /*
4993 * The XDR encode routine has set things up so that
4994 * the link text will be copied directly into the
4995 * buffer. We just have to do overflow-checking,
4996 * and and null-terminate the text (the VFS expects
4997 * null-termination).
4998 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004999 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005001out_overflow:
5002 print_overflow_msg(__func__, xdr);
5003 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004}
5005
5006static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5007{
5008 int status;
5009
5010 status = decode_op_hdr(xdr, OP_REMOVE);
5011 if (status)
5012 goto out;
5013 status = decode_change_info(xdr, cinfo);
5014out:
5015 return status;
5016}
5017
5018static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5019 struct nfs4_change_info *new_cinfo)
5020{
5021 int status;
5022
5023 status = decode_op_hdr(xdr, OP_RENAME);
5024 if (status)
5025 goto out;
5026 if ((status = decode_change_info(xdr, old_cinfo)))
5027 goto out;
5028 status = decode_change_info(xdr, new_cinfo);
5029out:
5030 return status;
5031}
5032
5033static int decode_renew(struct xdr_stream *xdr)
5034{
5035 return decode_op_hdr(xdr, OP_RENEW);
5036}
5037
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005038static int
5039decode_restorefh(struct xdr_stream *xdr)
5040{
5041 return decode_op_hdr(xdr, OP_RESTOREFH);
5042}
5043
J. Bruce Fields029d1052005-06-22 17:16:22 +00005044static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005045 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005046{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005047 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005048 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005049 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005050 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005051 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005052
Andy Adamsonbf118a32011-12-07 11:55:27 -05005053 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005054 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5055 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005056
Trond Myklebust519d3952012-08-14 17:30:10 -04005057 xdr_enter_page(xdr, xdr->buf->page_len);
5058
Trond Myklebustcff298c2012-08-14 17:14:17 -04005059 /* Calculate the offset of the page data */
5060 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005061
J. Bruce Fields029d1052005-06-22 17:16:22 +00005062 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5063 goto out;
5064 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5065 goto out;
5066
5067 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5068 return -EIO;
5069 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005070
Andy Adamsonbf118a32011-12-07 11:55:27 -05005071 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5072 * are stored with the acl data to handle the problem of
5073 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005074 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005075 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005076
5077 /* Check for receive buffer overflow */
5078 if (res->acl_len > (xdr->nwords << 2) ||
5079 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5080 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005081 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005082 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005083 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005084 } else
5085 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005086
5087out:
5088 return status;
5089}
5090
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091static int
5092decode_savefh(struct xdr_stream *xdr)
5093{
5094 return decode_op_hdr(xdr, OP_SAVEFH);
5095}
5096
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005097static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098{
Al Viro8687b632006-10-19 23:28:48 -07005099 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100 uint32_t bmlen;
5101 int status;
5102
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103 status = decode_op_hdr(xdr, OP_SETATTR);
5104 if (status)
5105 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005106 p = xdr_inline_decode(xdr, 4);
5107 if (unlikely(!p))
5108 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005109 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005110 p = xdr_inline_decode(xdr, bmlen << 2);
5111 if (likely(p))
5112 return 0;
5113out_overflow:
5114 print_overflow_msg(__func__, xdr);
5115 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116}
5117
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005118static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119{
Al Viro8687b632006-10-19 23:28:48 -07005120 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005121 uint32_t opnum;
5122 int32_t nfserr;
5123
Benny Halevyc0eae662009-08-14 17:20:14 +03005124 p = xdr_inline_decode(xdr, 8);
5125 if (unlikely(!p))
5126 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005127 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005129 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005130 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131 return -EIO;
5132 }
Benny Halevycccddf42009-08-14 17:20:19 +03005133 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005135 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5136 if (unlikely(!p))
5137 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005138 p = xdr_decode_hyper(p, &res->clientid);
5139 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140 } else if (nfserr == NFSERR_CLID_INUSE) {
5141 uint32_t len;
5142
5143 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005144 p = xdr_inline_decode(xdr, 4);
5145 if (unlikely(!p))
5146 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005147 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005148 p = xdr_inline_decode(xdr, len);
5149 if (unlikely(!p))
5150 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151
5152 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005153 p = xdr_inline_decode(xdr, 4);
5154 if (unlikely(!p))
5155 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005156 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005157 p = xdr_inline_decode(xdr, len);
5158 if (unlikely(!p))
5159 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160 return -NFSERR_CLID_INUSE;
5161 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005162 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163
5164 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005165out_overflow:
5166 print_overflow_msg(__func__, xdr);
5167 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168}
5169
5170static int decode_setclientid_confirm(struct xdr_stream *xdr)
5171{
5172 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5173}
5174
5175static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5176{
Al Viro8687b632006-10-19 23:28:48 -07005177 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178 int status;
5179
5180 status = decode_op_hdr(xdr, OP_WRITE);
5181 if (status)
5182 return status;
5183
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005184 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005185 if (unlikely(!p))
5186 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005187 res->count = be32_to_cpup(p++);
5188 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005189 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005190out_overflow:
5191 print_overflow_msg(__func__, xdr);
5192 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005193}
5194
5195static int decode_delegreturn(struct xdr_stream *xdr)
5196{
5197 return decode_op_hdr(xdr, OP_DELEGRETURN);
5198}
5199
Chuck Leverfb15b262013-03-16 15:54:34 -04005200static int decode_secinfo_gss(struct xdr_stream *xdr,
5201 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005202{
Chuck Leverfb15b262013-03-16 15:54:34 -04005203 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005204 __be32 *p;
5205
5206 p = xdr_inline_decode(xdr, 4);
5207 if (unlikely(!p))
5208 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005209 oid_len = be32_to_cpup(p);
5210 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005211 goto out_err;
5212
Chuck Leverfb15b262013-03-16 15:54:34 -04005213 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005214 if (unlikely(!p))
5215 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005216 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5217 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005218
5219 p = xdr_inline_decode(xdr, 8);
5220 if (unlikely(!p))
5221 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005222 flavor->flavor_info.qop = be32_to_cpup(p++);
5223 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005224
5225 return 0;
5226
5227out_overflow:
5228 print_overflow_msg(__func__, xdr);
5229 return -EIO;
5230out_err:
5231 return -EINVAL;
5232}
5233
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005234static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005235{
Chuck Leverfb15b262013-03-16 15:54:34 -04005236 struct nfs4_secinfo4 *sec_flavor;
5237 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005238 int status;
5239 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005240
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005241 p = xdr_inline_decode(xdr, 4);
5242 if (unlikely(!p))
5243 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005244
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005245 res->flavors->num_flavors = 0;
5246 num_flavors = be32_to_cpup(p);
5247
5248 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005249 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005250 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005251 break;
5252
5253 p = xdr_inline_decode(xdr, 4);
5254 if (unlikely(!p))
5255 goto out_overflow;
5256 sec_flavor->flavor = be32_to_cpup(p);
5257
5258 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005259 status = decode_secinfo_gss(xdr, sec_flavor);
5260 if (status)
5261 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005262 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005263 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005264 }
5265
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005266 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005267out:
5268 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005269out_overflow:
5270 print_overflow_msg(__func__, xdr);
5271 return -EIO;
5272}
5273
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005274static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5275{
5276 int status = decode_op_hdr(xdr, OP_SECINFO);
5277 if (status)
5278 return status;
5279 return decode_secinfo_common(xdr, res);
5280}
5281
Benny Halevy99fe60d2009-04-01 09:22:29 -04005282#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005283static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5284{
5285 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5286 if (status)
5287 return status;
5288 return decode_secinfo_common(xdr, res);
5289}
5290
Benny Halevy99fe60d2009-04-01 09:22:29 -04005291static int decode_exchange_id(struct xdr_stream *xdr,
5292 struct nfs41_exchange_id_res *res)
5293{
5294 __be32 *p;
5295 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005296 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005297 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005298 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005299
5300 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5301 if (status)
5302 return status;
5303
Benny Halevyc0eae662009-08-14 17:20:14 +03005304 p = xdr_inline_decode(xdr, 8);
5305 if (unlikely(!p))
5306 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005307 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005308 p = xdr_inline_decode(xdr, 12);
5309 if (unlikely(!p))
5310 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005311 res->seqid = be32_to_cpup(p++);
5312 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005313
5314 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005315 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005316 if (dummy != SP4_NONE)
5317 return -EIO;
5318
Chuck Leveracdeb692012-05-21 22:46:16 -04005319 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005320 p = xdr_inline_decode(xdr, 8);
5321 if (unlikely(!p))
5322 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005323 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005324
Chuck Leveracdeb692012-05-21 22:46:16 -04005325 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005326 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5327 if (unlikely(status))
5328 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005329 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5330 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005331 memcpy(res->server_owner->major_id, dummy_str, dummy);
5332 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005333
Chuck Leveracdeb692012-05-21 22:46:16 -04005334 /* server_scope4 */
5335 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5336 if (unlikely(status))
5337 return status;
5338 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5339 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005340 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5341 res->server_scope->server_scope_sz = dummy;
5342
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005343 /* Implementation Id */
5344 p = xdr_inline_decode(xdr, 4);
5345 if (unlikely(!p))
5346 goto out_overflow;
5347 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005348
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005349 if (impl_id_count) {
5350 /* nii_domain */
5351 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5352 if (unlikely(status))
5353 return status;
5354 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5355 return -EIO;
5356 memcpy(res->impl_id->domain, dummy_str, dummy);
5357
5358 /* nii_name */
5359 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5360 if (unlikely(status))
5361 return status;
5362 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5363 return -EIO;
5364 memcpy(res->impl_id->name, dummy_str, dummy);
5365
5366 /* nii_date */
5367 p = xdr_inline_decode(xdr, 12);
5368 if (unlikely(!p))
5369 goto out_overflow;
5370 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5371 res->impl_id->date.nseconds = be32_to_cpup(p);
5372
5373 /* if there's more than one entry, ignore the rest */
5374 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005375 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005376out_overflow:
5377 print_overflow_msg(__func__, xdr);
5378 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005379}
Andy Adamsonfc931582009-04-01 09:22:31 -04005380
5381static int decode_chan_attrs(struct xdr_stream *xdr,
5382 struct nfs4_channel_attrs *attrs)
5383{
5384 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005385 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005386
Benny Halevyc0eae662009-08-14 17:20:14 +03005387 p = xdr_inline_decode(xdr, 28);
5388 if (unlikely(!p))
5389 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005390 val = be32_to_cpup(p++); /* headerpadsz */
5391 if (val)
5392 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005393 attrs->max_rqst_sz = be32_to_cpup(p++);
5394 attrs->max_resp_sz = be32_to_cpup(p++);
5395 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5396 attrs->max_ops = be32_to_cpup(p++);
5397 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005398 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005399 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005400 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5401 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005402 return -EINVAL;
5403 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005404 if (nr_attrs == 1) {
5405 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5406 if (unlikely(!p))
5407 goto out_overflow;
5408 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005409 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005410out_overflow:
5411 print_overflow_msg(__func__, xdr);
5412 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005413}
5414
Benny Halevye78291e2009-08-14 17:20:00 +03005415static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5416{
5417 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005418}
5419
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005420static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5421 struct nfs41_bind_conn_to_session_res *res)
5422{
5423 __be32 *p;
5424 int status;
5425
5426 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5427 if (!status)
5428 status = decode_sessionid(xdr, &res->session->sess_id);
5429 if (unlikely(status))
5430 return status;
5431
5432 /* dir flags, rdma mode bool */
5433 p = xdr_inline_decode(xdr, 8);
5434 if (unlikely(!p))
5435 goto out_overflow;
5436
5437 res->dir = be32_to_cpup(p++);
5438 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5439 return -EIO;
5440 if (be32_to_cpup(p) == 0)
5441 res->use_conn_in_rdma_mode = false;
5442 else
5443 res->use_conn_in_rdma_mode = true;
5444
5445 return 0;
5446out_overflow:
5447 print_overflow_msg(__func__, xdr);
5448 return -EIO;
5449}
5450
Andy Adamsonfc931582009-04-01 09:22:31 -04005451static int decode_create_session(struct xdr_stream *xdr,
5452 struct nfs41_create_session_res *res)
5453{
5454 __be32 *p;
5455 int status;
5456 struct nfs_client *clp = res->client;
5457 struct nfs4_session *session = clp->cl_session;
5458
5459 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005460 if (!status)
5461 status = decode_sessionid(xdr, &session->sess_id);
5462 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005463 return status;
5464
Andy Adamsonfc931582009-04-01 09:22:31 -04005465 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005466 p = xdr_inline_decode(xdr, 8);
5467 if (unlikely(!p))
5468 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005469 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005470 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005471
5472 /* Channel attributes */
5473 status = decode_chan_attrs(xdr, &session->fc_attrs);
5474 if (!status)
5475 status = decode_chan_attrs(xdr, &session->bc_attrs);
5476 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005477out_overflow:
5478 print_overflow_msg(__func__, xdr);
5479 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005480}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005481
5482static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5483{
5484 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5485}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005486
Trond Myklebust66245532012-05-25 17:18:09 -04005487static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5488{
5489 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5490}
5491
Ricardo Labiaga180197532009-12-05 16:08:40 -05005492static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5493{
5494 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5495}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005496#endif /* CONFIG_NFS_V4_1 */
5497
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005498static int decode_sequence(struct xdr_stream *xdr,
5499 struct nfs4_sequence_res *res,
5500 struct rpc_rqst *rqstp)
5501{
5502#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005503 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005504 struct nfs4_sessionid id;
5505 u32 dummy;
5506 int status;
5507 __be32 *p;
5508
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005509 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005510 return 0;
5511
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005512 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005513 if (!status)
5514 status = decode_sessionid(xdr, &id);
5515 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005516 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005517
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005518 /*
5519 * If the server returns different values for sessionID, slotID or
5520 * sequence number, the server is looney tunes.
5521 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005522 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005523 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005524
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005525 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005526 NFS4_MAX_SESSIONID_LEN)) {
5527 dprintk("%s Invalid session id\n", __func__);
5528 goto out_err;
5529 }
Benny Halevye78291e2009-08-14 17:20:00 +03005530
Benny Halevyc0eae662009-08-14 17:20:14 +03005531 p = xdr_inline_decode(xdr, 20);
5532 if (unlikely(!p))
5533 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005534
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005535 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005536 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005537 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005538 dprintk("%s Invalid sequence number\n", __func__);
5539 goto out_err;
5540 }
5541 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005542 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005543 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005544 dprintk("%s Invalid slot id\n", __func__);
5545 goto out_err;
5546 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005547 /* highest slot id */
5548 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005549 /* target highest slot id */
5550 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005551 /* result flags */
5552 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005553 status = 0;
5554out_err:
5555 res->sr_status = status;
5556 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005557out_overflow:
5558 print_overflow_msg(__func__, xdr);
5559 status = -EIO;
5560 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005561#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005562 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005563#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005564}
5565
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005566#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005567/*
5568 * TODO: Need to handle case when EOF != true;
5569 */
5570static int decode_getdevicelist(struct xdr_stream *xdr,
5571 struct pnfs_devicelist *res)
5572{
5573 __be32 *p;
5574 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005575 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005576
5577 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5578 if (status)
5579 return status;
5580
5581 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5582 if (unlikely(!p))
5583 goto out_overflow;
5584
5585 /* TODO: Skip cookie for now */
5586 p += 2;
5587
5588 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005589 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005590
5591 res->num_devs = be32_to_cpup(p);
5592
5593 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5594
5595 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005596 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005597 __func__, res->num_devs);
5598 return -EIO;
5599 }
5600
5601 p = xdr_inline_decode(xdr,
5602 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5603 if (unlikely(!p))
5604 goto out_overflow;
5605 for (i = 0; i < res->num_devs; i++)
5606 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5607 NFS4_DEVICEID4_SIZE);
5608 res->eof = be32_to_cpup(p);
5609 return 0;
5610out_overflow:
5611 print_overflow_msg(__func__, xdr);
5612 return -EIO;
5613}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005614
5615static int decode_getdeviceinfo(struct xdr_stream *xdr,
5616 struct pnfs_device *pdev)
5617{
5618 __be32 *p;
5619 uint32_t len, type;
5620 int status;
5621
5622 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5623 if (status) {
5624 if (status == -ETOOSMALL) {
5625 p = xdr_inline_decode(xdr, 4);
5626 if (unlikely(!p))
5627 goto out_overflow;
5628 pdev->mincount = be32_to_cpup(p);
5629 dprintk("%s: Min count too small. mincnt = %u\n",
5630 __func__, pdev->mincount);
5631 }
5632 return status;
5633 }
5634
5635 p = xdr_inline_decode(xdr, 8);
5636 if (unlikely(!p))
5637 goto out_overflow;
5638 type = be32_to_cpup(p++);
5639 if (type != pdev->layout_type) {
5640 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5641 __func__, pdev->layout_type, type);
5642 return -EINVAL;
5643 }
5644 /*
5645 * Get the length of the opaque device_addr4. xdr_read_pages places
5646 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5647 * and places the remaining xdr data in xdr_buf->tail
5648 */
5649 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005650 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5651 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005652
5653 /* Parse notification bitmap, verifying that it is zero. */
5654 p = xdr_inline_decode(xdr, 4);
5655 if (unlikely(!p))
5656 goto out_overflow;
5657 len = be32_to_cpup(p);
5658 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005659 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005660
5661 p = xdr_inline_decode(xdr, 4 * len);
5662 if (unlikely(!p))
5663 goto out_overflow;
5664 for (i = 0; i < len; i++, p++) {
5665 if (be32_to_cpup(p)) {
5666 dprintk("%s: notifications not supported\n",
5667 __func__);
5668 return -EIO;
5669 }
5670 }
5671 }
5672 return 0;
5673out_overflow:
5674 print_overflow_msg(__func__, xdr);
5675 return -EIO;
5676}
5677
5678static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5679 struct nfs4_layoutget_res *res)
5680{
5681 __be32 *p;
5682 int status;
5683 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005684 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005685
5686 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5687 if (status)
5688 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005689 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005690 if (unlikely(!p))
5691 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005692 res->return_on_close = be32_to_cpup(p);
5693 decode_stateid(xdr, &res->stateid);
5694 p = xdr_inline_decode(xdr, 4);
5695 if (unlikely(!p))
5696 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005697 layout_count = be32_to_cpup(p);
5698 if (!layout_count) {
5699 dprintk("%s: server responded with empty layout array\n",
5700 __func__);
5701 return -EINVAL;
5702 }
5703
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005704 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005705 if (unlikely(!p))
5706 goto out_overflow;
5707 p = xdr_decode_hyper(p, &res->range.offset);
5708 p = xdr_decode_hyper(p, &res->range.length);
5709 res->range.iomode = be32_to_cpup(p++);
5710 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005711 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005712
5713 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5714 __func__,
5715 (unsigned long)res->range.offset,
5716 (unsigned long)res->range.length,
5717 res->range.iomode,
5718 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005719 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005720
Trond Myklebust64bd5772012-06-20 22:35:05 -04005721 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005722 if (res->layoutp->len > recvd) {
5723 dprintk("NFS: server cheating in layoutget reply: "
5724 "layout len %u > recvd %u\n",
5725 res->layoutp->len, recvd);
5726 return -EINVAL;
5727 }
5728
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005729 if (layout_count > 1) {
5730 /* We only handle a length one array at the moment. Any
5731 * further entries are just ignored. Note that this means
5732 * the client may see a response that is less than the
5733 * minimum it requested.
5734 */
5735 dprintk("%s: server responded with %d layouts, dropping tail\n",
5736 __func__, layout_count);
5737 }
5738
5739 return 0;
5740out_overflow:
5741 print_overflow_msg(__func__, xdr);
5742 return -EIO;
5743}
Andy Adamson863a3c62011-03-23 13:27:54 +00005744
Benny Halevycbe82602011-05-22 19:52:37 +03005745static int decode_layoutreturn(struct xdr_stream *xdr,
5746 struct nfs4_layoutreturn_res *res)
5747{
5748 __be32 *p;
5749 int status;
5750
5751 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5752 if (status)
5753 return status;
5754 p = xdr_inline_decode(xdr, 4);
5755 if (unlikely(!p))
5756 goto out_overflow;
5757 res->lrs_present = be32_to_cpup(p);
5758 if (res->lrs_present)
5759 status = decode_stateid(xdr, &res->stateid);
5760 return status;
5761out_overflow:
5762 print_overflow_msg(__func__, xdr);
5763 return -EIO;
5764}
5765
Andy Adamson863a3c62011-03-23 13:27:54 +00005766static int decode_layoutcommit(struct xdr_stream *xdr,
5767 struct rpc_rqst *req,
5768 struct nfs4_layoutcommit_res *res)
5769{
5770 __be32 *p;
5771 __u32 sizechanged;
5772 int status;
5773
5774 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005775 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005776 if (status)
5777 return status;
5778
5779 p = xdr_inline_decode(xdr, 4);
5780 if (unlikely(!p))
5781 goto out_overflow;
5782 sizechanged = be32_to_cpup(p);
5783
5784 if (sizechanged) {
5785 /* throw away new size */
5786 p = xdr_inline_decode(xdr, 8);
5787 if (unlikely(!p))
5788 goto out_overflow;
5789 }
5790 return 0;
5791out_overflow:
5792 print_overflow_msg(__func__, xdr);
5793 return -EIO;
5794}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005795
5796static int decode_test_stateid(struct xdr_stream *xdr,
5797 struct nfs41_test_stateid_res *res)
5798{
5799 __be32 *p;
5800 int status;
5801 int num_res;
5802
5803 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5804 if (status)
5805 return status;
5806
5807 p = xdr_inline_decode(xdr, 4);
5808 if (unlikely(!p))
5809 goto out_overflow;
5810 num_res = be32_to_cpup(p++);
5811 if (num_res != 1)
5812 goto out;
5813
5814 p = xdr_inline_decode(xdr, 4);
5815 if (unlikely(!p))
5816 goto out_overflow;
5817 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005818
5819 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005820out_overflow:
5821 print_overflow_msg(__func__, xdr);
5822out:
5823 return -EIO;
5824}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005825
5826static int decode_free_stateid(struct xdr_stream *xdr,
5827 struct nfs41_free_stateid_res *res)
5828{
5829 __be32 *p;
5830 int status;
5831
5832 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5833 if (status)
5834 return status;
5835
5836 p = xdr_inline_decode(xdr, 4);
5837 if (unlikely(!p))
5838 goto out_overflow;
5839 res->status = be32_to_cpup(p++);
5840 return res->status;
5841out_overflow:
5842 print_overflow_msg(__func__, xdr);
5843 return -EIO;
5844}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005845#endif /* CONFIG_NFS_V4_1 */
5846
Linus Torvalds1da177e2005-04-16 15:20:36 -07005847/*
Benny Halevy49c25592008-12-23 16:06:16 -05005848 * END OF "GENERIC" DECODE ROUTINES.
5849 */
5850
5851/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852 * Decode OPEN_DOWNGRADE response
5853 */
Chuck Leverbf269552010-12-14 14:59:29 +00005854static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5855 struct xdr_stream *xdr,
5856 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857{
Andy Adamson05d564f2008-12-23 16:06:15 -05005858 struct compound_hdr hdr;
5859 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005860
Chuck Leverbf269552010-12-14 14:59:29 +00005861 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005862 if (status)
5863 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005864 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005865 if (status)
5866 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005867 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005868 if (status)
5869 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005870 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005871 if (status != 0)
5872 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005873 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005874out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005875 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005876}
5877
5878/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879 * Decode ACCESS response
5880 */
Chuck Leverbf269552010-12-14 14:59:29 +00005881static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5882 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005883{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005884 struct compound_hdr hdr;
5885 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005886
Chuck Leverbf269552010-12-14 14:59:29 +00005887 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005888 if (status)
5889 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005890 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005891 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005893 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005894 if (status != 0)
5895 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04005896 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04005897 if (status != 0)
5898 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005899 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005900out:
5901 return status;
5902}
5903
5904/*
5905 * Decode LOOKUP response
5906 */
Chuck Leverbf269552010-12-14 14:59:29 +00005907static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5908 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005910 struct compound_hdr hdr;
5911 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005912
Chuck Leverbf269552010-12-14 14:59:29 +00005913 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005914 if (status)
5915 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005916 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005917 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005918 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005919 status = decode_putfh(xdr);
5920 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005921 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005922 status = decode_lookup(xdr);
5923 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005925 status = decode_getfh(xdr, res->fh);
5926 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005928 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929out:
5930 return status;
5931}
5932
5933/*
5934 * Decode LOOKUP_ROOT response
5935 */
Chuck Leverbf269552010-12-14 14:59:29 +00005936static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5937 struct xdr_stream *xdr,
5938 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005939{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940 struct compound_hdr hdr;
5941 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005942
Chuck Leverbf269552010-12-14 14:59:29 +00005943 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005944 if (status)
5945 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005946 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005947 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005949 status = decode_putrootfh(xdr);
5950 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005952 status = decode_getfh(xdr, res->fh);
5953 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005954 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005955out:
5956 return status;
5957}
5958
5959/*
5960 * Decode REMOVE response
5961 */
Chuck Leverbf269552010-12-14 14:59:29 +00005962static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5963 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005964{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005965 struct compound_hdr hdr;
5966 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005967
Chuck Leverbf269552010-12-14 14:59:29 +00005968 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005969 if (status)
5970 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005971 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005972 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005973 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005974 status = decode_putfh(xdr);
5975 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005976 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005977 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005978out:
5979 return status;
5980}
5981
5982/*
5983 * Decode RENAME response
5984 */
Chuck Leverbf269552010-12-14 14:59:29 +00005985static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5986 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005988 struct compound_hdr hdr;
5989 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005990
Chuck Leverbf269552010-12-14 14:59:29 +00005991 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005992 if (status)
5993 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005994 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005995 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005996 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005997 status = decode_putfh(xdr);
5998 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006000 status = decode_savefh(xdr);
6001 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006003 status = decode_putfh(xdr);
6004 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006005 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006006 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007out:
6008 return status;
6009}
6010
6011/*
6012 * Decode LINK response
6013 */
Chuck Leverbf269552010-12-14 14:59:29 +00006014static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6015 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006016{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006017 struct compound_hdr hdr;
6018 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006019
Chuck Leverbf269552010-12-14 14:59:29 +00006020 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006021 if (status)
6022 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006023 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006024 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006025 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006026 status = decode_putfh(xdr);
6027 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006028 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006029 status = decode_savefh(xdr);
6030 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006031 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006032 status = decode_putfh(xdr);
6033 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006035 status = decode_link(xdr, &res->cinfo);
6036 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006037 goto out;
6038 /*
6039 * Note order: OP_LINK leaves the directory as the current
6040 * filehandle.
6041 */
Chuck Leverbf269552010-12-14 14:59:29 +00006042 status = decode_restorefh(xdr);
6043 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006044 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006045 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046out:
6047 return status;
6048}
6049
6050/*
6051 * Decode CREATE response
6052 */
Chuck Leverbf269552010-12-14 14:59:29 +00006053static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6054 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056 struct compound_hdr hdr;
6057 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006058
Chuck Leverbf269552010-12-14 14:59:29 +00006059 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006060 if (status)
6061 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006062 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006063 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006064 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006065 status = decode_putfh(xdr);
6066 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006068 status = decode_create(xdr, &res->dir_cinfo);
6069 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006071 status = decode_getfh(xdr, res->fh);
6072 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073 goto out;
Trond Myklebust7c317fc2012-04-27 13:48:18 -04006074 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006075out:
6076 return status;
6077}
6078
6079/*
6080 * Decode SYMLINK response
6081 */
Chuck Leverbf269552010-12-14 14:59:29 +00006082static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6083 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006084{
Chuck Leverbf269552010-12-14 14:59:29 +00006085 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086}
6087
6088/*
6089 * Decode GETATTR response
6090 */
Chuck Leverbf269552010-12-14 14:59:29 +00006091static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6092 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006093{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094 struct compound_hdr hdr;
6095 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006096
Chuck Leverbf269552010-12-14 14:59:29 +00006097 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098 if (status)
6099 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006100 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006101 if (status)
6102 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006103 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104 if (status)
6105 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006106 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107out:
6108 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109}
6110
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006111/*
6112 * Encode an SETACL request
6113 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006114static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6115 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006116{
Andy Adamson05d564f2008-12-23 16:06:15 -05006117 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006118 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006119 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006120
Chuck Lever9f06c712010-12-14 14:59:18 +00006121 encode_compound_hdr(xdr, req, &hdr);
6122 encode_sequence(xdr, &args->seq_args, &hdr);
6123 encode_putfh(xdr, args->fh, &hdr);
6124 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006125 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006126}
Andy Adamson05d564f2008-12-23 16:06:15 -05006127
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006128/*
6129 * Decode SETACL response
6130 */
6131static int
Chuck Leverbf269552010-12-14 14:59:29 +00006132nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006133 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006134{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006135 struct compound_hdr hdr;
6136 int status;
6137
Chuck Leverbf269552010-12-14 14:59:29 +00006138 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006139 if (status)
6140 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006141 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006142 if (status)
6143 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006144 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006145 if (status)
6146 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006147 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006148out:
6149 return status;
6150}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151
6152/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006153 * Decode GETACL response
6154 */
6155static int
Chuck Leverbf269552010-12-14 14:59:29 +00006156nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006157 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006158{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006159 struct compound_hdr hdr;
6160 int status;
6161
Trond Myklebust331818f2012-02-03 18:30:53 -05006162 if (res->acl_scratch != NULL) {
6163 void *p = page_address(res->acl_scratch);
6164 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6165 }
Chuck Leverbf269552010-12-14 14:59:29 +00006166 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006167 if (status)
6168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006170 if (status)
6171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006172 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006173 if (status)
6174 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006175 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006176
6177out:
6178 return status;
6179}
6180
6181/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182 * Decode CLOSE response
6183 */
Chuck Leverbf269552010-12-14 14:59:29 +00006184static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6185 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186{
Andy Adamson05d564f2008-12-23 16:06:15 -05006187 struct compound_hdr hdr;
6188 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189
Chuck Leverbf269552010-12-14 14:59:29 +00006190 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006191 if (status)
6192 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006193 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006194 if (status)
6195 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006196 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006197 if (status)
6198 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006199 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006200 if (status != 0)
6201 goto out;
6202 /*
6203 * Note: Server may do delete on close for this file
6204 * in which case the getattr call will fail with
6205 * an ESTALE error. Shouldn't be a problem,
6206 * though, since fattr->valid will remain unset.
6207 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006208 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006210 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211}
6212
6213/*
6214 * Decode OPEN response
6215 */
Chuck Leverbf269552010-12-14 14:59:29 +00006216static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6217 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218{
Andy Adamson05d564f2008-12-23 16:06:15 -05006219 struct compound_hdr hdr;
6220 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221
Chuck Leverbf269552010-12-14 14:59:29 +00006222 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006223 if (status)
6224 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006225 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006226 if (status)
6227 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006228 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006229 if (status)
6230 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006231 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006232 if (status)
6233 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006234 status = decode_getfh(xdr, &res->fh);
6235 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006237 if (res->access_request)
6238 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust90ff0c52012-04-27 13:48:18 -04006239 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006241 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242}
6243
6244/*
6245 * Decode OPEN_CONFIRM response
6246 */
Chuck Leverbf269552010-12-14 14:59:29 +00006247static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6248 struct xdr_stream *xdr,
6249 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250{
Andy Adamson05d564f2008-12-23 16:06:15 -05006251 struct compound_hdr hdr;
6252 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253
Chuck Leverbf269552010-12-14 14:59:29 +00006254 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006255 if (status)
6256 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006257 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006258 if (status)
6259 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006260 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006262 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263}
6264
6265/*
6266 * Decode OPEN response
6267 */
Chuck Leverbf269552010-12-14 14:59:29 +00006268static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6269 struct xdr_stream *xdr,
6270 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271{
Andy Adamson05d564f2008-12-23 16:06:15 -05006272 struct compound_hdr hdr;
6273 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006274
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006276 if (status)
6277 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006278 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006279 if (status)
6280 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006281 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006282 if (status)
6283 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006285 if (status)
6286 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006287 if (res->access_request)
6288 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006289 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006291 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006292}
6293
6294/*
6295 * Decode SETATTR response
6296 */
Chuck Leverbf269552010-12-14 14:59:29 +00006297static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6298 struct xdr_stream *xdr,
6299 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300{
Andy Adamson05d564f2008-12-23 16:06:15 -05006301 struct compound_hdr hdr;
6302 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303
Chuck Leverbf269552010-12-14 14:59:29 +00006304 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006305 if (status)
6306 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006308 if (status)
6309 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006311 if (status)
6312 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006314 if (status)
6315 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006316 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006318 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319}
6320
6321/*
6322 * Decode LOCK response
6323 */
Chuck Leverbf269552010-12-14 14:59:29 +00006324static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6325 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006326{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327 struct compound_hdr hdr;
6328 int status;
6329
Chuck Leverbf269552010-12-14 14:59:29 +00006330 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331 if (status)
6332 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006333 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006334 if (status)
6335 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006336 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337 if (status)
6338 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006339 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340out:
6341 return status;
6342}
6343
6344/*
6345 * Decode LOCKT response
6346 */
Chuck Leverbf269552010-12-14 14:59:29 +00006347static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6348 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350 struct compound_hdr hdr;
6351 int status;
6352
Chuck Leverbf269552010-12-14 14:59:29 +00006353 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354 if (status)
6355 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006356 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006357 if (status)
6358 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006359 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006360 if (status)
6361 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006362 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363out:
6364 return status;
6365}
6366
6367/*
6368 * Decode LOCKU response
6369 */
Chuck Leverbf269552010-12-14 14:59:29 +00006370static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6371 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373 struct compound_hdr hdr;
6374 int status;
6375
Chuck Leverbf269552010-12-14 14:59:29 +00006376 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377 if (status)
6378 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006379 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006380 if (status)
6381 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006382 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006383 if (status)
6384 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386out:
6387 return status;
6388}
6389
Chuck Leverbf269552010-12-14 14:59:29 +00006390static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6391 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006392{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006393 struct compound_hdr hdr;
6394 int status;
6395
Chuck Leverbf269552010-12-14 14:59:29 +00006396 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006397 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006398 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006399 return status;
6400}
6401
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402/*
6403 * Decode READLINK response
6404 */
Chuck Leverbf269552010-12-14 14:59:29 +00006405static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6406 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006407 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006409 struct compound_hdr hdr;
6410 int status;
6411
Chuck Leverbf269552010-12-14 14:59:29 +00006412 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006413 if (status)
6414 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006415 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006416 if (status)
6417 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006418 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006419 if (status)
6420 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006421 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006422out:
6423 return status;
6424}
6425
6426/*
6427 * Decode READDIR response
6428 */
Chuck Leverbf269552010-12-14 14:59:29 +00006429static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6430 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006432 struct compound_hdr hdr;
6433 int status;
6434
Chuck Leverbf269552010-12-14 14:59:29 +00006435 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436 if (status)
6437 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006438 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006439 if (status)
6440 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006441 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442 if (status)
6443 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006444 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006445out:
6446 return status;
6447}
6448
6449/*
6450 * Decode Read response
6451 */
Chuck Leverbf269552010-12-14 14:59:29 +00006452static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6453 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006455 struct compound_hdr hdr;
6456 int status;
6457
Chuck Leverbf269552010-12-14 14:59:29 +00006458 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459 if (status)
6460 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006461 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006462 if (status)
6463 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006464 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465 if (status)
6466 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006467 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468 if (!status)
6469 status = res->count;
6470out:
6471 return status;
6472}
6473
6474/*
6475 * Decode WRITE response
6476 */
Chuck Leverbf269552010-12-14 14:59:29 +00006477static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6478 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480 struct compound_hdr hdr;
6481 int status;
6482
Chuck Leverbf269552010-12-14 14:59:29 +00006483 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484 if (status)
6485 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006487 if (status)
6488 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006489 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490 if (status)
6491 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006493 if (status)
6494 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006495 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006496 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497 if (!status)
6498 status = res->count;
6499out:
6500 return status;
6501}
6502
6503/*
6504 * Decode COMMIT response
6505 */
Chuck Leverbf269552010-12-14 14:59:29 +00006506static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006507 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006509 struct compound_hdr hdr;
6510 int status;
6511
Chuck Leverbf269552010-12-14 14:59:29 +00006512 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513 if (status)
6514 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006515 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006516 if (status)
6517 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006518 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519 if (status)
6520 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006521 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006522out:
6523 return status;
6524}
6525
6526/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006527 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006528 */
Chuck Leverbf269552010-12-14 14:59:29 +00006529static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006530 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006531{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532 struct compound_hdr hdr;
6533 int status;
6534
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006537 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006538 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006539 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006540 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006541 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006542 return status;
6543}
6544
6545/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006546 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547 */
Chuck Leverbf269552010-12-14 14:59:29 +00006548static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006549 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551 struct compound_hdr hdr;
6552 int status;
6553
Chuck Leverbf269552010-12-14 14:59:29 +00006554 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006556 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006557 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006560 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006561 return status;
6562}
6563
6564/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006565 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566 */
Chuck Leverbf269552010-12-14 14:59:29 +00006567static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006568 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570 struct compound_hdr hdr;
6571 int status;
6572
Chuck Leverbf269552010-12-14 14:59:29 +00006573 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006575 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006576 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006577 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006579 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006580 return status;
6581}
6582
6583/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006584 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585 */
Chuck Leverbf269552010-12-14 14:59:29 +00006586static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6587 struct xdr_stream *xdr,
6588 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590 struct compound_hdr hdr;
6591 int status;
6592
Chuck Leverbf269552010-12-14 14:59:29 +00006593 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006594 if (status)
6595 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006596 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006597 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006599 status = decode_putfh(xdr);
6600 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006601 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006602 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006603out:
6604 return status;
6605}
6606
6607/*
6608 * Decode RENEW response
6609 */
Chuck Leverbf269552010-12-14 14:59:29 +00006610static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6611 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006612{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613 struct compound_hdr hdr;
6614 int status;
6615
Chuck Leverbf269552010-12-14 14:59:29 +00006616 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006618 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619 return status;
6620}
6621
6622/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006623 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006624 */
Chuck Leverbf269552010-12-14 14:59:29 +00006625static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6626 struct xdr_stream *xdr,
6627 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006628{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629 struct compound_hdr hdr;
6630 int status;
6631
Chuck Leverbf269552010-12-14 14:59:29 +00006632 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006634 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006635 return status;
6636}
6637
6638/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006639 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 */
Chuck Leverbf269552010-12-14 14:59:29 +00006641static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006642 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644 struct compound_hdr hdr;
6645 int status;
6646
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006648 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006649 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650 return status;
6651}
6652
6653/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006654 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655 */
Chuck Leverbf269552010-12-14 14:59:29 +00006656static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6657 struct xdr_stream *xdr,
6658 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660 struct compound_hdr hdr;
6661 int status;
6662
Chuck Leverbf269552010-12-14 14:59:29 +00006663 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006664 if (status)
6665 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006666 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006667 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006668 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006670 if (status != 0)
6671 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006672 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006673 if (status != 0)
6674 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006675 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006676out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677 return status;
6678}
6679
Trond Myklebust683b57b2006-06-09 09:34:22 -04006680/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006681 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006682 */
Chuck Leverbf269552010-12-14 14:59:29 +00006683static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6684 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006685 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006686{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006687 struct compound_hdr hdr;
6688 int status;
6689
Chuck Leverbf269552010-12-14 14:59:29 +00006690 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006691 if (status)
6692 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006693 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006694 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006695 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006696 status = decode_putfh(xdr);
6697 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006698 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006699 status = decode_lookup(xdr);
6700 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006701 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006702 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006703 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6704 NULL, res->fs_locations,
6705 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006706out:
6707 return status;
6708}
6709
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006710/*
6711 * Decode SECINFO response
6712 */
6713static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6714 struct xdr_stream *xdr,
6715 struct nfs4_secinfo_res *res)
6716{
6717 struct compound_hdr hdr;
6718 int status;
6719
6720 status = decode_compound_hdr(xdr, &hdr);
6721 if (status)
6722 goto out;
6723 status = decode_sequence(xdr, &res->seq_res, rqstp);
6724 if (status)
6725 goto out;
6726 status = decode_putfh(xdr);
6727 if (status)
6728 goto out;
6729 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006730out:
6731 return status;
6732}
6733
Benny Halevy99fe60d2009-04-01 09:22:29 -04006734#if defined(CONFIG_NFS_V4_1)
6735/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006736 * Decode BIND_CONN_TO_SESSION response
6737 */
6738static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6739 struct xdr_stream *xdr,
6740 void *res)
6741{
6742 struct compound_hdr hdr;
6743 int status;
6744
6745 status = decode_compound_hdr(xdr, &hdr);
6746 if (!status)
6747 status = decode_bind_conn_to_session(xdr, res);
6748 return status;
6749}
6750
6751/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006752 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006753 */
Chuck Leverbf269552010-12-14 14:59:29 +00006754static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6755 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006756 void *res)
6757{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006758 struct compound_hdr hdr;
6759 int status;
6760
Chuck Leverbf269552010-12-14 14:59:29 +00006761 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006762 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006763 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006764 return status;
6765}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006766
6767/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006768 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006769 */
Chuck Leverbf269552010-12-14 14:59:29 +00006770static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6771 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006772 struct nfs41_create_session_res *res)
6773{
Andy Adamsonfc931582009-04-01 09:22:31 -04006774 struct compound_hdr hdr;
6775 int status;
6776
Chuck Leverbf269552010-12-14 14:59:29 +00006777 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006778 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006779 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006780 return status;
6781}
6782
6783/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006784 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006785 */
Chuck Leverbf269552010-12-14 14:59:29 +00006786static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6787 struct xdr_stream *xdr,
6788 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006789{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006790 struct compound_hdr hdr;
6791 int status;
6792
Chuck Leverbf269552010-12-14 14:59:29 +00006793 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006794 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006795 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006796 return status;
6797}
6798
6799/*
Trond Myklebust66245532012-05-25 17:18:09 -04006800 * Decode DESTROY_CLIENTID response
6801 */
6802static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6803 struct xdr_stream *xdr,
6804 void *res)
6805{
6806 struct compound_hdr hdr;
6807 int status;
6808
6809 status = decode_compound_hdr(xdr, &hdr);
6810 if (!status)
6811 status = decode_destroy_clientid(xdr, res);
6812 return status;
6813}
6814
6815/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006816 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006817 */
Chuck Leverbf269552010-12-14 14:59:29 +00006818static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6819 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006820 struct nfs4_sequence_res *res)
6821{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006822 struct compound_hdr hdr;
6823 int status;
6824
Chuck Leverbf269552010-12-14 14:59:29 +00006825 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006826 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006827 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006828 return status;
6829}
6830
6831/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006832 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006833 */
Chuck Leverbf269552010-12-14 14:59:29 +00006834static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6835 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006836 struct nfs4_get_lease_time_res *res)
6837{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006838 struct compound_hdr hdr;
6839 int status;
6840
Chuck Leverbf269552010-12-14 14:59:29 +00006841 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006842 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006843 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006844 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006845 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006846 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006847 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006848 return status;
6849}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006850
6851/*
6852 * Decode RECLAIM_COMPLETE response
6853 */
Chuck Leverbf269552010-12-14 14:59:29 +00006854static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6855 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006856 struct nfs41_reclaim_complete_res *res)
6857{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006858 struct compound_hdr hdr;
6859 int status;
6860
Chuck Leverbf269552010-12-14 14:59:29 +00006861 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006862 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006863 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006864 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006865 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006866 return status;
6867}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006868
6869/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006870 * Decode GETDEVICELIST response
6871 */
6872static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6873 struct xdr_stream *xdr,
6874 struct nfs4_getdevicelist_res *res)
6875{
6876 struct compound_hdr hdr;
6877 int status;
6878
6879 dprintk("encoding getdevicelist!\n");
6880
6881 status = decode_compound_hdr(xdr, &hdr);
6882 if (status != 0)
6883 goto out;
6884 status = decode_sequence(xdr, &res->seq_res, rqstp);
6885 if (status != 0)
6886 goto out;
6887 status = decode_putfh(xdr);
6888 if (status != 0)
6889 goto out;
6890 status = decode_getdevicelist(xdr, res->devlist);
6891out:
6892 return status;
6893}
6894
6895/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006896 * Decode GETDEVINFO response
6897 */
Chuck Leverbf269552010-12-14 14:59:29 +00006898static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6899 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006900 struct nfs4_getdeviceinfo_res *res)
6901{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006902 struct compound_hdr hdr;
6903 int status;
6904
Chuck Leverbf269552010-12-14 14:59:29 +00006905 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006906 if (status != 0)
6907 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006908 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006909 if (status != 0)
6910 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006911 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006912out:
6913 return status;
6914}
6915
6916/*
6917 * Decode LAYOUTGET response
6918 */
Chuck Leverbf269552010-12-14 14:59:29 +00006919static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6920 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006921 struct nfs4_layoutget_res *res)
6922{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006923 struct compound_hdr hdr;
6924 int status;
6925
Chuck Leverbf269552010-12-14 14:59:29 +00006926 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006927 if (status)
6928 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006929 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006930 if (status)
6931 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006932 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006933 if (status)
6934 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006935 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006936out:
6937 return status;
6938}
Andy Adamson863a3c62011-03-23 13:27:54 +00006939
6940/*
Benny Halevycbe82602011-05-22 19:52:37 +03006941 * Decode LAYOUTRETURN response
6942 */
6943static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6944 struct xdr_stream *xdr,
6945 struct nfs4_layoutreturn_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_layoutreturn(xdr, res);
6960out:
6961 return status;
6962}
6963
6964/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006965 * Decode LAYOUTCOMMIT response
6966 */
6967static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6968 struct xdr_stream *xdr,
6969 struct nfs4_layoutcommit_res *res)
6970{
6971 struct compound_hdr hdr;
6972 int status;
6973
6974 status = decode_compound_hdr(xdr, &hdr);
6975 if (status)
6976 goto out;
6977 status = decode_sequence(xdr, &res->seq_res, rqstp);
6978 if (status)
6979 goto out;
6980 status = decode_putfh(xdr);
6981 if (status)
6982 goto out;
6983 status = decode_layoutcommit(xdr, rqstp, res);
6984 if (status)
6985 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006986 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006987out:
6988 return status;
6989}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006990
6991/*
6992 * Decode SECINFO_NO_NAME response
6993 */
6994static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6995 struct xdr_stream *xdr,
6996 struct nfs4_secinfo_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_putrootfh(xdr);
7008 if (status)
7009 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007010 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007011out:
7012 return status;
7013}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007014
7015/*
7016 * Decode TEST_STATEID response
7017 */
7018static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7019 struct xdr_stream *xdr,
7020 struct nfs41_test_stateid_res *res)
7021{
7022 struct compound_hdr hdr;
7023 int status;
7024
7025 status = decode_compound_hdr(xdr, &hdr);
7026 if (status)
7027 goto out;
7028 status = decode_sequence(xdr, &res->seq_res, rqstp);
7029 if (status)
7030 goto out;
7031 status = decode_test_stateid(xdr, res);
7032out:
7033 return status;
7034}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007035
7036/*
7037 * Decode FREE_STATEID response
7038 */
7039static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7040 struct xdr_stream *xdr,
7041 struct nfs41_free_stateid_res *res)
7042{
7043 struct compound_hdr hdr;
7044 int status;
7045
7046 status = decode_compound_hdr(xdr, &hdr);
7047 if (status)
7048 goto out;
7049 status = decode_sequence(xdr, &res->seq_res, rqstp);
7050 if (status)
7051 goto out;
7052 status = decode_free_stateid(xdr, res);
7053out:
7054 return status;
7055}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007056#endif /* CONFIG_NFS_V4_1 */
7057
Chuck Lever573c4e12010-12-14 14:58:11 +00007058/**
7059 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7060 * the local page cache.
7061 * @xdr: XDR stream where entry resides
7062 * @entry: buffer to fill in with entry data
7063 * @plus: boolean indicating whether this should be a readdirplus entry
7064 *
7065 * Returns zero if successful, otherwise a negative errno value is
7066 * returned.
7067 *
7068 * This function is not invoked during READDIR reply decoding, but
7069 * rather whenever an application invokes the getdents(2) system call
7070 * on a directory already in our cache.
7071 */
7072int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7073 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007074{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007075 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007076 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007077 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007078 __be32 *p = xdr_inline_decode(xdr, 4);
7079 if (unlikely(!p))
7080 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007081 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007082 p = xdr_inline_decode(xdr, 4);
7083 if (unlikely(!p))
7084 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007085 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007086 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007087 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007088 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007089 }
7090
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007091 p = xdr_inline_decode(xdr, 12);
7092 if (unlikely(!p))
7093 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007094 entry->prev_cookie = entry->cookie;
7095 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007096 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007097
Trond Myklebust9af8c222010-10-24 11:52:55 -04007098 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007099 if (unlikely(!p))
7100 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007101 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007102
7103 /*
7104 * In case the server doesn't return an inode number,
7105 * we fake one here. (We don't use inode number 0,
7106 * since glibc seems to choke on it...)
7107 */
7108 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007109 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007110
Trond Myklebust9af8c222010-10-24 11:52:55 -04007111 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007112 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007113
Trond Myklebust256e48b2012-06-21 11:18:13 -04007114 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007115 goto out_overflow;
7116
Chuck Lever573c4e12010-12-14 14:58:11 +00007117 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007118 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007119 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007120 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7121 entry->ino = entry->fattr->mounted_on_fileid;
7122 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007123 entry->ino = entry->fattr->fileid;
7124
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007125 entry->d_type = DT_UNKNOWN;
7126 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7127 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7128
Chuck Lever573c4e12010-12-14 14:58:11 +00007129 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007130
7131out_overflow:
7132 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007133 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007134}
7135
7136/*
7137 * We need to translate between nfs status return values and
7138 * the local errno values which may not be the same.
7139 */
7140static struct {
7141 int stat;
7142 int errno;
7143} nfs_errtbl[] = {
7144 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007145 { NFS4ERR_PERM, -EPERM },
7146 { NFS4ERR_NOENT, -ENOENT },
7147 { NFS4ERR_IO, -errno_NFSERR_IO},
7148 { NFS4ERR_NXIO, -ENXIO },
7149 { NFS4ERR_ACCESS, -EACCES },
7150 { NFS4ERR_EXIST, -EEXIST },
7151 { NFS4ERR_XDEV, -EXDEV },
7152 { NFS4ERR_NOTDIR, -ENOTDIR },
7153 { NFS4ERR_ISDIR, -EISDIR },
7154 { NFS4ERR_INVAL, -EINVAL },
7155 { NFS4ERR_FBIG, -EFBIG },
7156 { NFS4ERR_NOSPC, -ENOSPC },
7157 { NFS4ERR_ROFS, -EROFS },
7158 { NFS4ERR_MLINK, -EMLINK },
7159 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7160 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7161 { NFS4ERR_DQUOT, -EDQUOT },
7162 { NFS4ERR_STALE, -ESTALE },
7163 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007164 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7165 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7166 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007167 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007168 { NFS4ERR_BADTYPE, -EBADTYPE },
7169 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007170 { NFS4ERR_SYMLINK, -ELOOP },
7171 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7172 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007173 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007174};
7175
7176/*
7177 * Convert an NFS error code to a local one.
7178 * This one is used jointly by NFSv2 and NFSv3.
7179 */
7180static int
David Howells0a8ea432006-08-22 20:06:08 -04007181nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007182{
7183 int i;
7184 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7185 if (nfs_errtbl[i].stat == stat)
7186 return nfs_errtbl[i].errno;
7187 }
7188 if (stat <= 10000 || stat > 10100) {
7189 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007190 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007191 }
7192 /* If we cannot translate the error, the recovery routines should
7193 * handle it.
7194 * Note: remaining NFSv4 error codes have values > 10000, so should
7195 * not conflict with native Linux error codes.
7196 */
Benny Halevy856dff32008-03-31 17:39:06 +03007197 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007198}
7199
Linus Torvalds1da177e2005-04-16 15:20:36 -07007200#define PROC(proc, argtype, restype) \
7201[NFSPROC4_CLNT_##proc] = { \
7202 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007203 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007204 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007205 .p_arglen = NFS4_##argtype##_sz, \
7206 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007207 .p_statidx = NFSPROC4_CLNT_##proc, \
7208 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007209}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007210
7211struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007212 PROC(READ, enc_read, dec_read),
7213 PROC(WRITE, enc_write, dec_write),
7214 PROC(COMMIT, enc_commit, dec_commit),
7215 PROC(OPEN, enc_open, dec_open),
7216 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7217 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7218 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7219 PROC(CLOSE, enc_close, dec_close),
7220 PROC(SETATTR, enc_setattr, dec_setattr),
7221 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7222 PROC(RENEW, enc_renew, dec_renew),
7223 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7224 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7225 PROC(LOCK, enc_lock, dec_lock),
7226 PROC(LOCKT, enc_lockt, dec_lockt),
7227 PROC(LOCKU, enc_locku, dec_locku),
7228 PROC(ACCESS, enc_access, dec_access),
7229 PROC(GETATTR, enc_getattr, dec_getattr),
7230 PROC(LOOKUP, enc_lookup, dec_lookup),
7231 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7232 PROC(REMOVE, enc_remove, dec_remove),
7233 PROC(RENAME, enc_rename, dec_rename),
7234 PROC(LINK, enc_link, dec_link),
7235 PROC(SYMLINK, enc_symlink, dec_symlink),
7236 PROC(CREATE, enc_create, dec_create),
7237 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7238 PROC(STATFS, enc_statfs, dec_statfs),
7239 PROC(READLINK, enc_readlink, dec_readlink),
7240 PROC(READDIR, enc_readdir, dec_readdir),
7241 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7242 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7243 PROC(GETACL, enc_getacl, dec_getacl),
7244 PROC(SETACL, enc_setacl, dec_setacl),
7245 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7246 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007247 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007248#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007249 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7250 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7251 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7252 PROC(SEQUENCE, enc_sequence, dec_sequence),
7253 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7254 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7255 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7256 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007257 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007258 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007259 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007260 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007261 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007262 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007263 PROC(BIND_CONN_TO_SESSION,
7264 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007265 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007266#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007267};
7268
Trond Myklebusta613fa12012-01-20 13:53:56 -05007269const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007270 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007271 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007272 .procs = nfs4_procedures
7273};
7274
7275/*
7276 * Local variables:
7277 * c-basic-offset: 8
7278 * End:
7279 */