blob: 2a3f77e14db6dd57cb61196affee4503726ec4e8 [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);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400870#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Trond Myklebustbca79472009-03-11 14:10:26 -0400872static const umode_t nfs_type2fmt[] = {
873 [NF4BAD] = 0,
874 [NF4REG] = S_IFREG,
875 [NF4DIR] = S_IFDIR,
876 [NF4BLK] = S_IFBLK,
877 [NF4CHR] = S_IFCHR,
878 [NF4LNK] = S_IFLNK,
879 [NF4SOCK] = S_IFSOCK,
880 [NF4FIFO] = S_IFIFO,
881 [NF4ATTRDIR] = 0,
882 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883};
884
885struct compound_hdr {
886 int32_t status;
887 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500888 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 uint32_t taglen;
890 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400891 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400892 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893};
894
Benny Halevy13c65ce2009-08-14 17:19:25 +0300895static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
896{
897 __be32 *p = xdr_reserve_space(xdr, nbytes);
898 BUG_ON(!p);
899 return p;
900}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Trond Myklebustcb17e552012-03-04 18:13:56 -0500902static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
903{
904 __be32 *p;
905
906 p = xdr_reserve_space(xdr, len);
907 xdr_encode_opaque_fixed(p, buf, len);
908}
909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
911{
Al Viro8687b632006-10-19 23:28:48 -0700912 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500914 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 xdr_encode_opaque(p, str, len);
916}
917
Trond Myklebust4ade9822012-03-04 18:13:57 -0500918static void encode_uint32(struct xdr_stream *xdr, u32 n)
919{
920 __be32 *p;
921
922 p = reserve_space(xdr, 4);
923 *p = cpu_to_be32(n);
924}
925
Trond Myklebustff2eb682012-03-05 11:40:12 -0500926static void encode_uint64(struct xdr_stream *xdr, u64 n)
927{
928 __be32 *p;
929
930 p = reserve_space(xdr, 8);
931 xdr_encode_hyper(p, n);
932}
933
Trond Myklebust4ade9822012-03-04 18:13:57 -0500934static void encode_nfs4_seqid(struct xdr_stream *xdr,
935 const struct nfs_seqid *seqid)
936{
937 encode_uint32(xdr, seqid->sequence->counter);
938}
939
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400940static void encode_compound_hdr(struct xdr_stream *xdr,
941 struct rpc_rqst *req,
942 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
Al Viro8687b632006-10-19 23:28:48 -0700944 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400945 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400946
947 /* initialize running count of expected bytes in reply.
948 * NOTE: the replied tag SHOULD be the same is the one sent,
949 * but this is not required as a MUST for the server to do so. */
950 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
Trond Myklebust7fc38842012-10-15 11:51:21 -0400952 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500953 encode_string(xdr, hdr->taglen, hdr->tag);
954 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300955 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500956 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300957 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500958}
959
Trond Myklebustab19b482012-03-04 18:13:57 -0500960static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
961 uint32_t replen,
962 struct compound_hdr *hdr)
963{
964 encode_uint32(xdr, op);
965 hdr->nops++;
966 hdr->replen += replen;
967}
968
Andy Adamsond0179312008-12-23 16:06:17 -0500969static void encode_nops(struct compound_hdr *hdr)
970{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400971 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500972 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973}
974
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500975static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
976{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500977 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500978}
979
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
981{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500982 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983}
984
David Quigleyaa9c2662013-05-22 12:50:44 -0400985static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
986 const struct nfs4_label *label,
987 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988{
989 char owner_name[IDMAP_NAMESZ];
990 char owner_group[IDMAP_NAMESZ];
991 int owner_namelen = 0;
992 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700993 __be32 *p;
994 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 int len;
996 uint32_t bmval0 = 0;
997 uint32_t bmval1 = 0;
David Quigleya09df2c2013-05-22 12:50:41 -0400998 uint32_t bmval2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
1000 /*
1001 * We reserve enough space to write the entire attribute buffer at once.
1002 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001003 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1004 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001005 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 */
David Quigleya09df2c2013-05-22 12:50:41 -04001007 len = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 /* Sigh */
1010 if (iap->ia_valid & ATTR_SIZE)
1011 len += 8;
1012 if (iap->ia_valid & ATTR_MODE)
1013 len += 4;
1014 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001015 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001017 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001018 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 /* XXX */
1020 strcpy(owner_name, "nobody");
1021 owner_namelen = sizeof("nobody") - 1;
1022 /* goto out; */
1023 }
1024 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1025 }
1026 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001027 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001029 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001030 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 strcpy(owner_group, "nobody");
1032 owner_grouplen = sizeof("nobody") - 1;
1033 /* goto out; */
1034 }
1035 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1036 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001037 if (label)
1038 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 if (iap->ia_valid & ATTR_ATIME_SET)
1040 len += 16;
1041 else if (iap->ia_valid & ATTR_ATIME)
1042 len += 4;
1043 if (iap->ia_valid & ATTR_MTIME_SET)
1044 len += 16;
1045 else if (iap->ia_valid & ATTR_MTIME)
1046 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001047 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
1049 /*
1050 * We write the bitmap length now, but leave the bitmap and the attribute
1051 * buffer length to be backfilled at the end of this routine.
1052 */
David Quigleya09df2c2013-05-22 12:50:41 -04001053 *p++ = cpu_to_be32(3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 q = p;
David Quigleya09df2c2013-05-22 12:50:41 -04001055 p += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
1057 if (iap->ia_valid & ATTR_SIZE) {
1058 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001059 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 }
1061 if (iap->ia_valid & ATTR_MODE) {
1062 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001063 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 }
1065 if (iap->ia_valid & ATTR_UID) {
1066 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001067 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
1069 if (iap->ia_valid & ATTR_GID) {
1070 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001071 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 }
1073 if (iap->ia_valid & ATTR_ATIME_SET) {
1074 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001075 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Bryan Schumaker042ad0b2013-04-19 16:09:37 -04001076 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001077 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 }
1079 else if (iap->ia_valid & ATTR_ATIME) {
1080 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001081 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 }
1083 if (iap->ia_valid & ATTR_MTIME_SET) {
1084 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001085 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Bryan Schumaker042ad0b2013-04-19 16:09:37 -04001086 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001087 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 }
1089 else if (iap->ia_valid & ATTR_MTIME) {
1090 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001091 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001093 if (label) {
1094 bmval2 |= FATTR4_WORD2_SECURITY_LABEL;
1095 *p++ = cpu_to_be32(label->lfs);
1096 *p++ = cpu_to_be32(label->pi);
1097 *p++ = cpu_to_be32(label->len);
1098 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1099 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 /*
1102 * Now we backfill the bitmap and the attribute buffer length.
1103 */
1104 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001105 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 len, ((char *)p - (char *)q) + 4);
1107 BUG();
1108 }
David Quigleya09df2c2013-05-22 12:50:41 -04001109 len = (char *)p - (char *)q - 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 *q++ = htonl(bmval0);
1111 *q++ = htonl(bmval1);
David Quigleya09df2c2013-05-22 12:50:41 -04001112 *q++ = htonl(bmval2);
Benny Halevy34558512009-08-14 17:19:30 +03001113 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001118static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001120 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1121 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001124static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
Trond Myklebustab19b482012-03-04 18:13:57 -05001126 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001127 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001128 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129}
1130
Fred Isaman0b7c0152012-04-20 14:47:39 -04001131static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132{
Al Viro8687b632006-10-19 23:28:48 -07001133 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001134
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001135 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1136 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001137 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001138 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Al Viro8687b632006-10-19 23:28:48 -07001143 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001144
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001145 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1146 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148 switch (create->ftype) {
1149 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001150 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001151 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001152 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 break;
1154
1155 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001156 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001157 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001158 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 break;
1160
1161 default:
1162 break;
1163 }
1164
Benny Halevy811652b2009-08-14 17:19:34 +03001165 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001166 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167}
1168
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001169static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170{
Andy Adamson05d564f2008-12-23 16:06:15 -05001171 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001173 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1174 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001175 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001176 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177}
1178
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001179static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180{
Andy Adamson05d564f2008-12-23 16:06:15 -05001181 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001183 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1184 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001185 *p++ = cpu_to_be32(2);
1186 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001187 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188}
1189
Fred Isamandae100c2011-07-30 20:52:37 -04001190static void
1191encode_getattr_three(struct xdr_stream *xdr,
1192 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1193 struct compound_hdr *hdr)
1194{
1195 __be32 *p;
1196
Trond Myklebustab19b482012-03-04 18:13:57 -05001197 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001198 if (bm2) {
1199 p = reserve_space(xdr, 16);
1200 *p++ = cpu_to_be32(3);
1201 *p++ = cpu_to_be32(bm0);
1202 *p++ = cpu_to_be32(bm1);
1203 *p = cpu_to_be32(bm2);
1204 } else if (bm1) {
1205 p = reserve_space(xdr, 12);
1206 *p++ = cpu_to_be32(2);
1207 *p++ = cpu_to_be32(bm0);
1208 *p = cpu_to_be32(bm1);
1209 } else {
1210 p = reserve_space(xdr, 8);
1211 *p++ = cpu_to_be32(1);
1212 *p = cpu_to_be32(bm0);
1213 }
Fred Isamandae100c2011-07-30 20:52:37 -04001214}
1215
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001216static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217{
David Quigleya09df2c2013-05-22 12:50:41 -04001218 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1219 bitmask[1] & nfs4_fattr_bitmap[1],
1220 bitmask[2] & nfs4_fattr_bitmap[2],
1221 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222}
1223
Andy Adamson88034c32012-05-23 05:02:34 -04001224static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001225 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001226 struct compound_hdr *hdr)
1227{
1228 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001229 bitmask[0] & open_bitmap[0],
1230 bitmask[1] & open_bitmap[1],
1231 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001232 hdr);
1233}
1234
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001235static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236{
Fred Isamandae100c2011-07-30 20:52:37 -04001237 encode_getattr_three(xdr,
1238 bitmask[0] & nfs4_fsinfo_bitmap[0],
1239 bitmask[1] & nfs4_fsinfo_bitmap[1],
1240 bitmask[2] & nfs4_fsinfo_bitmap[2],
1241 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242}
1243
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001244static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001245{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001246 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1247 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001248}
1249
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001250static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
Trond Myklebustab19b482012-03-04 18:13:57 -05001252 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253}
1254
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001255static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256{
Trond Myklebustab19b482012-03-04 18:13:57 -05001257 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001258 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259}
1260
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001261static inline int nfs4_lock_type(struct file_lock *fl, int block)
1262{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001263 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001264 return block ? NFS4_READW_LT : NFS4_READ_LT;
1265 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1266}
1267
1268static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1269{
1270 if (fl->fl_end == OFFSET_MAX)
1271 return ~(uint64_t)0;
1272 return fl->fl_end - fl->fl_start + 1;
1273}
1274
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001275static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1276{
1277 __be32 *p;
1278
Trond Myklebustd035c362010-12-21 10:45:27 -05001279 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001280 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001281 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001282 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001283 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001284 xdr_encode_hyper(p, lowner->id);
1285}
1286
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287/*
1288 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1289 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1290 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001291static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
Al Viro8687b632006-10-19 23:28:48 -07001293 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001295 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1296 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001297 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1298 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001299 p = xdr_encode_hyper(p, args->fl->fl_start);
1300 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001301 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001302 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001303 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001304 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001305 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001306 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 }
1308 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001309 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001310 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312}
1313
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001314static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
Al Viro8687b632006-10-19 23:28:48 -07001316 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001318 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1319 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001320 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001321 p = xdr_encode_hyper(p, args->fl->fl_start);
1322 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001323 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324}
1325
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001326static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
Al Viro8687b632006-10-19 23:28:48 -07001328 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001330 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1331 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001332 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001333 encode_nfs4_stateid(xdr, args->stateid);
1334 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001335 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001336 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001339static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1340{
Trond Myklebustab19b482012-03-04 18:13:57 -05001341 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001342 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001343}
1344
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001345static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
Trond Myklebustab19b482012-03-04 18:13:57 -05001347 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001348 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
1350
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001351static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352{
Al Viro8687b632006-10-19 23:28:48 -07001353 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Benny Halevy13c65ce2009-08-14 17:19:25 +03001355 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001356 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001357 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001358 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001359 break;
1360 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001361 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001362 break;
1363 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001364 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001365 break;
1366 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001367 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 }
Benny Halevy34558512009-08-14 17:19:30 +03001369 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370}
1371
1372static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1373{
Al Viro8687b632006-10-19 23:28:48 -07001374 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 /*
1376 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1377 * owner 4 = 32
1378 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001379 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001380 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001381 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001382 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001383 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001384 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001385 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001386 *p++ = cpu_to_be32(arg->id.uniquifier);
1387 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388}
1389
1390static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1391{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001392 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001393 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Benny Halevy13c65ce2009-08-14 17:19:25 +03001395 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001396 switch(arg->createmode) {
1397 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001398 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001399 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001400 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001401 case NFS4_CREATE_GUARDED:
1402 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001403 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001404 break;
1405 case NFS4_CREATE_EXCLUSIVE:
1406 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1407 encode_nfs4_verifier(xdr, &arg->u.verifier);
1408 break;
1409 case NFS4_CREATE_EXCLUSIVE4_1:
1410 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1411 encode_nfs4_verifier(xdr, &arg->u.verifier);
1412 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001413 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 }
1415}
1416
1417static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1418{
Al Viro8687b632006-10-19 23:28:48 -07001419 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Benny Halevy13c65ce2009-08-14 17:19:25 +03001421 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001423 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001424 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001425 break;
1426 default:
Benny Halevy34558512009-08-14 17:19:30 +03001427 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001428 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 }
1430}
1431
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001432static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433{
Al Viro8687b632006-10-19 23:28:48 -07001434 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Benny Halevy13c65ce2009-08-14 17:19:25 +03001436 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001439 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001440 break;
1441 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001442 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001443 break;
1444 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001445 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001446 break;
1447 default:
1448 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 }
1450}
1451
1452static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1453{
Al Viro8687b632006-10-19 23:28:48 -07001454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Benny Halevy13c65ce2009-08-14 17:19:25 +03001456 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001457 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 encode_string(xdr, name->len, name->name);
1459}
1460
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001461static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462{
Al Viro8687b632006-10-19 23:28:48 -07001463 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Benny Halevy13c65ce2009-08-14 17:19:25 +03001465 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001466 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 encode_delegation_type(xdr, type);
1468}
1469
1470static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1471{
Al Viro8687b632006-10-19 23:28:48 -07001472 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001474 p = reserve_space(xdr, 4);
1475 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1476 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 encode_string(xdr, name->len, name->name);
1478}
1479
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001480static inline void encode_claim_fh(struct xdr_stream *xdr)
1481{
1482 __be32 *p;
1483
1484 p = reserve_space(xdr, 4);
1485 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1486}
1487
1488static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1489{
1490 __be32 *p;
1491
1492 p = reserve_space(xdr, 4);
1493 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1494 encode_nfs4_stateid(xdr, stateid);
1495}
1496
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001497static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
Trond Myklebustab19b482012-03-04 18:13:57 -05001499 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 encode_openhdr(xdr, arg);
1501 encode_opentype(xdr, arg);
1502 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001503 case NFS4_OPEN_CLAIM_NULL:
1504 encode_claim_null(xdr, arg->name);
1505 break;
1506 case NFS4_OPEN_CLAIM_PREVIOUS:
1507 encode_claim_previous(xdr, arg->u.delegation_type);
1508 break;
1509 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1510 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1511 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001512 case NFS4_OPEN_CLAIM_FH:
1513 encode_claim_fh(xdr);
1514 break;
1515 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1516 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1517 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001518 default:
1519 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521}
1522
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001523static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524{
Trond Myklebustab19b482012-03-04 18:13:57 -05001525 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001526 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001527 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528}
1529
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001530static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
Trond Myklebustab19b482012-03-04 18:13:57 -05001532 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001533 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001534 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001535 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536}
1537
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001538static void
Andy Adamsond0179312008-12-23 16:06:17 -05001539encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540{
Trond Myklebustab19b482012-03-04 18:13:57 -05001541 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001542 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001545static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546{
Trond Myklebustab19b482012-03-04 18:13:57 -05001547 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001550static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
Al Viro8687b632006-10-19 23:28:48 -07001552 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Trond Myklebustab19b482012-03-04 18:13:57 -05001554 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001555 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Benny Halevy13c65ce2009-08-14 17:19:25 +03001557 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001558 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001559 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560}
1561
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001562static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
David Quigleyaa9c2662013-05-22 12:50:44 -04001564 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001565 FATTR4_WORD0_RDATTR_ERROR,
1566 FATTR4_WORD1_MOUNTED_ON_FILEID,
1567 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001568 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001569 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001571 if (readdir->plus) {
1572 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001573 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001574 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1575 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1576 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1577 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001578 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001579 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001580 /* Use mounted_on_fileid only if the server supports it */
1581 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1582 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001583
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001584 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001585 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001586 encode_nfs4_verifier(xdr, &readdir->verifier);
David Quigleyaa9c2662013-05-22 12:50:44 -04001587 p = reserve_space(xdr, encode_readdir_space);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001588 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001589 *p++ = cpu_to_be32(readdir->count);
David Quigleyaa9c2662013-05-22 12:50:44 -04001590 *p++ = cpu_to_be32(encode_readdir_bitmask_sz);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001591 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
David Quigleyaa9c2662013-05-22 12:50:44 -04001592 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1593 if (encode_readdir_bitmask_sz > 2) {
1594 if (hdr->minorversion > 1)
1595 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1596 p++, *p++ = cpu_to_be32(attrs[2] & readdir->bitmask[2]);
1597 }
Chuck Levercd937102012-03-02 17:14:31 -05001598 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001599
1600 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001601 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001602 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001603 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001604 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001605 attrs[1] & readdir->bitmask[1],
1606 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607}
1608
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001609static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
Trond Myklebustab19b482012-03-04 18:13:57 -05001611 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612}
1613
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615{
Trond Myklebustab19b482012-03-04 18:13:57 -05001616 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001617 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618}
1619
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001620static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621{
Trond Myklebustab19b482012-03-04 18:13:57 -05001622 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001623 encode_string(xdr, oldname->len, oldname->name);
1624 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625}
1626
Chuck Leverbb4dae52012-03-01 17:01:48 -05001627static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1628 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001630 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001631 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001634static void
Andy Adamsond0179312008-12-23 16:06:17 -05001635encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001636{
Trond Myklebustab19b482012-03-04 18:13:57 -05001637 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001638}
1639
Chuck Lever9f06c712010-12-14 14:59:18 +00001640static void
Andy Adamsond0179312008-12-23 16:06:17 -05001641encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001642{
Al Viro8687b632006-10-19 23:28:48 -07001643 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001644
Trond Myklebustab19b482012-03-04 18:13:57 -05001645 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001646 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001647 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001648 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001649 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001650 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001651 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001652 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001653}
1654
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001655static void
Andy Adamsond0179312008-12-23 16:06:17 -05001656encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657{
Trond Myklebustab19b482012-03-04 18:13:57 -05001658 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
1660
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001661static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662{
Trond Myklebustab19b482012-03-04 18:13:57 -05001663 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001664 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001665 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666}
1667
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001668static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669{
Al Viro8687b632006-10-19 23:28:48 -07001670 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Trond Myklebust70019512012-03-04 20:49:32 -05001672 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001673 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
1675 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001676 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001677 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1679 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001680 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001681 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682}
1683
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001684static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001686 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1687 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001688 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001689 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690}
1691
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001692static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693{
Al Viro8687b632006-10-19 23:28:48 -07001694 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Trond Myklebustab19b482012-03-04 18:13:57 -05001696 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001697 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
Benny Halevy13c65ce2009-08-14 17:19:25 +03001699 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001700 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001701 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001702 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
1704 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705}
1706
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001707static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708{
Trond Myklebustab19b482012-03-04 18:13:57 -05001709 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001710 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001712
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001713static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1714{
Trond Myklebustab19b482012-03-04 18:13:57 -05001715 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001716 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001717}
1718
Benny Halevy99fe60d2009-04-01 09:22:29 -04001719#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001720/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001721static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1722 struct nfs4_session *session,
1723 struct compound_hdr *hdr)
1724{
1725 __be32 *p;
1726
1727 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1728 decode_bind_conn_to_session_maxsz, hdr);
1729 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1730 p = xdr_reserve_space(xdr, 8);
1731 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1732 *p = 0; /* use_conn_in_rdma_mode = False */
1733}
1734
Benny Halevy99fe60d2009-04-01 09:22:29 -04001735static void encode_exchange_id(struct xdr_stream *xdr,
1736 struct nfs41_exchange_id_args *args,
1737 struct compound_hdr *hdr)
1738{
1739 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001740 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001741 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001742
Trond Myklebust70019512012-03-04 20:49:32 -05001743 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001744 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001745
1746 encode_string(xdr, args->id_len, args->id);
1747
Benny Halevy13c65ce2009-08-14 17:19:25 +03001748 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001749 *p++ = cpu_to_be32(args->flags);
1750 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001751
1752 if (send_implementation_id &&
1753 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1754 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001755 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001756 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1757 utsname()->sysname, utsname()->release,
1758 utsname()->version, utsname()->machine);
1759
1760 if (len > 0) {
1761 *p = cpu_to_be32(1); /* implementation id array length=1 */
1762
1763 encode_string(xdr,
1764 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1765 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1766 encode_string(xdr, len, impl_name);
1767 /* just send zeros for nii_date - the date is in nii_name */
1768 p = reserve_space(xdr, 12);
1769 p = xdr_encode_hyper(p, 0);
1770 *p = cpu_to_be32(0);
1771 } else
1772 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001773}
Andy Adamsonfc931582009-04-01 09:22:31 -04001774
1775static void encode_create_session(struct xdr_stream *xdr,
1776 struct nfs41_create_session_args *args,
1777 struct compound_hdr *hdr)
1778{
1779 __be32 *p;
1780 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1781 uint32_t len;
1782 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001783 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001784 u32 max_resp_sz_cached;
1785
1786 /*
1787 * Assumes OPEN is the biggest non-idempotent compound.
1788 * 2 is the verifier.
1789 */
1790 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1791 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001792
Andy Adamsonfc931582009-04-01 09:22:31 -04001793 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1794 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001795
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001796 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1797 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001798 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001799 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1800 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001801
Andy Adamsonfc931582009-04-01 09:22:31 -04001802 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001803 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001804 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1805 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001806 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001807 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1808 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1809 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001810
1811 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001812 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001813 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1814 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1815 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1816 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1817 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1818 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001819
Benny Halevye75bc1c2009-08-14 17:18:54 +03001820 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001821 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001822 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001823
1824 /* authsys_parms rfc1831 */
Chuck Leverf0920752012-05-21 22:45:41 -04001825 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001826 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001827 *p++ = cpu_to_be32(0); /* UID */
1828 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001829 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001830}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001831
1832static void encode_destroy_session(struct xdr_stream *xdr,
1833 struct nfs4_session *session,
1834 struct compound_hdr *hdr)
1835{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001836 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1837 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001838}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001839
Trond Myklebust66245532012-05-25 17:18:09 -04001840static void encode_destroy_clientid(struct xdr_stream *xdr,
1841 uint64_t clientid,
1842 struct compound_hdr *hdr)
1843{
1844 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1845 encode_uint64(xdr, clientid);
1846}
1847
Ricardo Labiaga180197532009-12-05 16:08:40 -05001848static void encode_reclaim_complete(struct xdr_stream *xdr,
1849 struct nfs41_reclaim_complete_args *args,
1850 struct compound_hdr *hdr)
1851{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001852 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1853 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001854}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001855#endif /* CONFIG_NFS_V4_1 */
1856
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001857static void encode_sequence(struct xdr_stream *xdr,
1858 const struct nfs4_sequence_args *args,
1859 struct compound_hdr *hdr)
1860{
1861#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001862 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001863 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001864 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001865 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001866
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001867 if (slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001868 return;
1869
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001870 tp = slot->table;
1871 session = tp->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001872
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001873 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001874
1875 /*
1876 * Sessionid + seqid + slotid + max slotid + cache_this
1877 */
1878 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1879 "max_slotid=%d cache_this=%d\n",
1880 __func__,
1881 ((u32 *)session->sess_id.data)[0],
1882 ((u32 *)session->sess_id.data)[1],
1883 ((u32 *)session->sess_id.data)[2],
1884 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001885 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001886 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001887 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001888 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001889 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001890 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001891 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001892 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001893#endif /* CONFIG_NFS_V4_1 */
1894}
1895
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001896#ifdef CONFIG_NFS_V4_1
1897static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001898encode_getdevicelist(struct xdr_stream *xdr,
1899 const struct nfs4_getdevicelist_args *args,
1900 struct compound_hdr *hdr)
1901{
1902 __be32 *p;
1903 nfs4_verifier dummy = {
1904 .data = "dummmmmy",
1905 };
1906
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001907 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1908 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001909 *p++ = cpu_to_be32(args->layoutclass);
1910 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1911 xdr_encode_hyper(p, 0ULL); /* cookie */
1912 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001913}
1914
1915static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001916encode_getdeviceinfo(struct xdr_stream *xdr,
1917 const struct nfs4_getdeviceinfo_args *args,
1918 struct compound_hdr *hdr)
1919{
1920 __be32 *p;
1921
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001922 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1923 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001924 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1925 NFS4_DEVICEID4_SIZE);
1926 *p++ = cpu_to_be32(args->pdev->layout_type);
1927 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1928 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001929}
1930
1931static void
1932encode_layoutget(struct xdr_stream *xdr,
1933 const struct nfs4_layoutget_args *args,
1934 struct compound_hdr *hdr)
1935{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001936 __be32 *p;
1937
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001938 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1939 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001940 *p++ = cpu_to_be32(0); /* Signal layout available */
1941 *p++ = cpu_to_be32(args->type);
1942 *p++ = cpu_to_be32(args->range.iomode);
1943 p = xdr_encode_hyper(p, args->range.offset);
1944 p = xdr_encode_hyper(p, args->range.length);
1945 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001946 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001947 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001948
1949 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1950 __func__,
1951 args->type,
1952 args->range.iomode,
1953 (unsigned long)args->range.offset,
1954 (unsigned long)args->range.length,
1955 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001956}
Andy Adamson863a3c62011-03-23 13:27:54 +00001957
1958static int
1959encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001960 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001961 const struct nfs4_layoutcommit_args *args,
1962 struct compound_hdr *hdr)
1963{
1964 __be32 *p;
1965
1966 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1967 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1968
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001969 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1970 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001971 /* Only whole file layouts */
1972 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001973 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001974 *p = cpu_to_be32(0); /* reclaim */
1975 encode_nfs4_stateid(xdr, &args->stateid);
1976 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001977 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1978 p = xdr_encode_hyper(p, args->lastbytewritten);
1979 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1980 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001981
1982 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1983 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1984 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001985 else
1986 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001987
Andy Adamson863a3c62011-03-23 13:27:54 +00001988 return 0;
1989}
Benny Halevycbe82602011-05-22 19:52:37 +03001990
1991static void
1992encode_layoutreturn(struct xdr_stream *xdr,
1993 const struct nfs4_layoutreturn_args *args,
1994 struct compound_hdr *hdr)
1995{
1996 __be32 *p;
1997
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001998 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1999 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002000 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2001 *p++ = cpu_to_be32(args->layout_type);
2002 *p++ = cpu_to_be32(IOMODE_ANY);
2003 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002004 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002005 p = xdr_encode_hyper(p, 0);
2006 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2007 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002008 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002009 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002010 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2011 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2012 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002013 } else
2014 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002015}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002016
2017static int
2018encode_secinfo_no_name(struct xdr_stream *xdr,
2019 const struct nfs41_secinfo_no_name_args *args,
2020 struct compound_hdr *hdr)
2021{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002022 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2023 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002024 return 0;
2025}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002026
2027static void encode_test_stateid(struct xdr_stream *xdr,
2028 struct nfs41_test_stateid_args *args,
2029 struct compound_hdr *hdr)
2030{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002031 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2032 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002033 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002034}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002035
2036static void encode_free_stateid(struct xdr_stream *xdr,
2037 struct nfs41_free_stateid_args *args,
2038 struct compound_hdr *hdr)
2039{
Trond Myklebustab19b482012-03-04 18:13:57 -05002040 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002041 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002042}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002043#endif /* CONFIG_NFS_V4_1 */
2044
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045/*
2046 * END OF "GENERIC" ENCODE ROUTINES.
2047 */
2048
Benny Halevy66cc0422009-04-01 09:22:10 -04002049static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2050{
2051#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05002052
2053 if (args->sa_slot)
2054 return args->sa_slot->table->session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002055#endif /* CONFIG_NFS_V4_1 */
2056 return 0;
2057}
2058
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059/*
2060 * Encode an ACCESS request
2061 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002062static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2063 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002066 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
Chuck Lever9f06c712010-12-14 14:59:18 +00002069 encode_compound_hdr(xdr, req, &hdr);
2070 encode_sequence(xdr, &args->seq_args, &hdr);
2071 encode_putfh(xdr, args->fh, &hdr);
2072 encode_access(xdr, args->access, &hdr);
2073 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002074 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075}
2076
2077/*
2078 * Encode LOOKUP request
2079 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002080static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2081 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002084 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
Chuck Lever9f06c712010-12-14 14:59:18 +00002087 encode_compound_hdr(xdr, req, &hdr);
2088 encode_sequence(xdr, &args->seq_args, &hdr);
2089 encode_putfh(xdr, args->dir_fh, &hdr);
2090 encode_lookup(xdr, args->name, &hdr);
2091 encode_getfh(xdr, &hdr);
2092 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002093 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094}
2095
2096/*
2097 * Encode LOOKUP_ROOT request
2098 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002099static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2100 struct xdr_stream *xdr,
2101 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002104 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
Chuck Lever9f06c712010-12-14 14:59:18 +00002107 encode_compound_hdr(xdr, req, &hdr);
2108 encode_sequence(xdr, &args->seq_args, &hdr);
2109 encode_putrootfh(xdr, &hdr);
2110 encode_getfh(xdr, &hdr);
2111 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002112 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113}
2114
2115/*
2116 * Encode REMOVE request
2117 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002118static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2119 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002122 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Chuck Lever9f06c712010-12-14 14:59:18 +00002125 encode_compound_hdr(xdr, req, &hdr);
2126 encode_sequence(xdr, &args->seq_args, &hdr);
2127 encode_putfh(xdr, args->fh, &hdr);
2128 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002129 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130}
2131
2132/*
2133 * Encode RENAME request
2134 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002135static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2136 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002139 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
Chuck Lever9f06c712010-12-14 14:59:18 +00002142 encode_compound_hdr(xdr, req, &hdr);
2143 encode_sequence(xdr, &args->seq_args, &hdr);
2144 encode_putfh(xdr, args->old_dir, &hdr);
2145 encode_savefh(xdr, &hdr);
2146 encode_putfh(xdr, args->new_dir, &hdr);
2147 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002148 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149}
2150
2151/*
2152 * Encode LINK request
2153 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002154static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2155 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002158 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
Chuck Lever9f06c712010-12-14 14:59:18 +00002161 encode_compound_hdr(xdr, req, &hdr);
2162 encode_sequence(xdr, &args->seq_args, &hdr);
2163 encode_putfh(xdr, args->fh, &hdr);
2164 encode_savefh(xdr, &hdr);
2165 encode_putfh(xdr, args->dir_fh, &hdr);
2166 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002167 encode_restorefh(xdr, &hdr);
2168 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002169 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170}
2171
2172/*
2173 * Encode CREATE request
2174 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002175static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2176 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002179 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
Chuck Lever9f06c712010-12-14 14:59:18 +00002182 encode_compound_hdr(xdr, req, &hdr);
2183 encode_sequence(xdr, &args->seq_args, &hdr);
2184 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002185 encode_create(xdr, args, &hdr);
2186 encode_getfh(xdr, &hdr);
2187 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002188 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189}
2190
2191/*
2192 * Encode SYMLINK request
2193 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002194static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2195 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196{
Chuck Lever9f06c712010-12-14 14:59:18 +00002197 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198}
2199
2200/*
2201 * Encode GETATTR request
2202 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002203static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2204 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002207 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
Chuck Lever9f06c712010-12-14 14:59:18 +00002210 encode_compound_hdr(xdr, req, &hdr);
2211 encode_sequence(xdr, &args->seq_args, &hdr);
2212 encode_putfh(xdr, args->fh, &hdr);
2213 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002214 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215}
2216
2217/*
2218 * Encode a CLOSE request
2219 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002220static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2221 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222{
Andy Adamson05d564f2008-12-23 16:06:15 -05002223 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002224 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002225 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
Chuck Lever9f06c712010-12-14 14:59:18 +00002227 encode_compound_hdr(xdr, req, &hdr);
2228 encode_sequence(xdr, &args->seq_args, &hdr);
2229 encode_putfh(xdr, args->fh, &hdr);
2230 encode_close(xdr, args, &hdr);
2231 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002232 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233}
2234
2235/*
2236 * Encode an OPEN request
2237 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002238static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2239 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002242 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244
Chuck Lever9f06c712010-12-14 14:59:18 +00002245 encode_compound_hdr(xdr, req, &hdr);
2246 encode_sequence(xdr, &args->seq_args, &hdr);
2247 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002248 encode_open(xdr, args, &hdr);
2249 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002250 if (args->access)
2251 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002252 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002253 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254}
2255
2256/*
2257 * Encode an OPEN_CONFIRM request
2258 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002259static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2260 struct xdr_stream *xdr,
2261 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002264 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Chuck Lever9f06c712010-12-14 14:59:18 +00002267 encode_compound_hdr(xdr, req, &hdr);
2268 encode_putfh(xdr, args->fh, &hdr);
2269 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002270 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271}
2272
2273/*
2274 * Encode an OPEN request with no attributes.
2275 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002276static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2277 struct xdr_stream *xdr,
2278 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002281 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283
Chuck Lever9f06c712010-12-14 14:59:18 +00002284 encode_compound_hdr(xdr, req, &hdr);
2285 encode_sequence(xdr, &args->seq_args, &hdr);
2286 encode_putfh(xdr, args->fh, &hdr);
2287 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002288 if (args->access)
2289 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002290 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002291 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292}
2293
2294/*
2295 * Encode an OPEN_DOWNGRADE request
2296 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002297static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2298 struct xdr_stream *xdr,
2299 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002302 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
Chuck Lever9f06c712010-12-14 14:59:18 +00002305 encode_compound_hdr(xdr, req, &hdr);
2306 encode_sequence(xdr, &args->seq_args, &hdr);
2307 encode_putfh(xdr, args->fh, &hdr);
2308 encode_open_downgrade(xdr, args, &hdr);
2309 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002310 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311}
2312
2313/*
2314 * Encode a LOCK request
2315 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002316static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2317 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002320 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
Chuck Lever9f06c712010-12-14 14:59:18 +00002323 encode_compound_hdr(xdr, req, &hdr);
2324 encode_sequence(xdr, &args->seq_args, &hdr);
2325 encode_putfh(xdr, args->fh, &hdr);
2326 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002327 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328}
2329
2330/*
2331 * Encode a LOCKT request
2332 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002333static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2334 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002337 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Chuck Lever9f06c712010-12-14 14:59:18 +00002340 encode_compound_hdr(xdr, req, &hdr);
2341 encode_sequence(xdr, &args->seq_args, &hdr);
2342 encode_putfh(xdr, args->fh, &hdr);
2343 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002344 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345}
2346
2347/*
2348 * Encode a LOCKU request
2349 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002350static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2351 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002354 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
Chuck Lever9f06c712010-12-14 14:59:18 +00002357 encode_compound_hdr(xdr, req, &hdr);
2358 encode_sequence(xdr, &args->seq_args, &hdr);
2359 encode_putfh(xdr, args->fh, &hdr);
2360 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002361 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362}
2363
Chuck Lever9f06c712010-12-14 14:59:18 +00002364static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2365 struct xdr_stream *xdr,
2366 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002367{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002368 struct compound_hdr hdr = {
2369 .minorversion = 0,
2370 };
2371
Chuck Lever9f06c712010-12-14 14:59:18 +00002372 encode_compound_hdr(xdr, req, &hdr);
2373 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002374 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002375}
2376
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377/*
2378 * Encode a READLINK request
2379 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002380static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2381 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002384 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
Chuck Lever9f06c712010-12-14 14:59:18 +00002387 encode_compound_hdr(xdr, req, &hdr);
2388 encode_sequence(xdr, &args->seq_args, &hdr);
2389 encode_putfh(xdr, args->fh, &hdr);
2390 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002391
Benny Halevy28f56692009-04-01 09:22:09 -04002392 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002393 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002394 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395}
2396
2397/*
2398 * Encode a READDIR request
2399 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002400static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2401 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002404 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
Chuck Lever9f06c712010-12-14 14:59:18 +00002407 encode_compound_hdr(xdr, req, &hdr);
2408 encode_sequence(xdr, &args->seq_args, &hdr);
2409 encode_putfh(xdr, args->fh, &hdr);
2410 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002411
Benny Halevy28f56692009-04-01 09:22:09 -04002412 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002413 args->pgbase, args->count);
2414 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002415 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002416 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002417 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418}
2419
2420/*
2421 * Encode a READ request
2422 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002423static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2424 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002427 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
Chuck Lever9f06c712010-12-14 14:59:18 +00002430 encode_compound_hdr(xdr, req, &hdr);
2431 encode_sequence(xdr, &args->seq_args, &hdr);
2432 encode_putfh(xdr, args->fh, &hdr);
2433 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434
Benny Halevy28f56692009-04-01 09:22:09 -04002435 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002437 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002438 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439}
2440
2441/*
2442 * Encode an SETATTR request
2443 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002444static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2445 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446{
Andy Adamson05d564f2008-12-23 16:06:15 -05002447 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002448 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002449 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Chuck Lever9f06c712010-12-14 14:59:18 +00002451 encode_compound_hdr(xdr, req, &hdr);
2452 encode_sequence(xdr, &args->seq_args, &hdr);
2453 encode_putfh(xdr, args->fh, &hdr);
2454 encode_setattr(xdr, args, args->server, &hdr);
2455 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002456 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457}
2458
2459/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002460 * Encode a GETACL request
2461 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002462static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2463 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002464{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002465 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002466 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002467 };
Benny Halevy28f56692009-04-01 09:22:09 -04002468 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002469
Chuck Lever9f06c712010-12-14 14:59:18 +00002470 encode_compound_hdr(xdr, req, &hdr);
2471 encode_sequence(xdr, &args->seq_args, &hdr);
2472 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002473 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002474 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002475
Benny Halevy28f56692009-04-01 09:22:09 -04002476 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002477 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002478
Andy Adamsond0179312008-12-23 16:06:17 -05002479 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002480}
2481
2482/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 * Encode a WRITE request
2484 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002485static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2486 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002489 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491
Chuck Lever9f06c712010-12-14 14:59:18 +00002492 encode_compound_hdr(xdr, req, &hdr);
2493 encode_sequence(xdr, &args->seq_args, &hdr);
2494 encode_putfh(xdr, args->fh, &hdr);
2495 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002496 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002497 if (args->bitmask)
2498 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002499 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500}
2501
2502/*
2503 * a COMMIT request
2504 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002505static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002506 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002509 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
Chuck Lever9f06c712010-12-14 14:59:18 +00002512 encode_compound_hdr(xdr, req, &hdr);
2513 encode_sequence(xdr, &args->seq_args, &hdr);
2514 encode_putfh(xdr, args->fh, &hdr);
2515 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002516 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517}
2518
2519/*
2520 * FSINFO request
2521 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002522static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2523 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002526 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528
Chuck Lever9f06c712010-12-14 14:59:18 +00002529 encode_compound_hdr(xdr, req, &hdr);
2530 encode_sequence(xdr, &args->seq_args, &hdr);
2531 encode_putfh(xdr, args->fh, &hdr);
2532 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002533 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534}
2535
2536/*
2537 * a PATHCONF request
2538 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002539static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2540 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002543 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545
Chuck Lever9f06c712010-12-14 14:59:18 +00002546 encode_compound_hdr(xdr, req, &hdr);
2547 encode_sequence(xdr, &args->seq_args, &hdr);
2548 encode_putfh(xdr, args->fh, &hdr);
2549 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002550 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002551 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552}
2553
2554/*
2555 * a STATFS request
2556 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002557static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2558 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002561 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
Chuck Lever9f06c712010-12-14 14:59:18 +00002564 encode_compound_hdr(xdr, req, &hdr);
2565 encode_sequence(xdr, &args->seq_args, &hdr);
2566 encode_putfh(xdr, args->fh, &hdr);
2567 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002568 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002569 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570}
2571
2572/*
2573 * GETATTR_BITMAP request
2574 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002575static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2576 struct xdr_stream *xdr,
2577 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002580 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582
Chuck Lever9f06c712010-12-14 14:59:18 +00002583 encode_compound_hdr(xdr, req, &hdr);
2584 encode_sequence(xdr, &args->seq_args, &hdr);
2585 encode_putfh(xdr, args->fhandle, &hdr);
2586 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002587 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002588 FATTR4_WORD0_LINK_SUPPORT|
2589 FATTR4_WORD0_SYMLINK_SUPPORT|
2590 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002591 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592}
2593
2594/*
2595 * a RENEW request
2596 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002597static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2598 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002601 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 };
2603
Chuck Lever9f06c712010-12-14 14:59:18 +00002604 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002605 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002606 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607}
2608
2609/*
2610 * a SETCLIENTID request
2611 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002612static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2613 struct xdr_stream *xdr,
2614 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002617 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 };
2619
Chuck Lever9f06c712010-12-14 14:59:18 +00002620 encode_compound_hdr(xdr, req, &hdr);
2621 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002622 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623}
2624
2625/*
2626 * a SETCLIENTID_CONFIRM request
2627 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002628static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2629 struct xdr_stream *xdr,
2630 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002633 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
Chuck Lever9f06c712010-12-14 14:59:18 +00002636 encode_compound_hdr(xdr, req, &hdr);
2637 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002638 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639}
2640
2641/*
2642 * DELEGRETURN request
2643 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002644static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2645 struct xdr_stream *xdr,
2646 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002649 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
Chuck Lever9f06c712010-12-14 14:59:18 +00002652 encode_compound_hdr(xdr, req, &hdr);
2653 encode_sequence(xdr, &args->seq_args, &hdr);
2654 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002655 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002656 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002657 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658}
2659
2660/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002661 * Encode FS_LOCATIONS request
2662 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002663static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2664 struct xdr_stream *xdr,
2665 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002666{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002667 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002668 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002669 };
Benny Halevy28f56692009-04-01 09:22:09 -04002670 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002671
Chuck Lever9f06c712010-12-14 14:59:18 +00002672 encode_compound_hdr(xdr, req, &hdr);
2673 encode_sequence(xdr, &args->seq_args, &hdr);
2674 encode_putfh(xdr, args->dir_fh, &hdr);
2675 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002676 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002677 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002678
Benny Halevy28f56692009-04-01 09:22:09 -04002679 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002680 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002681 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002682}
2683
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002684/*
2685 * Encode SECINFO request
2686 */
2687static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2688 struct xdr_stream *xdr,
2689 struct nfs4_secinfo_arg *args)
2690{
2691 struct compound_hdr hdr = {
2692 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2693 };
2694
2695 encode_compound_hdr(xdr, req, &hdr);
2696 encode_sequence(xdr, &args->seq_args, &hdr);
2697 encode_putfh(xdr, args->dir_fh, &hdr);
2698 encode_secinfo(xdr, args->name, &hdr);
2699 encode_nops(&hdr);
2700}
2701
Benny Halevy99fe60d2009-04-01 09:22:29 -04002702#if defined(CONFIG_NFS_V4_1)
2703/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002704 * BIND_CONN_TO_SESSION request
2705 */
2706static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2707 struct xdr_stream *xdr,
2708 struct nfs_client *clp)
2709{
2710 struct compound_hdr hdr = {
2711 .minorversion = clp->cl_mvops->minor_version,
2712 };
2713
2714 encode_compound_hdr(xdr, req, &hdr);
2715 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2716 encode_nops(&hdr);
2717}
2718
2719/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002720 * EXCHANGE_ID request
2721 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002722static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2723 struct xdr_stream *xdr,
2724 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002725{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002726 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002727 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002728 };
2729
Chuck Lever9f06c712010-12-14 14:59:18 +00002730 encode_compound_hdr(xdr, req, &hdr);
2731 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002732 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002733}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002734
2735/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002736 * a CREATE_SESSION request
2737 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002738static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2739 struct xdr_stream *xdr,
2740 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002741{
Andy Adamsonfc931582009-04-01 09:22:31 -04002742 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002743 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002744 };
2745
Chuck Lever9f06c712010-12-14 14:59:18 +00002746 encode_compound_hdr(xdr, req, &hdr);
2747 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002748 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002749}
2750
2751/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002752 * a DESTROY_SESSION request
2753 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002754static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2755 struct xdr_stream *xdr,
2756 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002757{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002758 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002759 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002760 };
2761
Chuck Lever9f06c712010-12-14 14:59:18 +00002762 encode_compound_hdr(xdr, req, &hdr);
2763 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002764 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002765}
2766
2767/*
Trond Myklebust66245532012-05-25 17:18:09 -04002768 * a DESTROY_CLIENTID request
2769 */
2770static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2771 struct xdr_stream *xdr,
2772 struct nfs_client *clp)
2773{
2774 struct compound_hdr hdr = {
2775 .minorversion = clp->cl_mvops->minor_version,
2776 };
2777
2778 encode_compound_hdr(xdr, req, &hdr);
2779 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2780 encode_nops(&hdr);
2781}
2782
2783/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002784 * a SEQUENCE request
2785 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002786static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2787 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002788{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002789 struct compound_hdr hdr = {
2790 .minorversion = nfs4_xdr_minorversion(args),
2791 };
2792
Chuck Lever9f06c712010-12-14 14:59:18 +00002793 encode_compound_hdr(xdr, req, &hdr);
2794 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002795 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002796}
2797
2798/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002799 * a GET_LEASE_TIME request
2800 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002801static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2802 struct xdr_stream *xdr,
2803 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002804{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002805 struct compound_hdr hdr = {
2806 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2807 };
Fred Isamandae100c2011-07-30 20:52:37 -04002808 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002809
Chuck Lever9f06c712010-12-14 14:59:18 +00002810 encode_compound_hdr(xdr, req, &hdr);
2811 encode_sequence(xdr, &args->la_seq_args, &hdr);
2812 encode_putrootfh(xdr, &hdr);
2813 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002814 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002815}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002816
2817/*
2818 * a RECLAIM_COMPLETE request
2819 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002820static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2821 struct xdr_stream *xdr,
2822 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002823{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002824 struct compound_hdr hdr = {
2825 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2826 };
2827
Chuck Lever9f06c712010-12-14 14:59:18 +00002828 encode_compound_hdr(xdr, req, &hdr);
2829 encode_sequence(xdr, &args->seq_args, &hdr);
2830 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002831 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002832}
2833
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002834/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002835 * Encode GETDEVICELIST request
2836 */
2837static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2838 struct xdr_stream *xdr,
2839 struct nfs4_getdevicelist_args *args)
2840{
2841 struct compound_hdr hdr = {
2842 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2843 };
2844
2845 encode_compound_hdr(xdr, req, &hdr);
2846 encode_sequence(xdr, &args->seq_args, &hdr);
2847 encode_putfh(xdr, args->fh, &hdr);
2848 encode_getdevicelist(xdr, args, &hdr);
2849 encode_nops(&hdr);
2850}
2851
2852/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002853 * Encode GETDEVICEINFO request
2854 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002855static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2856 struct xdr_stream *xdr,
2857 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002858{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002859 struct compound_hdr hdr = {
2860 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2861 };
2862
Chuck Lever9f06c712010-12-14 14:59:18 +00002863 encode_compound_hdr(xdr, req, &hdr);
2864 encode_sequence(xdr, &args->seq_args, &hdr);
2865 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002866
2867 /* set up reply kvec. Subtract notification bitmap max size (2)
2868 * so that notification bitmap is put in xdr_buf tail */
2869 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2870 args->pdev->pages, args->pdev->pgbase,
2871 args->pdev->pglen);
2872
2873 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002874}
2875
2876/*
2877 * Encode LAYOUTGET request
2878 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002879static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2880 struct xdr_stream *xdr,
2881 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002882{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002883 struct compound_hdr hdr = {
2884 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2885 };
2886
Chuck Lever9f06c712010-12-14 14:59:18 +00002887 encode_compound_hdr(xdr, req, &hdr);
2888 encode_sequence(xdr, &args->seq_args, &hdr);
2889 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2890 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002891
2892 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2893 args->layout.pages, 0, args->layout.pglen);
2894
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002895 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002896}
Andy Adamson863a3c62011-03-23 13:27:54 +00002897
2898/*
2899 * Encode LAYOUTCOMMIT request
2900 */
Benny Halevycbe82602011-05-22 19:52:37 +03002901static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2902 struct xdr_stream *xdr,
2903 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002904{
Benny Halevyac7db722011-05-22 19:53:48 +03002905 struct nfs4_layoutcommit_data *data =
2906 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002907 struct compound_hdr hdr = {
2908 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2909 };
2910
2911 encode_compound_hdr(xdr, req, &hdr);
2912 encode_sequence(xdr, &args->seq_args, &hdr);
2913 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002914 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002915 encode_getfattr(xdr, args->bitmask, &hdr);
2916 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002917}
2918
2919/*
2920 * Encode LAYOUTRETURN request
2921 */
2922static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2923 struct xdr_stream *xdr,
2924 struct nfs4_layoutreturn_args *args)
2925{
2926 struct compound_hdr hdr = {
2927 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2928 };
2929
2930 encode_compound_hdr(xdr, req, &hdr);
2931 encode_sequence(xdr, &args->seq_args, &hdr);
2932 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2933 encode_layoutreturn(xdr, args, &hdr);
2934 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002935}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002936
2937/*
2938 * Encode SECINFO_NO_NAME request
2939 */
2940static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2941 struct xdr_stream *xdr,
2942 struct nfs41_secinfo_no_name_args *args)
2943{
2944 struct compound_hdr hdr = {
2945 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2946 };
2947
2948 encode_compound_hdr(xdr, req, &hdr);
2949 encode_sequence(xdr, &args->seq_args, &hdr);
2950 encode_putrootfh(xdr, &hdr);
2951 encode_secinfo_no_name(xdr, args, &hdr);
2952 encode_nops(&hdr);
2953 return 0;
2954}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002955
2956/*
2957 * Encode TEST_STATEID request
2958 */
2959static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2960 struct xdr_stream *xdr,
2961 struct nfs41_test_stateid_args *args)
2962{
2963 struct compound_hdr hdr = {
2964 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2965 };
2966
2967 encode_compound_hdr(xdr, req, &hdr);
2968 encode_sequence(xdr, &args->seq_args, &hdr);
2969 encode_test_stateid(xdr, args, &hdr);
2970 encode_nops(&hdr);
2971}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002972
2973/*
2974 * Encode FREE_STATEID request
2975 */
2976static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2977 struct xdr_stream *xdr,
2978 struct nfs41_free_stateid_args *args)
2979{
2980 struct compound_hdr hdr = {
2981 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2982 };
2983
2984 encode_compound_hdr(xdr, req, &hdr);
2985 encode_sequence(xdr, &args->seq_args, &hdr);
2986 encode_free_stateid(xdr, args, &hdr);
2987 encode_nops(&hdr);
2988}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002989#endif /* CONFIG_NFS_V4_1 */
2990
Benny Halevy686841b2009-08-14 17:19:48 +03002991static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2992{
2993 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2994 "Remaining buffer length is %tu words.\n",
2995 func, xdr->end - xdr->p);
2996}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997
Trond Myklebust683b57b2006-06-09 09:34:22 -04002998static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999{
Al Viro8687b632006-10-19 23:28:48 -07003000 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001
Benny Halevyc0eae662009-08-14 17:20:14 +03003002 p = xdr_inline_decode(xdr, 4);
3003 if (unlikely(!p))
3004 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003005 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003006 p = xdr_inline_decode(xdr, *len);
3007 if (unlikely(!p))
3008 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 *string = (char *)p;
3010 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003011out_overflow:
3012 print_overflow_msg(__func__, xdr);
3013 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014}
3015
3016static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3017{
Al Viro8687b632006-10-19 23:28:48 -07003018 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019
Benny Halevyc0eae662009-08-14 17:20:14 +03003020 p = xdr_inline_decode(xdr, 8);
3021 if (unlikely(!p))
3022 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003023 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003024 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003025
Benny Halevyc0eae662009-08-14 17:20:14 +03003026 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3027 if (unlikely(!p))
3028 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 hdr->tag = (char *)p;
3030 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003031 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003032 if (unlikely(hdr->nops < 1))
3033 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003035out_overflow:
3036 print_overflow_msg(__func__, xdr);
3037 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038}
3039
3040static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3041{
Al Viro8687b632006-10-19 23:28:48 -07003042 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 uint32_t opnum;
3044 int32_t nfserr;
3045
Benny Halevyc0eae662009-08-14 17:20:14 +03003046 p = xdr_inline_decode(xdr, 8);
3047 if (unlikely(!p))
3048 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003049 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003051 dprintk("nfs: Server returned operation"
3052 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 opnum, expected);
3054 return -EIO;
3055 }
Benny Halevycccddf42009-08-14 17:20:19 +03003056 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003058 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003060out_overflow:
3061 print_overflow_msg(__func__, xdr);
3062 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063}
3064
3065/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003066static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067{
Al Viro8687b632006-10-19 23:28:48 -07003068 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003069 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 char *str;
3071
Benny Halevyc0eae662009-08-14 17:20:14 +03003072 p = xdr_inline_decode(xdr, 12);
3073 if (likely(p))
3074 return decode_opaque_inline(xdr, &strlen, &str);
3075 print_overflow_msg(__func__, xdr);
3076 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077}
3078
3079static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3080{
Al Viro8687b632006-10-19 23:28:48 -07003081 uint32_t bmlen;
3082 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083
Benny Halevyc0eae662009-08-14 17:20:14 +03003084 p = xdr_inline_decode(xdr, 4);
3085 if (unlikely(!p))
3086 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003087 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088
Fred Isamandae100c2011-07-30 20:52:37 -04003089 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003090 p = xdr_inline_decode(xdr, (bmlen << 2));
3091 if (unlikely(!p))
3092 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003094 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003095 if (bmlen > 1) {
3096 bitmap[1] = be32_to_cpup(p++);
3097 if (bmlen > 2)
3098 bitmap[2] = be32_to_cpup(p);
3099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 }
3101 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003102out_overflow:
3103 print_overflow_msg(__func__, xdr);
3104 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105}
3106
Trond Myklebust256e48b2012-06-21 11:18:13 -04003107static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108{
Al Viro8687b632006-10-19 23:28:48 -07003109 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
Benny Halevyc0eae662009-08-14 17:20:14 +03003111 p = xdr_inline_decode(xdr, 4);
3112 if (unlikely(!p))
3113 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003114 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003115 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003117out_overflow:
3118 print_overflow_msg(__func__, xdr);
3119 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120}
3121
3122static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3123{
3124 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003125 int ret;
3126 ret = decode_attr_bitmap(xdr, bitmask);
3127 if (unlikely(ret < 0))
3128 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3130 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003131 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3132 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3133 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 return 0;
3135}
3136
3137static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3138{
Al Viro8687b632006-10-19 23:28:48 -07003139 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003140 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141
3142 *type = 0;
3143 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3144 return -EIO;
3145 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003146 p = xdr_inline_decode(xdr, 4);
3147 if (unlikely(!p))
3148 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003149 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003151 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 return -EIO;
3153 }
3154 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003155 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003157 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003158 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003159out_overflow:
3160 print_overflow_msg(__func__, xdr);
3161 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162}
3163
Chuck Lever264e6352012-03-01 17:02:05 -05003164static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3165 uint32_t *bitmap, uint32_t *type)
3166{
3167 __be32 *p;
3168
3169 *type = 0;
3170 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3171 return -EIO;
3172 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3173 p = xdr_inline_decode(xdr, 4);
3174 if (unlikely(!p))
3175 goto out_overflow;
3176 *type = be32_to_cpup(p);
3177 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3178 }
3179 dprintk("%s: expire type=0x%x\n", __func__, *type);
3180 return 0;
3181out_overflow:
3182 print_overflow_msg(__func__, xdr);
3183 return -EIO;
3184}
3185
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3187{
Al Viro8687b632006-10-19 23:28:48 -07003188 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003189 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190
3191 *change = 0;
3192 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3193 return -EIO;
3194 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003195 p = xdr_inline_decode(xdr, 8);
3196 if (unlikely(!p))
3197 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003198 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003200 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003202 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003204 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003205out_overflow:
3206 print_overflow_msg(__func__, xdr);
3207 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208}
3209
3210static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3211{
Al Viro8687b632006-10-19 23:28:48 -07003212 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003213 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214
3215 *size = 0;
3216 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3217 return -EIO;
3218 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003219 p = xdr_inline_decode(xdr, 8);
3220 if (unlikely(!p))
3221 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003222 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003224 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003226 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003227 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003228out_overflow:
3229 print_overflow_msg(__func__, xdr);
3230 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231}
3232
3233static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3234{
Al Viro8687b632006-10-19 23:28:48 -07003235 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236
3237 *res = 0;
3238 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3239 return -EIO;
3240 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003241 p = xdr_inline_decode(xdr, 4);
3242 if (unlikely(!p))
3243 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003244 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3246 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003247 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003249out_overflow:
3250 print_overflow_msg(__func__, xdr);
3251 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252}
3253
3254static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3255{
Al Viro8687b632006-10-19 23:28:48 -07003256 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257
3258 *res = 0;
3259 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3260 return -EIO;
3261 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003262 p = xdr_inline_decode(xdr, 4);
3263 if (unlikely(!p))
3264 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003265 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3267 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003268 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003270out_overflow:
3271 print_overflow_msg(__func__, xdr);
3272 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273}
3274
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003275static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276{
Al Viro8687b632006-10-19 23:28:48 -07003277 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003278 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
3280 fsid->major = 0;
3281 fsid->minor = 0;
3282 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3283 return -EIO;
3284 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003285 p = xdr_inline_decode(xdr, 16);
3286 if (unlikely(!p))
3287 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003288 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003289 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003291 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003293 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 (unsigned long long)fsid->major,
3295 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003296 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003297out_overflow:
3298 print_overflow_msg(__func__, xdr);
3299 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300}
3301
3302static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3303{
Al Viro8687b632006-10-19 23:28:48 -07003304 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
3306 *res = 60;
3307 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3308 return -EIO;
3309 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003310 p = xdr_inline_decode(xdr, 4);
3311 if (unlikely(!p))
3312 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003313 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3315 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003316 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003318out_overflow:
3319 print_overflow_msg(__func__, xdr);
3320 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321}
3322
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003323static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003324{
3325 __be32 *p;
3326
3327 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3328 return -EIO;
3329 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3330 p = xdr_inline_decode(xdr, 4);
3331 if (unlikely(!p))
3332 goto out_overflow;
3333 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003334 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003335 }
3336 return 0;
3337out_overflow:
3338 print_overflow_msg(__func__, xdr);
3339 return -EIO;
3340}
3341
3342static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3343{
3344 __be32 *p;
3345 int len;
3346
Trond Myklebust7ad07352010-10-23 15:34:20 -04003347 if (fh != NULL)
3348 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003349
3350 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3351 return -EIO;
3352 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3353 p = xdr_inline_decode(xdr, 4);
3354 if (unlikely(!p))
3355 goto out_overflow;
3356 len = be32_to_cpup(p);
3357 if (len > NFS4_FHSIZE)
3358 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003359 p = xdr_inline_decode(xdr, len);
3360 if (unlikely(!p))
3361 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003362 if (fh != NULL) {
3363 memcpy(fh->data, p, len);
3364 fh->size = len;
3365 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003366 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3367 }
3368 return 0;
3369out_overflow:
3370 print_overflow_msg(__func__, xdr);
3371 return -EIO;
3372}
3373
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3375{
Al Viro8687b632006-10-19 23:28:48 -07003376 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377
3378 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3379 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3380 return -EIO;
3381 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003382 p = xdr_inline_decode(xdr, 4);
3383 if (unlikely(!p))
3384 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003385 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3387 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003388 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003390out_overflow:
3391 print_overflow_msg(__func__, xdr);
3392 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393}
3394
3395static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3396{
Al Viro8687b632006-10-19 23:28:48 -07003397 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003398 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399
3400 *fileid = 0;
3401 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3402 return -EIO;
3403 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003404 p = xdr_inline_decode(xdr, 8);
3405 if (unlikely(!p))
3406 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003407 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003409 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003411 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003412 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003413out_overflow:
3414 print_overflow_msg(__func__, xdr);
3415 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416}
3417
Manoj Naik99baf622006-06-09 09:34:24 -04003418static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3419{
Al Viro8687b632006-10-19 23:28:48 -07003420 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003421 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003422
3423 *fileid = 0;
3424 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3425 return -EIO;
3426 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003427 p = xdr_inline_decode(xdr, 8);
3428 if (unlikely(!p))
3429 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003430 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003431 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003432 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003433 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003434 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003435 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003436out_overflow:
3437 print_overflow_msg(__func__, xdr);
3438 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003439}
3440
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3442{
Al Viro8687b632006-10-19 23:28:48 -07003443 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 int status = 0;
3445
3446 *res = 0;
3447 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3448 return -EIO;
3449 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003450 p = xdr_inline_decode(xdr, 8);
3451 if (unlikely(!p))
3452 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003453 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3455 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003456 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003458out_overflow:
3459 print_overflow_msg(__func__, xdr);
3460 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461}
3462
3463static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3464{
Al Viro8687b632006-10-19 23:28:48 -07003465 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 int status = 0;
3467
3468 *res = 0;
3469 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3470 return -EIO;
3471 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003472 p = xdr_inline_decode(xdr, 8);
3473 if (unlikely(!p))
3474 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003475 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3477 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003478 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003480out_overflow:
3481 print_overflow_msg(__func__, xdr);
3482 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483}
3484
3485static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3486{
Al Viro8687b632006-10-19 23:28:48 -07003487 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 int status = 0;
3489
3490 *res = 0;
3491 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3492 return -EIO;
3493 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003494 p = xdr_inline_decode(xdr, 8);
3495 if (unlikely(!p))
3496 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003497 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3499 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003500 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003502out_overflow:
3503 print_overflow_msg(__func__, xdr);
3504 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505}
3506
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003507static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3508{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003509 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003510 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003511 int status = 0;
3512
Benny Halevyc0eae662009-08-14 17:20:14 +03003513 p = xdr_inline_decode(xdr, 4);
3514 if (unlikely(!p))
3515 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003516 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003517 if (n == 0)
3518 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003519 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003520 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3521 dprintk("cannot parse %d components in path\n", n);
3522 goto out_eio;
3523 }
3524 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003525 struct nfs4_string *component = &path->components[path->ncomponents];
3526 status = decode_opaque_inline(xdr, &component->len, &component->data);
3527 if (unlikely(status != 0))
3528 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003529 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003530 pr_cont("%s%.*s ",
3531 (path->ncomponents != n ? "/ " : ""),
3532 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003533 }
3534out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003535 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003536root_path:
3537/* a root pathname is sent as a zero component4 */
3538 path->ncomponents = 1;
3539 path->components[0].len=0;
3540 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003541 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003542 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003543out_eio:
3544 dprintk(" status %d", status);
3545 status = -EIO;
3546 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003547out_overflow:
3548 print_overflow_msg(__func__, xdr);
3549 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003550}
3551
3552static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003553{
3554 int n;
Al Viro8687b632006-10-19 23:28:48 -07003555 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003556 int status = -EIO;
3557
3558 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3559 goto out;
3560 status = 0;
3561 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3562 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003563 status = -EIO;
3564 /* Ignore borken servers that return unrequested attrs */
3565 if (unlikely(res == NULL))
3566 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003567 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003568 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003569 if (unlikely(status != 0))
3570 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003571 p = xdr_inline_decode(xdr, 4);
3572 if (unlikely(!p))
3573 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003574 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003575 if (n <= 0)
3576 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003577 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003578 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003579 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003580
Trond Myklebust809b4262013-03-27 11:54:45 -04003581 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3582 break;
3583 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003584 p = xdr_inline_decode(xdr, 4);
3585 if (unlikely(!p))
3586 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003587 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003588
Chuck Lever02a29762012-03-01 17:00:31 -05003589 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003590 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3591 struct nfs4_string *server;
3592
3593 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003594 unsigned int i;
3595 dprintk("%s: using first %u of %u servers "
3596 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003597 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003598 NFS4_FS_LOCATION_MAXSERVERS,
3599 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003600 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003601 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003602 char *data;
3603 status = decode_opaque_inline(xdr, &len, &data);
3604 if (unlikely(status != 0))
3605 goto out_eio;
3606 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003607 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003608 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003609 server = &loc->servers[loc->nservers];
3610 status = decode_opaque_inline(xdr, &server->len, &server->data);
3611 if (unlikely(status != 0))
3612 goto out_eio;
3613 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003614 }
3615 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003616 if (unlikely(status != 0))
3617 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003618 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003619 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003620 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003621out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003622 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003623 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003624out_overflow:
3625 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003626out_eio:
3627 status = -EIO;
3628 goto out;
3629}
3630
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3632{
Al Viro8687b632006-10-19 23:28:48 -07003633 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 int status = 0;
3635
3636 *res = 0;
3637 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3638 return -EIO;
3639 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003640 p = xdr_inline_decode(xdr, 8);
3641 if (unlikely(!p))
3642 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003643 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3645 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003646 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003648out_overflow:
3649 print_overflow_msg(__func__, xdr);
3650 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651}
3652
3653static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3654{
Al Viro8687b632006-10-19 23:28:48 -07003655 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656 int status = 0;
3657
3658 *maxlink = 1;
3659 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3660 return -EIO;
3661 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003662 p = xdr_inline_decode(xdr, 4);
3663 if (unlikely(!p))
3664 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003665 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3667 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003668 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003670out_overflow:
3671 print_overflow_msg(__func__, xdr);
3672 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673}
3674
3675static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3676{
Al Viro8687b632006-10-19 23:28:48 -07003677 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 int status = 0;
3679
3680 *maxname = 1024;
3681 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3682 return -EIO;
3683 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003684 p = xdr_inline_decode(xdr, 4);
3685 if (unlikely(!p))
3686 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003687 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3689 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003690 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003692out_overflow:
3693 print_overflow_msg(__func__, xdr);
3694 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695}
3696
3697static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3698{
Al Viro8687b632006-10-19 23:28:48 -07003699 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 int status = 0;
3701
3702 *res = 1024;
3703 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3704 return -EIO;
3705 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3706 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003707 p = xdr_inline_decode(xdr, 8);
3708 if (unlikely(!p))
3709 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003710 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 if (maxread > 0x7FFFFFFF)
3712 maxread = 0x7FFFFFFF;
3713 *res = (uint32_t)maxread;
3714 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3715 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003716 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003718out_overflow:
3719 print_overflow_msg(__func__, xdr);
3720 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721}
3722
3723static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3724{
Al Viro8687b632006-10-19 23:28:48 -07003725 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 int status = 0;
3727
3728 *res = 1024;
3729 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3730 return -EIO;
3731 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3732 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003733 p = xdr_inline_decode(xdr, 8);
3734 if (unlikely(!p))
3735 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003736 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 if (maxwrite > 0x7FFFFFFF)
3738 maxwrite = 0x7FFFFFFF;
3739 *res = (uint32_t)maxwrite;
3740 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3741 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003742 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003744out_overflow:
3745 print_overflow_msg(__func__, xdr);
3746 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747}
3748
Trond Myklebustbca79472009-03-11 14:10:26 -04003749static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750{
Trond Myklebustbca79472009-03-11 14:10:26 -04003751 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003752 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003753 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754
3755 *mode = 0;
3756 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3757 return -EIO;
3758 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003759 p = xdr_inline_decode(xdr, 4);
3760 if (unlikely(!p))
3761 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003762 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003763 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003765 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003767 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003768 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003769out_overflow:
3770 print_overflow_msg(__func__, xdr);
3771 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772}
3773
3774static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3775{
Al Viro8687b632006-10-19 23:28:48 -07003776 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003777 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778
3779 *nlink = 1;
3780 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3781 return -EIO;
3782 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003783 p = xdr_inline_decode(xdr, 4);
3784 if (unlikely(!p))
3785 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003786 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003788 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003790 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003791 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003792out_overflow:
3793 print_overflow_msg(__func__, xdr);
3794 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795}
3796
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003797static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003798 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003799 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800{
Al Viro8687b632006-10-19 23:28:48 -07003801 uint32_t len;
3802 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003803 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804
Eric W. Biedermane5782072013-02-01 14:22:02 -08003805 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3807 return -EIO;
3808 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003809 p = xdr_inline_decode(xdr, 4);
3810 if (unlikely(!p))
3811 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003812 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003813 p = xdr_inline_decode(xdr, len);
3814 if (unlikely(!p))
3815 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003816 if (owner_name != NULL) {
3817 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3818 if (owner_name->data != NULL) {
3819 owner_name->len = len;
3820 ret = NFS_ATTR_FATTR_OWNER_NAME;
3821 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003822 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003823 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003824 ret = NFS_ATTR_FATTR_OWNER;
3825 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003827 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003829 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003830 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3832 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003833 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003834 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003835out_overflow:
3836 print_overflow_msg(__func__, xdr);
3837 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838}
3839
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003840static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003841 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003842 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843{
Al Viro8687b632006-10-19 23:28:48 -07003844 uint32_t len;
3845 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003846 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847
Eric W. Biedermane5782072013-02-01 14:22:02 -08003848 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3850 return -EIO;
3851 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003852 p = xdr_inline_decode(xdr, 4);
3853 if (unlikely(!p))
3854 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003855 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003856 p = xdr_inline_decode(xdr, len);
3857 if (unlikely(!p))
3858 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003859 if (group_name != NULL) {
3860 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3861 if (group_name->data != NULL) {
3862 group_name->len = len;
3863 ret = NFS_ATTR_FATTR_GROUP_NAME;
3864 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003865 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003866 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003867 ret = NFS_ATTR_FATTR_GROUP;
3868 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003870 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003872 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003873 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3875 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003876 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003877 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003878out_overflow:
3879 print_overflow_msg(__func__, xdr);
3880 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881}
3882
3883static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3884{
Al Viro8687b632006-10-19 23:28:48 -07003885 uint32_t major = 0, minor = 0;
3886 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003887 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888
3889 *rdev = MKDEV(0,0);
3890 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3891 return -EIO;
3892 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3893 dev_t tmp;
3894
Benny Halevyc0eae662009-08-14 17:20:14 +03003895 p = xdr_inline_decode(xdr, 8);
3896 if (unlikely(!p))
3897 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003898 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003899 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900 tmp = MKDEV(major, minor);
3901 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3902 *rdev = tmp;
3903 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003904 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003906 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003907 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003908out_overflow:
3909 print_overflow_msg(__func__, xdr);
3910 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911}
3912
3913static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3914{
Al Viro8687b632006-10-19 23:28:48 -07003915 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 int status = 0;
3917
3918 *res = 0;
3919 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3920 return -EIO;
3921 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003922 p = xdr_inline_decode(xdr, 8);
3923 if (unlikely(!p))
3924 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003925 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3927 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003928 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003930out_overflow:
3931 print_overflow_msg(__func__, xdr);
3932 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933}
3934
3935static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3936{
Al Viro8687b632006-10-19 23:28:48 -07003937 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 int status = 0;
3939
3940 *res = 0;
3941 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3942 return -EIO;
3943 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003944 p = xdr_inline_decode(xdr, 8);
3945 if (unlikely(!p))
3946 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003947 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3949 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003950 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003952out_overflow:
3953 print_overflow_msg(__func__, xdr);
3954 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955}
3956
3957static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3958{
Al Viro8687b632006-10-19 23:28:48 -07003959 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960 int status = 0;
3961
3962 *res = 0;
3963 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3964 return -EIO;
3965 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003966 p = xdr_inline_decode(xdr, 8);
3967 if (unlikely(!p))
3968 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003969 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3971 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003972 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003974out_overflow:
3975 print_overflow_msg(__func__, xdr);
3976 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977}
3978
3979static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3980{
Al Viro8687b632006-10-19 23:28:48 -07003981 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003982 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983
3984 *used = 0;
3985 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3986 return -EIO;
3987 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003988 p = xdr_inline_decode(xdr, 8);
3989 if (unlikely(!p))
3990 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003991 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003993 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003995 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003997 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003998out_overflow:
3999 print_overflow_msg(__func__, xdr);
4000 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001}
4002
4003static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4004{
Al Viro8687b632006-10-19 23:28:48 -07004005 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 uint64_t sec;
4007 uint32_t nsec;
4008
Benny Halevyc0eae662009-08-14 17:20:14 +03004009 p = xdr_inline_decode(xdr, 12);
4010 if (unlikely(!p))
4011 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004012 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004013 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 time->tv_sec = (time_t)sec;
4015 time->tv_nsec = (long)nsec;
4016 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004017out_overflow:
4018 print_overflow_msg(__func__, xdr);
4019 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020}
4021
4022static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4023{
4024 int status = 0;
4025
4026 time->tv_sec = 0;
4027 time->tv_nsec = 0;
4028 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4029 return -EIO;
4030 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4031 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004032 if (status == 0)
4033 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4035 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004036 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 return status;
4038}
4039
4040static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4041{
4042 int status = 0;
4043
4044 time->tv_sec = 0;
4045 time->tv_nsec = 0;
4046 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4047 return -EIO;
4048 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4049 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004050 if (status == 0)
4051 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4053 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004054 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 return status;
4056}
4057
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004058static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4059 struct timespec *time)
4060{
4061 int status = 0;
4062
4063 time->tv_sec = 0;
4064 time->tv_nsec = 0;
4065 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4066 return -EIO;
4067 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4068 status = decode_attr_time(xdr, time);
4069 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4070 }
4071 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4072 (long)time->tv_nsec);
4073 return status;
4074}
4075
David Quigleyaa9c2662013-05-22 12:50:44 -04004076static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4077 struct nfs4_label *label)
4078{
4079 uint32_t pi = 0;
4080 uint32_t lfs = 0;
4081 __u32 len;
4082 __be32 *p;
4083 int status = 0;
4084
4085 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4086 return -EIO;
4087 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4088 p = xdr_inline_decode(xdr, 4);
4089 if (unlikely(!p))
4090 goto out_overflow;
4091 lfs = be32_to_cpup(p++);
4092 p = xdr_inline_decode(xdr, 4);
4093 if (unlikely(!p))
4094 goto out_overflow;
4095 pi = be32_to_cpup(p++);
4096 p = xdr_inline_decode(xdr, 4);
4097 if (unlikely(!p))
4098 goto out_overflow;
4099 len = be32_to_cpup(p++);
4100 p = xdr_inline_decode(xdr, len);
4101 if (unlikely(!p))
4102 goto out_overflow;
4103 if (len < NFS4_MAXLABELLEN) {
4104 if (label) {
4105 memcpy(label->label, p, len);
4106 label->len = len;
4107 label->pi = pi;
4108 label->lfs = lfs;
4109 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4110 }
4111 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4112 } else
4113 printk(KERN_WARNING "%s: label too long (%u)!\n",
4114 __func__, len);
4115 }
4116 if (label && label->label)
4117 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4118 (char *)label->label, label->len, label->pi, label->lfs);
4119 return status;
4120
4121out_overflow:
4122 print_overflow_msg(__func__, xdr);
4123 return -EIO;
4124}
4125
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4127{
4128 int status = 0;
4129
4130 time->tv_sec = 0;
4131 time->tv_nsec = 0;
4132 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4133 return -EIO;
4134 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4135 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004136 if (status == 0)
4137 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4139 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004140 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 return status;
4142}
4143
Trond Myklebust256e48b2012-06-21 11:18:13 -04004144static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145{
4146 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004147 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148
4149 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004150 dprintk("%s: server returned incorrect attribute length: "
4151 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004152 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 attrwords << 2,
4154 (attrwords < nwords) ? '<' : '>',
4155 nwords << 2);
4156 return -EIO;
4157 }
4158 return 0;
4159}
4160
4161static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4162{
Al Viro8687b632006-10-19 23:28:48 -07004163 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164
Benny Halevyc0eae662009-08-14 17:20:14 +03004165 p = xdr_inline_decode(xdr, 20);
4166 if (unlikely(!p))
4167 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004168 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004169 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004170 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004172out_overflow:
4173 print_overflow_msg(__func__, xdr);
4174 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175}
4176
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004177static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178{
Al Viro8687b632006-10-19 23:28:48 -07004179 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 uint32_t supp, acc;
4181 int status;
4182
4183 status = decode_op_hdr(xdr, OP_ACCESS);
4184 if (status)
4185 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004186 p = xdr_inline_decode(xdr, 8);
4187 if (unlikely(!p))
4188 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004189 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004190 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004191 *supported = supp;
4192 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004194out_overflow:
4195 print_overflow_msg(__func__, xdr);
4196 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197}
4198
Benny Halevy07d30432009-08-14 17:19:52 +03004199static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200{
Al Viro8687b632006-10-19 23:28:48 -07004201 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004202
4203 p = xdr_inline_decode(xdr, len);
4204 if (likely(p)) {
4205 memcpy(buf, p, len);
4206 return 0;
4207 }
4208 print_overflow_msg(__func__, xdr);
4209 return -EIO;
4210}
4211
4212static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4213{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004214 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215}
4216
4217static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4218{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 int status;
4220
4221 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004222 if (status != -EIO)
4223 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004224 if (!status)
4225 status = decode_stateid(xdr, &res->stateid);
4226 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227}
4228
Benny Halevydb942bb2009-08-14 17:19:56 +03004229static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4230{
Chuck Levercd937102012-03-02 17:14:31 -05004231 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232}
4233
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004234static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4235{
4236 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4237}
4238
Fred Isaman0b7c0152012-04-20 14:47:39 -04004239static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241 int status;
4242
4243 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004244 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004245 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004246 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247}
4248
4249static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4250{
Al Viro8687b632006-10-19 23:28:48 -07004251 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252 uint32_t bmlen;
4253 int status;
4254
4255 status = decode_op_hdr(xdr, OP_CREATE);
4256 if (status)
4257 return status;
4258 if ((status = decode_change_info(xdr, cinfo)))
4259 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004260 p = xdr_inline_decode(xdr, 4);
4261 if (unlikely(!p))
4262 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004263 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004264 p = xdr_inline_decode(xdr, bmlen << 2);
4265 if (likely(p))
4266 return 0;
4267out_overflow:
4268 print_overflow_msg(__func__, xdr);
4269 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270}
4271
4272static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4273{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004274 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004275 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276 int status;
4277
4278 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4279 goto xdr_error;
4280 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4281 goto xdr_error;
4282 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4283 goto xdr_error;
4284 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4285 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004286 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4287 &res->fh_expire_type)) != 0)
4288 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4290 goto xdr_error;
4291 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4292 goto xdr_error;
4293 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4294 goto xdr_error;
4295 status = verify_attr_len(xdr, savep, attrlen);
4296xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004297 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298 return status;
4299}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004300
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4302{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004303 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004304 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004306
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4308 goto xdr_error;
4309 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4310 goto xdr_error;
4311 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4312 goto xdr_error;
4313
4314 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4315 goto xdr_error;
4316 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4317 goto xdr_error;
4318 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4319 goto xdr_error;
4320 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4321 goto xdr_error;
4322 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4323 goto xdr_error;
4324 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4325 goto xdr_error;
4326
4327 status = verify_attr_len(xdr, savep, attrlen);
4328xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004329 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 return status;
4331}
4332
4333static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4334{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004335 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004336 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004338
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4340 goto xdr_error;
4341 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4342 goto xdr_error;
4343 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4344 goto xdr_error;
4345
4346 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4347 goto xdr_error;
4348 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4349 goto xdr_error;
4350
4351 status = verify_attr_len(xdr, savep, attrlen);
4352xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004353 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 return status;
4355}
4356
Andy Adamson88034c32012-05-23 05:02:34 -04004357static int decode_threshold_hint(struct xdr_stream *xdr,
4358 uint32_t *bitmap,
4359 uint64_t *res,
4360 uint32_t hint_bit)
4361{
4362 __be32 *p;
4363
4364 *res = 0;
4365 if (likely(bitmap[0] & hint_bit)) {
4366 p = xdr_inline_decode(xdr, 8);
4367 if (unlikely(!p))
4368 goto out_overflow;
4369 xdr_decode_hyper(p, res);
4370 }
4371 return 0;
4372out_overflow:
4373 print_overflow_msg(__func__, xdr);
4374 return -EIO;
4375}
4376
4377static int decode_first_threshold_item4(struct xdr_stream *xdr,
4378 struct nfs4_threshold *res)
4379{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004380 __be32 *p;
4381 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004382 uint32_t bitmap[3] = {0,}, attrlen;
4383 int status;
4384
4385 /* layout type */
4386 p = xdr_inline_decode(xdr, 4);
4387 if (unlikely(!p)) {
4388 print_overflow_msg(__func__, xdr);
4389 return -EIO;
4390 }
4391 res->l_type = be32_to_cpup(p);
4392
4393 /* thi_hintset bitmap */
4394 status = decode_attr_bitmap(xdr, bitmap);
4395 if (status < 0)
4396 goto xdr_error;
4397
4398 /* thi_hintlist length */
4399 status = decode_attr_length(xdr, &attrlen, &savep);
4400 if (status < 0)
4401 goto xdr_error;
4402 /* thi_hintlist */
4403 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4404 if (status < 0)
4405 goto xdr_error;
4406 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4407 if (status < 0)
4408 goto xdr_error;
4409 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4410 THRESHOLD_RD_IO);
4411 if (status < 0)
4412 goto xdr_error;
4413 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4414 THRESHOLD_WR_IO);
4415 if (status < 0)
4416 goto xdr_error;
4417
4418 status = verify_attr_len(xdr, savep, attrlen);
4419 res->bm = bitmap[0];
4420
4421 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4422 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4423 res->wr_io_sz);
4424xdr_error:
4425 dprintk("%s ret=%d!\n", __func__, status);
4426 return status;
4427}
4428
4429/*
4430 * Thresholds on pNFS direct I/O vrs MDS I/O
4431 */
4432static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4433 uint32_t *bitmap,
4434 struct nfs4_threshold *res)
4435{
4436 __be32 *p;
4437 int status = 0;
4438 uint32_t num;
4439
4440 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4441 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004442 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004443 /* Did the server return an unrequested attribute? */
4444 if (unlikely(res == NULL))
4445 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004446 p = xdr_inline_decode(xdr, 4);
4447 if (unlikely(!p))
4448 goto out_overflow;
4449 num = be32_to_cpup(p);
4450 if (num == 0)
4451 return 0;
4452 if (num > 1)
4453 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4454 "drivers per filesystem not supported\n",
4455 __func__);
4456
4457 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004458 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004459 }
4460 return status;
4461out_overflow:
4462 print_overflow_msg(__func__, xdr);
4463 return -EIO;
4464}
4465
Bryan Schumakerae42c702010-10-21 16:33:17 -04004466static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4467 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004468 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004469 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470{
Trond Myklebustbca79472009-03-11 14:10:26 -04004471 int status;
4472 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004473 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004474 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004476 status = decode_attr_type(xdr, bitmap, &type);
4477 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004479 fattr->mode = 0;
4480 if (status != 0) {
4481 fattr->mode |= nfs_type2fmt[type];
4482 fattr->valid |= status;
4483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004485 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4486 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004488 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004489
4490 status = decode_attr_size(xdr, bitmap, &fattr->size);
4491 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004493 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004494
4495 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4496 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004498 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004499
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004500 err = 0;
4501 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004502 if (status < 0)
4503 goto xdr_error;
4504
4505 status = decode_attr_filehandle(xdr, bitmap, fh);
4506 if (status < 0)
4507 goto xdr_error;
4508
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004509 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4510 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004512 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004513
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004514 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004515 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004516 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004517 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004518
4519 status = decode_attr_mode(xdr, bitmap, &fmode);
4520 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004522 if (status != 0) {
4523 fattr->mode |= fmode;
4524 fattr->valid |= status;
4525 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004526
4527 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4528 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004530 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004531
Trond Myklebust6926afd2012-01-07 13:22:46 -05004532 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004533 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004535 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004536
Trond Myklebust6926afd2012-01-07 13:22:46 -05004537 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004538 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004540 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004541
4542 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4543 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004545 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004546
4547 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4548 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004550 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004551
4552 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4553 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004555 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004556
4557 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4558 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004560 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004561
4562 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4563 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004565 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004566
Trond Myklebust28331a42011-04-27 13:47:52 -04004567 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004568 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004569 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004570 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004571
Andy Adamson88034c32012-05-23 05:02:34 -04004572 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4573 if (status < 0)
4574 goto xdr_error;
4575
David Quigleyaa9c2662013-05-22 12:50:44 -04004576 if (label) {
4577 status = decode_attr_security_label(xdr, bitmap, label);
4578 if (status < 0)
4579 goto xdr_error;
4580 fattr->valid |= status;
4581 }
4582
Bryan Schumakerae42c702010-10-21 16:33:17 -04004583xdr_error:
4584 dprintk("%s: xdr returned %d\n", __func__, -status);
4585 return status;
4586}
4587
4588static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004589 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004590 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004591{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004592 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004593 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004594 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004595 int status;
4596
4597 status = decode_op_hdr(xdr, OP_GETATTR);
4598 if (status < 0)
4599 goto xdr_error;
4600
4601 status = decode_attr_bitmap(xdr, bitmap);
4602 if (status < 0)
4603 goto xdr_error;
4604
4605 status = decode_attr_length(xdr, &attrlen, &savep);
4606 if (status < 0)
4607 goto xdr_error;
4608
David Quigleyaa9c2662013-05-22 12:50:44 -04004609 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4610 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004611 if (status < 0)
4612 goto xdr_error;
4613
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004614 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004615xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004616 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617 return status;
4618}
4619
David Quigleyaa9c2662013-05-22 12:50:44 -04004620static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4621 struct nfs4_label *label, const struct nfs_server *server)
4622{
4623 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4624}
4625
Bryan Schumakerae42c702010-10-21 16:33:17 -04004626static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004627 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004628{
David Quigleyaa9c2662013-05-22 12:50:44 -04004629 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004630}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631
Andy Adamson504913f2010-10-20 00:17:57 -04004632/*
4633 * Decode potentially multiple layout types. Currently we only support
4634 * one layout driver per file system.
4635 */
4636static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4637 uint32_t *layouttype)
4638{
4639 uint32_t *p;
4640 int num;
4641
4642 p = xdr_inline_decode(xdr, 4);
4643 if (unlikely(!p))
4644 goto out_overflow;
4645 num = be32_to_cpup(p);
4646
4647 /* pNFS is not supported by the underlying file system */
4648 if (num == 0) {
4649 *layouttype = 0;
4650 return 0;
4651 }
4652 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004653 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4654 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004655
4656 /* Decode and set first layout type, move xdr->p past unused types */
4657 p = xdr_inline_decode(xdr, num * 4);
4658 if (unlikely(!p))
4659 goto out_overflow;
4660 *layouttype = be32_to_cpup(p);
4661 return 0;
4662out_overflow:
4663 print_overflow_msg(__func__, xdr);
4664 return -EIO;
4665}
4666
4667/*
4668 * The type of file system exported.
4669 * Note we must ensure that layouttype is set in any non-error case.
4670 */
4671static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4672 uint32_t *layouttype)
4673{
4674 int status = 0;
4675
4676 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4677 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4678 return -EIO;
4679 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4680 status = decode_first_pnfs_layout_type(xdr, layouttype);
4681 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4682 } else
4683 *layouttype = 0;
4684 return status;
4685}
4686
Fred Isamandae100c2011-07-30 20:52:37 -04004687/*
4688 * The prefered block size for layout directed io
4689 */
4690static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4691 uint32_t *res)
4692{
4693 __be32 *p;
4694
4695 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4696 *res = 0;
4697 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4698 p = xdr_inline_decode(xdr, 4);
4699 if (unlikely(!p)) {
4700 print_overflow_msg(__func__, xdr);
4701 return -EIO;
4702 }
4703 *res = be32_to_cpup(p);
4704 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4705 }
4706 return 0;
4707}
4708
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4710{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004711 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004712 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713 int status;
4714
4715 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4716 goto xdr_error;
4717 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4718 goto xdr_error;
4719 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4720 goto xdr_error;
4721
4722 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4723
4724 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4725 goto xdr_error;
4726 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4727 goto xdr_error;
4728 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4729 goto xdr_error;
4730 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4731 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4732 goto xdr_error;
4733 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004734 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4735 if (status != 0)
4736 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004737 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4738 if (status != 0)
4739 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004740 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4741 if (status)
4742 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743
4744 status = verify_attr_len(xdr, savep, attrlen);
4745xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004746 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747 return status;
4748}
4749
4750static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4751{
Al Viro8687b632006-10-19 23:28:48 -07004752 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753 uint32_t len;
4754 int status;
4755
Trond Myklebust99367812007-07-17 21:52:41 -04004756 /* Zero handle first to allow comparisons */
4757 memset(fh, 0, sizeof(*fh));
4758
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759 status = decode_op_hdr(xdr, OP_GETFH);
4760 if (status)
4761 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762
Benny Halevyc0eae662009-08-14 17:20:14 +03004763 p = xdr_inline_decode(xdr, 4);
4764 if (unlikely(!p))
4765 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004766 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 if (len > NFS4_FHSIZE)
4768 return -EIO;
4769 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004770 p = xdr_inline_decode(xdr, len);
4771 if (unlikely(!p))
4772 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004773 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004775out_overflow:
4776 print_overflow_msg(__func__, xdr);
4777 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778}
4779
4780static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4781{
4782 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004783
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784 status = decode_op_hdr(xdr, OP_LINK);
4785 if (status)
4786 return status;
4787 return decode_change_info(xdr, cinfo);
4788}
4789
4790/*
4791 * We create the owner, so we know a proper owner.id length is 4.
4792 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004793static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004795 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004796 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004797 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004799 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004800 if (unlikely(!p))
4801 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004802 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004803 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004804 type = be32_to_cpup(p++); /* 4 byte read */
4805 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004806 fl->fl_start = (loff_t)offset;
4807 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4808 if (length == ~(uint64_t)0)
4809 fl->fl_end = OFFSET_MAX;
4810 fl->fl_type = F_WRLCK;
4811 if (type & 1)
4812 fl->fl_type = F_RDLCK;
4813 fl->fl_pid = 0;
4814 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004815 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4816 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4817 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004818 if (likely(p))
4819 return -NFS4ERR_DENIED;
4820out_overflow:
4821 print_overflow_msg(__func__, xdr);
4822 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004823}
4824
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004825static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827 int status;
4828
4829 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004830 if (status == -EIO)
4831 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004833 status = decode_stateid(xdr, &res->stateid);
4834 if (unlikely(status))
4835 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004837 status = decode_lock_denied(xdr, NULL);
4838 if (res->open_seqid != NULL)
4839 nfs_increment_open_seqid(status, res->open_seqid);
4840 nfs_increment_lock_seqid(status, res->lock_seqid);
4841out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842 return status;
4843}
4844
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004845static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846{
4847 int status;
4848 status = decode_op_hdr(xdr, OP_LOCKT);
4849 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004850 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851 return status;
4852}
4853
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004854static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856 int status;
4857
4858 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004859 if (status != -EIO)
4860 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004861 if (status == 0)
4862 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863 return status;
4864}
4865
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004866static int decode_release_lockowner(struct xdr_stream *xdr)
4867{
4868 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4869}
4870
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871static int decode_lookup(struct xdr_stream *xdr)
4872{
4873 return decode_op_hdr(xdr, OP_LOOKUP);
4874}
4875
4876/* This is too sick! */
4877static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4878{
Andy Adamson05d564f2008-12-23 16:06:15 -05004879 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880 uint32_t limit_type, nblocks, blocksize;
4881
Benny Halevyc0eae662009-08-14 17:20:14 +03004882 p = xdr_inline_decode(xdr, 12);
4883 if (unlikely(!p))
4884 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004885 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004887 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004888 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004889 break;
4890 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004891 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004892 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004893 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894 }
4895 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004896out_overflow:
4897 print_overflow_msg(__func__, xdr);
4898 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899}
4900
4901static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4902{
Andy Adamson05d564f2008-12-23 16:06:15 -05004903 __be32 *p;
4904 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004905 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906
Benny Halevyc0eae662009-08-14 17:20:14 +03004907 p = xdr_inline_decode(xdr, 4);
4908 if (unlikely(!p))
4909 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004910 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4912 res->delegation_type = 0;
4913 return 0;
4914 }
Benny Halevy07d30432009-08-14 17:19:52 +03004915 status = decode_stateid(xdr, &res->delegation);
4916 if (unlikely(status))
4917 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004918 p = xdr_inline_decode(xdr, 4);
4919 if (unlikely(!p))
4920 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004921 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004922
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004924 case NFS4_OPEN_DELEGATE_READ:
4925 res->delegation_type = FMODE_READ;
4926 break;
4927 case NFS4_OPEN_DELEGATE_WRITE:
4928 res->delegation_type = FMODE_WRITE|FMODE_READ;
4929 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930 return -EIO;
4931 }
David Howells7539bba2006-08-22 20:06:09 -04004932 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004933out_overflow:
4934 print_overflow_msg(__func__, xdr);
4935 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936}
4937
4938static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4939{
Andy Adamson05d564f2008-12-23 16:06:15 -05004940 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004941 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004942 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943
Andy Adamson05d564f2008-12-23 16:06:15 -05004944 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004945 if (status != -EIO)
4946 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004947 if (!status)
4948 status = decode_stateid(xdr, &res->stateid);
4949 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004950 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951
Andy Adamson05d564f2008-12-23 16:06:15 -05004952 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953
Benny Halevyc0eae662009-08-14 17:20:14 +03004954 p = xdr_inline_decode(xdr, 8);
4955 if (unlikely(!p))
4956 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004957 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004958 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004959 if (bmlen > 10)
4960 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961
Benny Halevyc0eae662009-08-14 17:20:14 +03004962 p = xdr_inline_decode(xdr, bmlen << 2);
4963 if (unlikely(!p))
4964 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004965 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4966 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004967 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004968 for (; i < NFS4_BITMAP_SIZE; i++)
4969 res->attrset[i] = 0;
4970
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 return decode_delegation(xdr, res);
4972xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004973 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004975out_overflow:
4976 print_overflow_msg(__func__, xdr);
4977 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978}
4979
4980static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4981{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 int status;
4983
Andy Adamson05d564f2008-12-23 16:06:15 -05004984 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004985 if (status != -EIO)
4986 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004987 if (!status)
4988 status = decode_stateid(xdr, &res->stateid);
4989 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990}
4991
4992static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4993{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994 int status;
4995
4996 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004997 if (status != -EIO)
4998 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004999 if (!status)
5000 status = decode_stateid(xdr, &res->stateid);
5001 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005002}
5003
5004static int decode_putfh(struct xdr_stream *xdr)
5005{
5006 return decode_op_hdr(xdr, OP_PUTFH);
5007}
5008
5009static int decode_putrootfh(struct xdr_stream *xdr)
5010{
5011 return decode_op_hdr(xdr, OP_PUTROOTFH);
5012}
5013
5014static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
5015{
Al Viro8687b632006-10-19 23:28:48 -07005016 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005017 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 int status;
5019
5020 status = decode_op_hdr(xdr, OP_READ);
5021 if (status)
5022 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005023 p = xdr_inline_decode(xdr, 8);
5024 if (unlikely(!p))
5025 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005026 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005027 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005028 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005030 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031 "count %u > recvd %u\n", count, recvd);
5032 count = recvd;
5033 eof = 0;
5034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035 res->eof = eof;
5036 res->count = count;
5037 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005038out_overflow:
5039 print_overflow_msg(__func__, xdr);
5040 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041}
5042
5043static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5044{
Chuck Leverbcecff72007-10-26 13:32:03 -04005045 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005046 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047
5048 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005049 if (!status)
5050 status = decode_verifier(xdr, readdir->verifier.data);
5051 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005053 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005054 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005055 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005056 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057}
5058
5059static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5060{
5061 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005062 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005063 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064 int status;
5065
5066 status = decode_op_hdr(xdr, OP_READLINK);
5067 if (status)
5068 return status;
5069
5070 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005071 p = xdr_inline_decode(xdr, 4);
5072 if (unlikely(!p))
5073 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005074 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005076 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077 return -ENAMETOOLONG;
5078 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005079 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005081 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082 "count %u > recvd %u\n", len, recvd);
5083 return -EIO;
5084 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085 /*
5086 * The XDR encode routine has set things up so that
5087 * the link text will be copied directly into the
5088 * buffer. We just have to do overflow-checking,
5089 * and and null-terminate the text (the VFS expects
5090 * null-termination).
5091 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005092 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005094out_overflow:
5095 print_overflow_msg(__func__, xdr);
5096 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097}
5098
5099static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5100{
5101 int status;
5102
5103 status = decode_op_hdr(xdr, OP_REMOVE);
5104 if (status)
5105 goto out;
5106 status = decode_change_info(xdr, cinfo);
5107out:
5108 return status;
5109}
5110
5111static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5112 struct nfs4_change_info *new_cinfo)
5113{
5114 int status;
5115
5116 status = decode_op_hdr(xdr, OP_RENAME);
5117 if (status)
5118 goto out;
5119 if ((status = decode_change_info(xdr, old_cinfo)))
5120 goto out;
5121 status = decode_change_info(xdr, new_cinfo);
5122out:
5123 return status;
5124}
5125
5126static int decode_renew(struct xdr_stream *xdr)
5127{
5128 return decode_op_hdr(xdr, OP_RENEW);
5129}
5130
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005131static int
5132decode_restorefh(struct xdr_stream *xdr)
5133{
5134 return decode_op_hdr(xdr, OP_RESTOREFH);
5135}
5136
J. Bruce Fields029d1052005-06-22 17:16:22 +00005137static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005138 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005139{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005140 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005141 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005142 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005143 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005144 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005145
Andy Adamsonbf118a32011-12-07 11:55:27 -05005146 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005147 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5148 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005149
Trond Myklebust519d3952012-08-14 17:30:10 -04005150 xdr_enter_page(xdr, xdr->buf->page_len);
5151
Trond Myklebustcff298c2012-08-14 17:14:17 -04005152 /* Calculate the offset of the page data */
5153 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005154
J. Bruce Fields029d1052005-06-22 17:16:22 +00005155 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5156 goto out;
5157 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5158 goto out;
5159
5160 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5161 return -EIO;
5162 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005163
Andy Adamsonbf118a32011-12-07 11:55:27 -05005164 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5165 * are stored with the acl data to handle the problem of
5166 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005167 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005168 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005169
5170 /* Check for receive buffer overflow */
5171 if (res->acl_len > (xdr->nwords << 2) ||
5172 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5173 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005174 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005175 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005176 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005177 } else
5178 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005179
5180out:
5181 return status;
5182}
5183
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184static int
5185decode_savefh(struct xdr_stream *xdr)
5186{
5187 return decode_op_hdr(xdr, OP_SAVEFH);
5188}
5189
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005190static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191{
Al Viro8687b632006-10-19 23:28:48 -07005192 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005193 uint32_t bmlen;
5194 int status;
5195
Linus Torvalds1da177e2005-04-16 15:20:36 -07005196 status = decode_op_hdr(xdr, OP_SETATTR);
5197 if (status)
5198 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005199 p = xdr_inline_decode(xdr, 4);
5200 if (unlikely(!p))
5201 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005202 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005203 p = xdr_inline_decode(xdr, bmlen << 2);
5204 if (likely(p))
5205 return 0;
5206out_overflow:
5207 print_overflow_msg(__func__, xdr);
5208 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209}
5210
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005211static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212{
Al Viro8687b632006-10-19 23:28:48 -07005213 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214 uint32_t opnum;
5215 int32_t nfserr;
5216
Benny Halevyc0eae662009-08-14 17:20:14 +03005217 p = xdr_inline_decode(xdr, 8);
5218 if (unlikely(!p))
5219 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005220 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005221 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005222 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005223 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005224 return -EIO;
5225 }
Benny Halevycccddf42009-08-14 17:20:19 +03005226 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005228 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5229 if (unlikely(!p))
5230 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005231 p = xdr_decode_hyper(p, &res->clientid);
5232 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233 } else if (nfserr == NFSERR_CLID_INUSE) {
5234 uint32_t len;
5235
5236 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005237 p = xdr_inline_decode(xdr, 4);
5238 if (unlikely(!p))
5239 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005240 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005241 p = xdr_inline_decode(xdr, len);
5242 if (unlikely(!p))
5243 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005244
5245 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005246 p = xdr_inline_decode(xdr, 4);
5247 if (unlikely(!p))
5248 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005249 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005250 p = xdr_inline_decode(xdr, len);
5251 if (unlikely(!p))
5252 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253 return -NFSERR_CLID_INUSE;
5254 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005255 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256
5257 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005258out_overflow:
5259 print_overflow_msg(__func__, xdr);
5260 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261}
5262
5263static int decode_setclientid_confirm(struct xdr_stream *xdr)
5264{
5265 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5266}
5267
5268static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5269{
Al Viro8687b632006-10-19 23:28:48 -07005270 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 int status;
5272
5273 status = decode_op_hdr(xdr, OP_WRITE);
5274 if (status)
5275 return status;
5276
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005277 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005278 if (unlikely(!p))
5279 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005280 res->count = be32_to_cpup(p++);
5281 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005282 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005283out_overflow:
5284 print_overflow_msg(__func__, xdr);
5285 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286}
5287
5288static int decode_delegreturn(struct xdr_stream *xdr)
5289{
5290 return decode_op_hdr(xdr, OP_DELEGRETURN);
5291}
5292
Chuck Leverfb15b262013-03-16 15:54:34 -04005293static int decode_secinfo_gss(struct xdr_stream *xdr,
5294 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005295{
Chuck Leverfb15b262013-03-16 15:54:34 -04005296 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005297 __be32 *p;
5298
5299 p = xdr_inline_decode(xdr, 4);
5300 if (unlikely(!p))
5301 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005302 oid_len = be32_to_cpup(p);
5303 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005304 goto out_err;
5305
Chuck Leverfb15b262013-03-16 15:54:34 -04005306 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005307 if (unlikely(!p))
5308 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005309 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5310 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005311
5312 p = xdr_inline_decode(xdr, 8);
5313 if (unlikely(!p))
5314 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005315 flavor->flavor_info.qop = be32_to_cpup(p++);
5316 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005317
5318 return 0;
5319
5320out_overflow:
5321 print_overflow_msg(__func__, xdr);
5322 return -EIO;
5323out_err:
5324 return -EINVAL;
5325}
5326
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005327static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005328{
Chuck Leverfb15b262013-03-16 15:54:34 -04005329 struct nfs4_secinfo4 *sec_flavor;
5330 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005331 int status;
5332 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005333
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005334 p = xdr_inline_decode(xdr, 4);
5335 if (unlikely(!p))
5336 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005337
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005338 res->flavors->num_flavors = 0;
5339 num_flavors = be32_to_cpup(p);
5340
5341 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005342 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005343 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005344 break;
5345
5346 p = xdr_inline_decode(xdr, 4);
5347 if (unlikely(!p))
5348 goto out_overflow;
5349 sec_flavor->flavor = be32_to_cpup(p);
5350
5351 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005352 status = decode_secinfo_gss(xdr, sec_flavor);
5353 if (status)
5354 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005355 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005356 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005357 }
5358
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005359 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005360out:
5361 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005362out_overflow:
5363 print_overflow_msg(__func__, xdr);
5364 return -EIO;
5365}
5366
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005367static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5368{
5369 int status = decode_op_hdr(xdr, OP_SECINFO);
5370 if (status)
5371 return status;
5372 return decode_secinfo_common(xdr, res);
5373}
5374
Benny Halevy99fe60d2009-04-01 09:22:29 -04005375#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005376static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5377{
5378 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5379 if (status)
5380 return status;
5381 return decode_secinfo_common(xdr, res);
5382}
5383
Benny Halevy99fe60d2009-04-01 09:22:29 -04005384static int decode_exchange_id(struct xdr_stream *xdr,
5385 struct nfs41_exchange_id_res *res)
5386{
5387 __be32 *p;
5388 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005389 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005390 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005391 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005392
5393 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5394 if (status)
5395 return status;
5396
Benny Halevyc0eae662009-08-14 17:20:14 +03005397 p = xdr_inline_decode(xdr, 8);
5398 if (unlikely(!p))
5399 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005400 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005401 p = xdr_inline_decode(xdr, 12);
5402 if (unlikely(!p))
5403 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005404 res->seqid = be32_to_cpup(p++);
5405 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005406
5407 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005408 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005409 if (dummy != SP4_NONE)
5410 return -EIO;
5411
Chuck Leveracdeb692012-05-21 22:46:16 -04005412 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005413 p = xdr_inline_decode(xdr, 8);
5414 if (unlikely(!p))
5415 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005416 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005417
Chuck Leveracdeb692012-05-21 22:46:16 -04005418 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005419 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5420 if (unlikely(status))
5421 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005422 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5423 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005424 memcpy(res->server_owner->major_id, dummy_str, dummy);
5425 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005426
Chuck Leveracdeb692012-05-21 22:46:16 -04005427 /* server_scope4 */
5428 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5429 if (unlikely(status))
5430 return status;
5431 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5432 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005433 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5434 res->server_scope->server_scope_sz = dummy;
5435
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005436 /* Implementation Id */
5437 p = xdr_inline_decode(xdr, 4);
5438 if (unlikely(!p))
5439 goto out_overflow;
5440 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005441
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005442 if (impl_id_count) {
5443 /* nii_domain */
5444 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5445 if (unlikely(status))
5446 return status;
5447 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5448 return -EIO;
5449 memcpy(res->impl_id->domain, dummy_str, dummy);
5450
5451 /* nii_name */
5452 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5453 if (unlikely(status))
5454 return status;
5455 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5456 return -EIO;
5457 memcpy(res->impl_id->name, dummy_str, dummy);
5458
5459 /* nii_date */
5460 p = xdr_inline_decode(xdr, 12);
5461 if (unlikely(!p))
5462 goto out_overflow;
5463 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5464 res->impl_id->date.nseconds = be32_to_cpup(p);
5465
5466 /* if there's more than one entry, ignore the rest */
5467 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005468 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005469out_overflow:
5470 print_overflow_msg(__func__, xdr);
5471 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005472}
Andy Adamsonfc931582009-04-01 09:22:31 -04005473
5474static int decode_chan_attrs(struct xdr_stream *xdr,
5475 struct nfs4_channel_attrs *attrs)
5476{
5477 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005478 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005479
Benny Halevyc0eae662009-08-14 17:20:14 +03005480 p = xdr_inline_decode(xdr, 28);
5481 if (unlikely(!p))
5482 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005483 val = be32_to_cpup(p++); /* headerpadsz */
5484 if (val)
5485 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005486 attrs->max_rqst_sz = be32_to_cpup(p++);
5487 attrs->max_resp_sz = be32_to_cpup(p++);
5488 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5489 attrs->max_ops = be32_to_cpup(p++);
5490 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005491 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005492 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005493 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5494 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005495 return -EINVAL;
5496 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005497 if (nr_attrs == 1) {
5498 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5499 if (unlikely(!p))
5500 goto out_overflow;
5501 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005502 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005503out_overflow:
5504 print_overflow_msg(__func__, xdr);
5505 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005506}
5507
Benny Halevye78291e2009-08-14 17:20:00 +03005508static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5509{
5510 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005511}
5512
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005513static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5514 struct nfs41_bind_conn_to_session_res *res)
5515{
5516 __be32 *p;
5517 int status;
5518
5519 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5520 if (!status)
5521 status = decode_sessionid(xdr, &res->session->sess_id);
5522 if (unlikely(status))
5523 return status;
5524
5525 /* dir flags, rdma mode bool */
5526 p = xdr_inline_decode(xdr, 8);
5527 if (unlikely(!p))
5528 goto out_overflow;
5529
5530 res->dir = be32_to_cpup(p++);
5531 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5532 return -EIO;
5533 if (be32_to_cpup(p) == 0)
5534 res->use_conn_in_rdma_mode = false;
5535 else
5536 res->use_conn_in_rdma_mode = true;
5537
5538 return 0;
5539out_overflow:
5540 print_overflow_msg(__func__, xdr);
5541 return -EIO;
5542}
5543
Andy Adamsonfc931582009-04-01 09:22:31 -04005544static int decode_create_session(struct xdr_stream *xdr,
5545 struct nfs41_create_session_res *res)
5546{
5547 __be32 *p;
5548 int status;
5549 struct nfs_client *clp = res->client;
5550 struct nfs4_session *session = clp->cl_session;
5551
5552 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005553 if (!status)
5554 status = decode_sessionid(xdr, &session->sess_id);
5555 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005556 return status;
5557
Andy Adamsonfc931582009-04-01 09:22:31 -04005558 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005559 p = xdr_inline_decode(xdr, 8);
5560 if (unlikely(!p))
5561 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005562 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005563 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005564
5565 /* Channel attributes */
5566 status = decode_chan_attrs(xdr, &session->fc_attrs);
5567 if (!status)
5568 status = decode_chan_attrs(xdr, &session->bc_attrs);
5569 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005570out_overflow:
5571 print_overflow_msg(__func__, xdr);
5572 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005573}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005574
5575static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5576{
5577 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5578}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005579
Trond Myklebust66245532012-05-25 17:18:09 -04005580static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5581{
5582 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5583}
5584
Ricardo Labiaga180197532009-12-05 16:08:40 -05005585static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5586{
5587 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5588}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005589#endif /* CONFIG_NFS_V4_1 */
5590
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005591static int decode_sequence(struct xdr_stream *xdr,
5592 struct nfs4_sequence_res *res,
5593 struct rpc_rqst *rqstp)
5594{
5595#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005596 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005597 struct nfs4_sessionid id;
5598 u32 dummy;
5599 int status;
5600 __be32 *p;
5601
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005602 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005603 return 0;
5604
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005605 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005606 if (!status)
5607 status = decode_sessionid(xdr, &id);
5608 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005609 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005610
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005611 /*
5612 * If the server returns different values for sessionID, slotID or
5613 * sequence number, the server is looney tunes.
5614 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005615 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005616 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005617
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005618 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005619 NFS4_MAX_SESSIONID_LEN)) {
5620 dprintk("%s Invalid session id\n", __func__);
5621 goto out_err;
5622 }
Benny Halevye78291e2009-08-14 17:20:00 +03005623
Benny Halevyc0eae662009-08-14 17:20:14 +03005624 p = xdr_inline_decode(xdr, 20);
5625 if (unlikely(!p))
5626 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005627
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005628 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005629 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005630 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005631 dprintk("%s Invalid sequence number\n", __func__);
5632 goto out_err;
5633 }
5634 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005635 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005636 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005637 dprintk("%s Invalid slot id\n", __func__);
5638 goto out_err;
5639 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005640 /* highest slot id */
5641 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005642 /* target highest slot id */
5643 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005644 /* result flags */
5645 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005646 status = 0;
5647out_err:
5648 res->sr_status = status;
5649 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005650out_overflow:
5651 print_overflow_msg(__func__, xdr);
5652 status = -EIO;
5653 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005654#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005655 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005656#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005657}
5658
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005659#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005660/*
5661 * TODO: Need to handle case when EOF != true;
5662 */
5663static int decode_getdevicelist(struct xdr_stream *xdr,
5664 struct pnfs_devicelist *res)
5665{
5666 __be32 *p;
5667 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005668 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005669
5670 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5671 if (status)
5672 return status;
5673
5674 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5675 if (unlikely(!p))
5676 goto out_overflow;
5677
5678 /* TODO: Skip cookie for now */
5679 p += 2;
5680
5681 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005682 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005683
5684 res->num_devs = be32_to_cpup(p);
5685
5686 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5687
5688 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005689 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005690 __func__, res->num_devs);
5691 return -EIO;
5692 }
5693
5694 p = xdr_inline_decode(xdr,
5695 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5696 if (unlikely(!p))
5697 goto out_overflow;
5698 for (i = 0; i < res->num_devs; i++)
5699 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5700 NFS4_DEVICEID4_SIZE);
5701 res->eof = be32_to_cpup(p);
5702 return 0;
5703out_overflow:
5704 print_overflow_msg(__func__, xdr);
5705 return -EIO;
5706}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005707
5708static int decode_getdeviceinfo(struct xdr_stream *xdr,
5709 struct pnfs_device *pdev)
5710{
5711 __be32 *p;
5712 uint32_t len, type;
5713 int status;
5714
5715 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5716 if (status) {
5717 if (status == -ETOOSMALL) {
5718 p = xdr_inline_decode(xdr, 4);
5719 if (unlikely(!p))
5720 goto out_overflow;
5721 pdev->mincount = be32_to_cpup(p);
5722 dprintk("%s: Min count too small. mincnt = %u\n",
5723 __func__, pdev->mincount);
5724 }
5725 return status;
5726 }
5727
5728 p = xdr_inline_decode(xdr, 8);
5729 if (unlikely(!p))
5730 goto out_overflow;
5731 type = be32_to_cpup(p++);
5732 if (type != pdev->layout_type) {
5733 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5734 __func__, pdev->layout_type, type);
5735 return -EINVAL;
5736 }
5737 /*
5738 * Get the length of the opaque device_addr4. xdr_read_pages places
5739 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5740 * and places the remaining xdr data in xdr_buf->tail
5741 */
5742 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005743 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5744 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005745
5746 /* Parse notification bitmap, verifying that it is zero. */
5747 p = xdr_inline_decode(xdr, 4);
5748 if (unlikely(!p))
5749 goto out_overflow;
5750 len = be32_to_cpup(p);
5751 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005752 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005753
5754 p = xdr_inline_decode(xdr, 4 * len);
5755 if (unlikely(!p))
5756 goto out_overflow;
5757 for (i = 0; i < len; i++, p++) {
5758 if (be32_to_cpup(p)) {
5759 dprintk("%s: notifications not supported\n",
5760 __func__);
5761 return -EIO;
5762 }
5763 }
5764 }
5765 return 0;
5766out_overflow:
5767 print_overflow_msg(__func__, xdr);
5768 return -EIO;
5769}
5770
5771static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5772 struct nfs4_layoutget_res *res)
5773{
5774 __be32 *p;
5775 int status;
5776 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005777 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005778
5779 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5780 if (status)
5781 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005782 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005783 if (unlikely(!p))
5784 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005785 res->return_on_close = be32_to_cpup(p);
5786 decode_stateid(xdr, &res->stateid);
5787 p = xdr_inline_decode(xdr, 4);
5788 if (unlikely(!p))
5789 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005790 layout_count = be32_to_cpup(p);
5791 if (!layout_count) {
5792 dprintk("%s: server responded with empty layout array\n",
5793 __func__);
5794 return -EINVAL;
5795 }
5796
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005797 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005798 if (unlikely(!p))
5799 goto out_overflow;
5800 p = xdr_decode_hyper(p, &res->range.offset);
5801 p = xdr_decode_hyper(p, &res->range.length);
5802 res->range.iomode = be32_to_cpup(p++);
5803 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005804 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005805
5806 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5807 __func__,
5808 (unsigned long)res->range.offset,
5809 (unsigned long)res->range.length,
5810 res->range.iomode,
5811 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005812 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005813
Trond Myklebust64bd5772012-06-20 22:35:05 -04005814 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005815 if (res->layoutp->len > recvd) {
5816 dprintk("NFS: server cheating in layoutget reply: "
5817 "layout len %u > recvd %u\n",
5818 res->layoutp->len, recvd);
5819 return -EINVAL;
5820 }
5821
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005822 if (layout_count > 1) {
5823 /* We only handle a length one array at the moment. Any
5824 * further entries are just ignored. Note that this means
5825 * the client may see a response that is less than the
5826 * minimum it requested.
5827 */
5828 dprintk("%s: server responded with %d layouts, dropping tail\n",
5829 __func__, layout_count);
5830 }
5831
5832 return 0;
5833out_overflow:
5834 print_overflow_msg(__func__, xdr);
5835 return -EIO;
5836}
Andy Adamson863a3c62011-03-23 13:27:54 +00005837
Benny Halevycbe82602011-05-22 19:52:37 +03005838static int decode_layoutreturn(struct xdr_stream *xdr,
5839 struct nfs4_layoutreturn_res *res)
5840{
5841 __be32 *p;
5842 int status;
5843
5844 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5845 if (status)
5846 return status;
5847 p = xdr_inline_decode(xdr, 4);
5848 if (unlikely(!p))
5849 goto out_overflow;
5850 res->lrs_present = be32_to_cpup(p);
5851 if (res->lrs_present)
5852 status = decode_stateid(xdr, &res->stateid);
5853 return status;
5854out_overflow:
5855 print_overflow_msg(__func__, xdr);
5856 return -EIO;
5857}
5858
Andy Adamson863a3c62011-03-23 13:27:54 +00005859static int decode_layoutcommit(struct xdr_stream *xdr,
5860 struct rpc_rqst *req,
5861 struct nfs4_layoutcommit_res *res)
5862{
5863 __be32 *p;
5864 __u32 sizechanged;
5865 int status;
5866
5867 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005868 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005869 if (status)
5870 return status;
5871
5872 p = xdr_inline_decode(xdr, 4);
5873 if (unlikely(!p))
5874 goto out_overflow;
5875 sizechanged = be32_to_cpup(p);
5876
5877 if (sizechanged) {
5878 /* throw away new size */
5879 p = xdr_inline_decode(xdr, 8);
5880 if (unlikely(!p))
5881 goto out_overflow;
5882 }
5883 return 0;
5884out_overflow:
5885 print_overflow_msg(__func__, xdr);
5886 return -EIO;
5887}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005888
5889static int decode_test_stateid(struct xdr_stream *xdr,
5890 struct nfs41_test_stateid_res *res)
5891{
5892 __be32 *p;
5893 int status;
5894 int num_res;
5895
5896 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5897 if (status)
5898 return status;
5899
5900 p = xdr_inline_decode(xdr, 4);
5901 if (unlikely(!p))
5902 goto out_overflow;
5903 num_res = be32_to_cpup(p++);
5904 if (num_res != 1)
5905 goto out;
5906
5907 p = xdr_inline_decode(xdr, 4);
5908 if (unlikely(!p))
5909 goto out_overflow;
5910 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005911
5912 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005913out_overflow:
5914 print_overflow_msg(__func__, xdr);
5915out:
5916 return -EIO;
5917}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005918
5919static int decode_free_stateid(struct xdr_stream *xdr,
5920 struct nfs41_free_stateid_res *res)
5921{
5922 __be32 *p;
5923 int status;
5924
5925 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5926 if (status)
5927 return status;
5928
5929 p = xdr_inline_decode(xdr, 4);
5930 if (unlikely(!p))
5931 goto out_overflow;
5932 res->status = be32_to_cpup(p++);
5933 return res->status;
5934out_overflow:
5935 print_overflow_msg(__func__, xdr);
5936 return -EIO;
5937}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005938#endif /* CONFIG_NFS_V4_1 */
5939
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940/*
Benny Halevy49c25592008-12-23 16:06:16 -05005941 * END OF "GENERIC" DECODE ROUTINES.
5942 */
5943
5944/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945 * Decode OPEN_DOWNGRADE response
5946 */
Chuck Leverbf269552010-12-14 14:59:29 +00005947static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5948 struct xdr_stream *xdr,
5949 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005950{
Andy Adamson05d564f2008-12-23 16:06:15 -05005951 struct compound_hdr hdr;
5952 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005953
Chuck Leverbf269552010-12-14 14:59:29 +00005954 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005955 if (status)
5956 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005957 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005958 if (status)
5959 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005960 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005961 if (status)
5962 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005963 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005964 if (status != 0)
5965 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005966 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005968 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969}
5970
5971/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972 * Decode ACCESS response
5973 */
Chuck Leverbf269552010-12-14 14:59:29 +00005974static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5975 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005977 struct compound_hdr hdr;
5978 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005979
Chuck Leverbf269552010-12-14 14:59:29 +00005980 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005981 if (status)
5982 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005983 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005984 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005986 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005987 if (status != 0)
5988 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04005989 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04005990 if (status != 0)
5991 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005992 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005993out:
5994 return status;
5995}
5996
5997/*
5998 * Decode LOOKUP response
5999 */
Chuck Leverbf269552010-12-14 14:59:29 +00006000static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6001 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003 struct compound_hdr hdr;
6004 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006005
Chuck Leverbf269552010-12-14 14:59:29 +00006006 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006007 if (status)
6008 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006009 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006010 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006012 status = decode_putfh(xdr);
6013 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006015 status = decode_lookup(xdr);
6016 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006017 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006018 status = decode_getfh(xdr, res->fh);
6019 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006021 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022out:
6023 return status;
6024}
6025
6026/*
6027 * Decode LOOKUP_ROOT response
6028 */
Chuck Leverbf269552010-12-14 14:59:29 +00006029static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6030 struct xdr_stream *xdr,
6031 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033 struct compound_hdr hdr;
6034 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006035
Chuck Leverbf269552010-12-14 14:59:29 +00006036 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006037 if (status)
6038 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006039 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006040 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006041 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006042 status = decode_putrootfh(xdr);
6043 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006045 status = decode_getfh(xdr, res->fh);
6046 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006047 status = decode_getfattr_label(xdr, res->fattr,
6048 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049out:
6050 return status;
6051}
6052
6053/*
6054 * Decode REMOVE response
6055 */
Chuck Leverbf269552010-12-14 14:59:29 +00006056static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6057 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006059 struct compound_hdr hdr;
6060 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006061
Chuck Leverbf269552010-12-14 14:59:29 +00006062 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006063 if (status)
6064 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006065 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006066 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006068 status = decode_putfh(xdr);
6069 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006070 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006071 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072out:
6073 return status;
6074}
6075
6076/*
6077 * Decode RENAME response
6078 */
Chuck Leverbf269552010-12-14 14:59:29 +00006079static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6080 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006082 struct compound_hdr hdr;
6083 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006084
Chuck Leverbf269552010-12-14 14:59:29 +00006085 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006086 if (status)
6087 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006089 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006091 status = decode_putfh(xdr);
6092 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006093 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006094 status = decode_savefh(xdr);
6095 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006097 status = decode_putfh(xdr);
6098 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006100 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101out:
6102 return status;
6103}
6104
6105/*
6106 * Decode LINK response
6107 */
Chuck Leverbf269552010-12-14 14:59:29 +00006108static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6109 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006111 struct compound_hdr hdr;
6112 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006113
Chuck Leverbf269552010-12-14 14:59:29 +00006114 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006115 if (status)
6116 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006117 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006118 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006119 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006120 status = decode_putfh(xdr);
6121 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006123 status = decode_savefh(xdr);
6124 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006126 status = decode_putfh(xdr);
6127 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006129 status = decode_link(xdr, &res->cinfo);
6130 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006131 goto out;
6132 /*
6133 * Note order: OP_LINK leaves the directory as the current
6134 * filehandle.
6135 */
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_restorefh(xdr);
6137 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006138 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006139 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006140out:
6141 return status;
6142}
6143
6144/*
6145 * Decode CREATE response
6146 */
Chuck Leverbf269552010-12-14 14:59:29 +00006147static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6148 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006149{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150 struct compound_hdr hdr;
6151 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006152
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006154 if (status)
6155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006157 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_putfh(xdr);
6160 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006162 status = decode_create(xdr, &res->dir_cinfo);
6163 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_getfh(xdr, res->fh);
6166 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006168 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169out:
6170 return status;
6171}
6172
6173/*
6174 * Decode SYMLINK response
6175 */
Chuck Leverbf269552010-12-14 14:59:29 +00006176static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6177 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006178{
Chuck Leverbf269552010-12-14 14:59:29 +00006179 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180}
6181
6182/*
6183 * Decode GETATTR response
6184 */
Chuck Leverbf269552010-12-14 14:59:29 +00006185static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6186 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188 struct compound_hdr hdr;
6189 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006190
Chuck Leverbf269552010-12-14 14:59:29 +00006191 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 if (status)
6193 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006194 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006195 if (status)
6196 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006197 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198 if (status)
6199 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006200 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201out:
6202 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203}
6204
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006205/*
6206 * Encode an SETACL request
6207 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006208static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6209 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006210{
Andy Adamson05d564f2008-12-23 16:06:15 -05006211 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006212 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006213 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006214
Chuck Lever9f06c712010-12-14 14:59:18 +00006215 encode_compound_hdr(xdr, req, &hdr);
6216 encode_sequence(xdr, &args->seq_args, &hdr);
6217 encode_putfh(xdr, args->fh, &hdr);
6218 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006219 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006220}
Andy Adamson05d564f2008-12-23 16:06:15 -05006221
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006222/*
6223 * Decode SETACL response
6224 */
6225static int
Chuck Leverbf269552010-12-14 14:59:29 +00006226nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006227 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006228{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006229 struct compound_hdr hdr;
6230 int status;
6231
Chuck Leverbf269552010-12-14 14:59:29 +00006232 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006233 if (status)
6234 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006235 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006236 if (status)
6237 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006239 if (status)
6240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006242out:
6243 return status;
6244}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245
6246/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006247 * Decode GETACL response
6248 */
6249static int
Chuck Leverbf269552010-12-14 14:59:29 +00006250nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006251 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006252{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006253 struct compound_hdr hdr;
6254 int status;
6255
Trond Myklebust331818f2012-02-03 18:30:53 -05006256 if (res->acl_scratch != NULL) {
6257 void *p = page_address(res->acl_scratch);
6258 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6259 }
Chuck Leverbf269552010-12-14 14:59:29 +00006260 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006261 if (status)
6262 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006263 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006264 if (status)
6265 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006266 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006267 if (status)
6268 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006269 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006270
6271out:
6272 return status;
6273}
6274
6275/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276 * Decode CLOSE response
6277 */
Chuck Leverbf269552010-12-14 14:59:29 +00006278static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6279 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280{
Andy Adamson05d564f2008-12-23 16:06:15 -05006281 struct compound_hdr hdr;
6282 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006283
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006285 if (status)
6286 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006287 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006288 if (status)
6289 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006290 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006291 if (status)
6292 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006293 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006294 if (status != 0)
6295 goto out;
6296 /*
6297 * Note: Server may do delete on close for this file
6298 * in which case the getattr call will fail with
6299 * an ESTALE error. Shouldn't be a problem,
6300 * though, since fattr->valid will remain unset.
6301 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006302 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006304 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305}
6306
6307/*
6308 * Decode OPEN response
6309 */
Chuck Leverbf269552010-12-14 14:59:29 +00006310static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6311 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312{
Andy Adamson05d564f2008-12-23 16:06:15 -05006313 struct compound_hdr hdr;
6314 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006315
Chuck Leverbf269552010-12-14 14:59:29 +00006316 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006317 if (status)
6318 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006320 if (status)
6321 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006322 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006323 if (status)
6324 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006326 if (status)
6327 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006328 status = decode_getfh(xdr, &res->fh);
6329 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006331 if (res->access_request)
6332 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006333 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006335 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006336}
6337
6338/*
6339 * Decode OPEN_CONFIRM response
6340 */
Chuck Leverbf269552010-12-14 14:59:29 +00006341static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6342 struct xdr_stream *xdr,
6343 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006344{
Andy Adamson05d564f2008-12-23 16:06:15 -05006345 struct compound_hdr hdr;
6346 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006347
Chuck Leverbf269552010-12-14 14:59:29 +00006348 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006349 if (status)
6350 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006351 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006352 if (status)
6353 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006354 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006356 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357}
6358
6359/*
6360 * Decode OPEN response
6361 */
Chuck Leverbf269552010-12-14 14:59:29 +00006362static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6363 struct xdr_stream *xdr,
6364 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006365{
Andy Adamson05d564f2008-12-23 16:06:15 -05006366 struct compound_hdr hdr;
6367 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368
Chuck Leverbf269552010-12-14 14:59:29 +00006369 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006370 if (status)
6371 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006372 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006373 if (status)
6374 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006375 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006376 if (status)
6377 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006378 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006379 if (status)
6380 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006381 if (res->access_request)
6382 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006383 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006384out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006385 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386}
6387
6388/*
6389 * Decode SETATTR response
6390 */
Chuck Leverbf269552010-12-14 14:59:29 +00006391static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6392 struct xdr_stream *xdr,
6393 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394{
Andy Adamson05d564f2008-12-23 16:06:15 -05006395 struct compound_hdr hdr;
6396 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006397
Chuck Leverbf269552010-12-14 14:59:29 +00006398 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006399 if (status)
6400 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006401 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006402 if (status)
6403 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006404 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006405 if (status)
6406 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006407 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006408 if (status)
6409 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006410 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006412 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006413}
6414
6415/*
6416 * Decode LOCK response
6417 */
Chuck Leverbf269552010-12-14 14:59:29 +00006418static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6419 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421 struct compound_hdr hdr;
6422 int status;
6423
Chuck Leverbf269552010-12-14 14:59:29 +00006424 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006425 if (status)
6426 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006427 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006428 if (status)
6429 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006430 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 if (status)
6432 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006434out:
6435 return status;
6436}
6437
6438/*
6439 * Decode LOCKT response
6440 */
Chuck Leverbf269552010-12-14 14:59:29 +00006441static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6442 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 struct compound_hdr hdr;
6445 int status;
6446
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448 if (status)
6449 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006450 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006451 if (status)
6452 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006453 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 if (status)
6455 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006456 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457out:
6458 return status;
6459}
6460
6461/*
6462 * Decode LOCKU response
6463 */
Chuck Leverbf269552010-12-14 14:59:29 +00006464static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6465 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467 struct compound_hdr hdr;
6468 int status;
6469
Chuck Leverbf269552010-12-14 14:59:29 +00006470 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 if (status)
6472 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006473 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006474 if (status)
6475 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006476 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477 if (status)
6478 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006479 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480out:
6481 return status;
6482}
6483
Chuck Leverbf269552010-12-14 14:59:29 +00006484static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6485 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006486{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006487 struct compound_hdr hdr;
6488 int status;
6489
Chuck Leverbf269552010-12-14 14:59:29 +00006490 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006491 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006493 return status;
6494}
6495
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496/*
6497 * Decode READLINK response
6498 */
Chuck Leverbf269552010-12-14 14:59:29 +00006499static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6500 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006501 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006503 struct compound_hdr hdr;
6504 int status;
6505
Chuck Leverbf269552010-12-14 14:59:29 +00006506 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507 if (status)
6508 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006509 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006510 if (status)
6511 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006512 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513 if (status)
6514 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006515 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516out:
6517 return status;
6518}
6519
6520/*
6521 * Decode READDIR response
6522 */
Chuck Leverbf269552010-12-14 14:59:29 +00006523static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6524 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526 struct compound_hdr hdr;
6527 int status;
6528
Chuck Leverbf269552010-12-14 14:59:29 +00006529 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530 if (status)
6531 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006533 if (status)
6534 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 if (status)
6537 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006538 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539out:
6540 return status;
6541}
6542
6543/*
6544 * Decode Read response
6545 */
Chuck Leverbf269552010-12-14 14:59:29 +00006546static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6547 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006549 struct compound_hdr hdr;
6550 int status;
6551
Chuck Leverbf269552010-12-14 14:59:29 +00006552 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553 if (status)
6554 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006556 if (status)
6557 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 if (status)
6560 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562 if (!status)
6563 status = res->count;
6564out:
6565 return status;
6566}
6567
6568/*
6569 * Decode WRITE response
6570 */
Chuck Leverbf269552010-12-14 14:59:29 +00006571static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6572 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574 struct compound_hdr hdr;
6575 int status;
6576
Chuck Leverbf269552010-12-14 14:59:29 +00006577 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578 if (status)
6579 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006581 if (status)
6582 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584 if (status)
6585 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006586 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006587 if (status)
6588 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006589 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006590 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006591 if (!status)
6592 status = res->count;
6593out:
6594 return status;
6595}
6596
6597/*
6598 * Decode COMMIT response
6599 */
Chuck Leverbf269552010-12-14 14:59:29 +00006600static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006601 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006602{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006603 struct compound_hdr hdr;
6604 int status;
6605
Chuck Leverbf269552010-12-14 14:59:29 +00006606 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607 if (status)
6608 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006609 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006610 if (status)
6611 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006612 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613 if (status)
6614 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006615 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616out:
6617 return status;
6618}
6619
6620/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006621 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622 */
Chuck Leverbf269552010-12-14 14:59:29 +00006623static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006624 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006626 struct compound_hdr hdr;
6627 int status;
6628
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006631 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006632 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006633 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006635 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636 return status;
6637}
6638
6639/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006640 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006641 */
Chuck Leverbf269552010-12-14 14:59:29 +00006642static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006643 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006645 struct compound_hdr hdr;
6646 int status;
6647
Chuck Leverbf269552010-12-14 14:59:29 +00006648 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006651 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006652 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006654 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655 return status;
6656}
6657
6658/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006659 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660 */
Chuck Leverbf269552010-12-14 14:59:29 +00006661static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006662 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006663{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664 struct compound_hdr hdr;
6665 int status;
6666
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006668 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006670 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006671 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006673 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674 return status;
6675}
6676
6677/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006678 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006679 */
Chuck Leverbf269552010-12-14 14:59:29 +00006680static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6681 struct xdr_stream *xdr,
6682 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006684 struct compound_hdr hdr;
6685 int status;
6686
Chuck Leverbf269552010-12-14 14:59:29 +00006687 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006688 if (status)
6689 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006690 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006691 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006692 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006693 status = decode_putfh(xdr);
6694 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006695 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006696 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006697out:
6698 return status;
6699}
6700
6701/*
6702 * Decode RENEW response
6703 */
Chuck Leverbf269552010-12-14 14:59:29 +00006704static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6705 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006706{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006707 struct compound_hdr hdr;
6708 int status;
6709
Chuck Leverbf269552010-12-14 14:59:29 +00006710 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006712 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006713 return status;
6714}
6715
6716/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006717 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006718 */
Chuck Leverbf269552010-12-14 14:59:29 +00006719static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6720 struct xdr_stream *xdr,
6721 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006722{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723 struct compound_hdr hdr;
6724 int status;
6725
Chuck Leverbf269552010-12-14 14:59:29 +00006726 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006727 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006729 return status;
6730}
6731
6732/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006733 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006734 */
Chuck Leverbf269552010-12-14 14:59:29 +00006735static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006736 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006737{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006738 struct compound_hdr hdr;
6739 int status;
6740
Chuck Leverbf269552010-12-14 14:59:29 +00006741 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006743 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744 return status;
6745}
6746
6747/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006748 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 */
Chuck Leverbf269552010-12-14 14:59:29 +00006750static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6751 struct xdr_stream *xdr,
6752 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754 struct compound_hdr hdr;
6755 int status;
6756
Chuck Leverbf269552010-12-14 14:59:29 +00006757 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006758 if (status)
6759 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006760 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006761 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006762 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006763 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006764 if (status != 0)
6765 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006766 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006767 if (status != 0)
6768 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006769 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006770out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006771 return status;
6772}
6773
Trond Myklebust683b57b2006-06-09 09:34:22 -04006774/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006775 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006776 */
Chuck Leverbf269552010-12-14 14:59:29 +00006777static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6778 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006779 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006780{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006781 struct compound_hdr hdr;
6782 int status;
6783
Chuck Leverbf269552010-12-14 14:59:29 +00006784 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006785 if (status)
6786 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006788 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006789 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006790 status = decode_putfh(xdr);
6791 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006792 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006793 status = decode_lookup(xdr);
6794 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006795 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006796 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006797 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6798 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006799 NULL, res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006800out:
6801 return status;
6802}
6803
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006804/*
6805 * Decode SECINFO response
6806 */
6807static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6808 struct xdr_stream *xdr,
6809 struct nfs4_secinfo_res *res)
6810{
6811 struct compound_hdr hdr;
6812 int status;
6813
6814 status = decode_compound_hdr(xdr, &hdr);
6815 if (status)
6816 goto out;
6817 status = decode_sequence(xdr, &res->seq_res, rqstp);
6818 if (status)
6819 goto out;
6820 status = decode_putfh(xdr);
6821 if (status)
6822 goto out;
6823 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006824out:
6825 return status;
6826}
6827
Benny Halevy99fe60d2009-04-01 09:22:29 -04006828#if defined(CONFIG_NFS_V4_1)
6829/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006830 * Decode BIND_CONN_TO_SESSION response
6831 */
6832static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6833 struct xdr_stream *xdr,
6834 void *res)
6835{
6836 struct compound_hdr hdr;
6837 int status;
6838
6839 status = decode_compound_hdr(xdr, &hdr);
6840 if (!status)
6841 status = decode_bind_conn_to_session(xdr, res);
6842 return status;
6843}
6844
6845/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006846 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006847 */
Chuck Leverbf269552010-12-14 14:59:29 +00006848static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6849 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006850 void *res)
6851{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006852 struct compound_hdr hdr;
6853 int status;
6854
Chuck Leverbf269552010-12-14 14:59:29 +00006855 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006856 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006857 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006858 return status;
6859}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006860
6861/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006862 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006863 */
Chuck Leverbf269552010-12-14 14:59:29 +00006864static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6865 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006866 struct nfs41_create_session_res *res)
6867{
Andy Adamsonfc931582009-04-01 09:22:31 -04006868 struct compound_hdr hdr;
6869 int status;
6870
Chuck Leverbf269552010-12-14 14:59:29 +00006871 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006872 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006873 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006874 return status;
6875}
6876
6877/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006878 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006879 */
Chuck Leverbf269552010-12-14 14:59:29 +00006880static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6881 struct xdr_stream *xdr,
6882 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006883{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006884 struct compound_hdr hdr;
6885 int status;
6886
Chuck Leverbf269552010-12-14 14:59:29 +00006887 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006888 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006889 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006890 return status;
6891}
6892
6893/*
Trond Myklebust66245532012-05-25 17:18:09 -04006894 * Decode DESTROY_CLIENTID response
6895 */
6896static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6897 struct xdr_stream *xdr,
6898 void *res)
6899{
6900 struct compound_hdr hdr;
6901 int status;
6902
6903 status = decode_compound_hdr(xdr, &hdr);
6904 if (!status)
6905 status = decode_destroy_clientid(xdr, res);
6906 return status;
6907}
6908
6909/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006910 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006911 */
Chuck Leverbf269552010-12-14 14:59:29 +00006912static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6913 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006914 struct nfs4_sequence_res *res)
6915{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006916 struct compound_hdr hdr;
6917 int status;
6918
Chuck Leverbf269552010-12-14 14:59:29 +00006919 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006920 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006921 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006922 return status;
6923}
6924
6925/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006926 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006927 */
Chuck Leverbf269552010-12-14 14:59:29 +00006928static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6929 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006930 struct nfs4_get_lease_time_res *res)
6931{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006932 struct compound_hdr hdr;
6933 int status;
6934
Chuck Leverbf269552010-12-14 14:59:29 +00006935 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006936 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006937 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006938 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006939 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006940 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006941 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006942 return status;
6943}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006944
6945/*
6946 * Decode RECLAIM_COMPLETE response
6947 */
Chuck Leverbf269552010-12-14 14:59:29 +00006948static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6949 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006950 struct nfs41_reclaim_complete_res *res)
6951{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006952 struct compound_hdr hdr;
6953 int status;
6954
Chuck Leverbf269552010-12-14 14:59:29 +00006955 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006956 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006957 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006958 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006959 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006960 return status;
6961}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006962
6963/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006964 * Decode GETDEVICELIST response
6965 */
6966static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6967 struct xdr_stream *xdr,
6968 struct nfs4_getdevicelist_res *res)
6969{
6970 struct compound_hdr hdr;
6971 int status;
6972
6973 dprintk("encoding getdevicelist!\n");
6974
6975 status = decode_compound_hdr(xdr, &hdr);
6976 if (status != 0)
6977 goto out;
6978 status = decode_sequence(xdr, &res->seq_res, rqstp);
6979 if (status != 0)
6980 goto out;
6981 status = decode_putfh(xdr);
6982 if (status != 0)
6983 goto out;
6984 status = decode_getdevicelist(xdr, res->devlist);
6985out:
6986 return status;
6987}
6988
6989/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006990 * Decode GETDEVINFO response
6991 */
Chuck Leverbf269552010-12-14 14:59:29 +00006992static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6993 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006994 struct nfs4_getdeviceinfo_res *res)
6995{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006996 struct compound_hdr hdr;
6997 int status;
6998
Chuck Leverbf269552010-12-14 14:59:29 +00006999 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007000 if (status != 0)
7001 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007002 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007003 if (status != 0)
7004 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007005 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007006out:
7007 return status;
7008}
7009
7010/*
7011 * Decode LAYOUTGET response
7012 */
Chuck Leverbf269552010-12-14 14:59:29 +00007013static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7014 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007015 struct nfs4_layoutget_res *res)
7016{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007017 struct compound_hdr hdr;
7018 int status;
7019
Chuck Leverbf269552010-12-14 14:59:29 +00007020 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007021 if (status)
7022 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007023 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007024 if (status)
7025 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007026 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007027 if (status)
7028 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007029 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007030out:
7031 return status;
7032}
Andy Adamson863a3c62011-03-23 13:27:54 +00007033
7034/*
Benny Halevycbe82602011-05-22 19:52:37 +03007035 * Decode LAYOUTRETURN response
7036 */
7037static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7038 struct xdr_stream *xdr,
7039 struct nfs4_layoutreturn_res *res)
7040{
7041 struct compound_hdr hdr;
7042 int status;
7043
7044 status = decode_compound_hdr(xdr, &hdr);
7045 if (status)
7046 goto out;
7047 status = decode_sequence(xdr, &res->seq_res, rqstp);
7048 if (status)
7049 goto out;
7050 status = decode_putfh(xdr);
7051 if (status)
7052 goto out;
7053 status = decode_layoutreturn(xdr, res);
7054out:
7055 return status;
7056}
7057
7058/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007059 * Decode LAYOUTCOMMIT response
7060 */
7061static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7062 struct xdr_stream *xdr,
7063 struct nfs4_layoutcommit_res *res)
7064{
7065 struct compound_hdr hdr;
7066 int status;
7067
7068 status = decode_compound_hdr(xdr, &hdr);
7069 if (status)
7070 goto out;
7071 status = decode_sequence(xdr, &res->seq_res, rqstp);
7072 if (status)
7073 goto out;
7074 status = decode_putfh(xdr);
7075 if (status)
7076 goto out;
7077 status = decode_layoutcommit(xdr, rqstp, res);
7078 if (status)
7079 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007080 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007081out:
7082 return status;
7083}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007084
7085/*
7086 * Decode SECINFO_NO_NAME response
7087 */
7088static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7089 struct xdr_stream *xdr,
7090 struct nfs4_secinfo_res *res)
7091{
7092 struct compound_hdr hdr;
7093 int status;
7094
7095 status = decode_compound_hdr(xdr, &hdr);
7096 if (status)
7097 goto out;
7098 status = decode_sequence(xdr, &res->seq_res, rqstp);
7099 if (status)
7100 goto out;
7101 status = decode_putrootfh(xdr);
7102 if (status)
7103 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007104 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007105out:
7106 return status;
7107}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007108
7109/*
7110 * Decode TEST_STATEID response
7111 */
7112static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7113 struct xdr_stream *xdr,
7114 struct nfs41_test_stateid_res *res)
7115{
7116 struct compound_hdr hdr;
7117 int status;
7118
7119 status = decode_compound_hdr(xdr, &hdr);
7120 if (status)
7121 goto out;
7122 status = decode_sequence(xdr, &res->seq_res, rqstp);
7123 if (status)
7124 goto out;
7125 status = decode_test_stateid(xdr, res);
7126out:
7127 return status;
7128}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007129
7130/*
7131 * Decode FREE_STATEID response
7132 */
7133static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7134 struct xdr_stream *xdr,
7135 struct nfs41_free_stateid_res *res)
7136{
7137 struct compound_hdr hdr;
7138 int status;
7139
7140 status = decode_compound_hdr(xdr, &hdr);
7141 if (status)
7142 goto out;
7143 status = decode_sequence(xdr, &res->seq_res, rqstp);
7144 if (status)
7145 goto out;
7146 status = decode_free_stateid(xdr, res);
7147out:
7148 return status;
7149}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007150#endif /* CONFIG_NFS_V4_1 */
7151
Chuck Lever573c4e12010-12-14 14:58:11 +00007152/**
7153 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7154 * the local page cache.
7155 * @xdr: XDR stream where entry resides
7156 * @entry: buffer to fill in with entry data
7157 * @plus: boolean indicating whether this should be a readdirplus entry
7158 *
7159 * Returns zero if successful, otherwise a negative errno value is
7160 * returned.
7161 *
7162 * This function is not invoked during READDIR reply decoding, but
7163 * rather whenever an application invokes the getdents(2) system call
7164 * on a directory already in our cache.
7165 */
7166int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7167 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007168{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007169 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007170 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007171 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007172 __be32 *p = xdr_inline_decode(xdr, 4);
7173 if (unlikely(!p))
7174 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007175 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007176 p = xdr_inline_decode(xdr, 4);
7177 if (unlikely(!p))
7178 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007179 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007180 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007181 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007182 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007183 }
7184
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007185 p = xdr_inline_decode(xdr, 12);
7186 if (unlikely(!p))
7187 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007188 entry->prev_cookie = entry->cookie;
7189 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007190 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007191
Trond Myklebust9af8c222010-10-24 11:52:55 -04007192 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007193 if (unlikely(!p))
7194 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007195 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007196
7197 /*
7198 * In case the server doesn't return an inode number,
7199 * we fake one here. (We don't use inode number 0,
7200 * since glibc seems to choke on it...)
7201 */
7202 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007203 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007204
Trond Myklebust9af8c222010-10-24 11:52:55 -04007205 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007206 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007207
Trond Myklebust256e48b2012-06-21 11:18:13 -04007208 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007209 goto out_overflow;
7210
Chuck Lever573c4e12010-12-14 14:58:11 +00007211 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007212 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007213 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007214 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7215 entry->ino = entry->fattr->mounted_on_fileid;
7216 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007217 entry->ino = entry->fattr->fileid;
7218
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007219 entry->d_type = DT_UNKNOWN;
7220 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7221 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7222
Chuck Lever573c4e12010-12-14 14:58:11 +00007223 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007224
7225out_overflow:
7226 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007227 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007228}
7229
7230/*
7231 * We need to translate between nfs status return values and
7232 * the local errno values which may not be the same.
7233 */
7234static struct {
7235 int stat;
7236 int errno;
7237} nfs_errtbl[] = {
7238 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007239 { NFS4ERR_PERM, -EPERM },
7240 { NFS4ERR_NOENT, -ENOENT },
7241 { NFS4ERR_IO, -errno_NFSERR_IO},
7242 { NFS4ERR_NXIO, -ENXIO },
7243 { NFS4ERR_ACCESS, -EACCES },
7244 { NFS4ERR_EXIST, -EEXIST },
7245 { NFS4ERR_XDEV, -EXDEV },
7246 { NFS4ERR_NOTDIR, -ENOTDIR },
7247 { NFS4ERR_ISDIR, -EISDIR },
7248 { NFS4ERR_INVAL, -EINVAL },
7249 { NFS4ERR_FBIG, -EFBIG },
7250 { NFS4ERR_NOSPC, -ENOSPC },
7251 { NFS4ERR_ROFS, -EROFS },
7252 { NFS4ERR_MLINK, -EMLINK },
7253 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7254 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7255 { NFS4ERR_DQUOT, -EDQUOT },
7256 { NFS4ERR_STALE, -ESTALE },
7257 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007258 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7259 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7260 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007261 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007262 { NFS4ERR_BADTYPE, -EBADTYPE },
7263 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007264 { NFS4ERR_SYMLINK, -ELOOP },
7265 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7266 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007267 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007268};
7269
7270/*
7271 * Convert an NFS error code to a local one.
7272 * This one is used jointly by NFSv2 and NFSv3.
7273 */
7274static int
David Howells0a8ea432006-08-22 20:06:08 -04007275nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007276{
7277 int i;
7278 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7279 if (nfs_errtbl[i].stat == stat)
7280 return nfs_errtbl[i].errno;
7281 }
7282 if (stat <= 10000 || stat > 10100) {
7283 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007284 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007285 }
7286 /* If we cannot translate the error, the recovery routines should
7287 * handle it.
7288 * Note: remaining NFSv4 error codes have values > 10000, so should
7289 * not conflict with native Linux error codes.
7290 */
Benny Halevy856dff32008-03-31 17:39:06 +03007291 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007292}
7293
Linus Torvalds1da177e2005-04-16 15:20:36 -07007294#define PROC(proc, argtype, restype) \
7295[NFSPROC4_CLNT_##proc] = { \
7296 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007297 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007298 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007299 .p_arglen = NFS4_##argtype##_sz, \
7300 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007301 .p_statidx = NFSPROC4_CLNT_##proc, \
7302 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007303}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007304
7305struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007306 PROC(READ, enc_read, dec_read),
7307 PROC(WRITE, enc_write, dec_write),
7308 PROC(COMMIT, enc_commit, dec_commit),
7309 PROC(OPEN, enc_open, dec_open),
7310 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7311 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7312 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7313 PROC(CLOSE, enc_close, dec_close),
7314 PROC(SETATTR, enc_setattr, dec_setattr),
7315 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7316 PROC(RENEW, enc_renew, dec_renew),
7317 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7318 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7319 PROC(LOCK, enc_lock, dec_lock),
7320 PROC(LOCKT, enc_lockt, dec_lockt),
7321 PROC(LOCKU, enc_locku, dec_locku),
7322 PROC(ACCESS, enc_access, dec_access),
7323 PROC(GETATTR, enc_getattr, dec_getattr),
7324 PROC(LOOKUP, enc_lookup, dec_lookup),
7325 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7326 PROC(REMOVE, enc_remove, dec_remove),
7327 PROC(RENAME, enc_rename, dec_rename),
7328 PROC(LINK, enc_link, dec_link),
7329 PROC(SYMLINK, enc_symlink, dec_symlink),
7330 PROC(CREATE, enc_create, dec_create),
7331 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7332 PROC(STATFS, enc_statfs, dec_statfs),
7333 PROC(READLINK, enc_readlink, dec_readlink),
7334 PROC(READDIR, enc_readdir, dec_readdir),
7335 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7336 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7337 PROC(GETACL, enc_getacl, dec_getacl),
7338 PROC(SETACL, enc_setacl, dec_setacl),
7339 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7340 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007341 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007342#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007343 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7344 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7345 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7346 PROC(SEQUENCE, enc_sequence, dec_sequence),
7347 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7348 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7349 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7350 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007351 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007352 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007353 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007354 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007355 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007356 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007357 PROC(BIND_CONN_TO_SESSION,
7358 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007359 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007360#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007361};
7362
Trond Myklebusta613fa12012-01-20 13:53:56 -05007363const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007364 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007365 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007366 .procs = nfs4_procedures
7367};
7368
7369/*
7370 * Local variables:
7371 * c-basic-offset: 8
7372 * End:
7373 */