blob: 650fa322b903961a8e90b07c1a75ea19d3c374b1 [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{
Al Viro8687b632006-10-19 23:28:48 -07001369 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001370 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Benny Halevy13c65ce2009-08-14 17:19:25 +03001372 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001374 case 0:
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;
1378 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001379 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001380 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001381 if (nfs4_has_persistent_session(clp)) {
1382 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1383 encode_attrs(xdr, arg->u.attrs, arg->server);
1384 } else {
1385 struct iattr dummy;
1386
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);
1391 }
1392 } else {
1393 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1394 encode_nfs4_verifier(xdr, &arg->u.verifier);
1395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 }
1397}
1398
1399static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1400{
Al Viro8687b632006-10-19 23:28:48 -07001401 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Benny Halevy13c65ce2009-08-14 17:19:25 +03001403 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001405 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001406 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001407 break;
1408 default:
Benny Halevy34558512009-08-14 17:19:30 +03001409 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001410 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 }
1412}
1413
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001414static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415{
Al Viro8687b632006-10-19 23:28:48 -07001416 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Benny Halevy13c65ce2009-08-14 17:19:25 +03001418 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001420 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001421 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001422 break;
1423 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001424 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001425 break;
1426 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001427 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001428 break;
1429 default:
1430 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 }
1432}
1433
1434static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1435{
Al Viro8687b632006-10-19 23:28:48 -07001436 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Benny Halevy13c65ce2009-08-14 17:19:25 +03001438 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001439 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 encode_string(xdr, name->len, name->name);
1441}
1442
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001443static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
Al Viro8687b632006-10-19 23:28:48 -07001445 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Benny Halevy13c65ce2009-08-14 17:19:25 +03001447 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001448 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 encode_delegation_type(xdr, type);
1450}
1451
1452static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1453{
Al Viro8687b632006-10-19 23:28:48 -07001454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001456 p = reserve_space(xdr, 4);
1457 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1458 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 encode_string(xdr, name->len, name->name);
1460}
1461
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001462static inline void encode_claim_fh(struct xdr_stream *xdr)
1463{
1464 __be32 *p;
1465
1466 p = reserve_space(xdr, 4);
1467 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1468}
1469
1470static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1471{
1472 __be32 *p;
1473
1474 p = reserve_space(xdr, 4);
1475 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1476 encode_nfs4_stateid(xdr, stateid);
1477}
1478
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001479static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480{
Trond Myklebustab19b482012-03-04 18:13:57 -05001481 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 encode_openhdr(xdr, arg);
1483 encode_opentype(xdr, arg);
1484 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001485 case NFS4_OPEN_CLAIM_NULL:
1486 encode_claim_null(xdr, arg->name);
1487 break;
1488 case NFS4_OPEN_CLAIM_PREVIOUS:
1489 encode_claim_previous(xdr, arg->u.delegation_type);
1490 break;
1491 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1492 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1493 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001494 case NFS4_OPEN_CLAIM_FH:
1495 encode_claim_fh(xdr);
1496 break;
1497 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1498 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1499 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001500 default:
1501 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503}
1504
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001505static 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 -07001506{
Trond Myklebustab19b482012-03-04 18:13:57 -05001507 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001508 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001509 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}
1511
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001512static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
Trond Myklebustab19b482012-03-04 18:13:57 -05001514 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001515 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001516 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001517 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518}
1519
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001520static void
Andy Adamsond0179312008-12-23 16:06:17 -05001521encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522{
Trond Myklebustab19b482012-03-04 18:13:57 -05001523 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001524 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
1526
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001527static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
Trond Myklebustab19b482012-03-04 18:13:57 -05001529 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001532static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533{
Al Viro8687b632006-10-19 23:28:48 -07001534 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Trond Myklebustab19b482012-03-04 18:13:57 -05001536 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001537 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
Benny Halevy13c65ce2009-08-14 17:19:25 +03001539 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001540 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001541 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542}
1543
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001544static 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 -07001545{
Trond Myklebust28331a42011-04-27 13:47:52 -04001546 uint32_t attrs[2] = {
1547 FATTR4_WORD0_RDATTR_ERROR,
1548 FATTR4_WORD1_MOUNTED_ON_FILEID,
1549 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001550 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001551 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001553 if (readdir->plus) {
1554 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001555 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001556 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1557 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1558 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1559 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001560 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001561 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001562 /* Use mounted_on_fileid only if the server supports it */
1563 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1564 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001565
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001566 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001567 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001568 encode_nfs4_verifier(xdr, &readdir->verifier);
1569 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001570 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001571 *p++ = cpu_to_be32(readdir->count);
1572 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001573
Benny Halevye75bc1c2009-08-14 17:18:54 +03001574 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001575 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001576 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001577 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1578 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001579 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001580 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001581 attrs[0] & readdir->bitmask[0],
1582 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583}
1584
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001585static 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 -07001586{
Trond Myklebustab19b482012-03-04 18:13:57 -05001587 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588}
1589
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001590static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591{
Trond Myklebustab19b482012-03-04 18:13:57 -05001592 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001593 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594}
1595
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001596static 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 -07001597{
Trond Myklebustab19b482012-03-04 18:13:57 -05001598 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001599 encode_string(xdr, oldname->len, oldname->name);
1600 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601}
1602
Chuck Leverbb4dae52012-03-01 17:01:48 -05001603static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1604 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001606 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001607 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608}
1609
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001610static void
Andy Adamsond0179312008-12-23 16:06:17 -05001611encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001612{
Trond Myklebustab19b482012-03-04 18:13:57 -05001613 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001614}
1615
Chuck Lever9f06c712010-12-14 14:59:18 +00001616static void
Andy Adamsond0179312008-12-23 16:06:17 -05001617encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001618{
Al Viro8687b632006-10-19 23:28:48 -07001619 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001620
Trond Myklebustab19b482012-03-04 18:13:57 -05001621 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001622 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001623 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001624 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001625 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001626 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001627 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001628 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001629}
1630
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001631static void
Andy Adamsond0179312008-12-23 16:06:17 -05001632encode_savefh(struct xdr_stream *xdr, 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_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635}
1636
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001637static 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 -07001638{
Trond Myklebustab19b482012-03-04 18:13:57 -05001639 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001640 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001641 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642}
1643
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001644static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645{
Al Viro8687b632006-10-19 23:28:48 -07001646 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
Trond Myklebust70019512012-03-04 20:49:32 -05001648 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001649 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
1651 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001652 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001653 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1655 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001656 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001657 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
1659
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001660static 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 -07001661{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001662 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1663 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001664 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001665 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666}
1667
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001668static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669{
Al Viro8687b632006-10-19 23:28:48 -07001670 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Trond Myklebustab19b482012-03-04 18:13:57 -05001672 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001673 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
Benny Halevy13c65ce2009-08-14 17:19:25 +03001675 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001676 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001677 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001678 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
1680 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681}
1682
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001683static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684{
Trond Myklebustab19b482012-03-04 18:13:57 -05001685 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001686 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001688
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001689static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1690{
Trond Myklebustab19b482012-03-04 18:13:57 -05001691 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001692 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001693}
1694
Benny Halevy99fe60d2009-04-01 09:22:29 -04001695#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001696/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001697static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1698 struct nfs4_session *session,
1699 struct compound_hdr *hdr)
1700{
1701 __be32 *p;
1702
1703 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1704 decode_bind_conn_to_session_maxsz, hdr);
1705 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1706 p = xdr_reserve_space(xdr, 8);
1707 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1708 *p = 0; /* use_conn_in_rdma_mode = False */
1709}
1710
Benny Halevy99fe60d2009-04-01 09:22:29 -04001711static void encode_exchange_id(struct xdr_stream *xdr,
1712 struct nfs41_exchange_id_args *args,
1713 struct compound_hdr *hdr)
1714{
1715 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001716 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001717 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001718
Trond Myklebust70019512012-03-04 20:49:32 -05001719 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001720 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001721
1722 encode_string(xdr, args->id_len, args->id);
1723
Benny Halevy13c65ce2009-08-14 17:19:25 +03001724 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001725 *p++ = cpu_to_be32(args->flags);
1726 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001727
1728 if (send_implementation_id &&
1729 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1730 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001731 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001732 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1733 utsname()->sysname, utsname()->release,
1734 utsname()->version, utsname()->machine);
1735
1736 if (len > 0) {
1737 *p = cpu_to_be32(1); /* implementation id array length=1 */
1738
1739 encode_string(xdr,
1740 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1741 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1742 encode_string(xdr, len, impl_name);
1743 /* just send zeros for nii_date - the date is in nii_name */
1744 p = reserve_space(xdr, 12);
1745 p = xdr_encode_hyper(p, 0);
1746 *p = cpu_to_be32(0);
1747 } else
1748 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001749}
Andy Adamsonfc931582009-04-01 09:22:31 -04001750
1751static void encode_create_session(struct xdr_stream *xdr,
1752 struct nfs41_create_session_args *args,
1753 struct compound_hdr *hdr)
1754{
1755 __be32 *p;
1756 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1757 uint32_t len;
1758 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001759 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001760 u32 max_resp_sz_cached;
1761
1762 /*
1763 * Assumes OPEN is the biggest non-idempotent compound.
1764 * 2 is the verifier.
1765 */
1766 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1767 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001768
Andy Adamsonfc931582009-04-01 09:22:31 -04001769 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1770 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001771
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001772 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1773 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001774 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001775 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1776 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001777
Andy Adamsonfc931582009-04-01 09:22:31 -04001778 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001779 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001780 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1781 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001782 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001783 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1784 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1785 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001786
1787 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001788 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001789 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1790 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1791 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1792 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1793 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1794 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001795
Benny Halevye75bc1c2009-08-14 17:18:54 +03001796 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001797 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001798 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001799
1800 /* authsys_parms rfc1831 */
Chuck Leverf0920752012-05-21 22:45:41 -04001801 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001802 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001803 *p++ = cpu_to_be32(0); /* UID */
1804 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001805 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001806}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001807
1808static void encode_destroy_session(struct xdr_stream *xdr,
1809 struct nfs4_session *session,
1810 struct compound_hdr *hdr)
1811{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001812 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1813 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001814}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001815
Trond Myklebust66245532012-05-25 17:18:09 -04001816static void encode_destroy_clientid(struct xdr_stream *xdr,
1817 uint64_t clientid,
1818 struct compound_hdr *hdr)
1819{
1820 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1821 encode_uint64(xdr, clientid);
1822}
1823
Ricardo Labiaga180197532009-12-05 16:08:40 -05001824static void encode_reclaim_complete(struct xdr_stream *xdr,
1825 struct nfs41_reclaim_complete_args *args,
1826 struct compound_hdr *hdr)
1827{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001828 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1829 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001830}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001831#endif /* CONFIG_NFS_V4_1 */
1832
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001833static void encode_sequence(struct xdr_stream *xdr,
1834 const struct nfs4_sequence_args *args,
1835 struct compound_hdr *hdr)
1836{
1837#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001838 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001839 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001840 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001841 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001842
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001843 if (slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001844 return;
1845
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001846 tp = slot->table;
1847 session = tp->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001848
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001849 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001850
1851 /*
1852 * Sessionid + seqid + slotid + max slotid + cache_this
1853 */
1854 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1855 "max_slotid=%d cache_this=%d\n",
1856 __func__,
1857 ((u32 *)session->sess_id.data)[0],
1858 ((u32 *)session->sess_id.data)[1],
1859 ((u32 *)session->sess_id.data)[2],
1860 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001861 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001862 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001863 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001864 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001865 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001866 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001867 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001868 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001869#endif /* CONFIG_NFS_V4_1 */
1870}
1871
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001872#ifdef CONFIG_NFS_V4_1
1873static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001874encode_getdevicelist(struct xdr_stream *xdr,
1875 const struct nfs4_getdevicelist_args *args,
1876 struct compound_hdr *hdr)
1877{
1878 __be32 *p;
1879 nfs4_verifier dummy = {
1880 .data = "dummmmmy",
1881 };
1882
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001883 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1884 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001885 *p++ = cpu_to_be32(args->layoutclass);
1886 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1887 xdr_encode_hyper(p, 0ULL); /* cookie */
1888 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001889}
1890
1891static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001892encode_getdeviceinfo(struct xdr_stream *xdr,
1893 const struct nfs4_getdeviceinfo_args *args,
1894 struct compound_hdr *hdr)
1895{
1896 __be32 *p;
1897
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001898 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1899 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001900 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1901 NFS4_DEVICEID4_SIZE);
1902 *p++ = cpu_to_be32(args->pdev->layout_type);
1903 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1904 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001905}
1906
1907static void
1908encode_layoutget(struct xdr_stream *xdr,
1909 const struct nfs4_layoutget_args *args,
1910 struct compound_hdr *hdr)
1911{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001912 __be32 *p;
1913
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001914 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1915 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001916 *p++ = cpu_to_be32(0); /* Signal layout available */
1917 *p++ = cpu_to_be32(args->type);
1918 *p++ = cpu_to_be32(args->range.iomode);
1919 p = xdr_encode_hyper(p, args->range.offset);
1920 p = xdr_encode_hyper(p, args->range.length);
1921 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001922 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001923 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001924
1925 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1926 __func__,
1927 args->type,
1928 args->range.iomode,
1929 (unsigned long)args->range.offset,
1930 (unsigned long)args->range.length,
1931 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001932}
Andy Adamson863a3c62011-03-23 13:27:54 +00001933
1934static int
1935encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001936 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001937 const struct nfs4_layoutcommit_args *args,
1938 struct compound_hdr *hdr)
1939{
1940 __be32 *p;
1941
1942 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1943 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1944
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001945 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1946 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001947 /* Only whole file layouts */
1948 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001949 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001950 *p = cpu_to_be32(0); /* reclaim */
1951 encode_nfs4_stateid(xdr, &args->stateid);
1952 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001953 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1954 p = xdr_encode_hyper(p, args->lastbytewritten);
1955 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1956 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001957
1958 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1959 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1960 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001961 else
1962 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001963
Andy Adamson863a3c62011-03-23 13:27:54 +00001964 return 0;
1965}
Benny Halevycbe82602011-05-22 19:52:37 +03001966
1967static void
1968encode_layoutreturn(struct xdr_stream *xdr,
1969 const struct nfs4_layoutreturn_args *args,
1970 struct compound_hdr *hdr)
1971{
1972 __be32 *p;
1973
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001974 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1975 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001976 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1977 *p++ = cpu_to_be32(args->layout_type);
1978 *p++ = cpu_to_be32(IOMODE_ANY);
1979 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001980 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001981 p = xdr_encode_hyper(p, 0);
1982 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1983 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001984 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001985 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001986 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1987 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1988 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001989 } else
1990 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001991}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001992
1993static int
1994encode_secinfo_no_name(struct xdr_stream *xdr,
1995 const struct nfs41_secinfo_no_name_args *args,
1996 struct compound_hdr *hdr)
1997{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001998 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1999 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002000 return 0;
2001}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002002
2003static void encode_test_stateid(struct xdr_stream *xdr,
2004 struct nfs41_test_stateid_args *args,
2005 struct compound_hdr *hdr)
2006{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002007 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2008 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002009 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002010}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002011
2012static void encode_free_stateid(struct xdr_stream *xdr,
2013 struct nfs41_free_stateid_args *args,
2014 struct compound_hdr *hdr)
2015{
Trond Myklebustab19b482012-03-04 18:13:57 -05002016 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002017 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002018}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002019#endif /* CONFIG_NFS_V4_1 */
2020
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021/*
2022 * END OF "GENERIC" ENCODE ROUTINES.
2023 */
2024
Benny Halevy66cc0422009-04-01 09:22:10 -04002025static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2026{
2027#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05002028
2029 if (args->sa_slot)
2030 return args->sa_slot->table->session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002031#endif /* CONFIG_NFS_V4_1 */
2032 return 0;
2033}
2034
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035/*
2036 * Encode an ACCESS request
2037 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002038static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2039 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002042 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
Chuck Lever9f06c712010-12-14 14:59:18 +00002045 encode_compound_hdr(xdr, req, &hdr);
2046 encode_sequence(xdr, &args->seq_args, &hdr);
2047 encode_putfh(xdr, args->fh, &hdr);
2048 encode_access(xdr, args->access, &hdr);
2049 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002050 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051}
2052
2053/*
2054 * Encode LOOKUP request
2055 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002056static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2057 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002060 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
Chuck Lever9f06c712010-12-14 14:59:18 +00002063 encode_compound_hdr(xdr, req, &hdr);
2064 encode_sequence(xdr, &args->seq_args, &hdr);
2065 encode_putfh(xdr, args->dir_fh, &hdr);
2066 encode_lookup(xdr, args->name, &hdr);
2067 encode_getfh(xdr, &hdr);
2068 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002069 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070}
2071
2072/*
2073 * Encode LOOKUP_ROOT request
2074 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002075static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2076 struct xdr_stream *xdr,
2077 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002080 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
Chuck Lever9f06c712010-12-14 14:59:18 +00002083 encode_compound_hdr(xdr, req, &hdr);
2084 encode_sequence(xdr, &args->seq_args, &hdr);
2085 encode_putrootfh(xdr, &hdr);
2086 encode_getfh(xdr, &hdr);
2087 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002088 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089}
2090
2091/*
2092 * Encode REMOVE request
2093 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002094static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2095 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002098 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Chuck Lever9f06c712010-12-14 14:59:18 +00002101 encode_compound_hdr(xdr, req, &hdr);
2102 encode_sequence(xdr, &args->seq_args, &hdr);
2103 encode_putfh(xdr, args->fh, &hdr);
2104 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002105 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
2108/*
2109 * Encode RENAME request
2110 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002111static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2112 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
Chuck Lever9f06c712010-12-14 14:59:18 +00002118 encode_compound_hdr(xdr, req, &hdr);
2119 encode_sequence(xdr, &args->seq_args, &hdr);
2120 encode_putfh(xdr, args->old_dir, &hdr);
2121 encode_savefh(xdr, &hdr);
2122 encode_putfh(xdr, args->new_dir, &hdr);
2123 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002124 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125}
2126
2127/*
2128 * Encode LINK request
2129 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002130static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2131 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002134 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
Chuck Lever9f06c712010-12-14 14:59:18 +00002137 encode_compound_hdr(xdr, req, &hdr);
2138 encode_sequence(xdr, &args->seq_args, &hdr);
2139 encode_putfh(xdr, args->fh, &hdr);
2140 encode_savefh(xdr, &hdr);
2141 encode_putfh(xdr, args->dir_fh, &hdr);
2142 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002143 encode_restorefh(xdr, &hdr);
2144 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002145 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146}
2147
2148/*
2149 * Encode CREATE request
2150 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002151static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2152 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002155 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
Chuck Lever9f06c712010-12-14 14:59:18 +00002158 encode_compound_hdr(xdr, req, &hdr);
2159 encode_sequence(xdr, &args->seq_args, &hdr);
2160 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002161 encode_create(xdr, args, &hdr);
2162 encode_getfh(xdr, &hdr);
2163 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002164 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165}
2166
2167/*
2168 * Encode SYMLINK request
2169 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002170static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2171 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
Chuck Lever9f06c712010-12-14 14:59:18 +00002173 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174}
2175
2176/*
2177 * Encode GETATTR request
2178 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002179static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2180 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002183 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
Chuck Lever9f06c712010-12-14 14:59:18 +00002186 encode_compound_hdr(xdr, req, &hdr);
2187 encode_sequence(xdr, &args->seq_args, &hdr);
2188 encode_putfh(xdr, args->fh, &hdr);
2189 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002190 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191}
2192
2193/*
2194 * Encode a CLOSE request
2195 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002196static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2197 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198{
Andy Adamson05d564f2008-12-23 16:06:15 -05002199 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002200 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002201 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
Chuck Lever9f06c712010-12-14 14:59:18 +00002203 encode_compound_hdr(xdr, req, &hdr);
2204 encode_sequence(xdr, &args->seq_args, &hdr);
2205 encode_putfh(xdr, args->fh, &hdr);
2206 encode_close(xdr, args, &hdr);
2207 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002208 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209}
2210
2211/*
2212 * Encode an OPEN request
2213 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002214static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2215 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002218 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
Chuck Lever9f06c712010-12-14 14:59:18 +00002221 encode_compound_hdr(xdr, req, &hdr);
2222 encode_sequence(xdr, &args->seq_args, &hdr);
2223 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002224 encode_open(xdr, args, &hdr);
2225 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002226 if (args->access)
2227 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002228 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002229 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230}
2231
2232/*
2233 * Encode an OPEN_CONFIRM request
2234 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002235static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2236 struct xdr_stream *xdr,
2237 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002240 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Chuck Lever9f06c712010-12-14 14:59:18 +00002243 encode_compound_hdr(xdr, req, &hdr);
2244 encode_putfh(xdr, args->fh, &hdr);
2245 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002246 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247}
2248
2249/*
2250 * Encode an OPEN request with no attributes.
2251 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002252static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2253 struct xdr_stream *xdr,
2254 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002257 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
Chuck Lever9f06c712010-12-14 14:59:18 +00002260 encode_compound_hdr(xdr, req, &hdr);
2261 encode_sequence(xdr, &args->seq_args, &hdr);
2262 encode_putfh(xdr, args->fh, &hdr);
2263 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002264 if (args->access)
2265 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002266 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002267 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268}
2269
2270/*
2271 * Encode an OPEN_DOWNGRADE request
2272 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002273static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2274 struct xdr_stream *xdr,
2275 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002278 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
Chuck Lever9f06c712010-12-14 14:59:18 +00002281 encode_compound_hdr(xdr, req, &hdr);
2282 encode_sequence(xdr, &args->seq_args, &hdr);
2283 encode_putfh(xdr, args->fh, &hdr);
2284 encode_open_downgrade(xdr, args, &hdr);
2285 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002286 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287}
2288
2289/*
2290 * Encode a LOCK request
2291 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002292static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2293 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002296 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Chuck Lever9f06c712010-12-14 14:59:18 +00002299 encode_compound_hdr(xdr, req, &hdr);
2300 encode_sequence(xdr, &args->seq_args, &hdr);
2301 encode_putfh(xdr, args->fh, &hdr);
2302 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002303 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304}
2305
2306/*
2307 * Encode a LOCKT request
2308 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002309static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2310 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002313 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Chuck Lever9f06c712010-12-14 14:59:18 +00002316 encode_compound_hdr(xdr, req, &hdr);
2317 encode_sequence(xdr, &args->seq_args, &hdr);
2318 encode_putfh(xdr, args->fh, &hdr);
2319 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002320 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321}
2322
2323/*
2324 * Encode a LOCKU request
2325 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002326static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2327 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002330 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
Chuck Lever9f06c712010-12-14 14:59:18 +00002333 encode_compound_hdr(xdr, req, &hdr);
2334 encode_sequence(xdr, &args->seq_args, &hdr);
2335 encode_putfh(xdr, args->fh, &hdr);
2336 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002337 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338}
2339
Chuck Lever9f06c712010-12-14 14:59:18 +00002340static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2341 struct xdr_stream *xdr,
2342 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002343{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002344 struct compound_hdr hdr = {
2345 .minorversion = 0,
2346 };
2347
Chuck Lever9f06c712010-12-14 14:59:18 +00002348 encode_compound_hdr(xdr, req, &hdr);
2349 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002350 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002351}
2352
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353/*
2354 * Encode a READLINK request
2355 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002356static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2357 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002360 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Chuck Lever9f06c712010-12-14 14:59:18 +00002363 encode_compound_hdr(xdr, req, &hdr);
2364 encode_sequence(xdr, &args->seq_args, &hdr);
2365 encode_putfh(xdr, args->fh, &hdr);
2366 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002367
Benny Halevy28f56692009-04-01 09:22:09 -04002368 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002369 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002370 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371}
2372
2373/*
2374 * Encode a READDIR request
2375 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002376static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2377 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002380 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
Chuck Lever9f06c712010-12-14 14:59:18 +00002383 encode_compound_hdr(xdr, req, &hdr);
2384 encode_sequence(xdr, &args->seq_args, &hdr);
2385 encode_putfh(xdr, args->fh, &hdr);
2386 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002387
Benny Halevy28f56692009-04-01 09:22:09 -04002388 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002389 args->pgbase, args->count);
2390 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002391 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002392 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002393 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394}
2395
2396/*
2397 * Encode a READ request
2398 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002399static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2400 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002403 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
Chuck Lever9f06c712010-12-14 14:59:18 +00002406 encode_compound_hdr(xdr, req, &hdr);
2407 encode_sequence(xdr, &args->seq_args, &hdr);
2408 encode_putfh(xdr, args->fh, &hdr);
2409 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
Benny Halevy28f56692009-04-01 09:22:09 -04002411 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002413 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002414 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415}
2416
2417/*
2418 * Encode an SETATTR request
2419 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002420static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2421 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422{
Andy Adamson05d564f2008-12-23 16:06:15 -05002423 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002424 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002425 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426
Chuck Lever9f06c712010-12-14 14:59:18 +00002427 encode_compound_hdr(xdr, req, &hdr);
2428 encode_sequence(xdr, &args->seq_args, &hdr);
2429 encode_putfh(xdr, args->fh, &hdr);
2430 encode_setattr(xdr, args, args->server, &hdr);
2431 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002432 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433}
2434
2435/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002436 * Encode a GETACL request
2437 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002438static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2439 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002440{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002441 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002442 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002443 };
Benny Halevy28f56692009-04-01 09:22:09 -04002444 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002445
Chuck Lever9f06c712010-12-14 14:59:18 +00002446 encode_compound_hdr(xdr, req, &hdr);
2447 encode_sequence(xdr, &args->seq_args, &hdr);
2448 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002449 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002450 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002451
Benny Halevy28f56692009-04-01 09:22:09 -04002452 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002453 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002454
Andy Adamsond0179312008-12-23 16:06:17 -05002455 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002456}
2457
2458/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 * Encode a WRITE request
2460 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002461static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2462 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002465 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467
Chuck Lever9f06c712010-12-14 14:59:18 +00002468 encode_compound_hdr(xdr, req, &hdr);
2469 encode_sequence(xdr, &args->seq_args, &hdr);
2470 encode_putfh(xdr, args->fh, &hdr);
2471 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002472 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002473 if (args->bitmask)
2474 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002475 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476}
2477
2478/*
2479 * a COMMIT request
2480 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002481static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002482 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002485 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
Chuck Lever9f06c712010-12-14 14:59:18 +00002488 encode_compound_hdr(xdr, req, &hdr);
2489 encode_sequence(xdr, &args->seq_args, &hdr);
2490 encode_putfh(xdr, args->fh, &hdr);
2491 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002492 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493}
2494
2495/*
2496 * FSINFO request
2497 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002498static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2499 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002502 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504
Chuck Lever9f06c712010-12-14 14:59:18 +00002505 encode_compound_hdr(xdr, req, &hdr);
2506 encode_sequence(xdr, &args->seq_args, &hdr);
2507 encode_putfh(xdr, args->fh, &hdr);
2508 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002509 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510}
2511
2512/*
2513 * a PATHCONF request
2514 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002515static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2516 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002519 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
Chuck Lever9f06c712010-12-14 14:59:18 +00002522 encode_compound_hdr(xdr, req, &hdr);
2523 encode_sequence(xdr, &args->seq_args, &hdr);
2524 encode_putfh(xdr, args->fh, &hdr);
2525 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002526 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002527 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528}
2529
2530/*
2531 * a STATFS request
2532 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002533static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2534 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002537 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
Chuck Lever9f06c712010-12-14 14:59:18 +00002540 encode_compound_hdr(xdr, req, &hdr);
2541 encode_sequence(xdr, &args->seq_args, &hdr);
2542 encode_putfh(xdr, args->fh, &hdr);
2543 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002544 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002545 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546}
2547
2548/*
2549 * GETATTR_BITMAP request
2550 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002551static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2552 struct xdr_stream *xdr,
2553 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002556 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
Chuck Lever9f06c712010-12-14 14:59:18 +00002559 encode_compound_hdr(xdr, req, &hdr);
2560 encode_sequence(xdr, &args->seq_args, &hdr);
2561 encode_putfh(xdr, args->fhandle, &hdr);
2562 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002563 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002564 FATTR4_WORD0_LINK_SUPPORT|
2565 FATTR4_WORD0_SYMLINK_SUPPORT|
2566 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002567 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568}
2569
2570/*
2571 * a RENEW request
2572 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002573static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2574 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002577 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 };
2579
Chuck Lever9f06c712010-12-14 14:59:18 +00002580 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002581 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002582 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583}
2584
2585/*
2586 * a SETCLIENTID request
2587 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002588static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2589 struct xdr_stream *xdr,
2590 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002593 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 };
2595
Chuck Lever9f06c712010-12-14 14:59:18 +00002596 encode_compound_hdr(xdr, req, &hdr);
2597 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002598 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599}
2600
2601/*
2602 * a SETCLIENTID_CONFIRM request
2603 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002604static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2605 struct xdr_stream *xdr,
2606 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002609 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 };
Fred Isamandae100c2011-07-30 20:52:37 -04002611 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
Chuck Lever9f06c712010-12-14 14:59:18 +00002613 encode_compound_hdr(xdr, req, &hdr);
2614 encode_setclientid_confirm(xdr, arg, &hdr);
2615 encode_putrootfh(xdr, &hdr);
2616 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002617 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618}
2619
2620/*
2621 * DELEGRETURN request
2622 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002623static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2624 struct xdr_stream *xdr,
2625 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002628 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
Chuck Lever9f06c712010-12-14 14:59:18 +00002631 encode_compound_hdr(xdr, req, &hdr);
2632 encode_sequence(xdr, &args->seq_args, &hdr);
2633 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002634 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002635 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002636 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637}
2638
2639/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002640 * Encode FS_LOCATIONS request
2641 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002642static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2643 struct xdr_stream *xdr,
2644 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002645{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002646 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002647 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002648 };
Benny Halevy28f56692009-04-01 09:22:09 -04002649 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002650
Chuck Lever9f06c712010-12-14 14:59:18 +00002651 encode_compound_hdr(xdr, req, &hdr);
2652 encode_sequence(xdr, &args->seq_args, &hdr);
2653 encode_putfh(xdr, args->dir_fh, &hdr);
2654 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002655 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002656 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002657
Benny Halevy28f56692009-04-01 09:22:09 -04002658 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002659 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002660 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002661}
2662
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002663/*
2664 * Encode SECINFO request
2665 */
2666static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2667 struct xdr_stream *xdr,
2668 struct nfs4_secinfo_arg *args)
2669{
2670 struct compound_hdr hdr = {
2671 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2672 };
2673
2674 encode_compound_hdr(xdr, req, &hdr);
2675 encode_sequence(xdr, &args->seq_args, &hdr);
2676 encode_putfh(xdr, args->dir_fh, &hdr);
2677 encode_secinfo(xdr, args->name, &hdr);
2678 encode_nops(&hdr);
2679}
2680
Benny Halevy99fe60d2009-04-01 09:22:29 -04002681#if defined(CONFIG_NFS_V4_1)
2682/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002683 * BIND_CONN_TO_SESSION request
2684 */
2685static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2686 struct xdr_stream *xdr,
2687 struct nfs_client *clp)
2688{
2689 struct compound_hdr hdr = {
2690 .minorversion = clp->cl_mvops->minor_version,
2691 };
2692
2693 encode_compound_hdr(xdr, req, &hdr);
2694 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2695 encode_nops(&hdr);
2696}
2697
2698/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002699 * EXCHANGE_ID request
2700 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002701static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2702 struct xdr_stream *xdr,
2703 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002704{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002705 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002706 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002707 };
2708
Chuck Lever9f06c712010-12-14 14:59:18 +00002709 encode_compound_hdr(xdr, req, &hdr);
2710 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002711 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002712}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002713
2714/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002715 * a CREATE_SESSION request
2716 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002717static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2718 struct xdr_stream *xdr,
2719 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002720{
Andy Adamsonfc931582009-04-01 09:22:31 -04002721 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002722 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002723 };
2724
Chuck Lever9f06c712010-12-14 14:59:18 +00002725 encode_compound_hdr(xdr, req, &hdr);
2726 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002727 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002728}
2729
2730/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002731 * a DESTROY_SESSION request
2732 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002733static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2734 struct xdr_stream *xdr,
2735 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002736{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002737 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002738 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002739 };
2740
Chuck Lever9f06c712010-12-14 14:59:18 +00002741 encode_compound_hdr(xdr, req, &hdr);
2742 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002743 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002744}
2745
2746/*
Trond Myklebust66245532012-05-25 17:18:09 -04002747 * a DESTROY_CLIENTID request
2748 */
2749static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2750 struct xdr_stream *xdr,
2751 struct nfs_client *clp)
2752{
2753 struct compound_hdr hdr = {
2754 .minorversion = clp->cl_mvops->minor_version,
2755 };
2756
2757 encode_compound_hdr(xdr, req, &hdr);
2758 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2759 encode_nops(&hdr);
2760}
2761
2762/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002763 * a SEQUENCE request
2764 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002765static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2766 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002767{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002768 struct compound_hdr hdr = {
2769 .minorversion = nfs4_xdr_minorversion(args),
2770 };
2771
Chuck Lever9f06c712010-12-14 14:59:18 +00002772 encode_compound_hdr(xdr, req, &hdr);
2773 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002774 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002775}
2776
2777/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002778 * a GET_LEASE_TIME request
2779 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002780static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2781 struct xdr_stream *xdr,
2782 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002783{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002784 struct compound_hdr hdr = {
2785 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2786 };
Fred Isamandae100c2011-07-30 20:52:37 -04002787 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002788
Chuck Lever9f06c712010-12-14 14:59:18 +00002789 encode_compound_hdr(xdr, req, &hdr);
2790 encode_sequence(xdr, &args->la_seq_args, &hdr);
2791 encode_putrootfh(xdr, &hdr);
2792 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002793 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002794}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002795
2796/*
2797 * a RECLAIM_COMPLETE request
2798 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002799static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2800 struct xdr_stream *xdr,
2801 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002802{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002803 struct compound_hdr hdr = {
2804 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2805 };
2806
Chuck Lever9f06c712010-12-14 14:59:18 +00002807 encode_compound_hdr(xdr, req, &hdr);
2808 encode_sequence(xdr, &args->seq_args, &hdr);
2809 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002810 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002811}
2812
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002813/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002814 * Encode GETDEVICELIST request
2815 */
2816static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2817 struct xdr_stream *xdr,
2818 struct nfs4_getdevicelist_args *args)
2819{
2820 struct compound_hdr hdr = {
2821 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2822 };
2823
2824 encode_compound_hdr(xdr, req, &hdr);
2825 encode_sequence(xdr, &args->seq_args, &hdr);
2826 encode_putfh(xdr, args->fh, &hdr);
2827 encode_getdevicelist(xdr, args, &hdr);
2828 encode_nops(&hdr);
2829}
2830
2831/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002832 * Encode GETDEVICEINFO request
2833 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002834static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2835 struct xdr_stream *xdr,
2836 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002837{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002838 struct compound_hdr hdr = {
2839 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2840 };
2841
Chuck Lever9f06c712010-12-14 14:59:18 +00002842 encode_compound_hdr(xdr, req, &hdr);
2843 encode_sequence(xdr, &args->seq_args, &hdr);
2844 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002845
2846 /* set up reply kvec. Subtract notification bitmap max size (2)
2847 * so that notification bitmap is put in xdr_buf tail */
2848 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2849 args->pdev->pages, args->pdev->pgbase,
2850 args->pdev->pglen);
2851
2852 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002853}
2854
2855/*
2856 * Encode LAYOUTGET request
2857 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002858static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2859 struct xdr_stream *xdr,
2860 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002861{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002862 struct compound_hdr hdr = {
2863 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2864 };
2865
Chuck Lever9f06c712010-12-14 14:59:18 +00002866 encode_compound_hdr(xdr, req, &hdr);
2867 encode_sequence(xdr, &args->seq_args, &hdr);
2868 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2869 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002870
2871 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2872 args->layout.pages, 0, args->layout.pglen);
2873
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002874 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002875}
Andy Adamson863a3c62011-03-23 13:27:54 +00002876
2877/*
2878 * Encode LAYOUTCOMMIT request
2879 */
Benny Halevycbe82602011-05-22 19:52:37 +03002880static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2881 struct xdr_stream *xdr,
2882 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002883{
Benny Halevyac7db722011-05-22 19:53:48 +03002884 struct nfs4_layoutcommit_data *data =
2885 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002886 struct compound_hdr hdr = {
2887 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2888 };
2889
2890 encode_compound_hdr(xdr, req, &hdr);
2891 encode_sequence(xdr, &args->seq_args, &hdr);
2892 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002893 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002894 encode_getfattr(xdr, args->bitmask, &hdr);
2895 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002896}
2897
2898/*
2899 * Encode LAYOUTRETURN request
2900 */
2901static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2902 struct xdr_stream *xdr,
2903 struct nfs4_layoutreturn_args *args)
2904{
2905 struct compound_hdr hdr = {
2906 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2907 };
2908
2909 encode_compound_hdr(xdr, req, &hdr);
2910 encode_sequence(xdr, &args->seq_args, &hdr);
2911 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2912 encode_layoutreturn(xdr, args, &hdr);
2913 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002914}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002915
2916/*
2917 * Encode SECINFO_NO_NAME request
2918 */
2919static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2920 struct xdr_stream *xdr,
2921 struct nfs41_secinfo_no_name_args *args)
2922{
2923 struct compound_hdr hdr = {
2924 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2925 };
2926
2927 encode_compound_hdr(xdr, req, &hdr);
2928 encode_sequence(xdr, &args->seq_args, &hdr);
2929 encode_putrootfh(xdr, &hdr);
2930 encode_secinfo_no_name(xdr, args, &hdr);
2931 encode_nops(&hdr);
2932 return 0;
2933}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002934
2935/*
2936 * Encode TEST_STATEID request
2937 */
2938static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2939 struct xdr_stream *xdr,
2940 struct nfs41_test_stateid_args *args)
2941{
2942 struct compound_hdr hdr = {
2943 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2944 };
2945
2946 encode_compound_hdr(xdr, req, &hdr);
2947 encode_sequence(xdr, &args->seq_args, &hdr);
2948 encode_test_stateid(xdr, args, &hdr);
2949 encode_nops(&hdr);
2950}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002951
2952/*
2953 * Encode FREE_STATEID request
2954 */
2955static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2956 struct xdr_stream *xdr,
2957 struct nfs41_free_stateid_args *args)
2958{
2959 struct compound_hdr hdr = {
2960 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2961 };
2962
2963 encode_compound_hdr(xdr, req, &hdr);
2964 encode_sequence(xdr, &args->seq_args, &hdr);
2965 encode_free_stateid(xdr, args, &hdr);
2966 encode_nops(&hdr);
2967}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002968#endif /* CONFIG_NFS_V4_1 */
2969
Benny Halevy686841b2009-08-14 17:19:48 +03002970static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2971{
2972 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2973 "Remaining buffer length is %tu words.\n",
2974 func, xdr->end - xdr->p);
2975}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976
Trond Myklebust683b57b2006-06-09 09:34:22 -04002977static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978{
Al Viro8687b632006-10-19 23:28:48 -07002979 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980
Benny Halevyc0eae662009-08-14 17:20:14 +03002981 p = xdr_inline_decode(xdr, 4);
2982 if (unlikely(!p))
2983 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002984 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002985 p = xdr_inline_decode(xdr, *len);
2986 if (unlikely(!p))
2987 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 *string = (char *)p;
2989 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002990out_overflow:
2991 print_overflow_msg(__func__, xdr);
2992 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993}
2994
2995static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2996{
Al Viro8687b632006-10-19 23:28:48 -07002997 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998
Benny Halevyc0eae662009-08-14 17:20:14 +03002999 p = xdr_inline_decode(xdr, 8);
3000 if (unlikely(!p))
3001 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003002 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003003 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003004
Benny Halevyc0eae662009-08-14 17:20:14 +03003005 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3006 if (unlikely(!p))
3007 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 hdr->tag = (char *)p;
3009 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003010 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003011 if (unlikely(hdr->nops < 1))
3012 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003014out_overflow:
3015 print_overflow_msg(__func__, xdr);
3016 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017}
3018
3019static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3020{
Al Viro8687b632006-10-19 23:28:48 -07003021 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 uint32_t opnum;
3023 int32_t nfserr;
3024
Benny Halevyc0eae662009-08-14 17:20:14 +03003025 p = xdr_inline_decode(xdr, 8);
3026 if (unlikely(!p))
3027 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003028 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003030 dprintk("nfs: Server returned operation"
3031 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 opnum, expected);
3033 return -EIO;
3034 }
Benny Halevycccddf42009-08-14 17:20:19 +03003035 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003037 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003039out_overflow:
3040 print_overflow_msg(__func__, xdr);
3041 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042}
3043
3044/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003045static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046{
Al Viro8687b632006-10-19 23:28:48 -07003047 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003048 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 char *str;
3050
Benny Halevyc0eae662009-08-14 17:20:14 +03003051 p = xdr_inline_decode(xdr, 12);
3052 if (likely(p))
3053 return decode_opaque_inline(xdr, &strlen, &str);
3054 print_overflow_msg(__func__, xdr);
3055 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056}
3057
3058static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3059{
Al Viro8687b632006-10-19 23:28:48 -07003060 uint32_t bmlen;
3061 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
Benny Halevyc0eae662009-08-14 17:20:14 +03003063 p = xdr_inline_decode(xdr, 4);
3064 if (unlikely(!p))
3065 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003066 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067
Fred Isamandae100c2011-07-30 20:52:37 -04003068 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003069 p = xdr_inline_decode(xdr, (bmlen << 2));
3070 if (unlikely(!p))
3071 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003073 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003074 if (bmlen > 1) {
3075 bitmap[1] = be32_to_cpup(p++);
3076 if (bmlen > 2)
3077 bitmap[2] = be32_to_cpup(p);
3078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 }
3080 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003081out_overflow:
3082 print_overflow_msg(__func__, xdr);
3083 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084}
3085
Trond Myklebust256e48b2012-06-21 11:18:13 -04003086static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087{
Al Viro8687b632006-10-19 23:28:48 -07003088 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089
Benny Halevyc0eae662009-08-14 17:20:14 +03003090 p = xdr_inline_decode(xdr, 4);
3091 if (unlikely(!p))
3092 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003093 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003094 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003096out_overflow:
3097 print_overflow_msg(__func__, xdr);
3098 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099}
3100
3101static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3102{
3103 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003104 int ret;
3105 ret = decode_attr_bitmap(xdr, bitmask);
3106 if (unlikely(ret < 0))
3107 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3109 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003110 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3111 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3112 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 return 0;
3114}
3115
3116static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3117{
Al Viro8687b632006-10-19 23:28:48 -07003118 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003119 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120
3121 *type = 0;
3122 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3123 return -EIO;
3124 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003125 p = xdr_inline_decode(xdr, 4);
3126 if (unlikely(!p))
3127 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003128 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003130 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 return -EIO;
3132 }
3133 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003134 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003136 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003137 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003138out_overflow:
3139 print_overflow_msg(__func__, xdr);
3140 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141}
3142
Chuck Lever264e6352012-03-01 17:02:05 -05003143static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3144 uint32_t *bitmap, uint32_t *type)
3145{
3146 __be32 *p;
3147
3148 *type = 0;
3149 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3150 return -EIO;
3151 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3152 p = xdr_inline_decode(xdr, 4);
3153 if (unlikely(!p))
3154 goto out_overflow;
3155 *type = be32_to_cpup(p);
3156 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3157 }
3158 dprintk("%s: expire type=0x%x\n", __func__, *type);
3159 return 0;
3160out_overflow:
3161 print_overflow_msg(__func__, xdr);
3162 return -EIO;
3163}
3164
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3166{
Al Viro8687b632006-10-19 23:28:48 -07003167 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003168 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
3170 *change = 0;
3171 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3172 return -EIO;
3173 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003174 p = xdr_inline_decode(xdr, 8);
3175 if (unlikely(!p))
3176 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003177 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003179 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003181 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003183 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003184out_overflow:
3185 print_overflow_msg(__func__, xdr);
3186 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187}
3188
3189static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3190{
Al Viro8687b632006-10-19 23:28:48 -07003191 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003192 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193
3194 *size = 0;
3195 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3196 return -EIO;
3197 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003198 p = xdr_inline_decode(xdr, 8);
3199 if (unlikely(!p))
3200 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003201 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003203 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003205 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003206 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003207out_overflow:
3208 print_overflow_msg(__func__, xdr);
3209 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210}
3211
3212static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3213{
Al Viro8687b632006-10-19 23:28:48 -07003214 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215
3216 *res = 0;
3217 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3218 return -EIO;
3219 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003220 p = xdr_inline_decode(xdr, 4);
3221 if (unlikely(!p))
3222 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003223 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3225 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003226 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003228out_overflow:
3229 print_overflow_msg(__func__, xdr);
3230 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231}
3232
3233static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3234{
Al Viro8687b632006-10-19 23:28:48 -07003235 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236
3237 *res = 0;
3238 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3239 return -EIO;
3240 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003241 p = xdr_inline_decode(xdr, 4);
3242 if (unlikely(!p))
3243 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003244 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3246 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003247 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003249out_overflow:
3250 print_overflow_msg(__func__, xdr);
3251 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252}
3253
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003254static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255{
Al Viro8687b632006-10-19 23:28:48 -07003256 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003257 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258
3259 fsid->major = 0;
3260 fsid->minor = 0;
3261 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3262 return -EIO;
3263 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003264 p = xdr_inline_decode(xdr, 16);
3265 if (unlikely(!p))
3266 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003267 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003268 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003270 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003272 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 (unsigned long long)fsid->major,
3274 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003275 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003276out_overflow:
3277 print_overflow_msg(__func__, xdr);
3278 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279}
3280
3281static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3282{
Al Viro8687b632006-10-19 23:28:48 -07003283 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284
3285 *res = 60;
3286 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3287 return -EIO;
3288 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003289 p = xdr_inline_decode(xdr, 4);
3290 if (unlikely(!p))
3291 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003292 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3294 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003295 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003297out_overflow:
3298 print_overflow_msg(__func__, xdr);
3299 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300}
3301
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003302static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003303{
3304 __be32 *p;
3305
3306 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3307 return -EIO;
3308 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3309 p = xdr_inline_decode(xdr, 4);
3310 if (unlikely(!p))
3311 goto out_overflow;
3312 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003313 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003314 }
3315 return 0;
3316out_overflow:
3317 print_overflow_msg(__func__, xdr);
3318 return -EIO;
3319}
3320
3321static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3322{
3323 __be32 *p;
3324 int len;
3325
Trond Myklebust7ad07352010-10-23 15:34:20 -04003326 if (fh != NULL)
3327 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003328
3329 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3330 return -EIO;
3331 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3332 p = xdr_inline_decode(xdr, 4);
3333 if (unlikely(!p))
3334 goto out_overflow;
3335 len = be32_to_cpup(p);
3336 if (len > NFS4_FHSIZE)
3337 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003338 p = xdr_inline_decode(xdr, len);
3339 if (unlikely(!p))
3340 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003341 if (fh != NULL) {
3342 memcpy(fh->data, p, len);
3343 fh->size = len;
3344 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003345 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3346 }
3347 return 0;
3348out_overflow:
3349 print_overflow_msg(__func__, xdr);
3350 return -EIO;
3351}
3352
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3354{
Al Viro8687b632006-10-19 23:28:48 -07003355 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356
3357 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3358 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3359 return -EIO;
3360 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003361 p = xdr_inline_decode(xdr, 4);
3362 if (unlikely(!p))
3363 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003364 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3366 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003367 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003369out_overflow:
3370 print_overflow_msg(__func__, xdr);
3371 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372}
3373
3374static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3375{
Al Viro8687b632006-10-19 23:28:48 -07003376 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003377 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
3379 *fileid = 0;
3380 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3381 return -EIO;
3382 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003383 p = xdr_inline_decode(xdr, 8);
3384 if (unlikely(!p))
3385 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003386 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003388 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003390 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003391 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003392out_overflow:
3393 print_overflow_msg(__func__, xdr);
3394 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395}
3396
Manoj Naik99baf622006-06-09 09:34:24 -04003397static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3398{
Al Viro8687b632006-10-19 23:28:48 -07003399 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003400 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003401
3402 *fileid = 0;
3403 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3404 return -EIO;
3405 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003406 p = xdr_inline_decode(xdr, 8);
3407 if (unlikely(!p))
3408 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003409 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003410 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003411 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003412 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003413 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003414 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003415out_overflow:
3416 print_overflow_msg(__func__, xdr);
3417 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003418}
3419
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3421{
Al Viro8687b632006-10-19 23:28:48 -07003422 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 int status = 0;
3424
3425 *res = 0;
3426 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3427 return -EIO;
3428 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003429 p = xdr_inline_decode(xdr, 8);
3430 if (unlikely(!p))
3431 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003432 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3434 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003435 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003437out_overflow:
3438 print_overflow_msg(__func__, xdr);
3439 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440}
3441
3442static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3443{
Al Viro8687b632006-10-19 23:28:48 -07003444 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 int status = 0;
3446
3447 *res = 0;
3448 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3449 return -EIO;
3450 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003451 p = xdr_inline_decode(xdr, 8);
3452 if (unlikely(!p))
3453 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003454 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3456 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003457 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003459out_overflow:
3460 print_overflow_msg(__func__, xdr);
3461 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462}
3463
3464static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3465{
Al Viro8687b632006-10-19 23:28:48 -07003466 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 int status = 0;
3468
3469 *res = 0;
3470 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3471 return -EIO;
3472 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003473 p = xdr_inline_decode(xdr, 8);
3474 if (unlikely(!p))
3475 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003476 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3478 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003479 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003481out_overflow:
3482 print_overflow_msg(__func__, xdr);
3483 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484}
3485
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003486static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3487{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003488 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003489 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003490 int status = 0;
3491
Benny Halevyc0eae662009-08-14 17:20:14 +03003492 p = xdr_inline_decode(xdr, 4);
3493 if (unlikely(!p))
3494 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003495 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003496 if (n == 0)
3497 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003498 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003499 path->ncomponents = 0;
3500 while (path->ncomponents < n) {
3501 struct nfs4_string *component = &path->components[path->ncomponents];
3502 status = decode_opaque_inline(xdr, &component->len, &component->data);
3503 if (unlikely(status != 0))
3504 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003505 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003506 pr_cont("%s%.*s ",
3507 (path->ncomponents != n ? "/ " : ""),
3508 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003509 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3510 path->ncomponents++;
3511 else {
3512 dprintk("cannot parse %d components in path\n", n);
3513 goto out_eio;
3514 }
3515 }
3516out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003517 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003518root_path:
3519/* a root pathname is sent as a zero component4 */
3520 path->ncomponents = 1;
3521 path->components[0].len=0;
3522 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003523 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003524 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003525out_eio:
3526 dprintk(" status %d", status);
3527 status = -EIO;
3528 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003529out_overflow:
3530 print_overflow_msg(__func__, xdr);
3531 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003532}
3533
3534static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003535{
3536 int n;
Al Viro8687b632006-10-19 23:28:48 -07003537 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003538 int status = -EIO;
3539
3540 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3541 goto out;
3542 status = 0;
3543 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3544 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003545 status = -EIO;
3546 /* Ignore borken servers that return unrequested attrs */
3547 if (unlikely(res == NULL))
3548 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003549 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003550 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003551 if (unlikely(status != 0))
3552 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003553 p = xdr_inline_decode(xdr, 4);
3554 if (unlikely(!p))
3555 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003556 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003557 if (n <= 0)
3558 goto out_eio;
3559 res->nlocations = 0;
3560 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003561 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003562 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003563
Benny Halevyc0eae662009-08-14 17:20:14 +03003564 p = xdr_inline_decode(xdr, 4);
3565 if (unlikely(!p))
3566 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003567 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003568
3569 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003570 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003571 while (loc->nservers < m) {
3572 struct nfs4_string *server = &loc->servers[loc->nservers];
3573 status = decode_opaque_inline(xdr, &server->len, &server->data);
3574 if (unlikely(status != 0))
3575 goto out_eio;
3576 dprintk("%s ", server->data);
3577 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3578 loc->nservers++;
3579 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003580 unsigned int i;
3581 dprintk("%s: using first %u of %u servers "
3582 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003583 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003584 NFS4_FS_LOCATION_MAXSERVERS,
3585 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003586 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003587 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003588 char *data;
3589 status = decode_opaque_inline(xdr, &len, &data);
3590 if (unlikely(status != 0))
3591 goto out_eio;
3592 }
3593 }
3594 }
3595 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003596 if (unlikely(status != 0))
3597 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003598 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003599 res->nlocations++;
3600 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003601 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003602 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003603out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003604 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003605 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003606out_overflow:
3607 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003608out_eio:
3609 status = -EIO;
3610 goto out;
3611}
3612
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3614{
Al Viro8687b632006-10-19 23:28:48 -07003615 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616 int status = 0;
3617
3618 *res = 0;
3619 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3620 return -EIO;
3621 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003622 p = xdr_inline_decode(xdr, 8);
3623 if (unlikely(!p))
3624 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003625 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3627 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003628 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003630out_overflow:
3631 print_overflow_msg(__func__, xdr);
3632 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633}
3634
3635static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3636{
Al Viro8687b632006-10-19 23:28:48 -07003637 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 int status = 0;
3639
3640 *maxlink = 1;
3641 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3642 return -EIO;
3643 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003644 p = xdr_inline_decode(xdr, 4);
3645 if (unlikely(!p))
3646 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003647 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3649 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003650 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003652out_overflow:
3653 print_overflow_msg(__func__, xdr);
3654 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655}
3656
3657static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3658{
Al Viro8687b632006-10-19 23:28:48 -07003659 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 int status = 0;
3661
3662 *maxname = 1024;
3663 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3664 return -EIO;
3665 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003666 p = xdr_inline_decode(xdr, 4);
3667 if (unlikely(!p))
3668 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003669 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3671 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003672 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003674out_overflow:
3675 print_overflow_msg(__func__, xdr);
3676 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677}
3678
3679static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3680{
Al Viro8687b632006-10-19 23:28:48 -07003681 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 int status = 0;
3683
3684 *res = 1024;
3685 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3686 return -EIO;
3687 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3688 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003689 p = xdr_inline_decode(xdr, 8);
3690 if (unlikely(!p))
3691 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003692 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 if (maxread > 0x7FFFFFFF)
3694 maxread = 0x7FFFFFFF;
3695 *res = (uint32_t)maxread;
3696 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3697 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003698 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003700out_overflow:
3701 print_overflow_msg(__func__, xdr);
3702 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703}
3704
3705static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3706{
Al Viro8687b632006-10-19 23:28:48 -07003707 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 int status = 0;
3709
3710 *res = 1024;
3711 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3712 return -EIO;
3713 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3714 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003715 p = xdr_inline_decode(xdr, 8);
3716 if (unlikely(!p))
3717 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003718 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 if (maxwrite > 0x7FFFFFFF)
3720 maxwrite = 0x7FFFFFFF;
3721 *res = (uint32_t)maxwrite;
3722 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3723 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003724 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003726out_overflow:
3727 print_overflow_msg(__func__, xdr);
3728 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729}
3730
Trond Myklebustbca79472009-03-11 14:10:26 -04003731static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732{
Trond Myklebustbca79472009-03-11 14:10:26 -04003733 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003734 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003735 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736
3737 *mode = 0;
3738 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3739 return -EIO;
3740 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003741 p = xdr_inline_decode(xdr, 4);
3742 if (unlikely(!p))
3743 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003744 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003745 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003747 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003749 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003750 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003751out_overflow:
3752 print_overflow_msg(__func__, xdr);
3753 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754}
3755
3756static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3757{
Al Viro8687b632006-10-19 23:28:48 -07003758 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003759 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760
3761 *nlink = 1;
3762 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3763 return -EIO;
3764 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003765 p = xdr_inline_decode(xdr, 4);
3766 if (unlikely(!p))
3767 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003768 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003770 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003772 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003773 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003774out_overflow:
3775 print_overflow_msg(__func__, xdr);
3776 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777}
3778
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003779static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003780 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003781 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782{
Al Viro8687b632006-10-19 23:28:48 -07003783 uint32_t len;
3784 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003785 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786
Eric W. Biedermane5782072013-02-01 14:22:02 -08003787 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3789 return -EIO;
3790 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003791 p = xdr_inline_decode(xdr, 4);
3792 if (unlikely(!p))
3793 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003794 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003795 p = xdr_inline_decode(xdr, len);
3796 if (unlikely(!p))
3797 goto out_overflow;
Trond Myklebust6926afd12012-01-07 13:22:46 -05003798 if (owner_name != NULL) {
3799 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3800 if (owner_name->data != NULL) {
3801 owner_name->len = len;
3802 ret = NFS_ATTR_FATTR_OWNER_NAME;
3803 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003804 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003805 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003806 ret = NFS_ATTR_FATTR_OWNER;
3807 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003809 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003811 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003812 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3814 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003815 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003816 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003817out_overflow:
3818 print_overflow_msg(__func__, xdr);
3819 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820}
3821
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003822static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003823 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd12012-01-07 13:22:46 -05003824 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825{
Al Viro8687b632006-10-19 23:28:48 -07003826 uint32_t len;
3827 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003828 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829
Eric W. Biedermane5782072013-02-01 14:22:02 -08003830 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3832 return -EIO;
3833 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003834 p = xdr_inline_decode(xdr, 4);
3835 if (unlikely(!p))
3836 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003837 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003838 p = xdr_inline_decode(xdr, len);
3839 if (unlikely(!p))
3840 goto out_overflow;
Trond Myklebust6926afd12012-01-07 13:22:46 -05003841 if (group_name != NULL) {
3842 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3843 if (group_name->data != NULL) {
3844 group_name->len = len;
3845 ret = NFS_ATTR_FATTR_GROUP_NAME;
3846 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003847 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003848 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003849 ret = NFS_ATTR_FATTR_GROUP;
3850 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003852 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003854 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003855 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3857 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003858 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003859 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003860out_overflow:
3861 print_overflow_msg(__func__, xdr);
3862 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863}
3864
3865static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3866{
Al Viro8687b632006-10-19 23:28:48 -07003867 uint32_t major = 0, minor = 0;
3868 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003869 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870
3871 *rdev = MKDEV(0,0);
3872 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3873 return -EIO;
3874 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3875 dev_t tmp;
3876
Benny Halevyc0eae662009-08-14 17:20:14 +03003877 p = xdr_inline_decode(xdr, 8);
3878 if (unlikely(!p))
3879 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003880 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003881 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 tmp = MKDEV(major, minor);
3883 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3884 *rdev = tmp;
3885 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003886 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003888 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003889 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003890out_overflow:
3891 print_overflow_msg(__func__, xdr);
3892 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893}
3894
3895static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3896{
Al Viro8687b632006-10-19 23:28:48 -07003897 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 int status = 0;
3899
3900 *res = 0;
3901 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3902 return -EIO;
3903 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003904 p = xdr_inline_decode(xdr, 8);
3905 if (unlikely(!p))
3906 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003907 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3909 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003910 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003912out_overflow:
3913 print_overflow_msg(__func__, xdr);
3914 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915}
3916
3917static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3918{
Al Viro8687b632006-10-19 23:28:48 -07003919 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 int status = 0;
3921
3922 *res = 0;
3923 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3924 return -EIO;
3925 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003926 p = xdr_inline_decode(xdr, 8);
3927 if (unlikely(!p))
3928 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003929 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3931 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003932 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003934out_overflow:
3935 print_overflow_msg(__func__, xdr);
3936 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937}
3938
3939static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3940{
Al Viro8687b632006-10-19 23:28:48 -07003941 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 int status = 0;
3943
3944 *res = 0;
3945 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3946 return -EIO;
3947 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003948 p = xdr_inline_decode(xdr, 8);
3949 if (unlikely(!p))
3950 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003951 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3953 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003954 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003956out_overflow:
3957 print_overflow_msg(__func__, xdr);
3958 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959}
3960
3961static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3962{
Al Viro8687b632006-10-19 23:28:48 -07003963 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003964 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965
3966 *used = 0;
3967 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3968 return -EIO;
3969 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003970 p = xdr_inline_decode(xdr, 8);
3971 if (unlikely(!p))
3972 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003973 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003975 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003977 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003979 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003980out_overflow:
3981 print_overflow_msg(__func__, xdr);
3982 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983}
3984
3985static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3986{
Al Viro8687b632006-10-19 23:28:48 -07003987 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 uint64_t sec;
3989 uint32_t nsec;
3990
Benny Halevyc0eae662009-08-14 17:20:14 +03003991 p = xdr_inline_decode(xdr, 12);
3992 if (unlikely(!p))
3993 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003994 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003995 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 time->tv_sec = (time_t)sec;
3997 time->tv_nsec = (long)nsec;
3998 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003999out_overflow:
4000 print_overflow_msg(__func__, xdr);
4001 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002}
4003
4004static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4005{
4006 int status = 0;
4007
4008 time->tv_sec = 0;
4009 time->tv_nsec = 0;
4010 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4011 return -EIO;
4012 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4013 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004014 if (status == 0)
4015 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4017 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004018 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 return status;
4020}
4021
4022static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4023{
4024 int status = 0;
4025
4026 time->tv_sec = 0;
4027 time->tv_nsec = 0;
4028 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4029 return -EIO;
4030 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4031 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004032 if (status == 0)
4033 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4035 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004036 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 return status;
4038}
4039
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004040static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4041 struct timespec *time)
4042{
4043 int status = 0;
4044
4045 time->tv_sec = 0;
4046 time->tv_nsec = 0;
4047 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4048 return -EIO;
4049 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4050 status = decode_attr_time(xdr, time);
4051 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4052 }
4053 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4054 (long)time->tv_nsec);
4055 return status;
4056}
4057
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4059{
4060 int status = 0;
4061
4062 time->tv_sec = 0;
4063 time->tv_nsec = 0;
4064 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4065 return -EIO;
4066 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4067 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004068 if (status == 0)
4069 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4071 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004072 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 return status;
4074}
4075
Trond Myklebust256e48b2012-06-21 11:18:13 -04004076static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077{
4078 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004079 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080
4081 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004082 dprintk("%s: server returned incorrect attribute length: "
4083 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004084 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 attrwords << 2,
4086 (attrwords < nwords) ? '<' : '>',
4087 nwords << 2);
4088 return -EIO;
4089 }
4090 return 0;
4091}
4092
4093static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4094{
Al Viro8687b632006-10-19 23:28:48 -07004095 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096
Benny Halevyc0eae662009-08-14 17:20:14 +03004097 p = xdr_inline_decode(xdr, 20);
4098 if (unlikely(!p))
4099 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004100 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004101 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004102 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004104out_overflow:
4105 print_overflow_msg(__func__, xdr);
4106 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107}
4108
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004109static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110{
Al Viro8687b632006-10-19 23:28:48 -07004111 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 uint32_t supp, acc;
4113 int status;
4114
4115 status = decode_op_hdr(xdr, OP_ACCESS);
4116 if (status)
4117 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004118 p = xdr_inline_decode(xdr, 8);
4119 if (unlikely(!p))
4120 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004121 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004122 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004123 *supported = supp;
4124 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004126out_overflow:
4127 print_overflow_msg(__func__, xdr);
4128 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129}
4130
Benny Halevy07d30432009-08-14 17:19:52 +03004131static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132{
Al Viro8687b632006-10-19 23:28:48 -07004133 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004134
4135 p = xdr_inline_decode(xdr, len);
4136 if (likely(p)) {
4137 memcpy(buf, p, len);
4138 return 0;
4139 }
4140 print_overflow_msg(__func__, xdr);
4141 return -EIO;
4142}
4143
4144static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4145{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004146 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147}
4148
4149static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4150{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 int status;
4152
4153 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004154 if (status != -EIO)
4155 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004156 if (!status)
4157 status = decode_stateid(xdr, &res->stateid);
4158 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159}
4160
Benny Halevydb942bb2009-08-14 17:19:56 +03004161static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4162{
Chuck Levercd937102012-03-02 17:14:31 -05004163 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164}
4165
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004166static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4167{
4168 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4169}
4170
Fred Isaman0b7c0152012-04-20 14:47:39 -04004171static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 int status;
4174
4175 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004176 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004177 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004178 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179}
4180
4181static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4182{
Al Viro8687b632006-10-19 23:28:48 -07004183 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 uint32_t bmlen;
4185 int status;
4186
4187 status = decode_op_hdr(xdr, OP_CREATE);
4188 if (status)
4189 return status;
4190 if ((status = decode_change_info(xdr, cinfo)))
4191 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004192 p = xdr_inline_decode(xdr, 4);
4193 if (unlikely(!p))
4194 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004195 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004196 p = xdr_inline_decode(xdr, bmlen << 2);
4197 if (likely(p))
4198 return 0;
4199out_overflow:
4200 print_overflow_msg(__func__, xdr);
4201 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202}
4203
4204static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4205{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004206 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004207 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 int status;
4209
4210 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4211 goto xdr_error;
4212 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4213 goto xdr_error;
4214 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4215 goto xdr_error;
4216 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4217 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004218 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4219 &res->fh_expire_type)) != 0)
4220 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4222 goto xdr_error;
4223 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4224 goto xdr_error;
4225 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4226 goto xdr_error;
4227 status = verify_attr_len(xdr, savep, attrlen);
4228xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004229 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 return status;
4231}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004232
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4234{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004235 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004236 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004238
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4240 goto xdr_error;
4241 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4242 goto xdr_error;
4243 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4244 goto xdr_error;
4245
4246 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4247 goto xdr_error;
4248 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4249 goto xdr_error;
4250 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4251 goto xdr_error;
4252 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4253 goto xdr_error;
4254 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4255 goto xdr_error;
4256 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4257 goto xdr_error;
4258
4259 status = verify_attr_len(xdr, savep, attrlen);
4260xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004261 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262 return status;
4263}
4264
4265static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4266{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004267 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004268 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004270
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4272 goto xdr_error;
4273 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4274 goto xdr_error;
4275 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4276 goto xdr_error;
4277
4278 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4279 goto xdr_error;
4280 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4281 goto xdr_error;
4282
4283 status = verify_attr_len(xdr, savep, attrlen);
4284xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004285 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286 return status;
4287}
4288
Andy Adamson88034c32012-05-23 05:02:34 -04004289static int decode_threshold_hint(struct xdr_stream *xdr,
4290 uint32_t *bitmap,
4291 uint64_t *res,
4292 uint32_t hint_bit)
4293{
4294 __be32 *p;
4295
4296 *res = 0;
4297 if (likely(bitmap[0] & hint_bit)) {
4298 p = xdr_inline_decode(xdr, 8);
4299 if (unlikely(!p))
4300 goto out_overflow;
4301 xdr_decode_hyper(p, res);
4302 }
4303 return 0;
4304out_overflow:
4305 print_overflow_msg(__func__, xdr);
4306 return -EIO;
4307}
4308
4309static int decode_first_threshold_item4(struct xdr_stream *xdr,
4310 struct nfs4_threshold *res)
4311{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004312 __be32 *p;
4313 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004314 uint32_t bitmap[3] = {0,}, attrlen;
4315 int status;
4316
4317 /* layout type */
4318 p = xdr_inline_decode(xdr, 4);
4319 if (unlikely(!p)) {
4320 print_overflow_msg(__func__, xdr);
4321 return -EIO;
4322 }
4323 res->l_type = be32_to_cpup(p);
4324
4325 /* thi_hintset bitmap */
4326 status = decode_attr_bitmap(xdr, bitmap);
4327 if (status < 0)
4328 goto xdr_error;
4329
4330 /* thi_hintlist length */
4331 status = decode_attr_length(xdr, &attrlen, &savep);
4332 if (status < 0)
4333 goto xdr_error;
4334 /* thi_hintlist */
4335 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4336 if (status < 0)
4337 goto xdr_error;
4338 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4339 if (status < 0)
4340 goto xdr_error;
4341 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4342 THRESHOLD_RD_IO);
4343 if (status < 0)
4344 goto xdr_error;
4345 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4346 THRESHOLD_WR_IO);
4347 if (status < 0)
4348 goto xdr_error;
4349
4350 status = verify_attr_len(xdr, savep, attrlen);
4351 res->bm = bitmap[0];
4352
4353 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4354 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4355 res->wr_io_sz);
4356xdr_error:
4357 dprintk("%s ret=%d!\n", __func__, status);
4358 return status;
4359}
4360
4361/*
4362 * Thresholds on pNFS direct I/O vrs MDS I/O
4363 */
4364static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4365 uint32_t *bitmap,
4366 struct nfs4_threshold *res)
4367{
4368 __be32 *p;
4369 int status = 0;
4370 uint32_t num;
4371
4372 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4373 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004374 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004375 /* Did the server return an unrequested attribute? */
4376 if (unlikely(res == NULL))
4377 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004378 p = xdr_inline_decode(xdr, 4);
4379 if (unlikely(!p))
4380 goto out_overflow;
4381 num = be32_to_cpup(p);
4382 if (num == 0)
4383 return 0;
4384 if (num > 1)
4385 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4386 "drivers per filesystem not supported\n",
4387 __func__);
4388
4389 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004390 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004391 }
4392 return status;
4393out_overflow:
4394 print_overflow_msg(__func__, xdr);
4395 return -EIO;
4396}
4397
Bryan Schumakerae42c702010-10-21 16:33:17 -04004398static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4399 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004400 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004401 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402{
Trond Myklebustbca79472009-03-11 14:10:26 -04004403 int status;
4404 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004405 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004406 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004408 status = decode_attr_type(xdr, bitmap, &type);
4409 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004411 fattr->mode = 0;
4412 if (status != 0) {
4413 fattr->mode |= nfs_type2fmt[type];
4414 fattr->valid |= status;
4415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004417 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4418 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004420 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004421
4422 status = decode_attr_size(xdr, bitmap, &fattr->size);
4423 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004425 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004426
4427 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4428 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004430 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004431
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004432 err = 0;
4433 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004434 if (status < 0)
4435 goto xdr_error;
4436
4437 status = decode_attr_filehandle(xdr, bitmap, fh);
4438 if (status < 0)
4439 goto xdr_error;
4440
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004441 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4442 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004444 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004445
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004446 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004447 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004448 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004449 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004450
4451 status = decode_attr_mode(xdr, bitmap, &fmode);
4452 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004454 if (status != 0) {
4455 fattr->mode |= fmode;
4456 fattr->valid |= status;
4457 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004458
4459 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4460 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004462 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004463
Trond Myklebust6926afd12012-01-07 13:22:46 -05004464 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004465 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004467 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004468
Trond Myklebust6926afd12012-01-07 13:22:46 -05004469 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004470 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004471 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004472 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004473
4474 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4475 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004477 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004478
4479 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4480 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004482 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004483
4484 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4485 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004487 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004488
4489 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4490 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004492 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004493
4494 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4495 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004497 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004498
Trond Myklebust28331a42011-04-27 13:47:52 -04004499 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004500 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004501 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004502 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004503
Andy Adamson88034c32012-05-23 05:02:34 -04004504 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4505 if (status < 0)
4506 goto xdr_error;
4507
Bryan Schumakerae42c702010-10-21 16:33:17 -04004508xdr_error:
4509 dprintk("%s: xdr returned %d\n", __func__, -status);
4510 return status;
4511}
4512
4513static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004514 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4515 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004516{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004517 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004518 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004519 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004520 int status;
4521
4522 status = decode_op_hdr(xdr, OP_GETATTR);
4523 if (status < 0)
4524 goto xdr_error;
4525
4526 status = decode_attr_bitmap(xdr, bitmap);
4527 if (status < 0)
4528 goto xdr_error;
4529
4530 status = decode_attr_length(xdr, &attrlen, &savep);
4531 if (status < 0)
4532 goto xdr_error;
4533
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004534 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004535 if (status < 0)
4536 goto xdr_error;
4537
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004538 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004540 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541 return status;
4542}
4543
Bryan Schumakerae42c702010-10-21 16:33:17 -04004544static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd12012-01-07 13:22:46 -05004545 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004546{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004547 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004548}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549
Andy Adamson504913f2010-10-20 00:17:57 -04004550/*
4551 * Decode potentially multiple layout types. Currently we only support
4552 * one layout driver per file system.
4553 */
4554static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4555 uint32_t *layouttype)
4556{
4557 uint32_t *p;
4558 int num;
4559
4560 p = xdr_inline_decode(xdr, 4);
4561 if (unlikely(!p))
4562 goto out_overflow;
4563 num = be32_to_cpup(p);
4564
4565 /* pNFS is not supported by the underlying file system */
4566 if (num == 0) {
4567 *layouttype = 0;
4568 return 0;
4569 }
4570 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004571 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4572 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004573
4574 /* Decode and set first layout type, move xdr->p past unused types */
4575 p = xdr_inline_decode(xdr, num * 4);
4576 if (unlikely(!p))
4577 goto out_overflow;
4578 *layouttype = be32_to_cpup(p);
4579 return 0;
4580out_overflow:
4581 print_overflow_msg(__func__, xdr);
4582 return -EIO;
4583}
4584
4585/*
4586 * The type of file system exported.
4587 * Note we must ensure that layouttype is set in any non-error case.
4588 */
4589static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4590 uint32_t *layouttype)
4591{
4592 int status = 0;
4593
4594 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4595 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4596 return -EIO;
4597 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4598 status = decode_first_pnfs_layout_type(xdr, layouttype);
4599 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4600 } else
4601 *layouttype = 0;
4602 return status;
4603}
4604
Fred Isamandae100c2011-07-30 20:52:37 -04004605/*
4606 * The prefered block size for layout directed io
4607 */
4608static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4609 uint32_t *res)
4610{
4611 __be32 *p;
4612
4613 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4614 *res = 0;
4615 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4616 p = xdr_inline_decode(xdr, 4);
4617 if (unlikely(!p)) {
4618 print_overflow_msg(__func__, xdr);
4619 return -EIO;
4620 }
4621 *res = be32_to_cpup(p);
4622 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4623 }
4624 return 0;
4625}
4626
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4628{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004629 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004630 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 int status;
4632
4633 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4634 goto xdr_error;
4635 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4636 goto xdr_error;
4637 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4638 goto xdr_error;
4639
4640 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4641
4642 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4643 goto xdr_error;
4644 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4645 goto xdr_error;
4646 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4647 goto xdr_error;
4648 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4649 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4650 goto xdr_error;
4651 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004652 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4653 if (status != 0)
4654 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004655 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4656 if (status != 0)
4657 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004658 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4659 if (status)
4660 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661
4662 status = verify_attr_len(xdr, savep, attrlen);
4663xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004664 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 return status;
4666}
4667
4668static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4669{
Al Viro8687b632006-10-19 23:28:48 -07004670 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671 uint32_t len;
4672 int status;
4673
Trond Myklebust99367812007-07-17 21:52:41 -04004674 /* Zero handle first to allow comparisons */
4675 memset(fh, 0, sizeof(*fh));
4676
Linus Torvalds1da177e2005-04-16 15:20:36 -07004677 status = decode_op_hdr(xdr, OP_GETFH);
4678 if (status)
4679 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004680
Benny Halevyc0eae662009-08-14 17:20:14 +03004681 p = xdr_inline_decode(xdr, 4);
4682 if (unlikely(!p))
4683 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004684 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685 if (len > NFS4_FHSIZE)
4686 return -EIO;
4687 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004688 p = xdr_inline_decode(xdr, len);
4689 if (unlikely(!p))
4690 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004691 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004693out_overflow:
4694 print_overflow_msg(__func__, xdr);
4695 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696}
4697
4698static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4699{
4700 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004701
Linus Torvalds1da177e2005-04-16 15:20:36 -07004702 status = decode_op_hdr(xdr, OP_LINK);
4703 if (status)
4704 return status;
4705 return decode_change_info(xdr, cinfo);
4706}
4707
4708/*
4709 * We create the owner, so we know a proper owner.id length is 4.
4710 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004711static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004713 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004714 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004715 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004717 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004718 if (unlikely(!p))
4719 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004720 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004721 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004722 type = be32_to_cpup(p++); /* 4 byte read */
4723 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004724 fl->fl_start = (loff_t)offset;
4725 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4726 if (length == ~(uint64_t)0)
4727 fl->fl_end = OFFSET_MAX;
4728 fl->fl_type = F_WRLCK;
4729 if (type & 1)
4730 fl->fl_type = F_RDLCK;
4731 fl->fl_pid = 0;
4732 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004733 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4734 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4735 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004736 if (likely(p))
4737 return -NFS4ERR_DENIED;
4738out_overflow:
4739 print_overflow_msg(__func__, xdr);
4740 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741}
4742
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004743static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745 int status;
4746
4747 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004748 if (status == -EIO)
4749 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004751 status = decode_stateid(xdr, &res->stateid);
4752 if (unlikely(status))
4753 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004755 status = decode_lock_denied(xdr, NULL);
4756 if (res->open_seqid != NULL)
4757 nfs_increment_open_seqid(status, res->open_seqid);
4758 nfs_increment_lock_seqid(status, res->lock_seqid);
4759out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 return status;
4761}
4762
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004763static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764{
4765 int status;
4766 status = decode_op_hdr(xdr, OP_LOCKT);
4767 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004768 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769 return status;
4770}
4771
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004772static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 int status;
4775
4776 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004777 if (status != -EIO)
4778 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004779 if (status == 0)
4780 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781 return status;
4782}
4783
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004784static int decode_release_lockowner(struct xdr_stream *xdr)
4785{
4786 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4787}
4788
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789static int decode_lookup(struct xdr_stream *xdr)
4790{
4791 return decode_op_hdr(xdr, OP_LOOKUP);
4792}
4793
4794/* This is too sick! */
4795static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4796{
Andy Adamson05d564f2008-12-23 16:06:15 -05004797 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 uint32_t limit_type, nblocks, blocksize;
4799
Benny Halevyc0eae662009-08-14 17:20:14 +03004800 p = xdr_inline_decode(xdr, 12);
4801 if (unlikely(!p))
4802 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004803 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004805 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004806 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004807 break;
4808 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004809 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004810 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004811 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812 }
4813 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004814out_overflow:
4815 print_overflow_msg(__func__, xdr);
4816 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817}
4818
4819static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4820{
Andy Adamson05d564f2008-12-23 16:06:15 -05004821 __be32 *p;
4822 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004823 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824
Benny Halevyc0eae662009-08-14 17:20:14 +03004825 p = xdr_inline_decode(xdr, 4);
4826 if (unlikely(!p))
4827 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004828 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4830 res->delegation_type = 0;
4831 return 0;
4832 }
Benny Halevy07d30432009-08-14 17:19:52 +03004833 status = decode_stateid(xdr, &res->delegation);
4834 if (unlikely(status))
4835 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004836 p = xdr_inline_decode(xdr, 4);
4837 if (unlikely(!p))
4838 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004839 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004840
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004842 case NFS4_OPEN_DELEGATE_READ:
4843 res->delegation_type = FMODE_READ;
4844 break;
4845 case NFS4_OPEN_DELEGATE_WRITE:
4846 res->delegation_type = FMODE_WRITE|FMODE_READ;
4847 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 return -EIO;
4849 }
David Howells7539bba2006-08-22 20:06:09 -04004850 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004851out_overflow:
4852 print_overflow_msg(__func__, xdr);
4853 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854}
4855
4856static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4857{
Andy Adamson05d564f2008-12-23 16:06:15 -05004858 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004859 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004860 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861
Andy Adamson05d564f2008-12-23 16:06:15 -05004862 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004863 if (status != -EIO)
4864 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004865 if (!status)
4866 status = decode_stateid(xdr, &res->stateid);
4867 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004868 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869
Andy Adamson05d564f2008-12-23 16:06:15 -05004870 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871
Benny Halevyc0eae662009-08-14 17:20:14 +03004872 p = xdr_inline_decode(xdr, 8);
4873 if (unlikely(!p))
4874 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004875 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004876 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004877 if (bmlen > 10)
4878 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879
Benny Halevyc0eae662009-08-14 17:20:14 +03004880 p = xdr_inline_decode(xdr, bmlen << 2);
4881 if (unlikely(!p))
4882 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004883 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4884 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004885 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004886 for (; i < NFS4_BITMAP_SIZE; i++)
4887 res->attrset[i] = 0;
4888
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 return decode_delegation(xdr, res);
4890xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004891 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004893out_overflow:
4894 print_overflow_msg(__func__, xdr);
4895 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896}
4897
4898static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4899{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 int status;
4901
Andy Adamson05d564f2008-12-23 16:06:15 -05004902 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004903 if (status != -EIO)
4904 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004905 if (!status)
4906 status = decode_stateid(xdr, &res->stateid);
4907 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908}
4909
4910static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4911{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912 int status;
4913
4914 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004915 if (status != -EIO)
4916 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004917 if (!status)
4918 status = decode_stateid(xdr, &res->stateid);
4919 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920}
4921
4922static int decode_putfh(struct xdr_stream *xdr)
4923{
4924 return decode_op_hdr(xdr, OP_PUTFH);
4925}
4926
4927static int decode_putrootfh(struct xdr_stream *xdr)
4928{
4929 return decode_op_hdr(xdr, OP_PUTROOTFH);
4930}
4931
4932static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4933{
Al Viro8687b632006-10-19 23:28:48 -07004934 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04004935 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936 int status;
4937
4938 status = decode_op_hdr(xdr, OP_READ);
4939 if (status)
4940 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004941 p = xdr_inline_decode(xdr, 8);
4942 if (unlikely(!p))
4943 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004944 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004945 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04004946 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004948 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004949 "count %u > recvd %u\n", count, recvd);
4950 count = recvd;
4951 eof = 0;
4952 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953 res->eof = eof;
4954 res->count = count;
4955 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004956out_overflow:
4957 print_overflow_msg(__func__, xdr);
4958 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959}
4960
4961static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4962{
Chuck Leverbcecff72007-10-26 13:32:03 -04004963 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004964 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965
4966 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004967 if (!status)
4968 status = decode_verifier(xdr, readdir->verifier.data);
4969 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004971 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004972 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004973 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04004974 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975}
4976
4977static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4978{
4979 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04004980 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004981 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 int status;
4983
4984 status = decode_op_hdr(xdr, OP_READLINK);
4985 if (status)
4986 return status;
4987
4988 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004989 p = xdr_inline_decode(xdr, 4);
4990 if (unlikely(!p))
4991 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004992 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004994 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995 return -ENAMETOOLONG;
4996 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04004997 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004999 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000 "count %u > recvd %u\n", len, recvd);
5001 return -EIO;
5002 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003 /*
5004 * The XDR encode routine has set things up so that
5005 * the link text will be copied directly into the
5006 * buffer. We just have to do overflow-checking,
5007 * and and null-terminate the text (the VFS expects
5008 * null-termination).
5009 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005010 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005012out_overflow:
5013 print_overflow_msg(__func__, xdr);
5014 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015}
5016
5017static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5018{
5019 int status;
5020
5021 status = decode_op_hdr(xdr, OP_REMOVE);
5022 if (status)
5023 goto out;
5024 status = decode_change_info(xdr, cinfo);
5025out:
5026 return status;
5027}
5028
5029static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5030 struct nfs4_change_info *new_cinfo)
5031{
5032 int status;
5033
5034 status = decode_op_hdr(xdr, OP_RENAME);
5035 if (status)
5036 goto out;
5037 if ((status = decode_change_info(xdr, old_cinfo)))
5038 goto out;
5039 status = decode_change_info(xdr, new_cinfo);
5040out:
5041 return status;
5042}
5043
5044static int decode_renew(struct xdr_stream *xdr)
5045{
5046 return decode_op_hdr(xdr, OP_RENEW);
5047}
5048
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005049static int
5050decode_restorefh(struct xdr_stream *xdr)
5051{
5052 return decode_op_hdr(xdr, OP_RESTOREFH);
5053}
5054
J. Bruce Fields029d1052005-06-22 17:16:22 +00005055static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005056 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005057{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005058 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005059 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005060 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005061 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005062 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005063
Andy Adamsonbf118a32011-12-07 11:55:27 -05005064 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005065 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5066 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005067
Trond Myklebust519d3952012-08-14 17:30:10 -04005068 xdr_enter_page(xdr, xdr->buf->page_len);
5069
Trond Myklebustcff298c2012-08-14 17:14:17 -04005070 /* Calculate the offset of the page data */
5071 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005072
J. Bruce Fields029d1052005-06-22 17:16:22 +00005073 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5074 goto out;
5075 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5076 goto out;
5077
5078 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5079 return -EIO;
5080 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005081
Andy Adamsonbf118a32011-12-07 11:55:27 -05005082 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5083 * are stored with the acl data to handle the problem of
5084 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005085 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005086 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005087
5088 /* Check for receive buffer overflow */
5089 if (res->acl_len > (xdr->nwords << 2) ||
5090 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5091 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005092 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005093 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005094 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005095 } else
5096 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005097
5098out:
5099 return status;
5100}
5101
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102static int
5103decode_savefh(struct xdr_stream *xdr)
5104{
5105 return decode_op_hdr(xdr, OP_SAVEFH);
5106}
5107
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005108static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109{
Al Viro8687b632006-10-19 23:28:48 -07005110 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111 uint32_t bmlen;
5112 int status;
5113
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114 status = decode_op_hdr(xdr, OP_SETATTR);
5115 if (status)
5116 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005117 p = xdr_inline_decode(xdr, 4);
5118 if (unlikely(!p))
5119 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005120 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005121 p = xdr_inline_decode(xdr, bmlen << 2);
5122 if (likely(p))
5123 return 0;
5124out_overflow:
5125 print_overflow_msg(__func__, xdr);
5126 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127}
5128
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005129static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130{
Al Viro8687b632006-10-19 23:28:48 -07005131 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132 uint32_t opnum;
5133 int32_t nfserr;
5134
Benny Halevyc0eae662009-08-14 17:20:14 +03005135 p = xdr_inline_decode(xdr, 8);
5136 if (unlikely(!p))
5137 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005138 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005140 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005141 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142 return -EIO;
5143 }
Benny Halevycccddf42009-08-14 17:20:19 +03005144 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005146 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5147 if (unlikely(!p))
5148 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005149 p = xdr_decode_hyper(p, &res->clientid);
5150 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151 } else if (nfserr == NFSERR_CLID_INUSE) {
5152 uint32_t len;
5153
5154 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005155 p = xdr_inline_decode(xdr, 4);
5156 if (unlikely(!p))
5157 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005158 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005159 p = xdr_inline_decode(xdr, len);
5160 if (unlikely(!p))
5161 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162
5163 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005164 p = xdr_inline_decode(xdr, 4);
5165 if (unlikely(!p))
5166 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005167 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005168 p = xdr_inline_decode(xdr, len);
5169 if (unlikely(!p))
5170 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171 return -NFSERR_CLID_INUSE;
5172 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005173 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174
5175 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005176out_overflow:
5177 print_overflow_msg(__func__, xdr);
5178 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005179}
5180
5181static int decode_setclientid_confirm(struct xdr_stream *xdr)
5182{
5183 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5184}
5185
5186static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5187{
Al Viro8687b632006-10-19 23:28:48 -07005188 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005189 int status;
5190
5191 status = decode_op_hdr(xdr, OP_WRITE);
5192 if (status)
5193 return status;
5194
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005195 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005196 if (unlikely(!p))
5197 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005198 res->count = be32_to_cpup(p++);
5199 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005200 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005201out_overflow:
5202 print_overflow_msg(__func__, xdr);
5203 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204}
5205
5206static int decode_delegreturn(struct xdr_stream *xdr)
5207{
5208 return decode_op_hdr(xdr, OP_DELEGRETURN);
5209}
5210
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005211static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5212{
5213 __be32 *p;
5214
5215 p = xdr_inline_decode(xdr, 4);
5216 if (unlikely(!p))
5217 goto out_overflow;
5218 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5219 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5220 goto out_err;
5221
5222 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5223 if (unlikely(!p))
5224 goto out_overflow;
5225 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5226
5227 p = xdr_inline_decode(xdr, 8);
5228 if (unlikely(!p))
5229 goto out_overflow;
5230 flavor->gss.qop4 = be32_to_cpup(p++);
5231 flavor->gss.service = be32_to_cpup(p);
5232
5233 return 0;
5234
5235out_overflow:
5236 print_overflow_msg(__func__, xdr);
5237 return -EIO;
5238out_err:
5239 return -EINVAL;
5240}
5241
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005242static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005243{
5244 struct nfs4_secinfo_flavor *sec_flavor;
5245 int status;
5246 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005247 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005248
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005249 p = xdr_inline_decode(xdr, 4);
5250 if (unlikely(!p))
5251 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005252
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005253 res->flavors->num_flavors = 0;
5254 num_flavors = be32_to_cpup(p);
5255
5256 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005257 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005258 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005259 break;
5260
5261 p = xdr_inline_decode(xdr, 4);
5262 if (unlikely(!p))
5263 goto out_overflow;
5264 sec_flavor->flavor = be32_to_cpup(p);
5265
5266 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005267 status = decode_secinfo_gss(xdr, sec_flavor);
5268 if (status)
5269 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005270 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005271 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005272 }
5273
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005274 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005275out:
5276 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005277out_overflow:
5278 print_overflow_msg(__func__, xdr);
5279 return -EIO;
5280}
5281
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005282static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5283{
5284 int status = decode_op_hdr(xdr, OP_SECINFO);
5285 if (status)
5286 return status;
5287 return decode_secinfo_common(xdr, res);
5288}
5289
Benny Halevy99fe60d2009-04-01 09:22:29 -04005290#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005291static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5292{
5293 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5294 if (status)
5295 return status;
5296 return decode_secinfo_common(xdr, res);
5297}
5298
Benny Halevy99fe60d2009-04-01 09:22:29 -04005299static int decode_exchange_id(struct xdr_stream *xdr,
5300 struct nfs41_exchange_id_res *res)
5301{
5302 __be32 *p;
5303 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005304 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005305 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005306 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005307
5308 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5309 if (status)
5310 return status;
5311
Benny Halevyc0eae662009-08-14 17:20:14 +03005312 p = xdr_inline_decode(xdr, 8);
5313 if (unlikely(!p))
5314 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005315 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005316 p = xdr_inline_decode(xdr, 12);
5317 if (unlikely(!p))
5318 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005319 res->seqid = be32_to_cpup(p++);
5320 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005321
5322 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005323 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005324 if (dummy != SP4_NONE)
5325 return -EIO;
5326
Chuck Leveracdeb692012-05-21 22:46:16 -04005327 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005328 p = xdr_inline_decode(xdr, 8);
5329 if (unlikely(!p))
5330 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005331 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005332
Chuck Leveracdeb692012-05-21 22:46:16 -04005333 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005334 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5335 if (unlikely(status))
5336 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005337 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5338 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005339 memcpy(res->server_owner->major_id, dummy_str, dummy);
5340 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005341
Chuck Leveracdeb692012-05-21 22:46:16 -04005342 /* server_scope4 */
5343 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5344 if (unlikely(status))
5345 return status;
5346 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5347 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005348 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5349 res->server_scope->server_scope_sz = dummy;
5350
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005351 /* Implementation Id */
5352 p = xdr_inline_decode(xdr, 4);
5353 if (unlikely(!p))
5354 goto out_overflow;
5355 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005356
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005357 if (impl_id_count) {
5358 /* nii_domain */
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->domain, dummy_str, dummy);
5365
5366 /* nii_name */
5367 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5368 if (unlikely(status))
5369 return status;
5370 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5371 return -EIO;
5372 memcpy(res->impl_id->name, dummy_str, dummy);
5373
5374 /* nii_date */
5375 p = xdr_inline_decode(xdr, 12);
5376 if (unlikely(!p))
5377 goto out_overflow;
5378 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5379 res->impl_id->date.nseconds = be32_to_cpup(p);
5380
5381 /* if there's more than one entry, ignore the rest */
5382 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005383 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005384out_overflow:
5385 print_overflow_msg(__func__, xdr);
5386 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005387}
Andy Adamsonfc931582009-04-01 09:22:31 -04005388
5389static int decode_chan_attrs(struct xdr_stream *xdr,
5390 struct nfs4_channel_attrs *attrs)
5391{
5392 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005393 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005394
Benny Halevyc0eae662009-08-14 17:20:14 +03005395 p = xdr_inline_decode(xdr, 28);
5396 if (unlikely(!p))
5397 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005398 val = be32_to_cpup(p++); /* headerpadsz */
5399 if (val)
5400 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005401 attrs->max_rqst_sz = be32_to_cpup(p++);
5402 attrs->max_resp_sz = be32_to_cpup(p++);
5403 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5404 attrs->max_ops = be32_to_cpup(p++);
5405 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005406 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005407 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005408 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5409 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005410 return -EINVAL;
5411 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005412 if (nr_attrs == 1) {
5413 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5414 if (unlikely(!p))
5415 goto out_overflow;
5416 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005417 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005418out_overflow:
5419 print_overflow_msg(__func__, xdr);
5420 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005421}
5422
Benny Halevye78291e2009-08-14 17:20:00 +03005423static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5424{
5425 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005426}
5427
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005428static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5429 struct nfs41_bind_conn_to_session_res *res)
5430{
5431 __be32 *p;
5432 int status;
5433
5434 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5435 if (!status)
5436 status = decode_sessionid(xdr, &res->session->sess_id);
5437 if (unlikely(status))
5438 return status;
5439
5440 /* dir flags, rdma mode bool */
5441 p = xdr_inline_decode(xdr, 8);
5442 if (unlikely(!p))
5443 goto out_overflow;
5444
5445 res->dir = be32_to_cpup(p++);
5446 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5447 return -EIO;
5448 if (be32_to_cpup(p) == 0)
5449 res->use_conn_in_rdma_mode = false;
5450 else
5451 res->use_conn_in_rdma_mode = true;
5452
5453 return 0;
5454out_overflow:
5455 print_overflow_msg(__func__, xdr);
5456 return -EIO;
5457}
5458
Andy Adamsonfc931582009-04-01 09:22:31 -04005459static int decode_create_session(struct xdr_stream *xdr,
5460 struct nfs41_create_session_res *res)
5461{
5462 __be32 *p;
5463 int status;
5464 struct nfs_client *clp = res->client;
5465 struct nfs4_session *session = clp->cl_session;
5466
5467 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005468 if (!status)
5469 status = decode_sessionid(xdr, &session->sess_id);
5470 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005471 return status;
5472
Andy Adamsonfc931582009-04-01 09:22:31 -04005473 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005474 p = xdr_inline_decode(xdr, 8);
5475 if (unlikely(!p))
5476 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005477 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005478 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005479
5480 /* Channel attributes */
5481 status = decode_chan_attrs(xdr, &session->fc_attrs);
5482 if (!status)
5483 status = decode_chan_attrs(xdr, &session->bc_attrs);
5484 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005485out_overflow:
5486 print_overflow_msg(__func__, xdr);
5487 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005488}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005489
5490static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5491{
5492 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5493}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005494
Trond Myklebust66245532012-05-25 17:18:09 -04005495static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5496{
5497 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5498}
5499
Ricardo Labiaga180197532009-12-05 16:08:40 -05005500static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5501{
5502 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5503}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005504#endif /* CONFIG_NFS_V4_1 */
5505
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005506static int decode_sequence(struct xdr_stream *xdr,
5507 struct nfs4_sequence_res *res,
5508 struct rpc_rqst *rqstp)
5509{
5510#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005511 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005512 struct nfs4_sessionid id;
5513 u32 dummy;
5514 int status;
5515 __be32 *p;
5516
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005517 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005518 return 0;
5519
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005520 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005521 if (!status)
5522 status = decode_sessionid(xdr, &id);
5523 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005524 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005525
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005526 /*
5527 * If the server returns different values for sessionID, slotID or
5528 * sequence number, the server is looney tunes.
5529 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005530 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005531 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005532
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005533 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005534 NFS4_MAX_SESSIONID_LEN)) {
5535 dprintk("%s Invalid session id\n", __func__);
5536 goto out_err;
5537 }
Benny Halevye78291e2009-08-14 17:20:00 +03005538
Benny Halevyc0eae662009-08-14 17:20:14 +03005539 p = xdr_inline_decode(xdr, 20);
5540 if (unlikely(!p))
5541 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005542
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005543 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005544 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005545 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005546 dprintk("%s Invalid sequence number\n", __func__);
5547 goto out_err;
5548 }
5549 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005550 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005551 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005552 dprintk("%s Invalid slot id\n", __func__);
5553 goto out_err;
5554 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005555 /* highest slot id */
5556 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005557 /* target highest slot id */
5558 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005559 /* result flags */
5560 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005561 status = 0;
5562out_err:
5563 res->sr_status = status;
5564 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005565out_overflow:
5566 print_overflow_msg(__func__, xdr);
5567 status = -EIO;
5568 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005569#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005570 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005571#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005572}
5573
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005574#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005575/*
5576 * TODO: Need to handle case when EOF != true;
5577 */
5578static int decode_getdevicelist(struct xdr_stream *xdr,
5579 struct pnfs_devicelist *res)
5580{
5581 __be32 *p;
5582 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005583 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005584
5585 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5586 if (status)
5587 return status;
5588
5589 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5590 if (unlikely(!p))
5591 goto out_overflow;
5592
5593 /* TODO: Skip cookie for now */
5594 p += 2;
5595
5596 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005597 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005598
5599 res->num_devs = be32_to_cpup(p);
5600
5601 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5602
5603 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005604 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005605 __func__, res->num_devs);
5606 return -EIO;
5607 }
5608
5609 p = xdr_inline_decode(xdr,
5610 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5611 if (unlikely(!p))
5612 goto out_overflow;
5613 for (i = 0; i < res->num_devs; i++)
5614 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5615 NFS4_DEVICEID4_SIZE);
5616 res->eof = be32_to_cpup(p);
5617 return 0;
5618out_overflow:
5619 print_overflow_msg(__func__, xdr);
5620 return -EIO;
5621}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005622
5623static int decode_getdeviceinfo(struct xdr_stream *xdr,
5624 struct pnfs_device *pdev)
5625{
5626 __be32 *p;
5627 uint32_t len, type;
5628 int status;
5629
5630 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5631 if (status) {
5632 if (status == -ETOOSMALL) {
5633 p = xdr_inline_decode(xdr, 4);
5634 if (unlikely(!p))
5635 goto out_overflow;
5636 pdev->mincount = be32_to_cpup(p);
5637 dprintk("%s: Min count too small. mincnt = %u\n",
5638 __func__, pdev->mincount);
5639 }
5640 return status;
5641 }
5642
5643 p = xdr_inline_decode(xdr, 8);
5644 if (unlikely(!p))
5645 goto out_overflow;
5646 type = be32_to_cpup(p++);
5647 if (type != pdev->layout_type) {
5648 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5649 __func__, pdev->layout_type, type);
5650 return -EINVAL;
5651 }
5652 /*
5653 * Get the length of the opaque device_addr4. xdr_read_pages places
5654 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5655 * and places the remaining xdr data in xdr_buf->tail
5656 */
5657 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005658 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5659 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005660
5661 /* Parse notification bitmap, verifying that it is zero. */
5662 p = xdr_inline_decode(xdr, 4);
5663 if (unlikely(!p))
5664 goto out_overflow;
5665 len = be32_to_cpup(p);
5666 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005667 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005668
5669 p = xdr_inline_decode(xdr, 4 * len);
5670 if (unlikely(!p))
5671 goto out_overflow;
5672 for (i = 0; i < len; i++, p++) {
5673 if (be32_to_cpup(p)) {
5674 dprintk("%s: notifications not supported\n",
5675 __func__);
5676 return -EIO;
5677 }
5678 }
5679 }
5680 return 0;
5681out_overflow:
5682 print_overflow_msg(__func__, xdr);
5683 return -EIO;
5684}
5685
5686static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5687 struct nfs4_layoutget_res *res)
5688{
5689 __be32 *p;
5690 int status;
5691 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005692 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005693
5694 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5695 if (status)
5696 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005697 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005698 if (unlikely(!p))
5699 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005700 res->return_on_close = be32_to_cpup(p);
5701 decode_stateid(xdr, &res->stateid);
5702 p = xdr_inline_decode(xdr, 4);
5703 if (unlikely(!p))
5704 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005705 layout_count = be32_to_cpup(p);
5706 if (!layout_count) {
5707 dprintk("%s: server responded with empty layout array\n",
5708 __func__);
5709 return -EINVAL;
5710 }
5711
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005712 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005713 if (unlikely(!p))
5714 goto out_overflow;
5715 p = xdr_decode_hyper(p, &res->range.offset);
5716 p = xdr_decode_hyper(p, &res->range.length);
5717 res->range.iomode = be32_to_cpup(p++);
5718 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005719 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005720
5721 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5722 __func__,
5723 (unsigned long)res->range.offset,
5724 (unsigned long)res->range.length,
5725 res->range.iomode,
5726 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005727 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005728
Trond Myklebust64bd5772012-06-20 22:35:05 -04005729 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005730 if (res->layoutp->len > recvd) {
5731 dprintk("NFS: server cheating in layoutget reply: "
5732 "layout len %u > recvd %u\n",
5733 res->layoutp->len, recvd);
5734 return -EINVAL;
5735 }
5736
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005737 if (layout_count > 1) {
5738 /* We only handle a length one array at the moment. Any
5739 * further entries are just ignored. Note that this means
5740 * the client may see a response that is less than the
5741 * minimum it requested.
5742 */
5743 dprintk("%s: server responded with %d layouts, dropping tail\n",
5744 __func__, layout_count);
5745 }
5746
5747 return 0;
5748out_overflow:
5749 print_overflow_msg(__func__, xdr);
5750 return -EIO;
5751}
Andy Adamson863a3c62011-03-23 13:27:54 +00005752
Benny Halevycbe82602011-05-22 19:52:37 +03005753static int decode_layoutreturn(struct xdr_stream *xdr,
5754 struct nfs4_layoutreturn_res *res)
5755{
5756 __be32 *p;
5757 int status;
5758
5759 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5760 if (status)
5761 return status;
5762 p = xdr_inline_decode(xdr, 4);
5763 if (unlikely(!p))
5764 goto out_overflow;
5765 res->lrs_present = be32_to_cpup(p);
5766 if (res->lrs_present)
5767 status = decode_stateid(xdr, &res->stateid);
5768 return status;
5769out_overflow:
5770 print_overflow_msg(__func__, xdr);
5771 return -EIO;
5772}
5773
Andy Adamson863a3c62011-03-23 13:27:54 +00005774static int decode_layoutcommit(struct xdr_stream *xdr,
5775 struct rpc_rqst *req,
5776 struct nfs4_layoutcommit_res *res)
5777{
5778 __be32 *p;
5779 __u32 sizechanged;
5780 int status;
5781
5782 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005783 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005784 if (status)
5785 return status;
5786
5787 p = xdr_inline_decode(xdr, 4);
5788 if (unlikely(!p))
5789 goto out_overflow;
5790 sizechanged = be32_to_cpup(p);
5791
5792 if (sizechanged) {
5793 /* throw away new size */
5794 p = xdr_inline_decode(xdr, 8);
5795 if (unlikely(!p))
5796 goto out_overflow;
5797 }
5798 return 0;
5799out_overflow:
5800 print_overflow_msg(__func__, xdr);
5801 return -EIO;
5802}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005803
5804static int decode_test_stateid(struct xdr_stream *xdr,
5805 struct nfs41_test_stateid_res *res)
5806{
5807 __be32 *p;
5808 int status;
5809 int num_res;
5810
5811 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5812 if (status)
5813 return status;
5814
5815 p = xdr_inline_decode(xdr, 4);
5816 if (unlikely(!p))
5817 goto out_overflow;
5818 num_res = be32_to_cpup(p++);
5819 if (num_res != 1)
5820 goto out;
5821
5822 p = xdr_inline_decode(xdr, 4);
5823 if (unlikely(!p))
5824 goto out_overflow;
5825 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005826
5827 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005828out_overflow:
5829 print_overflow_msg(__func__, xdr);
5830out:
5831 return -EIO;
5832}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005833
5834static int decode_free_stateid(struct xdr_stream *xdr,
5835 struct nfs41_free_stateid_res *res)
5836{
5837 __be32 *p;
5838 int status;
5839
5840 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5841 if (status)
5842 return status;
5843
5844 p = xdr_inline_decode(xdr, 4);
5845 if (unlikely(!p))
5846 goto out_overflow;
5847 res->status = be32_to_cpup(p++);
5848 return res->status;
5849out_overflow:
5850 print_overflow_msg(__func__, xdr);
5851 return -EIO;
5852}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005853#endif /* CONFIG_NFS_V4_1 */
5854
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855/*
Benny Halevy49c25592008-12-23 16:06:16 -05005856 * END OF "GENERIC" DECODE ROUTINES.
5857 */
5858
5859/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005860 * Decode OPEN_DOWNGRADE response
5861 */
Chuck Leverbf269552010-12-14 14:59:29 +00005862static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5863 struct xdr_stream *xdr,
5864 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865{
Andy Adamson05d564f2008-12-23 16:06:15 -05005866 struct compound_hdr hdr;
5867 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868
Chuck Leverbf269552010-12-14 14:59:29 +00005869 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005870 if (status)
5871 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005872 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005873 if (status)
5874 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005875 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005876 if (status)
5877 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005878 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005879 if (status != 0)
5880 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005881 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005882out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005883 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005884}
5885
5886/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005887 * Decode ACCESS response
5888 */
Chuck Leverbf269552010-12-14 14:59:29 +00005889static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5890 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892 struct compound_hdr hdr;
5893 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005894
Chuck Leverbf269552010-12-14 14:59:29 +00005895 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005896 if (status)
5897 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005898 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005899 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005900 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005901 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005902 if (status != 0)
5903 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04005904 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04005905 if (status != 0)
5906 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005907 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005908out:
5909 return status;
5910}
5911
5912/*
5913 * Decode LOOKUP response
5914 */
Chuck Leverbf269552010-12-14 14:59:29 +00005915static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5916 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005917{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005918 struct compound_hdr hdr;
5919 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005920
Chuck Leverbf269552010-12-14 14:59:29 +00005921 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005922 if (status)
5923 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005924 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005925 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005927 status = decode_putfh(xdr);
5928 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005930 status = decode_lookup(xdr);
5931 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005933 status = decode_getfh(xdr, res->fh);
5934 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005935 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05005936 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937out:
5938 return status;
5939}
5940
5941/*
5942 * Decode LOOKUP_ROOT response
5943 */
Chuck Leverbf269552010-12-14 14:59:29 +00005944static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5945 struct xdr_stream *xdr,
5946 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948 struct compound_hdr hdr;
5949 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005950
Chuck Leverbf269552010-12-14 14:59:29 +00005951 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005952 if (status)
5953 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005954 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005955 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005957 status = decode_putrootfh(xdr);
5958 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005959 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005960 status = decode_getfh(xdr, res->fh);
5961 if (status == 0)
Trond Myklebust6926afd12012-01-07 13:22:46 -05005962 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963out:
5964 return status;
5965}
5966
5967/*
5968 * Decode REMOVE response
5969 */
Chuck Leverbf269552010-12-14 14:59:29 +00005970static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5971 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005973 struct compound_hdr hdr;
5974 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005975
Chuck Leverbf269552010-12-14 14:59:29 +00005976 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005977 if (status)
5978 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005979 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005980 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005981 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005982 status = decode_putfh(xdr);
5983 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005984 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005985 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005986out:
5987 return status;
5988}
5989
5990/*
5991 * Decode RENAME response
5992 */
Chuck Leverbf269552010-12-14 14:59:29 +00005993static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5994 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005996 struct compound_hdr hdr;
5997 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005998
Chuck Leverbf269552010-12-14 14:59:29 +00005999 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006000 if (status)
6001 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006002 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006003 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006004 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006005 status = decode_putfh(xdr);
6006 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006008 status = decode_savefh(xdr);
6009 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006011 status = decode_putfh(xdr);
6012 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006014 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015out:
6016 return status;
6017}
6018
6019/*
6020 * Decode LINK response
6021 */
Chuck Leverbf269552010-12-14 14:59:29 +00006022static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6023 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006025 struct compound_hdr hdr;
6026 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006027
Chuck Leverbf269552010-12-14 14:59:29 +00006028 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006029 if (status)
6030 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006032 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_putfh(xdr);
6035 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006036 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006037 status = decode_savefh(xdr);
6038 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006040 status = decode_putfh(xdr);
6041 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006043 status = decode_link(xdr, &res->cinfo);
6044 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006045 goto out;
6046 /*
6047 * Note order: OP_LINK leaves the directory as the current
6048 * filehandle.
6049 */
Chuck Leverbf269552010-12-14 14:59:29 +00006050 status = decode_restorefh(xdr);
6051 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006052 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006053 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054out:
6055 return status;
6056}
6057
6058/*
6059 * Decode CREATE response
6060 */
Chuck Leverbf269552010-12-14 14:59:29 +00006061static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6062 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006063{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006064 struct compound_hdr hdr;
6065 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006066
Chuck Leverbf269552010-12-14 14:59:29 +00006067 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006068 if (status)
6069 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006070 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006071 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006073 status = decode_putfh(xdr);
6074 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006075 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006076 status = decode_create(xdr, &res->dir_cinfo);
6077 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006079 status = decode_getfh(xdr, res->fh);
6080 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081 goto out;
Trond Myklebust7c317fc2012-04-27 13:48:18 -04006082 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083out:
6084 return status;
6085}
6086
6087/*
6088 * Decode SYMLINK response
6089 */
Chuck Leverbf269552010-12-14 14:59:29 +00006090static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6091 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092{
Chuck Leverbf269552010-12-14 14:59:29 +00006093 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094}
6095
6096/*
6097 * Decode GETATTR response
6098 */
Chuck Leverbf269552010-12-14 14:59:29 +00006099static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6100 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102 struct compound_hdr hdr;
6103 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006104
Chuck Leverbf269552010-12-14 14:59:29 +00006105 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106 if (status)
6107 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006108 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006109 if (status)
6110 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006111 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006112 if (status)
6113 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006114 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006115out:
6116 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117}
6118
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006119/*
6120 * Encode an SETACL request
6121 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006122static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6123 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006124{
Andy Adamson05d564f2008-12-23 16:06:15 -05006125 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006126 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006127 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006128
Chuck Lever9f06c712010-12-14 14:59:18 +00006129 encode_compound_hdr(xdr, req, &hdr);
6130 encode_sequence(xdr, &args->seq_args, &hdr);
6131 encode_putfh(xdr, args->fh, &hdr);
6132 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006133 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006134}
Andy Adamson05d564f2008-12-23 16:06:15 -05006135
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006136/*
6137 * Decode SETACL response
6138 */
6139static int
Chuck Leverbf269552010-12-14 14:59:29 +00006140nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006141 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006142{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006143 struct compound_hdr hdr;
6144 int status;
6145
Chuck Leverbf269552010-12-14 14:59:29 +00006146 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006147 if (status)
6148 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006149 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006150 if (status)
6151 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006152 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006153 if (status)
6154 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006155 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006156out:
6157 return status;
6158}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006159
6160/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006161 * Decode GETACL response
6162 */
6163static int
Chuck Leverbf269552010-12-14 14:59:29 +00006164nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006165 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006166{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006167 struct compound_hdr hdr;
6168 int status;
6169
Trond Myklebust331818f2012-02-03 18:30:53 -05006170 if (res->acl_scratch != NULL) {
6171 void *p = page_address(res->acl_scratch);
6172 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6173 }
Chuck Leverbf269552010-12-14 14:59:29 +00006174 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006175 if (status)
6176 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006178 if (status)
6179 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006180 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006181 if (status)
6182 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006183 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006184
6185out:
6186 return status;
6187}
6188
6189/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190 * Decode CLOSE response
6191 */
Chuck Leverbf269552010-12-14 14:59:29 +00006192static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6193 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194{
Andy Adamson05d564f2008-12-23 16:06:15 -05006195 struct compound_hdr hdr;
6196 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006199 if (status)
6200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006202 if (status)
6203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006205 if (status)
6206 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006207 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006208 if (status != 0)
6209 goto out;
6210 /*
6211 * Note: Server may do delete on close for this file
6212 * in which case the getattr call will fail with
6213 * an ESTALE error. Shouldn't be a problem,
6214 * though, since fattr->valid will remain unset.
6215 */
Trond Myklebust6926afd12012-01-07 13:22:46 -05006216 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006218 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219}
6220
6221/*
6222 * Decode OPEN response
6223 */
Chuck Leverbf269552010-12-14 14:59:29 +00006224static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6225 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226{
Andy Adamson05d564f2008-12-23 16:06:15 -05006227 struct compound_hdr hdr;
6228 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229
Chuck Leverbf269552010-12-14 14:59:29 +00006230 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006231 if (status)
6232 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006233 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006234 if (status)
6235 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006236 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006237 if (status)
6238 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006239 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006240 if (status)
6241 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006242 status = decode_getfh(xdr, &res->fh);
6243 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006244 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006245 if (res->access_request)
6246 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust90ff0c52012-04-27 13:48:18 -04006247 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006249 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250}
6251
6252/*
6253 * Decode OPEN_CONFIRM response
6254 */
Chuck Leverbf269552010-12-14 14:59:29 +00006255static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6256 struct xdr_stream *xdr,
6257 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258{
Andy Adamson05d564f2008-12-23 16:06:15 -05006259 struct compound_hdr hdr;
6260 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261
Chuck Leverbf269552010-12-14 14:59:29 +00006262 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006263 if (status)
6264 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006265 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006266 if (status)
6267 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006268 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006270 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271}
6272
6273/*
6274 * Decode OPEN response
6275 */
Chuck Leverbf269552010-12-14 14:59:29 +00006276static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6277 struct xdr_stream *xdr,
6278 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006279{
Andy Adamson05d564f2008-12-23 16:06:15 -05006280 struct compound_hdr hdr;
6281 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282
Chuck Leverbf269552010-12-14 14:59:29 +00006283 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006284 if (status)
6285 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006286 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006287 if (status)
6288 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006289 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006290 if (status)
6291 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006292 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006293 if (status)
6294 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006295 if (res->access_request)
6296 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd12012-01-07 13:22:46 -05006297 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006299 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300}
6301
6302/*
6303 * Decode SETATTR response
6304 */
Chuck Leverbf269552010-12-14 14:59:29 +00006305static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6306 struct xdr_stream *xdr,
6307 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006308{
Andy Adamson05d564f2008-12-23 16:06:15 -05006309 struct compound_hdr hdr;
6310 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311
Chuck Leverbf269552010-12-14 14:59:29 +00006312 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006313 if (status)
6314 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006315 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006316 if (status)
6317 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006318 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006319 if (status)
6320 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006321 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006322 if (status)
6323 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006324 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006326 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006327}
6328
6329/*
6330 * Decode LOCK response
6331 */
Chuck Leverbf269552010-12-14 14:59:29 +00006332static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6333 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335 struct compound_hdr hdr;
6336 int status;
6337
Chuck Leverbf269552010-12-14 14:59:29 +00006338 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339 if (status)
6340 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006341 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006342 if (status)
6343 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006344 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 if (status)
6346 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006347 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348out:
6349 return status;
6350}
6351
6352/*
6353 * Decode LOCKT response
6354 */
Chuck Leverbf269552010-12-14 14:59:29 +00006355static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6356 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 struct compound_hdr hdr;
6359 int status;
6360
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 if (status)
6363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006365 if (status)
6366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368 if (status)
6369 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371out:
6372 return status;
6373}
6374
6375/*
6376 * Decode LOCKU response
6377 */
Chuck Leverbf269552010-12-14 14:59:29 +00006378static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6379 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 struct compound_hdr hdr;
6382 int status;
6383
Chuck Leverbf269552010-12-14 14:59:29 +00006384 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006385 if (status)
6386 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006387 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006388 if (status)
6389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006390 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391 if (status)
6392 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394out:
6395 return status;
6396}
6397
Chuck Leverbf269552010-12-14 14:59:29 +00006398static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6399 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006400{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006401 struct compound_hdr hdr;
6402 int status;
6403
Chuck Leverbf269552010-12-14 14:59:29 +00006404 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006405 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006406 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006407 return status;
6408}
6409
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410/*
6411 * Decode READLINK response
6412 */
Chuck Leverbf269552010-12-14 14:59:29 +00006413static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6414 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006415 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006417 struct compound_hdr hdr;
6418 int status;
6419
Chuck Leverbf269552010-12-14 14:59:29 +00006420 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421 if (status)
6422 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006423 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006424 if (status)
6425 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006426 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427 if (status)
6428 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006429 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430out:
6431 return status;
6432}
6433
6434/*
6435 * Decode READDIR response
6436 */
Chuck Leverbf269552010-12-14 14:59:29 +00006437static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6438 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440 struct compound_hdr hdr;
6441 int status;
6442
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 if (status)
6445 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006446 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006447 if (status)
6448 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006449 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 if (status)
6451 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006452 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453out:
6454 return status;
6455}
6456
6457/*
6458 * Decode Read response
6459 */
Chuck Leverbf269552010-12-14 14:59:29 +00006460static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6461 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006462{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463 struct compound_hdr hdr;
6464 int status;
6465
Chuck Leverbf269552010-12-14 14:59:29 +00006466 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467 if (status)
6468 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006469 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006470 if (status)
6471 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006472 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006473 if (status)
6474 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006475 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006476 if (!status)
6477 status = res->count;
6478out:
6479 return status;
6480}
6481
6482/*
6483 * Decode WRITE response
6484 */
Chuck Leverbf269552010-12-14 14:59:29 +00006485static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6486 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006488 struct compound_hdr hdr;
6489 int status;
6490
Chuck Leverbf269552010-12-14 14:59:29 +00006491 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006492 if (status)
6493 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006494 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006495 if (status)
6496 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006497 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498 if (status)
6499 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006500 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006501 if (status)
6502 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006503 if (res->fattr)
Trond Myklebust6926afd12012-01-07 13:22:46 -05006504 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006505 if (!status)
6506 status = res->count;
6507out:
6508 return status;
6509}
6510
6511/*
6512 * Decode COMMIT response
6513 */
Chuck Leverbf269552010-12-14 14:59:29 +00006514static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006515 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006517 struct compound_hdr hdr;
6518 int status;
6519
Chuck Leverbf269552010-12-14 14:59:29 +00006520 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006521 if (status)
6522 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006523 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006524 if (status)
6525 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527 if (status)
6528 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006529 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530out:
6531 return status;
6532}
6533
6534/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006535 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 */
Chuck Leverbf269552010-12-14 14:59:29 +00006537static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006538 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006540 struct compound_hdr hdr;
6541 int status;
6542
Chuck Leverbf269552010-12-14 14:59:29 +00006543 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006545 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006546 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006547 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550 return status;
6551}
6552
6553/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006554 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555 */
Chuck Leverbf269552010-12-14 14:59:29 +00006556static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006557 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006558{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 struct compound_hdr hdr;
6560 int status;
6561
Chuck Leverbf269552010-12-14 14:59:29 +00006562 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006563 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006565 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006566 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006568 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569 return status;
6570}
6571
6572/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006573 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574 */
Chuck Leverbf269552010-12-14 14:59:29 +00006575static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006576 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578 struct compound_hdr hdr;
6579 int status;
6580
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006582 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006584 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006585 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006586 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006587 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006588 return status;
6589}
6590
6591/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006592 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593 */
Chuck Leverbf269552010-12-14 14:59:29 +00006594static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6595 struct xdr_stream *xdr,
6596 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598 struct compound_hdr hdr;
6599 int status;
6600
Chuck Leverbf269552010-12-14 14:59:29 +00006601 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006602 if (status)
6603 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006604 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006605 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006607 status = decode_putfh(xdr);
6608 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006609 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006610 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611out:
6612 return status;
6613}
6614
6615/*
6616 * Decode RENEW response
6617 */
Chuck Leverbf269552010-12-14 14:59:29 +00006618static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6619 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006621 struct compound_hdr hdr;
6622 int status;
6623
Chuck Leverbf269552010-12-14 14:59:29 +00006624 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627 return status;
6628}
6629
6630/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006631 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006632 */
Chuck Leverbf269552010-12-14 14:59:29 +00006633static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6634 struct xdr_stream *xdr,
6635 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006637 struct compound_hdr hdr;
6638 int status;
6639
Chuck Leverbf269552010-12-14 14:59:29 +00006640 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006641 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006642 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643 return status;
6644}
6645
6646/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006647 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006648 */
Chuck Leverbf269552010-12-14 14:59:29 +00006649static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6650 struct xdr_stream *xdr,
6651 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006652{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 struct compound_hdr hdr;
6654 int status;
6655
Chuck Leverbf269552010-12-14 14:59:29 +00006656 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006657 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006658 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006660 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006661 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006662 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006663 return status;
6664}
6665
6666/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006667 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006668 */
Chuck Leverbf269552010-12-14 14:59:29 +00006669static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6670 struct xdr_stream *xdr,
6671 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006673 struct compound_hdr hdr;
6674 int status;
6675
Chuck Leverbf269552010-12-14 14:59:29 +00006676 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006677 if (status)
6678 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006679 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006680 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006681 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006682 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006683 if (status != 0)
6684 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006685 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006686 if (status != 0)
6687 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006688 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006689out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006690 return status;
6691}
6692
Trond Myklebust683b57b2006-06-09 09:34:22 -04006693/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006694 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006695 */
Chuck Leverbf269552010-12-14 14:59:29 +00006696static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6697 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006698 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006699{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006700 struct compound_hdr hdr;
6701 int status;
6702
Chuck Leverbf269552010-12-14 14:59:29 +00006703 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006704 if (status)
6705 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006706 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006707 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006708 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006709 status = decode_putfh(xdr);
6710 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006711 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006712 status = decode_lookup(xdr);
6713 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006714 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006715 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006716 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6717 NULL, res->fs_locations,
6718 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006719out:
6720 return status;
6721}
6722
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006723/*
6724 * Decode SECINFO response
6725 */
6726static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6727 struct xdr_stream *xdr,
6728 struct nfs4_secinfo_res *res)
6729{
6730 struct compound_hdr hdr;
6731 int status;
6732
6733 status = decode_compound_hdr(xdr, &hdr);
6734 if (status)
6735 goto out;
6736 status = decode_sequence(xdr, &res->seq_res, rqstp);
6737 if (status)
6738 goto out;
6739 status = decode_putfh(xdr);
6740 if (status)
6741 goto out;
6742 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006743out:
6744 return status;
6745}
6746
Benny Halevy99fe60d2009-04-01 09:22:29 -04006747#if defined(CONFIG_NFS_V4_1)
6748/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006749 * Decode BIND_CONN_TO_SESSION response
6750 */
6751static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6752 struct xdr_stream *xdr,
6753 void *res)
6754{
6755 struct compound_hdr hdr;
6756 int status;
6757
6758 status = decode_compound_hdr(xdr, &hdr);
6759 if (!status)
6760 status = decode_bind_conn_to_session(xdr, res);
6761 return status;
6762}
6763
6764/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006765 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006766 */
Chuck Leverbf269552010-12-14 14:59:29 +00006767static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6768 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006769 void *res)
6770{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006771 struct compound_hdr hdr;
6772 int status;
6773
Chuck Leverbf269552010-12-14 14:59:29 +00006774 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006775 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006776 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006777 return status;
6778}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006779
6780/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006781 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006782 */
Chuck Leverbf269552010-12-14 14:59:29 +00006783static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6784 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006785 struct nfs41_create_session_res *res)
6786{
Andy Adamsonfc931582009-04-01 09:22:31 -04006787 struct compound_hdr hdr;
6788 int status;
6789
Chuck Leverbf269552010-12-14 14:59:29 +00006790 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006791 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006792 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006793 return status;
6794}
6795
6796/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006797 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006798 */
Chuck Leverbf269552010-12-14 14:59:29 +00006799static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6800 struct xdr_stream *xdr,
6801 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006802{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006803 struct compound_hdr hdr;
6804 int status;
6805
Chuck Leverbf269552010-12-14 14:59:29 +00006806 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006807 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006808 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006809 return status;
6810}
6811
6812/*
Trond Myklebust66245532012-05-25 17:18:09 -04006813 * Decode DESTROY_CLIENTID response
6814 */
6815static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6816 struct xdr_stream *xdr,
6817 void *res)
6818{
6819 struct compound_hdr hdr;
6820 int status;
6821
6822 status = decode_compound_hdr(xdr, &hdr);
6823 if (!status)
6824 status = decode_destroy_clientid(xdr, res);
6825 return status;
6826}
6827
6828/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006829 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006830 */
Chuck Leverbf269552010-12-14 14:59:29 +00006831static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6832 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006833 struct nfs4_sequence_res *res)
6834{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006835 struct compound_hdr hdr;
6836 int status;
6837
Chuck Leverbf269552010-12-14 14:59:29 +00006838 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006839 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006840 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006841 return status;
6842}
6843
6844/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006845 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006846 */
Chuck Leverbf269552010-12-14 14:59:29 +00006847static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6848 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006849 struct nfs4_get_lease_time_res *res)
6850{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006851 struct compound_hdr hdr;
6852 int status;
6853
Chuck Leverbf269552010-12-14 14:59:29 +00006854 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006855 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006856 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006857 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006858 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006859 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006860 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006861 return status;
6862}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006863
6864/*
6865 * Decode RECLAIM_COMPLETE response
6866 */
Chuck Leverbf269552010-12-14 14:59:29 +00006867static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6868 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006869 struct nfs41_reclaim_complete_res *res)
6870{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006871 struct compound_hdr hdr;
6872 int status;
6873
Chuck Leverbf269552010-12-14 14:59:29 +00006874 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006875 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006876 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006877 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006878 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006879 return status;
6880}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006881
6882/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006883 * Decode GETDEVICELIST response
6884 */
6885static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6886 struct xdr_stream *xdr,
6887 struct nfs4_getdevicelist_res *res)
6888{
6889 struct compound_hdr hdr;
6890 int status;
6891
6892 dprintk("encoding getdevicelist!\n");
6893
6894 status = decode_compound_hdr(xdr, &hdr);
6895 if (status != 0)
6896 goto out;
6897 status = decode_sequence(xdr, &res->seq_res, rqstp);
6898 if (status != 0)
6899 goto out;
6900 status = decode_putfh(xdr);
6901 if (status != 0)
6902 goto out;
6903 status = decode_getdevicelist(xdr, res->devlist);
6904out:
6905 return status;
6906}
6907
6908/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006909 * Decode GETDEVINFO response
6910 */
Chuck Leverbf269552010-12-14 14:59:29 +00006911static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6912 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006913 struct nfs4_getdeviceinfo_res *res)
6914{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006915 struct compound_hdr hdr;
6916 int status;
6917
Chuck Leverbf269552010-12-14 14:59:29 +00006918 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006919 if (status != 0)
6920 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006921 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006922 if (status != 0)
6923 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006924 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006925out:
6926 return status;
6927}
6928
6929/*
6930 * Decode LAYOUTGET response
6931 */
Chuck Leverbf269552010-12-14 14:59:29 +00006932static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6933 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006934 struct nfs4_layoutget_res *res)
6935{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006936 struct compound_hdr hdr;
6937 int status;
6938
Chuck Leverbf269552010-12-14 14:59:29 +00006939 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006940 if (status)
6941 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006942 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006943 if (status)
6944 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006945 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006946 if (status)
6947 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006948 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006949out:
6950 return status;
6951}
Andy Adamson863a3c62011-03-23 13:27:54 +00006952
6953/*
Benny Halevycbe82602011-05-22 19:52:37 +03006954 * Decode LAYOUTRETURN response
6955 */
6956static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6957 struct xdr_stream *xdr,
6958 struct nfs4_layoutreturn_res *res)
6959{
6960 struct compound_hdr hdr;
6961 int status;
6962
6963 status = decode_compound_hdr(xdr, &hdr);
6964 if (status)
6965 goto out;
6966 status = decode_sequence(xdr, &res->seq_res, rqstp);
6967 if (status)
6968 goto out;
6969 status = decode_putfh(xdr);
6970 if (status)
6971 goto out;
6972 status = decode_layoutreturn(xdr, res);
6973out:
6974 return status;
6975}
6976
6977/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006978 * Decode LAYOUTCOMMIT response
6979 */
6980static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6981 struct xdr_stream *xdr,
6982 struct nfs4_layoutcommit_res *res)
6983{
6984 struct compound_hdr hdr;
6985 int status;
6986
6987 status = decode_compound_hdr(xdr, &hdr);
6988 if (status)
6989 goto out;
6990 status = decode_sequence(xdr, &res->seq_res, rqstp);
6991 if (status)
6992 goto out;
6993 status = decode_putfh(xdr);
6994 if (status)
6995 goto out;
6996 status = decode_layoutcommit(xdr, rqstp, res);
6997 if (status)
6998 goto out;
Trond Myklebust6926afd12012-01-07 13:22:46 -05006999 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007000out:
7001 return status;
7002}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007003
7004/*
7005 * Decode SECINFO_NO_NAME response
7006 */
7007static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7008 struct xdr_stream *xdr,
7009 struct nfs4_secinfo_res *res)
7010{
7011 struct compound_hdr hdr;
7012 int status;
7013
7014 status = decode_compound_hdr(xdr, &hdr);
7015 if (status)
7016 goto out;
7017 status = decode_sequence(xdr, &res->seq_res, rqstp);
7018 if (status)
7019 goto out;
7020 status = decode_putrootfh(xdr);
7021 if (status)
7022 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007023 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007024out:
7025 return status;
7026}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007027
7028/*
7029 * Decode TEST_STATEID response
7030 */
7031static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7032 struct xdr_stream *xdr,
7033 struct nfs41_test_stateid_res *res)
7034{
7035 struct compound_hdr hdr;
7036 int status;
7037
7038 status = decode_compound_hdr(xdr, &hdr);
7039 if (status)
7040 goto out;
7041 status = decode_sequence(xdr, &res->seq_res, rqstp);
7042 if (status)
7043 goto out;
7044 status = decode_test_stateid(xdr, res);
7045out:
7046 return status;
7047}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007048
7049/*
7050 * Decode FREE_STATEID response
7051 */
7052static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7053 struct xdr_stream *xdr,
7054 struct nfs41_free_stateid_res *res)
7055{
7056 struct compound_hdr hdr;
7057 int status;
7058
7059 status = decode_compound_hdr(xdr, &hdr);
7060 if (status)
7061 goto out;
7062 status = decode_sequence(xdr, &res->seq_res, rqstp);
7063 if (status)
7064 goto out;
7065 status = decode_free_stateid(xdr, res);
7066out:
7067 return status;
7068}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007069#endif /* CONFIG_NFS_V4_1 */
7070
Chuck Lever573c4e12010-12-14 14:58:11 +00007071/**
7072 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7073 * the local page cache.
7074 * @xdr: XDR stream where entry resides
7075 * @entry: buffer to fill in with entry data
7076 * @plus: boolean indicating whether this should be a readdirplus entry
7077 *
7078 * Returns zero if successful, otherwise a negative errno value is
7079 * returned.
7080 *
7081 * This function is not invoked during READDIR reply decoding, but
7082 * rather whenever an application invokes the getdents(2) system call
7083 * on a directory already in our cache.
7084 */
7085int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7086 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007087{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007088 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007089 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007090 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007091 __be32 *p = xdr_inline_decode(xdr, 4);
7092 if (unlikely(!p))
7093 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007094 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007095 p = xdr_inline_decode(xdr, 4);
7096 if (unlikely(!p))
7097 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007098 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007099 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007100 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007101 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007102 }
7103
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007104 p = xdr_inline_decode(xdr, 12);
7105 if (unlikely(!p))
7106 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007107 entry->prev_cookie = entry->cookie;
7108 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007109 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007110
Trond Myklebust9af8c222010-10-24 11:52:55 -04007111 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007112 if (unlikely(!p))
7113 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007114 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007115
7116 /*
7117 * In case the server doesn't return an inode number,
7118 * we fake one here. (We don't use inode number 0,
7119 * since glibc seems to choke on it...)
7120 */
7121 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007122 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007123
Trond Myklebust9af8c222010-10-24 11:52:55 -04007124 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007125 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007126
Trond Myklebust256e48b2012-06-21 11:18:13 -04007127 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007128 goto out_overflow;
7129
Chuck Lever573c4e12010-12-14 14:58:11 +00007130 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007131 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007132 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007133 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7134 entry->ino = entry->fattr->mounted_on_fileid;
7135 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007136 entry->ino = entry->fattr->fileid;
7137
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007138 entry->d_type = DT_UNKNOWN;
7139 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7140 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7141
Chuck Lever573c4e12010-12-14 14:58:11 +00007142 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007143
7144out_overflow:
7145 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007146 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007147}
7148
7149/*
7150 * We need to translate between nfs status return values and
7151 * the local errno values which may not be the same.
7152 */
7153static struct {
7154 int stat;
7155 int errno;
7156} nfs_errtbl[] = {
7157 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007158 { NFS4ERR_PERM, -EPERM },
7159 { NFS4ERR_NOENT, -ENOENT },
7160 { NFS4ERR_IO, -errno_NFSERR_IO},
7161 { NFS4ERR_NXIO, -ENXIO },
7162 { NFS4ERR_ACCESS, -EACCES },
7163 { NFS4ERR_EXIST, -EEXIST },
7164 { NFS4ERR_XDEV, -EXDEV },
7165 { NFS4ERR_NOTDIR, -ENOTDIR },
7166 { NFS4ERR_ISDIR, -EISDIR },
7167 { NFS4ERR_INVAL, -EINVAL },
7168 { NFS4ERR_FBIG, -EFBIG },
7169 { NFS4ERR_NOSPC, -ENOSPC },
7170 { NFS4ERR_ROFS, -EROFS },
7171 { NFS4ERR_MLINK, -EMLINK },
7172 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7173 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7174 { NFS4ERR_DQUOT, -EDQUOT },
7175 { NFS4ERR_STALE, -ESTALE },
7176 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007177 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7178 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7179 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007180 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007181 { NFS4ERR_BADTYPE, -EBADTYPE },
7182 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007183 { NFS4ERR_SYMLINK, -ELOOP },
7184 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7185 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007186 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007187};
7188
7189/*
7190 * Convert an NFS error code to a local one.
7191 * This one is used jointly by NFSv2 and NFSv3.
7192 */
7193static int
David Howells0a8ea432006-08-22 20:06:08 -04007194nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007195{
7196 int i;
7197 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7198 if (nfs_errtbl[i].stat == stat)
7199 return nfs_errtbl[i].errno;
7200 }
7201 if (stat <= 10000 || stat > 10100) {
7202 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007203 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007204 }
7205 /* If we cannot translate the error, the recovery routines should
7206 * handle it.
7207 * Note: remaining NFSv4 error codes have values > 10000, so should
7208 * not conflict with native Linux error codes.
7209 */
Benny Halevy856dff32008-03-31 17:39:06 +03007210 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007211}
7212
Linus Torvalds1da177e2005-04-16 15:20:36 -07007213#define PROC(proc, argtype, restype) \
7214[NFSPROC4_CLNT_##proc] = { \
7215 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007216 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007217 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007218 .p_arglen = NFS4_##argtype##_sz, \
7219 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007220 .p_statidx = NFSPROC4_CLNT_##proc, \
7221 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007222}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007223
7224struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007225 PROC(READ, enc_read, dec_read),
7226 PROC(WRITE, enc_write, dec_write),
7227 PROC(COMMIT, enc_commit, dec_commit),
7228 PROC(OPEN, enc_open, dec_open),
7229 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7230 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7231 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7232 PROC(CLOSE, enc_close, dec_close),
7233 PROC(SETATTR, enc_setattr, dec_setattr),
7234 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7235 PROC(RENEW, enc_renew, dec_renew),
7236 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7237 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7238 PROC(LOCK, enc_lock, dec_lock),
7239 PROC(LOCKT, enc_lockt, dec_lockt),
7240 PROC(LOCKU, enc_locku, dec_locku),
7241 PROC(ACCESS, enc_access, dec_access),
7242 PROC(GETATTR, enc_getattr, dec_getattr),
7243 PROC(LOOKUP, enc_lookup, dec_lookup),
7244 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7245 PROC(REMOVE, enc_remove, dec_remove),
7246 PROC(RENAME, enc_rename, dec_rename),
7247 PROC(LINK, enc_link, dec_link),
7248 PROC(SYMLINK, enc_symlink, dec_symlink),
7249 PROC(CREATE, enc_create, dec_create),
7250 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7251 PROC(STATFS, enc_statfs, dec_statfs),
7252 PROC(READLINK, enc_readlink, dec_readlink),
7253 PROC(READDIR, enc_readdir, dec_readdir),
7254 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7255 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7256 PROC(GETACL, enc_getacl, dec_getacl),
7257 PROC(SETACL, enc_setacl, dec_setacl),
7258 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7259 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007260 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007261#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007262 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7263 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7264 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7265 PROC(SEQUENCE, enc_sequence, dec_sequence),
7266 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7267 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7268 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7269 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007270 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007271 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007272 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007273 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007274 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007275 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007276 PROC(BIND_CONN_TO_SESSION,
7277 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007278 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007279#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007280};
7281
Trond Myklebusta613fa12012-01-20 13:53:56 -05007282const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007283 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007284 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007285 .procs = nfs4_procedures
7286};
7287
7288/*
7289 * Local variables:
7290 * c-basic-offset: 8
7291 * End:
7292 */