blob: 1854b04f828fb2362045f50e358b1cf39a57adc4 [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))
David Quigleyaa9c2662013-05-22 12:50:44 -0400105#ifdef CONFIG_NFS_V4_SECURITY_LABEL
106/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
108#define encode_readdir_space 24
109#define encode_readdir_bitmask_sz 3
110#else
111#define nfs4_label_maxsz 0
112#define encode_readdir_space 20
113#define encode_readdir_bitmask_sz 2
114#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400115/* We support only one layout type per file system */
116#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000117/* This is based on getfattr, which uses the most attributes: */
118#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400119 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400120 nfs4_group_maxsz + nfs4_label_maxsz + \
121 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000122#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
123 nfs4_fattr_value_maxsz)
124#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400125#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
126 1 + 2 + 1 + \
127 nfs4_owner_maxsz + \
128 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400129 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400130 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#define encode_savefh_maxsz (op_encode_hdr_maxsz)
132#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400133#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
134#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200135#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400136/* The 5 accounts for the PNFS attributes, and assumes that at most three
137 * layout types will be returned.
138 */
139#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
140 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
142#define decode_renew_maxsz (op_decode_hdr_maxsz)
143#define encode_setclientid_maxsz \
144 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500145 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
146 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
147 1 /* sc_prog */ + \
148 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
149 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
150 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#define decode_setclientid_maxsz \
152 (op_decode_hdr_maxsz + \
153 2 + \
154 1024) /* large value for CLID_INUSE */
155#define encode_setclientid_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 3 + (NFS4_VERIFIER_SIZE >> 2))
158#define decode_setclientid_confirm_maxsz \
159 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400160#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
161#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400162#define encode_share_access_maxsz \
163 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500164#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400165#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
166#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
167#define encode_open_maxsz (op_encode_hdr_maxsz + \
168 2 + encode_share_access_maxsz + 2 + \
169 open_owner_id_maxsz + \
170 encode_opentype_maxsz + \
171 encode_claim_null_maxsz)
172#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400173#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400174 decode_ace_maxsz)
175#define decode_change_info_maxsz (5)
176#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400177 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400178 decode_change_info_maxsz + 1 + \
179 nfs4_fattr_bitmap_maxsz + \
180 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400181#define encode_open_confirm_maxsz \
182 (op_encode_hdr_maxsz + \
183 encode_stateid_maxsz + 1)
184#define decode_open_confirm_maxsz \
185 (op_decode_hdr_maxsz + \
186 decode_stateid_maxsz)
187#define encode_open_downgrade_maxsz \
188 (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 1 + \
190 encode_share_access_maxsz)
191#define decode_open_downgrade_maxsz \
192 (op_decode_hdr_maxsz + \
193 decode_stateid_maxsz)
194#define encode_close_maxsz (op_encode_hdr_maxsz + \
195 1 + encode_stateid_maxsz)
196#define decode_close_maxsz (op_decode_hdr_maxsz + \
197 decode_stateid_maxsz)
198#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
199 encode_stateid_maxsz + \
200 encode_attrs_maxsz)
201#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
202 nfs4_fattr_bitmap_maxsz)
203#define encode_read_maxsz (op_encode_hdr_maxsz + \
204 encode_stateid_maxsz + 3)
205#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
206#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400207 2 + encode_verifier_maxsz + 5 + \
208 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400209#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400210 decode_verifier_maxsz + \
211 nfs4_label_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400212#define encode_readlink_maxsz (op_encode_hdr_maxsz)
213#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
214#define encode_write_maxsz (op_encode_hdr_maxsz + \
215 encode_stateid_maxsz + 4)
216#define decode_write_maxsz (op_decode_hdr_maxsz + \
217 2 + decode_verifier_maxsz)
218#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
219#define decode_commit_maxsz (op_decode_hdr_maxsz + \
220 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#define encode_remove_maxsz (op_encode_hdr_maxsz + \
222 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400223#define decode_remove_maxsz (op_decode_hdr_maxsz + \
224 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#define encode_rename_maxsz (op_encode_hdr_maxsz + \
226 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400227#define decode_rename_maxsz (op_decode_hdr_maxsz + \
228 decode_change_info_maxsz + \
229 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230#define encode_link_maxsz (op_encode_hdr_maxsz + \
231 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400232#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400233#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400234#define encode_lock_maxsz (op_encode_hdr_maxsz + \
235 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400236 1 + encode_stateid_maxsz + 1 + \
237 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400238#define decode_lock_denied_maxsz \
239 (8 + decode_lockowner_maxsz)
240#define decode_lock_maxsz (op_decode_hdr_maxsz + \
241 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400242#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
243 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400244#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
245 decode_lock_denied_maxsz)
246#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
247 encode_stateid_maxsz + \
248 4)
249#define decode_locku_maxsz (op_decode_hdr_maxsz + \
250 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400251#define encode_release_lockowner_maxsz \
252 (op_encode_hdr_maxsz + \
253 encode_lockowner_maxsz)
254#define decode_release_lockowner_maxsz \
255 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400256#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
257#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
259 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400260 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000261 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
263#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400264 1 + 2 + nfs4_name_maxsz + \
265 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400266#define decode_create_maxsz (op_decode_hdr_maxsz + \
267 decode_change_info_maxsz + \
268 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400269#define encode_statfs_maxsz (encode_getattr_maxsz)
270#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
272#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400273#define encode_getacl_maxsz (encode_getattr_maxsz)
274#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
275 nfs4_fattr_bitmap_maxsz + 1)
276#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
277 encode_stateid_maxsz + 3)
278#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400279#define encode_fs_locations_maxsz \
280 (encode_getattr_maxsz)
281#define decode_fs_locations_maxsz \
282 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000283#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400284#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 -0400285
286#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400287#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500288#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
289 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400290
Benny Halevy99fe60d2009-04-01 09:22:29 -0400291#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
292 encode_verifier_maxsz + \
293 1 /* co_ownerid.len */ + \
294 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
295 1 /* flags */ + \
296 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400297 /* max is SP4_MACH_CRED (for now) */ + \
298 1 + NFS4_OP_MAP_NUM_WORDS + \
299 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500300 1 /* implementation id array of size 1 */ + \
301 1 /* nii_domain */ + \
302 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
303 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500304 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500305 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400306#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
307 2 /* eir_clientid */ + \
308 1 /* eir_sequenceid */ + \
309 1 /* eir_flags */ + \
310 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400311 /* max is SP4_MACH_CRED (for now) */ + \
312 1 + NFS4_OP_MAP_NUM_WORDS + \
313 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400314 2 /* eir_server_owner.so_minor_id */ + \
315 /* eir_server_owner.so_major_id<> */ \
316 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
317 /* eir_server_scope<> */ \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
319 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500320 1 /* nii_domain */ + \
321 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
322 1 /* nii_name */ + \
323 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
324 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400325#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
326#define decode_channel_attrs_maxsz (6 + \
327 1 /* ca_rdma_ird.len */ + \
328 1 /* ca_rdma_ird */)
329#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
330 2 /* csa_clientid */ + \
331 1 /* csa_sequence */ + \
332 1 /* csa_flags */ + \
333 encode_channel_attrs_maxsz + \
334 encode_channel_attrs_maxsz + \
335 1 /* csa_cb_program */ + \
336 1 /* csa_sec_parms.len (1) */ + \
337 1 /* cb_secflavor (AUTH_SYS) */ + \
338 1 /* stamp */ + \
339 1 /* machinename.len */ + \
340 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
341 1 /* uid */ + \
342 1 /* gid */ + \
343 1 /* gids.len (0) */)
344#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
345 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
346 1 /* csr_sequence */ + \
347 1 /* csr_flags */ + \
348 decode_channel_attrs_maxsz + \
349 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400350#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
351 /* bctsa_sessid */ \
352 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
353 1 /* bctsa_dir */ + \
354 1 /* bctsa_use_conn_in_rdma_mode */)
355#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
356 /* bctsr_sessid */ \
357 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
358 1 /* bctsr_dir */ + \
359 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400360#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
361#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400362#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
363#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400364#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
365 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
366#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
367 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500368#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
369#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400370#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
371 encode_verifier_maxsz)
372#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
373 2 /* nfs_cookie4 gdlr_cookie */ + \
374 decode_verifier_maxsz \
375 /* verifier4 gdlr_verifier */ + \
376 1 /* gdlr_deviceid_list count */ + \
377 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
378 NFS4_DEVICEID4_SIZE) \
379 /* gdlr_deviceid_list */ + \
380 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400381#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
382 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
383#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
384 1 /* layout type */ + \
385 1 /* opaque devaddr4 length */ + \
386 /* devaddr4 payload is read into page */ \
387 1 /* notification bitmap length */ + \
388 1 /* notification bitmap */)
389#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
390 encode_stateid_maxsz)
391#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
392 decode_stateid_maxsz + \
393 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000394#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
395 2 /* offset */ + \
396 2 /* length */ + \
397 1 /* reclaim */ + \
398 encode_stateid_maxsz + \
399 1 /* new offset (true) */ + \
400 2 /* last byte written */ + \
401 1 /* nt_timechanged (false) */ + \
402 1 /* layoutupdate4 layout type */ + \
403 1 /* NULL filelayout layoutupdate4 payload */)
404#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300405#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
406 encode_stateid_maxsz + \
407 1 /* FIXME: opaque lrf_body always empty at the moment */)
408#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
409 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400410#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
411#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400412#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
413 XDR_QUADLEN(NFS4_STATEID_SIZE))
414#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400415#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
416 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400417#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400418#else /* CONFIG_NFS_V4_1 */
419#define encode_sequence_maxsz 0
420#define decode_sequence_maxsz 0
421#endif /* CONFIG_NFS_V4_1 */
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
424#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
425#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400432 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_enc_readdir_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 Myklebust9104a552007-07-17 21:52:42 -0400444 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_dec_readdir_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 Myklebust9104a552007-07-17 21:52:42 -0400448 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400450 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400452 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400453 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400455 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400457 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400458 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400462 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400466 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400468 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400469 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400470 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400471 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400477 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400478 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400479 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400480 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400481#define NFS4_enc_open_confirm_sz \
482 (compound_encode_hdr_maxsz + \
483 encode_putfh_maxsz + \
484 encode_open_confirm_maxsz)
485#define NFS4_dec_open_confirm_sz \
486 (compound_decode_hdr_maxsz + \
487 decode_putfh_maxsz + \
488 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400492 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400493 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400498 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400499 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400500 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501#define NFS4_enc_open_downgrade_sz \
502 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400504 encode_putfh_maxsz + \
505 encode_open_downgrade_maxsz + \
506 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#define NFS4_dec_open_downgrade_sz \
508 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400509 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400510 decode_putfh_maxsz + \
511 decode_open_downgrade_maxsz + \
512 decode_getattr_maxsz)
513#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400514 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400515 encode_putfh_maxsz + \
516 encode_close_maxsz + \
517 encode_getattr_maxsz)
518#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400519 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400520 decode_putfh_maxsz + \
521 decode_close_maxsz + \
522 decode_getattr_maxsz)
523#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400525 encode_putfh_maxsz + \
526 encode_setattr_maxsz + \
527 encode_getattr_maxsz)
528#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400529 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400530 decode_putfh_maxsz + \
531 decode_setattr_maxsz + \
532 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 encode_putfh_maxsz + \
536 encode_fsinfo_maxsz)
537#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 decode_putfh_maxsz + \
540 decode_fsinfo_maxsz)
541#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
542 encode_renew_maxsz)
543#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
544 decode_renew_maxsz)
545#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
546 encode_setclientid_maxsz)
547#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
548 decode_setclientid_maxsz)
549#define NFS4_enc_setclientid_confirm_sz \
550 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400551 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#define NFS4_dec_setclientid_confirm_sz \
553 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400554 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400558 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400562 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400566 encode_lockt_maxsz)
567#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400569 decode_putfh_maxsz + \
570 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_enc_locku_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 Myklebust9104a552007-07-17 21:52:42 -0400574 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400576 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400578 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400579#define NFS4_enc_release_lockowner_sz \
580 (compound_encode_hdr_maxsz + \
581 encode_lockowner_maxsz)
582#define NFS4_dec_release_lockowner_sz \
583 (compound_decode_hdr_maxsz + \
584 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400588 encode_access_maxsz + \
589 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400593 decode_access_maxsz + \
594 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 encode_putfh_maxsz + \
598 encode_getattr_maxsz)
599#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 decode_putfh_maxsz + \
602 decode_getattr_maxsz)
603#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400604 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 encode_putfh_maxsz + \
606 encode_lookup_maxsz + \
607 encode_getattr_maxsz + \
608 encode_getfh_maxsz)
609#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400612 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 decode_getattr_maxsz + \
614 decode_getfh_maxsz)
615#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 encode_putrootfh_maxsz + \
618 encode_getattr_maxsz + \
619 encode_getfh_maxsz)
620#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400621 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 decode_putrootfh_maxsz + \
623 decode_getattr_maxsz + \
624 decode_getfh_maxsz)
625#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400628 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400632 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 encode_putfh_maxsz + \
636 encode_savefh_maxsz + \
637 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400638 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#define NFS4_dec_rename_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 Myklebust778d2812012-04-27 13:48:19 -0400644 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 encode_putfh_maxsz + \
648 encode_savefh_maxsz + \
649 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400650 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400651 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400652 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653#define NFS4_dec_link_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_savefh_maxsz + \
657 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400658 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400659 decode_restorefh_maxsz + \
660 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400662 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 encode_putfh_maxsz + \
664 encode_symlink_maxsz + \
665 encode_getattr_maxsz + \
666 encode_getfh_maxsz)
667#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 decode_putfh_maxsz + \
670 decode_symlink_maxsz + \
671 decode_getattr_maxsz + \
672 decode_getfh_maxsz)
673#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400674 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 encode_putfh_maxsz + \
676 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400677 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400678 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 decode_putfh_maxsz + \
682 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400683 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400684 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400686 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 encode_putfh_maxsz + \
688 encode_getattr_maxsz)
689#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 decode_putfh_maxsz + \
692 decode_getattr_maxsz)
693#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400696 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400700 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800703 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 encode_getattr_maxsz)
705#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800707 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 decode_getattr_maxsz)
709#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400710 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100712 encode_delegreturn_maxsz + \
713 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400715 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100716 decode_delegreturn_maxsz + \
717 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000718#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400719 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000720 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400721 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000722#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400723 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000724 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400725 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000726#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400727 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000728 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400729 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000730#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400731 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000732 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400733 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400734#define NFS4_enc_fs_locations_sz \
735 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400736 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400737 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400738 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400739 encode_fs_locations_maxsz + \
740 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400741#define NFS4_dec_fs_locations_sz \
742 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400743 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400744 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400745 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400746 decode_fs_locations_maxsz + \
747 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000748#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
749 encode_sequence_maxsz + \
750 encode_putfh_maxsz + \
751 encode_secinfo_maxsz)
752#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
753 decode_sequence_maxsz + \
754 decode_putfh_maxsz + \
755 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400756#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400757#define NFS4_enc_bind_conn_to_session_sz \
758 (compound_encode_hdr_maxsz + \
759 encode_bind_conn_to_session_maxsz)
760#define NFS4_dec_bind_conn_to_session_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400763#define NFS4_enc_exchange_id_sz \
764 (compound_encode_hdr_maxsz + \
765 encode_exchange_id_maxsz)
766#define NFS4_dec_exchange_id_sz \
767 (compound_decode_hdr_maxsz + \
768 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400769#define NFS4_enc_create_session_sz \
770 (compound_encode_hdr_maxsz + \
771 encode_create_session_maxsz)
772#define NFS4_dec_create_session_sz \
773 (compound_decode_hdr_maxsz + \
774 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400775#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
776 encode_destroy_session_maxsz)
777#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
778 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400779#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
780 encode_destroy_clientid_maxsz)
781#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
782 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400783#define NFS4_enc_sequence_sz \
784 (compound_decode_hdr_maxsz + \
785 encode_sequence_maxsz)
786#define NFS4_dec_sequence_sz \
787 (compound_decode_hdr_maxsz + \
788 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400789#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
790 encode_sequence_maxsz + \
791 encode_putrootfh_maxsz + \
792 encode_fsinfo_maxsz)
793#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
794 decode_sequence_maxsz + \
795 decode_putrootfh_maxsz + \
796 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500797#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_reclaim_complete_maxsz)
800#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
801 decode_sequence_maxsz + \
802 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400803#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
804 encode_sequence_maxsz + \
805 encode_putfh_maxsz + \
806 encode_getdevicelist_maxsz)
807#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
808 decode_sequence_maxsz + \
809 decode_putfh_maxsz + \
810 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400811#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
812 encode_sequence_maxsz +\
813 encode_getdeviceinfo_maxsz)
814#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_getdeviceinfo_maxsz)
817#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
818 encode_sequence_maxsz + \
819 encode_putfh_maxsz + \
820 encode_layoutget_maxsz)
821#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_putfh_maxsz + \
824 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000825#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
826 encode_sequence_maxsz +\
827 encode_putfh_maxsz + \
828 encode_layoutcommit_maxsz + \
829 encode_getattr_maxsz)
830#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
831 decode_sequence_maxsz + \
832 decode_putfh_maxsz + \
833 decode_layoutcommit_maxsz + \
834 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300835#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
836 encode_sequence_maxsz + \
837 encode_putfh_maxsz + \
838 encode_layoutreturn_maxsz)
839#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
840 decode_sequence_maxsz + \
841 decode_putfh_maxsz + \
842 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400843#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
844 encode_sequence_maxsz + \
845 encode_putrootfh_maxsz +\
846 encode_secinfo_no_name_maxsz)
847#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
848 decode_sequence_maxsz + \
849 decode_putrootfh_maxsz + \
850 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400851#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
852 encode_sequence_maxsz + \
853 encode_test_stateid_maxsz)
854#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
855 decode_sequence_maxsz + \
856 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400857#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
858 encode_sequence_maxsz + \
859 encode_free_stateid_maxsz)
860#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
861 decode_sequence_maxsz + \
862 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500863
864const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
865 compound_encode_hdr_maxsz +
866 encode_sequence_maxsz +
867 encode_putfh_maxsz +
868 encode_getattr_maxsz) *
869 XDR_UNIT);
870
871const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
872 compound_decode_hdr_maxsz +
873 decode_sequence_maxsz +
874 decode_putfh_maxsz) *
875 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400876
877const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
878 compound_decode_hdr_maxsz +
879 decode_sequence_maxsz) *
880 XDR_UNIT);
881EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400882#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Trond Myklebustbca79472009-03-11 14:10:26 -0400884static const umode_t nfs_type2fmt[] = {
885 [NF4BAD] = 0,
886 [NF4REG] = S_IFREG,
887 [NF4DIR] = S_IFDIR,
888 [NF4BLK] = S_IFBLK,
889 [NF4CHR] = S_IFCHR,
890 [NF4LNK] = S_IFLNK,
891 [NF4SOCK] = S_IFSOCK,
892 [NF4FIFO] = S_IFIFO,
893 [NF4ATTRDIR] = 0,
894 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895};
896
897struct compound_hdr {
898 int32_t status;
899 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500900 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 uint32_t taglen;
902 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400903 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400904 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905};
906
Benny Halevy13c65ce2009-08-14 17:19:25 +0300907static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
908{
909 __be32 *p = xdr_reserve_space(xdr, nbytes);
910 BUG_ON(!p);
911 return p;
912}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Trond Myklebustcb17e552012-03-04 18:13:56 -0500914static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
915{
916 __be32 *p;
917
918 p = xdr_reserve_space(xdr, len);
919 xdr_encode_opaque_fixed(p, buf, len);
920}
921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
923{
Al Viro8687b632006-10-19 23:28:48 -0700924 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500926 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 xdr_encode_opaque(p, str, len);
928}
929
Trond Myklebust4ade9822012-03-04 18:13:57 -0500930static void encode_uint32(struct xdr_stream *xdr, u32 n)
931{
932 __be32 *p;
933
934 p = reserve_space(xdr, 4);
935 *p = cpu_to_be32(n);
936}
937
Trond Myklebustff2eb682012-03-05 11:40:12 -0500938static void encode_uint64(struct xdr_stream *xdr, u64 n)
939{
940 __be32 *p;
941
942 p = reserve_space(xdr, 8);
943 xdr_encode_hyper(p, n);
944}
945
Trond Myklebust4ade9822012-03-04 18:13:57 -0500946static void encode_nfs4_seqid(struct xdr_stream *xdr,
947 const struct nfs_seqid *seqid)
948{
949 encode_uint32(xdr, seqid->sequence->counter);
950}
951
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400952static void encode_compound_hdr(struct xdr_stream *xdr,
953 struct rpc_rqst *req,
954 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
Al Viro8687b632006-10-19 23:28:48 -0700956 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400957 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400958
959 /* initialize running count of expected bytes in reply.
960 * NOTE: the replied tag SHOULD be the same is the one sent,
961 * but this is not required as a MUST for the server to do so. */
962 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Trond Myklebust7fc38842012-10-15 11:51:21 -0400964 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500965 encode_string(xdr, hdr->taglen, hdr->tag);
966 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300967 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500968 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300969 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500970}
971
Trond Myklebustab19b482012-03-04 18:13:57 -0500972static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
973 uint32_t replen,
974 struct compound_hdr *hdr)
975{
976 encode_uint32(xdr, op);
977 hdr->nops++;
978 hdr->replen += replen;
979}
980
Andy Adamsond0179312008-12-23 16:06:17 -0500981static void encode_nops(struct compound_hdr *hdr)
982{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400983 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500984 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985}
986
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500987static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
988{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500989 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500990}
991
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
993{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500994 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995}
996
David Quigleyaa9c2662013-05-22 12:50:44 -0400997static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
998 const struct nfs4_label *label,
999 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
1001 char owner_name[IDMAP_NAMESZ];
1002 char owner_group[IDMAP_NAMESZ];
1003 int owner_namelen = 0;
1004 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001005 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001006 unsigned i;
1007 uint32_t len = 0;
1008 uint32_t bmval_len;
1009 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
1011 /*
1012 * We reserve enough space to write the entire attribute buffer at once.
1013 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001014 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1015 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001016 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001018 if (iap->ia_valid & ATTR_SIZE) {
1019 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001021 }
1022 if (iap->ia_valid & ATTR_MODE) {
1023 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001025 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001027 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001029 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001030 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 /* XXX */
1032 strcpy(owner_name, "nobody");
1033 owner_namelen = sizeof("nobody") - 1;
1034 /* goto out; */
1035 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001036 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1038 }
1039 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001040 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001042 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001043 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 strcpy(owner_group, "nobody");
1045 owner_grouplen = sizeof("nobody") - 1;
1046 /* goto out; */
1047 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001048 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1050 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001052 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1053 len += 16;
1054 } else if (iap->ia_valid & ATTR_ATIME) {
1055 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1056 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
1058 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001059 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1060 len += 16;
1061 } else if (iap->ia_valid & ATTR_MTIME) {
1062 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1063 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001065 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001066 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1067 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1068 }
1069
1070 if (bmval[2] != 0)
1071 bmval_len = 3;
1072 else if (bmval[1] != 0)
1073 bmval_len = 2;
1074 else
1075 bmval_len = 1;
1076
1077 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1078
1079 *p++ = cpu_to_be32(bmval_len);
1080 for (i = 0; i < bmval_len; i++)
1081 *p++ = cpu_to_be32(bmval[i]);
1082 *p++ = cpu_to_be32(len);
1083
1084 if (bmval[0] & FATTR4_WORD0_SIZE)
1085 p = xdr_encode_hyper(p, iap->ia_size);
1086 if (bmval[1] & FATTR4_WORD1_MODE)
1087 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1088 if (bmval[1] & FATTR4_WORD1_OWNER)
1089 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1090 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1091 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1092 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1093 if (iap->ia_valid & ATTR_ATIME_SET) {
1094 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1095 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1096 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1097 } else
1098 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1099 }
1100 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1101 if (iap->ia_valid & ATTR_MTIME_SET) {
1102 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1103 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1104 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1105 } else
1106 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1107 }
1108 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001109 *p++ = cpu_to_be32(label->lfs);
1110 *p++ = cpu_to_be32(label->pi);
1111 *p++ = cpu_to_be32(label->len);
1112 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1113 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001118static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001120 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1121 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001124static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
Trond Myklebustab19b482012-03-04 18:13:57 -05001126 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001127 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001128 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129}
1130
Fred Isaman0b7c0152012-04-20 14:47:39 -04001131static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132{
Al Viro8687b632006-10-19 23:28:48 -07001133 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001134
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001135 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1136 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001137 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001138 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Al Viro8687b632006-10-19 23:28:48 -07001143 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001144
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001145 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1146 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148 switch (create->ftype) {
1149 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001150 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001151 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001152 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 break;
1154
1155 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001156 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001157 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001158 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 break;
1160
1161 default:
1162 break;
1163 }
1164
Benny Halevy811652b2009-08-14 17:19:34 +03001165 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001166 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167}
1168
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001169static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170{
Andy Adamson05d564f2008-12-23 16:06:15 -05001171 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001173 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1174 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001175 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001176 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177}
1178
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001179static 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 -07001180{
Andy Adamson05d564f2008-12-23 16:06:15 -05001181 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001183 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1184 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001185 *p++ = cpu_to_be32(2);
1186 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001187 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188}
1189
Fred Isamandae100c2011-07-30 20:52:37 -04001190static void
1191encode_getattr_three(struct xdr_stream *xdr,
1192 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1193 struct compound_hdr *hdr)
1194{
1195 __be32 *p;
1196
Trond Myklebustab19b482012-03-04 18:13:57 -05001197 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001198 if (bm2) {
1199 p = reserve_space(xdr, 16);
1200 *p++ = cpu_to_be32(3);
1201 *p++ = cpu_to_be32(bm0);
1202 *p++ = cpu_to_be32(bm1);
1203 *p = cpu_to_be32(bm2);
1204 } else if (bm1) {
1205 p = reserve_space(xdr, 12);
1206 *p++ = cpu_to_be32(2);
1207 *p++ = cpu_to_be32(bm0);
1208 *p = cpu_to_be32(bm1);
1209 } else {
1210 p = reserve_space(xdr, 8);
1211 *p++ = cpu_to_be32(1);
1212 *p = cpu_to_be32(bm0);
1213 }
Fred Isamandae100c2011-07-30 20:52:37 -04001214}
1215
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001216static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217{
David Quigleya09df2c2013-05-22 12:50:41 -04001218 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1219 bitmask[1] & nfs4_fattr_bitmap[1],
1220 bitmask[2] & nfs4_fattr_bitmap[2],
1221 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222}
1223
Andy Adamson88034c32012-05-23 05:02:34 -04001224static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001225 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001226 struct compound_hdr *hdr)
1227{
1228 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001229 bitmask[0] & open_bitmap[0],
1230 bitmask[1] & open_bitmap[1],
1231 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001232 hdr);
1233}
1234
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001235static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236{
Fred Isamandae100c2011-07-30 20:52:37 -04001237 encode_getattr_three(xdr,
1238 bitmask[0] & nfs4_fsinfo_bitmap[0],
1239 bitmask[1] & nfs4_fsinfo_bitmap[1],
1240 bitmask[2] & nfs4_fsinfo_bitmap[2],
1241 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242}
1243
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001244static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001245{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001246 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1247 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001248}
1249
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001250static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
Trond Myklebustab19b482012-03-04 18:13:57 -05001252 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253}
1254
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001255static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256{
Trond Myklebustab19b482012-03-04 18:13:57 -05001257 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001258 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259}
1260
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001261static inline int nfs4_lock_type(struct file_lock *fl, int block)
1262{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001263 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001264 return block ? NFS4_READW_LT : NFS4_READ_LT;
1265 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1266}
1267
1268static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1269{
1270 if (fl->fl_end == OFFSET_MAX)
1271 return ~(uint64_t)0;
1272 return fl->fl_end - fl->fl_start + 1;
1273}
1274
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001275static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1276{
1277 __be32 *p;
1278
Trond Myklebustd035c362010-12-21 10:45:27 -05001279 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001280 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001281 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001282 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001283 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001284 xdr_encode_hyper(p, lowner->id);
1285}
1286
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287/*
1288 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1289 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1290 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001291static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_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_LOCK, decode_lock_maxsz, hdr);
1296 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001297 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1298 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001299 p = xdr_encode_hyper(p, args->fl->fl_start);
1300 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001301 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001302 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001303 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001304 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001305 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001306 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 }
1308 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001309 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001310 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312}
1313
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001314static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
Al Viro8687b632006-10-19 23:28:48 -07001316 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001318 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1319 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001320 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001321 p = xdr_encode_hyper(p, args->fl->fl_start);
1322 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001323 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324}
1325
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001326static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
Al Viro8687b632006-10-19 23:28:48 -07001328 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001330 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1331 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001332 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001333 encode_nfs4_stateid(xdr, args->stateid);
1334 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001335 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001336 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001339static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1340{
Trond Myklebustab19b482012-03-04 18:13:57 -05001341 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001342 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001343}
1344
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001345static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
Trond Myklebustab19b482012-03-04 18:13:57 -05001347 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001348 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
1350
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001351static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352{
Al Viro8687b632006-10-19 23:28:48 -07001353 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Benny Halevy13c65ce2009-08-14 17:19:25 +03001355 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001356 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001357 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001358 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001359 break;
1360 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001361 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001362 break;
1363 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001364 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001365 break;
1366 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001367 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 }
Benny Halevy34558512009-08-14 17:19:30 +03001369 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370}
1371
1372static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1373{
Al Viro8687b632006-10-19 23:28:48 -07001374 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 /*
1376 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1377 * owner 4 = 32
1378 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001379 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001380 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001381 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001382 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001383 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001384 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001385 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001386 *p++ = cpu_to_be32(arg->id.uniquifier);
1387 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388}
1389
1390static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1391{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001392 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001393 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Benny Halevy13c65ce2009-08-14 17:19:25 +03001395 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001396 switch(arg->createmode) {
1397 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001398 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001399 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001400 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001401 case NFS4_CREATE_GUARDED:
1402 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001403 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001404 break;
1405 case NFS4_CREATE_EXCLUSIVE:
1406 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1407 encode_nfs4_verifier(xdr, &arg->u.verifier);
1408 break;
1409 case NFS4_CREATE_EXCLUSIVE4_1:
1410 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1411 encode_nfs4_verifier(xdr, &arg->u.verifier);
1412 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001413 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 }
1415}
1416
1417static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1418{
Al Viro8687b632006-10-19 23:28:48 -07001419 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Benny Halevy13c65ce2009-08-14 17:19:25 +03001421 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001423 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001424 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001425 break;
1426 default:
Benny Halevy34558512009-08-14 17:19:30 +03001427 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001428 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 }
1430}
1431
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001432static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433{
Al Viro8687b632006-10-19 23:28:48 -07001434 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Benny Halevy13c65ce2009-08-14 17:19:25 +03001436 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001439 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001440 break;
1441 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001442 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001443 break;
1444 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001445 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001446 break;
1447 default:
1448 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 }
1450}
1451
1452static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1453{
Al Viro8687b632006-10-19 23:28:48 -07001454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Benny Halevy13c65ce2009-08-14 17:19:25 +03001456 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001457 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 encode_string(xdr, name->len, name->name);
1459}
1460
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001461static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462{
Al Viro8687b632006-10-19 23:28:48 -07001463 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Benny Halevy13c65ce2009-08-14 17:19:25 +03001465 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001466 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 encode_delegation_type(xdr, type);
1468}
1469
1470static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1471{
Al Viro8687b632006-10-19 23:28:48 -07001472 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001474 p = reserve_space(xdr, 4);
1475 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1476 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 encode_string(xdr, name->len, name->name);
1478}
1479
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001480static inline void encode_claim_fh(struct xdr_stream *xdr)
1481{
1482 __be32 *p;
1483
1484 p = reserve_space(xdr, 4);
1485 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1486}
1487
1488static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1489{
1490 __be32 *p;
1491
1492 p = reserve_space(xdr, 4);
1493 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1494 encode_nfs4_stateid(xdr, stateid);
1495}
1496
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001497static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
Trond Myklebustab19b482012-03-04 18:13:57 -05001499 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 encode_openhdr(xdr, arg);
1501 encode_opentype(xdr, arg);
1502 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001503 case NFS4_OPEN_CLAIM_NULL:
1504 encode_claim_null(xdr, arg->name);
1505 break;
1506 case NFS4_OPEN_CLAIM_PREVIOUS:
1507 encode_claim_previous(xdr, arg->u.delegation_type);
1508 break;
1509 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1510 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1511 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001512 case NFS4_OPEN_CLAIM_FH:
1513 encode_claim_fh(xdr);
1514 break;
1515 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1516 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1517 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001518 default:
1519 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521}
1522
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001523static 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 -07001524{
Trond Myklebustab19b482012-03-04 18:13:57 -05001525 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001526 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001527 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528}
1529
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001530static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
Trond Myklebustab19b482012-03-04 18:13:57 -05001532 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001533 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001534 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001535 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536}
1537
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001538static void
Andy Adamsond0179312008-12-23 16:06:17 -05001539encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540{
Trond Myklebustab19b482012-03-04 18:13:57 -05001541 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001542 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001545static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546{
Trond Myklebustab19b482012-03-04 18:13:57 -05001547 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001550static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
Al Viro8687b632006-10-19 23:28:48 -07001552 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Trond Myklebustab19b482012-03-04 18:13:57 -05001554 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001555 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Benny Halevy13c65ce2009-08-14 17:19:25 +03001557 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001558 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001559 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560}
1561
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001562static 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 -07001563{
David Quigleyaa9c2662013-05-22 12:50:44 -04001564 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001565 FATTR4_WORD0_RDATTR_ERROR,
1566 FATTR4_WORD1_MOUNTED_ON_FILEID,
1567 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001568 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001569 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001571 if (readdir->plus) {
1572 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001573 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001574 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1575 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1576 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1577 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001578 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001579 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001580 /* Use mounted_on_fileid only if the server supports it */
1581 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1582 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001583
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001584 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001585 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001586 encode_nfs4_verifier(xdr, &readdir->verifier);
David Quigleyaa9c2662013-05-22 12:50:44 -04001587 p = reserve_space(xdr, encode_readdir_space);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001588 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001589 *p++ = cpu_to_be32(readdir->count);
David Quigleyaa9c2662013-05-22 12:50:44 -04001590 *p++ = cpu_to_be32(encode_readdir_bitmask_sz);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001591 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
David Quigleyaa9c2662013-05-22 12:50:44 -04001592 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1593 if (encode_readdir_bitmask_sz > 2) {
1594 if (hdr->minorversion > 1)
1595 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1596 p++, *p++ = cpu_to_be32(attrs[2] & readdir->bitmask[2]);
1597 }
Chuck Levercd937102012-03-02 17:14:31 -05001598 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001599
1600 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001601 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001602 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001603 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001604 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001605 attrs[1] & readdir->bitmask[1],
1606 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607}
1608
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001609static 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 -07001610{
Trond Myklebustab19b482012-03-04 18:13:57 -05001611 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612}
1613
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615{
Trond Myklebustab19b482012-03-04 18:13:57 -05001616 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001617 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618}
1619
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001620static 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 -07001621{
Trond Myklebustab19b482012-03-04 18:13:57 -05001622 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001623 encode_string(xdr, oldname->len, oldname->name);
1624 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625}
1626
Chuck Leverbb4dae52012-03-01 17:01:48 -05001627static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1628 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001630 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001631 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001634static void
Andy Adamsond0179312008-12-23 16:06:17 -05001635encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001636{
Trond Myklebustab19b482012-03-04 18:13:57 -05001637 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001638}
1639
Chuck Lever9f06c712010-12-14 14:59:18 +00001640static void
Andy Adamsond0179312008-12-23 16:06:17 -05001641encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001642{
Al Viro8687b632006-10-19 23:28:48 -07001643 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001644
Trond Myklebustab19b482012-03-04 18:13:57 -05001645 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001646 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001647 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001648 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001649 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001650 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001651 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001652 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001653}
1654
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001655static void
Andy Adamsond0179312008-12-23 16:06:17 -05001656encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657{
Trond Myklebustab19b482012-03-04 18:13:57 -05001658 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
1660
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001661static 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 -07001662{
Trond Myklebustab19b482012-03-04 18:13:57 -05001663 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001664 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001665 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666}
1667
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001668static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, 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 Myklebust70019512012-03-04 20:49:32 -05001672 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001673 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
1675 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001676 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001677 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1679 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001680 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001681 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682}
1683
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001684static 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 -07001685{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001686 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1687 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001688 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001689 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690}
1691
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001692static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693{
Al Viro8687b632006-10-19 23:28:48 -07001694 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Trond Myklebustab19b482012-03-04 18:13:57 -05001696 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001697 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
Benny Halevy13c65ce2009-08-14 17:19:25 +03001699 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001700 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001701 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001702 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
1704 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705}
1706
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001707static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708{
Trond Myklebustab19b482012-03-04 18:13:57 -05001709 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001710 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001712
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001713static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1714{
Trond Myklebustab19b482012-03-04 18:13:57 -05001715 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001716 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001717}
1718
Benny Halevy99fe60d2009-04-01 09:22:29 -04001719#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001720/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001721static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1722 struct nfs4_session *session,
1723 struct compound_hdr *hdr)
1724{
1725 __be32 *p;
1726
1727 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1728 decode_bind_conn_to_session_maxsz, hdr);
1729 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1730 p = xdr_reserve_space(xdr, 8);
1731 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1732 *p = 0; /* use_conn_in_rdma_mode = False */
1733}
1734
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001735static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1736{
1737 unsigned int i;
1738 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1739 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1740 encode_uint32(xdr, op_map->u.words[i]);
1741}
1742
Benny Halevy99fe60d2009-04-01 09:22:29 -04001743static void encode_exchange_id(struct xdr_stream *xdr,
1744 struct nfs41_exchange_id_args *args,
1745 struct compound_hdr *hdr)
1746{
1747 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001748 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001749 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001750
Trond Myklebust70019512012-03-04 20:49:32 -05001751 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001752 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001753
1754 encode_string(xdr, args->id_len, args->id);
1755
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001756 encode_uint32(xdr, args->flags);
1757 encode_uint32(xdr, args->state_protect.how);
1758
1759 switch (args->state_protect.how) {
1760 case SP4_NONE:
1761 break;
1762 case SP4_MACH_CRED:
1763 encode_op_map(xdr, &args->state_protect.enforce);
1764 encode_op_map(xdr, &args->state_protect.allow);
1765 break;
1766 default:
1767 WARN_ON_ONCE(1);
1768 break;
1769 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001770
1771 if (send_implementation_id &&
1772 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1773 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001774 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001775 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1776 utsname()->sysname, utsname()->release,
1777 utsname()->version, utsname()->machine);
1778
1779 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001780 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001781
1782 encode_string(xdr,
1783 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1784 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1785 encode_string(xdr, len, impl_name);
1786 /* just send zeros for nii_date - the date is in nii_name */
1787 p = reserve_space(xdr, 12);
1788 p = xdr_encode_hyper(p, 0);
1789 *p = cpu_to_be32(0);
1790 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001791 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001792}
Andy Adamsonfc931582009-04-01 09:22:31 -04001793
1794static void encode_create_session(struct xdr_stream *xdr,
1795 struct nfs41_create_session_args *args,
1796 struct compound_hdr *hdr)
1797{
1798 __be32 *p;
1799 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1800 uint32_t len;
1801 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001802 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001803 u32 max_resp_sz_cached;
1804
1805 /*
1806 * Assumes OPEN is the biggest non-idempotent compound.
1807 * 2 is the verifier.
1808 */
1809 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1810 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001811
Andy Adamsonfc931582009-04-01 09:22:31 -04001812 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1813 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001814
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001815 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1816 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001817 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001818 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1819 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001820
Andy Adamsonfc931582009-04-01 09:22:31 -04001821 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001822 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001823 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1824 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001825 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001826 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1827 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1828 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001829
1830 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001831 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001832 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1833 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1834 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1835 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1836 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1837 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001838
Benny Halevye75bc1c2009-08-14 17:18:54 +03001839 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001840 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001841 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001842
1843 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001844 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001845 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001846 *p++ = cpu_to_be32(0); /* UID */
1847 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001848 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001849}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001850
1851static void encode_destroy_session(struct xdr_stream *xdr,
1852 struct nfs4_session *session,
1853 struct compound_hdr *hdr)
1854{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001855 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1856 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001857}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001858
Trond Myklebust66245532012-05-25 17:18:09 -04001859static void encode_destroy_clientid(struct xdr_stream *xdr,
1860 uint64_t clientid,
1861 struct compound_hdr *hdr)
1862{
1863 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1864 encode_uint64(xdr, clientid);
1865}
1866
Ricardo Labiaga180197532009-12-05 16:08:40 -05001867static void encode_reclaim_complete(struct xdr_stream *xdr,
1868 struct nfs41_reclaim_complete_args *args,
1869 struct compound_hdr *hdr)
1870{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001871 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1872 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001873}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001874#endif /* CONFIG_NFS_V4_1 */
1875
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001876static void encode_sequence(struct xdr_stream *xdr,
1877 const struct nfs4_sequence_args *args,
1878 struct compound_hdr *hdr)
1879{
1880#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001881 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001882 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001883 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001884 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001885
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001886 tp = slot->table;
1887 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001888 if (!session)
1889 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001890
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001891 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001892
1893 /*
1894 * Sessionid + seqid + slotid + max slotid + cache_this
1895 */
1896 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1897 "max_slotid=%d cache_this=%d\n",
1898 __func__,
1899 ((u32 *)session->sess_id.data)[0],
1900 ((u32 *)session->sess_id.data)[1],
1901 ((u32 *)session->sess_id.data)[2],
1902 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001903 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001904 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001905 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001906 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001907 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001908 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001909 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001910 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001911#endif /* CONFIG_NFS_V4_1 */
1912}
1913
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001914#ifdef CONFIG_NFS_V4_1
1915static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001916encode_getdevicelist(struct xdr_stream *xdr,
1917 const struct nfs4_getdevicelist_args *args,
1918 struct compound_hdr *hdr)
1919{
1920 __be32 *p;
1921 nfs4_verifier dummy = {
1922 .data = "dummmmmy",
1923 };
1924
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001925 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1926 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001927 *p++ = cpu_to_be32(args->layoutclass);
1928 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1929 xdr_encode_hyper(p, 0ULL); /* cookie */
1930 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001931}
1932
1933static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001934encode_getdeviceinfo(struct xdr_stream *xdr,
1935 const struct nfs4_getdeviceinfo_args *args,
1936 struct compound_hdr *hdr)
1937{
1938 __be32 *p;
1939
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001940 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1941 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001942 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1943 NFS4_DEVICEID4_SIZE);
1944 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001945 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001946 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001947}
1948
1949static void
1950encode_layoutget(struct xdr_stream *xdr,
1951 const struct nfs4_layoutget_args *args,
1952 struct compound_hdr *hdr)
1953{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001954 __be32 *p;
1955
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001956 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1957 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001958 *p++ = cpu_to_be32(0); /* Signal layout available */
1959 *p++ = cpu_to_be32(args->type);
1960 *p++ = cpu_to_be32(args->range.iomode);
1961 p = xdr_encode_hyper(p, args->range.offset);
1962 p = xdr_encode_hyper(p, args->range.length);
1963 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001964 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001965 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001966
1967 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1968 __func__,
1969 args->type,
1970 args->range.iomode,
1971 (unsigned long)args->range.offset,
1972 (unsigned long)args->range.length,
1973 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001974}
Andy Adamson863a3c62011-03-23 13:27:54 +00001975
1976static int
1977encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001978 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001979 const struct nfs4_layoutcommit_args *args,
1980 struct compound_hdr *hdr)
1981{
1982 __be32 *p;
1983
1984 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1985 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1986
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001987 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1988 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001989 /* Only whole file layouts */
1990 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001991 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001992 *p = cpu_to_be32(0); /* reclaim */
1993 encode_nfs4_stateid(xdr, &args->stateid);
1994 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001995 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1996 p = xdr_encode_hyper(p, args->lastbytewritten);
1997 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1998 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001999
2000 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2001 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2002 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002003 else
2004 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00002005
Andy Adamson863a3c62011-03-23 13:27:54 +00002006 return 0;
2007}
Benny Halevycbe82602011-05-22 19:52:37 +03002008
2009static void
2010encode_layoutreturn(struct xdr_stream *xdr,
2011 const struct nfs4_layoutreturn_args *args,
2012 struct compound_hdr *hdr)
2013{
2014 __be32 *p;
2015
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002016 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2017 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002018 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2019 *p++ = cpu_to_be32(args->layout_type);
2020 *p++ = cpu_to_be32(IOMODE_ANY);
2021 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002022 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002023 p = xdr_encode_hyper(p, 0);
2024 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2025 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002026 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002027 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002028 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2029 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2030 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002031 } else
2032 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002033}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002034
2035static int
2036encode_secinfo_no_name(struct xdr_stream *xdr,
2037 const struct nfs41_secinfo_no_name_args *args,
2038 struct compound_hdr *hdr)
2039{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002040 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2041 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002042 return 0;
2043}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002044
2045static void encode_test_stateid(struct xdr_stream *xdr,
2046 struct nfs41_test_stateid_args *args,
2047 struct compound_hdr *hdr)
2048{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002049 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2050 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002051 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002052}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002053
2054static void encode_free_stateid(struct xdr_stream *xdr,
2055 struct nfs41_free_stateid_args *args,
2056 struct compound_hdr *hdr)
2057{
Trond Myklebustab19b482012-03-04 18:13:57 -05002058 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002059 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002060}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002061#endif /* CONFIG_NFS_V4_1 */
2062
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063/*
2064 * END OF "GENERIC" ENCODE ROUTINES.
2065 */
2066
Benny Halevy66cc0422009-04-01 09:22:10 -04002067static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2068{
2069#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002070 struct nfs4_session *session = args->sa_slot->table->session;
2071 if (session)
2072 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002073#endif /* CONFIG_NFS_V4_1 */
2074 return 0;
2075}
2076
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077/*
2078 * Encode an ACCESS request
2079 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002080static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2081 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002084 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
Chuck Lever9f06c712010-12-14 14:59:18 +00002087 encode_compound_hdr(xdr, req, &hdr);
2088 encode_sequence(xdr, &args->seq_args, &hdr);
2089 encode_putfh(xdr, args->fh, &hdr);
2090 encode_access(xdr, args->access, &hdr);
2091 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002092 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093}
2094
2095/*
2096 * Encode LOOKUP request
2097 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002098static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2099 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002102 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
Chuck Lever9f06c712010-12-14 14:59:18 +00002105 encode_compound_hdr(xdr, req, &hdr);
2106 encode_sequence(xdr, &args->seq_args, &hdr);
2107 encode_putfh(xdr, args->dir_fh, &hdr);
2108 encode_lookup(xdr, args->name, &hdr);
2109 encode_getfh(xdr, &hdr);
2110 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002111 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112}
2113
2114/*
2115 * Encode LOOKUP_ROOT request
2116 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002117static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2118 struct xdr_stream *xdr,
2119 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002122 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Chuck Lever9f06c712010-12-14 14:59:18 +00002125 encode_compound_hdr(xdr, req, &hdr);
2126 encode_sequence(xdr, &args->seq_args, &hdr);
2127 encode_putrootfh(xdr, &hdr);
2128 encode_getfh(xdr, &hdr);
2129 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002130 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131}
2132
2133/*
2134 * Encode REMOVE request
2135 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002136static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2137 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002140 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
Chuck Lever9f06c712010-12-14 14:59:18 +00002143 encode_compound_hdr(xdr, req, &hdr);
2144 encode_sequence(xdr, &args->seq_args, &hdr);
2145 encode_putfh(xdr, args->fh, &hdr);
2146 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002147 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148}
2149
2150/*
2151 * Encode RENAME request
2152 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002153static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2154 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002157 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159
Chuck Lever9f06c712010-12-14 14:59:18 +00002160 encode_compound_hdr(xdr, req, &hdr);
2161 encode_sequence(xdr, &args->seq_args, &hdr);
2162 encode_putfh(xdr, args->old_dir, &hdr);
2163 encode_savefh(xdr, &hdr);
2164 encode_putfh(xdr, args->new_dir, &hdr);
2165 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002166 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167}
2168
2169/*
2170 * Encode LINK request
2171 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002172static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2173 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002176 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Chuck Lever9f06c712010-12-14 14:59:18 +00002179 encode_compound_hdr(xdr, req, &hdr);
2180 encode_sequence(xdr, &args->seq_args, &hdr);
2181 encode_putfh(xdr, args->fh, &hdr);
2182 encode_savefh(xdr, &hdr);
2183 encode_putfh(xdr, args->dir_fh, &hdr);
2184 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002185 encode_restorefh(xdr, &hdr);
2186 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002187 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188}
2189
2190/*
2191 * Encode CREATE request
2192 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002193static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2194 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002197 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
Chuck Lever9f06c712010-12-14 14:59:18 +00002200 encode_compound_hdr(xdr, req, &hdr);
2201 encode_sequence(xdr, &args->seq_args, &hdr);
2202 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002203 encode_create(xdr, args, &hdr);
2204 encode_getfh(xdr, &hdr);
2205 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002206 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207}
2208
2209/*
2210 * Encode SYMLINK request
2211 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002212static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2213 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214{
Chuck Lever9f06c712010-12-14 14:59:18 +00002215 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216}
2217
2218/*
2219 * Encode GETATTR request
2220 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002221static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2222 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002225 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
Chuck Lever9f06c712010-12-14 14:59:18 +00002228 encode_compound_hdr(xdr, req, &hdr);
2229 encode_sequence(xdr, &args->seq_args, &hdr);
2230 encode_putfh(xdr, args->fh, &hdr);
2231 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002232 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233}
2234
2235/*
2236 * Encode a CLOSE request
2237 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002238static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2239 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240{
Andy Adamson05d564f2008-12-23 16:06:15 -05002241 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002242 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002243 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244
Chuck Lever9f06c712010-12-14 14:59:18 +00002245 encode_compound_hdr(xdr, req, &hdr);
2246 encode_sequence(xdr, &args->seq_args, &hdr);
2247 encode_putfh(xdr, args->fh, &hdr);
2248 encode_close(xdr, args, &hdr);
2249 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002250 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251}
2252
2253/*
2254 * Encode an OPEN request
2255 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002256static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2257 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002260 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Chuck Lever9f06c712010-12-14 14:59:18 +00002263 encode_compound_hdr(xdr, req, &hdr);
2264 encode_sequence(xdr, &args->seq_args, &hdr);
2265 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002266 encode_open(xdr, args, &hdr);
2267 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002268 if (args->access)
2269 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002270 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002271 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272}
2273
2274/*
2275 * Encode an OPEN_CONFIRM request
2276 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002277static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2278 struct xdr_stream *xdr,
2279 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002282 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
Chuck Lever9f06c712010-12-14 14:59:18 +00002285 encode_compound_hdr(xdr, req, &hdr);
2286 encode_putfh(xdr, args->fh, &hdr);
2287 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002288 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289}
2290
2291/*
2292 * Encode an OPEN request with no attributes.
2293 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002294static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2295 struct xdr_stream *xdr,
2296 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002299 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301
Chuck Lever9f06c712010-12-14 14:59:18 +00002302 encode_compound_hdr(xdr, req, &hdr);
2303 encode_sequence(xdr, &args->seq_args, &hdr);
2304 encode_putfh(xdr, args->fh, &hdr);
2305 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002306 if (args->access)
2307 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002308 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002309 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310}
2311
2312/*
2313 * Encode an OPEN_DOWNGRADE request
2314 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002315static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2316 struct xdr_stream *xdr,
2317 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002320 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
Chuck Lever9f06c712010-12-14 14:59:18 +00002323 encode_compound_hdr(xdr, req, &hdr);
2324 encode_sequence(xdr, &args->seq_args, &hdr);
2325 encode_putfh(xdr, args->fh, &hdr);
2326 encode_open_downgrade(xdr, args, &hdr);
2327 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002328 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329}
2330
2331/*
2332 * Encode a LOCK request
2333 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002334static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2335 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002338 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
Chuck Lever9f06c712010-12-14 14:59:18 +00002341 encode_compound_hdr(xdr, req, &hdr);
2342 encode_sequence(xdr, &args->seq_args, &hdr);
2343 encode_putfh(xdr, args->fh, &hdr);
2344 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002345 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346}
2347
2348/*
2349 * Encode a LOCKT request
2350 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002351static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2352 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002355 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
Chuck Lever9f06c712010-12-14 14:59:18 +00002358 encode_compound_hdr(xdr, req, &hdr);
2359 encode_sequence(xdr, &args->seq_args, &hdr);
2360 encode_putfh(xdr, args->fh, &hdr);
2361 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002362 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363}
2364
2365/*
2366 * Encode a LOCKU request
2367 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002368static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2369 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002372 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
Chuck Lever9f06c712010-12-14 14:59:18 +00002375 encode_compound_hdr(xdr, req, &hdr);
2376 encode_sequence(xdr, &args->seq_args, &hdr);
2377 encode_putfh(xdr, args->fh, &hdr);
2378 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002379 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380}
2381
Chuck Lever9f06c712010-12-14 14:59:18 +00002382static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2383 struct xdr_stream *xdr,
2384 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002385{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002386 struct compound_hdr hdr = {
2387 .minorversion = 0,
2388 };
2389
Chuck Lever9f06c712010-12-14 14:59:18 +00002390 encode_compound_hdr(xdr, req, &hdr);
2391 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002392 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002393}
2394
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395/*
2396 * Encode a READLINK request
2397 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002398static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2399 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002402 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
Chuck Lever9f06c712010-12-14 14:59:18 +00002405 encode_compound_hdr(xdr, req, &hdr);
2406 encode_sequence(xdr, &args->seq_args, &hdr);
2407 encode_putfh(xdr, args->fh, &hdr);
2408 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002409
Benny Halevy28f56692009-04-01 09:22:09 -04002410 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002411 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002412 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413}
2414
2415/*
2416 * Encode a READDIR request
2417 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002418static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2419 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002422 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
Chuck Lever9f06c712010-12-14 14:59:18 +00002425 encode_compound_hdr(xdr, req, &hdr);
2426 encode_sequence(xdr, &args->seq_args, &hdr);
2427 encode_putfh(xdr, args->fh, &hdr);
2428 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002429
Benny Halevy28f56692009-04-01 09:22:09 -04002430 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002431 args->pgbase, args->count);
2432 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002433 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002434 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002435 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436}
2437
2438/*
2439 * Encode a READ request
2440 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002441static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2442 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002445 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447
Chuck Lever9f06c712010-12-14 14:59:18 +00002448 encode_compound_hdr(xdr, req, &hdr);
2449 encode_sequence(xdr, &args->seq_args, &hdr);
2450 encode_putfh(xdr, args->fh, &hdr);
2451 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452
Benny Halevy28f56692009-04-01 09:22:09 -04002453 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002455 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002456 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457}
2458
2459/*
2460 * Encode an SETATTR request
2461 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002462static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2463 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464{
Andy Adamson05d564f2008-12-23 16:06:15 -05002465 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002466 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002467 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
Chuck Lever9f06c712010-12-14 14:59:18 +00002469 encode_compound_hdr(xdr, req, &hdr);
2470 encode_sequence(xdr, &args->seq_args, &hdr);
2471 encode_putfh(xdr, args->fh, &hdr);
2472 encode_setattr(xdr, args, args->server, &hdr);
2473 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002474 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475}
2476
2477/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002478 * Encode a GETACL request
2479 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002480static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2481 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002482{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002483 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002484 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002485 };
Benny Halevy28f56692009-04-01 09:22:09 -04002486 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002487
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);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002491 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002492 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002493
Benny Halevy28f56692009-04-01 09:22:09 -04002494 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002495 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002496
Andy Adamsond0179312008-12-23 16:06:17 -05002497 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002498}
2499
2500/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 * Encode a WRITE request
2502 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002503static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2504 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002507 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509
Chuck Lever9f06c712010-12-14 14:59:18 +00002510 encode_compound_hdr(xdr, req, &hdr);
2511 encode_sequence(xdr, &args->seq_args, &hdr);
2512 encode_putfh(xdr, args->fh, &hdr);
2513 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002514 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002515 if (args->bitmask)
2516 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002517 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518}
2519
2520/*
2521 * a COMMIT request
2522 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002523static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002524 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002527 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529
Chuck Lever9f06c712010-12-14 14:59:18 +00002530 encode_compound_hdr(xdr, req, &hdr);
2531 encode_sequence(xdr, &args->seq_args, &hdr);
2532 encode_putfh(xdr, args->fh, &hdr);
2533 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002534 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535}
2536
2537/*
2538 * FSINFO request
2539 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002540static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2541 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002544 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546
Chuck Lever9f06c712010-12-14 14:59:18 +00002547 encode_compound_hdr(xdr, req, &hdr);
2548 encode_sequence(xdr, &args->seq_args, &hdr);
2549 encode_putfh(xdr, args->fh, &hdr);
2550 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002551 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552}
2553
2554/*
2555 * a PATHCONF request
2556 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002557static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2558 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002561 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
Chuck Lever9f06c712010-12-14 14:59:18 +00002564 encode_compound_hdr(xdr, req, &hdr);
2565 encode_sequence(xdr, &args->seq_args, &hdr);
2566 encode_putfh(xdr, args->fh, &hdr);
2567 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002568 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002569 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570}
2571
2572/*
2573 * a STATFS request
2574 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002575static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2576 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002579 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
Chuck Lever9f06c712010-12-14 14:59:18 +00002582 encode_compound_hdr(xdr, req, &hdr);
2583 encode_sequence(xdr, &args->seq_args, &hdr);
2584 encode_putfh(xdr, args->fh, &hdr);
2585 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002586 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002587 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588}
2589
2590/*
2591 * GETATTR_BITMAP request
2592 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002593static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2594 struct xdr_stream *xdr,
2595 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002598 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600
Chuck Lever9f06c712010-12-14 14:59:18 +00002601 encode_compound_hdr(xdr, req, &hdr);
2602 encode_sequence(xdr, &args->seq_args, &hdr);
2603 encode_putfh(xdr, args->fhandle, &hdr);
2604 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002605 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002606 FATTR4_WORD0_LINK_SUPPORT|
2607 FATTR4_WORD0_SYMLINK_SUPPORT|
2608 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002609 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610}
2611
2612/*
2613 * a RENEW request
2614 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002615static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2616 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002619 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 };
2621
Chuck Lever9f06c712010-12-14 14:59:18 +00002622 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002623 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002624 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625}
2626
2627/*
2628 * a SETCLIENTID request
2629 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002630static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2631 struct xdr_stream *xdr,
2632 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002635 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 };
2637
Chuck Lever9f06c712010-12-14 14:59:18 +00002638 encode_compound_hdr(xdr, req, &hdr);
2639 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002640 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641}
2642
2643/*
2644 * a SETCLIENTID_CONFIRM request
2645 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002646static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2647 struct xdr_stream *xdr,
2648 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002651 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653
Chuck Lever9f06c712010-12-14 14:59:18 +00002654 encode_compound_hdr(xdr, req, &hdr);
2655 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002656 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657}
2658
2659/*
2660 * DELEGRETURN request
2661 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002662static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2663 struct xdr_stream *xdr,
2664 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002667 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669
Chuck Lever9f06c712010-12-14 14:59:18 +00002670 encode_compound_hdr(xdr, req, &hdr);
2671 encode_sequence(xdr, &args->seq_args, &hdr);
2672 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002673 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002674 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002675 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676}
2677
2678/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002679 * Encode FS_LOCATIONS request
2680 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002681static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2682 struct xdr_stream *xdr,
2683 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002684{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002685 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002686 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002687 };
Benny Halevy28f56692009-04-01 09:22:09 -04002688 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002689
Chuck Lever9f06c712010-12-14 14:59:18 +00002690 encode_compound_hdr(xdr, req, &hdr);
2691 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002692 if (args->migration) {
2693 encode_putfh(xdr, args->fh, &hdr);
2694 replen = hdr.replen;
2695 encode_fs_locations(xdr, args->bitmask, &hdr);
2696 if (args->renew)
2697 encode_renew(xdr, args->clientid, &hdr);
2698 } else {
2699 encode_putfh(xdr, args->dir_fh, &hdr);
2700 encode_lookup(xdr, args->name, &hdr);
2701 replen = hdr.replen;
2702 encode_fs_locations(xdr, args->bitmask, &hdr);
2703 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002704
Chuck Leverb03d7352013-10-17 14:12:50 -04002705 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002706 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002707 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002708 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002709}
2710
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002711/*
2712 * Encode SECINFO request
2713 */
2714static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2715 struct xdr_stream *xdr,
2716 struct nfs4_secinfo_arg *args)
2717{
2718 struct compound_hdr hdr = {
2719 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2720 };
2721
2722 encode_compound_hdr(xdr, req, &hdr);
2723 encode_sequence(xdr, &args->seq_args, &hdr);
2724 encode_putfh(xdr, args->dir_fh, &hdr);
2725 encode_secinfo(xdr, args->name, &hdr);
2726 encode_nops(&hdr);
2727}
2728
Benny Halevy99fe60d2009-04-01 09:22:29 -04002729#if defined(CONFIG_NFS_V4_1)
2730/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002731 * BIND_CONN_TO_SESSION request
2732 */
2733static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2734 struct xdr_stream *xdr,
2735 struct nfs_client *clp)
2736{
2737 struct compound_hdr hdr = {
2738 .minorversion = clp->cl_mvops->minor_version,
2739 };
2740
2741 encode_compound_hdr(xdr, req, &hdr);
2742 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2743 encode_nops(&hdr);
2744}
2745
2746/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002747 * EXCHANGE_ID request
2748 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002749static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2750 struct xdr_stream *xdr,
2751 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002752{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002753 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002754 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002755 };
2756
Chuck Lever9f06c712010-12-14 14:59:18 +00002757 encode_compound_hdr(xdr, req, &hdr);
2758 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002759 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002760}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002761
2762/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002763 * a CREATE_SESSION request
2764 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002765static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2766 struct xdr_stream *xdr,
2767 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002768{
Andy Adamsonfc931582009-04-01 09:22:31 -04002769 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002770 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002771 };
2772
Chuck Lever9f06c712010-12-14 14:59:18 +00002773 encode_compound_hdr(xdr, req, &hdr);
2774 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002775 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002776}
2777
2778/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002779 * a DESTROY_SESSION request
2780 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002781static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2782 struct xdr_stream *xdr,
2783 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002784{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002785 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002786 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002787 };
2788
Chuck Lever9f06c712010-12-14 14:59:18 +00002789 encode_compound_hdr(xdr, req, &hdr);
2790 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002791 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002792}
2793
2794/*
Trond Myklebust66245532012-05-25 17:18:09 -04002795 * a DESTROY_CLIENTID request
2796 */
2797static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2798 struct xdr_stream *xdr,
2799 struct nfs_client *clp)
2800{
2801 struct compound_hdr hdr = {
2802 .minorversion = clp->cl_mvops->minor_version,
2803 };
2804
2805 encode_compound_hdr(xdr, req, &hdr);
2806 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2807 encode_nops(&hdr);
2808}
2809
2810/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002811 * a SEQUENCE request
2812 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002813static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2814 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002815{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002816 struct compound_hdr hdr = {
2817 .minorversion = nfs4_xdr_minorversion(args),
2818 };
2819
Chuck Lever9f06c712010-12-14 14:59:18 +00002820 encode_compound_hdr(xdr, req, &hdr);
2821 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002822 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002823}
2824
2825/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002826 * a GET_LEASE_TIME request
2827 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002828static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2829 struct xdr_stream *xdr,
2830 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002831{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002832 struct compound_hdr hdr = {
2833 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2834 };
Fred Isamandae100c2011-07-30 20:52:37 -04002835 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002836
Chuck Lever9f06c712010-12-14 14:59:18 +00002837 encode_compound_hdr(xdr, req, &hdr);
2838 encode_sequence(xdr, &args->la_seq_args, &hdr);
2839 encode_putrootfh(xdr, &hdr);
2840 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002841 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002842}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002843
2844/*
2845 * a RECLAIM_COMPLETE request
2846 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002847static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2848 struct xdr_stream *xdr,
2849 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002850{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002851 struct compound_hdr hdr = {
2852 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2853 };
2854
Chuck Lever9f06c712010-12-14 14:59:18 +00002855 encode_compound_hdr(xdr, req, &hdr);
2856 encode_sequence(xdr, &args->seq_args, &hdr);
2857 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002858 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002859}
2860
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002861/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002862 * Encode GETDEVICELIST request
2863 */
2864static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2865 struct xdr_stream *xdr,
2866 struct nfs4_getdevicelist_args *args)
2867{
2868 struct compound_hdr hdr = {
2869 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2870 };
2871
2872 encode_compound_hdr(xdr, req, &hdr);
2873 encode_sequence(xdr, &args->seq_args, &hdr);
2874 encode_putfh(xdr, args->fh, &hdr);
2875 encode_getdevicelist(xdr, args, &hdr);
2876 encode_nops(&hdr);
2877}
2878
2879/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002880 * Encode GETDEVICEINFO request
2881 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002882static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2883 struct xdr_stream *xdr,
2884 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002885{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002886 struct compound_hdr hdr = {
2887 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2888 };
2889
Chuck Lever9f06c712010-12-14 14:59:18 +00002890 encode_compound_hdr(xdr, req, &hdr);
2891 encode_sequence(xdr, &args->seq_args, &hdr);
2892 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002893
2894 /* set up reply kvec. Subtract notification bitmap max size (2)
2895 * so that notification bitmap is put in xdr_buf tail */
2896 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2897 args->pdev->pages, args->pdev->pgbase,
2898 args->pdev->pglen);
2899
2900 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002901}
2902
2903/*
2904 * Encode LAYOUTGET request
2905 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002906static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2907 struct xdr_stream *xdr,
2908 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002909{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002910 struct compound_hdr hdr = {
2911 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2912 };
2913
Chuck Lever9f06c712010-12-14 14:59:18 +00002914 encode_compound_hdr(xdr, req, &hdr);
2915 encode_sequence(xdr, &args->seq_args, &hdr);
2916 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2917 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002918
2919 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2920 args->layout.pages, 0, args->layout.pglen);
2921
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002922 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002923}
Andy Adamson863a3c62011-03-23 13:27:54 +00002924
2925/*
2926 * Encode LAYOUTCOMMIT request
2927 */
Benny Halevycbe82602011-05-22 19:52:37 +03002928static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2929 struct xdr_stream *xdr,
2930 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002931{
Benny Halevyac7db722011-05-22 19:53:48 +03002932 struct nfs4_layoutcommit_data *data =
2933 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002934 struct compound_hdr hdr = {
2935 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2936 };
2937
2938 encode_compound_hdr(xdr, req, &hdr);
2939 encode_sequence(xdr, &args->seq_args, &hdr);
2940 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002941 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002942 encode_getfattr(xdr, args->bitmask, &hdr);
2943 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002944}
2945
2946/*
2947 * Encode LAYOUTRETURN request
2948 */
2949static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2950 struct xdr_stream *xdr,
2951 struct nfs4_layoutreturn_args *args)
2952{
2953 struct compound_hdr hdr = {
2954 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2955 };
2956
2957 encode_compound_hdr(xdr, req, &hdr);
2958 encode_sequence(xdr, &args->seq_args, &hdr);
2959 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2960 encode_layoutreturn(xdr, args, &hdr);
2961 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002962}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002963
2964/*
2965 * Encode SECINFO_NO_NAME request
2966 */
2967static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2968 struct xdr_stream *xdr,
2969 struct nfs41_secinfo_no_name_args *args)
2970{
2971 struct compound_hdr hdr = {
2972 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2973 };
2974
2975 encode_compound_hdr(xdr, req, &hdr);
2976 encode_sequence(xdr, &args->seq_args, &hdr);
2977 encode_putrootfh(xdr, &hdr);
2978 encode_secinfo_no_name(xdr, args, &hdr);
2979 encode_nops(&hdr);
2980 return 0;
2981}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002982
2983/*
2984 * Encode TEST_STATEID request
2985 */
2986static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2987 struct xdr_stream *xdr,
2988 struct nfs41_test_stateid_args *args)
2989{
2990 struct compound_hdr hdr = {
2991 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2992 };
2993
2994 encode_compound_hdr(xdr, req, &hdr);
2995 encode_sequence(xdr, &args->seq_args, &hdr);
2996 encode_test_stateid(xdr, args, &hdr);
2997 encode_nops(&hdr);
2998}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002999
3000/*
3001 * Encode FREE_STATEID request
3002 */
3003static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3004 struct xdr_stream *xdr,
3005 struct nfs41_free_stateid_args *args)
3006{
3007 struct compound_hdr hdr = {
3008 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3009 };
3010
3011 encode_compound_hdr(xdr, req, &hdr);
3012 encode_sequence(xdr, &args->seq_args, &hdr);
3013 encode_free_stateid(xdr, args, &hdr);
3014 encode_nops(&hdr);
3015}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003016#endif /* CONFIG_NFS_V4_1 */
3017
Benny Halevy686841b2009-08-14 17:19:48 +03003018static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3019{
3020 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3021 "Remaining buffer length is %tu words.\n",
3022 func, xdr->end - xdr->p);
3023}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024
Trond Myklebust683b57b2006-06-09 09:34:22 -04003025static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026{
Al Viro8687b632006-10-19 23:28:48 -07003027 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028
Benny Halevyc0eae662009-08-14 17:20:14 +03003029 p = xdr_inline_decode(xdr, 4);
3030 if (unlikely(!p))
3031 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003032 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003033 p = xdr_inline_decode(xdr, *len);
3034 if (unlikely(!p))
3035 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 *string = (char *)p;
3037 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003038out_overflow:
3039 print_overflow_msg(__func__, xdr);
3040 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041}
3042
3043static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3044{
Al Viro8687b632006-10-19 23:28:48 -07003045 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046
Benny Halevyc0eae662009-08-14 17:20:14 +03003047 p = xdr_inline_decode(xdr, 8);
3048 if (unlikely(!p))
3049 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003050 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003051 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003052
Benny Halevyc0eae662009-08-14 17:20:14 +03003053 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3054 if (unlikely(!p))
3055 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 hdr->tag = (char *)p;
3057 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003058 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003059 if (unlikely(hdr->nops < 1))
3060 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003062out_overflow:
3063 print_overflow_msg(__func__, xdr);
3064 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065}
3066
3067static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3068{
Al Viro8687b632006-10-19 23:28:48 -07003069 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 uint32_t opnum;
3071 int32_t nfserr;
3072
Benny Halevyc0eae662009-08-14 17:20:14 +03003073 p = xdr_inline_decode(xdr, 8);
3074 if (unlikely(!p))
3075 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003076 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003078 dprintk("nfs: Server returned operation"
3079 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 opnum, expected);
3081 return -EIO;
3082 }
Benny Halevycccddf42009-08-14 17:20:19 +03003083 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003085 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003087out_overflow:
3088 print_overflow_msg(__func__, xdr);
3089 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090}
3091
3092/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003093static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094{
Al Viro8687b632006-10-19 23:28:48 -07003095 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003096 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 char *str;
3098
Benny Halevyc0eae662009-08-14 17:20:14 +03003099 p = xdr_inline_decode(xdr, 12);
3100 if (likely(p))
3101 return decode_opaque_inline(xdr, &strlen, &str);
3102 print_overflow_msg(__func__, xdr);
3103 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104}
3105
3106static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3107{
Al Viro8687b632006-10-19 23:28:48 -07003108 uint32_t bmlen;
3109 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
Benny Halevyc0eae662009-08-14 17:20:14 +03003111 p = xdr_inline_decode(xdr, 4);
3112 if (unlikely(!p))
3113 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003114 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115
Fred Isamandae100c2011-07-30 20:52:37 -04003116 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003117 p = xdr_inline_decode(xdr, (bmlen << 2));
3118 if (unlikely(!p))
3119 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003121 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003122 if (bmlen > 1) {
3123 bitmap[1] = be32_to_cpup(p++);
3124 if (bmlen > 2)
3125 bitmap[2] = be32_to_cpup(p);
3126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 }
3128 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003129out_overflow:
3130 print_overflow_msg(__func__, xdr);
3131 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132}
3133
Trond Myklebust256e48b2012-06-21 11:18:13 -04003134static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135{
Al Viro8687b632006-10-19 23:28:48 -07003136 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137
Benny Halevyc0eae662009-08-14 17:20:14 +03003138 p = xdr_inline_decode(xdr, 4);
3139 if (unlikely(!p))
3140 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003141 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003142 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003144out_overflow:
3145 print_overflow_msg(__func__, xdr);
3146 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147}
3148
3149static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3150{
3151 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003152 int ret;
3153 ret = decode_attr_bitmap(xdr, bitmask);
3154 if (unlikely(ret < 0))
3155 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3157 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003158 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3159 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3160 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 return 0;
3162}
3163
3164static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3165{
Al Viro8687b632006-10-19 23:28:48 -07003166 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003167 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168
3169 *type = 0;
3170 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3171 return -EIO;
3172 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003173 p = xdr_inline_decode(xdr, 4);
3174 if (unlikely(!p))
3175 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003176 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003178 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 return -EIO;
3180 }
3181 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003182 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003184 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003185 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003186out_overflow:
3187 print_overflow_msg(__func__, xdr);
3188 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189}
3190
Chuck Lever264e6352012-03-01 17:02:05 -05003191static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3192 uint32_t *bitmap, uint32_t *type)
3193{
3194 __be32 *p;
3195
3196 *type = 0;
3197 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3198 return -EIO;
3199 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3200 p = xdr_inline_decode(xdr, 4);
3201 if (unlikely(!p))
3202 goto out_overflow;
3203 *type = be32_to_cpup(p);
3204 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3205 }
3206 dprintk("%s: expire type=0x%x\n", __func__, *type);
3207 return 0;
3208out_overflow:
3209 print_overflow_msg(__func__, xdr);
3210 return -EIO;
3211}
3212
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3214{
Al Viro8687b632006-10-19 23:28:48 -07003215 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003216 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217
3218 *change = 0;
3219 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3220 return -EIO;
3221 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003222 p = xdr_inline_decode(xdr, 8);
3223 if (unlikely(!p))
3224 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003225 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003227 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003229 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003231 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003232out_overflow:
3233 print_overflow_msg(__func__, xdr);
3234 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235}
3236
3237static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3238{
Al Viro8687b632006-10-19 23:28:48 -07003239 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003240 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241
3242 *size = 0;
3243 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3244 return -EIO;
3245 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003246 p = xdr_inline_decode(xdr, 8);
3247 if (unlikely(!p))
3248 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003249 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003251 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003253 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003254 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003255out_overflow:
3256 print_overflow_msg(__func__, xdr);
3257 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258}
3259
3260static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3261{
Al Viro8687b632006-10-19 23:28:48 -07003262 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263
3264 *res = 0;
3265 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3266 return -EIO;
3267 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003268 p = xdr_inline_decode(xdr, 4);
3269 if (unlikely(!p))
3270 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003271 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3273 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003274 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 return 0;
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_symlink_support(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 = 0;
3286 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3287 return -EIO;
3288 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
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_SYMLINK_SUPPORT;
3294 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003295 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
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 Myklebust8b4bdcf2006-06-09 09:34:19 -04003302static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303{
Al Viro8687b632006-10-19 23:28:48 -07003304 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003305 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306
3307 fsid->major = 0;
3308 fsid->minor = 0;
3309 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3310 return -EIO;
3311 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003312 p = xdr_inline_decode(xdr, 16);
3313 if (unlikely(!p))
3314 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003315 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003316 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003318 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003320 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 (unsigned long long)fsid->major,
3322 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003323 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003324out_overflow:
3325 print_overflow_msg(__func__, xdr);
3326 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327}
3328
3329static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3330{
Al Viro8687b632006-10-19 23:28:48 -07003331 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332
3333 *res = 60;
3334 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3335 return -EIO;
3336 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003337 p = xdr_inline_decode(xdr, 4);
3338 if (unlikely(!p))
3339 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003340 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3342 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003343 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003345out_overflow:
3346 print_overflow_msg(__func__, xdr);
3347 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348}
3349
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003350static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003351{
3352 __be32 *p;
3353
3354 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3355 return -EIO;
3356 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3357 p = xdr_inline_decode(xdr, 4);
3358 if (unlikely(!p))
3359 goto out_overflow;
3360 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003361 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003362 }
3363 return 0;
3364out_overflow:
3365 print_overflow_msg(__func__, xdr);
3366 return -EIO;
3367}
3368
3369static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3370{
3371 __be32 *p;
3372 int len;
3373
Trond Myklebust7ad07352010-10-23 15:34:20 -04003374 if (fh != NULL)
3375 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003376
3377 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3378 return -EIO;
3379 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3380 p = xdr_inline_decode(xdr, 4);
3381 if (unlikely(!p))
3382 goto out_overflow;
3383 len = be32_to_cpup(p);
3384 if (len > NFS4_FHSIZE)
3385 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003386 p = xdr_inline_decode(xdr, len);
3387 if (unlikely(!p))
3388 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003389 if (fh != NULL) {
3390 memcpy(fh->data, p, len);
3391 fh->size = len;
3392 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003393 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3394 }
3395 return 0;
3396out_overflow:
3397 print_overflow_msg(__func__, xdr);
3398 return -EIO;
3399}
3400
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3402{
Al Viro8687b632006-10-19 23:28:48 -07003403 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404
3405 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3406 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3407 return -EIO;
3408 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003409 p = xdr_inline_decode(xdr, 4);
3410 if (unlikely(!p))
3411 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003412 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3414 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003415 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003417out_overflow:
3418 print_overflow_msg(__func__, xdr);
3419 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420}
3421
3422static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3423{
Al Viro8687b632006-10-19 23:28:48 -07003424 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003425 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426
3427 *fileid = 0;
3428 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3429 return -EIO;
3430 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003431 p = xdr_inline_decode(xdr, 8);
3432 if (unlikely(!p))
3433 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003434 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003436 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003438 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003439 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003440out_overflow:
3441 print_overflow_msg(__func__, xdr);
3442 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443}
3444
Manoj Naik99baf622006-06-09 09:34:24 -04003445static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3446{
Al Viro8687b632006-10-19 23:28:48 -07003447 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003448 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003449
3450 *fileid = 0;
3451 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3452 return -EIO;
3453 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003454 p = xdr_inline_decode(xdr, 8);
3455 if (unlikely(!p))
3456 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003457 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003458 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003459 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003460 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003461 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003462 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003463out_overflow:
3464 print_overflow_msg(__func__, xdr);
3465 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003466}
3467
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3469{
Al Viro8687b632006-10-19 23:28:48 -07003470 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471 int status = 0;
3472
3473 *res = 0;
3474 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3475 return -EIO;
3476 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003477 p = xdr_inline_decode(xdr, 8);
3478 if (unlikely(!p))
3479 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003480 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3482 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003483 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003485out_overflow:
3486 print_overflow_msg(__func__, xdr);
3487 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488}
3489
3490static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3491{
Al Viro8687b632006-10-19 23:28:48 -07003492 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 int status = 0;
3494
3495 *res = 0;
3496 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3497 return -EIO;
3498 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003499 p = xdr_inline_decode(xdr, 8);
3500 if (unlikely(!p))
3501 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003502 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3504 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003505 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003507out_overflow:
3508 print_overflow_msg(__func__, xdr);
3509 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510}
3511
3512static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3513{
Al Viro8687b632006-10-19 23:28:48 -07003514 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515 int status = 0;
3516
3517 *res = 0;
3518 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3519 return -EIO;
3520 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003521 p = xdr_inline_decode(xdr, 8);
3522 if (unlikely(!p))
3523 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003524 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3526 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003527 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003529out_overflow:
3530 print_overflow_msg(__func__, xdr);
3531 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532}
3533
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003534static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3535{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003536 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003537 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003538 int status = 0;
3539
Benny Halevyc0eae662009-08-14 17:20:14 +03003540 p = xdr_inline_decode(xdr, 4);
3541 if (unlikely(!p))
3542 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003543 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003544 if (n == 0)
3545 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003546 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003547 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3548 dprintk("cannot parse %d components in path\n", n);
3549 goto out_eio;
3550 }
3551 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003552 struct nfs4_string *component = &path->components[path->ncomponents];
3553 status = decode_opaque_inline(xdr, &component->len, &component->data);
3554 if (unlikely(status != 0))
3555 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003556 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003557 pr_cont("%s%.*s ",
3558 (path->ncomponents != n ? "/ " : ""),
3559 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003560 }
3561out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003562 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003563root_path:
3564/* a root pathname is sent as a zero component4 */
3565 path->ncomponents = 1;
3566 path->components[0].len=0;
3567 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003568 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003569 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003570out_eio:
3571 dprintk(" status %d", status);
3572 status = -EIO;
3573 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003574out_overflow:
3575 print_overflow_msg(__func__, xdr);
3576 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003577}
3578
3579static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003580{
3581 int n;
Al Viro8687b632006-10-19 23:28:48 -07003582 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003583 int status = -EIO;
3584
3585 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3586 goto out;
3587 status = 0;
3588 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3589 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003590 status = -EIO;
3591 /* Ignore borken servers that return unrequested attrs */
3592 if (unlikely(res == NULL))
3593 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003594 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003595 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003596 if (unlikely(status != 0))
3597 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003598 p = xdr_inline_decode(xdr, 4);
3599 if (unlikely(!p))
3600 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003601 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003602 if (n <= 0)
3603 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003604 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003605 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003606 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003607
Trond Myklebust809b4262013-03-27 11:54:45 -04003608 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3609 break;
3610 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003611 p = xdr_inline_decode(xdr, 4);
3612 if (unlikely(!p))
3613 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003614 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003615
Chuck Lever02a29762012-03-01 17:00:31 -05003616 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003617 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3618 struct nfs4_string *server;
3619
3620 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003621 unsigned int i;
3622 dprintk("%s: using first %u of %u servers "
3623 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003624 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003625 NFS4_FS_LOCATION_MAXSERVERS,
3626 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003627 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003628 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003629 char *data;
3630 status = decode_opaque_inline(xdr, &len, &data);
3631 if (unlikely(status != 0))
3632 goto out_eio;
3633 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003634 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003635 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003636 server = &loc->servers[loc->nservers];
3637 status = decode_opaque_inline(xdr, &server->len, &server->data);
3638 if (unlikely(status != 0))
3639 goto out_eio;
3640 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003641 }
3642 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003643 if (unlikely(status != 0))
3644 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003645 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003646 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003647 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003648out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003649 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003650 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003651out_overflow:
3652 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003653out_eio:
3654 status = -EIO;
3655 goto out;
3656}
3657
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3659{
Al Viro8687b632006-10-19 23:28:48 -07003660 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661 int status = 0;
3662
3663 *res = 0;
3664 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3665 return -EIO;
3666 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003667 p = xdr_inline_decode(xdr, 8);
3668 if (unlikely(!p))
3669 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003670 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3672 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003673 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003675out_overflow:
3676 print_overflow_msg(__func__, xdr);
3677 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678}
3679
3680static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3681{
Al Viro8687b632006-10-19 23:28:48 -07003682 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 int status = 0;
3684
3685 *maxlink = 1;
3686 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3687 return -EIO;
3688 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003689 p = xdr_inline_decode(xdr, 4);
3690 if (unlikely(!p))
3691 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003692 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3694 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003695 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003697out_overflow:
3698 print_overflow_msg(__func__, xdr);
3699 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700}
3701
3702static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3703{
Al Viro8687b632006-10-19 23:28:48 -07003704 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 int status = 0;
3706
3707 *maxname = 1024;
3708 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3709 return -EIO;
3710 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003711 p = xdr_inline_decode(xdr, 4);
3712 if (unlikely(!p))
3713 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003714 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3716 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003717 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003719out_overflow:
3720 print_overflow_msg(__func__, xdr);
3721 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722}
3723
3724static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3725{
Al Viro8687b632006-10-19 23:28:48 -07003726 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727 int status = 0;
3728
3729 *res = 1024;
3730 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3731 return -EIO;
3732 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3733 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003734 p = xdr_inline_decode(xdr, 8);
3735 if (unlikely(!p))
3736 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003737 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 if (maxread > 0x7FFFFFFF)
3739 maxread = 0x7FFFFFFF;
3740 *res = (uint32_t)maxread;
3741 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3742 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003743 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003745out_overflow:
3746 print_overflow_msg(__func__, xdr);
3747 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748}
3749
3750static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3751{
Al Viro8687b632006-10-19 23:28:48 -07003752 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 int status = 0;
3754
3755 *res = 1024;
3756 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3757 return -EIO;
3758 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3759 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003760 p = xdr_inline_decode(xdr, 8);
3761 if (unlikely(!p))
3762 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003763 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764 if (maxwrite > 0x7FFFFFFF)
3765 maxwrite = 0x7FFFFFFF;
3766 *res = (uint32_t)maxwrite;
3767 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3768 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003769 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003771out_overflow:
3772 print_overflow_msg(__func__, xdr);
3773 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774}
3775
Trond Myklebustbca79472009-03-11 14:10:26 -04003776static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777{
Trond Myklebustbca79472009-03-11 14:10:26 -04003778 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003779 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003780 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781
3782 *mode = 0;
3783 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3784 return -EIO;
3785 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003786 p = xdr_inline_decode(xdr, 4);
3787 if (unlikely(!p))
3788 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003789 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003790 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003792 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003794 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003795 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003796out_overflow:
3797 print_overflow_msg(__func__, xdr);
3798 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799}
3800
3801static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3802{
Al Viro8687b632006-10-19 23:28:48 -07003803 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003804 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805
3806 *nlink = 1;
3807 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3808 return -EIO;
3809 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003810 p = xdr_inline_decode(xdr, 4);
3811 if (unlikely(!p))
3812 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003813 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003815 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003817 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003818 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003819out_overflow:
3820 print_overflow_msg(__func__, xdr);
3821 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822}
3823
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003824static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003825 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003826 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827{
Al Viro8687b632006-10-19 23:28:48 -07003828 uint32_t len;
3829 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003830 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831
Eric W. Biedermane5782072013-02-01 14:22:02 -08003832 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3834 return -EIO;
3835 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003836 p = xdr_inline_decode(xdr, 4);
3837 if (unlikely(!p))
3838 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003839 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003840 p = xdr_inline_decode(xdr, len);
3841 if (unlikely(!p))
3842 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003843 if (owner_name != NULL) {
3844 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3845 if (owner_name->data != NULL) {
3846 owner_name->len = len;
3847 ret = NFS_ATTR_FATTR_OWNER_NAME;
3848 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003849 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003850 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003851 ret = NFS_ATTR_FATTR_OWNER;
3852 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003854 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003856 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003857 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3859 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003860 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003861 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003862out_overflow:
3863 print_overflow_msg(__func__, xdr);
3864 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865}
3866
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003867static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003868 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003869 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870{
Al Viro8687b632006-10-19 23:28:48 -07003871 uint32_t len;
3872 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003873 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874
Eric W. Biedermane5782072013-02-01 14:22:02 -08003875 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3877 return -EIO;
3878 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003879 p = xdr_inline_decode(xdr, 4);
3880 if (unlikely(!p))
3881 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003882 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003883 p = xdr_inline_decode(xdr, len);
3884 if (unlikely(!p))
3885 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003886 if (group_name != NULL) {
3887 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3888 if (group_name->data != NULL) {
3889 group_name->len = len;
3890 ret = NFS_ATTR_FATTR_GROUP_NAME;
3891 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003892 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003893 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003894 ret = NFS_ATTR_FATTR_GROUP;
3895 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003897 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003899 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003900 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3902 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003903 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003904 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003905out_overflow:
3906 print_overflow_msg(__func__, xdr);
3907 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908}
3909
3910static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3911{
Al Viro8687b632006-10-19 23:28:48 -07003912 uint32_t major = 0, minor = 0;
3913 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003914 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915
3916 *rdev = MKDEV(0,0);
3917 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3918 return -EIO;
3919 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3920 dev_t tmp;
3921
Benny Halevyc0eae662009-08-14 17:20:14 +03003922 p = xdr_inline_decode(xdr, 8);
3923 if (unlikely(!p))
3924 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003925 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003926 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927 tmp = MKDEV(major, minor);
3928 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3929 *rdev = tmp;
3930 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003931 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003933 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003934 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003935out_overflow:
3936 print_overflow_msg(__func__, xdr);
3937 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938}
3939
3940static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3941{
Al Viro8687b632006-10-19 23:28:48 -07003942 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 int status = 0;
3944
3945 *res = 0;
3946 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3947 return -EIO;
3948 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003949 p = xdr_inline_decode(xdr, 8);
3950 if (unlikely(!p))
3951 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003952 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3954 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003955 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003957out_overflow:
3958 print_overflow_msg(__func__, xdr);
3959 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960}
3961
3962static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3963{
Al Viro8687b632006-10-19 23:28:48 -07003964 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 int status = 0;
3966
3967 *res = 0;
3968 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3969 return -EIO;
3970 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003971 p = xdr_inline_decode(xdr, 8);
3972 if (unlikely(!p))
3973 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003974 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3976 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003977 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003979out_overflow:
3980 print_overflow_msg(__func__, xdr);
3981 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982}
3983
3984static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3985{
Al Viro8687b632006-10-19 23:28:48 -07003986 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 int status = 0;
3988
3989 *res = 0;
3990 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3991 return -EIO;
3992 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003993 p = xdr_inline_decode(xdr, 8);
3994 if (unlikely(!p))
3995 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003996 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3998 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003999 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004001out_overflow:
4002 print_overflow_msg(__func__, xdr);
4003 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004}
4005
4006static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4007{
Al Viro8687b632006-10-19 23:28:48 -07004008 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004009 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010
4011 *used = 0;
4012 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4013 return -EIO;
4014 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004015 p = xdr_inline_decode(xdr, 8);
4016 if (unlikely(!p))
4017 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004018 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004020 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004022 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004024 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004025out_overflow:
4026 print_overflow_msg(__func__, xdr);
4027 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028}
4029
4030static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4031{
Al Viro8687b632006-10-19 23:28:48 -07004032 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 uint64_t sec;
4034 uint32_t nsec;
4035
Benny Halevyc0eae662009-08-14 17:20:14 +03004036 p = xdr_inline_decode(xdr, 12);
4037 if (unlikely(!p))
4038 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004039 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004040 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041 time->tv_sec = (time_t)sec;
4042 time->tv_nsec = (long)nsec;
4043 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004044out_overflow:
4045 print_overflow_msg(__func__, xdr);
4046 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047}
4048
4049static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4050{
4051 int status = 0;
4052
4053 time->tv_sec = 0;
4054 time->tv_nsec = 0;
4055 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4056 return -EIO;
4057 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4058 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004059 if (status == 0)
4060 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4062 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004063 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 return status;
4065}
4066
4067static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4068{
4069 int status = 0;
4070
4071 time->tv_sec = 0;
4072 time->tv_nsec = 0;
4073 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4074 return -EIO;
4075 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4076 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004077 if (status == 0)
4078 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4080 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004081 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 return status;
4083}
4084
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004085static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4086 struct timespec *time)
4087{
4088 int status = 0;
4089
4090 time->tv_sec = 0;
4091 time->tv_nsec = 0;
4092 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4093 return -EIO;
4094 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4095 status = decode_attr_time(xdr, time);
4096 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4097 }
4098 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4099 (long)time->tv_nsec);
4100 return status;
4101}
4102
David Quigleyaa9c2662013-05-22 12:50:44 -04004103static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4104 struct nfs4_label *label)
4105{
4106 uint32_t pi = 0;
4107 uint32_t lfs = 0;
4108 __u32 len;
4109 __be32 *p;
4110 int status = 0;
4111
4112 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4113 return -EIO;
4114 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4115 p = xdr_inline_decode(xdr, 4);
4116 if (unlikely(!p))
4117 goto out_overflow;
4118 lfs = be32_to_cpup(p++);
4119 p = xdr_inline_decode(xdr, 4);
4120 if (unlikely(!p))
4121 goto out_overflow;
4122 pi = be32_to_cpup(p++);
4123 p = xdr_inline_decode(xdr, 4);
4124 if (unlikely(!p))
4125 goto out_overflow;
4126 len = be32_to_cpup(p++);
4127 p = xdr_inline_decode(xdr, len);
4128 if (unlikely(!p))
4129 goto out_overflow;
4130 if (len < NFS4_MAXLABELLEN) {
4131 if (label) {
4132 memcpy(label->label, p, len);
4133 label->len = len;
4134 label->pi = pi;
4135 label->lfs = lfs;
4136 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4137 }
4138 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4139 } else
4140 printk(KERN_WARNING "%s: label too long (%u)!\n",
4141 __func__, len);
4142 }
4143 if (label && label->label)
4144 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4145 (char *)label->label, label->len, label->pi, label->lfs);
4146 return status;
4147
4148out_overflow:
4149 print_overflow_msg(__func__, xdr);
4150 return -EIO;
4151}
4152
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4154{
4155 int status = 0;
4156
4157 time->tv_sec = 0;
4158 time->tv_nsec = 0;
4159 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4160 return -EIO;
4161 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4162 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004163 if (status == 0)
4164 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4166 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004167 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168 return status;
4169}
4170
Trond Myklebust256e48b2012-06-21 11:18:13 -04004171static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172{
4173 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004174 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175
4176 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004177 dprintk("%s: server returned incorrect attribute length: "
4178 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004179 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 attrwords << 2,
4181 (attrwords < nwords) ? '<' : '>',
4182 nwords << 2);
4183 return -EIO;
4184 }
4185 return 0;
4186}
4187
4188static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4189{
Al Viro8687b632006-10-19 23:28:48 -07004190 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191
Benny Halevyc0eae662009-08-14 17:20:14 +03004192 p = xdr_inline_decode(xdr, 20);
4193 if (unlikely(!p))
4194 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004195 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004196 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004197 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004199out_overflow:
4200 print_overflow_msg(__func__, xdr);
4201 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202}
4203
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004204static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205{
Al Viro8687b632006-10-19 23:28:48 -07004206 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 uint32_t supp, acc;
4208 int status;
4209
4210 status = decode_op_hdr(xdr, OP_ACCESS);
4211 if (status)
4212 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004213 p = xdr_inline_decode(xdr, 8);
4214 if (unlikely(!p))
4215 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004216 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004217 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004218 *supported = supp;
4219 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004221out_overflow:
4222 print_overflow_msg(__func__, xdr);
4223 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224}
4225
Benny Halevy07d30432009-08-14 17:19:52 +03004226static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227{
Al Viro8687b632006-10-19 23:28:48 -07004228 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004229
4230 p = xdr_inline_decode(xdr, len);
4231 if (likely(p)) {
4232 memcpy(buf, p, len);
4233 return 0;
4234 }
4235 print_overflow_msg(__func__, xdr);
4236 return -EIO;
4237}
4238
4239static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4240{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004241 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242}
4243
4244static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4245{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246 int status;
4247
4248 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004249 if (status != -EIO)
4250 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004251 if (!status)
4252 status = decode_stateid(xdr, &res->stateid);
4253 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254}
4255
Benny Halevydb942bb2009-08-14 17:19:56 +03004256static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4257{
Chuck Levercd937102012-03-02 17:14:31 -05004258 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259}
4260
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004261static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4262{
4263 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4264}
4265
Fred Isaman0b7c0152012-04-20 14:47:39 -04004266static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 int status;
4269
4270 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004271 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004272 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004273 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274}
4275
4276static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4277{
Al Viro8687b632006-10-19 23:28:48 -07004278 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279 uint32_t bmlen;
4280 int status;
4281
4282 status = decode_op_hdr(xdr, OP_CREATE);
4283 if (status)
4284 return status;
4285 if ((status = decode_change_info(xdr, cinfo)))
4286 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004287 p = xdr_inline_decode(xdr, 4);
4288 if (unlikely(!p))
4289 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004290 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004291 p = xdr_inline_decode(xdr, bmlen << 2);
4292 if (likely(p))
4293 return 0;
4294out_overflow:
4295 print_overflow_msg(__func__, xdr);
4296 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297}
4298
4299static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4300{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004301 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004302 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303 int status;
4304
4305 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4306 goto xdr_error;
4307 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4308 goto xdr_error;
4309 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4310 goto xdr_error;
4311 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4312 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004313 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4314 &res->fh_expire_type)) != 0)
4315 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4317 goto xdr_error;
4318 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4319 goto xdr_error;
4320 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4321 goto xdr_error;
4322 status = verify_attr_len(xdr, savep, attrlen);
4323xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004324 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325 return status;
4326}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004327
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4329{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004330 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004331 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004333
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4335 goto xdr_error;
4336 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4337 goto xdr_error;
4338 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4339 goto xdr_error;
4340
4341 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4342 goto xdr_error;
4343 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4344 goto xdr_error;
4345 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4346 goto xdr_error;
4347 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4348 goto xdr_error;
4349 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4350 goto xdr_error;
4351 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4352 goto xdr_error;
4353
4354 status = verify_attr_len(xdr, savep, attrlen);
4355xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004356 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 return status;
4358}
4359
4360static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4361{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004362 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004363 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004365
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4367 goto xdr_error;
4368 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4369 goto xdr_error;
4370 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4371 goto xdr_error;
4372
4373 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4374 goto xdr_error;
4375 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4376 goto xdr_error;
4377
4378 status = verify_attr_len(xdr, savep, attrlen);
4379xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004380 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381 return status;
4382}
4383
Andy Adamson88034c32012-05-23 05:02:34 -04004384static int decode_threshold_hint(struct xdr_stream *xdr,
4385 uint32_t *bitmap,
4386 uint64_t *res,
4387 uint32_t hint_bit)
4388{
4389 __be32 *p;
4390
4391 *res = 0;
4392 if (likely(bitmap[0] & hint_bit)) {
4393 p = xdr_inline_decode(xdr, 8);
4394 if (unlikely(!p))
4395 goto out_overflow;
4396 xdr_decode_hyper(p, res);
4397 }
4398 return 0;
4399out_overflow:
4400 print_overflow_msg(__func__, xdr);
4401 return -EIO;
4402}
4403
4404static int decode_first_threshold_item4(struct xdr_stream *xdr,
4405 struct nfs4_threshold *res)
4406{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004407 __be32 *p;
4408 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004409 uint32_t bitmap[3] = {0,}, attrlen;
4410 int status;
4411
4412 /* layout type */
4413 p = xdr_inline_decode(xdr, 4);
4414 if (unlikely(!p)) {
4415 print_overflow_msg(__func__, xdr);
4416 return -EIO;
4417 }
4418 res->l_type = be32_to_cpup(p);
4419
4420 /* thi_hintset bitmap */
4421 status = decode_attr_bitmap(xdr, bitmap);
4422 if (status < 0)
4423 goto xdr_error;
4424
4425 /* thi_hintlist length */
4426 status = decode_attr_length(xdr, &attrlen, &savep);
4427 if (status < 0)
4428 goto xdr_error;
4429 /* thi_hintlist */
4430 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4431 if (status < 0)
4432 goto xdr_error;
4433 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4434 if (status < 0)
4435 goto xdr_error;
4436 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4437 THRESHOLD_RD_IO);
4438 if (status < 0)
4439 goto xdr_error;
4440 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4441 THRESHOLD_WR_IO);
4442 if (status < 0)
4443 goto xdr_error;
4444
4445 status = verify_attr_len(xdr, savep, attrlen);
4446 res->bm = bitmap[0];
4447
4448 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4449 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4450 res->wr_io_sz);
4451xdr_error:
4452 dprintk("%s ret=%d!\n", __func__, status);
4453 return status;
4454}
4455
4456/*
4457 * Thresholds on pNFS direct I/O vrs MDS I/O
4458 */
4459static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4460 uint32_t *bitmap,
4461 struct nfs4_threshold *res)
4462{
4463 __be32 *p;
4464 int status = 0;
4465 uint32_t num;
4466
4467 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4468 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004469 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004470 /* Did the server return an unrequested attribute? */
4471 if (unlikely(res == NULL))
4472 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004473 p = xdr_inline_decode(xdr, 4);
4474 if (unlikely(!p))
4475 goto out_overflow;
4476 num = be32_to_cpup(p);
4477 if (num == 0)
4478 return 0;
4479 if (num > 1)
4480 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4481 "drivers per filesystem not supported\n",
4482 __func__);
4483
4484 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004485 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004486 }
4487 return status;
4488out_overflow:
4489 print_overflow_msg(__func__, xdr);
4490 return -EIO;
4491}
4492
Bryan Schumakerae42c702010-10-21 16:33:17 -04004493static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4494 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004495 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004496 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497{
Trond Myklebustbca79472009-03-11 14:10:26 -04004498 int status;
4499 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004500 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004501 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004503 status = decode_attr_type(xdr, bitmap, &type);
4504 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004506 fattr->mode = 0;
4507 if (status != 0) {
4508 fattr->mode |= nfs_type2fmt[type];
4509 fattr->valid |= status;
4510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004512 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4513 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004515 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004516
4517 status = decode_attr_size(xdr, bitmap, &fattr->size);
4518 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004520 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004521
4522 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4523 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004525 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004526
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004527 err = 0;
4528 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004529 if (status < 0)
4530 goto xdr_error;
4531
4532 status = decode_attr_filehandle(xdr, bitmap, fh);
4533 if (status < 0)
4534 goto xdr_error;
4535
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004536 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4537 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004539 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004540
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004541 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004542 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004543 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004544 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004545
4546 status = decode_attr_mode(xdr, bitmap, &fmode);
4547 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004549 if (status != 0) {
4550 fattr->mode |= fmode;
4551 fattr->valid |= status;
4552 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004553
4554 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4555 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004557 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004558
Trond Myklebust6926afd2012-01-07 13:22:46 -05004559 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004560 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004562 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004563
Trond Myklebust6926afd2012-01-07 13:22:46 -05004564 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004565 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004567 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004568
4569 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4570 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004572 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004573
4574 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4575 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004577 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004578
4579 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4580 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004582 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004583
4584 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4585 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004587 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004588
4589 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4590 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004592 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004593
Trond Myklebust28331a42011-04-27 13:47:52 -04004594 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004595 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004596 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004597 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004598
Andy Adamson88034c32012-05-23 05:02:34 -04004599 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4600 if (status < 0)
4601 goto xdr_error;
4602
David Quigleyaa9c2662013-05-22 12:50:44 -04004603 if (label) {
4604 status = decode_attr_security_label(xdr, bitmap, label);
4605 if (status < 0)
4606 goto xdr_error;
4607 fattr->valid |= status;
4608 }
4609
Bryan Schumakerae42c702010-10-21 16:33:17 -04004610xdr_error:
4611 dprintk("%s: xdr returned %d\n", __func__, -status);
4612 return status;
4613}
4614
4615static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004616 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004617 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004618{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004619 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004620 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004621 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004622 int status;
4623
4624 status = decode_op_hdr(xdr, OP_GETATTR);
4625 if (status < 0)
4626 goto xdr_error;
4627
4628 status = decode_attr_bitmap(xdr, bitmap);
4629 if (status < 0)
4630 goto xdr_error;
4631
4632 status = decode_attr_length(xdr, &attrlen, &savep);
4633 if (status < 0)
4634 goto xdr_error;
4635
David Quigleyaa9c2662013-05-22 12:50:44 -04004636 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4637 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004638 if (status < 0)
4639 goto xdr_error;
4640
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004641 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004643 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 return status;
4645}
4646
David Quigleyaa9c2662013-05-22 12:50:44 -04004647static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4648 struct nfs4_label *label, const struct nfs_server *server)
4649{
4650 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4651}
4652
Bryan Schumakerae42c702010-10-21 16:33:17 -04004653static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004654 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004655{
David Quigleyaa9c2662013-05-22 12:50:44 -04004656 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004657}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658
Andy Adamson504913f2010-10-20 00:17:57 -04004659/*
4660 * Decode potentially multiple layout types. Currently we only support
4661 * one layout driver per file system.
4662 */
4663static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4664 uint32_t *layouttype)
4665{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004666 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004667 int num;
4668
4669 p = xdr_inline_decode(xdr, 4);
4670 if (unlikely(!p))
4671 goto out_overflow;
4672 num = be32_to_cpup(p);
4673
4674 /* pNFS is not supported by the underlying file system */
4675 if (num == 0) {
4676 *layouttype = 0;
4677 return 0;
4678 }
4679 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004680 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4681 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004682
4683 /* Decode and set first layout type, move xdr->p past unused types */
4684 p = xdr_inline_decode(xdr, num * 4);
4685 if (unlikely(!p))
4686 goto out_overflow;
4687 *layouttype = be32_to_cpup(p);
4688 return 0;
4689out_overflow:
4690 print_overflow_msg(__func__, xdr);
4691 return -EIO;
4692}
4693
4694/*
4695 * The type of file system exported.
4696 * Note we must ensure that layouttype is set in any non-error case.
4697 */
4698static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4699 uint32_t *layouttype)
4700{
4701 int status = 0;
4702
4703 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4704 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4705 return -EIO;
4706 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4707 status = decode_first_pnfs_layout_type(xdr, layouttype);
4708 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4709 } else
4710 *layouttype = 0;
4711 return status;
4712}
4713
Fred Isamandae100c2011-07-30 20:52:37 -04004714/*
4715 * The prefered block size for layout directed io
4716 */
4717static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4718 uint32_t *res)
4719{
4720 __be32 *p;
4721
4722 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4723 *res = 0;
4724 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4725 p = xdr_inline_decode(xdr, 4);
4726 if (unlikely(!p)) {
4727 print_overflow_msg(__func__, xdr);
4728 return -EIO;
4729 }
4730 *res = be32_to_cpup(p);
4731 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4732 }
4733 return 0;
4734}
4735
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4737{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004738 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004739 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 int status;
4741
4742 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4743 goto xdr_error;
4744 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4745 goto xdr_error;
4746 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4747 goto xdr_error;
4748
4749 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4750
4751 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4752 goto xdr_error;
4753 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4754 goto xdr_error;
4755 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4756 goto xdr_error;
4757 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4758 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4759 goto xdr_error;
4760 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004761 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4762 if (status != 0)
4763 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004764 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4765 if (status != 0)
4766 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004767 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4768 if (status)
4769 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770
4771 status = verify_attr_len(xdr, savep, attrlen);
4772xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004773 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 return status;
4775}
4776
4777static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4778{
Al Viro8687b632006-10-19 23:28:48 -07004779 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 uint32_t len;
4781 int status;
4782
Trond Myklebust99367812007-07-17 21:52:41 -04004783 /* Zero handle first to allow comparisons */
4784 memset(fh, 0, sizeof(*fh));
4785
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 status = decode_op_hdr(xdr, OP_GETFH);
4787 if (status)
4788 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789
Benny Halevyc0eae662009-08-14 17:20:14 +03004790 p = xdr_inline_decode(xdr, 4);
4791 if (unlikely(!p))
4792 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004793 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 if (len > NFS4_FHSIZE)
4795 return -EIO;
4796 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004797 p = xdr_inline_decode(xdr, len);
4798 if (unlikely(!p))
4799 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004800 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004802out_overflow:
4803 print_overflow_msg(__func__, xdr);
4804 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004805}
4806
4807static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4808{
4809 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004810
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811 status = decode_op_hdr(xdr, OP_LINK);
4812 if (status)
4813 return status;
4814 return decode_change_info(xdr, cinfo);
4815}
4816
4817/*
4818 * We create the owner, so we know a proper owner.id length is 4.
4819 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004820static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004822 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004823 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004824 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004826 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004827 if (unlikely(!p))
4828 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004829 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004830 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004831 type = be32_to_cpup(p++); /* 4 byte read */
4832 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004833 fl->fl_start = (loff_t)offset;
4834 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4835 if (length == ~(uint64_t)0)
4836 fl->fl_end = OFFSET_MAX;
4837 fl->fl_type = F_WRLCK;
4838 if (type & 1)
4839 fl->fl_type = F_RDLCK;
4840 fl->fl_pid = 0;
4841 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004842 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4843 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4844 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004845 if (likely(p))
4846 return -NFS4ERR_DENIED;
4847out_overflow:
4848 print_overflow_msg(__func__, xdr);
4849 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850}
4851
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004852static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854 int status;
4855
4856 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004857 if (status == -EIO)
4858 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004860 status = decode_stateid(xdr, &res->stateid);
4861 if (unlikely(status))
4862 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004864 status = decode_lock_denied(xdr, NULL);
4865 if (res->open_seqid != NULL)
4866 nfs_increment_open_seqid(status, res->open_seqid);
4867 nfs_increment_lock_seqid(status, res->lock_seqid);
4868out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869 return status;
4870}
4871
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004872static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873{
4874 int status;
4875 status = decode_op_hdr(xdr, OP_LOCKT);
4876 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004877 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 return status;
4879}
4880
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004881static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 int status;
4884
4885 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004886 if (status != -EIO)
4887 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004888 if (status == 0)
4889 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 return status;
4891}
4892
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004893static int decode_release_lockowner(struct xdr_stream *xdr)
4894{
4895 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4896}
4897
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898static int decode_lookup(struct xdr_stream *xdr)
4899{
4900 return decode_op_hdr(xdr, OP_LOOKUP);
4901}
4902
4903/* This is too sick! */
4904static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4905{
Andy Adamson05d564f2008-12-23 16:06:15 -05004906 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907 uint32_t limit_type, nblocks, blocksize;
4908
Benny Halevyc0eae662009-08-14 17:20:14 +03004909 p = xdr_inline_decode(xdr, 12);
4910 if (unlikely(!p))
4911 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004912 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004914 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004915 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004916 break;
4917 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004918 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004919 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004920 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921 }
4922 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004923out_overflow:
4924 print_overflow_msg(__func__, xdr);
4925 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004926}
4927
4928static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4929{
Andy Adamson05d564f2008-12-23 16:06:15 -05004930 __be32 *p;
4931 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004932 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933
Benny Halevyc0eae662009-08-14 17:20:14 +03004934 p = xdr_inline_decode(xdr, 4);
4935 if (unlikely(!p))
4936 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004937 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4939 res->delegation_type = 0;
4940 return 0;
4941 }
Benny Halevy07d30432009-08-14 17:19:52 +03004942 status = decode_stateid(xdr, &res->delegation);
4943 if (unlikely(status))
4944 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004945 p = xdr_inline_decode(xdr, 4);
4946 if (unlikely(!p))
4947 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004948 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004949
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004951 case NFS4_OPEN_DELEGATE_READ:
4952 res->delegation_type = FMODE_READ;
4953 break;
4954 case NFS4_OPEN_DELEGATE_WRITE:
4955 res->delegation_type = FMODE_WRITE|FMODE_READ;
4956 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 return -EIO;
4958 }
David Howells7539bba2006-08-22 20:06:09 -04004959 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004960out_overflow:
4961 print_overflow_msg(__func__, xdr);
4962 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963}
4964
4965static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4966{
Andy Adamson05d564f2008-12-23 16:06:15 -05004967 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004968 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004969 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970
Andy Adamson05d564f2008-12-23 16:06:15 -05004971 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004972 if (status != -EIO)
4973 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004974 if (!status)
4975 status = decode_stateid(xdr, &res->stateid);
4976 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004977 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978
Andy Adamson05d564f2008-12-23 16:06:15 -05004979 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980
Benny Halevyc0eae662009-08-14 17:20:14 +03004981 p = xdr_inline_decode(xdr, 8);
4982 if (unlikely(!p))
4983 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004984 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004985 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004986 if (bmlen > 10)
4987 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988
Benny Halevyc0eae662009-08-14 17:20:14 +03004989 p = xdr_inline_decode(xdr, bmlen << 2);
4990 if (unlikely(!p))
4991 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004992 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4993 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004994 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004995 for (; i < NFS4_BITMAP_SIZE; i++)
4996 res->attrset[i] = 0;
4997
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998 return decode_delegation(xdr, res);
4999xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005000 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005002out_overflow:
5003 print_overflow_msg(__func__, xdr);
5004 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005}
5006
5007static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5008{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 int status;
5010
Andy Adamson05d564f2008-12-23 16:06:15 -05005011 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005012 if (status != -EIO)
5013 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005014 if (!status)
5015 status = decode_stateid(xdr, &res->stateid);
5016 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017}
5018
5019static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5020{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021 int status;
5022
5023 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005024 if (status != -EIO)
5025 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005026 if (!status)
5027 status = decode_stateid(xdr, &res->stateid);
5028 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029}
5030
5031static int decode_putfh(struct xdr_stream *xdr)
5032{
5033 return decode_op_hdr(xdr, OP_PUTFH);
5034}
5035
5036static int decode_putrootfh(struct xdr_stream *xdr)
5037{
5038 return decode_op_hdr(xdr, OP_PUTROOTFH);
5039}
5040
5041static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
5042{
Al Viro8687b632006-10-19 23:28:48 -07005043 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005044 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045 int status;
5046
5047 status = decode_op_hdr(xdr, OP_READ);
5048 if (status)
5049 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005050 p = xdr_inline_decode(xdr, 8);
5051 if (unlikely(!p))
5052 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005053 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005054 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005055 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005057 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058 "count %u > recvd %u\n", count, recvd);
5059 count = recvd;
5060 eof = 0;
5061 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062 res->eof = eof;
5063 res->count = count;
5064 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005065out_overflow:
5066 print_overflow_msg(__func__, xdr);
5067 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068}
5069
5070static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5071{
Chuck Leverbcecff72007-10-26 13:32:03 -04005072 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005073 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074
5075 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005076 if (!status)
5077 status = decode_verifier(xdr, readdir->verifier.data);
5078 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005080 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005081 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005082 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005083 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005084}
5085
5086static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5087{
5088 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005089 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005090 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 int status;
5092
5093 status = decode_op_hdr(xdr, OP_READLINK);
5094 if (status)
5095 return status;
5096
5097 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005098 p = xdr_inline_decode(xdr, 4);
5099 if (unlikely(!p))
5100 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005101 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005103 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104 return -ENAMETOOLONG;
5105 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005106 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005108 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 "count %u > recvd %u\n", len, recvd);
5110 return -EIO;
5111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112 /*
5113 * The XDR encode routine has set things up so that
5114 * the link text will be copied directly into the
5115 * buffer. We just have to do overflow-checking,
5116 * and and null-terminate the text (the VFS expects
5117 * null-termination).
5118 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005119 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005121out_overflow:
5122 print_overflow_msg(__func__, xdr);
5123 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124}
5125
5126static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5127{
5128 int status;
5129
5130 status = decode_op_hdr(xdr, OP_REMOVE);
5131 if (status)
5132 goto out;
5133 status = decode_change_info(xdr, cinfo);
5134out:
5135 return status;
5136}
5137
5138static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5139 struct nfs4_change_info *new_cinfo)
5140{
5141 int status;
5142
5143 status = decode_op_hdr(xdr, OP_RENAME);
5144 if (status)
5145 goto out;
5146 if ((status = decode_change_info(xdr, old_cinfo)))
5147 goto out;
5148 status = decode_change_info(xdr, new_cinfo);
5149out:
5150 return status;
5151}
5152
5153static int decode_renew(struct xdr_stream *xdr)
5154{
5155 return decode_op_hdr(xdr, OP_RENEW);
5156}
5157
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005158static int
5159decode_restorefh(struct xdr_stream *xdr)
5160{
5161 return decode_op_hdr(xdr, OP_RESTOREFH);
5162}
5163
J. Bruce Fields029d1052005-06-22 17:16:22 +00005164static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005165 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005166{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005167 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005168 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005169 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005170 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005171 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005172
Andy Adamsonbf118a32011-12-07 11:55:27 -05005173 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005174 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5175 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005176
Trond Myklebust519d3952012-08-14 17:30:10 -04005177 xdr_enter_page(xdr, xdr->buf->page_len);
5178
Trond Myklebustcff298c2012-08-14 17:14:17 -04005179 /* Calculate the offset of the page data */
5180 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005181
J. Bruce Fields029d1052005-06-22 17:16:22 +00005182 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5183 goto out;
5184 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5185 goto out;
5186
5187 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5188 return -EIO;
5189 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005190
Andy Adamsonbf118a32011-12-07 11:55:27 -05005191 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5192 * are stored with the acl data to handle the problem of
5193 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005194 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005195 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005196
5197 /* Check for receive buffer overflow */
5198 if (res->acl_len > (xdr->nwords << 2) ||
5199 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5200 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005201 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005202 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005203 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005204 } else
5205 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005206
5207out:
5208 return status;
5209}
5210
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211static int
5212decode_savefh(struct xdr_stream *xdr)
5213{
5214 return decode_op_hdr(xdr, OP_SAVEFH);
5215}
5216
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005217static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218{
Al Viro8687b632006-10-19 23:28:48 -07005219 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 uint32_t bmlen;
5221 int status;
5222
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 status = decode_op_hdr(xdr, OP_SETATTR);
5224 if (status)
5225 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005226 p = xdr_inline_decode(xdr, 4);
5227 if (unlikely(!p))
5228 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005229 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005230 p = xdr_inline_decode(xdr, bmlen << 2);
5231 if (likely(p))
5232 return 0;
5233out_overflow:
5234 print_overflow_msg(__func__, xdr);
5235 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236}
5237
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005238static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239{
Al Viro8687b632006-10-19 23:28:48 -07005240 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241 uint32_t opnum;
5242 int32_t nfserr;
5243
Benny Halevyc0eae662009-08-14 17:20:14 +03005244 p = xdr_inline_decode(xdr, 8);
5245 if (unlikely(!p))
5246 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005247 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005249 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005250 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251 return -EIO;
5252 }
Benny Halevycccddf42009-08-14 17:20:19 +03005253 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005255 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5256 if (unlikely(!p))
5257 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005258 p = xdr_decode_hyper(p, &res->clientid);
5259 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005260 } else if (nfserr == NFSERR_CLID_INUSE) {
5261 uint32_t len;
5262
5263 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005264 p = xdr_inline_decode(xdr, 4);
5265 if (unlikely(!p))
5266 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005267 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005268 p = xdr_inline_decode(xdr, len);
5269 if (unlikely(!p))
5270 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271
5272 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005273 p = xdr_inline_decode(xdr, 4);
5274 if (unlikely(!p))
5275 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005276 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005277 p = xdr_inline_decode(xdr, len);
5278 if (unlikely(!p))
5279 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005280 return -NFSERR_CLID_INUSE;
5281 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005282 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005283
5284 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005285out_overflow:
5286 print_overflow_msg(__func__, xdr);
5287 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005288}
5289
5290static int decode_setclientid_confirm(struct xdr_stream *xdr)
5291{
5292 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5293}
5294
5295static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5296{
Al Viro8687b632006-10-19 23:28:48 -07005297 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298 int status;
5299
5300 status = decode_op_hdr(xdr, OP_WRITE);
5301 if (status)
5302 return status;
5303
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005304 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005305 if (unlikely(!p))
5306 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005307 res->count = be32_to_cpup(p++);
5308 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005309 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005310out_overflow:
5311 print_overflow_msg(__func__, xdr);
5312 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005313}
5314
5315static int decode_delegreturn(struct xdr_stream *xdr)
5316{
5317 return decode_op_hdr(xdr, OP_DELEGRETURN);
5318}
5319
Chuck Leverfb15b262013-03-16 15:54:34 -04005320static int decode_secinfo_gss(struct xdr_stream *xdr,
5321 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005322{
Chuck Leverfb15b262013-03-16 15:54:34 -04005323 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005324 __be32 *p;
5325
5326 p = xdr_inline_decode(xdr, 4);
5327 if (unlikely(!p))
5328 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005329 oid_len = be32_to_cpup(p);
5330 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005331 goto out_err;
5332
Chuck Leverfb15b262013-03-16 15:54:34 -04005333 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005334 if (unlikely(!p))
5335 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005336 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5337 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005338
5339 p = xdr_inline_decode(xdr, 8);
5340 if (unlikely(!p))
5341 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005342 flavor->flavor_info.qop = be32_to_cpup(p++);
5343 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005344
5345 return 0;
5346
5347out_overflow:
5348 print_overflow_msg(__func__, xdr);
5349 return -EIO;
5350out_err:
5351 return -EINVAL;
5352}
5353
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005354static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005355{
Chuck Leverfb15b262013-03-16 15:54:34 -04005356 struct nfs4_secinfo4 *sec_flavor;
5357 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005358 int status;
5359 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005360
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005361 p = xdr_inline_decode(xdr, 4);
5362 if (unlikely(!p))
5363 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005364
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005365 res->flavors->num_flavors = 0;
5366 num_flavors = be32_to_cpup(p);
5367
5368 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005369 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005370 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005371 break;
5372
5373 p = xdr_inline_decode(xdr, 4);
5374 if (unlikely(!p))
5375 goto out_overflow;
5376 sec_flavor->flavor = be32_to_cpup(p);
5377
5378 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005379 status = decode_secinfo_gss(xdr, sec_flavor);
5380 if (status)
5381 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005382 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005383 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005384 }
5385
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005386 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005387out:
5388 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005389out_overflow:
5390 print_overflow_msg(__func__, xdr);
5391 return -EIO;
5392}
5393
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005394static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5395{
5396 int status = decode_op_hdr(xdr, OP_SECINFO);
5397 if (status)
5398 return status;
5399 return decode_secinfo_common(xdr, res);
5400}
5401
Benny Halevy99fe60d2009-04-01 09:22:29 -04005402#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005403static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5404{
5405 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5406 if (status)
5407 return status;
5408 return decode_secinfo_common(xdr, res);
5409}
5410
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005411static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5412{
5413 __be32 *p;
5414 uint32_t bitmap_words;
5415 unsigned int i;
5416
5417 p = xdr_inline_decode(xdr, 4);
5418 bitmap_words = be32_to_cpup(p++);
5419 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5420 return -EIO;
5421 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5422 for (i = 0; i < bitmap_words; i++)
5423 op_map->u.words[i] = be32_to_cpup(p++);
5424
5425 return 0;
5426}
5427
Benny Halevy99fe60d2009-04-01 09:22:29 -04005428static int decode_exchange_id(struct xdr_stream *xdr,
5429 struct nfs41_exchange_id_res *res)
5430{
5431 __be32 *p;
5432 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005433 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005434 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005435 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005436
5437 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5438 if (status)
5439 return status;
5440
Benny Halevyc0eae662009-08-14 17:20:14 +03005441 p = xdr_inline_decode(xdr, 8);
5442 if (unlikely(!p))
5443 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005444 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005445 p = xdr_inline_decode(xdr, 12);
5446 if (unlikely(!p))
5447 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005448 res->seqid = be32_to_cpup(p++);
5449 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005450
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005451 res->state_protect.how = be32_to_cpup(p);
5452 switch (res->state_protect.how) {
5453 case SP4_NONE:
5454 break;
5455 case SP4_MACH_CRED:
5456 status = decode_op_map(xdr, &res->state_protect.enforce);
5457 if (status)
5458 return status;
5459 status = decode_op_map(xdr, &res->state_protect.allow);
5460 if (status)
5461 return status;
5462 break;
5463 default:
5464 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005465 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005466 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005467
Chuck Leveracdeb692012-05-21 22:46:16 -04005468 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005469 p = xdr_inline_decode(xdr, 8);
5470 if (unlikely(!p))
5471 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005472 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005473
Chuck Leveracdeb692012-05-21 22:46:16 -04005474 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005475 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5476 if (unlikely(status))
5477 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005478 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5479 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005480 memcpy(res->server_owner->major_id, dummy_str, dummy);
5481 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005482
Chuck Leveracdeb692012-05-21 22:46:16 -04005483 /* server_scope4 */
5484 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5485 if (unlikely(status))
5486 return status;
5487 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5488 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005489 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5490 res->server_scope->server_scope_sz = dummy;
5491
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005492 /* Implementation Id */
5493 p = xdr_inline_decode(xdr, 4);
5494 if (unlikely(!p))
5495 goto out_overflow;
5496 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005497
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005498 if (impl_id_count) {
5499 /* nii_domain */
5500 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5501 if (unlikely(status))
5502 return status;
5503 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5504 return -EIO;
5505 memcpy(res->impl_id->domain, dummy_str, dummy);
5506
5507 /* nii_name */
5508 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5509 if (unlikely(status))
5510 return status;
5511 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5512 return -EIO;
5513 memcpy(res->impl_id->name, dummy_str, dummy);
5514
5515 /* nii_date */
5516 p = xdr_inline_decode(xdr, 12);
5517 if (unlikely(!p))
5518 goto out_overflow;
5519 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5520 res->impl_id->date.nseconds = be32_to_cpup(p);
5521
5522 /* if there's more than one entry, ignore the rest */
5523 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005524 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005525out_overflow:
5526 print_overflow_msg(__func__, xdr);
5527 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005528}
Andy Adamsonfc931582009-04-01 09:22:31 -04005529
5530static int decode_chan_attrs(struct xdr_stream *xdr,
5531 struct nfs4_channel_attrs *attrs)
5532{
5533 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005534 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005535
Benny Halevyc0eae662009-08-14 17:20:14 +03005536 p = xdr_inline_decode(xdr, 28);
5537 if (unlikely(!p))
5538 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005539 val = be32_to_cpup(p++); /* headerpadsz */
5540 if (val)
5541 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005542 attrs->max_rqst_sz = be32_to_cpup(p++);
5543 attrs->max_resp_sz = be32_to_cpup(p++);
5544 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5545 attrs->max_ops = be32_to_cpup(p++);
5546 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005547 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005548 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005549 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5550 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005551 return -EINVAL;
5552 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005553 if (nr_attrs == 1) {
5554 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5555 if (unlikely(!p))
5556 goto out_overflow;
5557 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005558 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005559out_overflow:
5560 print_overflow_msg(__func__, xdr);
5561 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005562}
5563
Benny Halevye78291e2009-08-14 17:20:00 +03005564static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5565{
5566 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005567}
5568
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005569static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5570 struct nfs41_bind_conn_to_session_res *res)
5571{
5572 __be32 *p;
5573 int status;
5574
5575 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5576 if (!status)
5577 status = decode_sessionid(xdr, &res->session->sess_id);
5578 if (unlikely(status))
5579 return status;
5580
5581 /* dir flags, rdma mode bool */
5582 p = xdr_inline_decode(xdr, 8);
5583 if (unlikely(!p))
5584 goto out_overflow;
5585
5586 res->dir = be32_to_cpup(p++);
5587 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5588 return -EIO;
5589 if (be32_to_cpup(p) == 0)
5590 res->use_conn_in_rdma_mode = false;
5591 else
5592 res->use_conn_in_rdma_mode = true;
5593
5594 return 0;
5595out_overflow:
5596 print_overflow_msg(__func__, xdr);
5597 return -EIO;
5598}
5599
Andy Adamsonfc931582009-04-01 09:22:31 -04005600static int decode_create_session(struct xdr_stream *xdr,
5601 struct nfs41_create_session_res *res)
5602{
5603 __be32 *p;
5604 int status;
5605 struct nfs_client *clp = res->client;
5606 struct nfs4_session *session = clp->cl_session;
5607
5608 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005609 if (!status)
5610 status = decode_sessionid(xdr, &session->sess_id);
5611 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005612 return status;
5613
Andy Adamsonfc931582009-04-01 09:22:31 -04005614 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005615 p = xdr_inline_decode(xdr, 8);
5616 if (unlikely(!p))
5617 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005618 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005619 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005620
5621 /* Channel attributes */
5622 status = decode_chan_attrs(xdr, &session->fc_attrs);
5623 if (!status)
5624 status = decode_chan_attrs(xdr, &session->bc_attrs);
5625 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005626out_overflow:
5627 print_overflow_msg(__func__, xdr);
5628 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005629}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005630
5631static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5632{
5633 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5634}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005635
Trond Myklebust66245532012-05-25 17:18:09 -04005636static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5637{
5638 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5639}
5640
Ricardo Labiaga180197532009-12-05 16:08:40 -05005641static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5642{
5643 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5644}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005645#endif /* CONFIG_NFS_V4_1 */
5646
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005647static int decode_sequence(struct xdr_stream *xdr,
5648 struct nfs4_sequence_res *res,
5649 struct rpc_rqst *rqstp)
5650{
5651#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005652 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005653 struct nfs4_sessionid id;
5654 u32 dummy;
5655 int status;
5656 __be32 *p;
5657
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005658 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005659 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005660 if (!res->sr_slot->table->session)
5661 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005662
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005663 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005664 if (!status)
5665 status = decode_sessionid(xdr, &id);
5666 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005667 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005668
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005669 /*
5670 * If the server returns different values for sessionID, slotID or
5671 * sequence number, the server is looney tunes.
5672 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005673 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005674 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005675
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005676 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005677 NFS4_MAX_SESSIONID_LEN)) {
5678 dprintk("%s Invalid session id\n", __func__);
5679 goto out_err;
5680 }
Benny Halevye78291e2009-08-14 17:20:00 +03005681
Benny Halevyc0eae662009-08-14 17:20:14 +03005682 p = xdr_inline_decode(xdr, 20);
5683 if (unlikely(!p))
5684 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005685
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005686 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005687 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005688 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005689 dprintk("%s Invalid sequence number\n", __func__);
5690 goto out_err;
5691 }
5692 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005693 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005694 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005695 dprintk("%s Invalid slot id\n", __func__);
5696 goto out_err;
5697 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005698 /* highest slot id */
5699 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005700 /* target highest slot id */
5701 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005702 /* result flags */
5703 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005704 status = 0;
5705out_err:
5706 res->sr_status = status;
5707 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005708out_overflow:
5709 print_overflow_msg(__func__, xdr);
5710 status = -EIO;
5711 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005712#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005713 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005714#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005715}
5716
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005717#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005718/*
5719 * TODO: Need to handle case when EOF != true;
5720 */
5721static int decode_getdevicelist(struct xdr_stream *xdr,
5722 struct pnfs_devicelist *res)
5723{
5724 __be32 *p;
5725 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005726 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005727
5728 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5729 if (status)
5730 return status;
5731
5732 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5733 if (unlikely(!p))
5734 goto out_overflow;
5735
5736 /* TODO: Skip cookie for now */
5737 p += 2;
5738
5739 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005740 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005741
5742 res->num_devs = be32_to_cpup(p);
5743
5744 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5745
5746 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005747 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005748 __func__, res->num_devs);
5749 return -EIO;
5750 }
5751
5752 p = xdr_inline_decode(xdr,
5753 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5754 if (unlikely(!p))
5755 goto out_overflow;
5756 for (i = 0; i < res->num_devs; i++)
5757 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5758 NFS4_DEVICEID4_SIZE);
5759 res->eof = be32_to_cpup(p);
5760 return 0;
5761out_overflow:
5762 print_overflow_msg(__func__, xdr);
5763 return -EIO;
5764}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005765
5766static int decode_getdeviceinfo(struct xdr_stream *xdr,
5767 struct pnfs_device *pdev)
5768{
5769 __be32 *p;
5770 uint32_t len, type;
5771 int status;
5772
5773 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5774 if (status) {
5775 if (status == -ETOOSMALL) {
5776 p = xdr_inline_decode(xdr, 4);
5777 if (unlikely(!p))
5778 goto out_overflow;
5779 pdev->mincount = be32_to_cpup(p);
5780 dprintk("%s: Min count too small. mincnt = %u\n",
5781 __func__, pdev->mincount);
5782 }
5783 return status;
5784 }
5785
5786 p = xdr_inline_decode(xdr, 8);
5787 if (unlikely(!p))
5788 goto out_overflow;
5789 type = be32_to_cpup(p++);
5790 if (type != pdev->layout_type) {
5791 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5792 __func__, pdev->layout_type, type);
5793 return -EINVAL;
5794 }
5795 /*
5796 * Get the length of the opaque device_addr4. xdr_read_pages places
5797 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5798 * and places the remaining xdr data in xdr_buf->tail
5799 */
5800 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005801 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5802 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005803
5804 /* Parse notification bitmap, verifying that it is zero. */
5805 p = xdr_inline_decode(xdr, 4);
5806 if (unlikely(!p))
5807 goto out_overflow;
5808 len = be32_to_cpup(p);
5809 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005810 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005811
5812 p = xdr_inline_decode(xdr, 4 * len);
5813 if (unlikely(!p))
5814 goto out_overflow;
5815 for (i = 0; i < len; i++, p++) {
5816 if (be32_to_cpup(p)) {
5817 dprintk("%s: notifications not supported\n",
5818 __func__);
5819 return -EIO;
5820 }
5821 }
5822 }
5823 return 0;
5824out_overflow:
5825 print_overflow_msg(__func__, xdr);
5826 return -EIO;
5827}
5828
5829static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5830 struct nfs4_layoutget_res *res)
5831{
5832 __be32 *p;
5833 int status;
5834 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005835 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005836
5837 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5838 if (status)
5839 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005840 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005841 if (unlikely(!p))
5842 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005843 res->return_on_close = be32_to_cpup(p);
5844 decode_stateid(xdr, &res->stateid);
5845 p = xdr_inline_decode(xdr, 4);
5846 if (unlikely(!p))
5847 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005848 layout_count = be32_to_cpup(p);
5849 if (!layout_count) {
5850 dprintk("%s: server responded with empty layout array\n",
5851 __func__);
5852 return -EINVAL;
5853 }
5854
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005855 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005856 if (unlikely(!p))
5857 goto out_overflow;
5858 p = xdr_decode_hyper(p, &res->range.offset);
5859 p = xdr_decode_hyper(p, &res->range.length);
5860 res->range.iomode = be32_to_cpup(p++);
5861 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005862 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005863
5864 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5865 __func__,
5866 (unsigned long)res->range.offset,
5867 (unsigned long)res->range.length,
5868 res->range.iomode,
5869 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005870 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005871
Trond Myklebust64bd5772012-06-20 22:35:05 -04005872 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005873 if (res->layoutp->len > recvd) {
5874 dprintk("NFS: server cheating in layoutget reply: "
5875 "layout len %u > recvd %u\n",
5876 res->layoutp->len, recvd);
5877 return -EINVAL;
5878 }
5879
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005880 if (layout_count > 1) {
5881 /* We only handle a length one array at the moment. Any
5882 * further entries are just ignored. Note that this means
5883 * the client may see a response that is less than the
5884 * minimum it requested.
5885 */
5886 dprintk("%s: server responded with %d layouts, dropping tail\n",
5887 __func__, layout_count);
5888 }
5889
5890 return 0;
5891out_overflow:
5892 print_overflow_msg(__func__, xdr);
5893 return -EIO;
5894}
Andy Adamson863a3c62011-03-23 13:27:54 +00005895
Benny Halevycbe82602011-05-22 19:52:37 +03005896static int decode_layoutreturn(struct xdr_stream *xdr,
5897 struct nfs4_layoutreturn_res *res)
5898{
5899 __be32 *p;
5900 int status;
5901
5902 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5903 if (status)
5904 return status;
5905 p = xdr_inline_decode(xdr, 4);
5906 if (unlikely(!p))
5907 goto out_overflow;
5908 res->lrs_present = be32_to_cpup(p);
5909 if (res->lrs_present)
5910 status = decode_stateid(xdr, &res->stateid);
5911 return status;
5912out_overflow:
5913 print_overflow_msg(__func__, xdr);
5914 return -EIO;
5915}
5916
Andy Adamson863a3c62011-03-23 13:27:54 +00005917static int decode_layoutcommit(struct xdr_stream *xdr,
5918 struct rpc_rqst *req,
5919 struct nfs4_layoutcommit_res *res)
5920{
5921 __be32 *p;
5922 __u32 sizechanged;
5923 int status;
5924
5925 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005926 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005927 if (status)
5928 return status;
5929
5930 p = xdr_inline_decode(xdr, 4);
5931 if (unlikely(!p))
5932 goto out_overflow;
5933 sizechanged = be32_to_cpup(p);
5934
5935 if (sizechanged) {
5936 /* throw away new size */
5937 p = xdr_inline_decode(xdr, 8);
5938 if (unlikely(!p))
5939 goto out_overflow;
5940 }
5941 return 0;
5942out_overflow:
5943 print_overflow_msg(__func__, xdr);
5944 return -EIO;
5945}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005946
5947static int decode_test_stateid(struct xdr_stream *xdr,
5948 struct nfs41_test_stateid_res *res)
5949{
5950 __be32 *p;
5951 int status;
5952 int num_res;
5953
5954 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5955 if (status)
5956 return status;
5957
5958 p = xdr_inline_decode(xdr, 4);
5959 if (unlikely(!p))
5960 goto out_overflow;
5961 num_res = be32_to_cpup(p++);
5962 if (num_res != 1)
5963 goto out;
5964
5965 p = xdr_inline_decode(xdr, 4);
5966 if (unlikely(!p))
5967 goto out_overflow;
5968 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005969
5970 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005971out_overflow:
5972 print_overflow_msg(__func__, xdr);
5973out:
5974 return -EIO;
5975}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005976
5977static int decode_free_stateid(struct xdr_stream *xdr,
5978 struct nfs41_free_stateid_res *res)
5979{
Andy Adamson9f79fb42013-09-10 12:56:29 -04005980 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005981 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005982}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005983#endif /* CONFIG_NFS_V4_1 */
5984
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985/*
Benny Halevy49c25592008-12-23 16:06:16 -05005986 * END OF "GENERIC" DECODE ROUTINES.
5987 */
5988
5989/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005990 * Decode OPEN_DOWNGRADE response
5991 */
Chuck Leverbf269552010-12-14 14:59:29 +00005992static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5993 struct xdr_stream *xdr,
5994 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995{
Andy Adamson05d564f2008-12-23 16:06:15 -05005996 struct compound_hdr hdr;
5997 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005998
Chuck Leverbf269552010-12-14 14:59:29 +00005999 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006000 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)
6004 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006005 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006006 if (status)
6007 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006008 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006009 if (status != 0)
6010 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006011 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006013 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014}
6015
6016/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006017 * Decode ACCESS response
6018 */
Chuck Leverbf269552010-12-14 14:59:29 +00006019static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6020 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022 struct compound_hdr hdr;
6023 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006024
Chuck Leverbf269552010-12-14 14:59:29 +00006025 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006026 if (status)
6027 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006028 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006029 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006032 if (status != 0)
6033 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006034 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006035 if (status != 0)
6036 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006037 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006038out:
6039 return status;
6040}
6041
6042/*
6043 * Decode LOOKUP response
6044 */
Chuck Leverbf269552010-12-14 14:59:29 +00006045static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6046 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006048 struct compound_hdr hdr;
6049 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006050
Chuck Leverbf269552010-12-14 14:59:29 +00006051 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006052 if (status)
6053 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006054 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006055 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006057 status = decode_putfh(xdr);
6058 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006059 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006060 status = decode_lookup(xdr);
6061 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006063 status = decode_getfh(xdr, res->fh);
6064 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006066 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067out:
6068 return status;
6069}
6070
6071/*
6072 * Decode LOOKUP_ROOT response
6073 */
Chuck Leverbf269552010-12-14 14:59:29 +00006074static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6075 struct xdr_stream *xdr,
6076 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078 struct compound_hdr hdr;
6079 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006080
Chuck Leverbf269552010-12-14 14:59:29 +00006081 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006082 if (status)
6083 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006084 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006085 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006087 status = decode_putrootfh(xdr);
6088 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006090 status = decode_getfh(xdr, res->fh);
6091 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006092 status = decode_getfattr_label(xdr, res->fattr,
6093 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094out:
6095 return status;
6096}
6097
6098/*
6099 * Decode REMOVE response
6100 */
Chuck Leverbf269552010-12-14 14:59:29 +00006101static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6102 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104 struct compound_hdr hdr;
6105 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006106
Chuck Leverbf269552010-12-14 14:59:29 +00006107 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006108 if (status)
6109 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006110 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006111 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006112 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006113 status = decode_putfh(xdr);
6114 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006115 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006116 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117out:
6118 return status;
6119}
6120
6121/*
6122 * Decode RENAME response
6123 */
Chuck Leverbf269552010-12-14 14:59:29 +00006124static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6125 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127 struct compound_hdr hdr;
6128 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006129
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006131 if (status)
6132 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006134 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_putfh(xdr);
6137 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_savefh(xdr);
6140 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_putfh(xdr);
6143 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006144 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006145 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146out:
6147 return status;
6148}
6149
6150/*
6151 * Decode LINK response
6152 */
Chuck Leverbf269552010-12-14 14:59:29 +00006153static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6154 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156 struct compound_hdr hdr;
6157 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006158
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006160 if (status)
6161 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006162 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006163 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_putfh(xdr);
6166 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006168 status = decode_savefh(xdr);
6169 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006171 status = decode_putfh(xdr);
6172 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006174 status = decode_link(xdr, &res->cinfo);
6175 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006176 goto out;
6177 /*
6178 * Note order: OP_LINK leaves the directory as the current
6179 * filehandle.
6180 */
Chuck Leverbf269552010-12-14 14:59:29 +00006181 status = decode_restorefh(xdr);
6182 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006183 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006184 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185out:
6186 return status;
6187}
6188
6189/*
6190 * Decode CREATE response
6191 */
Chuck Leverbf269552010-12-14 14:59:29 +00006192static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6193 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195 struct compound_hdr hdr;
6196 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006197
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006199 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)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_putfh(xdr);
6205 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006207 status = decode_create(xdr, &res->dir_cinfo);
6208 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006210 status = decode_getfh(xdr, res->fh);
6211 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006213 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214out:
6215 return status;
6216}
6217
6218/*
6219 * Decode SYMLINK response
6220 */
Chuck Leverbf269552010-12-14 14:59:29 +00006221static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6222 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006223{
Chuck Leverbf269552010-12-14 14:59:29 +00006224 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225}
6226
6227/*
6228 * Decode GETATTR response
6229 */
Chuck Leverbf269552010-12-14 14:59:29 +00006230static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6231 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233 struct compound_hdr hdr;
6234 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006235
Chuck Leverbf269552010-12-14 14:59:29 +00006236 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237 if (status)
6238 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006239 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006240 if (status)
6241 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006242 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 if (status)
6244 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006245 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246out:
6247 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248}
6249
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006250/*
6251 * Encode an SETACL request
6252 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006253static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6254 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006255{
Andy Adamson05d564f2008-12-23 16:06:15 -05006256 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006257 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006258 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006259
Chuck Lever9f06c712010-12-14 14:59:18 +00006260 encode_compound_hdr(xdr, req, &hdr);
6261 encode_sequence(xdr, &args->seq_args, &hdr);
6262 encode_putfh(xdr, args->fh, &hdr);
6263 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006264 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006265}
Andy Adamson05d564f2008-12-23 16:06:15 -05006266
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006267/*
6268 * Decode SETACL response
6269 */
6270static int
Chuck Leverbf269552010-12-14 14:59:29 +00006271nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006272 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006273{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006274 struct compound_hdr hdr;
6275 int status;
6276
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006278 if (status)
6279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006281 if (status)
6282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006283 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006284 if (status)
6285 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006286 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006287out:
6288 return status;
6289}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290
6291/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006292 * Decode GETACL response
6293 */
6294static int
Chuck Leverbf269552010-12-14 14:59:29 +00006295nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006296 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006297{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006298 struct compound_hdr hdr;
6299 int status;
6300
Trond Myklebust331818f2012-02-03 18:30:53 -05006301 if (res->acl_scratch != NULL) {
6302 void *p = page_address(res->acl_scratch);
6303 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6304 }
Chuck Leverbf269552010-12-14 14:59:29 +00006305 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006306 if (status)
6307 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006308 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006309 if (status)
6310 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006311 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006312 if (status)
6313 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006314 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006315
6316out:
6317 return status;
6318}
6319
6320/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321 * Decode CLOSE response
6322 */
Chuck Leverbf269552010-12-14 14:59:29 +00006323static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6324 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325{
Andy Adamson05d564f2008-12-23 16:06:15 -05006326 struct compound_hdr hdr;
6327 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328
Chuck Leverbf269552010-12-14 14:59:29 +00006329 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006330 if (status)
6331 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006332 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006333 if (status)
6334 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006335 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006336 if (status)
6337 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006338 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006339 if (status != 0)
6340 goto out;
6341 /*
6342 * Note: Server may do delete on close for this file
6343 * in which case the getattr call will fail with
6344 * an ESTALE error. Shouldn't be a problem,
6345 * though, since fattr->valid will remain unset.
6346 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006347 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006349 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350}
6351
6352/*
6353 * Decode OPEN response
6354 */
Chuck Leverbf269552010-12-14 14:59:29 +00006355static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6356 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357{
Andy Adamson05d564f2008-12-23 16:06:15 -05006358 struct compound_hdr hdr;
6359 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006360
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006362 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);
Andy Adamson05d564f2008-12-23 16:06:15 -05006368 if (status)
6369 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006371 if (status)
6372 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006373 status = decode_getfh(xdr, &res->fh);
6374 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006376 if (res->access_request)
6377 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006378 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006379out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006380 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381}
6382
6383/*
6384 * Decode OPEN_CONFIRM response
6385 */
Chuck Leverbf269552010-12-14 14:59:29 +00006386static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6387 struct xdr_stream *xdr,
6388 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006389{
Andy Adamson05d564f2008-12-23 16:06:15 -05006390 struct compound_hdr hdr;
6391 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006394 if (status)
6395 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006396 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006397 if (status)
6398 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006399 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006401 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402}
6403
6404/*
6405 * Decode OPEN response
6406 */
Chuck Leverbf269552010-12-14 14:59:29 +00006407static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6408 struct xdr_stream *xdr,
6409 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410{
Andy Adamson05d564f2008-12-23 16:06:15 -05006411 struct compound_hdr hdr;
6412 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006413
Chuck Leverbf269552010-12-14 14:59:29 +00006414 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006415 if (status)
6416 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006417 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006418 if (status)
6419 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006420 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006421 if (status)
6422 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006423 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006424 if (status)
6425 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006426 if (res->access_request)
6427 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006428 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006430 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431}
6432
6433/*
6434 * Decode SETATTR response
6435 */
Chuck Leverbf269552010-12-14 14:59:29 +00006436static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6437 struct xdr_stream *xdr,
6438 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439{
Andy Adamson05d564f2008-12-23 16:06:15 -05006440 struct compound_hdr hdr;
6441 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006444 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);
Andy Adamson05d564f2008-12-23 16:06:15 -05006450 if (status)
6451 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006452 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006453 if (status)
6454 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006455 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006457 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458}
6459
6460/*
6461 * Decode LOCK response
6462 */
Chuck Leverbf269552010-12-14 14:59:29 +00006463static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6464 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466 struct compound_hdr hdr;
6467 int status;
6468
Chuck Leverbf269552010-12-14 14:59:29 +00006469 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470 if (status)
6471 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006472 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006473 if (status)
6474 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006475 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006476 if (status)
6477 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006478 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479out:
6480 return status;
6481}
6482
6483/*
6484 * Decode LOCKT response
6485 */
Chuck Leverbf269552010-12-14 14:59:29 +00006486static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6487 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006488{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489 struct compound_hdr hdr;
6490 int status;
6491
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493 if (status)
6494 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006495 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006496 if (status)
6497 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006498 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006499 if (status)
6500 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006501 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502out:
6503 return status;
6504}
6505
6506/*
6507 * Decode LOCKU response
6508 */
Chuck Leverbf269552010-12-14 14:59:29 +00006509static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6510 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006511{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006512 struct compound_hdr hdr;
6513 int status;
6514
Chuck Leverbf269552010-12-14 14:59:29 +00006515 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516 if (status)
6517 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006518 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006519 if (status)
6520 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006521 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006522 if (status)
6523 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006524 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525out:
6526 return status;
6527}
6528
Chuck Leverbf269552010-12-14 14:59:29 +00006529static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6530 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006531{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006532 struct compound_hdr hdr;
6533 int status;
6534
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006536 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006537 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006538 return status;
6539}
6540
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541/*
6542 * Decode READLINK response
6543 */
Chuck Leverbf269552010-12-14 14:59:29 +00006544static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6545 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006546 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 struct compound_hdr hdr;
6549 int status;
6550
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552 if (status)
6553 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006554 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006555 if (status)
6556 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006557 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006558 if (status)
6559 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006560 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006561out:
6562 return status;
6563}
6564
6565/*
6566 * Decode READDIR response
6567 */
Chuck Leverbf269552010-12-14 14:59:29 +00006568static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6569 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006571 struct compound_hdr hdr;
6572 int status;
6573
Chuck Leverbf269552010-12-14 14:59:29 +00006574 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575 if (status)
6576 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006577 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006578 if (status)
6579 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006581 if (status)
6582 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584out:
6585 return status;
6586}
6587
6588/*
6589 * Decode Read response
6590 */
Chuck Leverbf269552010-12-14 14:59:29 +00006591static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6592 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006594 struct compound_hdr hdr;
6595 int status;
6596
Chuck Leverbf269552010-12-14 14:59:29 +00006597 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598 if (status)
6599 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006600 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006601 if (status)
6602 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604 if (status)
6605 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006606 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607 if (!status)
6608 status = res->count;
6609out:
6610 return status;
6611}
6612
6613/*
6614 * Decode WRITE response
6615 */
Chuck Leverbf269552010-12-14 14:59:29 +00006616static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6617 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006618{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619 struct compound_hdr hdr;
6620 int status;
6621
Chuck Leverbf269552010-12-14 14:59:29 +00006622 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006623 if (status)
6624 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006625 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006626 if (status)
6627 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006628 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629 if (status)
6630 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006631 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006632 if (status)
6633 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006634 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006635 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636 if (!status)
6637 status = res->count;
6638out:
6639 return status;
6640}
6641
6642/*
6643 * Decode COMMIT response
6644 */
Chuck Leverbf269552010-12-14 14:59:29 +00006645static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006646 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006648 struct compound_hdr hdr;
6649 int status;
6650
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006652 if (status)
6653 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006654 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006655 if (status)
6656 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006657 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006658 if (status)
6659 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006660 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006661out:
6662 return status;
6663}
6664
6665/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006666 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006667 */
Chuck Leverbf269552010-12-14 14:59:29 +00006668static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006669 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006670{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006671 struct compound_hdr hdr;
6672 int status;
6673
Chuck Leverbf269552010-12-14 14:59:29 +00006674 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006676 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006677 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006678 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006679 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006680 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006681 return status;
6682}
6683
6684/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006685 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006686 */
Chuck Leverbf269552010-12-14 14:59:29 +00006687static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006688 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006690 struct compound_hdr hdr;
6691 int status;
6692
Chuck Leverbf269552010-12-14 14:59:29 +00006693 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006694 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006695 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006696 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006697 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006698 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006699 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006700 return status;
6701}
6702
6703/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006704 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006705 */
Chuck Leverbf269552010-12-14 14:59:29 +00006706static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006707 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006708{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006709 struct compound_hdr hdr;
6710 int status;
6711
Chuck Leverbf269552010-12-14 14:59:29 +00006712 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006713 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006714 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006715 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006716 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006717 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006718 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006719 return status;
6720}
6721
6722/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006723 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724 */
Chuck Leverbf269552010-12-14 14:59:29 +00006725static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6726 struct xdr_stream *xdr,
6727 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006728{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006729 struct compound_hdr hdr;
6730 int status;
6731
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006733 if (status)
6734 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006735 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006736 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006738 status = decode_putfh(xdr);
6739 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006740 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006741 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742out:
6743 return status;
6744}
6745
6746/*
6747 * Decode RENEW response
6748 */
Chuck Leverbf269552010-12-14 14:59:29 +00006749static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6750 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006751{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006752 struct compound_hdr hdr;
6753 int status;
6754
Chuck Leverbf269552010-12-14 14:59:29 +00006755 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006756 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006757 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006758 return status;
6759}
6760
6761/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006762 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006763 */
Chuck Leverbf269552010-12-14 14:59:29 +00006764static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6765 struct xdr_stream *xdr,
6766 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006767{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768 struct compound_hdr hdr;
6769 int status;
6770
Chuck Leverbf269552010-12-14 14:59:29 +00006771 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006772 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006773 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006774 return status;
6775}
6776
6777/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006778 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006779 */
Chuck Leverbf269552010-12-14 14:59:29 +00006780static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006781 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006782{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006783 struct compound_hdr hdr;
6784 int status;
6785
Chuck Leverbf269552010-12-14 14:59:29 +00006786 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006787 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006788 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006789 return status;
6790}
6791
6792/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006793 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006794 */
Chuck Leverbf269552010-12-14 14:59:29 +00006795static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6796 struct xdr_stream *xdr,
6797 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006798{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006799 struct compound_hdr hdr;
6800 int status;
6801
Chuck Leverbf269552010-12-14 14:59:29 +00006802 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006803 if (status)
6804 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006805 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006806 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006807 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006808 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006809 if (status != 0)
6810 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006811 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006812 if (status != 0)
6813 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006814 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006815out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006816 return status;
6817}
6818
Trond Myklebust683b57b2006-06-09 09:34:22 -04006819/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006820 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006821 */
Chuck Leverbf269552010-12-14 14:59:29 +00006822static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6823 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006824 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006825{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006826 struct compound_hdr hdr;
6827 int status;
6828
Chuck Leverbf269552010-12-14 14:59:29 +00006829 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006830 if (status)
6831 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006832 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006833 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006834 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_putfh(xdr);
6836 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006837 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006838 if (res->migration) {
6839 xdr_enter_page(xdr, PAGE_SIZE);
6840 status = decode_getfattr_generic(xdr,
6841 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006842 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006843 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006844 if (status)
6845 goto out;
6846 if (res->renew)
6847 status = decode_renew(xdr);
6848 } else {
6849 status = decode_lookup(xdr);
6850 if (status)
6851 goto out;
6852 xdr_enter_page(xdr, PAGE_SIZE);
6853 status = decode_getfattr_generic(xdr,
6854 &res->fs_locations->fattr,
6855 NULL, res->fs_locations,
6856 NULL, res->fs_locations->server);
6857 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006858out:
6859 return status;
6860}
6861
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006862/*
6863 * Decode SECINFO response
6864 */
6865static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6866 struct xdr_stream *xdr,
6867 struct nfs4_secinfo_res *res)
6868{
6869 struct compound_hdr hdr;
6870 int status;
6871
6872 status = decode_compound_hdr(xdr, &hdr);
6873 if (status)
6874 goto out;
6875 status = decode_sequence(xdr, &res->seq_res, rqstp);
6876 if (status)
6877 goto out;
6878 status = decode_putfh(xdr);
6879 if (status)
6880 goto out;
6881 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006882out:
6883 return status;
6884}
6885
Benny Halevy99fe60d2009-04-01 09:22:29 -04006886#if defined(CONFIG_NFS_V4_1)
6887/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006888 * Decode BIND_CONN_TO_SESSION response
6889 */
6890static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6891 struct xdr_stream *xdr,
6892 void *res)
6893{
6894 struct compound_hdr hdr;
6895 int status;
6896
6897 status = decode_compound_hdr(xdr, &hdr);
6898 if (!status)
6899 status = decode_bind_conn_to_session(xdr, res);
6900 return status;
6901}
6902
6903/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006904 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006905 */
Chuck Leverbf269552010-12-14 14:59:29 +00006906static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6907 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006908 void *res)
6909{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006910 struct compound_hdr hdr;
6911 int status;
6912
Chuck Leverbf269552010-12-14 14:59:29 +00006913 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006914 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006915 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006916 return status;
6917}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006918
6919/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006920 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006921 */
Chuck Leverbf269552010-12-14 14:59:29 +00006922static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6923 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006924 struct nfs41_create_session_res *res)
6925{
Andy Adamsonfc931582009-04-01 09:22:31 -04006926 struct compound_hdr hdr;
6927 int status;
6928
Chuck Leverbf269552010-12-14 14:59:29 +00006929 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006930 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006931 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006932 return status;
6933}
6934
6935/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006936 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006937 */
Chuck Leverbf269552010-12-14 14:59:29 +00006938static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6939 struct xdr_stream *xdr,
6940 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006941{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006942 struct compound_hdr hdr;
6943 int status;
6944
Chuck Leverbf269552010-12-14 14:59:29 +00006945 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006946 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006947 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006948 return status;
6949}
6950
6951/*
Trond Myklebust66245532012-05-25 17:18:09 -04006952 * Decode DESTROY_CLIENTID response
6953 */
6954static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6955 struct xdr_stream *xdr,
6956 void *res)
6957{
6958 struct compound_hdr hdr;
6959 int status;
6960
6961 status = decode_compound_hdr(xdr, &hdr);
6962 if (!status)
6963 status = decode_destroy_clientid(xdr, res);
6964 return status;
6965}
6966
6967/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006968 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006969 */
Chuck Leverbf269552010-12-14 14:59:29 +00006970static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6971 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006972 struct nfs4_sequence_res *res)
6973{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006974 struct compound_hdr hdr;
6975 int status;
6976
Chuck Leverbf269552010-12-14 14:59:29 +00006977 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006978 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006979 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006980 return status;
6981}
6982
6983/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006984 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006985 */
Chuck Leverbf269552010-12-14 14:59:29 +00006986static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6987 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006988 struct nfs4_get_lease_time_res *res)
6989{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006990 struct compound_hdr hdr;
6991 int status;
6992
Chuck Leverbf269552010-12-14 14:59:29 +00006993 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006994 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006995 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006996 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006997 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006998 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006999 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007000 return status;
7001}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007002
7003/*
7004 * Decode RECLAIM_COMPLETE response
7005 */
Chuck Leverbf269552010-12-14 14:59:29 +00007006static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7007 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007008 struct nfs41_reclaim_complete_res *res)
7009{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007010 struct compound_hdr hdr;
7011 int status;
7012
Chuck Leverbf269552010-12-14 14:59:29 +00007013 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007014 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007015 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007016 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007017 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007018 return status;
7019}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007020
7021/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007022 * Decode GETDEVICELIST response
7023 */
7024static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
7025 struct xdr_stream *xdr,
7026 struct nfs4_getdevicelist_res *res)
7027{
7028 struct compound_hdr hdr;
7029 int status;
7030
7031 dprintk("encoding getdevicelist!\n");
7032
7033 status = decode_compound_hdr(xdr, &hdr);
7034 if (status != 0)
7035 goto out;
7036 status = decode_sequence(xdr, &res->seq_res, rqstp);
7037 if (status != 0)
7038 goto out;
7039 status = decode_putfh(xdr);
7040 if (status != 0)
7041 goto out;
7042 status = decode_getdevicelist(xdr, res->devlist);
7043out:
7044 return status;
7045}
7046
7047/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007048 * Decode GETDEVINFO response
7049 */
Chuck Leverbf269552010-12-14 14:59:29 +00007050static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7051 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007052 struct nfs4_getdeviceinfo_res *res)
7053{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007054 struct compound_hdr hdr;
7055 int status;
7056
Chuck Leverbf269552010-12-14 14:59:29 +00007057 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007058 if (status != 0)
7059 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007060 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007061 if (status != 0)
7062 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007063 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007064out:
7065 return status;
7066}
7067
7068/*
7069 * Decode LAYOUTGET response
7070 */
Chuck Leverbf269552010-12-14 14:59:29 +00007071static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7072 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007073 struct nfs4_layoutget_res *res)
7074{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007075 struct compound_hdr hdr;
7076 int status;
7077
Chuck Leverbf269552010-12-14 14:59:29 +00007078 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007079 if (status)
7080 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007081 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007082 if (status)
7083 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007084 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007085 if (status)
7086 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007087 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007088out:
7089 return status;
7090}
Andy Adamson863a3c62011-03-23 13:27:54 +00007091
7092/*
Benny Halevycbe82602011-05-22 19:52:37 +03007093 * Decode LAYOUTRETURN response
7094 */
7095static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7096 struct xdr_stream *xdr,
7097 struct nfs4_layoutreturn_res *res)
7098{
7099 struct compound_hdr hdr;
7100 int status;
7101
7102 status = decode_compound_hdr(xdr, &hdr);
7103 if (status)
7104 goto out;
7105 status = decode_sequence(xdr, &res->seq_res, rqstp);
7106 if (status)
7107 goto out;
7108 status = decode_putfh(xdr);
7109 if (status)
7110 goto out;
7111 status = decode_layoutreturn(xdr, res);
7112out:
7113 return status;
7114}
7115
7116/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007117 * Decode LAYOUTCOMMIT response
7118 */
7119static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7120 struct xdr_stream *xdr,
7121 struct nfs4_layoutcommit_res *res)
7122{
7123 struct compound_hdr hdr;
7124 int status;
7125
7126 status = decode_compound_hdr(xdr, &hdr);
7127 if (status)
7128 goto out;
7129 status = decode_sequence(xdr, &res->seq_res, rqstp);
7130 if (status)
7131 goto out;
7132 status = decode_putfh(xdr);
7133 if (status)
7134 goto out;
7135 status = decode_layoutcommit(xdr, rqstp, res);
7136 if (status)
7137 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007138 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007139out:
7140 return status;
7141}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007142
7143/*
7144 * Decode SECINFO_NO_NAME response
7145 */
7146static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7147 struct xdr_stream *xdr,
7148 struct nfs4_secinfo_res *res)
7149{
7150 struct compound_hdr hdr;
7151 int status;
7152
7153 status = decode_compound_hdr(xdr, &hdr);
7154 if (status)
7155 goto out;
7156 status = decode_sequence(xdr, &res->seq_res, rqstp);
7157 if (status)
7158 goto out;
7159 status = decode_putrootfh(xdr);
7160 if (status)
7161 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007162 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007163out:
7164 return status;
7165}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007166
7167/*
7168 * Decode TEST_STATEID response
7169 */
7170static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7171 struct xdr_stream *xdr,
7172 struct nfs41_test_stateid_res *res)
7173{
7174 struct compound_hdr hdr;
7175 int status;
7176
7177 status = decode_compound_hdr(xdr, &hdr);
7178 if (status)
7179 goto out;
7180 status = decode_sequence(xdr, &res->seq_res, rqstp);
7181 if (status)
7182 goto out;
7183 status = decode_test_stateid(xdr, res);
7184out:
7185 return status;
7186}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007187
7188/*
7189 * Decode FREE_STATEID response
7190 */
7191static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7192 struct xdr_stream *xdr,
7193 struct nfs41_free_stateid_res *res)
7194{
7195 struct compound_hdr hdr;
7196 int status;
7197
7198 status = decode_compound_hdr(xdr, &hdr);
7199 if (status)
7200 goto out;
7201 status = decode_sequence(xdr, &res->seq_res, rqstp);
7202 if (status)
7203 goto out;
7204 status = decode_free_stateid(xdr, res);
7205out:
7206 return status;
7207}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007208#endif /* CONFIG_NFS_V4_1 */
7209
Chuck Lever573c4e12010-12-14 14:58:11 +00007210/**
7211 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7212 * the local page cache.
7213 * @xdr: XDR stream where entry resides
7214 * @entry: buffer to fill in with entry data
7215 * @plus: boolean indicating whether this should be a readdirplus entry
7216 *
7217 * Returns zero if successful, otherwise a negative errno value is
7218 * returned.
7219 *
7220 * This function is not invoked during READDIR reply decoding, but
7221 * rather whenever an application invokes the getdents(2) system call
7222 * on a directory already in our cache.
7223 */
7224int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7225 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007226{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007227 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007228 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007229 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007230 __be32 *p = xdr_inline_decode(xdr, 4);
7231 if (unlikely(!p))
7232 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007233 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007234 p = xdr_inline_decode(xdr, 4);
7235 if (unlikely(!p))
7236 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007237 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007238 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007239 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007240 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007241 }
7242
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007243 p = xdr_inline_decode(xdr, 12);
7244 if (unlikely(!p))
7245 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007246 entry->prev_cookie = entry->cookie;
7247 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007248 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007249
Trond Myklebust9af8c222010-10-24 11:52:55 -04007250 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007251 if (unlikely(!p))
7252 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007253 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007254
7255 /*
7256 * In case the server doesn't return an inode number,
7257 * we fake one here. (We don't use inode number 0,
7258 * since glibc seems to choke on it...)
7259 */
7260 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007261 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007262
Trond Myklebust9af8c222010-10-24 11:52:55 -04007263 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007264 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007265
Trond Myklebust256e48b2012-06-21 11:18:13 -04007266 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007267 goto out_overflow;
7268
Chuck Lever573c4e12010-12-14 14:58:11 +00007269 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007270 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007271 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007272 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7273 entry->ino = entry->fattr->mounted_on_fileid;
7274 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007275 entry->ino = entry->fattr->fileid;
7276
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007277 entry->d_type = DT_UNKNOWN;
7278 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7279 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7280
Chuck Lever573c4e12010-12-14 14:58:11 +00007281 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007282
7283out_overflow:
7284 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007285 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007286}
7287
7288/*
7289 * We need to translate between nfs status return values and
7290 * the local errno values which may not be the same.
7291 */
7292static struct {
7293 int stat;
7294 int errno;
7295} nfs_errtbl[] = {
7296 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007297 { NFS4ERR_PERM, -EPERM },
7298 { NFS4ERR_NOENT, -ENOENT },
7299 { NFS4ERR_IO, -errno_NFSERR_IO},
7300 { NFS4ERR_NXIO, -ENXIO },
7301 { NFS4ERR_ACCESS, -EACCES },
7302 { NFS4ERR_EXIST, -EEXIST },
7303 { NFS4ERR_XDEV, -EXDEV },
7304 { NFS4ERR_NOTDIR, -ENOTDIR },
7305 { NFS4ERR_ISDIR, -EISDIR },
7306 { NFS4ERR_INVAL, -EINVAL },
7307 { NFS4ERR_FBIG, -EFBIG },
7308 { NFS4ERR_NOSPC, -ENOSPC },
7309 { NFS4ERR_ROFS, -EROFS },
7310 { NFS4ERR_MLINK, -EMLINK },
7311 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7312 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7313 { NFS4ERR_DQUOT, -EDQUOT },
7314 { NFS4ERR_STALE, -ESTALE },
7315 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007316 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7317 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7318 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007319 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007320 { NFS4ERR_BADTYPE, -EBADTYPE },
7321 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007322 { NFS4ERR_SYMLINK, -ELOOP },
7323 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7324 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007325 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007326};
7327
7328/*
7329 * Convert an NFS error code to a local one.
7330 * This one is used jointly by NFSv2 and NFSv3.
7331 */
7332static int
David Howells0a8ea432006-08-22 20:06:08 -04007333nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007334{
7335 int i;
7336 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7337 if (nfs_errtbl[i].stat == stat)
7338 return nfs_errtbl[i].errno;
7339 }
7340 if (stat <= 10000 || stat > 10100) {
7341 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007342 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007343 }
7344 /* If we cannot translate the error, the recovery routines should
7345 * handle it.
7346 * Note: remaining NFSv4 error codes have values > 10000, so should
7347 * not conflict with native Linux error codes.
7348 */
Benny Halevy856dff32008-03-31 17:39:06 +03007349 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007350}
7351
Linus Torvalds1da177e2005-04-16 15:20:36 -07007352#define PROC(proc, argtype, restype) \
7353[NFSPROC4_CLNT_##proc] = { \
7354 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007355 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007356 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007357 .p_arglen = NFS4_##argtype##_sz, \
7358 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007359 .p_statidx = NFSPROC4_CLNT_##proc, \
7360 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007361}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007362
7363struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007364 PROC(READ, enc_read, dec_read),
7365 PROC(WRITE, enc_write, dec_write),
7366 PROC(COMMIT, enc_commit, dec_commit),
7367 PROC(OPEN, enc_open, dec_open),
7368 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7369 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7370 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7371 PROC(CLOSE, enc_close, dec_close),
7372 PROC(SETATTR, enc_setattr, dec_setattr),
7373 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7374 PROC(RENEW, enc_renew, dec_renew),
7375 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7376 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7377 PROC(LOCK, enc_lock, dec_lock),
7378 PROC(LOCKT, enc_lockt, dec_lockt),
7379 PROC(LOCKU, enc_locku, dec_locku),
7380 PROC(ACCESS, enc_access, dec_access),
7381 PROC(GETATTR, enc_getattr, dec_getattr),
7382 PROC(LOOKUP, enc_lookup, dec_lookup),
7383 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7384 PROC(REMOVE, enc_remove, dec_remove),
7385 PROC(RENAME, enc_rename, dec_rename),
7386 PROC(LINK, enc_link, dec_link),
7387 PROC(SYMLINK, enc_symlink, dec_symlink),
7388 PROC(CREATE, enc_create, dec_create),
7389 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7390 PROC(STATFS, enc_statfs, dec_statfs),
7391 PROC(READLINK, enc_readlink, dec_readlink),
7392 PROC(READDIR, enc_readdir, dec_readdir),
7393 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7394 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7395 PROC(GETACL, enc_getacl, dec_getacl),
7396 PROC(SETACL, enc_setacl, dec_setacl),
7397 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7398 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007399 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007400#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007401 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7402 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7403 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7404 PROC(SEQUENCE, enc_sequence, dec_sequence),
7405 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7406 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7407 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7408 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007409 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007410 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007411 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007412 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007413 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007414 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007415 PROC(BIND_CONN_TO_SESSION,
7416 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007417 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007418#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007419};
7420
Trond Myklebusta613fa12012-01-20 13:53:56 -05007421const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007422 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007423 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007424 .procs = nfs4_procedures
7425};
7426
7427/*
7428 * Local variables:
7429 * c-basic-offset: 8
7430 * End:
7431 */