blob: fef71cbec501845ab386632656d06c74a6edc99f [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 + \
533 encode_setclientid_confirm_maxsz + \
534 encode_putrootfh_maxsz + \
535 encode_fsinfo_maxsz)
536#define NFS4_dec_setclientid_confirm_sz \
537 (compound_decode_hdr_maxsz + \
538 decode_setclientid_confirm_maxsz + \
539 decode_putrootfh_maxsz + \
540 decode_fsinfo_maxsz)
541#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400544 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400548 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400552 encode_lockt_maxsz)
553#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400554 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400555 decode_putfh_maxsz + \
556 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400560 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400564 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400565#define NFS4_enc_release_lockowner_sz \
566 (compound_encode_hdr_maxsz + \
567 encode_lockowner_maxsz)
568#define NFS4_dec_release_lockowner_sz \
569 (compound_decode_hdr_maxsz + \
570 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400574 encode_access_maxsz + \
575 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400577 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400579 decode_access_maxsz + \
580 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 encode_putfh_maxsz + \
584 encode_getattr_maxsz)
585#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 decode_putfh_maxsz + \
588 decode_getattr_maxsz)
589#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
592 encode_lookup_maxsz + \
593 encode_getattr_maxsz + \
594 encode_getfh_maxsz)
595#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400598 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 decode_getattr_maxsz + \
600 decode_getfh_maxsz)
601#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400602 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 encode_putrootfh_maxsz + \
604 encode_getattr_maxsz + \
605 encode_getfh_maxsz)
606#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400607 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 decode_putrootfh_maxsz + \
609 decode_getattr_maxsz + \
610 decode_getfh_maxsz)
611#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400612 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400614 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400618 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400620 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 encode_putfh_maxsz + \
622 encode_savefh_maxsz + \
623 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400624 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 decode_putfh_maxsz + \
628 decode_savefh_maxsz + \
629 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400630 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400632 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 encode_putfh_maxsz + \
634 encode_savefh_maxsz + \
635 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400636 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400637 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400638 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400640 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 decode_putfh_maxsz + \
642 decode_savefh_maxsz + \
643 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400644 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400645 decode_restorefh_maxsz + \
646 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 encode_putfh_maxsz + \
650 encode_symlink_maxsz + \
651 encode_getattr_maxsz + \
652 encode_getfh_maxsz)
653#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 decode_putfh_maxsz + \
656 decode_symlink_maxsz + \
657 decode_getattr_maxsz + \
658 decode_getfh_maxsz)
659#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 encode_putfh_maxsz + \
662 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400663 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400664 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 decode_putfh_maxsz + \
668 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400669 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400670 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
674 encode_getattr_maxsz)
675#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_getattr_maxsz)
679#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400686 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800689 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 encode_getattr_maxsz)
691#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800693 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 decode_getattr_maxsz)
695#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100698 encode_delegreturn_maxsz + \
699 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100702 decode_delegreturn_maxsz + \
703 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000706 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000708#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000710 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400711 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000714 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000716#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000718 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400720#define NFS4_enc_fs_locations_sz \
721 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400723 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400724 encode_lookup_maxsz + \
725 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400726#define NFS4_dec_fs_locations_sz \
727 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400729 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400730 decode_lookup_maxsz + \
731 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000732#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
733 encode_sequence_maxsz + \
734 encode_putfh_maxsz + \
735 encode_secinfo_maxsz)
736#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
737 decode_sequence_maxsz + \
738 decode_putfh_maxsz + \
739 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400740#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400741#define NFS4_enc_bind_conn_to_session_sz \
742 (compound_encode_hdr_maxsz + \
743 encode_bind_conn_to_session_maxsz)
744#define NFS4_dec_bind_conn_to_session_sz \
745 (compound_decode_hdr_maxsz + \
746 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400747#define NFS4_enc_exchange_id_sz \
748 (compound_encode_hdr_maxsz + \
749 encode_exchange_id_maxsz)
750#define NFS4_dec_exchange_id_sz \
751 (compound_decode_hdr_maxsz + \
752 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400753#define NFS4_enc_create_session_sz \
754 (compound_encode_hdr_maxsz + \
755 encode_create_session_maxsz)
756#define NFS4_dec_create_session_sz \
757 (compound_decode_hdr_maxsz + \
758 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400759#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
760 encode_destroy_session_maxsz)
761#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
762 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400763#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
764 encode_destroy_clientid_maxsz)
765#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
766 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400767#define NFS4_enc_sequence_sz \
768 (compound_decode_hdr_maxsz + \
769 encode_sequence_maxsz)
770#define NFS4_dec_sequence_sz \
771 (compound_decode_hdr_maxsz + \
772 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400773#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
774 encode_sequence_maxsz + \
775 encode_putrootfh_maxsz + \
776 encode_fsinfo_maxsz)
777#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
778 decode_sequence_maxsz + \
779 decode_putrootfh_maxsz + \
780 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500781#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
782 encode_sequence_maxsz + \
783 encode_reclaim_complete_maxsz)
784#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
785 decode_sequence_maxsz + \
786 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400787#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
788 encode_sequence_maxsz + \
789 encode_putfh_maxsz + \
790 encode_getdevicelist_maxsz)
791#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
792 decode_sequence_maxsz + \
793 decode_putfh_maxsz + \
794 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400795#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
796 encode_sequence_maxsz +\
797 encode_getdeviceinfo_maxsz)
798#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
799 decode_sequence_maxsz + \
800 decode_getdeviceinfo_maxsz)
801#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
802 encode_sequence_maxsz + \
803 encode_putfh_maxsz + \
804 encode_layoutget_maxsz)
805#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
806 decode_sequence_maxsz + \
807 decode_putfh_maxsz + \
808 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000809#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz +\
811 encode_putfh_maxsz + \
812 encode_layoutcommit_maxsz + \
813 encode_getattr_maxsz)
814#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_putfh_maxsz + \
817 decode_layoutcommit_maxsz + \
818 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300819#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz + \
821 encode_putfh_maxsz + \
822 encode_layoutreturn_maxsz)
823#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
824 decode_sequence_maxsz + \
825 decode_putfh_maxsz + \
826 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400827#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
828 encode_sequence_maxsz + \
829 encode_putrootfh_maxsz +\
830 encode_secinfo_no_name_maxsz)
831#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
832 decode_sequence_maxsz + \
833 decode_putrootfh_maxsz + \
834 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400835#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
836 encode_sequence_maxsz + \
837 encode_test_stateid_maxsz)
838#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
839 decode_sequence_maxsz + \
840 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400841#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
842 encode_sequence_maxsz + \
843 encode_free_stateid_maxsz)
844#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
845 decode_sequence_maxsz + \
846 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500847
848const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
849 compound_encode_hdr_maxsz +
850 encode_sequence_maxsz +
851 encode_putfh_maxsz +
852 encode_getattr_maxsz) *
853 XDR_UNIT);
854
855const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
856 compound_decode_hdr_maxsz +
857 decode_sequence_maxsz +
858 decode_putfh_maxsz) *
859 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400860#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Trond Myklebustbca79472009-03-11 14:10:26 -0400862static const umode_t nfs_type2fmt[] = {
863 [NF4BAD] = 0,
864 [NF4REG] = S_IFREG,
865 [NF4DIR] = S_IFDIR,
866 [NF4BLK] = S_IFBLK,
867 [NF4CHR] = S_IFCHR,
868 [NF4LNK] = S_IFLNK,
869 [NF4SOCK] = S_IFSOCK,
870 [NF4FIFO] = S_IFIFO,
871 [NF4ATTRDIR] = 0,
872 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873};
874
875struct compound_hdr {
876 int32_t status;
877 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500878 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 uint32_t taglen;
880 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400881 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400882 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883};
884
Benny Halevy13c65ce2009-08-14 17:19:25 +0300885static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
886{
887 __be32 *p = xdr_reserve_space(xdr, nbytes);
888 BUG_ON(!p);
889 return p;
890}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Trond Myklebustcb17e552012-03-04 18:13:56 -0500892static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
893{
894 __be32 *p;
895
896 p = xdr_reserve_space(xdr, len);
897 xdr_encode_opaque_fixed(p, buf, len);
898}
899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
901{
Al Viro8687b632006-10-19 23:28:48 -0700902 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500904 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 xdr_encode_opaque(p, str, len);
906}
907
Trond Myklebust4ade9822012-03-04 18:13:57 -0500908static void encode_uint32(struct xdr_stream *xdr, u32 n)
909{
910 __be32 *p;
911
912 p = reserve_space(xdr, 4);
913 *p = cpu_to_be32(n);
914}
915
Trond Myklebustff2eb682012-03-05 11:40:12 -0500916static void encode_uint64(struct xdr_stream *xdr, u64 n)
917{
918 __be32 *p;
919
920 p = reserve_space(xdr, 8);
921 xdr_encode_hyper(p, n);
922}
923
Trond Myklebust4ade9822012-03-04 18:13:57 -0500924static void encode_nfs4_seqid(struct xdr_stream *xdr,
925 const struct nfs_seqid *seqid)
926{
927 encode_uint32(xdr, seqid->sequence->counter);
928}
929
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400930static void encode_compound_hdr(struct xdr_stream *xdr,
931 struct rpc_rqst *req,
932 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
Al Viro8687b632006-10-19 23:28:48 -0700934 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400935 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400936
937 /* initialize running count of expected bytes in reply.
938 * NOTE: the replied tag SHOULD be the same is the one sent,
939 * but this is not required as a MUST for the server to do so. */
940 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Trond Myklebust7fc38842012-10-15 11:51:21 -0400942 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500943 encode_string(xdr, hdr->taglen, hdr->tag);
944 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300945 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500946 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300947 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500948}
949
Trond Myklebustab19b482012-03-04 18:13:57 -0500950static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
951 uint32_t replen,
952 struct compound_hdr *hdr)
953{
954 encode_uint32(xdr, op);
955 hdr->nops++;
956 hdr->replen += replen;
957}
958
Andy Adamsond0179312008-12-23 16:06:17 -0500959static void encode_nops(struct compound_hdr *hdr)
960{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400961 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500962 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500965static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
966{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500967 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500968}
969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
971{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500972 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973}
974
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500975static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
977 char owner_name[IDMAP_NAMESZ];
978 char owner_group[IDMAP_NAMESZ];
979 int owner_namelen = 0;
980 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700981 __be32 *p;
982 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 int len;
984 uint32_t bmval0 = 0;
985 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
987 /*
988 * We reserve enough space to write the entire attribute buffer at once.
989 * In the worst-case, this would be
990 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
991 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000992 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 */
994 len = 16;
995
996 /* Sigh */
997 if (iap->ia_valid & ATTR_SIZE)
998 len += 8;
999 if (iap->ia_valid & ATTR_MODE)
1000 len += 4;
1001 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001002 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001004 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001005 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 /* XXX */
1007 strcpy(owner_name, "nobody");
1008 owner_namelen = sizeof("nobody") - 1;
1009 /* goto out; */
1010 }
1011 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1012 }
1013 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001014 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001016 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001017 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 strcpy(owner_group, "nobody");
1019 owner_grouplen = sizeof("nobody") - 1;
1020 /* goto out; */
1021 }
1022 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1023 }
1024 if (iap->ia_valid & ATTR_ATIME_SET)
1025 len += 16;
1026 else if (iap->ia_valid & ATTR_ATIME)
1027 len += 4;
1028 if (iap->ia_valid & ATTR_MTIME_SET)
1029 len += 16;
1030 else if (iap->ia_valid & ATTR_MTIME)
1031 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001032 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
1034 /*
1035 * We write the bitmap length now, but leave the bitmap and the attribute
1036 * buffer length to be backfilled at the end of this routine.
1037 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001038 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 q = p;
1040 p += 3;
1041
1042 if (iap->ia_valid & ATTR_SIZE) {
1043 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001044 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046 if (iap->ia_valid & ATTR_MODE) {
1047 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001048 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 }
1050 if (iap->ia_valid & ATTR_UID) {
1051 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001052 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
1054 if (iap->ia_valid & ATTR_GID) {
1055 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001056 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
1058 if (iap->ia_valid & ATTR_ATIME_SET) {
1059 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001060 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1061 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001062 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1063 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 }
1065 else if (iap->ia_valid & ATTR_ATIME) {
1066 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
1069 if (iap->ia_valid & ATTR_MTIME_SET) {
1070 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001071 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1072 *p++ = cpu_to_be32(0);
1073 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1074 *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);
1898 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1899 *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 Myklebustea9d23f2012-03-04 18:13:56 -05002012 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 };
Fred Isamandae100c2011-07-30 20:52:37 -04002606 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607
Chuck Lever9f06c712010-12-14 14:59:18 +00002608 encode_compound_hdr(xdr, req, &hdr);
2609 encode_setclientid_confirm(xdr, arg, &hdr);
2610 encode_putrootfh(xdr, &hdr);
2611 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002612 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613}
2614
2615/*
2616 * DELEGRETURN request
2617 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002618static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2619 struct xdr_stream *xdr,
2620 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002623 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625
Chuck Lever9f06c712010-12-14 14:59:18 +00002626 encode_compound_hdr(xdr, req, &hdr);
2627 encode_sequence(xdr, &args->seq_args, &hdr);
2628 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002629 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002630 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002631 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632}
2633
2634/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002635 * Encode FS_LOCATIONS request
2636 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002637static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2638 struct xdr_stream *xdr,
2639 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002640{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002641 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002642 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002643 };
Benny Halevy28f56692009-04-01 09:22:09 -04002644 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002645
Chuck Lever9f06c712010-12-14 14:59:18 +00002646 encode_compound_hdr(xdr, req, &hdr);
2647 encode_sequence(xdr, &args->seq_args, &hdr);
2648 encode_putfh(xdr, args->dir_fh, &hdr);
2649 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002650 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002651 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002652
Benny Halevy28f56692009-04-01 09:22:09 -04002653 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002654 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002655 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002656}
2657
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002658/*
2659 * Encode SECINFO request
2660 */
2661static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2662 struct xdr_stream *xdr,
2663 struct nfs4_secinfo_arg *args)
2664{
2665 struct compound_hdr hdr = {
2666 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2667 };
2668
2669 encode_compound_hdr(xdr, req, &hdr);
2670 encode_sequence(xdr, &args->seq_args, &hdr);
2671 encode_putfh(xdr, args->dir_fh, &hdr);
2672 encode_secinfo(xdr, args->name, &hdr);
2673 encode_nops(&hdr);
2674}
2675
Benny Halevy99fe60d2009-04-01 09:22:29 -04002676#if defined(CONFIG_NFS_V4_1)
2677/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002678 * BIND_CONN_TO_SESSION request
2679 */
2680static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2681 struct xdr_stream *xdr,
2682 struct nfs_client *clp)
2683{
2684 struct compound_hdr hdr = {
2685 .minorversion = clp->cl_mvops->minor_version,
2686 };
2687
2688 encode_compound_hdr(xdr, req, &hdr);
2689 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2690 encode_nops(&hdr);
2691}
2692
2693/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002694 * EXCHANGE_ID request
2695 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002696static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2697 struct xdr_stream *xdr,
2698 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002699{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002700 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002701 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002702 };
2703
Chuck Lever9f06c712010-12-14 14:59:18 +00002704 encode_compound_hdr(xdr, req, &hdr);
2705 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002706 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002707}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002708
2709/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002710 * a CREATE_SESSION request
2711 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002712static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2713 struct xdr_stream *xdr,
2714 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002715{
Andy Adamsonfc931582009-04-01 09:22:31 -04002716 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002717 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002718 };
2719
Chuck Lever9f06c712010-12-14 14:59:18 +00002720 encode_compound_hdr(xdr, req, &hdr);
2721 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002722 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002723}
2724
2725/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002726 * a DESTROY_SESSION request
2727 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002728static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2729 struct xdr_stream *xdr,
2730 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002731{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002732 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002733 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002734 };
2735
Chuck Lever9f06c712010-12-14 14:59:18 +00002736 encode_compound_hdr(xdr, req, &hdr);
2737 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002738 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002739}
2740
2741/*
Trond Myklebust66245532012-05-25 17:18:09 -04002742 * a DESTROY_CLIENTID request
2743 */
2744static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2745 struct xdr_stream *xdr,
2746 struct nfs_client *clp)
2747{
2748 struct compound_hdr hdr = {
2749 .minorversion = clp->cl_mvops->minor_version,
2750 };
2751
2752 encode_compound_hdr(xdr, req, &hdr);
2753 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2754 encode_nops(&hdr);
2755}
2756
2757/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002758 * a SEQUENCE request
2759 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002760static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2761 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002762{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002763 struct compound_hdr hdr = {
2764 .minorversion = nfs4_xdr_minorversion(args),
2765 };
2766
Chuck Lever9f06c712010-12-14 14:59:18 +00002767 encode_compound_hdr(xdr, req, &hdr);
2768 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002769 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002770}
2771
2772/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002773 * a GET_LEASE_TIME request
2774 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002775static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2776 struct xdr_stream *xdr,
2777 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002778{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002779 struct compound_hdr hdr = {
2780 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2781 };
Fred Isamandae100c2011-07-30 20:52:37 -04002782 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002783
Chuck Lever9f06c712010-12-14 14:59:18 +00002784 encode_compound_hdr(xdr, req, &hdr);
2785 encode_sequence(xdr, &args->la_seq_args, &hdr);
2786 encode_putrootfh(xdr, &hdr);
2787 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002788 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002789}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002790
2791/*
2792 * a RECLAIM_COMPLETE request
2793 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002794static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2795 struct xdr_stream *xdr,
2796 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002797{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002798 struct compound_hdr hdr = {
2799 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2800 };
2801
Chuck Lever9f06c712010-12-14 14:59:18 +00002802 encode_compound_hdr(xdr, req, &hdr);
2803 encode_sequence(xdr, &args->seq_args, &hdr);
2804 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002805 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002806}
2807
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002808/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002809 * Encode GETDEVICELIST request
2810 */
2811static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2812 struct xdr_stream *xdr,
2813 struct nfs4_getdevicelist_args *args)
2814{
2815 struct compound_hdr hdr = {
2816 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2817 };
2818
2819 encode_compound_hdr(xdr, req, &hdr);
2820 encode_sequence(xdr, &args->seq_args, &hdr);
2821 encode_putfh(xdr, args->fh, &hdr);
2822 encode_getdevicelist(xdr, args, &hdr);
2823 encode_nops(&hdr);
2824}
2825
2826/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002827 * Encode GETDEVICEINFO request
2828 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002829static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2830 struct xdr_stream *xdr,
2831 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002832{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002833 struct compound_hdr hdr = {
2834 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2835 };
2836
Chuck Lever9f06c712010-12-14 14:59:18 +00002837 encode_compound_hdr(xdr, req, &hdr);
2838 encode_sequence(xdr, &args->seq_args, &hdr);
2839 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002840
2841 /* set up reply kvec. Subtract notification bitmap max size (2)
2842 * so that notification bitmap is put in xdr_buf tail */
2843 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2844 args->pdev->pages, args->pdev->pgbase,
2845 args->pdev->pglen);
2846
2847 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002848}
2849
2850/*
2851 * Encode LAYOUTGET request
2852 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002853static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2854 struct xdr_stream *xdr,
2855 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002856{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002857 struct compound_hdr hdr = {
2858 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2859 };
2860
Chuck Lever9f06c712010-12-14 14:59:18 +00002861 encode_compound_hdr(xdr, req, &hdr);
2862 encode_sequence(xdr, &args->seq_args, &hdr);
2863 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2864 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002865
2866 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2867 args->layout.pages, 0, args->layout.pglen);
2868
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002869 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002870}
Andy Adamson863a3c62011-03-23 13:27:54 +00002871
2872/*
2873 * Encode LAYOUTCOMMIT request
2874 */
Benny Halevycbe82602011-05-22 19:52:37 +03002875static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2876 struct xdr_stream *xdr,
2877 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002878{
Benny Halevyac7db722011-05-22 19:53:48 +03002879 struct nfs4_layoutcommit_data *data =
2880 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002881 struct compound_hdr hdr = {
2882 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2883 };
2884
2885 encode_compound_hdr(xdr, req, &hdr);
2886 encode_sequence(xdr, &args->seq_args, &hdr);
2887 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002888 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002889 encode_getfattr(xdr, args->bitmask, &hdr);
2890 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002891}
2892
2893/*
2894 * Encode LAYOUTRETURN request
2895 */
2896static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2897 struct xdr_stream *xdr,
2898 struct nfs4_layoutreturn_args *args)
2899{
2900 struct compound_hdr hdr = {
2901 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2902 };
2903
2904 encode_compound_hdr(xdr, req, &hdr);
2905 encode_sequence(xdr, &args->seq_args, &hdr);
2906 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2907 encode_layoutreturn(xdr, args, &hdr);
2908 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002909}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002910
2911/*
2912 * Encode SECINFO_NO_NAME request
2913 */
2914static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2915 struct xdr_stream *xdr,
2916 struct nfs41_secinfo_no_name_args *args)
2917{
2918 struct compound_hdr hdr = {
2919 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2920 };
2921
2922 encode_compound_hdr(xdr, req, &hdr);
2923 encode_sequence(xdr, &args->seq_args, &hdr);
2924 encode_putrootfh(xdr, &hdr);
2925 encode_secinfo_no_name(xdr, args, &hdr);
2926 encode_nops(&hdr);
2927 return 0;
2928}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002929
2930/*
2931 * Encode TEST_STATEID request
2932 */
2933static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2934 struct xdr_stream *xdr,
2935 struct nfs41_test_stateid_args *args)
2936{
2937 struct compound_hdr hdr = {
2938 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2939 };
2940
2941 encode_compound_hdr(xdr, req, &hdr);
2942 encode_sequence(xdr, &args->seq_args, &hdr);
2943 encode_test_stateid(xdr, args, &hdr);
2944 encode_nops(&hdr);
2945}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002946
2947/*
2948 * Encode FREE_STATEID request
2949 */
2950static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2951 struct xdr_stream *xdr,
2952 struct nfs41_free_stateid_args *args)
2953{
2954 struct compound_hdr hdr = {
2955 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2956 };
2957
2958 encode_compound_hdr(xdr, req, &hdr);
2959 encode_sequence(xdr, &args->seq_args, &hdr);
2960 encode_free_stateid(xdr, args, &hdr);
2961 encode_nops(&hdr);
2962}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002963#endif /* CONFIG_NFS_V4_1 */
2964
Benny Halevy686841b2009-08-14 17:19:48 +03002965static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2966{
2967 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2968 "Remaining buffer length is %tu words.\n",
2969 func, xdr->end - xdr->p);
2970}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971
Trond Myklebust683b57b2006-06-09 09:34:22 -04002972static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973{
Al Viro8687b632006-10-19 23:28:48 -07002974 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
Benny Halevyc0eae662009-08-14 17:20:14 +03002976 p = xdr_inline_decode(xdr, 4);
2977 if (unlikely(!p))
2978 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002979 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002980 p = xdr_inline_decode(xdr, *len);
2981 if (unlikely(!p))
2982 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 *string = (char *)p;
2984 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002985out_overflow:
2986 print_overflow_msg(__func__, xdr);
2987 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988}
2989
2990static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2991{
Al Viro8687b632006-10-19 23:28:48 -07002992 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993
Benny Halevyc0eae662009-08-14 17:20:14 +03002994 p = xdr_inline_decode(xdr, 8);
2995 if (unlikely(!p))
2996 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002997 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002998 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002999
Benny Halevyc0eae662009-08-14 17:20:14 +03003000 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3001 if (unlikely(!p))
3002 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 hdr->tag = (char *)p;
3004 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003005 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003006 if (unlikely(hdr->nops < 1))
3007 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003009out_overflow:
3010 print_overflow_msg(__func__, xdr);
3011 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012}
3013
3014static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3015{
Al Viro8687b632006-10-19 23:28:48 -07003016 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 uint32_t opnum;
3018 int32_t nfserr;
3019
Benny Halevyc0eae662009-08-14 17:20:14 +03003020 p = xdr_inline_decode(xdr, 8);
3021 if (unlikely(!p))
3022 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003023 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003025 dprintk("nfs: Server returned operation"
3026 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 opnum, expected);
3028 return -EIO;
3029 }
Benny Halevycccddf42009-08-14 17:20:19 +03003030 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003032 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003034out_overflow:
3035 print_overflow_msg(__func__, xdr);
3036 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037}
3038
3039/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003040static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041{
Al Viro8687b632006-10-19 23:28:48 -07003042 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003043 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 char *str;
3045
Benny Halevyc0eae662009-08-14 17:20:14 +03003046 p = xdr_inline_decode(xdr, 12);
3047 if (likely(p))
3048 return decode_opaque_inline(xdr, &strlen, &str);
3049 print_overflow_msg(__func__, xdr);
3050 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051}
3052
3053static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3054{
Al Viro8687b632006-10-19 23:28:48 -07003055 uint32_t bmlen;
3056 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
Benny Halevyc0eae662009-08-14 17:20:14 +03003058 p = xdr_inline_decode(xdr, 4);
3059 if (unlikely(!p))
3060 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003061 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
Fred Isamandae100c2011-07-30 20:52:37 -04003063 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003064 p = xdr_inline_decode(xdr, (bmlen << 2));
3065 if (unlikely(!p))
3066 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003068 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003069 if (bmlen > 1) {
3070 bitmap[1] = be32_to_cpup(p++);
3071 if (bmlen > 2)
3072 bitmap[2] = be32_to_cpup(p);
3073 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 }
3075 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003076out_overflow:
3077 print_overflow_msg(__func__, xdr);
3078 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079}
3080
Trond Myklebust256e48b2012-06-21 11:18:13 -04003081static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082{
Al Viro8687b632006-10-19 23:28:48 -07003083 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084
Benny Halevyc0eae662009-08-14 17:20:14 +03003085 p = xdr_inline_decode(xdr, 4);
3086 if (unlikely(!p))
3087 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003088 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003089 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003091out_overflow:
3092 print_overflow_msg(__func__, xdr);
3093 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094}
3095
3096static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3097{
3098 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003099 int ret;
3100 ret = decode_attr_bitmap(xdr, bitmask);
3101 if (unlikely(ret < 0))
3102 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3104 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003105 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3106 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3107 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 return 0;
3109}
3110
3111static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3112{
Al Viro8687b632006-10-19 23:28:48 -07003113 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003114 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115
3116 *type = 0;
3117 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3118 return -EIO;
3119 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003120 p = xdr_inline_decode(xdr, 4);
3121 if (unlikely(!p))
3122 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003123 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003125 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 return -EIO;
3127 }
3128 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003129 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003131 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003132 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003133out_overflow:
3134 print_overflow_msg(__func__, xdr);
3135 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136}
3137
Chuck Lever264e6352012-03-01 17:02:05 -05003138static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3139 uint32_t *bitmap, uint32_t *type)
3140{
3141 __be32 *p;
3142
3143 *type = 0;
3144 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3145 return -EIO;
3146 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3147 p = xdr_inline_decode(xdr, 4);
3148 if (unlikely(!p))
3149 goto out_overflow;
3150 *type = be32_to_cpup(p);
3151 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3152 }
3153 dprintk("%s: expire type=0x%x\n", __func__, *type);
3154 return 0;
3155out_overflow:
3156 print_overflow_msg(__func__, xdr);
3157 return -EIO;
3158}
3159
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3161{
Al Viro8687b632006-10-19 23:28:48 -07003162 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003163 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164
3165 *change = 0;
3166 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3167 return -EIO;
3168 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003169 p = xdr_inline_decode(xdr, 8);
3170 if (unlikely(!p))
3171 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003172 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003174 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003176 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003178 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003179out_overflow:
3180 print_overflow_msg(__func__, xdr);
3181 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182}
3183
3184static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3185{
Al Viro8687b632006-10-19 23:28:48 -07003186 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003187 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188
3189 *size = 0;
3190 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3191 return -EIO;
3192 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003193 p = xdr_inline_decode(xdr, 8);
3194 if (unlikely(!p))
3195 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003196 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003198 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003200 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003201 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003202out_overflow:
3203 print_overflow_msg(__func__, xdr);
3204 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205}
3206
3207static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3208{
Al Viro8687b632006-10-19 23:28:48 -07003209 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210
3211 *res = 0;
3212 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3213 return -EIO;
3214 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003215 p = xdr_inline_decode(xdr, 4);
3216 if (unlikely(!p))
3217 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003218 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3220 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003221 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003223out_overflow:
3224 print_overflow_msg(__func__, xdr);
3225 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226}
3227
3228static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3229{
Al Viro8687b632006-10-19 23:28:48 -07003230 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231
3232 *res = 0;
3233 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3234 return -EIO;
3235 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003236 p = xdr_inline_decode(xdr, 4);
3237 if (unlikely(!p))
3238 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003239 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3241 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003242 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003244out_overflow:
3245 print_overflow_msg(__func__, xdr);
3246 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247}
3248
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003249static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250{
Al Viro8687b632006-10-19 23:28:48 -07003251 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003252 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253
3254 fsid->major = 0;
3255 fsid->minor = 0;
3256 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3257 return -EIO;
3258 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003259 p = xdr_inline_decode(xdr, 16);
3260 if (unlikely(!p))
3261 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003262 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003263 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003265 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003267 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 (unsigned long long)fsid->major,
3269 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003270 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003271out_overflow:
3272 print_overflow_msg(__func__, xdr);
3273 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274}
3275
3276static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3277{
Al Viro8687b632006-10-19 23:28:48 -07003278 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
3280 *res = 60;
3281 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3282 return -EIO;
3283 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003284 p = xdr_inline_decode(xdr, 4);
3285 if (unlikely(!p))
3286 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003287 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3289 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003290 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003292out_overflow:
3293 print_overflow_msg(__func__, xdr);
3294 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295}
3296
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003297static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003298{
3299 __be32 *p;
3300
3301 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3302 return -EIO;
3303 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3304 p = xdr_inline_decode(xdr, 4);
3305 if (unlikely(!p))
3306 goto out_overflow;
3307 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003308 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003309 }
3310 return 0;
3311out_overflow:
3312 print_overflow_msg(__func__, xdr);
3313 return -EIO;
3314}
3315
3316static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3317{
3318 __be32 *p;
3319 int len;
3320
Trond Myklebust7ad07352010-10-23 15:34:20 -04003321 if (fh != NULL)
3322 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003323
3324 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3325 return -EIO;
3326 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3327 p = xdr_inline_decode(xdr, 4);
3328 if (unlikely(!p))
3329 goto out_overflow;
3330 len = be32_to_cpup(p);
3331 if (len > NFS4_FHSIZE)
3332 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003333 p = xdr_inline_decode(xdr, len);
3334 if (unlikely(!p))
3335 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003336 if (fh != NULL) {
3337 memcpy(fh->data, p, len);
3338 fh->size = len;
3339 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003340 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3341 }
3342 return 0;
3343out_overflow:
3344 print_overflow_msg(__func__, xdr);
3345 return -EIO;
3346}
3347
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3349{
Al Viro8687b632006-10-19 23:28:48 -07003350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351
3352 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3353 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3354 return -EIO;
3355 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003356 p = xdr_inline_decode(xdr, 4);
3357 if (unlikely(!p))
3358 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003359 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3361 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003362 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003364out_overflow:
3365 print_overflow_msg(__func__, xdr);
3366 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367}
3368
3369static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3370{
Al Viro8687b632006-10-19 23:28:48 -07003371 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003372 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373
3374 *fileid = 0;
3375 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3376 return -EIO;
3377 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003378 p = xdr_inline_decode(xdr, 8);
3379 if (unlikely(!p))
3380 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003381 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003383 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003385 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003386 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003387out_overflow:
3388 print_overflow_msg(__func__, xdr);
3389 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390}
3391
Manoj Naik99baf622006-06-09 09:34:24 -04003392static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3393{
Al Viro8687b632006-10-19 23:28:48 -07003394 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003395 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003396
3397 *fileid = 0;
3398 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3399 return -EIO;
3400 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003401 p = xdr_inline_decode(xdr, 8);
3402 if (unlikely(!p))
3403 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003404 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003405 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003406 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003407 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003408 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003409 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003410out_overflow:
3411 print_overflow_msg(__func__, xdr);
3412 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003413}
3414
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3416{
Al Viro8687b632006-10-19 23:28:48 -07003417 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 int status = 0;
3419
3420 *res = 0;
3421 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3422 return -EIO;
3423 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003424 p = xdr_inline_decode(xdr, 8);
3425 if (unlikely(!p))
3426 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003427 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3429 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003430 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003432out_overflow:
3433 print_overflow_msg(__func__, xdr);
3434 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435}
3436
3437static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3438{
Al Viro8687b632006-10-19 23:28:48 -07003439 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 int status = 0;
3441
3442 *res = 0;
3443 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3444 return -EIO;
3445 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003446 p = xdr_inline_decode(xdr, 8);
3447 if (unlikely(!p))
3448 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003449 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3451 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003452 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003454out_overflow:
3455 print_overflow_msg(__func__, xdr);
3456 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457}
3458
3459static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3460{
Al Viro8687b632006-10-19 23:28:48 -07003461 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 int status = 0;
3463
3464 *res = 0;
3465 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3466 return -EIO;
3467 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003468 p = xdr_inline_decode(xdr, 8);
3469 if (unlikely(!p))
3470 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003471 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3473 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003474 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003476out_overflow:
3477 print_overflow_msg(__func__, xdr);
3478 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479}
3480
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003481static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3482{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003483 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003484 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003485 int status = 0;
3486
Benny Halevyc0eae662009-08-14 17:20:14 +03003487 p = xdr_inline_decode(xdr, 4);
3488 if (unlikely(!p))
3489 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003490 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003491 if (n == 0)
3492 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003493 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003494 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3495 dprintk("cannot parse %d components in path\n", n);
3496 goto out_eio;
3497 }
3498 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003499 struct nfs4_string *component = &path->components[path->ncomponents];
3500 status = decode_opaque_inline(xdr, &component->len, &component->data);
3501 if (unlikely(status != 0))
3502 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003503 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003504 pr_cont("%s%.*s ",
3505 (path->ncomponents != n ? "/ " : ""),
3506 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003507 }
3508out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003509 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003510root_path:
3511/* a root pathname is sent as a zero component4 */
3512 path->ncomponents = 1;
3513 path->components[0].len=0;
3514 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003515 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003516 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003517out_eio:
3518 dprintk(" status %d", status);
3519 status = -EIO;
3520 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003521out_overflow:
3522 print_overflow_msg(__func__, xdr);
3523 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003524}
3525
3526static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003527{
3528 int n;
Al Viro8687b632006-10-19 23:28:48 -07003529 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003530 int status = -EIO;
3531
3532 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3533 goto out;
3534 status = 0;
3535 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3536 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003537 status = -EIO;
3538 /* Ignore borken servers that return unrequested attrs */
3539 if (unlikely(res == NULL))
3540 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003541 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003542 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003543 if (unlikely(status != 0))
3544 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003545 p = xdr_inline_decode(xdr, 4);
3546 if (unlikely(!p))
3547 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003548 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003549 if (n <= 0)
3550 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003551 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003552 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003553 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003554
Trond Myklebust809b4262013-03-27 11:54:45 -04003555 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3556 break;
3557 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003558 p = xdr_inline_decode(xdr, 4);
3559 if (unlikely(!p))
3560 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003561 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003562
Chuck Lever02a29762012-03-01 17:00:31 -05003563 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003564 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3565 struct nfs4_string *server;
3566
3567 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003568 unsigned int i;
3569 dprintk("%s: using first %u of %u servers "
3570 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003571 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003572 NFS4_FS_LOCATION_MAXSERVERS,
3573 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003574 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003575 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003576 char *data;
3577 status = decode_opaque_inline(xdr, &len, &data);
3578 if (unlikely(status != 0))
3579 goto out_eio;
3580 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003581 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003582 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003583 server = &loc->servers[loc->nservers];
3584 status = decode_opaque_inline(xdr, &server->len, &server->data);
3585 if (unlikely(status != 0))
3586 goto out_eio;
3587 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003588 }
3589 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003590 if (unlikely(status != 0))
3591 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003592 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003593 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003594 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003595out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003596 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003597 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003598out_overflow:
3599 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003600out_eio:
3601 status = -EIO;
3602 goto out;
3603}
3604
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3606{
Al Viro8687b632006-10-19 23:28:48 -07003607 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608 int status = 0;
3609
3610 *res = 0;
3611 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3612 return -EIO;
3613 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003614 p = xdr_inline_decode(xdr, 8);
3615 if (unlikely(!p))
3616 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003617 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3619 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003620 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003622out_overflow:
3623 print_overflow_msg(__func__, xdr);
3624 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625}
3626
3627static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3628{
Al Viro8687b632006-10-19 23:28:48 -07003629 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 int status = 0;
3631
3632 *maxlink = 1;
3633 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3634 return -EIO;
3635 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003636 p = xdr_inline_decode(xdr, 4);
3637 if (unlikely(!p))
3638 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003639 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3641 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003642 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003644out_overflow:
3645 print_overflow_msg(__func__, xdr);
3646 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647}
3648
3649static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3650{
Al Viro8687b632006-10-19 23:28:48 -07003651 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 int status = 0;
3653
3654 *maxname = 1024;
3655 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3656 return -EIO;
3657 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003658 p = xdr_inline_decode(xdr, 4);
3659 if (unlikely(!p))
3660 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003661 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3663 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003664 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003666out_overflow:
3667 print_overflow_msg(__func__, xdr);
3668 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669}
3670
3671static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3672{
Al Viro8687b632006-10-19 23:28:48 -07003673 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 int status = 0;
3675
3676 *res = 1024;
3677 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3678 return -EIO;
3679 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3680 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003681 p = xdr_inline_decode(xdr, 8);
3682 if (unlikely(!p))
3683 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003684 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 if (maxread > 0x7FFFFFFF)
3686 maxread = 0x7FFFFFFF;
3687 *res = (uint32_t)maxread;
3688 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3689 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003690 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003692out_overflow:
3693 print_overflow_msg(__func__, xdr);
3694 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695}
3696
3697static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3698{
Al Viro8687b632006-10-19 23:28:48 -07003699 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 int status = 0;
3701
3702 *res = 1024;
3703 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3704 return -EIO;
3705 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3706 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003707 p = xdr_inline_decode(xdr, 8);
3708 if (unlikely(!p))
3709 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003710 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 if (maxwrite > 0x7FFFFFFF)
3712 maxwrite = 0x7FFFFFFF;
3713 *res = (uint32_t)maxwrite;
3714 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3715 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003716 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003718out_overflow:
3719 print_overflow_msg(__func__, xdr);
3720 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721}
3722
Trond Myklebustbca79472009-03-11 14:10:26 -04003723static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724{
Trond Myklebustbca79472009-03-11 14:10:26 -04003725 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003726 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003727 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728
3729 *mode = 0;
3730 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3731 return -EIO;
3732 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003733 p = xdr_inline_decode(xdr, 4);
3734 if (unlikely(!p))
3735 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003736 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003737 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003739 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003741 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003742 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003743out_overflow:
3744 print_overflow_msg(__func__, xdr);
3745 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746}
3747
3748static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3749{
Al Viro8687b632006-10-19 23:28:48 -07003750 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003751 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752
3753 *nlink = 1;
3754 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3755 return -EIO;
3756 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003757 p = xdr_inline_decode(xdr, 4);
3758 if (unlikely(!p))
3759 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003760 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003762 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003764 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003765 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003766out_overflow:
3767 print_overflow_msg(__func__, xdr);
3768 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769}
3770
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003771static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003772 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003773 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774{
Al Viro8687b632006-10-19 23:28:48 -07003775 uint32_t len;
3776 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003777 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778
Eric W. Biedermane5782072013-02-01 14:22:02 -08003779 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3781 return -EIO;
3782 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003783 p = xdr_inline_decode(xdr, 4);
3784 if (unlikely(!p))
3785 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003786 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003787 p = xdr_inline_decode(xdr, len);
3788 if (unlikely(!p))
3789 goto out_overflow;
Trond Myklebust6926afd12012-01-07 13:22:46 -05003790 if (owner_name != NULL) {
3791 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3792 if (owner_name->data != NULL) {
3793 owner_name->len = len;
3794 ret = NFS_ATTR_FATTR_OWNER_NAME;
3795 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003796 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003797 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003798 ret = NFS_ATTR_FATTR_OWNER;
3799 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003801 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003803 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003804 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3806 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003807 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003808 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003809out_overflow:
3810 print_overflow_msg(__func__, xdr);
3811 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812}
3813
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003814static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003815 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003816 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817{
Al Viro8687b632006-10-19 23:28:48 -07003818 uint32_t len;
3819 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003820 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821
Eric W. Biedermane5782072013-02-01 14:22:02 -08003822 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3824 return -EIO;
3825 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003826 p = xdr_inline_decode(xdr, 4);
3827 if (unlikely(!p))
3828 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003829 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003830 p = xdr_inline_decode(xdr, len);
3831 if (unlikely(!p))
3832 goto out_overflow;
Trond Myklebust6926afd12012-01-07 13:22:46 -05003833 if (group_name != NULL) {
3834 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3835 if (group_name->data != NULL) {
3836 group_name->len = len;
3837 ret = NFS_ATTR_FATTR_GROUP_NAME;
3838 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003839 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003840 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003841 ret = NFS_ATTR_FATTR_GROUP;
3842 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003844 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003846 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003847 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3849 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003850 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003851 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003852out_overflow:
3853 print_overflow_msg(__func__, xdr);
3854 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855}
3856
3857static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3858{
Al Viro8687b632006-10-19 23:28:48 -07003859 uint32_t major = 0, minor = 0;
3860 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003861 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862
3863 *rdev = MKDEV(0,0);
3864 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3865 return -EIO;
3866 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3867 dev_t tmp;
3868
Benny Halevyc0eae662009-08-14 17:20:14 +03003869 p = xdr_inline_decode(xdr, 8);
3870 if (unlikely(!p))
3871 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003872 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003873 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 tmp = MKDEV(major, minor);
3875 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3876 *rdev = tmp;
3877 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003878 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003880 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003881 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003882out_overflow:
3883 print_overflow_msg(__func__, xdr);
3884 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885}
3886
3887static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3888{
Al Viro8687b632006-10-19 23:28:48 -07003889 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 int status = 0;
3891
3892 *res = 0;
3893 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3894 return -EIO;
3895 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003896 p = xdr_inline_decode(xdr, 8);
3897 if (unlikely(!p))
3898 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003899 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3901 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003902 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003904out_overflow:
3905 print_overflow_msg(__func__, xdr);
3906 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907}
3908
3909static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3910{
Al Viro8687b632006-10-19 23:28:48 -07003911 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 int status = 0;
3913
3914 *res = 0;
3915 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3916 return -EIO;
3917 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003918 p = xdr_inline_decode(xdr, 8);
3919 if (unlikely(!p))
3920 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003921 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3923 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003924 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003926out_overflow:
3927 print_overflow_msg(__func__, xdr);
3928 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929}
3930
3931static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3932{
Al Viro8687b632006-10-19 23:28:48 -07003933 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 int status = 0;
3935
3936 *res = 0;
3937 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3938 return -EIO;
3939 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003940 p = xdr_inline_decode(xdr, 8);
3941 if (unlikely(!p))
3942 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003943 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3945 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003946 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003948out_overflow:
3949 print_overflow_msg(__func__, xdr);
3950 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951}
3952
3953static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3954{
Al Viro8687b632006-10-19 23:28:48 -07003955 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003956 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957
3958 *used = 0;
3959 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3960 return -EIO;
3961 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003962 p = xdr_inline_decode(xdr, 8);
3963 if (unlikely(!p))
3964 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003965 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003967 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003969 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003971 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003972out_overflow:
3973 print_overflow_msg(__func__, xdr);
3974 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975}
3976
3977static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3978{
Al Viro8687b632006-10-19 23:28:48 -07003979 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 uint64_t sec;
3981 uint32_t nsec;
3982
Benny Halevyc0eae662009-08-14 17:20:14 +03003983 p = xdr_inline_decode(xdr, 12);
3984 if (unlikely(!p))
3985 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003986 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003987 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 time->tv_sec = (time_t)sec;
3989 time->tv_nsec = (long)nsec;
3990 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003991out_overflow:
3992 print_overflow_msg(__func__, xdr);
3993 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994}
3995
3996static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3997{
3998 int status = 0;
3999
4000 time->tv_sec = 0;
4001 time->tv_nsec = 0;
4002 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4003 return -EIO;
4004 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4005 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004006 if (status == 0)
4007 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4009 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004010 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 return status;
4012}
4013
4014static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4015{
4016 int status = 0;
4017
4018 time->tv_sec = 0;
4019 time->tv_nsec = 0;
4020 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4021 return -EIO;
4022 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4023 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004024 if (status == 0)
4025 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4027 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004028 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 return status;
4030}
4031
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004032static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4033 struct timespec *time)
4034{
4035 int status = 0;
4036
4037 time->tv_sec = 0;
4038 time->tv_nsec = 0;
4039 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4040 return -EIO;
4041 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4042 status = decode_attr_time(xdr, time);
4043 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4044 }
4045 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4046 (long)time->tv_nsec);
4047 return status;
4048}
4049
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4051{
4052 int status = 0;
4053
4054 time->tv_sec = 0;
4055 time->tv_nsec = 0;
4056 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4057 return -EIO;
4058 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4059 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004060 if (status == 0)
4061 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4063 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004064 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065 return status;
4066}
4067
Trond Myklebust256e48b2012-06-21 11:18:13 -04004068static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069{
4070 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004071 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072
4073 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004074 dprintk("%s: server returned incorrect attribute length: "
4075 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004076 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 attrwords << 2,
4078 (attrwords < nwords) ? '<' : '>',
4079 nwords << 2);
4080 return -EIO;
4081 }
4082 return 0;
4083}
4084
4085static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4086{
Al Viro8687b632006-10-19 23:28:48 -07004087 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088
Benny Halevyc0eae662009-08-14 17:20:14 +03004089 p = xdr_inline_decode(xdr, 20);
4090 if (unlikely(!p))
4091 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004092 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004093 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004094 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004096out_overflow:
4097 print_overflow_msg(__func__, xdr);
4098 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099}
4100
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004101static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102{
Al Viro8687b632006-10-19 23:28:48 -07004103 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104 uint32_t supp, acc;
4105 int status;
4106
4107 status = decode_op_hdr(xdr, OP_ACCESS);
4108 if (status)
4109 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004110 p = xdr_inline_decode(xdr, 8);
4111 if (unlikely(!p))
4112 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004113 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004114 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004115 *supported = supp;
4116 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004118out_overflow:
4119 print_overflow_msg(__func__, xdr);
4120 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121}
4122
Benny Halevy07d30432009-08-14 17:19:52 +03004123static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124{
Al Viro8687b632006-10-19 23:28:48 -07004125 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004126
4127 p = xdr_inline_decode(xdr, len);
4128 if (likely(p)) {
4129 memcpy(buf, p, len);
4130 return 0;
4131 }
4132 print_overflow_msg(__func__, xdr);
4133 return -EIO;
4134}
4135
4136static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4137{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004138 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139}
4140
4141static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4142{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 int status;
4144
4145 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004146 if (status != -EIO)
4147 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004148 if (!status)
4149 status = decode_stateid(xdr, &res->stateid);
4150 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151}
4152
Benny Halevydb942bb2009-08-14 17:19:56 +03004153static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4154{
Chuck Levercd937102012-03-02 17:14:31 -05004155 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156}
4157
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004158static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4159{
4160 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4161}
4162
Fred Isaman0b7c0152012-04-20 14:47:39 -04004163static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165 int status;
4166
4167 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004168 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004169 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004170 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171}
4172
4173static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4174{
Al Viro8687b632006-10-19 23:28:48 -07004175 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 uint32_t bmlen;
4177 int status;
4178
4179 status = decode_op_hdr(xdr, OP_CREATE);
4180 if (status)
4181 return status;
4182 if ((status = decode_change_info(xdr, cinfo)))
4183 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004184 p = xdr_inline_decode(xdr, 4);
4185 if (unlikely(!p))
4186 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004187 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004188 p = xdr_inline_decode(xdr, bmlen << 2);
4189 if (likely(p))
4190 return 0;
4191out_overflow:
4192 print_overflow_msg(__func__, xdr);
4193 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194}
4195
4196static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4197{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004198 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004199 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200 int status;
4201
4202 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4203 goto xdr_error;
4204 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4205 goto xdr_error;
4206 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4207 goto xdr_error;
4208 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4209 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004210 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4211 &res->fh_expire_type)) != 0)
4212 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4214 goto xdr_error;
4215 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4216 goto xdr_error;
4217 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4218 goto xdr_error;
4219 status = verify_attr_len(xdr, savep, attrlen);
4220xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004221 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 return status;
4223}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004224
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4226{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004227 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004228 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004230
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4232 goto xdr_error;
4233 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4234 goto xdr_error;
4235 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4236 goto xdr_error;
4237
4238 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4239 goto xdr_error;
4240 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4241 goto xdr_error;
4242 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4243 goto xdr_error;
4244 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4245 goto xdr_error;
4246 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4247 goto xdr_error;
4248 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4249 goto xdr_error;
4250
4251 status = verify_attr_len(xdr, savep, attrlen);
4252xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004253 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 return status;
4255}
4256
4257static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4258{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004259 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004260 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004262
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4264 goto xdr_error;
4265 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4266 goto xdr_error;
4267 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4268 goto xdr_error;
4269
4270 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4271 goto xdr_error;
4272 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4273 goto xdr_error;
4274
4275 status = verify_attr_len(xdr, savep, attrlen);
4276xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004277 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 return status;
4279}
4280
Andy Adamson88034c32012-05-23 05:02:34 -04004281static int decode_threshold_hint(struct xdr_stream *xdr,
4282 uint32_t *bitmap,
4283 uint64_t *res,
4284 uint32_t hint_bit)
4285{
4286 __be32 *p;
4287
4288 *res = 0;
4289 if (likely(bitmap[0] & hint_bit)) {
4290 p = xdr_inline_decode(xdr, 8);
4291 if (unlikely(!p))
4292 goto out_overflow;
4293 xdr_decode_hyper(p, res);
4294 }
4295 return 0;
4296out_overflow:
4297 print_overflow_msg(__func__, xdr);
4298 return -EIO;
4299}
4300
4301static int decode_first_threshold_item4(struct xdr_stream *xdr,
4302 struct nfs4_threshold *res)
4303{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004304 __be32 *p;
4305 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004306 uint32_t bitmap[3] = {0,}, attrlen;
4307 int status;
4308
4309 /* layout type */
4310 p = xdr_inline_decode(xdr, 4);
4311 if (unlikely(!p)) {
4312 print_overflow_msg(__func__, xdr);
4313 return -EIO;
4314 }
4315 res->l_type = be32_to_cpup(p);
4316
4317 /* thi_hintset bitmap */
4318 status = decode_attr_bitmap(xdr, bitmap);
4319 if (status < 0)
4320 goto xdr_error;
4321
4322 /* thi_hintlist length */
4323 status = decode_attr_length(xdr, &attrlen, &savep);
4324 if (status < 0)
4325 goto xdr_error;
4326 /* thi_hintlist */
4327 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4328 if (status < 0)
4329 goto xdr_error;
4330 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4331 if (status < 0)
4332 goto xdr_error;
4333 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4334 THRESHOLD_RD_IO);
4335 if (status < 0)
4336 goto xdr_error;
4337 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4338 THRESHOLD_WR_IO);
4339 if (status < 0)
4340 goto xdr_error;
4341
4342 status = verify_attr_len(xdr, savep, attrlen);
4343 res->bm = bitmap[0];
4344
4345 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4346 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4347 res->wr_io_sz);
4348xdr_error:
4349 dprintk("%s ret=%d!\n", __func__, status);
4350 return status;
4351}
4352
4353/*
4354 * Thresholds on pNFS direct I/O vrs MDS I/O
4355 */
4356static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4357 uint32_t *bitmap,
4358 struct nfs4_threshold *res)
4359{
4360 __be32 *p;
4361 int status = 0;
4362 uint32_t num;
4363
4364 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4365 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004366 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004367 /* Did the server return an unrequested attribute? */
4368 if (unlikely(res == NULL))
4369 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004370 p = xdr_inline_decode(xdr, 4);
4371 if (unlikely(!p))
4372 goto out_overflow;
4373 num = be32_to_cpup(p);
4374 if (num == 0)
4375 return 0;
4376 if (num > 1)
4377 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4378 "drivers per filesystem not supported\n",
4379 __func__);
4380
4381 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004382 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004383 }
4384 return status;
4385out_overflow:
4386 print_overflow_msg(__func__, xdr);
4387 return -EIO;
4388}
4389
Bryan Schumakerae42c702010-10-21 16:33:17 -04004390static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4391 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004392 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004393 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394{
Trond Myklebustbca79472009-03-11 14:10:26 -04004395 int status;
4396 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004397 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004398 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004400 status = decode_attr_type(xdr, bitmap, &type);
4401 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004403 fattr->mode = 0;
4404 if (status != 0) {
4405 fattr->mode |= nfs_type2fmt[type];
4406 fattr->valid |= status;
4407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004409 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4410 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004412 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004413
4414 status = decode_attr_size(xdr, bitmap, &fattr->size);
4415 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004417 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004418
4419 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4420 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004422 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004423
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004424 err = 0;
4425 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004426 if (status < 0)
4427 goto xdr_error;
4428
4429 status = decode_attr_filehandle(xdr, bitmap, fh);
4430 if (status < 0)
4431 goto xdr_error;
4432
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004433 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4434 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004436 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004437
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004438 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004439 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004440 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004441 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004442
4443 status = decode_attr_mode(xdr, bitmap, &fmode);
4444 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004446 if (status != 0) {
4447 fattr->mode |= fmode;
4448 fattr->valid |= status;
4449 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004450
4451 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4452 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004454 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004455
Trond Myklebust6926afd12012-01-07 13:22:46 -05004456 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004457 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004459 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004460
Trond Myklebust6926afd12012-01-07 13:22:46 -05004461 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004462 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004464 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004465
4466 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4467 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004469 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004470
4471 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4472 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004474 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004475
4476 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4477 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004479 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004480
4481 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4482 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004484 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004485
4486 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4487 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004489 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004490
Trond Myklebust28331a42011-04-27 13:47:52 -04004491 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004492 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004493 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004494 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004495
Andy Adamson88034c32012-05-23 05:02:34 -04004496 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4497 if (status < 0)
4498 goto xdr_error;
4499
Bryan Schumakerae42c702010-10-21 16:33:17 -04004500xdr_error:
4501 dprintk("%s: xdr returned %d\n", __func__, -status);
4502 return status;
4503}
4504
4505static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004506 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4507 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004508{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004509 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004510 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004511 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004512 int status;
4513
4514 status = decode_op_hdr(xdr, OP_GETATTR);
4515 if (status < 0)
4516 goto xdr_error;
4517
4518 status = decode_attr_bitmap(xdr, bitmap);
4519 if (status < 0)
4520 goto xdr_error;
4521
4522 status = decode_attr_length(xdr, &attrlen, &savep);
4523 if (status < 0)
4524 goto xdr_error;
4525
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004526 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004527 if (status < 0)
4528 goto xdr_error;
4529
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004530 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004532 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533 return status;
4534}
4535
Bryan Schumakerae42c702010-10-21 16:33:17 -04004536static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004537 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004538{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004539 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004540}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541
Andy Adamson504913f2010-10-20 00:17:57 -04004542/*
4543 * Decode potentially multiple layout types. Currently we only support
4544 * one layout driver per file system.
4545 */
4546static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4547 uint32_t *layouttype)
4548{
4549 uint32_t *p;
4550 int num;
4551
4552 p = xdr_inline_decode(xdr, 4);
4553 if (unlikely(!p))
4554 goto out_overflow;
4555 num = be32_to_cpup(p);
4556
4557 /* pNFS is not supported by the underlying file system */
4558 if (num == 0) {
4559 *layouttype = 0;
4560 return 0;
4561 }
4562 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004563 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4564 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004565
4566 /* Decode and set first layout type, move xdr->p past unused types */
4567 p = xdr_inline_decode(xdr, num * 4);
4568 if (unlikely(!p))
4569 goto out_overflow;
4570 *layouttype = be32_to_cpup(p);
4571 return 0;
4572out_overflow:
4573 print_overflow_msg(__func__, xdr);
4574 return -EIO;
4575}
4576
4577/*
4578 * The type of file system exported.
4579 * Note we must ensure that layouttype is set in any non-error case.
4580 */
4581static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4582 uint32_t *layouttype)
4583{
4584 int status = 0;
4585
4586 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4587 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4588 return -EIO;
4589 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4590 status = decode_first_pnfs_layout_type(xdr, layouttype);
4591 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4592 } else
4593 *layouttype = 0;
4594 return status;
4595}
4596
Fred Isamandae100c2011-07-30 20:52:37 -04004597/*
4598 * The prefered block size for layout directed io
4599 */
4600static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4601 uint32_t *res)
4602{
4603 __be32 *p;
4604
4605 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4606 *res = 0;
4607 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4608 p = xdr_inline_decode(xdr, 4);
4609 if (unlikely(!p)) {
4610 print_overflow_msg(__func__, xdr);
4611 return -EIO;
4612 }
4613 *res = be32_to_cpup(p);
4614 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4615 }
4616 return 0;
4617}
4618
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4620{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004621 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004622 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623 int status;
4624
4625 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4626 goto xdr_error;
4627 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4628 goto xdr_error;
4629 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4630 goto xdr_error;
4631
4632 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4633
4634 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4635 goto xdr_error;
4636 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4637 goto xdr_error;
4638 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4639 goto xdr_error;
4640 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4641 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4642 goto xdr_error;
4643 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004644 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4645 if (status != 0)
4646 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004647 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4648 if (status != 0)
4649 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004650 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4651 if (status)
4652 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004653
4654 status = verify_attr_len(xdr, savep, attrlen);
4655xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004656 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 return status;
4658}
4659
4660static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4661{
Al Viro8687b632006-10-19 23:28:48 -07004662 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004663 uint32_t len;
4664 int status;
4665
Trond Myklebust99367812007-07-17 21:52:41 -04004666 /* Zero handle first to allow comparisons */
4667 memset(fh, 0, sizeof(*fh));
4668
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669 status = decode_op_hdr(xdr, OP_GETFH);
4670 if (status)
4671 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672
Benny Halevyc0eae662009-08-14 17:20:14 +03004673 p = xdr_inline_decode(xdr, 4);
4674 if (unlikely(!p))
4675 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004676 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004677 if (len > NFS4_FHSIZE)
4678 return -EIO;
4679 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004680 p = xdr_inline_decode(xdr, len);
4681 if (unlikely(!p))
4682 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004683 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004685out_overflow:
4686 print_overflow_msg(__func__, xdr);
4687 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004688}
4689
4690static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4691{
4692 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004693
Linus Torvalds1da177e2005-04-16 15:20:36 -07004694 status = decode_op_hdr(xdr, OP_LINK);
4695 if (status)
4696 return status;
4697 return decode_change_info(xdr, cinfo);
4698}
4699
4700/*
4701 * We create the owner, so we know a proper owner.id length is 4.
4702 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004703static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004705 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004706 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004707 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004709 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004710 if (unlikely(!p))
4711 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004712 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004713 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004714 type = be32_to_cpup(p++); /* 4 byte read */
4715 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004716 fl->fl_start = (loff_t)offset;
4717 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4718 if (length == ~(uint64_t)0)
4719 fl->fl_end = OFFSET_MAX;
4720 fl->fl_type = F_WRLCK;
4721 if (type & 1)
4722 fl->fl_type = F_RDLCK;
4723 fl->fl_pid = 0;
4724 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004725 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4726 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4727 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004728 if (likely(p))
4729 return -NFS4ERR_DENIED;
4730out_overflow:
4731 print_overflow_msg(__func__, xdr);
4732 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733}
4734
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004735static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 int status;
4738
4739 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004740 if (status == -EIO)
4741 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004743 status = decode_stateid(xdr, &res->stateid);
4744 if (unlikely(status))
4745 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004747 status = decode_lock_denied(xdr, NULL);
4748 if (res->open_seqid != NULL)
4749 nfs_increment_open_seqid(status, res->open_seqid);
4750 nfs_increment_lock_seqid(status, res->lock_seqid);
4751out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752 return status;
4753}
4754
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004755static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756{
4757 int status;
4758 status = decode_op_hdr(xdr, OP_LOCKT);
4759 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004760 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004761 return status;
4762}
4763
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004764static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 int status;
4767
4768 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004769 if (status != -EIO)
4770 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004771 if (status == 0)
4772 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773 return status;
4774}
4775
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004776static int decode_release_lockowner(struct xdr_stream *xdr)
4777{
4778 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4779}
4780
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781static int decode_lookup(struct xdr_stream *xdr)
4782{
4783 return decode_op_hdr(xdr, OP_LOOKUP);
4784}
4785
4786/* This is too sick! */
4787static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4788{
Andy Adamson05d564f2008-12-23 16:06:15 -05004789 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790 uint32_t limit_type, nblocks, blocksize;
4791
Benny Halevyc0eae662009-08-14 17:20:14 +03004792 p = xdr_inline_decode(xdr, 12);
4793 if (unlikely(!p))
4794 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004795 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004797 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004798 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004799 break;
4800 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004801 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004802 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004803 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804 }
4805 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004806out_overflow:
4807 print_overflow_msg(__func__, xdr);
4808 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809}
4810
4811static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4812{
Andy Adamson05d564f2008-12-23 16:06:15 -05004813 __be32 *p;
4814 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004815 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816
Benny Halevyc0eae662009-08-14 17:20:14 +03004817 p = xdr_inline_decode(xdr, 4);
4818 if (unlikely(!p))
4819 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004820 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4822 res->delegation_type = 0;
4823 return 0;
4824 }
Benny Halevy07d30432009-08-14 17:19:52 +03004825 status = decode_stateid(xdr, &res->delegation);
4826 if (unlikely(status))
4827 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004828 p = xdr_inline_decode(xdr, 4);
4829 if (unlikely(!p))
4830 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004831 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004832
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004834 case NFS4_OPEN_DELEGATE_READ:
4835 res->delegation_type = FMODE_READ;
4836 break;
4837 case NFS4_OPEN_DELEGATE_WRITE:
4838 res->delegation_type = FMODE_WRITE|FMODE_READ;
4839 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840 return -EIO;
4841 }
David Howells7539bba2006-08-22 20:06:09 -04004842 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004843out_overflow:
4844 print_overflow_msg(__func__, xdr);
4845 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846}
4847
4848static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4849{
Andy Adamson05d564f2008-12-23 16:06:15 -05004850 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004851 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004852 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853
Andy Adamson05d564f2008-12-23 16:06:15 -05004854 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004855 if (status != -EIO)
4856 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004857 if (!status)
4858 status = decode_stateid(xdr, &res->stateid);
4859 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004860 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861
Andy Adamson05d564f2008-12-23 16:06:15 -05004862 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863
Benny Halevyc0eae662009-08-14 17:20:14 +03004864 p = xdr_inline_decode(xdr, 8);
4865 if (unlikely(!p))
4866 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004867 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004868 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004869 if (bmlen > 10)
4870 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871
Benny Halevyc0eae662009-08-14 17:20:14 +03004872 p = xdr_inline_decode(xdr, bmlen << 2);
4873 if (unlikely(!p))
4874 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004875 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4876 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004877 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004878 for (; i < NFS4_BITMAP_SIZE; i++)
4879 res->attrset[i] = 0;
4880
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 return decode_delegation(xdr, res);
4882xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004883 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004885out_overflow:
4886 print_overflow_msg(__func__, xdr);
4887 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888}
4889
4890static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4891{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892 int status;
4893
Andy Adamson05d564f2008-12-23 16:06:15 -05004894 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004895 if (status != -EIO)
4896 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004897 if (!status)
4898 status = decode_stateid(xdr, &res->stateid);
4899 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900}
4901
4902static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4903{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904 int status;
4905
4906 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004907 if (status != -EIO)
4908 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004909 if (!status)
4910 status = decode_stateid(xdr, &res->stateid);
4911 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912}
4913
4914static int decode_putfh(struct xdr_stream *xdr)
4915{
4916 return decode_op_hdr(xdr, OP_PUTFH);
4917}
4918
4919static int decode_putrootfh(struct xdr_stream *xdr)
4920{
4921 return decode_op_hdr(xdr, OP_PUTROOTFH);
4922}
4923
4924static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4925{
Al Viro8687b632006-10-19 23:28:48 -07004926 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04004927 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928 int status;
4929
4930 status = decode_op_hdr(xdr, OP_READ);
4931 if (status)
4932 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004933 p = xdr_inline_decode(xdr, 8);
4934 if (unlikely(!p))
4935 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004936 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004937 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04004938 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004940 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941 "count %u > recvd %u\n", count, recvd);
4942 count = recvd;
4943 eof = 0;
4944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945 res->eof = eof;
4946 res->count = count;
4947 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004948out_overflow:
4949 print_overflow_msg(__func__, xdr);
4950 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951}
4952
4953static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4954{
Chuck Leverbcecff72007-10-26 13:32:03 -04004955 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004956 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957
4958 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004959 if (!status)
4960 status = decode_verifier(xdr, readdir->verifier.data);
4961 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004963 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004964 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004965 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04004966 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967}
4968
4969static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4970{
4971 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04004972 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004973 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974 int status;
4975
4976 status = decode_op_hdr(xdr, OP_READLINK);
4977 if (status)
4978 return status;
4979
4980 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004981 p = xdr_inline_decode(xdr, 4);
4982 if (unlikely(!p))
4983 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004984 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004986 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 return -ENAMETOOLONG;
4988 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04004989 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004991 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992 "count %u > recvd %u\n", len, recvd);
4993 return -EIO;
4994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995 /*
4996 * The XDR encode routine has set things up so that
4997 * the link text will be copied directly into the
4998 * buffer. We just have to do overflow-checking,
4999 * and and null-terminate the text (the VFS expects
5000 * null-termination).
5001 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005002 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005004out_overflow:
5005 print_overflow_msg(__func__, xdr);
5006 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007}
5008
5009static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5010{
5011 int status;
5012
5013 status = decode_op_hdr(xdr, OP_REMOVE);
5014 if (status)
5015 goto out;
5016 status = decode_change_info(xdr, cinfo);
5017out:
5018 return status;
5019}
5020
5021static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5022 struct nfs4_change_info *new_cinfo)
5023{
5024 int status;
5025
5026 status = decode_op_hdr(xdr, OP_RENAME);
5027 if (status)
5028 goto out;
5029 if ((status = decode_change_info(xdr, old_cinfo)))
5030 goto out;
5031 status = decode_change_info(xdr, new_cinfo);
5032out:
5033 return status;
5034}
5035
5036static int decode_renew(struct xdr_stream *xdr)
5037{
5038 return decode_op_hdr(xdr, OP_RENEW);
5039}
5040
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005041static int
5042decode_restorefh(struct xdr_stream *xdr)
5043{
5044 return decode_op_hdr(xdr, OP_RESTOREFH);
5045}
5046
J. Bruce Fields029d1052005-06-22 17:16:22 +00005047static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005048 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005049{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005050 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005051 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005052 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005053 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005054 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005055
Andy Adamsonbf118a32011-12-07 11:55:27 -05005056 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005057 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5058 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005059
Trond Myklebust519d3952012-08-14 17:30:10 -04005060 xdr_enter_page(xdr, xdr->buf->page_len);
5061
Trond Myklebustcff298c2012-08-14 17:14:17 -04005062 /* Calculate the offset of the page data */
5063 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005064
J. Bruce Fields029d1052005-06-22 17:16:22 +00005065 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5066 goto out;
5067 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5068 goto out;
5069
5070 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5071 return -EIO;
5072 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005073
Andy Adamsonbf118a32011-12-07 11:55:27 -05005074 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5075 * are stored with the acl data to handle the problem of
5076 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005077 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005078 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005079
5080 /* Check for receive buffer overflow */
5081 if (res->acl_len > (xdr->nwords << 2) ||
5082 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5083 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005084 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005085 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005086 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005087 } else
5088 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005089
5090out:
5091 return status;
5092}
5093
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094static int
5095decode_savefh(struct xdr_stream *xdr)
5096{
5097 return decode_op_hdr(xdr, OP_SAVEFH);
5098}
5099
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005100static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101{
Al Viro8687b632006-10-19 23:28:48 -07005102 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103 uint32_t bmlen;
5104 int status;
5105
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106 status = decode_op_hdr(xdr, OP_SETATTR);
5107 if (status)
5108 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005109 p = xdr_inline_decode(xdr, 4);
5110 if (unlikely(!p))
5111 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005112 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005113 p = xdr_inline_decode(xdr, bmlen << 2);
5114 if (likely(p))
5115 return 0;
5116out_overflow:
5117 print_overflow_msg(__func__, xdr);
5118 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119}
5120
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005121static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122{
Al Viro8687b632006-10-19 23:28:48 -07005123 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124 uint32_t opnum;
5125 int32_t nfserr;
5126
Benny Halevyc0eae662009-08-14 17:20:14 +03005127 p = xdr_inline_decode(xdr, 8);
5128 if (unlikely(!p))
5129 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005130 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005132 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005133 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134 return -EIO;
5135 }
Benny Halevycccddf42009-08-14 17:20:19 +03005136 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005138 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5139 if (unlikely(!p))
5140 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005141 p = xdr_decode_hyper(p, &res->clientid);
5142 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143 } else if (nfserr == NFSERR_CLID_INUSE) {
5144 uint32_t len;
5145
5146 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005147 p = xdr_inline_decode(xdr, 4);
5148 if (unlikely(!p))
5149 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005150 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005151 p = xdr_inline_decode(xdr, len);
5152 if (unlikely(!p))
5153 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005154
5155 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005156 p = xdr_inline_decode(xdr, 4);
5157 if (unlikely(!p))
5158 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005159 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005160 p = xdr_inline_decode(xdr, len);
5161 if (unlikely(!p))
5162 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 return -NFSERR_CLID_INUSE;
5164 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005165 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166
5167 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005168out_overflow:
5169 print_overflow_msg(__func__, xdr);
5170 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171}
5172
5173static int decode_setclientid_confirm(struct xdr_stream *xdr)
5174{
5175 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5176}
5177
5178static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5179{
Al Viro8687b632006-10-19 23:28:48 -07005180 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181 int status;
5182
5183 status = decode_op_hdr(xdr, OP_WRITE);
5184 if (status)
5185 return status;
5186
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005187 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005188 if (unlikely(!p))
5189 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005190 res->count = be32_to_cpup(p++);
5191 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005192 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005193out_overflow:
5194 print_overflow_msg(__func__, xdr);
5195 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005196}
5197
5198static int decode_delegreturn(struct xdr_stream *xdr)
5199{
5200 return decode_op_hdr(xdr, OP_DELEGRETURN);
5201}
5202
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005203static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5204{
5205 __be32 *p;
5206
5207 p = xdr_inline_decode(xdr, 4);
5208 if (unlikely(!p))
5209 goto out_overflow;
5210 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5211 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5212 goto out_err;
5213
5214 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5215 if (unlikely(!p))
5216 goto out_overflow;
5217 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5218
5219 p = xdr_inline_decode(xdr, 8);
5220 if (unlikely(!p))
5221 goto out_overflow;
5222 flavor->gss.qop4 = be32_to_cpup(p++);
5223 flavor->gss.service = be32_to_cpup(p);
5224
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{
5236 struct nfs4_secinfo_flavor *sec_flavor;
5237 int status;
5238 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005239 int i, num_flavors;
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 Myklebust6926afd12012-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 Myklebust6926afd12012-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 Myklebust6926afd12012-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 Myklebust6926afd12012-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 Myklebust6926afd12012-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 Myklebust6926afd12012-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 Myklebust6926afd12012-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 Myklebust6926afd12012-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 Myklebust6926afd12012-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 Myklebust6926afd12012-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,
6642 struct xdr_stream *xdr,
6643 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006645 struct compound_hdr hdr;
6646 int status;
6647
Chuck Leverbf269552010-12-14 14:59:29 +00006648 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006651 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006652 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006654 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655 return status;
6656}
6657
6658/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006659 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660 */
Chuck Leverbf269552010-12-14 14:59:29 +00006661static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6662 struct xdr_stream *xdr,
6663 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006665 struct compound_hdr hdr;
6666 int status;
6667
Chuck Leverbf269552010-12-14 14:59:29 +00006668 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006669 if (status)
6670 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006671 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006672 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006673 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006674 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006675 if (status != 0)
6676 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006677 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006678 if (status != 0)
6679 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006680 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006681out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006682 return status;
6683}
6684
Trond Myklebust683b57b2006-06-09 09:34:22 -04006685/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006686 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006687 */
Chuck Leverbf269552010-12-14 14:59:29 +00006688static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6689 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006690 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006691{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006692 struct compound_hdr hdr;
6693 int status;
6694
Chuck Leverbf269552010-12-14 14:59:29 +00006695 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006696 if (status)
6697 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006698 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006699 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006700 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_putfh(xdr);
6702 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006703 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006704 status = decode_lookup(xdr);
6705 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006706 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006707 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006708 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6709 NULL, res->fs_locations,
6710 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006711out:
6712 return status;
6713}
6714
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006715/*
6716 * Decode SECINFO response
6717 */
6718static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6719 struct xdr_stream *xdr,
6720 struct nfs4_secinfo_res *res)
6721{
6722 struct compound_hdr hdr;
6723 int status;
6724
6725 status = decode_compound_hdr(xdr, &hdr);
6726 if (status)
6727 goto out;
6728 status = decode_sequence(xdr, &res->seq_res, rqstp);
6729 if (status)
6730 goto out;
6731 status = decode_putfh(xdr);
6732 if (status)
6733 goto out;
6734 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006735out:
6736 return status;
6737}
6738
Benny Halevy99fe60d2009-04-01 09:22:29 -04006739#if defined(CONFIG_NFS_V4_1)
6740/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006741 * Decode BIND_CONN_TO_SESSION response
6742 */
6743static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6744 struct xdr_stream *xdr,
6745 void *res)
6746{
6747 struct compound_hdr hdr;
6748 int status;
6749
6750 status = decode_compound_hdr(xdr, &hdr);
6751 if (!status)
6752 status = decode_bind_conn_to_session(xdr, res);
6753 return status;
6754}
6755
6756/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006757 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006758 */
Chuck Leverbf269552010-12-14 14:59:29 +00006759static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6760 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006761 void *res)
6762{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006763 struct compound_hdr hdr;
6764 int status;
6765
Chuck Leverbf269552010-12-14 14:59:29 +00006766 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006767 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006768 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006769 return status;
6770}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006771
6772/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006773 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006774 */
Chuck Leverbf269552010-12-14 14:59:29 +00006775static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6776 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006777 struct nfs41_create_session_res *res)
6778{
Andy Adamsonfc931582009-04-01 09:22:31 -04006779 struct compound_hdr hdr;
6780 int status;
6781
Chuck Leverbf269552010-12-14 14:59:29 +00006782 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006783 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006784 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006785 return status;
6786}
6787
6788/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006789 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006790 */
Chuck Leverbf269552010-12-14 14:59:29 +00006791static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6792 struct xdr_stream *xdr,
6793 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006794{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006795 struct compound_hdr hdr;
6796 int status;
6797
Chuck Leverbf269552010-12-14 14:59:29 +00006798 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006799 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006800 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006801 return status;
6802}
6803
6804/*
Trond Myklebust66245532012-05-25 17:18:09 -04006805 * Decode DESTROY_CLIENTID response
6806 */
6807static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6808 struct xdr_stream *xdr,
6809 void *res)
6810{
6811 struct compound_hdr hdr;
6812 int status;
6813
6814 status = decode_compound_hdr(xdr, &hdr);
6815 if (!status)
6816 status = decode_destroy_clientid(xdr, res);
6817 return status;
6818}
6819
6820/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006821 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006822 */
Chuck Leverbf269552010-12-14 14:59:29 +00006823static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6824 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006825 struct nfs4_sequence_res *res)
6826{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006827 struct compound_hdr hdr;
6828 int status;
6829
Chuck Leverbf269552010-12-14 14:59:29 +00006830 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006831 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006832 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006833 return status;
6834}
6835
6836/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006837 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006838 */
Chuck Leverbf269552010-12-14 14:59:29 +00006839static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6840 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006841 struct nfs4_get_lease_time_res *res)
6842{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006843 struct compound_hdr hdr;
6844 int status;
6845
Chuck Leverbf269552010-12-14 14:59:29 +00006846 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006847 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006848 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006849 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006850 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006851 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006852 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006853 return status;
6854}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006855
6856/*
6857 * Decode RECLAIM_COMPLETE response
6858 */
Chuck Leverbf269552010-12-14 14:59:29 +00006859static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6860 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006861 struct nfs41_reclaim_complete_res *res)
6862{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006863 struct compound_hdr hdr;
6864 int status;
6865
Chuck Leverbf269552010-12-14 14:59:29 +00006866 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006867 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006868 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006869 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006870 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006871 return status;
6872}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006873
6874/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006875 * Decode GETDEVICELIST response
6876 */
6877static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6878 struct xdr_stream *xdr,
6879 struct nfs4_getdevicelist_res *res)
6880{
6881 struct compound_hdr hdr;
6882 int status;
6883
6884 dprintk("encoding getdevicelist!\n");
6885
6886 status = decode_compound_hdr(xdr, &hdr);
6887 if (status != 0)
6888 goto out;
6889 status = decode_sequence(xdr, &res->seq_res, rqstp);
6890 if (status != 0)
6891 goto out;
6892 status = decode_putfh(xdr);
6893 if (status != 0)
6894 goto out;
6895 status = decode_getdevicelist(xdr, res->devlist);
6896out:
6897 return status;
6898}
6899
6900/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006901 * Decode GETDEVINFO response
6902 */
Chuck Leverbf269552010-12-14 14:59:29 +00006903static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6904 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006905 struct nfs4_getdeviceinfo_res *res)
6906{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006907 struct compound_hdr hdr;
6908 int status;
6909
Chuck Leverbf269552010-12-14 14:59:29 +00006910 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006911 if (status != 0)
6912 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006913 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006914 if (status != 0)
6915 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006916 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006917out:
6918 return status;
6919}
6920
6921/*
6922 * Decode LAYOUTGET response
6923 */
Chuck Leverbf269552010-12-14 14:59:29 +00006924static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6925 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006926 struct nfs4_layoutget_res *res)
6927{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006928 struct compound_hdr hdr;
6929 int status;
6930
Chuck Leverbf269552010-12-14 14:59:29 +00006931 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006932 if (status)
6933 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006934 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006935 if (status)
6936 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006937 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006938 if (status)
6939 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006940 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006941out:
6942 return status;
6943}
Andy Adamson863a3c62011-03-23 13:27:54 +00006944
6945/*
Benny Halevycbe82602011-05-22 19:52:37 +03006946 * Decode LAYOUTRETURN response
6947 */
6948static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6949 struct xdr_stream *xdr,
6950 struct nfs4_layoutreturn_res *res)
6951{
6952 struct compound_hdr hdr;
6953 int status;
6954
6955 status = decode_compound_hdr(xdr, &hdr);
6956 if (status)
6957 goto out;
6958 status = decode_sequence(xdr, &res->seq_res, rqstp);
6959 if (status)
6960 goto out;
6961 status = decode_putfh(xdr);
6962 if (status)
6963 goto out;
6964 status = decode_layoutreturn(xdr, res);
6965out:
6966 return status;
6967}
6968
6969/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006970 * Decode LAYOUTCOMMIT response
6971 */
6972static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6973 struct xdr_stream *xdr,
6974 struct nfs4_layoutcommit_res *res)
6975{
6976 struct compound_hdr hdr;
6977 int status;
6978
6979 status = decode_compound_hdr(xdr, &hdr);
6980 if (status)
6981 goto out;
6982 status = decode_sequence(xdr, &res->seq_res, rqstp);
6983 if (status)
6984 goto out;
6985 status = decode_putfh(xdr);
6986 if (status)
6987 goto out;
6988 status = decode_layoutcommit(xdr, rqstp, res);
6989 if (status)
6990 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006991 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006992out:
6993 return status;
6994}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006995
6996/*
6997 * Decode SECINFO_NO_NAME response
6998 */
6999static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7000 struct xdr_stream *xdr,
7001 struct nfs4_secinfo_res *res)
7002{
7003 struct compound_hdr hdr;
7004 int status;
7005
7006 status = decode_compound_hdr(xdr, &hdr);
7007 if (status)
7008 goto out;
7009 status = decode_sequence(xdr, &res->seq_res, rqstp);
7010 if (status)
7011 goto out;
7012 status = decode_putrootfh(xdr);
7013 if (status)
7014 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007015 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007016out:
7017 return status;
7018}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007019
7020/*
7021 * Decode TEST_STATEID response
7022 */
7023static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7024 struct xdr_stream *xdr,
7025 struct nfs41_test_stateid_res *res)
7026{
7027 struct compound_hdr hdr;
7028 int status;
7029
7030 status = decode_compound_hdr(xdr, &hdr);
7031 if (status)
7032 goto out;
7033 status = decode_sequence(xdr, &res->seq_res, rqstp);
7034 if (status)
7035 goto out;
7036 status = decode_test_stateid(xdr, res);
7037out:
7038 return status;
7039}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007040
7041/*
7042 * Decode FREE_STATEID response
7043 */
7044static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7045 struct xdr_stream *xdr,
7046 struct nfs41_free_stateid_res *res)
7047{
7048 struct compound_hdr hdr;
7049 int status;
7050
7051 status = decode_compound_hdr(xdr, &hdr);
7052 if (status)
7053 goto out;
7054 status = decode_sequence(xdr, &res->seq_res, rqstp);
7055 if (status)
7056 goto out;
7057 status = decode_free_stateid(xdr, res);
7058out:
7059 return status;
7060}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007061#endif /* CONFIG_NFS_V4_1 */
7062
Chuck Lever573c4e12010-12-14 14:58:11 +00007063/**
7064 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7065 * the local page cache.
7066 * @xdr: XDR stream where entry resides
7067 * @entry: buffer to fill in with entry data
7068 * @plus: boolean indicating whether this should be a readdirplus entry
7069 *
7070 * Returns zero if successful, otherwise a negative errno value is
7071 * returned.
7072 *
7073 * This function is not invoked during READDIR reply decoding, but
7074 * rather whenever an application invokes the getdents(2) system call
7075 * on a directory already in our cache.
7076 */
7077int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7078 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007079{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007080 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007081 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007082 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007083 __be32 *p = xdr_inline_decode(xdr, 4);
7084 if (unlikely(!p))
7085 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007086 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007087 p = xdr_inline_decode(xdr, 4);
7088 if (unlikely(!p))
7089 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007090 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007091 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007092 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007093 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007094 }
7095
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007096 p = xdr_inline_decode(xdr, 12);
7097 if (unlikely(!p))
7098 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007099 entry->prev_cookie = entry->cookie;
7100 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007101 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007102
Trond Myklebust9af8c222010-10-24 11:52:55 -04007103 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007104 if (unlikely(!p))
7105 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007106 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007107
7108 /*
7109 * In case the server doesn't return an inode number,
7110 * we fake one here. (We don't use inode number 0,
7111 * since glibc seems to choke on it...)
7112 */
7113 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007114 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007115
Trond Myklebust9af8c222010-10-24 11:52:55 -04007116 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007117 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007118
Trond Myklebust256e48b2012-06-21 11:18:13 -04007119 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007120 goto out_overflow;
7121
Chuck Lever573c4e12010-12-14 14:58:11 +00007122 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007123 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007124 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007125 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7126 entry->ino = entry->fattr->mounted_on_fileid;
7127 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007128 entry->ino = entry->fattr->fileid;
7129
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007130 entry->d_type = DT_UNKNOWN;
7131 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7132 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7133
Chuck Lever573c4e12010-12-14 14:58:11 +00007134 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007135
7136out_overflow:
7137 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007138 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007139}
7140
7141/*
7142 * We need to translate between nfs status return values and
7143 * the local errno values which may not be the same.
7144 */
7145static struct {
7146 int stat;
7147 int errno;
7148} nfs_errtbl[] = {
7149 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007150 { NFS4ERR_PERM, -EPERM },
7151 { NFS4ERR_NOENT, -ENOENT },
7152 { NFS4ERR_IO, -errno_NFSERR_IO},
7153 { NFS4ERR_NXIO, -ENXIO },
7154 { NFS4ERR_ACCESS, -EACCES },
7155 { NFS4ERR_EXIST, -EEXIST },
7156 { NFS4ERR_XDEV, -EXDEV },
7157 { NFS4ERR_NOTDIR, -ENOTDIR },
7158 { NFS4ERR_ISDIR, -EISDIR },
7159 { NFS4ERR_INVAL, -EINVAL },
7160 { NFS4ERR_FBIG, -EFBIG },
7161 { NFS4ERR_NOSPC, -ENOSPC },
7162 { NFS4ERR_ROFS, -EROFS },
7163 { NFS4ERR_MLINK, -EMLINK },
7164 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7165 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7166 { NFS4ERR_DQUOT, -EDQUOT },
7167 { NFS4ERR_STALE, -ESTALE },
7168 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007169 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7170 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7171 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007172 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007173 { NFS4ERR_BADTYPE, -EBADTYPE },
7174 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007175 { NFS4ERR_SYMLINK, -ELOOP },
7176 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7177 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007178 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007179};
7180
7181/*
7182 * Convert an NFS error code to a local one.
7183 * This one is used jointly by NFSv2 and NFSv3.
7184 */
7185static int
David Howells0a8ea432006-08-22 20:06:08 -04007186nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007187{
7188 int i;
7189 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7190 if (nfs_errtbl[i].stat == stat)
7191 return nfs_errtbl[i].errno;
7192 }
7193 if (stat <= 10000 || stat > 10100) {
7194 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007195 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007196 }
7197 /* If we cannot translate the error, the recovery routines should
7198 * handle it.
7199 * Note: remaining NFSv4 error codes have values > 10000, so should
7200 * not conflict with native Linux error codes.
7201 */
Benny Halevy856dff32008-03-31 17:39:06 +03007202 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007203}
7204
Linus Torvalds1da177e2005-04-16 15:20:36 -07007205#define PROC(proc, argtype, restype) \
7206[NFSPROC4_CLNT_##proc] = { \
7207 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007208 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007209 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007210 .p_arglen = NFS4_##argtype##_sz, \
7211 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007212 .p_statidx = NFSPROC4_CLNT_##proc, \
7213 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007214}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007215
7216struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007217 PROC(READ, enc_read, dec_read),
7218 PROC(WRITE, enc_write, dec_write),
7219 PROC(COMMIT, enc_commit, dec_commit),
7220 PROC(OPEN, enc_open, dec_open),
7221 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7222 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7223 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7224 PROC(CLOSE, enc_close, dec_close),
7225 PROC(SETATTR, enc_setattr, dec_setattr),
7226 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7227 PROC(RENEW, enc_renew, dec_renew),
7228 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7229 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7230 PROC(LOCK, enc_lock, dec_lock),
7231 PROC(LOCKT, enc_lockt, dec_lockt),
7232 PROC(LOCKU, enc_locku, dec_locku),
7233 PROC(ACCESS, enc_access, dec_access),
7234 PROC(GETATTR, enc_getattr, dec_getattr),
7235 PROC(LOOKUP, enc_lookup, dec_lookup),
7236 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7237 PROC(REMOVE, enc_remove, dec_remove),
7238 PROC(RENAME, enc_rename, dec_rename),
7239 PROC(LINK, enc_link, dec_link),
7240 PROC(SYMLINK, enc_symlink, dec_symlink),
7241 PROC(CREATE, enc_create, dec_create),
7242 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7243 PROC(STATFS, enc_statfs, dec_statfs),
7244 PROC(READLINK, enc_readlink, dec_readlink),
7245 PROC(READDIR, enc_readdir, dec_readdir),
7246 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7247 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7248 PROC(GETACL, enc_getacl, dec_getacl),
7249 PROC(SETACL, enc_setacl, dec_setacl),
7250 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7251 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007252 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007253#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007254 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7255 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7256 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7257 PROC(SEQUENCE, enc_sequence, dec_sequence),
7258 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7259 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7260 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7261 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007262 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007263 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007264 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007265 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007266 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007267 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007268 PROC(BIND_CONN_TO_SESSION,
7269 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007270 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007271#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007272};
7273
Trond Myklebusta613fa12012-01-20 13:53:56 -05007274const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007275 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007276 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007277 .procs = nfs4_procedures
7278};
7279
7280/*
7281 * Local variables:
7282 * c-basic-offset: 8
7283 * End:
7284 */