blob: cb5f94640be65c99fda15322f9447caeea3ab788 [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 */ + \
297 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500298 1 /* implementation id array of size 1 */ + \
299 1 /* nii_domain */ + \
300 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
301 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500302 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500303 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400304#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
305 2 /* eir_clientid */ + \
306 1 /* eir_sequenceid */ + \
307 1 /* eir_flags */ + \
308 1 /* spr_how */ + \
309 0 /* SP4_NONE (for now) */ + \
310 2 /* eir_server_owner.so_minor_id */ + \
311 /* eir_server_owner.so_major_id<> */ \
312 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
313 /* eir_server_scope<> */ \
314 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
315 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500316 1 /* nii_domain */ + \
317 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
318 1 /* nii_name */ + \
319 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
320 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400321#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
322#define decode_channel_attrs_maxsz (6 + \
323 1 /* ca_rdma_ird.len */ + \
324 1 /* ca_rdma_ird */)
325#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
326 2 /* csa_clientid */ + \
327 1 /* csa_sequence */ + \
328 1 /* csa_flags */ + \
329 encode_channel_attrs_maxsz + \
330 encode_channel_attrs_maxsz + \
331 1 /* csa_cb_program */ + \
332 1 /* csa_sec_parms.len (1) */ + \
333 1 /* cb_secflavor (AUTH_SYS) */ + \
334 1 /* stamp */ + \
335 1 /* machinename.len */ + \
336 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
337 1 /* uid */ + \
338 1 /* gid */ + \
339 1 /* gids.len (0) */)
340#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
341 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
342 1 /* csr_sequence */ + \
343 1 /* csr_flags */ + \
344 decode_channel_attrs_maxsz + \
345 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400346#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
347 /* bctsa_sessid */ \
348 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
349 1 /* bctsa_dir */ + \
350 1 /* bctsa_use_conn_in_rdma_mode */)
351#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
352 /* bctsr_sessid */ \
353 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
354 1 /* bctsr_dir */ + \
355 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400356#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
357#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400358#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
359#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400360#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
361 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
362#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
363 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500364#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
365#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400366#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
367 encode_verifier_maxsz)
368#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
369 2 /* nfs_cookie4 gdlr_cookie */ + \
370 decode_verifier_maxsz \
371 /* verifier4 gdlr_verifier */ + \
372 1 /* gdlr_deviceid_list count */ + \
373 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
374 NFS4_DEVICEID4_SIZE) \
375 /* gdlr_deviceid_list */ + \
376 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400377#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
378 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
379#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
380 1 /* layout type */ + \
381 1 /* opaque devaddr4 length */ + \
382 /* devaddr4 payload is read into page */ \
383 1 /* notification bitmap length */ + \
384 1 /* notification bitmap */)
385#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
386 encode_stateid_maxsz)
387#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
388 decode_stateid_maxsz + \
389 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000390#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
391 2 /* offset */ + \
392 2 /* length */ + \
393 1 /* reclaim */ + \
394 encode_stateid_maxsz + \
395 1 /* new offset (true) */ + \
396 2 /* last byte written */ + \
397 1 /* nt_timechanged (false) */ + \
398 1 /* layoutupdate4 layout type */ + \
399 1 /* NULL filelayout layoutupdate4 payload */)
400#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300401#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
402 encode_stateid_maxsz + \
403 1 /* FIXME: opaque lrf_body always empty at the moment */)
404#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
405 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400406#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
407#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400408#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
409 XDR_QUADLEN(NFS4_STATEID_SIZE))
410#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400411#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
412 XDR_QUADLEN(NFS4_STATEID_SIZE))
413#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400414#else /* CONFIG_NFS_V4_1 */
415#define encode_sequence_maxsz 0
416#define decode_sequence_maxsz 0
417#endif /* CONFIG_NFS_V4_1 */
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
420#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
421#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400432 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400444 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400448 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400449 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400453 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400454 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400458 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400462 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400466 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400467 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400468 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400469 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400474 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400475 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400477#define NFS4_enc_open_confirm_sz \
478 (compound_encode_hdr_maxsz + \
479 encode_putfh_maxsz + \
480 encode_open_confirm_maxsz)
481#define NFS4_dec_open_confirm_sz \
482 (compound_decode_hdr_maxsz + \
483 decode_putfh_maxsz + \
484 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400486 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400488 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400489 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400490 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400495 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400496 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497#define NFS4_enc_open_downgrade_sz \
498 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400499 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400500 encode_putfh_maxsz + \
501 encode_open_downgrade_maxsz + \
502 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#define NFS4_dec_open_downgrade_sz \
504 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400505 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400506 decode_putfh_maxsz + \
507 decode_open_downgrade_maxsz + \
508 decode_getattr_maxsz)
509#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400510 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400511 encode_putfh_maxsz + \
512 encode_close_maxsz + \
513 encode_getattr_maxsz)
514#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400515 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400516 decode_putfh_maxsz + \
517 decode_close_maxsz + \
518 decode_getattr_maxsz)
519#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400521 encode_putfh_maxsz + \
522 encode_setattr_maxsz + \
523 encode_getattr_maxsz)
524#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400525 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400526 decode_putfh_maxsz + \
527 decode_setattr_maxsz + \
528 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 encode_putfh_maxsz + \
532 encode_fsinfo_maxsz)
533#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 decode_putfh_maxsz + \
536 decode_fsinfo_maxsz)
537#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
538 encode_renew_maxsz)
539#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
540 decode_renew_maxsz)
541#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
542 encode_setclientid_maxsz)
543#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
544 decode_setclientid_maxsz)
545#define NFS4_enc_setclientid_confirm_sz \
546 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400547 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#define NFS4_dec_setclientid_confirm_sz \
549 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400550 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400552 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400554 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400558 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400562 encode_lockt_maxsz)
563#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400565 decode_putfh_maxsz + \
566 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400570 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400574 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400575#define NFS4_enc_release_lockowner_sz \
576 (compound_encode_hdr_maxsz + \
577 encode_lockowner_maxsz)
578#define NFS4_dec_release_lockowner_sz \
579 (compound_decode_hdr_maxsz + \
580 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400584 encode_access_maxsz + \
585 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400587 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400589 decode_access_maxsz + \
590 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 encode_putfh_maxsz + \
594 encode_getattr_maxsz)
595#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 decode_putfh_maxsz + \
598 decode_getattr_maxsz)
599#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 encode_putfh_maxsz + \
602 encode_lookup_maxsz + \
603 encode_getattr_maxsz + \
604 encode_getfh_maxsz)
605#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400608 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 decode_getattr_maxsz + \
610 decode_getfh_maxsz)
611#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400612 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 encode_putrootfh_maxsz + \
614 encode_getattr_maxsz + \
615 encode_getfh_maxsz)
616#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400617 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 decode_putrootfh_maxsz + \
619 decode_getattr_maxsz + \
620 decode_getfh_maxsz)
621#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400624 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400628 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 encode_putfh_maxsz + \
632 encode_savefh_maxsz + \
633 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400634 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 decode_putfh_maxsz + \
638 decode_savefh_maxsz + \
639 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400640 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
644 encode_savefh_maxsz + \
645 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400646 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400647 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400648 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_putfh_maxsz + \
652 decode_savefh_maxsz + \
653 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400654 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400655 decode_restorefh_maxsz + \
656 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400658 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_putfh_maxsz + \
660 encode_symlink_maxsz + \
661 encode_getattr_maxsz + \
662 encode_getfh_maxsz)
663#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 decode_putfh_maxsz + \
666 decode_symlink_maxsz + \
667 decode_getattr_maxsz + \
668 decode_getfh_maxsz)
669#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400670 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 encode_putfh_maxsz + \
672 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400673 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400674 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400679 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400680 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400682 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 encode_putfh_maxsz + \
684 encode_getattr_maxsz)
685#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400686 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 decode_putfh_maxsz + \
688 decode_getattr_maxsz)
689#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400692 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400696 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800699 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 encode_getattr_maxsz)
701#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800703 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 decode_getattr_maxsz)
705#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100708 encode_delegreturn_maxsz + \
709 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400711 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100712 decode_delegreturn_maxsz + \
713 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000714#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400715 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000716 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400717 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000718#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400719 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000720 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400721 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000722#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400723 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000724 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400725 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000726#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400727 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000728 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400729 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400730#define NFS4_enc_fs_locations_sz \
731 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400732 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400733 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400734 encode_lookup_maxsz + \
735 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400736#define NFS4_dec_fs_locations_sz \
737 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400738 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400739 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400740 decode_lookup_maxsz + \
741 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000742#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
743 encode_sequence_maxsz + \
744 encode_putfh_maxsz + \
745 encode_secinfo_maxsz)
746#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
747 decode_sequence_maxsz + \
748 decode_putfh_maxsz + \
749 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400750#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400751#define NFS4_enc_bind_conn_to_session_sz \
752 (compound_encode_hdr_maxsz + \
753 encode_bind_conn_to_session_maxsz)
754#define NFS4_dec_bind_conn_to_session_sz \
755 (compound_decode_hdr_maxsz + \
756 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400757#define NFS4_enc_exchange_id_sz \
758 (compound_encode_hdr_maxsz + \
759 encode_exchange_id_maxsz)
760#define NFS4_dec_exchange_id_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400763#define NFS4_enc_create_session_sz \
764 (compound_encode_hdr_maxsz + \
765 encode_create_session_maxsz)
766#define NFS4_dec_create_session_sz \
767 (compound_decode_hdr_maxsz + \
768 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400769#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
770 encode_destroy_session_maxsz)
771#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
772 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400773#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
774 encode_destroy_clientid_maxsz)
775#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
776 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400777#define NFS4_enc_sequence_sz \
778 (compound_decode_hdr_maxsz + \
779 encode_sequence_maxsz)
780#define NFS4_dec_sequence_sz \
781 (compound_decode_hdr_maxsz + \
782 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400783#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
784 encode_sequence_maxsz + \
785 encode_putrootfh_maxsz + \
786 encode_fsinfo_maxsz)
787#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
788 decode_sequence_maxsz + \
789 decode_putrootfh_maxsz + \
790 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500791#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_reclaim_complete_maxsz)
794#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
795 decode_sequence_maxsz + \
796 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400797#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_putfh_maxsz + \
800 encode_getdevicelist_maxsz)
801#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_putfh_maxsz + \
804 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400805#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz +\
807 encode_getdeviceinfo_maxsz)
808#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
809 decode_sequence_maxsz + \
810 decode_getdeviceinfo_maxsz)
811#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
812 encode_sequence_maxsz + \
813 encode_putfh_maxsz + \
814 encode_layoutget_maxsz)
815#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
816 decode_sequence_maxsz + \
817 decode_putfh_maxsz + \
818 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000819#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz +\
821 encode_putfh_maxsz + \
822 encode_layoutcommit_maxsz + \
823 encode_getattr_maxsz)
824#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
825 decode_sequence_maxsz + \
826 decode_putfh_maxsz + \
827 decode_layoutcommit_maxsz + \
828 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300829#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
830 encode_sequence_maxsz + \
831 encode_putfh_maxsz + \
832 encode_layoutreturn_maxsz)
833#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
834 decode_sequence_maxsz + \
835 decode_putfh_maxsz + \
836 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400837#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
838 encode_sequence_maxsz + \
839 encode_putrootfh_maxsz +\
840 encode_secinfo_no_name_maxsz)
841#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
842 decode_sequence_maxsz + \
843 decode_putrootfh_maxsz + \
844 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400845#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
846 encode_sequence_maxsz + \
847 encode_test_stateid_maxsz)
848#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
849 decode_sequence_maxsz + \
850 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400851#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
852 encode_sequence_maxsz + \
853 encode_free_stateid_maxsz)
854#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
855 decode_sequence_maxsz + \
856 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500857
858const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
859 compound_encode_hdr_maxsz +
860 encode_sequence_maxsz +
861 encode_putfh_maxsz +
862 encode_getattr_maxsz) *
863 XDR_UNIT);
864
865const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
866 compound_decode_hdr_maxsz +
867 decode_sequence_maxsz +
868 decode_putfh_maxsz) *
869 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400870
871const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
872 compound_decode_hdr_maxsz +
873 decode_sequence_maxsz) *
874 XDR_UNIT);
875EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400876#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Trond Myklebustbca79472009-03-11 14:10:26 -0400878static const umode_t nfs_type2fmt[] = {
879 [NF4BAD] = 0,
880 [NF4REG] = S_IFREG,
881 [NF4DIR] = S_IFDIR,
882 [NF4BLK] = S_IFBLK,
883 [NF4CHR] = S_IFCHR,
884 [NF4LNK] = S_IFLNK,
885 [NF4SOCK] = S_IFSOCK,
886 [NF4FIFO] = S_IFIFO,
887 [NF4ATTRDIR] = 0,
888 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889};
890
891struct compound_hdr {
892 int32_t status;
893 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500894 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 uint32_t taglen;
896 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400897 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400898 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899};
900
Benny Halevy13c65ce2009-08-14 17:19:25 +0300901static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
902{
903 __be32 *p = xdr_reserve_space(xdr, nbytes);
904 BUG_ON(!p);
905 return p;
906}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Trond Myklebustcb17e552012-03-04 18:13:56 -0500908static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
909{
910 __be32 *p;
911
912 p = xdr_reserve_space(xdr, len);
913 xdr_encode_opaque_fixed(p, buf, len);
914}
915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
917{
Al Viro8687b632006-10-19 23:28:48 -0700918 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500920 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 xdr_encode_opaque(p, str, len);
922}
923
Trond Myklebust4ade9822012-03-04 18:13:57 -0500924static void encode_uint32(struct xdr_stream *xdr, u32 n)
925{
926 __be32 *p;
927
928 p = reserve_space(xdr, 4);
929 *p = cpu_to_be32(n);
930}
931
Trond Myklebustff2eb682012-03-05 11:40:12 -0500932static void encode_uint64(struct xdr_stream *xdr, u64 n)
933{
934 __be32 *p;
935
936 p = reserve_space(xdr, 8);
937 xdr_encode_hyper(p, n);
938}
939
Trond Myklebust4ade9822012-03-04 18:13:57 -0500940static void encode_nfs4_seqid(struct xdr_stream *xdr,
941 const struct nfs_seqid *seqid)
942{
943 encode_uint32(xdr, seqid->sequence->counter);
944}
945
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400946static void encode_compound_hdr(struct xdr_stream *xdr,
947 struct rpc_rqst *req,
948 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949{
Al Viro8687b632006-10-19 23:28:48 -0700950 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400951 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400952
953 /* initialize running count of expected bytes in reply.
954 * NOTE: the replied tag SHOULD be the same is the one sent,
955 * but this is not required as a MUST for the server to do so. */
956 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Trond Myklebust7fc38842012-10-15 11:51:21 -0400958 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500959 encode_string(xdr, hdr->taglen, hdr->tag);
960 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300961 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500962 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300963 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500964}
965
Trond Myklebustab19b482012-03-04 18:13:57 -0500966static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
967 uint32_t replen,
968 struct compound_hdr *hdr)
969{
970 encode_uint32(xdr, op);
971 hdr->nops++;
972 hdr->replen += replen;
973}
974
Andy Adamsond0179312008-12-23 16:06:17 -0500975static void encode_nops(struct compound_hdr *hdr)
976{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400977 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500978 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979}
980
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500981static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
982{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500983 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500984}
985
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
987{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500988 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
David Quigleyaa9c2662013-05-22 12:50:44 -0400991static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
992 const struct nfs4_label *label,
993 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
995 char owner_name[IDMAP_NAMESZ];
996 char owner_group[IDMAP_NAMESZ];
997 int owner_namelen = 0;
998 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700999 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001000 unsigned i;
1001 uint32_t len = 0;
1002 uint32_t bmval_len;
1003 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 /*
1006 * We reserve enough space to write the entire attribute buffer at once.
1007 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001008 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1009 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001010 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001012 if (iap->ia_valid & ATTR_SIZE) {
1013 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001015 }
1016 if (iap->ia_valid & ATTR_MODE) {
1017 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001019 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001021 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001023 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001024 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 /* XXX */
1026 strcpy(owner_name, "nobody");
1027 owner_namelen = sizeof("nobody") - 1;
1028 /* goto out; */
1029 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001030 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1032 }
1033 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001034 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001036 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001037 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 strcpy(owner_group, "nobody");
1039 owner_grouplen = sizeof("nobody") - 1;
1040 /* goto out; */
1041 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001042 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1044 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001046 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1047 len += 16;
1048 } else if (iap->ia_valid & ATTR_ATIME) {
1049 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1050 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 }
1052 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001053 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1054 len += 16;
1055 } else if (iap->ia_valid & ATTR_MTIME) {
1056 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1057 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001059 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001060 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1061 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1062 }
1063
1064 if (bmval[2] != 0)
1065 bmval_len = 3;
1066 else if (bmval[1] != 0)
1067 bmval_len = 2;
1068 else
1069 bmval_len = 1;
1070
1071 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1072
1073 *p++ = cpu_to_be32(bmval_len);
1074 for (i = 0; i < bmval_len; i++)
1075 *p++ = cpu_to_be32(bmval[i]);
1076 *p++ = cpu_to_be32(len);
1077
1078 if (bmval[0] & FATTR4_WORD0_SIZE)
1079 p = xdr_encode_hyper(p, iap->ia_size);
1080 if (bmval[1] & FATTR4_WORD1_MODE)
1081 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1082 if (bmval[1] & FATTR4_WORD1_OWNER)
1083 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1084 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1085 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1086 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1087 if (iap->ia_valid & ATTR_ATIME_SET) {
1088 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1089 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1090 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1091 } else
1092 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1093 }
1094 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1095 if (iap->ia_valid & ATTR_MTIME_SET) {
1096 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1097 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1098 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1099 } else
1100 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1101 }
1102 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001103 *p++ = cpu_to_be32(label->lfs);
1104 *p++ = cpu_to_be32(label->pi);
1105 *p++ = cpu_to_be32(label->len);
1106 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1107 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110}
1111
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001112static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001114 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1115 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001118static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Trond Myklebustab19b482012-03-04 18:13:57 -05001120 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001121 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001122 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123}
1124
Fred Isaman0b7c0152012-04-20 14:47:39 -04001125static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126{
Al Viro8687b632006-10-19 23:28:48 -07001127 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001128
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001129 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1130 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001131 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001132 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133}
1134
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001135static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
Al Viro8687b632006-10-19 23:28:48 -07001137 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001138
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001139 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1140 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
1142 switch (create->ftype) {
1143 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001144 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001145 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001146 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 break;
1148
1149 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001150 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001151 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001152 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 break;
1154
1155 default:
1156 break;
1157 }
1158
Benny Halevy811652b2009-08-14 17:19:34 +03001159 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001160 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161}
1162
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001163static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164{
Andy Adamson05d564f2008-12-23 16:06:15 -05001165 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001167 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1168 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001169 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001170 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171}
1172
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001173static 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 -07001174{
Andy Adamson05d564f2008-12-23 16:06:15 -05001175 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001177 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1178 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001179 *p++ = cpu_to_be32(2);
1180 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001181 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182}
1183
Fred Isamandae100c2011-07-30 20:52:37 -04001184static void
1185encode_getattr_three(struct xdr_stream *xdr,
1186 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1187 struct compound_hdr *hdr)
1188{
1189 __be32 *p;
1190
Trond Myklebustab19b482012-03-04 18:13:57 -05001191 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001192 if (bm2) {
1193 p = reserve_space(xdr, 16);
1194 *p++ = cpu_to_be32(3);
1195 *p++ = cpu_to_be32(bm0);
1196 *p++ = cpu_to_be32(bm1);
1197 *p = cpu_to_be32(bm2);
1198 } else if (bm1) {
1199 p = reserve_space(xdr, 12);
1200 *p++ = cpu_to_be32(2);
1201 *p++ = cpu_to_be32(bm0);
1202 *p = cpu_to_be32(bm1);
1203 } else {
1204 p = reserve_space(xdr, 8);
1205 *p++ = cpu_to_be32(1);
1206 *p = cpu_to_be32(bm0);
1207 }
Fred Isamandae100c2011-07-30 20:52:37 -04001208}
1209
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001210static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211{
David Quigleya09df2c2013-05-22 12:50:41 -04001212 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1213 bitmask[1] & nfs4_fattr_bitmap[1],
1214 bitmask[2] & nfs4_fattr_bitmap[2],
1215 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216}
1217
Andy Adamson88034c32012-05-23 05:02:34 -04001218static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001219 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001220 struct compound_hdr *hdr)
1221{
1222 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001223 bitmask[0] & open_bitmap[0],
1224 bitmask[1] & open_bitmap[1],
1225 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001226 hdr);
1227}
1228
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001229static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
Fred Isamandae100c2011-07-30 20:52:37 -04001231 encode_getattr_three(xdr,
1232 bitmask[0] & nfs4_fsinfo_bitmap[0],
1233 bitmask[1] & nfs4_fsinfo_bitmap[1],
1234 bitmask[2] & nfs4_fsinfo_bitmap[2],
1235 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236}
1237
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001238static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001239{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001240 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1241 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001242}
1243
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001244static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
Trond Myklebustab19b482012-03-04 18:13:57 -05001246 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247}
1248
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001249static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250{
Trond Myklebustab19b482012-03-04 18:13:57 -05001251 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001252 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253}
1254
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001255static inline int nfs4_lock_type(struct file_lock *fl, int block)
1256{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001257 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001258 return block ? NFS4_READW_LT : NFS4_READ_LT;
1259 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1260}
1261
1262static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1263{
1264 if (fl->fl_end == OFFSET_MAX)
1265 return ~(uint64_t)0;
1266 return fl->fl_end - fl->fl_start + 1;
1267}
1268
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001269static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1270{
1271 __be32 *p;
1272
Trond Myklebustd035c362010-12-21 10:45:27 -05001273 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001274 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001275 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001276 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001277 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001278 xdr_encode_hyper(p, lowner->id);
1279}
1280
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281/*
1282 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1283 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1284 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001285static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
Al Viro8687b632006-10-19 23:28:48 -07001287 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001289 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1290 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001291 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1292 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001293 p = xdr_encode_hyper(p, args->fl->fl_start);
1294 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001295 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001296 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001297 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001298 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001299 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001300 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 }
1302 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001303 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001304 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306}
1307
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001308static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309{
Al Viro8687b632006-10-19 23:28:48 -07001310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001312 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1313 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001314 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001315 p = xdr_encode_hyper(p, args->fl->fl_start);
1316 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001317 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
1319
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001320static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321{
Al Viro8687b632006-10-19 23:28:48 -07001322 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001324 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1325 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001326 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001327 encode_nfs4_stateid(xdr, args->stateid);
1328 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001329 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001330 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001333static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1334{
Trond Myklebustab19b482012-03-04 18:13:57 -05001335 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001336 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001337}
1338
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001339static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
Trond Myklebustab19b482012-03-04 18:13:57 -05001341 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001342 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343}
1344
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001345static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
Al Viro8687b632006-10-19 23:28:48 -07001347 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Benny Halevy13c65ce2009-08-14 17:19:25 +03001349 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001350 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001351 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001352 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001353 break;
1354 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001355 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001356 break;
1357 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001358 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001359 break;
1360 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001361 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 }
Benny Halevy34558512009-08-14 17:19:30 +03001363 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364}
1365
1366static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1367{
Al Viro8687b632006-10-19 23:28:48 -07001368 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 /*
1370 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1371 * owner 4 = 32
1372 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001373 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001374 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001375 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001376 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001377 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001378 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001379 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001380 *p++ = cpu_to_be32(arg->id.uniquifier);
1381 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
1384static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1385{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001386 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001387 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Benny Halevy13c65ce2009-08-14 17:19:25 +03001389 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001390 switch(arg->createmode) {
1391 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001392 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001393 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001394 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001395 case NFS4_CREATE_GUARDED:
1396 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001397 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001398 break;
1399 case NFS4_CREATE_EXCLUSIVE:
1400 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1401 encode_nfs4_verifier(xdr, &arg->u.verifier);
1402 break;
1403 case NFS4_CREATE_EXCLUSIVE4_1:
1404 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1405 encode_nfs4_verifier(xdr, &arg->u.verifier);
1406 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001407 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 }
1409}
1410
1411static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1412{
Al Viro8687b632006-10-19 23:28:48 -07001413 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Benny Halevy13c65ce2009-08-14 17:19:25 +03001415 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001417 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001418 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001419 break;
1420 default:
Benny Halevy34558512009-08-14 17:19:30 +03001421 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001422 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 }
1424}
1425
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001426static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
Al Viro8687b632006-10-19 23:28:48 -07001428 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Benny Halevy13c65ce2009-08-14 17:19:25 +03001430 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001432 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001433 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001434 break;
1435 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001436 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001437 break;
1438 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001439 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001440 break;
1441 default:
1442 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 }
1444}
1445
1446static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1447{
Al Viro8687b632006-10-19 23:28:48 -07001448 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
Benny Halevy13c65ce2009-08-14 17:19:25 +03001450 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001451 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 encode_string(xdr, name->len, name->name);
1453}
1454
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001455static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456{
Al Viro8687b632006-10-19 23:28:48 -07001457 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Benny Halevy13c65ce2009-08-14 17:19:25 +03001459 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001460 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 encode_delegation_type(xdr, type);
1462}
1463
1464static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1465{
Al Viro8687b632006-10-19 23:28:48 -07001466 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001468 p = reserve_space(xdr, 4);
1469 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1470 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 encode_string(xdr, name->len, name->name);
1472}
1473
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001474static inline void encode_claim_fh(struct xdr_stream *xdr)
1475{
1476 __be32 *p;
1477
1478 p = reserve_space(xdr, 4);
1479 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1480}
1481
1482static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1483{
1484 __be32 *p;
1485
1486 p = reserve_space(xdr, 4);
1487 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1488 encode_nfs4_stateid(xdr, stateid);
1489}
1490
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001491static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492{
Trond Myklebustab19b482012-03-04 18:13:57 -05001493 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 encode_openhdr(xdr, arg);
1495 encode_opentype(xdr, arg);
1496 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001497 case NFS4_OPEN_CLAIM_NULL:
1498 encode_claim_null(xdr, arg->name);
1499 break;
1500 case NFS4_OPEN_CLAIM_PREVIOUS:
1501 encode_claim_previous(xdr, arg->u.delegation_type);
1502 break;
1503 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1504 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1505 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001506 case NFS4_OPEN_CLAIM_FH:
1507 encode_claim_fh(xdr);
1508 break;
1509 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1510 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1511 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001512 default:
1513 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515}
1516
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001517static 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 -07001518{
Trond Myklebustab19b482012-03-04 18:13:57 -05001519 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001520 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001521 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522}
1523
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001524static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
Trond Myklebustab19b482012-03-04 18:13:57 -05001526 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001527 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001528 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001529 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001532static void
Andy Adamsond0179312008-12-23 16:06:17 -05001533encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534{
Trond Myklebustab19b482012-03-04 18:13:57 -05001535 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001536 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537}
1538
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001539static void encode_putrootfh(struct xdr_stream *xdr, 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_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542}
1543
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001544static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
Al Viro8687b632006-10-19 23:28:48 -07001546 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Trond Myklebustab19b482012-03-04 18:13:57 -05001548 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001549 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Benny Halevy13c65ce2009-08-14 17:19:25 +03001551 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001552 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001553 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001556static 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 -07001557{
David Quigleyaa9c2662013-05-22 12:50:44 -04001558 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001559 FATTR4_WORD0_RDATTR_ERROR,
1560 FATTR4_WORD1_MOUNTED_ON_FILEID,
1561 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001562 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001563 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001565 if (readdir->plus) {
1566 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001567 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001568 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1569 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1570 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1571 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001572 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001573 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001574 /* Use mounted_on_fileid only if the server supports it */
1575 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1576 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001577
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001578 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001579 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001580 encode_nfs4_verifier(xdr, &readdir->verifier);
David Quigleyaa9c2662013-05-22 12:50:44 -04001581 p = reserve_space(xdr, encode_readdir_space);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001582 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001583 *p++ = cpu_to_be32(readdir->count);
David Quigleyaa9c2662013-05-22 12:50:44 -04001584 *p++ = cpu_to_be32(encode_readdir_bitmask_sz);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001585 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
David Quigleyaa9c2662013-05-22 12:50:44 -04001586 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1587 if (encode_readdir_bitmask_sz > 2) {
1588 if (hdr->minorversion > 1)
1589 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1590 p++, *p++ = cpu_to_be32(attrs[2] & readdir->bitmask[2]);
1591 }
Chuck Levercd937102012-03-02 17:14:31 -05001592 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001593
1594 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001595 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001596 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001597 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001598 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001599 attrs[1] & readdir->bitmask[1],
1600 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601}
1602
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001603static 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 -07001604{
Trond Myklebustab19b482012-03-04 18:13:57 -05001605 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606}
1607
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001608static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609{
Trond Myklebustab19b482012-03-04 18:13:57 -05001610 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001611 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612}
1613
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614static 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 -07001615{
Trond Myklebustab19b482012-03-04 18:13:57 -05001616 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001617 encode_string(xdr, oldname->len, oldname->name);
1618 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619}
1620
Chuck Leverbb4dae52012-03-01 17:01:48 -05001621static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1622 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001624 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001625 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626}
1627
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001628static void
Andy Adamsond0179312008-12-23 16:06:17 -05001629encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001630{
Trond Myklebustab19b482012-03-04 18:13:57 -05001631 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001632}
1633
Chuck Lever9f06c712010-12-14 14:59:18 +00001634static void
Andy Adamsond0179312008-12-23 16:06:17 -05001635encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001636{
Al Viro8687b632006-10-19 23:28:48 -07001637 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001638
Trond Myklebustab19b482012-03-04 18:13:57 -05001639 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001640 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001641 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001642 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001643 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001644 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001645 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001646 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001647}
1648
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001649static void
Andy Adamsond0179312008-12-23 16:06:17 -05001650encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651{
Trond Myklebustab19b482012-03-04 18:13:57 -05001652 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
1654
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001655static 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 -07001656{
Trond Myklebustab19b482012-03-04 18:13:57 -05001657 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001658 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001659 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660}
1661
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001662static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663{
Al Viro8687b632006-10-19 23:28:48 -07001664 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
Trond Myklebust70019512012-03-04 20:49:32 -05001666 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001667 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
1669 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001670 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001671 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1673 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001674 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001675 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676}
1677
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001678static 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 -07001679{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001680 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1681 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001682 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001683 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684}
1685
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001686static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687{
Al Viro8687b632006-10-19 23:28:48 -07001688 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Trond Myklebustab19b482012-03-04 18:13:57 -05001690 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001691 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Benny Halevy13c65ce2009-08-14 17:19:25 +03001693 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001694 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001695 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001696 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
1698 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699}
1700
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001701static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702{
Trond Myklebustab19b482012-03-04 18:13:57 -05001703 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001704 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001706
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001707static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1708{
Trond Myklebustab19b482012-03-04 18:13:57 -05001709 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001710 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001711}
1712
Benny Halevy99fe60d2009-04-01 09:22:29 -04001713#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001714/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001715static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1716 struct nfs4_session *session,
1717 struct compound_hdr *hdr)
1718{
1719 __be32 *p;
1720
1721 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1722 decode_bind_conn_to_session_maxsz, hdr);
1723 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1724 p = xdr_reserve_space(xdr, 8);
1725 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1726 *p = 0; /* use_conn_in_rdma_mode = False */
1727}
1728
Benny Halevy99fe60d2009-04-01 09:22:29 -04001729static void encode_exchange_id(struct xdr_stream *xdr,
1730 struct nfs41_exchange_id_args *args,
1731 struct compound_hdr *hdr)
1732{
1733 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001734 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001735 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001736
Trond Myklebust70019512012-03-04 20:49:32 -05001737 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001738 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001739
1740 encode_string(xdr, args->id_len, args->id);
1741
Benny Halevy13c65ce2009-08-14 17:19:25 +03001742 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001743 *p++ = cpu_to_be32(args->flags);
1744 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001745
1746 if (send_implementation_id &&
1747 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1748 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001749 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001750 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1751 utsname()->sysname, utsname()->release,
1752 utsname()->version, utsname()->machine);
1753
1754 if (len > 0) {
1755 *p = cpu_to_be32(1); /* implementation id array length=1 */
1756
1757 encode_string(xdr,
1758 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1759 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1760 encode_string(xdr, len, impl_name);
1761 /* just send zeros for nii_date - the date is in nii_name */
1762 p = reserve_space(xdr, 12);
1763 p = xdr_encode_hyper(p, 0);
1764 *p = cpu_to_be32(0);
1765 } else
1766 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001767}
Andy Adamsonfc931582009-04-01 09:22:31 -04001768
1769static void encode_create_session(struct xdr_stream *xdr,
1770 struct nfs41_create_session_args *args,
1771 struct compound_hdr *hdr)
1772{
1773 __be32 *p;
1774 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1775 uint32_t len;
1776 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001777 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001778 u32 max_resp_sz_cached;
1779
1780 /*
1781 * Assumes OPEN is the biggest non-idempotent compound.
1782 * 2 is the verifier.
1783 */
1784 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1785 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001786
Andy Adamsonfc931582009-04-01 09:22:31 -04001787 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1788 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001789
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001790 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1791 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001792 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001793 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1794 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001795
Andy Adamsonfc931582009-04-01 09:22:31 -04001796 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001797 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001798 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1799 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001800 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001801 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1802 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1803 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001804
1805 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001806 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001807 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1808 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1809 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1810 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1811 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1812 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001813
Benny Halevye75bc1c2009-08-14 17:18:54 +03001814 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001815 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001816 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001817
1818 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001819 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001820 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001821 *p++ = cpu_to_be32(0); /* UID */
1822 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001823 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001824}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001825
1826static void encode_destroy_session(struct xdr_stream *xdr,
1827 struct nfs4_session *session,
1828 struct compound_hdr *hdr)
1829{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001830 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1831 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001832}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001833
Trond Myklebust66245532012-05-25 17:18:09 -04001834static void encode_destroy_clientid(struct xdr_stream *xdr,
1835 uint64_t clientid,
1836 struct compound_hdr *hdr)
1837{
1838 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1839 encode_uint64(xdr, clientid);
1840}
1841
Ricardo Labiaga180197532009-12-05 16:08:40 -05001842static void encode_reclaim_complete(struct xdr_stream *xdr,
1843 struct nfs41_reclaim_complete_args *args,
1844 struct compound_hdr *hdr)
1845{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001846 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1847 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001848}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001849#endif /* CONFIG_NFS_V4_1 */
1850
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001851static void encode_sequence(struct xdr_stream *xdr,
1852 const struct nfs4_sequence_args *args,
1853 struct compound_hdr *hdr)
1854{
1855#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001856 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001857 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001858 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001859 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001860
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001861 tp = slot->table;
1862 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001863 if (!session)
1864 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001865
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001866 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001867
1868 /*
1869 * Sessionid + seqid + slotid + max slotid + cache_this
1870 */
1871 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1872 "max_slotid=%d cache_this=%d\n",
1873 __func__,
1874 ((u32 *)session->sess_id.data)[0],
1875 ((u32 *)session->sess_id.data)[1],
1876 ((u32 *)session->sess_id.data)[2],
1877 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001878 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001879 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001880 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001881 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001882 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001883 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001884 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001885 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001886#endif /* CONFIG_NFS_V4_1 */
1887}
1888
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001889#ifdef CONFIG_NFS_V4_1
1890static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001891encode_getdevicelist(struct xdr_stream *xdr,
1892 const struct nfs4_getdevicelist_args *args,
1893 struct compound_hdr *hdr)
1894{
1895 __be32 *p;
1896 nfs4_verifier dummy = {
1897 .data = "dummmmmy",
1898 };
1899
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001900 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1901 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001902 *p++ = cpu_to_be32(args->layoutclass);
1903 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1904 xdr_encode_hyper(p, 0ULL); /* cookie */
1905 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001906}
1907
1908static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001909encode_getdeviceinfo(struct xdr_stream *xdr,
1910 const struct nfs4_getdeviceinfo_args *args,
1911 struct compound_hdr *hdr)
1912{
1913 __be32 *p;
1914
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001915 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1916 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001917 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1918 NFS4_DEVICEID4_SIZE);
1919 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001920 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001921 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001922}
1923
1924static void
1925encode_layoutget(struct xdr_stream *xdr,
1926 const struct nfs4_layoutget_args *args,
1927 struct compound_hdr *hdr)
1928{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001929 __be32 *p;
1930
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001931 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1932 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001933 *p++ = cpu_to_be32(0); /* Signal layout available */
1934 *p++ = cpu_to_be32(args->type);
1935 *p++ = cpu_to_be32(args->range.iomode);
1936 p = xdr_encode_hyper(p, args->range.offset);
1937 p = xdr_encode_hyper(p, args->range.length);
1938 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001939 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001940 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001941
1942 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1943 __func__,
1944 args->type,
1945 args->range.iomode,
1946 (unsigned long)args->range.offset,
1947 (unsigned long)args->range.length,
1948 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001949}
Andy Adamson863a3c62011-03-23 13:27:54 +00001950
1951static int
1952encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001953 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001954 const struct nfs4_layoutcommit_args *args,
1955 struct compound_hdr *hdr)
1956{
1957 __be32 *p;
1958
1959 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1960 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1961
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001962 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1963 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001964 /* Only whole file layouts */
1965 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001966 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001967 *p = cpu_to_be32(0); /* reclaim */
1968 encode_nfs4_stateid(xdr, &args->stateid);
1969 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001970 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1971 p = xdr_encode_hyper(p, args->lastbytewritten);
1972 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1973 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001974
1975 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1976 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1977 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001978 else
1979 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001980
Andy Adamson863a3c62011-03-23 13:27:54 +00001981 return 0;
1982}
Benny Halevycbe82602011-05-22 19:52:37 +03001983
1984static void
1985encode_layoutreturn(struct xdr_stream *xdr,
1986 const struct nfs4_layoutreturn_args *args,
1987 struct compound_hdr *hdr)
1988{
1989 __be32 *p;
1990
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001991 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1992 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001993 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1994 *p++ = cpu_to_be32(args->layout_type);
1995 *p++ = cpu_to_be32(IOMODE_ANY);
1996 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001997 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001998 p = xdr_encode_hyper(p, 0);
1999 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2000 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002001 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002002 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002003 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2004 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2005 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002006 } else
2007 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002008}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002009
2010static int
2011encode_secinfo_no_name(struct xdr_stream *xdr,
2012 const struct nfs41_secinfo_no_name_args *args,
2013 struct compound_hdr *hdr)
2014{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002015 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2016 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002017 return 0;
2018}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002019
2020static void encode_test_stateid(struct xdr_stream *xdr,
2021 struct nfs41_test_stateid_args *args,
2022 struct compound_hdr *hdr)
2023{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002024 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2025 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002026 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002027}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002028
2029static void encode_free_stateid(struct xdr_stream *xdr,
2030 struct nfs41_free_stateid_args *args,
2031 struct compound_hdr *hdr)
2032{
Trond Myklebustab19b482012-03-04 18:13:57 -05002033 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002034 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002035}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002036#endif /* CONFIG_NFS_V4_1 */
2037
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038/*
2039 * END OF "GENERIC" ENCODE ROUTINES.
2040 */
2041
Benny Halevy66cc0422009-04-01 09:22:10 -04002042static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2043{
2044#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002045 struct nfs4_session *session = args->sa_slot->table->session;
2046 if (session)
2047 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002048#endif /* CONFIG_NFS_V4_1 */
2049 return 0;
2050}
2051
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052/*
2053 * Encode an ACCESS request
2054 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002055static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2056 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002059 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
Chuck Lever9f06c712010-12-14 14:59:18 +00002062 encode_compound_hdr(xdr, req, &hdr);
2063 encode_sequence(xdr, &args->seq_args, &hdr);
2064 encode_putfh(xdr, args->fh, &hdr);
2065 encode_access(xdr, args->access, &hdr);
2066 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002067 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068}
2069
2070/*
2071 * Encode LOOKUP request
2072 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002073static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2074 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002077 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
Chuck Lever9f06c712010-12-14 14:59:18 +00002080 encode_compound_hdr(xdr, req, &hdr);
2081 encode_sequence(xdr, &args->seq_args, &hdr);
2082 encode_putfh(xdr, args->dir_fh, &hdr);
2083 encode_lookup(xdr, args->name, &hdr);
2084 encode_getfh(xdr, &hdr);
2085 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002086 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087}
2088
2089/*
2090 * Encode LOOKUP_ROOT request
2091 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002092static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2093 struct xdr_stream *xdr,
2094 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002097 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Chuck Lever9f06c712010-12-14 14:59:18 +00002100 encode_compound_hdr(xdr, req, &hdr);
2101 encode_sequence(xdr, &args->seq_args, &hdr);
2102 encode_putrootfh(xdr, &hdr);
2103 encode_getfh(xdr, &hdr);
2104 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002105 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
2108/*
2109 * Encode REMOVE request
2110 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002111static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2112 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
Chuck Lever9f06c712010-12-14 14:59:18 +00002118 encode_compound_hdr(xdr, req, &hdr);
2119 encode_sequence(xdr, &args->seq_args, &hdr);
2120 encode_putfh(xdr, args->fh, &hdr);
2121 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002122 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123}
2124
2125/*
2126 * Encode RENAME request
2127 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002128static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2129 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002132 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Chuck Lever9f06c712010-12-14 14:59:18 +00002135 encode_compound_hdr(xdr, req, &hdr);
2136 encode_sequence(xdr, &args->seq_args, &hdr);
2137 encode_putfh(xdr, args->old_dir, &hdr);
2138 encode_savefh(xdr, &hdr);
2139 encode_putfh(xdr, args->new_dir, &hdr);
2140 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002141 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142}
2143
2144/*
2145 * Encode LINK request
2146 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002147static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2148 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002151 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153
Chuck Lever9f06c712010-12-14 14:59:18 +00002154 encode_compound_hdr(xdr, req, &hdr);
2155 encode_sequence(xdr, &args->seq_args, &hdr);
2156 encode_putfh(xdr, args->fh, &hdr);
2157 encode_savefh(xdr, &hdr);
2158 encode_putfh(xdr, args->dir_fh, &hdr);
2159 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002160 encode_restorefh(xdr, &hdr);
2161 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002162 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163}
2164
2165/*
2166 * Encode CREATE request
2167 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002168static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2169 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002172 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
Chuck Lever9f06c712010-12-14 14:59:18 +00002175 encode_compound_hdr(xdr, req, &hdr);
2176 encode_sequence(xdr, &args->seq_args, &hdr);
2177 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002178 encode_create(xdr, args, &hdr);
2179 encode_getfh(xdr, &hdr);
2180 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002181 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182}
2183
2184/*
2185 * Encode SYMLINK request
2186 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002187static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2188 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189{
Chuck Lever9f06c712010-12-14 14:59:18 +00002190 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191}
2192
2193/*
2194 * Encode GETATTR request
2195 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002196static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2197 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002200 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
Chuck Lever9f06c712010-12-14 14:59:18 +00002203 encode_compound_hdr(xdr, req, &hdr);
2204 encode_sequence(xdr, &args->seq_args, &hdr);
2205 encode_putfh(xdr, args->fh, &hdr);
2206 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002207 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208}
2209
2210/*
2211 * Encode a CLOSE request
2212 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002213static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2214 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
Andy Adamson05d564f2008-12-23 16:06:15 -05002216 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002217 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002218 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
Chuck Lever9f06c712010-12-14 14:59:18 +00002220 encode_compound_hdr(xdr, req, &hdr);
2221 encode_sequence(xdr, &args->seq_args, &hdr);
2222 encode_putfh(xdr, args->fh, &hdr);
2223 encode_close(xdr, args, &hdr);
2224 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002225 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226}
2227
2228/*
2229 * Encode an OPEN request
2230 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002231static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2232 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002235 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237
Chuck Lever9f06c712010-12-14 14:59:18 +00002238 encode_compound_hdr(xdr, req, &hdr);
2239 encode_sequence(xdr, &args->seq_args, &hdr);
2240 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002241 encode_open(xdr, args, &hdr);
2242 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002243 if (args->access)
2244 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002245 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002246 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247}
2248
2249/*
2250 * Encode an OPEN_CONFIRM request
2251 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002252static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2253 struct xdr_stream *xdr,
2254 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002257 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
Chuck Lever9f06c712010-12-14 14:59:18 +00002260 encode_compound_hdr(xdr, req, &hdr);
2261 encode_putfh(xdr, args->fh, &hdr);
2262 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002263 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264}
2265
2266/*
2267 * Encode an OPEN request with no attributes.
2268 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002269static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2270 struct xdr_stream *xdr,
2271 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002274 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
Chuck Lever9f06c712010-12-14 14:59:18 +00002277 encode_compound_hdr(xdr, req, &hdr);
2278 encode_sequence(xdr, &args->seq_args, &hdr);
2279 encode_putfh(xdr, args->fh, &hdr);
2280 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002281 if (args->access)
2282 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002283 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002284 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285}
2286
2287/*
2288 * Encode an OPEN_DOWNGRADE request
2289 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002290static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2291 struct xdr_stream *xdr,
2292 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002295 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297
Chuck Lever9f06c712010-12-14 14:59:18 +00002298 encode_compound_hdr(xdr, req, &hdr);
2299 encode_sequence(xdr, &args->seq_args, &hdr);
2300 encode_putfh(xdr, args->fh, &hdr);
2301 encode_open_downgrade(xdr, args, &hdr);
2302 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002303 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304}
2305
2306/*
2307 * Encode a LOCK request
2308 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002309static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2310 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002313 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Chuck Lever9f06c712010-12-14 14:59:18 +00002316 encode_compound_hdr(xdr, req, &hdr);
2317 encode_sequence(xdr, &args->seq_args, &hdr);
2318 encode_putfh(xdr, args->fh, &hdr);
2319 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002320 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321}
2322
2323/*
2324 * Encode a LOCKT request
2325 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002326static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2327 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002330 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
Chuck Lever9f06c712010-12-14 14:59:18 +00002333 encode_compound_hdr(xdr, req, &hdr);
2334 encode_sequence(xdr, &args->seq_args, &hdr);
2335 encode_putfh(xdr, args->fh, &hdr);
2336 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002337 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338}
2339
2340/*
2341 * Encode a LOCKU request
2342 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002343static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2344 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002347 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349
Chuck Lever9f06c712010-12-14 14:59:18 +00002350 encode_compound_hdr(xdr, req, &hdr);
2351 encode_sequence(xdr, &args->seq_args, &hdr);
2352 encode_putfh(xdr, args->fh, &hdr);
2353 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002354 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355}
2356
Chuck Lever9f06c712010-12-14 14:59:18 +00002357static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2358 struct xdr_stream *xdr,
2359 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002360{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002361 struct compound_hdr hdr = {
2362 .minorversion = 0,
2363 };
2364
Chuck Lever9f06c712010-12-14 14:59:18 +00002365 encode_compound_hdr(xdr, req, &hdr);
2366 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002367 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002368}
2369
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370/*
2371 * Encode a READLINK request
2372 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002373static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2374 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002377 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
Chuck Lever9f06c712010-12-14 14:59:18 +00002380 encode_compound_hdr(xdr, req, &hdr);
2381 encode_sequence(xdr, &args->seq_args, &hdr);
2382 encode_putfh(xdr, args->fh, &hdr);
2383 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002384
Benny Halevy28f56692009-04-01 09:22:09 -04002385 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002386 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002387 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388}
2389
2390/*
2391 * Encode a READDIR request
2392 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002393static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2394 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002397 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
Chuck Lever9f06c712010-12-14 14:59:18 +00002400 encode_compound_hdr(xdr, req, &hdr);
2401 encode_sequence(xdr, &args->seq_args, &hdr);
2402 encode_putfh(xdr, args->fh, &hdr);
2403 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002404
Benny Halevy28f56692009-04-01 09:22:09 -04002405 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002406 args->pgbase, args->count);
2407 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002408 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002409 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002410 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411}
2412
2413/*
2414 * Encode a READ request
2415 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002416static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2417 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002420 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422
Chuck Lever9f06c712010-12-14 14:59:18 +00002423 encode_compound_hdr(xdr, req, &hdr);
2424 encode_sequence(xdr, &args->seq_args, &hdr);
2425 encode_putfh(xdr, args->fh, &hdr);
2426 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Benny Halevy28f56692009-04-01 09:22:09 -04002428 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002430 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002431 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432}
2433
2434/*
2435 * Encode an SETATTR request
2436 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002437static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2438 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439{
Andy Adamson05d564f2008-12-23 16:06:15 -05002440 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002441 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002442 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
Chuck Lever9f06c712010-12-14 14:59:18 +00002444 encode_compound_hdr(xdr, req, &hdr);
2445 encode_sequence(xdr, &args->seq_args, &hdr);
2446 encode_putfh(xdr, args->fh, &hdr);
2447 encode_setattr(xdr, args, args->server, &hdr);
2448 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002449 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450}
2451
2452/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002453 * Encode a GETACL request
2454 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002455static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2456 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002457{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002458 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002459 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002460 };
Benny Halevy28f56692009-04-01 09:22:09 -04002461 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002462
Chuck Lever9f06c712010-12-14 14:59:18 +00002463 encode_compound_hdr(xdr, req, &hdr);
2464 encode_sequence(xdr, &args->seq_args, &hdr);
2465 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002466 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002467 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002468
Benny Halevy28f56692009-04-01 09:22:09 -04002469 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002470 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002471
Andy Adamsond0179312008-12-23 16:06:17 -05002472 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002473}
2474
2475/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 * Encode a WRITE request
2477 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002478static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2479 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002482 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484
Chuck Lever9f06c712010-12-14 14:59:18 +00002485 encode_compound_hdr(xdr, req, &hdr);
2486 encode_sequence(xdr, &args->seq_args, &hdr);
2487 encode_putfh(xdr, args->fh, &hdr);
2488 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002489 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002490 if (args->bitmask)
2491 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002492 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493}
2494
2495/*
2496 * a COMMIT request
2497 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002498static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002499 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002502 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504
Chuck Lever9f06c712010-12-14 14:59:18 +00002505 encode_compound_hdr(xdr, req, &hdr);
2506 encode_sequence(xdr, &args->seq_args, &hdr);
2507 encode_putfh(xdr, args->fh, &hdr);
2508 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002509 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510}
2511
2512/*
2513 * FSINFO request
2514 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002515static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2516 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002519 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
Chuck Lever9f06c712010-12-14 14:59:18 +00002522 encode_compound_hdr(xdr, req, &hdr);
2523 encode_sequence(xdr, &args->seq_args, &hdr);
2524 encode_putfh(xdr, args->fh, &hdr);
2525 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002526 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527}
2528
2529/*
2530 * a PATHCONF request
2531 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002532static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2533 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002536 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538
Chuck Lever9f06c712010-12-14 14:59:18 +00002539 encode_compound_hdr(xdr, req, &hdr);
2540 encode_sequence(xdr, &args->seq_args, &hdr);
2541 encode_putfh(xdr, args->fh, &hdr);
2542 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002543 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002544 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545}
2546
2547/*
2548 * a STATFS request
2549 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002550static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2551 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002554 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556
Chuck Lever9f06c712010-12-14 14:59:18 +00002557 encode_compound_hdr(xdr, req, &hdr);
2558 encode_sequence(xdr, &args->seq_args, &hdr);
2559 encode_putfh(xdr, args->fh, &hdr);
2560 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002561 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002562 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563}
2564
2565/*
2566 * GETATTR_BITMAP request
2567 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002568static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2569 struct xdr_stream *xdr,
2570 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002573 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
Chuck Lever9f06c712010-12-14 14:59:18 +00002576 encode_compound_hdr(xdr, req, &hdr);
2577 encode_sequence(xdr, &args->seq_args, &hdr);
2578 encode_putfh(xdr, args->fhandle, &hdr);
2579 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002580 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002581 FATTR4_WORD0_LINK_SUPPORT|
2582 FATTR4_WORD0_SYMLINK_SUPPORT|
2583 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002584 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585}
2586
2587/*
2588 * a RENEW request
2589 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002590static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2591 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002594 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 };
2596
Chuck Lever9f06c712010-12-14 14:59:18 +00002597 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002598 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002599 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600}
2601
2602/*
2603 * a SETCLIENTID request
2604 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002605static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2606 struct xdr_stream *xdr,
2607 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002610 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 };
2612
Chuck Lever9f06c712010-12-14 14:59:18 +00002613 encode_compound_hdr(xdr, req, &hdr);
2614 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002615 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616}
2617
2618/*
2619 * a SETCLIENTID_CONFIRM request
2620 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002621static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2622 struct xdr_stream *xdr,
2623 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002626 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
Chuck Lever9f06c712010-12-14 14:59:18 +00002629 encode_compound_hdr(xdr, req, &hdr);
2630 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002631 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632}
2633
2634/*
2635 * DELEGRETURN request
2636 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002637static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2638 struct xdr_stream *xdr,
2639 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002642 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
Chuck Lever9f06c712010-12-14 14:59:18 +00002645 encode_compound_hdr(xdr, req, &hdr);
2646 encode_sequence(xdr, &args->seq_args, &hdr);
2647 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002648 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002649 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002650 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651}
2652
2653/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002654 * Encode FS_LOCATIONS request
2655 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002656static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2657 struct xdr_stream *xdr,
2658 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002659{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002660 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002661 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002662 };
Benny Halevy28f56692009-04-01 09:22:09 -04002663 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002664
Chuck Lever9f06c712010-12-14 14:59:18 +00002665 encode_compound_hdr(xdr, req, &hdr);
2666 encode_sequence(xdr, &args->seq_args, &hdr);
2667 encode_putfh(xdr, args->dir_fh, &hdr);
2668 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002669 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002670 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002671
Benny Halevy28f56692009-04-01 09:22:09 -04002672 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002673 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002674 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002675}
2676
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002677/*
2678 * Encode SECINFO request
2679 */
2680static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2681 struct xdr_stream *xdr,
2682 struct nfs4_secinfo_arg *args)
2683{
2684 struct compound_hdr hdr = {
2685 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2686 };
2687
2688 encode_compound_hdr(xdr, req, &hdr);
2689 encode_sequence(xdr, &args->seq_args, &hdr);
2690 encode_putfh(xdr, args->dir_fh, &hdr);
2691 encode_secinfo(xdr, args->name, &hdr);
2692 encode_nops(&hdr);
2693}
2694
Benny Halevy99fe60d2009-04-01 09:22:29 -04002695#if defined(CONFIG_NFS_V4_1)
2696/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002697 * BIND_CONN_TO_SESSION request
2698 */
2699static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2700 struct xdr_stream *xdr,
2701 struct nfs_client *clp)
2702{
2703 struct compound_hdr hdr = {
2704 .minorversion = clp->cl_mvops->minor_version,
2705 };
2706
2707 encode_compound_hdr(xdr, req, &hdr);
2708 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2709 encode_nops(&hdr);
2710}
2711
2712/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002713 * EXCHANGE_ID request
2714 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002715static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2716 struct xdr_stream *xdr,
2717 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002718{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002719 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002720 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002721 };
2722
Chuck Lever9f06c712010-12-14 14:59:18 +00002723 encode_compound_hdr(xdr, req, &hdr);
2724 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002725 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002726}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002727
2728/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002729 * a CREATE_SESSION request
2730 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002731static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2732 struct xdr_stream *xdr,
2733 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002734{
Andy Adamsonfc931582009-04-01 09:22:31 -04002735 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002736 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002737 };
2738
Chuck Lever9f06c712010-12-14 14:59:18 +00002739 encode_compound_hdr(xdr, req, &hdr);
2740 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002741 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002742}
2743
2744/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002745 * a DESTROY_SESSION request
2746 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002747static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2748 struct xdr_stream *xdr,
2749 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002750{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002751 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002752 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002753 };
2754
Chuck Lever9f06c712010-12-14 14:59:18 +00002755 encode_compound_hdr(xdr, req, &hdr);
2756 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002757 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002758}
2759
2760/*
Trond Myklebust66245532012-05-25 17:18:09 -04002761 * a DESTROY_CLIENTID request
2762 */
2763static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2764 struct xdr_stream *xdr,
2765 struct nfs_client *clp)
2766{
2767 struct compound_hdr hdr = {
2768 .minorversion = clp->cl_mvops->minor_version,
2769 };
2770
2771 encode_compound_hdr(xdr, req, &hdr);
2772 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2773 encode_nops(&hdr);
2774}
2775
2776/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002777 * a SEQUENCE request
2778 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002779static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2780 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002781{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002782 struct compound_hdr hdr = {
2783 .minorversion = nfs4_xdr_minorversion(args),
2784 };
2785
Chuck Lever9f06c712010-12-14 14:59:18 +00002786 encode_compound_hdr(xdr, req, &hdr);
2787 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002788 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002789}
2790
2791/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002792 * a GET_LEASE_TIME request
2793 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002794static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2795 struct xdr_stream *xdr,
2796 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002797{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002798 struct compound_hdr hdr = {
2799 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2800 };
Fred Isamandae100c2011-07-30 20:52:37 -04002801 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002802
Chuck Lever9f06c712010-12-14 14:59:18 +00002803 encode_compound_hdr(xdr, req, &hdr);
2804 encode_sequence(xdr, &args->la_seq_args, &hdr);
2805 encode_putrootfh(xdr, &hdr);
2806 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002807 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002808}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002809
2810/*
2811 * a RECLAIM_COMPLETE request
2812 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002813static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2814 struct xdr_stream *xdr,
2815 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002816{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002817 struct compound_hdr hdr = {
2818 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2819 };
2820
Chuck Lever9f06c712010-12-14 14:59:18 +00002821 encode_compound_hdr(xdr, req, &hdr);
2822 encode_sequence(xdr, &args->seq_args, &hdr);
2823 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002824 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002825}
2826
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002827/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002828 * Encode GETDEVICELIST request
2829 */
2830static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2831 struct xdr_stream *xdr,
2832 struct nfs4_getdevicelist_args *args)
2833{
2834 struct compound_hdr hdr = {
2835 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2836 };
2837
2838 encode_compound_hdr(xdr, req, &hdr);
2839 encode_sequence(xdr, &args->seq_args, &hdr);
2840 encode_putfh(xdr, args->fh, &hdr);
2841 encode_getdevicelist(xdr, args, &hdr);
2842 encode_nops(&hdr);
2843}
2844
2845/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002846 * Encode GETDEVICEINFO request
2847 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002848static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2849 struct xdr_stream *xdr,
2850 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002851{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002852 struct compound_hdr hdr = {
2853 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2854 };
2855
Chuck Lever9f06c712010-12-14 14:59:18 +00002856 encode_compound_hdr(xdr, req, &hdr);
2857 encode_sequence(xdr, &args->seq_args, &hdr);
2858 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002859
2860 /* set up reply kvec. Subtract notification bitmap max size (2)
2861 * so that notification bitmap is put in xdr_buf tail */
2862 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2863 args->pdev->pages, args->pdev->pgbase,
2864 args->pdev->pglen);
2865
2866 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002867}
2868
2869/*
2870 * Encode LAYOUTGET request
2871 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002872static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2873 struct xdr_stream *xdr,
2874 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002875{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002876 struct compound_hdr hdr = {
2877 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2878 };
2879
Chuck Lever9f06c712010-12-14 14:59:18 +00002880 encode_compound_hdr(xdr, req, &hdr);
2881 encode_sequence(xdr, &args->seq_args, &hdr);
2882 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2883 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002884
2885 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2886 args->layout.pages, 0, args->layout.pglen);
2887
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002888 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002889}
Andy Adamson863a3c62011-03-23 13:27:54 +00002890
2891/*
2892 * Encode LAYOUTCOMMIT request
2893 */
Benny Halevycbe82602011-05-22 19:52:37 +03002894static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2895 struct xdr_stream *xdr,
2896 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002897{
Benny Halevyac7db722011-05-22 19:53:48 +03002898 struct nfs4_layoutcommit_data *data =
2899 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002900 struct compound_hdr hdr = {
2901 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2902 };
2903
2904 encode_compound_hdr(xdr, req, &hdr);
2905 encode_sequence(xdr, &args->seq_args, &hdr);
2906 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002907 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002908 encode_getfattr(xdr, args->bitmask, &hdr);
2909 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002910}
2911
2912/*
2913 * Encode LAYOUTRETURN request
2914 */
2915static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2916 struct xdr_stream *xdr,
2917 struct nfs4_layoutreturn_args *args)
2918{
2919 struct compound_hdr hdr = {
2920 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2921 };
2922
2923 encode_compound_hdr(xdr, req, &hdr);
2924 encode_sequence(xdr, &args->seq_args, &hdr);
2925 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2926 encode_layoutreturn(xdr, args, &hdr);
2927 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002928}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002929
2930/*
2931 * Encode SECINFO_NO_NAME request
2932 */
2933static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2934 struct xdr_stream *xdr,
2935 struct nfs41_secinfo_no_name_args *args)
2936{
2937 struct compound_hdr hdr = {
2938 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2939 };
2940
2941 encode_compound_hdr(xdr, req, &hdr);
2942 encode_sequence(xdr, &args->seq_args, &hdr);
2943 encode_putrootfh(xdr, &hdr);
2944 encode_secinfo_no_name(xdr, args, &hdr);
2945 encode_nops(&hdr);
2946 return 0;
2947}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002948
2949/*
2950 * Encode TEST_STATEID request
2951 */
2952static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2953 struct xdr_stream *xdr,
2954 struct nfs41_test_stateid_args *args)
2955{
2956 struct compound_hdr hdr = {
2957 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2958 };
2959
2960 encode_compound_hdr(xdr, req, &hdr);
2961 encode_sequence(xdr, &args->seq_args, &hdr);
2962 encode_test_stateid(xdr, args, &hdr);
2963 encode_nops(&hdr);
2964}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002965
2966/*
2967 * Encode FREE_STATEID request
2968 */
2969static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2970 struct xdr_stream *xdr,
2971 struct nfs41_free_stateid_args *args)
2972{
2973 struct compound_hdr hdr = {
2974 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2975 };
2976
2977 encode_compound_hdr(xdr, req, &hdr);
2978 encode_sequence(xdr, &args->seq_args, &hdr);
2979 encode_free_stateid(xdr, args, &hdr);
2980 encode_nops(&hdr);
2981}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002982#endif /* CONFIG_NFS_V4_1 */
2983
Benny Halevy686841b2009-08-14 17:19:48 +03002984static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2985{
2986 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2987 "Remaining buffer length is %tu words.\n",
2988 func, xdr->end - xdr->p);
2989}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
Trond Myklebust683b57b2006-06-09 09:34:22 -04002991static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992{
Al Viro8687b632006-10-19 23:28:48 -07002993 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994
Benny Halevyc0eae662009-08-14 17:20:14 +03002995 p = xdr_inline_decode(xdr, 4);
2996 if (unlikely(!p))
2997 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002998 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002999 p = xdr_inline_decode(xdr, *len);
3000 if (unlikely(!p))
3001 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 *string = (char *)p;
3003 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003004out_overflow:
3005 print_overflow_msg(__func__, xdr);
3006 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007}
3008
3009static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3010{
Al Viro8687b632006-10-19 23:28:48 -07003011 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012
Benny Halevyc0eae662009-08-14 17:20:14 +03003013 p = xdr_inline_decode(xdr, 8);
3014 if (unlikely(!p))
3015 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003016 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003017 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003018
Benny Halevyc0eae662009-08-14 17:20:14 +03003019 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3020 if (unlikely(!p))
3021 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 hdr->tag = (char *)p;
3023 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003024 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003025 if (unlikely(hdr->nops < 1))
3026 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003028out_overflow:
3029 print_overflow_msg(__func__, xdr);
3030 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031}
3032
3033static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3034{
Al Viro8687b632006-10-19 23:28:48 -07003035 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 uint32_t opnum;
3037 int32_t nfserr;
3038
Benny Halevyc0eae662009-08-14 17:20:14 +03003039 p = xdr_inline_decode(xdr, 8);
3040 if (unlikely(!p))
3041 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003042 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003044 dprintk("nfs: Server returned operation"
3045 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 opnum, expected);
3047 return -EIO;
3048 }
Benny Halevycccddf42009-08-14 17:20:19 +03003049 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003051 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003053out_overflow:
3054 print_overflow_msg(__func__, xdr);
3055 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056}
3057
3058/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003059static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060{
Al Viro8687b632006-10-19 23:28:48 -07003061 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003062 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 char *str;
3064
Benny Halevyc0eae662009-08-14 17:20:14 +03003065 p = xdr_inline_decode(xdr, 12);
3066 if (likely(p))
3067 return decode_opaque_inline(xdr, &strlen, &str);
3068 print_overflow_msg(__func__, xdr);
3069 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070}
3071
3072static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3073{
Al Viro8687b632006-10-19 23:28:48 -07003074 uint32_t bmlen;
3075 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076
Benny Halevyc0eae662009-08-14 17:20:14 +03003077 p = xdr_inline_decode(xdr, 4);
3078 if (unlikely(!p))
3079 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003080 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081
Fred Isamandae100c2011-07-30 20:52:37 -04003082 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003083 p = xdr_inline_decode(xdr, (bmlen << 2));
3084 if (unlikely(!p))
3085 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003087 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003088 if (bmlen > 1) {
3089 bitmap[1] = be32_to_cpup(p++);
3090 if (bmlen > 2)
3091 bitmap[2] = be32_to_cpup(p);
3092 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 }
3094 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003095out_overflow:
3096 print_overflow_msg(__func__, xdr);
3097 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098}
3099
Trond Myklebust256e48b2012-06-21 11:18:13 -04003100static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101{
Al Viro8687b632006-10-19 23:28:48 -07003102 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103
Benny Halevyc0eae662009-08-14 17:20:14 +03003104 p = xdr_inline_decode(xdr, 4);
3105 if (unlikely(!p))
3106 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003107 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003108 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003110out_overflow:
3111 print_overflow_msg(__func__, xdr);
3112 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113}
3114
3115static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3116{
3117 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003118 int ret;
3119 ret = decode_attr_bitmap(xdr, bitmask);
3120 if (unlikely(ret < 0))
3121 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3123 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003124 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3125 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3126 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 return 0;
3128}
3129
3130static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3131{
Al Viro8687b632006-10-19 23:28:48 -07003132 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003133 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134
3135 *type = 0;
3136 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3137 return -EIO;
3138 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003139 p = xdr_inline_decode(xdr, 4);
3140 if (unlikely(!p))
3141 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003142 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003144 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 return -EIO;
3146 }
3147 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003148 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003150 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003151 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003152out_overflow:
3153 print_overflow_msg(__func__, xdr);
3154 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155}
3156
Chuck Lever264e6352012-03-01 17:02:05 -05003157static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3158 uint32_t *bitmap, uint32_t *type)
3159{
3160 __be32 *p;
3161
3162 *type = 0;
3163 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3164 return -EIO;
3165 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3166 p = xdr_inline_decode(xdr, 4);
3167 if (unlikely(!p))
3168 goto out_overflow;
3169 *type = be32_to_cpup(p);
3170 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3171 }
3172 dprintk("%s: expire type=0x%x\n", __func__, *type);
3173 return 0;
3174out_overflow:
3175 print_overflow_msg(__func__, xdr);
3176 return -EIO;
3177}
3178
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3180{
Al Viro8687b632006-10-19 23:28:48 -07003181 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003182 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183
3184 *change = 0;
3185 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3186 return -EIO;
3187 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003188 p = xdr_inline_decode(xdr, 8);
3189 if (unlikely(!p))
3190 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003191 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003193 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003195 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003197 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003198out_overflow:
3199 print_overflow_msg(__func__, xdr);
3200 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201}
3202
3203static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3204{
Al Viro8687b632006-10-19 23:28:48 -07003205 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003206 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207
3208 *size = 0;
3209 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3210 return -EIO;
3211 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003212 p = xdr_inline_decode(xdr, 8);
3213 if (unlikely(!p))
3214 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003215 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003217 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003219 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003220 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003221out_overflow:
3222 print_overflow_msg(__func__, xdr);
3223 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224}
3225
3226static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3227{
Al Viro8687b632006-10-19 23:28:48 -07003228 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
3230 *res = 0;
3231 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3232 return -EIO;
3233 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003234 p = xdr_inline_decode(xdr, 4);
3235 if (unlikely(!p))
3236 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003237 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3239 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003240 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003242out_overflow:
3243 print_overflow_msg(__func__, xdr);
3244 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245}
3246
3247static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3248{
Al Viro8687b632006-10-19 23:28:48 -07003249 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250
3251 *res = 0;
3252 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3253 return -EIO;
3254 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003255 p = xdr_inline_decode(xdr, 4);
3256 if (unlikely(!p))
3257 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003258 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3260 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003261 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003263out_overflow:
3264 print_overflow_msg(__func__, xdr);
3265 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266}
3267
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003268static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269{
Al Viro8687b632006-10-19 23:28:48 -07003270 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003271 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272
3273 fsid->major = 0;
3274 fsid->minor = 0;
3275 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3276 return -EIO;
3277 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003278 p = xdr_inline_decode(xdr, 16);
3279 if (unlikely(!p))
3280 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003281 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003282 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003284 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003286 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 (unsigned long long)fsid->major,
3288 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003289 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003290out_overflow:
3291 print_overflow_msg(__func__, xdr);
3292 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293}
3294
3295static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3296{
Al Viro8687b632006-10-19 23:28:48 -07003297 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298
3299 *res = 60;
3300 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3301 return -EIO;
3302 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003303 p = xdr_inline_decode(xdr, 4);
3304 if (unlikely(!p))
3305 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003306 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3308 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003309 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003311out_overflow:
3312 print_overflow_msg(__func__, xdr);
3313 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314}
3315
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003316static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003317{
3318 __be32 *p;
3319
3320 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3321 return -EIO;
3322 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3323 p = xdr_inline_decode(xdr, 4);
3324 if (unlikely(!p))
3325 goto out_overflow;
3326 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003327 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003328 }
3329 return 0;
3330out_overflow:
3331 print_overflow_msg(__func__, xdr);
3332 return -EIO;
3333}
3334
3335static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3336{
3337 __be32 *p;
3338 int len;
3339
Trond Myklebust7ad07352010-10-23 15:34:20 -04003340 if (fh != NULL)
3341 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003342
3343 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3344 return -EIO;
3345 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3346 p = xdr_inline_decode(xdr, 4);
3347 if (unlikely(!p))
3348 goto out_overflow;
3349 len = be32_to_cpup(p);
3350 if (len > NFS4_FHSIZE)
3351 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003352 p = xdr_inline_decode(xdr, len);
3353 if (unlikely(!p))
3354 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003355 if (fh != NULL) {
3356 memcpy(fh->data, p, len);
3357 fh->size = len;
3358 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003359 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3360 }
3361 return 0;
3362out_overflow:
3363 print_overflow_msg(__func__, xdr);
3364 return -EIO;
3365}
3366
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3368{
Al Viro8687b632006-10-19 23:28:48 -07003369 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370
3371 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3372 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3373 return -EIO;
3374 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003375 p = xdr_inline_decode(xdr, 4);
3376 if (unlikely(!p))
3377 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003378 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3380 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003381 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003383out_overflow:
3384 print_overflow_msg(__func__, xdr);
3385 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386}
3387
3388static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3389{
Al Viro8687b632006-10-19 23:28:48 -07003390 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003391 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392
3393 *fileid = 0;
3394 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3395 return -EIO;
3396 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003397 p = xdr_inline_decode(xdr, 8);
3398 if (unlikely(!p))
3399 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003400 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003402 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003404 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003405 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003406out_overflow:
3407 print_overflow_msg(__func__, xdr);
3408 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409}
3410
Manoj Naik99baf622006-06-09 09:34:24 -04003411static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3412{
Al Viro8687b632006-10-19 23:28:48 -07003413 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003414 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003415
3416 *fileid = 0;
3417 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3418 return -EIO;
3419 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003420 p = xdr_inline_decode(xdr, 8);
3421 if (unlikely(!p))
3422 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003423 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003424 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003425 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003426 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003427 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003428 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003429out_overflow:
3430 print_overflow_msg(__func__, xdr);
3431 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003432}
3433
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3435{
Al Viro8687b632006-10-19 23:28:48 -07003436 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 int status = 0;
3438
3439 *res = 0;
3440 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3441 return -EIO;
3442 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003443 p = xdr_inline_decode(xdr, 8);
3444 if (unlikely(!p))
3445 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003446 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3448 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003449 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003451out_overflow:
3452 print_overflow_msg(__func__, xdr);
3453 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454}
3455
3456static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3457{
Al Viro8687b632006-10-19 23:28:48 -07003458 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 int status = 0;
3460
3461 *res = 0;
3462 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3463 return -EIO;
3464 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003465 p = xdr_inline_decode(xdr, 8);
3466 if (unlikely(!p))
3467 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003468 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3470 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003471 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003473out_overflow:
3474 print_overflow_msg(__func__, xdr);
3475 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476}
3477
3478static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3479{
Al Viro8687b632006-10-19 23:28:48 -07003480 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 int status = 0;
3482
3483 *res = 0;
3484 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3485 return -EIO;
3486 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003487 p = xdr_inline_decode(xdr, 8);
3488 if (unlikely(!p))
3489 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003490 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3492 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003493 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003495out_overflow:
3496 print_overflow_msg(__func__, xdr);
3497 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498}
3499
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003500static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3501{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003502 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003503 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003504 int status = 0;
3505
Benny Halevyc0eae662009-08-14 17:20:14 +03003506 p = xdr_inline_decode(xdr, 4);
3507 if (unlikely(!p))
3508 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003509 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003510 if (n == 0)
3511 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003512 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003513 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3514 dprintk("cannot parse %d components in path\n", n);
3515 goto out_eio;
3516 }
3517 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003518 struct nfs4_string *component = &path->components[path->ncomponents];
3519 status = decode_opaque_inline(xdr, &component->len, &component->data);
3520 if (unlikely(status != 0))
3521 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003522 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003523 pr_cont("%s%.*s ",
3524 (path->ncomponents != n ? "/ " : ""),
3525 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003526 }
3527out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003528 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003529root_path:
3530/* a root pathname is sent as a zero component4 */
3531 path->ncomponents = 1;
3532 path->components[0].len=0;
3533 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003534 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003535 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003536out_eio:
3537 dprintk(" status %d", status);
3538 status = -EIO;
3539 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003540out_overflow:
3541 print_overflow_msg(__func__, xdr);
3542 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003543}
3544
3545static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003546{
3547 int n;
Al Viro8687b632006-10-19 23:28:48 -07003548 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003549 int status = -EIO;
3550
3551 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3552 goto out;
3553 status = 0;
3554 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3555 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003556 status = -EIO;
3557 /* Ignore borken servers that return unrequested attrs */
3558 if (unlikely(res == NULL))
3559 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003560 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003561 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003562 if (unlikely(status != 0))
3563 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003564 p = xdr_inline_decode(xdr, 4);
3565 if (unlikely(!p))
3566 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003567 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003568 if (n <= 0)
3569 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003570 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003571 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003572 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003573
Trond Myklebust809b4262013-03-27 11:54:45 -04003574 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3575 break;
3576 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003577 p = xdr_inline_decode(xdr, 4);
3578 if (unlikely(!p))
3579 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003580 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003581
Chuck Lever02a29762012-03-01 17:00:31 -05003582 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003583 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3584 struct nfs4_string *server;
3585
3586 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003587 unsigned int i;
3588 dprintk("%s: using first %u of %u servers "
3589 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003590 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003591 NFS4_FS_LOCATION_MAXSERVERS,
3592 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003593 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003594 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003595 char *data;
3596 status = decode_opaque_inline(xdr, &len, &data);
3597 if (unlikely(status != 0))
3598 goto out_eio;
3599 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003600 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003601 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003602 server = &loc->servers[loc->nservers];
3603 status = decode_opaque_inline(xdr, &server->len, &server->data);
3604 if (unlikely(status != 0))
3605 goto out_eio;
3606 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003607 }
3608 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003609 if (unlikely(status != 0))
3610 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003611 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003612 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003613 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003614out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003615 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003616 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003617out_overflow:
3618 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003619out_eio:
3620 status = -EIO;
3621 goto out;
3622}
3623
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3625{
Al Viro8687b632006-10-19 23:28:48 -07003626 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 int status = 0;
3628
3629 *res = 0;
3630 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3631 return -EIO;
3632 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003633 p = xdr_inline_decode(xdr, 8);
3634 if (unlikely(!p))
3635 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003636 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3638 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003639 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003641out_overflow:
3642 print_overflow_msg(__func__, xdr);
3643 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644}
3645
3646static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3647{
Al Viro8687b632006-10-19 23:28:48 -07003648 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649 int status = 0;
3650
3651 *maxlink = 1;
3652 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3653 return -EIO;
3654 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003655 p = xdr_inline_decode(xdr, 4);
3656 if (unlikely(!p))
3657 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003658 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3660 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003661 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003663out_overflow:
3664 print_overflow_msg(__func__, xdr);
3665 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666}
3667
3668static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3669{
Al Viro8687b632006-10-19 23:28:48 -07003670 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 int status = 0;
3672
3673 *maxname = 1024;
3674 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3675 return -EIO;
3676 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003677 p = xdr_inline_decode(xdr, 4);
3678 if (unlikely(!p))
3679 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003680 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3682 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003683 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003685out_overflow:
3686 print_overflow_msg(__func__, xdr);
3687 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688}
3689
3690static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3691{
Al Viro8687b632006-10-19 23:28:48 -07003692 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 int status = 0;
3694
3695 *res = 1024;
3696 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3697 return -EIO;
3698 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3699 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003700 p = xdr_inline_decode(xdr, 8);
3701 if (unlikely(!p))
3702 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003703 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 if (maxread > 0x7FFFFFFF)
3705 maxread = 0x7FFFFFFF;
3706 *res = (uint32_t)maxread;
3707 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3708 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003709 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003711out_overflow:
3712 print_overflow_msg(__func__, xdr);
3713 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714}
3715
3716static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3717{
Al Viro8687b632006-10-19 23:28:48 -07003718 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 int status = 0;
3720
3721 *res = 1024;
3722 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3723 return -EIO;
3724 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3725 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003726 p = xdr_inline_decode(xdr, 8);
3727 if (unlikely(!p))
3728 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003729 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 if (maxwrite > 0x7FFFFFFF)
3731 maxwrite = 0x7FFFFFFF;
3732 *res = (uint32_t)maxwrite;
3733 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3734 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003735 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003737out_overflow:
3738 print_overflow_msg(__func__, xdr);
3739 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740}
3741
Trond Myklebustbca79472009-03-11 14:10:26 -04003742static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743{
Trond Myklebustbca79472009-03-11 14:10:26 -04003744 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003745 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003746 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747
3748 *mode = 0;
3749 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3750 return -EIO;
3751 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003752 p = xdr_inline_decode(xdr, 4);
3753 if (unlikely(!p))
3754 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003755 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003756 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003758 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003760 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003761 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003762out_overflow:
3763 print_overflow_msg(__func__, xdr);
3764 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765}
3766
3767static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3768{
Al Viro8687b632006-10-19 23:28:48 -07003769 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003770 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771
3772 *nlink = 1;
3773 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3774 return -EIO;
3775 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003776 p = xdr_inline_decode(xdr, 4);
3777 if (unlikely(!p))
3778 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003779 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003781 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003783 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003784 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003785out_overflow:
3786 print_overflow_msg(__func__, xdr);
3787 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788}
3789
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003790static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003791 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003792 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793{
Al Viro8687b632006-10-19 23:28:48 -07003794 uint32_t len;
3795 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003796 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797
Eric W. Biedermane5782072013-02-01 14:22:02 -08003798 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3800 return -EIO;
3801 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003802 p = xdr_inline_decode(xdr, 4);
3803 if (unlikely(!p))
3804 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003805 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003806 p = xdr_inline_decode(xdr, len);
3807 if (unlikely(!p))
3808 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003809 if (owner_name != NULL) {
3810 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3811 if (owner_name->data != NULL) {
3812 owner_name->len = len;
3813 ret = NFS_ATTR_FATTR_OWNER_NAME;
3814 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003815 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003816 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003817 ret = NFS_ATTR_FATTR_OWNER;
3818 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003820 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003822 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003823 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3825 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003826 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003827 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003828out_overflow:
3829 print_overflow_msg(__func__, xdr);
3830 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831}
3832
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003833static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003834 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003835 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836{
Al Viro8687b632006-10-19 23:28:48 -07003837 uint32_t len;
3838 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003839 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840
Eric W. Biedermane5782072013-02-01 14:22:02 -08003841 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3843 return -EIO;
3844 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003845 p = xdr_inline_decode(xdr, 4);
3846 if (unlikely(!p))
3847 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003848 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003849 p = xdr_inline_decode(xdr, len);
3850 if (unlikely(!p))
3851 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003852 if (group_name != NULL) {
3853 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3854 if (group_name->data != NULL) {
3855 group_name->len = len;
3856 ret = NFS_ATTR_FATTR_GROUP_NAME;
3857 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003858 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003859 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003860 ret = NFS_ATTR_FATTR_GROUP;
3861 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003863 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003865 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003866 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3868 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003869 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003870 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003871out_overflow:
3872 print_overflow_msg(__func__, xdr);
3873 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874}
3875
3876static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3877{
Al Viro8687b632006-10-19 23:28:48 -07003878 uint32_t major = 0, minor = 0;
3879 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003880 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881
3882 *rdev = MKDEV(0,0);
3883 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3884 return -EIO;
3885 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3886 dev_t tmp;
3887
Benny Halevyc0eae662009-08-14 17:20:14 +03003888 p = xdr_inline_decode(xdr, 8);
3889 if (unlikely(!p))
3890 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003891 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003892 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 tmp = MKDEV(major, minor);
3894 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3895 *rdev = tmp;
3896 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003897 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003899 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003900 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003901out_overflow:
3902 print_overflow_msg(__func__, xdr);
3903 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904}
3905
3906static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3907{
Al Viro8687b632006-10-19 23:28:48 -07003908 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 int status = 0;
3910
3911 *res = 0;
3912 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3913 return -EIO;
3914 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003915 p = xdr_inline_decode(xdr, 8);
3916 if (unlikely(!p))
3917 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003918 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3920 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003921 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003923out_overflow:
3924 print_overflow_msg(__func__, xdr);
3925 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926}
3927
3928static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3929{
Al Viro8687b632006-10-19 23:28:48 -07003930 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 int status = 0;
3932
3933 *res = 0;
3934 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3935 return -EIO;
3936 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003937 p = xdr_inline_decode(xdr, 8);
3938 if (unlikely(!p))
3939 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003940 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3942 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003943 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003945out_overflow:
3946 print_overflow_msg(__func__, xdr);
3947 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948}
3949
3950static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3951{
Al Viro8687b632006-10-19 23:28:48 -07003952 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 int status = 0;
3954
3955 *res = 0;
3956 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3957 return -EIO;
3958 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003959 p = xdr_inline_decode(xdr, 8);
3960 if (unlikely(!p))
3961 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003962 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3964 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003965 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003967out_overflow:
3968 print_overflow_msg(__func__, xdr);
3969 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970}
3971
3972static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3973{
Al Viro8687b632006-10-19 23:28:48 -07003974 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003975 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976
3977 *used = 0;
3978 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3979 return -EIO;
3980 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003981 p = xdr_inline_decode(xdr, 8);
3982 if (unlikely(!p))
3983 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003984 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003986 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003988 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003990 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003991out_overflow:
3992 print_overflow_msg(__func__, xdr);
3993 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994}
3995
3996static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3997{
Al Viro8687b632006-10-19 23:28:48 -07003998 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 uint64_t sec;
4000 uint32_t nsec;
4001
Benny Halevyc0eae662009-08-14 17:20:14 +03004002 p = xdr_inline_decode(xdr, 12);
4003 if (unlikely(!p))
4004 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004005 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004006 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 time->tv_sec = (time_t)sec;
4008 time->tv_nsec = (long)nsec;
4009 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004010out_overflow:
4011 print_overflow_msg(__func__, xdr);
4012 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013}
4014
4015static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4016{
4017 int status = 0;
4018
4019 time->tv_sec = 0;
4020 time->tv_nsec = 0;
4021 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4022 return -EIO;
4023 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4024 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004025 if (status == 0)
4026 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4028 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004029 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 return status;
4031}
4032
4033static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4034{
4035 int status = 0;
4036
4037 time->tv_sec = 0;
4038 time->tv_nsec = 0;
4039 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4040 return -EIO;
4041 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4042 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004043 if (status == 0)
4044 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4046 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004047 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 return status;
4049}
4050
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004051static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4052 struct timespec *time)
4053{
4054 int status = 0;
4055
4056 time->tv_sec = 0;
4057 time->tv_nsec = 0;
4058 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4059 return -EIO;
4060 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4061 status = decode_attr_time(xdr, time);
4062 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4063 }
4064 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4065 (long)time->tv_nsec);
4066 return status;
4067}
4068
David Quigleyaa9c2662013-05-22 12:50:44 -04004069static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4070 struct nfs4_label *label)
4071{
4072 uint32_t pi = 0;
4073 uint32_t lfs = 0;
4074 __u32 len;
4075 __be32 *p;
4076 int status = 0;
4077
4078 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4079 return -EIO;
4080 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4081 p = xdr_inline_decode(xdr, 4);
4082 if (unlikely(!p))
4083 goto out_overflow;
4084 lfs = be32_to_cpup(p++);
4085 p = xdr_inline_decode(xdr, 4);
4086 if (unlikely(!p))
4087 goto out_overflow;
4088 pi = be32_to_cpup(p++);
4089 p = xdr_inline_decode(xdr, 4);
4090 if (unlikely(!p))
4091 goto out_overflow;
4092 len = be32_to_cpup(p++);
4093 p = xdr_inline_decode(xdr, len);
4094 if (unlikely(!p))
4095 goto out_overflow;
4096 if (len < NFS4_MAXLABELLEN) {
4097 if (label) {
4098 memcpy(label->label, p, len);
4099 label->len = len;
4100 label->pi = pi;
4101 label->lfs = lfs;
4102 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4103 }
4104 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4105 } else
4106 printk(KERN_WARNING "%s: label too long (%u)!\n",
4107 __func__, len);
4108 }
4109 if (label && label->label)
4110 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4111 (char *)label->label, label->len, label->pi, label->lfs);
4112 return status;
4113
4114out_overflow:
4115 print_overflow_msg(__func__, xdr);
4116 return -EIO;
4117}
4118
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4120{
4121 int status = 0;
4122
4123 time->tv_sec = 0;
4124 time->tv_nsec = 0;
4125 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4126 return -EIO;
4127 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4128 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004129 if (status == 0)
4130 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4132 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004133 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 return status;
4135}
4136
Trond Myklebust256e48b2012-06-21 11:18:13 -04004137static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138{
4139 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004140 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141
4142 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004143 dprintk("%s: server returned incorrect attribute length: "
4144 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004145 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 attrwords << 2,
4147 (attrwords < nwords) ? '<' : '>',
4148 nwords << 2);
4149 return -EIO;
4150 }
4151 return 0;
4152}
4153
4154static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4155{
Al Viro8687b632006-10-19 23:28:48 -07004156 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157
Benny Halevyc0eae662009-08-14 17:20:14 +03004158 p = xdr_inline_decode(xdr, 20);
4159 if (unlikely(!p))
4160 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004161 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004162 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004163 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004165out_overflow:
4166 print_overflow_msg(__func__, xdr);
4167 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168}
4169
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004170static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171{
Al Viro8687b632006-10-19 23:28:48 -07004172 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 uint32_t supp, acc;
4174 int status;
4175
4176 status = decode_op_hdr(xdr, OP_ACCESS);
4177 if (status)
4178 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004179 p = xdr_inline_decode(xdr, 8);
4180 if (unlikely(!p))
4181 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004182 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004183 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004184 *supported = supp;
4185 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004187out_overflow:
4188 print_overflow_msg(__func__, xdr);
4189 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190}
4191
Benny Halevy07d30432009-08-14 17:19:52 +03004192static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193{
Al Viro8687b632006-10-19 23:28:48 -07004194 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004195
4196 p = xdr_inline_decode(xdr, len);
4197 if (likely(p)) {
4198 memcpy(buf, p, len);
4199 return 0;
4200 }
4201 print_overflow_msg(__func__, xdr);
4202 return -EIO;
4203}
4204
4205static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4206{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004207 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208}
4209
4210static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4211{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 int status;
4213
4214 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004215 if (status != -EIO)
4216 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004217 if (!status)
4218 status = decode_stateid(xdr, &res->stateid);
4219 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220}
4221
Benny Halevydb942bb2009-08-14 17:19:56 +03004222static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4223{
Chuck Levercd937102012-03-02 17:14:31 -05004224 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225}
4226
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004227static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4228{
4229 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4230}
4231
Fred Isaman0b7c0152012-04-20 14:47:39 -04004232static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 int status;
4235
4236 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004237 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004238 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004239 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240}
4241
4242static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4243{
Al Viro8687b632006-10-19 23:28:48 -07004244 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 uint32_t bmlen;
4246 int status;
4247
4248 status = decode_op_hdr(xdr, OP_CREATE);
4249 if (status)
4250 return status;
4251 if ((status = decode_change_info(xdr, cinfo)))
4252 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004253 p = xdr_inline_decode(xdr, 4);
4254 if (unlikely(!p))
4255 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004256 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004257 p = xdr_inline_decode(xdr, bmlen << 2);
4258 if (likely(p))
4259 return 0;
4260out_overflow:
4261 print_overflow_msg(__func__, xdr);
4262 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263}
4264
4265static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4266{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004267 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004268 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 int status;
4270
4271 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4272 goto xdr_error;
4273 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4274 goto xdr_error;
4275 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4276 goto xdr_error;
4277 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4278 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004279 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4280 &res->fh_expire_type)) != 0)
4281 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4283 goto xdr_error;
4284 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4285 goto xdr_error;
4286 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4287 goto xdr_error;
4288 status = verify_attr_len(xdr, savep, attrlen);
4289xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004290 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291 return status;
4292}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004293
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4295{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004296 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004297 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004299
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4301 goto xdr_error;
4302 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4303 goto xdr_error;
4304 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4305 goto xdr_error;
4306
4307 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4308 goto xdr_error;
4309 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4310 goto xdr_error;
4311 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4312 goto xdr_error;
4313 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4314 goto xdr_error;
4315 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4316 goto xdr_error;
4317 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4318 goto xdr_error;
4319
4320 status = verify_attr_len(xdr, savep, attrlen);
4321xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004322 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 return status;
4324}
4325
4326static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4327{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004328 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004329 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004331
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4333 goto xdr_error;
4334 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4335 goto xdr_error;
4336 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4337 goto xdr_error;
4338
4339 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4340 goto xdr_error;
4341 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4342 goto xdr_error;
4343
4344 status = verify_attr_len(xdr, savep, attrlen);
4345xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004346 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347 return status;
4348}
4349
Andy Adamson88034c32012-05-23 05:02:34 -04004350static int decode_threshold_hint(struct xdr_stream *xdr,
4351 uint32_t *bitmap,
4352 uint64_t *res,
4353 uint32_t hint_bit)
4354{
4355 __be32 *p;
4356
4357 *res = 0;
4358 if (likely(bitmap[0] & hint_bit)) {
4359 p = xdr_inline_decode(xdr, 8);
4360 if (unlikely(!p))
4361 goto out_overflow;
4362 xdr_decode_hyper(p, res);
4363 }
4364 return 0;
4365out_overflow:
4366 print_overflow_msg(__func__, xdr);
4367 return -EIO;
4368}
4369
4370static int decode_first_threshold_item4(struct xdr_stream *xdr,
4371 struct nfs4_threshold *res)
4372{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004373 __be32 *p;
4374 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004375 uint32_t bitmap[3] = {0,}, attrlen;
4376 int status;
4377
4378 /* layout type */
4379 p = xdr_inline_decode(xdr, 4);
4380 if (unlikely(!p)) {
4381 print_overflow_msg(__func__, xdr);
4382 return -EIO;
4383 }
4384 res->l_type = be32_to_cpup(p);
4385
4386 /* thi_hintset bitmap */
4387 status = decode_attr_bitmap(xdr, bitmap);
4388 if (status < 0)
4389 goto xdr_error;
4390
4391 /* thi_hintlist length */
4392 status = decode_attr_length(xdr, &attrlen, &savep);
4393 if (status < 0)
4394 goto xdr_error;
4395 /* thi_hintlist */
4396 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4397 if (status < 0)
4398 goto xdr_error;
4399 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4400 if (status < 0)
4401 goto xdr_error;
4402 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4403 THRESHOLD_RD_IO);
4404 if (status < 0)
4405 goto xdr_error;
4406 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4407 THRESHOLD_WR_IO);
4408 if (status < 0)
4409 goto xdr_error;
4410
4411 status = verify_attr_len(xdr, savep, attrlen);
4412 res->bm = bitmap[0];
4413
4414 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4415 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4416 res->wr_io_sz);
4417xdr_error:
4418 dprintk("%s ret=%d!\n", __func__, status);
4419 return status;
4420}
4421
4422/*
4423 * Thresholds on pNFS direct I/O vrs MDS I/O
4424 */
4425static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4426 uint32_t *bitmap,
4427 struct nfs4_threshold *res)
4428{
4429 __be32 *p;
4430 int status = 0;
4431 uint32_t num;
4432
4433 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4434 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004435 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004436 /* Did the server return an unrequested attribute? */
4437 if (unlikely(res == NULL))
4438 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004439 p = xdr_inline_decode(xdr, 4);
4440 if (unlikely(!p))
4441 goto out_overflow;
4442 num = be32_to_cpup(p);
4443 if (num == 0)
4444 return 0;
4445 if (num > 1)
4446 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4447 "drivers per filesystem not supported\n",
4448 __func__);
4449
4450 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004451 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004452 }
4453 return status;
4454out_overflow:
4455 print_overflow_msg(__func__, xdr);
4456 return -EIO;
4457}
4458
Bryan Schumakerae42c702010-10-21 16:33:17 -04004459static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4460 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004461 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004462 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463{
Trond Myklebustbca79472009-03-11 14:10:26 -04004464 int status;
4465 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004466 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004467 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004469 status = decode_attr_type(xdr, bitmap, &type);
4470 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004471 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004472 fattr->mode = 0;
4473 if (status != 0) {
4474 fattr->mode |= nfs_type2fmt[type];
4475 fattr->valid |= status;
4476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004478 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4479 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004481 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004482
4483 status = decode_attr_size(xdr, bitmap, &fattr->size);
4484 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004486 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004487
4488 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4489 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004491 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004492
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004493 err = 0;
4494 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004495 if (status < 0)
4496 goto xdr_error;
4497
4498 status = decode_attr_filehandle(xdr, bitmap, fh);
4499 if (status < 0)
4500 goto xdr_error;
4501
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004502 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4503 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004504 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004505 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004506
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004507 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004508 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004509 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004510 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004511
4512 status = decode_attr_mode(xdr, bitmap, &fmode);
4513 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004515 if (status != 0) {
4516 fattr->mode |= fmode;
4517 fattr->valid |= status;
4518 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004519
4520 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4521 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004523 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004524
Trond Myklebust6926afd2012-01-07 13:22:46 -05004525 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004526 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004528 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004529
Trond Myklebust6926afd2012-01-07 13:22:46 -05004530 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004531 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004533 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004534
4535 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4536 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004538 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004539
4540 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4541 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004542 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004543 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004544
4545 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4546 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004548 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004549
4550 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4551 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004553 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004554
4555 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4556 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004558 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004559
Trond Myklebust28331a42011-04-27 13:47:52 -04004560 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004561 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004562 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004563 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004564
Andy Adamson88034c32012-05-23 05:02:34 -04004565 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4566 if (status < 0)
4567 goto xdr_error;
4568
David Quigleyaa9c2662013-05-22 12:50:44 -04004569 if (label) {
4570 status = decode_attr_security_label(xdr, bitmap, label);
4571 if (status < 0)
4572 goto xdr_error;
4573 fattr->valid |= status;
4574 }
4575
Bryan Schumakerae42c702010-10-21 16:33:17 -04004576xdr_error:
4577 dprintk("%s: xdr returned %d\n", __func__, -status);
4578 return status;
4579}
4580
4581static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004582 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004583 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004584{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004585 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004586 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004587 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004588 int status;
4589
4590 status = decode_op_hdr(xdr, OP_GETATTR);
4591 if (status < 0)
4592 goto xdr_error;
4593
4594 status = decode_attr_bitmap(xdr, bitmap);
4595 if (status < 0)
4596 goto xdr_error;
4597
4598 status = decode_attr_length(xdr, &attrlen, &savep);
4599 if (status < 0)
4600 goto xdr_error;
4601
David Quigleyaa9c2662013-05-22 12:50:44 -04004602 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4603 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004604 if (status < 0)
4605 goto xdr_error;
4606
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004607 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004609 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 return status;
4611}
4612
David Quigleyaa9c2662013-05-22 12:50:44 -04004613static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4614 struct nfs4_label *label, const struct nfs_server *server)
4615{
4616 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4617}
4618
Bryan Schumakerae42c702010-10-21 16:33:17 -04004619static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004620 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004621{
David Quigleyaa9c2662013-05-22 12:50:44 -04004622 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004623}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624
Andy Adamson504913f2010-10-20 00:17:57 -04004625/*
4626 * Decode potentially multiple layout types. Currently we only support
4627 * one layout driver per file system.
4628 */
4629static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4630 uint32_t *layouttype)
4631{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004632 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004633 int num;
4634
4635 p = xdr_inline_decode(xdr, 4);
4636 if (unlikely(!p))
4637 goto out_overflow;
4638 num = be32_to_cpup(p);
4639
4640 /* pNFS is not supported by the underlying file system */
4641 if (num == 0) {
4642 *layouttype = 0;
4643 return 0;
4644 }
4645 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004646 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4647 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004648
4649 /* Decode and set first layout type, move xdr->p past unused types */
4650 p = xdr_inline_decode(xdr, num * 4);
4651 if (unlikely(!p))
4652 goto out_overflow;
4653 *layouttype = be32_to_cpup(p);
4654 return 0;
4655out_overflow:
4656 print_overflow_msg(__func__, xdr);
4657 return -EIO;
4658}
4659
4660/*
4661 * The type of file system exported.
4662 * Note we must ensure that layouttype is set in any non-error case.
4663 */
4664static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4665 uint32_t *layouttype)
4666{
4667 int status = 0;
4668
4669 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4670 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4671 return -EIO;
4672 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4673 status = decode_first_pnfs_layout_type(xdr, layouttype);
4674 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4675 } else
4676 *layouttype = 0;
4677 return status;
4678}
4679
Fred Isamandae100c2011-07-30 20:52:37 -04004680/*
4681 * The prefered block size for layout directed io
4682 */
4683static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4684 uint32_t *res)
4685{
4686 __be32 *p;
4687
4688 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4689 *res = 0;
4690 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4691 p = xdr_inline_decode(xdr, 4);
4692 if (unlikely(!p)) {
4693 print_overflow_msg(__func__, xdr);
4694 return -EIO;
4695 }
4696 *res = be32_to_cpup(p);
4697 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4698 }
4699 return 0;
4700}
4701
Linus Torvalds1da177e2005-04-16 15:20:36 -07004702static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4703{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004704 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004705 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706 int status;
4707
4708 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4709 goto xdr_error;
4710 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4711 goto xdr_error;
4712 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4713 goto xdr_error;
4714
4715 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4716
4717 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4718 goto xdr_error;
4719 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4720 goto xdr_error;
4721 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4722 goto xdr_error;
4723 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4724 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4725 goto xdr_error;
4726 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004727 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4728 if (status != 0)
4729 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004730 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4731 if (status != 0)
4732 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004733 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4734 if (status)
4735 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736
4737 status = verify_attr_len(xdr, savep, attrlen);
4738xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004739 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 return status;
4741}
4742
4743static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4744{
Al Viro8687b632006-10-19 23:28:48 -07004745 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746 uint32_t len;
4747 int status;
4748
Trond Myklebust99367812007-07-17 21:52:41 -04004749 /* Zero handle first to allow comparisons */
4750 memset(fh, 0, sizeof(*fh));
4751
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752 status = decode_op_hdr(xdr, OP_GETFH);
4753 if (status)
4754 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755
Benny Halevyc0eae662009-08-14 17:20:14 +03004756 p = xdr_inline_decode(xdr, 4);
4757 if (unlikely(!p))
4758 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004759 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 if (len > NFS4_FHSIZE)
4761 return -EIO;
4762 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004763 p = xdr_inline_decode(xdr, len);
4764 if (unlikely(!p))
4765 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004766 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004768out_overflow:
4769 print_overflow_msg(__func__, xdr);
4770 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771}
4772
4773static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4774{
4775 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004776
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777 status = decode_op_hdr(xdr, OP_LINK);
4778 if (status)
4779 return status;
4780 return decode_change_info(xdr, cinfo);
4781}
4782
4783/*
4784 * We create the owner, so we know a proper owner.id length is 4.
4785 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004786static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004788 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004789 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004790 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004792 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004793 if (unlikely(!p))
4794 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004795 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004796 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004797 type = be32_to_cpup(p++); /* 4 byte read */
4798 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004799 fl->fl_start = (loff_t)offset;
4800 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4801 if (length == ~(uint64_t)0)
4802 fl->fl_end = OFFSET_MAX;
4803 fl->fl_type = F_WRLCK;
4804 if (type & 1)
4805 fl->fl_type = F_RDLCK;
4806 fl->fl_pid = 0;
4807 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004808 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4809 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4810 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004811 if (likely(p))
4812 return -NFS4ERR_DENIED;
4813out_overflow:
4814 print_overflow_msg(__func__, xdr);
4815 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816}
4817
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004818static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820 int status;
4821
4822 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004823 if (status == -EIO)
4824 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004826 status = decode_stateid(xdr, &res->stateid);
4827 if (unlikely(status))
4828 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004830 status = decode_lock_denied(xdr, NULL);
4831 if (res->open_seqid != NULL)
4832 nfs_increment_open_seqid(status, res->open_seqid);
4833 nfs_increment_lock_seqid(status, res->lock_seqid);
4834out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835 return status;
4836}
4837
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004838static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839{
4840 int status;
4841 status = decode_op_hdr(xdr, OP_LOCKT);
4842 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004843 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 return status;
4845}
4846
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004847static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849 int status;
4850
4851 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004852 if (status != -EIO)
4853 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004854 if (status == 0)
4855 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856 return status;
4857}
4858
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004859static int decode_release_lockowner(struct xdr_stream *xdr)
4860{
4861 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4862}
4863
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864static int decode_lookup(struct xdr_stream *xdr)
4865{
4866 return decode_op_hdr(xdr, OP_LOOKUP);
4867}
4868
4869/* This is too sick! */
4870static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4871{
Andy Adamson05d564f2008-12-23 16:06:15 -05004872 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873 uint32_t limit_type, nblocks, blocksize;
4874
Benny Halevyc0eae662009-08-14 17:20:14 +03004875 p = xdr_inline_decode(xdr, 12);
4876 if (unlikely(!p))
4877 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004878 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004880 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004881 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004882 break;
4883 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004884 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004885 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004886 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 }
4888 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004889out_overflow:
4890 print_overflow_msg(__func__, xdr);
4891 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892}
4893
4894static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4895{
Andy Adamson05d564f2008-12-23 16:06:15 -05004896 __be32 *p;
4897 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004898 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899
Benny Halevyc0eae662009-08-14 17:20:14 +03004900 p = xdr_inline_decode(xdr, 4);
4901 if (unlikely(!p))
4902 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004903 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4905 res->delegation_type = 0;
4906 return 0;
4907 }
Benny Halevy07d30432009-08-14 17:19:52 +03004908 status = decode_stateid(xdr, &res->delegation);
4909 if (unlikely(status))
4910 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004911 p = xdr_inline_decode(xdr, 4);
4912 if (unlikely(!p))
4913 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004914 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004915
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004917 case NFS4_OPEN_DELEGATE_READ:
4918 res->delegation_type = FMODE_READ;
4919 break;
4920 case NFS4_OPEN_DELEGATE_WRITE:
4921 res->delegation_type = FMODE_WRITE|FMODE_READ;
4922 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923 return -EIO;
4924 }
David Howells7539bba2006-08-22 20:06:09 -04004925 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004926out_overflow:
4927 print_overflow_msg(__func__, xdr);
4928 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004929}
4930
4931static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4932{
Andy Adamson05d564f2008-12-23 16:06:15 -05004933 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004934 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004935 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936
Andy Adamson05d564f2008-12-23 16:06:15 -05004937 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004938 if (status != -EIO)
4939 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004940 if (!status)
4941 status = decode_stateid(xdr, &res->stateid);
4942 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004943 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944
Andy Adamson05d564f2008-12-23 16:06:15 -05004945 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946
Benny Halevyc0eae662009-08-14 17:20:14 +03004947 p = xdr_inline_decode(xdr, 8);
4948 if (unlikely(!p))
4949 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004950 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004951 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004952 if (bmlen > 10)
4953 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954
Benny Halevyc0eae662009-08-14 17:20:14 +03004955 p = xdr_inline_decode(xdr, bmlen << 2);
4956 if (unlikely(!p))
4957 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004958 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4959 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004960 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004961 for (; i < NFS4_BITMAP_SIZE; i++)
4962 res->attrset[i] = 0;
4963
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964 return decode_delegation(xdr, res);
4965xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004966 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004968out_overflow:
4969 print_overflow_msg(__func__, xdr);
4970 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971}
4972
4973static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4974{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975 int status;
4976
Andy Adamson05d564f2008-12-23 16:06:15 -05004977 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004978 if (status != -EIO)
4979 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004980 if (!status)
4981 status = decode_stateid(xdr, &res->stateid);
4982 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983}
4984
4985static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4986{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 int status;
4988
4989 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004990 if (status != -EIO)
4991 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004992 if (!status)
4993 status = decode_stateid(xdr, &res->stateid);
4994 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995}
4996
4997static int decode_putfh(struct xdr_stream *xdr)
4998{
4999 return decode_op_hdr(xdr, OP_PUTFH);
5000}
5001
5002static int decode_putrootfh(struct xdr_stream *xdr)
5003{
5004 return decode_op_hdr(xdr, OP_PUTROOTFH);
5005}
5006
5007static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
5008{
Al Viro8687b632006-10-19 23:28:48 -07005009 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005010 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011 int status;
5012
5013 status = decode_op_hdr(xdr, OP_READ);
5014 if (status)
5015 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005016 p = xdr_inline_decode(xdr, 8);
5017 if (unlikely(!p))
5018 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005019 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005020 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005021 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005023 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024 "count %u > recvd %u\n", count, recvd);
5025 count = recvd;
5026 eof = 0;
5027 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028 res->eof = eof;
5029 res->count = count;
5030 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005031out_overflow:
5032 print_overflow_msg(__func__, xdr);
5033 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034}
5035
5036static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5037{
Chuck Leverbcecff72007-10-26 13:32:03 -04005038 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005039 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005040
5041 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005042 if (!status)
5043 status = decode_verifier(xdr, readdir->verifier.data);
5044 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005046 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005047 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005048 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005049 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050}
5051
5052static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5053{
5054 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005055 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005056 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057 int status;
5058
5059 status = decode_op_hdr(xdr, OP_READLINK);
5060 if (status)
5061 return status;
5062
5063 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005064 p = xdr_inline_decode(xdr, 4);
5065 if (unlikely(!p))
5066 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005067 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005069 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005070 return -ENAMETOOLONG;
5071 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005072 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005074 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075 "count %u > recvd %u\n", len, recvd);
5076 return -EIO;
5077 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078 /*
5079 * The XDR encode routine has set things up so that
5080 * the link text will be copied directly into the
5081 * buffer. We just have to do overflow-checking,
5082 * and and null-terminate the text (the VFS expects
5083 * null-termination).
5084 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005085 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005087out_overflow:
5088 print_overflow_msg(__func__, xdr);
5089 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090}
5091
5092static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5093{
5094 int status;
5095
5096 status = decode_op_hdr(xdr, OP_REMOVE);
5097 if (status)
5098 goto out;
5099 status = decode_change_info(xdr, cinfo);
5100out:
5101 return status;
5102}
5103
5104static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5105 struct nfs4_change_info *new_cinfo)
5106{
5107 int status;
5108
5109 status = decode_op_hdr(xdr, OP_RENAME);
5110 if (status)
5111 goto out;
5112 if ((status = decode_change_info(xdr, old_cinfo)))
5113 goto out;
5114 status = decode_change_info(xdr, new_cinfo);
5115out:
5116 return status;
5117}
5118
5119static int decode_renew(struct xdr_stream *xdr)
5120{
5121 return decode_op_hdr(xdr, OP_RENEW);
5122}
5123
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005124static int
5125decode_restorefh(struct xdr_stream *xdr)
5126{
5127 return decode_op_hdr(xdr, OP_RESTOREFH);
5128}
5129
J. Bruce Fields029d1052005-06-22 17:16:22 +00005130static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005131 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005132{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005133 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005134 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005135 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005136 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005137 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005138
Andy Adamsonbf118a32011-12-07 11:55:27 -05005139 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005140 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5141 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005142
Trond Myklebust519d3952012-08-14 17:30:10 -04005143 xdr_enter_page(xdr, xdr->buf->page_len);
5144
Trond Myklebustcff298c2012-08-14 17:14:17 -04005145 /* Calculate the offset of the page data */
5146 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005147
J. Bruce Fields029d1052005-06-22 17:16:22 +00005148 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5149 goto out;
5150 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5151 goto out;
5152
5153 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5154 return -EIO;
5155 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005156
Andy Adamsonbf118a32011-12-07 11:55:27 -05005157 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5158 * are stored with the acl data to handle the problem of
5159 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005160 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005161 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005162
5163 /* Check for receive buffer overflow */
5164 if (res->acl_len > (xdr->nwords << 2) ||
5165 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5166 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005167 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005168 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005169 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005170 } else
5171 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005172
5173out:
5174 return status;
5175}
5176
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177static int
5178decode_savefh(struct xdr_stream *xdr)
5179{
5180 return decode_op_hdr(xdr, OP_SAVEFH);
5181}
5182
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005183static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184{
Al Viro8687b632006-10-19 23:28:48 -07005185 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186 uint32_t bmlen;
5187 int status;
5188
Linus Torvalds1da177e2005-04-16 15:20:36 -07005189 status = decode_op_hdr(xdr, OP_SETATTR);
5190 if (status)
5191 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005192 p = xdr_inline_decode(xdr, 4);
5193 if (unlikely(!p))
5194 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005195 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005196 p = xdr_inline_decode(xdr, bmlen << 2);
5197 if (likely(p))
5198 return 0;
5199out_overflow:
5200 print_overflow_msg(__func__, xdr);
5201 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005202}
5203
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005204static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205{
Al Viro8687b632006-10-19 23:28:48 -07005206 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 uint32_t opnum;
5208 int32_t nfserr;
5209
Benny Halevyc0eae662009-08-14 17:20:14 +03005210 p = xdr_inline_decode(xdr, 8);
5211 if (unlikely(!p))
5212 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005213 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005215 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005216 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005217 return -EIO;
5218 }
Benny Halevycccddf42009-08-14 17:20:19 +03005219 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005221 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5222 if (unlikely(!p))
5223 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005224 p = xdr_decode_hyper(p, &res->clientid);
5225 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226 } else if (nfserr == NFSERR_CLID_INUSE) {
5227 uint32_t len;
5228
5229 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005230 p = xdr_inline_decode(xdr, 4);
5231 if (unlikely(!p))
5232 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005233 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005234 p = xdr_inline_decode(xdr, len);
5235 if (unlikely(!p))
5236 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005237
5238 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005239 p = xdr_inline_decode(xdr, 4);
5240 if (unlikely(!p))
5241 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005242 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005243 p = xdr_inline_decode(xdr, len);
5244 if (unlikely(!p))
5245 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246 return -NFSERR_CLID_INUSE;
5247 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005248 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249
5250 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005251out_overflow:
5252 print_overflow_msg(__func__, xdr);
5253 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254}
5255
5256static int decode_setclientid_confirm(struct xdr_stream *xdr)
5257{
5258 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5259}
5260
5261static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5262{
Al Viro8687b632006-10-19 23:28:48 -07005263 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264 int status;
5265
5266 status = decode_op_hdr(xdr, OP_WRITE);
5267 if (status)
5268 return status;
5269
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005270 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005271 if (unlikely(!p))
5272 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005273 res->count = be32_to_cpup(p++);
5274 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005275 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005276out_overflow:
5277 print_overflow_msg(__func__, xdr);
5278 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279}
5280
5281static int decode_delegreturn(struct xdr_stream *xdr)
5282{
5283 return decode_op_hdr(xdr, OP_DELEGRETURN);
5284}
5285
Chuck Leverfb15b262013-03-16 15:54:34 -04005286static int decode_secinfo_gss(struct xdr_stream *xdr,
5287 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005288{
Chuck Leverfb15b262013-03-16 15:54:34 -04005289 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005290 __be32 *p;
5291
5292 p = xdr_inline_decode(xdr, 4);
5293 if (unlikely(!p))
5294 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005295 oid_len = be32_to_cpup(p);
5296 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005297 goto out_err;
5298
Chuck Leverfb15b262013-03-16 15:54:34 -04005299 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005300 if (unlikely(!p))
5301 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005302 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5303 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005304
5305 p = xdr_inline_decode(xdr, 8);
5306 if (unlikely(!p))
5307 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005308 flavor->flavor_info.qop = be32_to_cpup(p++);
5309 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005310
5311 return 0;
5312
5313out_overflow:
5314 print_overflow_msg(__func__, xdr);
5315 return -EIO;
5316out_err:
5317 return -EINVAL;
5318}
5319
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005320static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005321{
Chuck Leverfb15b262013-03-16 15:54:34 -04005322 struct nfs4_secinfo4 *sec_flavor;
5323 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005324 int status;
5325 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005326
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005327 p = xdr_inline_decode(xdr, 4);
5328 if (unlikely(!p))
5329 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005330
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005331 res->flavors->num_flavors = 0;
5332 num_flavors = be32_to_cpup(p);
5333
5334 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005335 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005336 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005337 break;
5338
5339 p = xdr_inline_decode(xdr, 4);
5340 if (unlikely(!p))
5341 goto out_overflow;
5342 sec_flavor->flavor = be32_to_cpup(p);
5343
5344 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005345 status = decode_secinfo_gss(xdr, sec_flavor);
5346 if (status)
5347 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005348 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005349 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005350 }
5351
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005352 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005353out:
5354 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005355out_overflow:
5356 print_overflow_msg(__func__, xdr);
5357 return -EIO;
5358}
5359
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005360static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5361{
5362 int status = decode_op_hdr(xdr, OP_SECINFO);
5363 if (status)
5364 return status;
5365 return decode_secinfo_common(xdr, res);
5366}
5367
Benny Halevy99fe60d2009-04-01 09:22:29 -04005368#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005369static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5370{
5371 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5372 if (status)
5373 return status;
5374 return decode_secinfo_common(xdr, res);
5375}
5376
Benny Halevy99fe60d2009-04-01 09:22:29 -04005377static int decode_exchange_id(struct xdr_stream *xdr,
5378 struct nfs41_exchange_id_res *res)
5379{
5380 __be32 *p;
5381 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005382 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005383 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005384 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005385
5386 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5387 if (status)
5388 return status;
5389
Benny Halevyc0eae662009-08-14 17:20:14 +03005390 p = xdr_inline_decode(xdr, 8);
5391 if (unlikely(!p))
5392 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005393 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005394 p = xdr_inline_decode(xdr, 12);
5395 if (unlikely(!p))
5396 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005397 res->seqid = be32_to_cpup(p++);
5398 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005399
5400 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005401 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005402 if (dummy != SP4_NONE)
5403 return -EIO;
5404
Chuck Leveracdeb692012-05-21 22:46:16 -04005405 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005406 p = xdr_inline_decode(xdr, 8);
5407 if (unlikely(!p))
5408 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005409 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005410
Chuck Leveracdeb692012-05-21 22:46:16 -04005411 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005412 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5413 if (unlikely(status))
5414 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005415 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5416 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005417 memcpy(res->server_owner->major_id, dummy_str, dummy);
5418 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005419
Chuck Leveracdeb692012-05-21 22:46:16 -04005420 /* server_scope4 */
5421 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5422 if (unlikely(status))
5423 return status;
5424 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5425 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005426 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5427 res->server_scope->server_scope_sz = dummy;
5428
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005429 /* Implementation Id */
5430 p = xdr_inline_decode(xdr, 4);
5431 if (unlikely(!p))
5432 goto out_overflow;
5433 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005434
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005435 if (impl_id_count) {
5436 /* nii_domain */
5437 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5438 if (unlikely(status))
5439 return status;
5440 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5441 return -EIO;
5442 memcpy(res->impl_id->domain, dummy_str, dummy);
5443
5444 /* nii_name */
5445 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5446 if (unlikely(status))
5447 return status;
5448 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5449 return -EIO;
5450 memcpy(res->impl_id->name, dummy_str, dummy);
5451
5452 /* nii_date */
5453 p = xdr_inline_decode(xdr, 12);
5454 if (unlikely(!p))
5455 goto out_overflow;
5456 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5457 res->impl_id->date.nseconds = be32_to_cpup(p);
5458
5459 /* if there's more than one entry, ignore the rest */
5460 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005461 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005462out_overflow:
5463 print_overflow_msg(__func__, xdr);
5464 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005465}
Andy Adamsonfc931582009-04-01 09:22:31 -04005466
5467static int decode_chan_attrs(struct xdr_stream *xdr,
5468 struct nfs4_channel_attrs *attrs)
5469{
5470 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005471 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005472
Benny Halevyc0eae662009-08-14 17:20:14 +03005473 p = xdr_inline_decode(xdr, 28);
5474 if (unlikely(!p))
5475 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005476 val = be32_to_cpup(p++); /* headerpadsz */
5477 if (val)
5478 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005479 attrs->max_rqst_sz = be32_to_cpup(p++);
5480 attrs->max_resp_sz = be32_to_cpup(p++);
5481 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5482 attrs->max_ops = be32_to_cpup(p++);
5483 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005484 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005485 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005486 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5487 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005488 return -EINVAL;
5489 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005490 if (nr_attrs == 1) {
5491 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5492 if (unlikely(!p))
5493 goto out_overflow;
5494 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005495 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005496out_overflow:
5497 print_overflow_msg(__func__, xdr);
5498 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005499}
5500
Benny Halevye78291e2009-08-14 17:20:00 +03005501static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5502{
5503 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005504}
5505
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005506static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5507 struct nfs41_bind_conn_to_session_res *res)
5508{
5509 __be32 *p;
5510 int status;
5511
5512 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5513 if (!status)
5514 status = decode_sessionid(xdr, &res->session->sess_id);
5515 if (unlikely(status))
5516 return status;
5517
5518 /* dir flags, rdma mode bool */
5519 p = xdr_inline_decode(xdr, 8);
5520 if (unlikely(!p))
5521 goto out_overflow;
5522
5523 res->dir = be32_to_cpup(p++);
5524 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5525 return -EIO;
5526 if (be32_to_cpup(p) == 0)
5527 res->use_conn_in_rdma_mode = false;
5528 else
5529 res->use_conn_in_rdma_mode = true;
5530
5531 return 0;
5532out_overflow:
5533 print_overflow_msg(__func__, xdr);
5534 return -EIO;
5535}
5536
Andy Adamsonfc931582009-04-01 09:22:31 -04005537static int decode_create_session(struct xdr_stream *xdr,
5538 struct nfs41_create_session_res *res)
5539{
5540 __be32 *p;
5541 int status;
5542 struct nfs_client *clp = res->client;
5543 struct nfs4_session *session = clp->cl_session;
5544
5545 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005546 if (!status)
5547 status = decode_sessionid(xdr, &session->sess_id);
5548 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005549 return status;
5550
Andy Adamsonfc931582009-04-01 09:22:31 -04005551 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005552 p = xdr_inline_decode(xdr, 8);
5553 if (unlikely(!p))
5554 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005555 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005556 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005557
5558 /* Channel attributes */
5559 status = decode_chan_attrs(xdr, &session->fc_attrs);
5560 if (!status)
5561 status = decode_chan_attrs(xdr, &session->bc_attrs);
5562 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005563out_overflow:
5564 print_overflow_msg(__func__, xdr);
5565 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005566}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005567
5568static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5569{
5570 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5571}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005572
Trond Myklebust66245532012-05-25 17:18:09 -04005573static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5574{
5575 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5576}
5577
Ricardo Labiaga180197532009-12-05 16:08:40 -05005578static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5579{
5580 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5581}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005582#endif /* CONFIG_NFS_V4_1 */
5583
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005584static int decode_sequence(struct xdr_stream *xdr,
5585 struct nfs4_sequence_res *res,
5586 struct rpc_rqst *rqstp)
5587{
5588#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005589 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005590 struct nfs4_sessionid id;
5591 u32 dummy;
5592 int status;
5593 __be32 *p;
5594
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005595 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005596 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005597 if (!res->sr_slot->table->session)
5598 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005599
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005600 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005601 if (!status)
5602 status = decode_sessionid(xdr, &id);
5603 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005604 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005605
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005606 /*
5607 * If the server returns different values for sessionID, slotID or
5608 * sequence number, the server is looney tunes.
5609 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005610 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005611 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005612
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005613 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005614 NFS4_MAX_SESSIONID_LEN)) {
5615 dprintk("%s Invalid session id\n", __func__);
5616 goto out_err;
5617 }
Benny Halevye78291e2009-08-14 17:20:00 +03005618
Benny Halevyc0eae662009-08-14 17:20:14 +03005619 p = xdr_inline_decode(xdr, 20);
5620 if (unlikely(!p))
5621 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005622
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005623 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005624 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005625 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005626 dprintk("%s Invalid sequence number\n", __func__);
5627 goto out_err;
5628 }
5629 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005630 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005631 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005632 dprintk("%s Invalid slot id\n", __func__);
5633 goto out_err;
5634 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005635 /* highest slot id */
5636 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005637 /* target highest slot id */
5638 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005639 /* result flags */
5640 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005641 status = 0;
5642out_err:
5643 res->sr_status = status;
5644 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005645out_overflow:
5646 print_overflow_msg(__func__, xdr);
5647 status = -EIO;
5648 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005649#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005650 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005651#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005652}
5653
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005654#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005655/*
5656 * TODO: Need to handle case when EOF != true;
5657 */
5658static int decode_getdevicelist(struct xdr_stream *xdr,
5659 struct pnfs_devicelist *res)
5660{
5661 __be32 *p;
5662 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005663 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005664
5665 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5666 if (status)
5667 return status;
5668
5669 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5670 if (unlikely(!p))
5671 goto out_overflow;
5672
5673 /* TODO: Skip cookie for now */
5674 p += 2;
5675
5676 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005677 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005678
5679 res->num_devs = be32_to_cpup(p);
5680
5681 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5682
5683 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005684 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005685 __func__, res->num_devs);
5686 return -EIO;
5687 }
5688
5689 p = xdr_inline_decode(xdr,
5690 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5691 if (unlikely(!p))
5692 goto out_overflow;
5693 for (i = 0; i < res->num_devs; i++)
5694 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5695 NFS4_DEVICEID4_SIZE);
5696 res->eof = be32_to_cpup(p);
5697 return 0;
5698out_overflow:
5699 print_overflow_msg(__func__, xdr);
5700 return -EIO;
5701}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005702
5703static int decode_getdeviceinfo(struct xdr_stream *xdr,
5704 struct pnfs_device *pdev)
5705{
5706 __be32 *p;
5707 uint32_t len, type;
5708 int status;
5709
5710 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5711 if (status) {
5712 if (status == -ETOOSMALL) {
5713 p = xdr_inline_decode(xdr, 4);
5714 if (unlikely(!p))
5715 goto out_overflow;
5716 pdev->mincount = be32_to_cpup(p);
5717 dprintk("%s: Min count too small. mincnt = %u\n",
5718 __func__, pdev->mincount);
5719 }
5720 return status;
5721 }
5722
5723 p = xdr_inline_decode(xdr, 8);
5724 if (unlikely(!p))
5725 goto out_overflow;
5726 type = be32_to_cpup(p++);
5727 if (type != pdev->layout_type) {
5728 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5729 __func__, pdev->layout_type, type);
5730 return -EINVAL;
5731 }
5732 /*
5733 * Get the length of the opaque device_addr4. xdr_read_pages places
5734 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5735 * and places the remaining xdr data in xdr_buf->tail
5736 */
5737 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005738 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5739 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005740
5741 /* Parse notification bitmap, verifying that it is zero. */
5742 p = xdr_inline_decode(xdr, 4);
5743 if (unlikely(!p))
5744 goto out_overflow;
5745 len = be32_to_cpup(p);
5746 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005747 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005748
5749 p = xdr_inline_decode(xdr, 4 * len);
5750 if (unlikely(!p))
5751 goto out_overflow;
5752 for (i = 0; i < len; i++, p++) {
5753 if (be32_to_cpup(p)) {
5754 dprintk("%s: notifications not supported\n",
5755 __func__);
5756 return -EIO;
5757 }
5758 }
5759 }
5760 return 0;
5761out_overflow:
5762 print_overflow_msg(__func__, xdr);
5763 return -EIO;
5764}
5765
5766static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5767 struct nfs4_layoutget_res *res)
5768{
5769 __be32 *p;
5770 int status;
5771 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005772 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005773
5774 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5775 if (status)
5776 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005777 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005778 if (unlikely(!p))
5779 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005780 res->return_on_close = be32_to_cpup(p);
5781 decode_stateid(xdr, &res->stateid);
5782 p = xdr_inline_decode(xdr, 4);
5783 if (unlikely(!p))
5784 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005785 layout_count = be32_to_cpup(p);
5786 if (!layout_count) {
5787 dprintk("%s: server responded with empty layout array\n",
5788 __func__);
5789 return -EINVAL;
5790 }
5791
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005792 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005793 if (unlikely(!p))
5794 goto out_overflow;
5795 p = xdr_decode_hyper(p, &res->range.offset);
5796 p = xdr_decode_hyper(p, &res->range.length);
5797 res->range.iomode = be32_to_cpup(p++);
5798 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005799 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005800
5801 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5802 __func__,
5803 (unsigned long)res->range.offset,
5804 (unsigned long)res->range.length,
5805 res->range.iomode,
5806 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005807 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005808
Trond Myklebust64bd5772012-06-20 22:35:05 -04005809 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005810 if (res->layoutp->len > recvd) {
5811 dprintk("NFS: server cheating in layoutget reply: "
5812 "layout len %u > recvd %u\n",
5813 res->layoutp->len, recvd);
5814 return -EINVAL;
5815 }
5816
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005817 if (layout_count > 1) {
5818 /* We only handle a length one array at the moment. Any
5819 * further entries are just ignored. Note that this means
5820 * the client may see a response that is less than the
5821 * minimum it requested.
5822 */
5823 dprintk("%s: server responded with %d layouts, dropping tail\n",
5824 __func__, layout_count);
5825 }
5826
5827 return 0;
5828out_overflow:
5829 print_overflow_msg(__func__, xdr);
5830 return -EIO;
5831}
Andy Adamson863a3c62011-03-23 13:27:54 +00005832
Benny Halevycbe82602011-05-22 19:52:37 +03005833static int decode_layoutreturn(struct xdr_stream *xdr,
5834 struct nfs4_layoutreturn_res *res)
5835{
5836 __be32 *p;
5837 int status;
5838
5839 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5840 if (status)
5841 return status;
5842 p = xdr_inline_decode(xdr, 4);
5843 if (unlikely(!p))
5844 goto out_overflow;
5845 res->lrs_present = be32_to_cpup(p);
5846 if (res->lrs_present)
5847 status = decode_stateid(xdr, &res->stateid);
5848 return status;
5849out_overflow:
5850 print_overflow_msg(__func__, xdr);
5851 return -EIO;
5852}
5853
Andy Adamson863a3c62011-03-23 13:27:54 +00005854static int decode_layoutcommit(struct xdr_stream *xdr,
5855 struct rpc_rqst *req,
5856 struct nfs4_layoutcommit_res *res)
5857{
5858 __be32 *p;
5859 __u32 sizechanged;
5860 int status;
5861
5862 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005863 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005864 if (status)
5865 return status;
5866
5867 p = xdr_inline_decode(xdr, 4);
5868 if (unlikely(!p))
5869 goto out_overflow;
5870 sizechanged = be32_to_cpup(p);
5871
5872 if (sizechanged) {
5873 /* throw away new size */
5874 p = xdr_inline_decode(xdr, 8);
5875 if (unlikely(!p))
5876 goto out_overflow;
5877 }
5878 return 0;
5879out_overflow:
5880 print_overflow_msg(__func__, xdr);
5881 return -EIO;
5882}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005883
5884static int decode_test_stateid(struct xdr_stream *xdr,
5885 struct nfs41_test_stateid_res *res)
5886{
5887 __be32 *p;
5888 int status;
5889 int num_res;
5890
5891 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5892 if (status)
5893 return status;
5894
5895 p = xdr_inline_decode(xdr, 4);
5896 if (unlikely(!p))
5897 goto out_overflow;
5898 num_res = be32_to_cpup(p++);
5899 if (num_res != 1)
5900 goto out;
5901
5902 p = xdr_inline_decode(xdr, 4);
5903 if (unlikely(!p))
5904 goto out_overflow;
5905 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005906
5907 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005908out_overflow:
5909 print_overflow_msg(__func__, xdr);
5910out:
5911 return -EIO;
5912}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005913
5914static int decode_free_stateid(struct xdr_stream *xdr,
5915 struct nfs41_free_stateid_res *res)
5916{
5917 __be32 *p;
5918 int status;
5919
5920 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5921 if (status)
5922 return status;
5923
5924 p = xdr_inline_decode(xdr, 4);
5925 if (unlikely(!p))
5926 goto out_overflow;
5927 res->status = be32_to_cpup(p++);
5928 return res->status;
5929out_overflow:
5930 print_overflow_msg(__func__, xdr);
5931 return -EIO;
5932}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005933#endif /* CONFIG_NFS_V4_1 */
5934
Linus Torvalds1da177e2005-04-16 15:20:36 -07005935/*
Benny Halevy49c25592008-12-23 16:06:16 -05005936 * END OF "GENERIC" DECODE ROUTINES.
5937 */
5938
5939/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940 * Decode OPEN_DOWNGRADE response
5941 */
Chuck Leverbf269552010-12-14 14:59:29 +00005942static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5943 struct xdr_stream *xdr,
5944 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945{
Andy Adamson05d564f2008-12-23 16:06:15 -05005946 struct compound_hdr hdr;
5947 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948
Chuck Leverbf269552010-12-14 14:59:29 +00005949 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005950 if (status)
5951 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005952 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005953 if (status)
5954 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005955 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005956 if (status)
5957 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005958 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005959 if (status != 0)
5960 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005961 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005963 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005964}
5965
5966/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967 * Decode ACCESS response
5968 */
Chuck Leverbf269552010-12-14 14:59:29 +00005969static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5970 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972 struct compound_hdr hdr;
5973 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005974
Chuck Leverbf269552010-12-14 14:59:29 +00005975 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005976 if (status)
5977 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005978 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005979 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005980 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005981 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005982 if (status != 0)
5983 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04005984 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04005985 if (status != 0)
5986 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005987 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005988out:
5989 return status;
5990}
5991
5992/*
5993 * Decode LOOKUP response
5994 */
Chuck Leverbf269552010-12-14 14:59:29 +00005995static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5996 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005998 struct compound_hdr hdr;
5999 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006000
Chuck Leverbf269552010-12-14 14:59:29 +00006001 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006002 if (status)
6003 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006004 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006005 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006006 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006007 status = decode_putfh(xdr);
6008 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006009 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006010 status = decode_lookup(xdr);
6011 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006013 status = decode_getfh(xdr, res->fh);
6014 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006016 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006017out:
6018 return status;
6019}
6020
6021/*
6022 * Decode LOOKUP_ROOT response
6023 */
Chuck Leverbf269552010-12-14 14:59:29 +00006024static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6025 struct xdr_stream *xdr,
6026 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006027{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006028 struct compound_hdr hdr;
6029 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006030
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006032 if (status)
6033 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006035 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006036 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006037 status = decode_putrootfh(xdr);
6038 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006040 status = decode_getfh(xdr, res->fh);
6041 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006042 status = decode_getfattr_label(xdr, res->fattr,
6043 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044out:
6045 return status;
6046}
6047
6048/*
6049 * Decode REMOVE response
6050 */
Chuck Leverbf269552010-12-14 14:59:29 +00006051static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6052 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054 struct compound_hdr hdr;
6055 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006056
Chuck Leverbf269552010-12-14 14:59:29 +00006057 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006058 if (status)
6059 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006060 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006061 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006063 status = decode_putfh(xdr);
6064 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006065 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006066 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067out:
6068 return status;
6069}
6070
6071/*
6072 * Decode RENAME response
6073 */
Chuck Leverbf269552010-12-14 14:59:29 +00006074static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6075 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006076{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077 struct compound_hdr hdr;
6078 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006079
Chuck Leverbf269552010-12-14 14:59:29 +00006080 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006081 if (status)
6082 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006083 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006084 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006086 status = decode_putfh(xdr);
6087 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006088 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006089 status = decode_savefh(xdr);
6090 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006091 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006092 status = decode_putfh(xdr);
6093 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006095 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096out:
6097 return status;
6098}
6099
6100/*
6101 * Decode LINK response
6102 */
Chuck Leverbf269552010-12-14 14:59:29 +00006103static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6104 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006105{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106 struct compound_hdr hdr;
6107 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006108
Chuck Leverbf269552010-12-14 14:59:29 +00006109 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006110 if (status)
6111 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006112 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006113 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006115 status = decode_putfh(xdr);
6116 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006118 status = decode_savefh(xdr);
6119 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006120 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006121 status = decode_putfh(xdr);
6122 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006124 status = decode_link(xdr, &res->cinfo);
6125 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006126 goto out;
6127 /*
6128 * Note order: OP_LINK leaves the directory as the current
6129 * filehandle.
6130 */
Chuck Leverbf269552010-12-14 14:59:29 +00006131 status = decode_restorefh(xdr);
6132 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006133 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006134 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135out:
6136 return status;
6137}
6138
6139/*
6140 * Decode CREATE response
6141 */
Chuck Leverbf269552010-12-14 14:59:29 +00006142static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6143 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006144{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145 struct compound_hdr hdr;
6146 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006147
Chuck Leverbf269552010-12-14 14:59:29 +00006148 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006149 if (status)
6150 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006151 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006152 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006154 status = decode_putfh(xdr);
6155 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006157 status = decode_create(xdr, &res->dir_cinfo);
6158 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006159 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006160 status = decode_getfh(xdr, res->fh);
6161 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006163 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164out:
6165 return status;
6166}
6167
6168/*
6169 * Decode SYMLINK response
6170 */
Chuck Leverbf269552010-12-14 14:59:29 +00006171static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6172 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173{
Chuck Leverbf269552010-12-14 14:59:29 +00006174 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175}
6176
6177/*
6178 * Decode GETATTR response
6179 */
Chuck Leverbf269552010-12-14 14:59:29 +00006180static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6181 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183 struct compound_hdr hdr;
6184 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006185
Chuck Leverbf269552010-12-14 14:59:29 +00006186 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 if (status)
6188 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006189 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006190 if (status)
6191 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006192 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193 if (status)
6194 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006195 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196out:
6197 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198}
6199
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006200/*
6201 * Encode an SETACL request
6202 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006203static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6204 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006205{
Andy Adamson05d564f2008-12-23 16:06:15 -05006206 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006207 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006208 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006209
Chuck Lever9f06c712010-12-14 14:59:18 +00006210 encode_compound_hdr(xdr, req, &hdr);
6211 encode_sequence(xdr, &args->seq_args, &hdr);
6212 encode_putfh(xdr, args->fh, &hdr);
6213 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006214 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006215}
Andy Adamson05d564f2008-12-23 16:06:15 -05006216
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006217/*
6218 * Decode SETACL response
6219 */
6220static int
Chuck Leverbf269552010-12-14 14:59:29 +00006221nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006222 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006223{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006224 struct compound_hdr hdr;
6225 int status;
6226
Chuck Leverbf269552010-12-14 14:59:29 +00006227 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006228 if (status)
6229 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006230 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006231 if (status)
6232 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006233 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006234 if (status)
6235 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006236 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006237out:
6238 return status;
6239}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240
6241/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006242 * Decode GETACL response
6243 */
6244static int
Chuck Leverbf269552010-12-14 14:59:29 +00006245nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006246 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006247{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006248 struct compound_hdr hdr;
6249 int status;
6250
Trond Myklebust331818f2012-02-03 18:30:53 -05006251 if (res->acl_scratch != NULL) {
6252 void *p = page_address(res->acl_scratch);
6253 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6254 }
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006256 if (status)
6257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006259 if (status)
6260 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006262 if (status)
6263 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006264 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006265
6266out:
6267 return status;
6268}
6269
6270/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271 * Decode CLOSE response
6272 */
Chuck Leverbf269552010-12-14 14:59:29 +00006273static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6274 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006275{
Andy Adamson05d564f2008-12-23 16:06:15 -05006276 struct compound_hdr hdr;
6277 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006278
Chuck Leverbf269552010-12-14 14:59:29 +00006279 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006280 if (status)
6281 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006282 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006283 if (status)
6284 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006285 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006286 if (status)
6287 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006288 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006289 if (status != 0)
6290 goto out;
6291 /*
6292 * Note: Server may do delete on close for this file
6293 * in which case the getattr call will fail with
6294 * an ESTALE error. Shouldn't be a problem,
6295 * though, since fattr->valid will remain unset.
6296 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006297 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006299 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300}
6301
6302/*
6303 * Decode OPEN response
6304 */
Chuck Leverbf269552010-12-14 14:59:29 +00006305static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6306 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006307{
Andy Adamson05d564f2008-12-23 16:06:15 -05006308 struct compound_hdr hdr;
6309 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310
Chuck Leverbf269552010-12-14 14:59:29 +00006311 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006312 if (status)
6313 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006314 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006315 if (status)
6316 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006317 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006318 if (status)
6319 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006320 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006321 if (status)
6322 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006323 status = decode_getfh(xdr, &res->fh);
6324 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006326 if (res->access_request)
6327 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006328 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006330 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331}
6332
6333/*
6334 * Decode OPEN_CONFIRM response
6335 */
Chuck Leverbf269552010-12-14 14:59:29 +00006336static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6337 struct xdr_stream *xdr,
6338 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339{
Andy Adamson05d564f2008-12-23 16:06:15 -05006340 struct compound_hdr hdr;
6341 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342
Chuck Leverbf269552010-12-14 14:59:29 +00006343 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006344 if (status)
6345 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006346 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006347 if (status)
6348 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006349 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006351 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352}
6353
6354/*
6355 * Decode OPEN response
6356 */
Chuck Leverbf269552010-12-14 14:59:29 +00006357static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6358 struct xdr_stream *xdr,
6359 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006360{
Andy Adamson05d564f2008-12-23 16:06:15 -05006361 struct compound_hdr hdr;
6362 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006365 if (status)
6366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006368 if (status)
6369 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006371 if (status)
6372 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006373 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006374 if (status)
6375 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);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006378 decode_getfattr(xdr, res->f_attr, 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 SETATTR response
6385 */
Chuck Leverbf269552010-12-14 14:59:29 +00006386static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6387 struct xdr_stream *xdr,
6388 struct nfs_setattrres *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_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006397 if (status)
6398 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006399 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006400 if (status)
6401 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006402 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006403 if (status)
6404 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006405 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006407 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408}
6409
6410/*
6411 * Decode LOCK response
6412 */
Chuck Leverbf269552010-12-14 14:59:29 +00006413static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6414 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416 struct compound_hdr hdr;
6417 int status;
6418
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420 if (status)
6421 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006422 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006423 if (status)
6424 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006425 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426 if (status)
6427 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006428 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429out:
6430 return status;
6431}
6432
6433/*
6434 * Decode LOCKT response
6435 */
Chuck Leverbf269552010-12-14 14:59:29 +00006436static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6437 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439 struct compound_hdr hdr;
6440 int status;
6441
Chuck Leverbf269552010-12-14 14:59:29 +00006442 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443 if (status)
6444 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006445 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006446 if (status)
6447 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006449 if (status)
6450 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006451 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006452out:
6453 return status;
6454}
6455
6456/*
6457 * Decode LOCKU response
6458 */
Chuck Leverbf269552010-12-14 14:59:29 +00006459static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6460 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006462 struct compound_hdr hdr;
6463 int status;
6464
Chuck Leverbf269552010-12-14 14:59:29 +00006465 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466 if (status)
6467 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006468 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006469 if (status)
6470 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472 if (status)
6473 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006474 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475out:
6476 return status;
6477}
6478
Chuck Leverbf269552010-12-14 14:59:29 +00006479static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6480 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006481{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006482 struct compound_hdr hdr;
6483 int status;
6484
Chuck Leverbf269552010-12-14 14:59:29 +00006485 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006486 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006487 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006488 return status;
6489}
6490
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491/*
6492 * Decode READLINK response
6493 */
Chuck Leverbf269552010-12-14 14:59:29 +00006494static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6495 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006496 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498 struct compound_hdr hdr;
6499 int status;
6500
Chuck Leverbf269552010-12-14 14:59:29 +00006501 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502 if (status)
6503 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006504 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006505 if (status)
6506 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006507 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 if (status)
6509 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006510 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006511out:
6512 return status;
6513}
6514
6515/*
6516 * Decode READDIR response
6517 */
Chuck Leverbf269552010-12-14 14:59:29 +00006518static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6519 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006521 struct compound_hdr hdr;
6522 int status;
6523
Chuck Leverbf269552010-12-14 14:59:29 +00006524 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525 if (status)
6526 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006527 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006528 if (status)
6529 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006530 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006531 if (status)
6532 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006533 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006534out:
6535 return status;
6536}
6537
6538/*
6539 * Decode Read response
6540 */
Chuck Leverbf269552010-12-14 14:59:29 +00006541static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6542 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544 struct compound_hdr hdr;
6545 int status;
6546
Chuck Leverbf269552010-12-14 14:59:29 +00006547 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 if (status)
6549 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006550 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006551 if (status)
6552 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006553 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554 if (status)
6555 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006556 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006557 if (!status)
6558 status = res->count;
6559out:
6560 return status;
6561}
6562
6563/*
6564 * Decode WRITE response
6565 */
Chuck Leverbf269552010-12-14 14:59:29 +00006566static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6567 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569 struct compound_hdr hdr;
6570 int status;
6571
Chuck Leverbf269552010-12-14 14:59:29 +00006572 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573 if (status)
6574 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006575 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006576 if (status)
6577 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006578 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579 if (status)
6580 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006582 if (status)
6583 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006584 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006585 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006586 if (!status)
6587 status = res->count;
6588out:
6589 return status;
6590}
6591
6592/*
6593 * Decode COMMIT response
6594 */
Chuck Leverbf269552010-12-14 14:59:29 +00006595static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006596 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598 struct compound_hdr hdr;
6599 int status;
6600
Chuck Leverbf269552010-12-14 14:59:29 +00006601 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006602 if (status)
6603 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006604 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006605 if (status)
6606 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006607 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006608 if (status)
6609 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006610 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611out:
6612 return status;
6613}
6614
6615/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006616 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617 */
Chuck Leverbf269552010-12-14 14:59:29 +00006618static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006619 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006621 struct compound_hdr hdr;
6622 int status;
6623
Chuck Leverbf269552010-12-14 14:59:29 +00006624 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006627 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006628 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006630 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631 return status;
6632}
6633
6634/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006635 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636 */
Chuck Leverbf269552010-12-14 14:59:29 +00006637static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006638 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 struct compound_hdr hdr;
6641 int status;
6642
Chuck Leverbf269552010-12-14 14:59:29 +00006643 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006645 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006646 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006648 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006649 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650 return status;
6651}
6652
6653/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006654 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655 */
Chuck Leverbf269552010-12-14 14:59:29 +00006656static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006657 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006658{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659 struct compound_hdr hdr;
6660 int status;
6661
Chuck Leverbf269552010-12-14 14:59:29 +00006662 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006663 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006664 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006665 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006666 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006667 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006668 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669 return status;
6670}
6671
6672/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006673 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674 */
Chuck Leverbf269552010-12-14 14:59:29 +00006675static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6676 struct xdr_stream *xdr,
6677 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006678{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006679 struct compound_hdr hdr;
6680 int status;
6681
Chuck Leverbf269552010-12-14 14:59:29 +00006682 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006683 if (status)
6684 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006685 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006686 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006687 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_putfh(xdr);
6689 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006691 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006692out:
6693 return status;
6694}
6695
6696/*
6697 * Decode RENEW response
6698 */
Chuck Leverbf269552010-12-14 14:59:29 +00006699static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6700 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006701{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702 struct compound_hdr hdr;
6703 int status;
6704
Chuck Leverbf269552010-12-14 14:59:29 +00006705 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006706 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006707 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006708 return status;
6709}
6710
6711/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006712 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006713 */
Chuck Leverbf269552010-12-14 14:59:29 +00006714static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6715 struct xdr_stream *xdr,
6716 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006717{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006718 struct compound_hdr hdr;
6719 int status;
6720
Chuck Leverbf269552010-12-14 14:59:29 +00006721 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006722 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006723 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724 return status;
6725}
6726
6727/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006728 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006729 */
Chuck Leverbf269552010-12-14 14:59:29 +00006730static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006731 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006732{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006733 struct compound_hdr hdr;
6734 int status;
6735
Chuck Leverbf269552010-12-14 14:59:29 +00006736 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006737 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006738 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006739 return status;
6740}
6741
6742/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006743 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744 */
Chuck Leverbf269552010-12-14 14:59:29 +00006745static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6746 struct xdr_stream *xdr,
6747 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006748{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 struct compound_hdr hdr;
6750 int status;
6751
Chuck Leverbf269552010-12-14 14:59:29 +00006752 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006753 if (status)
6754 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006755 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006756 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006757 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006758 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006759 if (status != 0)
6760 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006761 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006762 if (status != 0)
6763 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006764 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006765out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766 return status;
6767}
6768
Trond Myklebust683b57b2006-06-09 09:34:22 -04006769/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006770 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006771 */
Chuck Leverbf269552010-12-14 14:59:29 +00006772static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6773 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006774 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006775{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006776 struct compound_hdr hdr;
6777 int status;
6778
Chuck Leverbf269552010-12-14 14:59:29 +00006779 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006780 if (status)
6781 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006782 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006783 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006784 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006785 status = decode_putfh(xdr);
6786 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006787 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006788 status = decode_lookup(xdr);
6789 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006790 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006791 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006792 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6793 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006794 NULL, res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006795out:
6796 return status;
6797}
6798
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006799/*
6800 * Decode SECINFO response
6801 */
6802static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6803 struct xdr_stream *xdr,
6804 struct nfs4_secinfo_res *res)
6805{
6806 struct compound_hdr hdr;
6807 int status;
6808
6809 status = decode_compound_hdr(xdr, &hdr);
6810 if (status)
6811 goto out;
6812 status = decode_sequence(xdr, &res->seq_res, rqstp);
6813 if (status)
6814 goto out;
6815 status = decode_putfh(xdr);
6816 if (status)
6817 goto out;
6818 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006819out:
6820 return status;
6821}
6822
Benny Halevy99fe60d2009-04-01 09:22:29 -04006823#if defined(CONFIG_NFS_V4_1)
6824/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006825 * Decode BIND_CONN_TO_SESSION response
6826 */
6827static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6828 struct xdr_stream *xdr,
6829 void *res)
6830{
6831 struct compound_hdr hdr;
6832 int status;
6833
6834 status = decode_compound_hdr(xdr, &hdr);
6835 if (!status)
6836 status = decode_bind_conn_to_session(xdr, res);
6837 return status;
6838}
6839
6840/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006841 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006842 */
Chuck Leverbf269552010-12-14 14:59:29 +00006843static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6844 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006845 void *res)
6846{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006847 struct compound_hdr hdr;
6848 int status;
6849
Chuck Leverbf269552010-12-14 14:59:29 +00006850 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006851 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006852 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006853 return status;
6854}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006855
6856/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006857 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006858 */
Chuck Leverbf269552010-12-14 14:59:29 +00006859static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6860 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006861 struct nfs41_create_session_res *res)
6862{
Andy Adamsonfc931582009-04-01 09:22:31 -04006863 struct compound_hdr hdr;
6864 int status;
6865
Chuck Leverbf269552010-12-14 14:59:29 +00006866 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006867 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006868 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006869 return status;
6870}
6871
6872/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006873 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006874 */
Chuck Leverbf269552010-12-14 14:59:29 +00006875static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6876 struct xdr_stream *xdr,
6877 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006878{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006879 struct compound_hdr hdr;
6880 int status;
6881
Chuck Leverbf269552010-12-14 14:59:29 +00006882 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006883 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006884 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006885 return status;
6886}
6887
6888/*
Trond Myklebust66245532012-05-25 17:18:09 -04006889 * Decode DESTROY_CLIENTID response
6890 */
6891static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6892 struct xdr_stream *xdr,
6893 void *res)
6894{
6895 struct compound_hdr hdr;
6896 int status;
6897
6898 status = decode_compound_hdr(xdr, &hdr);
6899 if (!status)
6900 status = decode_destroy_clientid(xdr, res);
6901 return status;
6902}
6903
6904/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006905 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006906 */
Chuck Leverbf269552010-12-14 14:59:29 +00006907static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6908 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006909 struct nfs4_sequence_res *res)
6910{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006911 struct compound_hdr hdr;
6912 int status;
6913
Chuck Leverbf269552010-12-14 14:59:29 +00006914 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006915 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006916 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006917 return status;
6918}
6919
6920/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006921 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006922 */
Chuck Leverbf269552010-12-14 14:59:29 +00006923static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6924 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006925 struct nfs4_get_lease_time_res *res)
6926{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006927 struct compound_hdr hdr;
6928 int status;
6929
Chuck Leverbf269552010-12-14 14:59:29 +00006930 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006931 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006932 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006933 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006934 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006935 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006936 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006937 return status;
6938}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006939
6940/*
6941 * Decode RECLAIM_COMPLETE response
6942 */
Chuck Leverbf269552010-12-14 14:59:29 +00006943static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6944 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006945 struct nfs41_reclaim_complete_res *res)
6946{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006947 struct compound_hdr hdr;
6948 int status;
6949
Chuck Leverbf269552010-12-14 14:59:29 +00006950 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006951 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006952 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006953 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006954 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006955 return status;
6956}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006957
6958/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006959 * Decode GETDEVICELIST response
6960 */
6961static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6962 struct xdr_stream *xdr,
6963 struct nfs4_getdevicelist_res *res)
6964{
6965 struct compound_hdr hdr;
6966 int status;
6967
6968 dprintk("encoding getdevicelist!\n");
6969
6970 status = decode_compound_hdr(xdr, &hdr);
6971 if (status != 0)
6972 goto out;
6973 status = decode_sequence(xdr, &res->seq_res, rqstp);
6974 if (status != 0)
6975 goto out;
6976 status = decode_putfh(xdr);
6977 if (status != 0)
6978 goto out;
6979 status = decode_getdevicelist(xdr, res->devlist);
6980out:
6981 return status;
6982}
6983
6984/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006985 * Decode GETDEVINFO response
6986 */
Chuck Leverbf269552010-12-14 14:59:29 +00006987static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6988 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006989 struct nfs4_getdeviceinfo_res *res)
6990{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006991 struct compound_hdr hdr;
6992 int status;
6993
Chuck Leverbf269552010-12-14 14:59:29 +00006994 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006995 if (status != 0)
6996 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006997 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006998 if (status != 0)
6999 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007000 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007001out:
7002 return status;
7003}
7004
7005/*
7006 * Decode LAYOUTGET response
7007 */
Chuck Leverbf269552010-12-14 14:59:29 +00007008static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7009 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007010 struct nfs4_layoutget_res *res)
7011{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007012 struct compound_hdr hdr;
7013 int status;
7014
Chuck Leverbf269552010-12-14 14:59:29 +00007015 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007016 if (status)
7017 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007018 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007019 if (status)
7020 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007021 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007022 if (status)
7023 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007024 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007025out:
7026 return status;
7027}
Andy Adamson863a3c62011-03-23 13:27:54 +00007028
7029/*
Benny Halevycbe82602011-05-22 19:52:37 +03007030 * Decode LAYOUTRETURN response
7031 */
7032static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7033 struct xdr_stream *xdr,
7034 struct nfs4_layoutreturn_res *res)
7035{
7036 struct compound_hdr hdr;
7037 int status;
7038
7039 status = decode_compound_hdr(xdr, &hdr);
7040 if (status)
7041 goto out;
7042 status = decode_sequence(xdr, &res->seq_res, rqstp);
7043 if (status)
7044 goto out;
7045 status = decode_putfh(xdr);
7046 if (status)
7047 goto out;
7048 status = decode_layoutreturn(xdr, res);
7049out:
7050 return status;
7051}
7052
7053/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007054 * Decode LAYOUTCOMMIT response
7055 */
7056static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7057 struct xdr_stream *xdr,
7058 struct nfs4_layoutcommit_res *res)
7059{
7060 struct compound_hdr hdr;
7061 int status;
7062
7063 status = decode_compound_hdr(xdr, &hdr);
7064 if (status)
7065 goto out;
7066 status = decode_sequence(xdr, &res->seq_res, rqstp);
7067 if (status)
7068 goto out;
7069 status = decode_putfh(xdr);
7070 if (status)
7071 goto out;
7072 status = decode_layoutcommit(xdr, rqstp, res);
7073 if (status)
7074 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007075 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007076out:
7077 return status;
7078}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007079
7080/*
7081 * Decode SECINFO_NO_NAME response
7082 */
7083static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7084 struct xdr_stream *xdr,
7085 struct nfs4_secinfo_res *res)
7086{
7087 struct compound_hdr hdr;
7088 int status;
7089
7090 status = decode_compound_hdr(xdr, &hdr);
7091 if (status)
7092 goto out;
7093 status = decode_sequence(xdr, &res->seq_res, rqstp);
7094 if (status)
7095 goto out;
7096 status = decode_putrootfh(xdr);
7097 if (status)
7098 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007099 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007100out:
7101 return status;
7102}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007103
7104/*
7105 * Decode TEST_STATEID response
7106 */
7107static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7108 struct xdr_stream *xdr,
7109 struct nfs41_test_stateid_res *res)
7110{
7111 struct compound_hdr hdr;
7112 int status;
7113
7114 status = decode_compound_hdr(xdr, &hdr);
7115 if (status)
7116 goto out;
7117 status = decode_sequence(xdr, &res->seq_res, rqstp);
7118 if (status)
7119 goto out;
7120 status = decode_test_stateid(xdr, res);
7121out:
7122 return status;
7123}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007124
7125/*
7126 * Decode FREE_STATEID response
7127 */
7128static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7129 struct xdr_stream *xdr,
7130 struct nfs41_free_stateid_res *res)
7131{
7132 struct compound_hdr hdr;
7133 int status;
7134
7135 status = decode_compound_hdr(xdr, &hdr);
7136 if (status)
7137 goto out;
7138 status = decode_sequence(xdr, &res->seq_res, rqstp);
7139 if (status)
7140 goto out;
7141 status = decode_free_stateid(xdr, res);
7142out:
7143 return status;
7144}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007145#endif /* CONFIG_NFS_V4_1 */
7146
Chuck Lever573c4e12010-12-14 14:58:11 +00007147/**
7148 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7149 * the local page cache.
7150 * @xdr: XDR stream where entry resides
7151 * @entry: buffer to fill in with entry data
7152 * @plus: boolean indicating whether this should be a readdirplus entry
7153 *
7154 * Returns zero if successful, otherwise a negative errno value is
7155 * returned.
7156 *
7157 * This function is not invoked during READDIR reply decoding, but
7158 * rather whenever an application invokes the getdents(2) system call
7159 * on a directory already in our cache.
7160 */
7161int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7162 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007163{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007164 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007165 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007166 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007167 __be32 *p = xdr_inline_decode(xdr, 4);
7168 if (unlikely(!p))
7169 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007170 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007171 p = xdr_inline_decode(xdr, 4);
7172 if (unlikely(!p))
7173 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007174 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007175 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007176 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007177 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007178 }
7179
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007180 p = xdr_inline_decode(xdr, 12);
7181 if (unlikely(!p))
7182 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007183 entry->prev_cookie = entry->cookie;
7184 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007185 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007186
Trond Myklebust9af8c222010-10-24 11:52:55 -04007187 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007188 if (unlikely(!p))
7189 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007190 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007191
7192 /*
7193 * In case the server doesn't return an inode number,
7194 * we fake one here. (We don't use inode number 0,
7195 * since glibc seems to choke on it...)
7196 */
7197 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007198 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007199
Trond Myklebust9af8c222010-10-24 11:52:55 -04007200 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007201 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007202
Trond Myklebust256e48b2012-06-21 11:18:13 -04007203 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007204 goto out_overflow;
7205
Chuck Lever573c4e12010-12-14 14:58:11 +00007206 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007207 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007208 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007209 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7210 entry->ino = entry->fattr->mounted_on_fileid;
7211 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007212 entry->ino = entry->fattr->fileid;
7213
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007214 entry->d_type = DT_UNKNOWN;
7215 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7216 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7217
Chuck Lever573c4e12010-12-14 14:58:11 +00007218 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007219
7220out_overflow:
7221 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007222 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007223}
7224
7225/*
7226 * We need to translate between nfs status return values and
7227 * the local errno values which may not be the same.
7228 */
7229static struct {
7230 int stat;
7231 int errno;
7232} nfs_errtbl[] = {
7233 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007234 { NFS4ERR_PERM, -EPERM },
7235 { NFS4ERR_NOENT, -ENOENT },
7236 { NFS4ERR_IO, -errno_NFSERR_IO},
7237 { NFS4ERR_NXIO, -ENXIO },
7238 { NFS4ERR_ACCESS, -EACCES },
7239 { NFS4ERR_EXIST, -EEXIST },
7240 { NFS4ERR_XDEV, -EXDEV },
7241 { NFS4ERR_NOTDIR, -ENOTDIR },
7242 { NFS4ERR_ISDIR, -EISDIR },
7243 { NFS4ERR_INVAL, -EINVAL },
7244 { NFS4ERR_FBIG, -EFBIG },
7245 { NFS4ERR_NOSPC, -ENOSPC },
7246 { NFS4ERR_ROFS, -EROFS },
7247 { NFS4ERR_MLINK, -EMLINK },
7248 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7249 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7250 { NFS4ERR_DQUOT, -EDQUOT },
7251 { NFS4ERR_STALE, -ESTALE },
7252 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007253 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7254 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7255 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007256 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007257 { NFS4ERR_BADTYPE, -EBADTYPE },
7258 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007259 { NFS4ERR_SYMLINK, -ELOOP },
7260 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7261 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007262 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007263};
7264
7265/*
7266 * Convert an NFS error code to a local one.
7267 * This one is used jointly by NFSv2 and NFSv3.
7268 */
7269static int
David Howells0a8ea432006-08-22 20:06:08 -04007270nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007271{
7272 int i;
7273 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7274 if (nfs_errtbl[i].stat == stat)
7275 return nfs_errtbl[i].errno;
7276 }
7277 if (stat <= 10000 || stat > 10100) {
7278 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007279 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007280 }
7281 /* If we cannot translate the error, the recovery routines should
7282 * handle it.
7283 * Note: remaining NFSv4 error codes have values > 10000, so should
7284 * not conflict with native Linux error codes.
7285 */
Benny Halevy856dff32008-03-31 17:39:06 +03007286 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007287}
7288
Linus Torvalds1da177e2005-04-16 15:20:36 -07007289#define PROC(proc, argtype, restype) \
7290[NFSPROC4_CLNT_##proc] = { \
7291 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007292 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007293 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007294 .p_arglen = NFS4_##argtype##_sz, \
7295 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007296 .p_statidx = NFSPROC4_CLNT_##proc, \
7297 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007298}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007299
7300struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007301 PROC(READ, enc_read, dec_read),
7302 PROC(WRITE, enc_write, dec_write),
7303 PROC(COMMIT, enc_commit, dec_commit),
7304 PROC(OPEN, enc_open, dec_open),
7305 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7306 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7307 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7308 PROC(CLOSE, enc_close, dec_close),
7309 PROC(SETATTR, enc_setattr, dec_setattr),
7310 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7311 PROC(RENEW, enc_renew, dec_renew),
7312 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7313 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7314 PROC(LOCK, enc_lock, dec_lock),
7315 PROC(LOCKT, enc_lockt, dec_lockt),
7316 PROC(LOCKU, enc_locku, dec_locku),
7317 PROC(ACCESS, enc_access, dec_access),
7318 PROC(GETATTR, enc_getattr, dec_getattr),
7319 PROC(LOOKUP, enc_lookup, dec_lookup),
7320 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7321 PROC(REMOVE, enc_remove, dec_remove),
7322 PROC(RENAME, enc_rename, dec_rename),
7323 PROC(LINK, enc_link, dec_link),
7324 PROC(SYMLINK, enc_symlink, dec_symlink),
7325 PROC(CREATE, enc_create, dec_create),
7326 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7327 PROC(STATFS, enc_statfs, dec_statfs),
7328 PROC(READLINK, enc_readlink, dec_readlink),
7329 PROC(READDIR, enc_readdir, dec_readdir),
7330 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7331 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7332 PROC(GETACL, enc_getacl, dec_getacl),
7333 PROC(SETACL, enc_setacl, dec_setacl),
7334 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7335 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007336 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007337#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007338 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7339 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7340 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7341 PROC(SEQUENCE, enc_sequence, dec_sequence),
7342 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7343 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7344 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7345 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007346 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007347 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007348 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007349 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007350 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007351 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007352 PROC(BIND_CONN_TO_SESSION,
7353 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007354 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007355#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007356};
7357
Trond Myklebusta613fa12012-01-20 13:53:56 -05007358const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007359 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007360 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007361 .procs = nfs4_procedures
7362};
7363
7364/*
7365 * Local variables:
7366 * c-basic-offset: 8
7367 * End:
7368 */