blob: 3850b018815f2d07e4740fdd3ff8200523b9fe92 [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 Labiaga18019752009-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 Labiaga18019752009-12-05 16:08:40 -0500791#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_reclaim_complete_maxsz)
794#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
795 decode_sequence_maxsz + \
796 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400797#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_putfh_maxsz + \
800 encode_getdevicelist_maxsz)
801#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_putfh_maxsz + \
804 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400805#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz +\
807 encode_getdeviceinfo_maxsz)
808#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
809 decode_sequence_maxsz + \
810 decode_getdeviceinfo_maxsz)
811#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
812 encode_sequence_maxsz + \
813 encode_putfh_maxsz + \
814 encode_layoutget_maxsz)
815#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
816 decode_sequence_maxsz + \
817 decode_putfh_maxsz + \
818 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000819#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz +\
821 encode_putfh_maxsz + \
822 encode_layoutcommit_maxsz + \
823 encode_getattr_maxsz)
824#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
825 decode_sequence_maxsz + \
826 decode_putfh_maxsz + \
827 decode_layoutcommit_maxsz + \
828 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300829#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
830 encode_sequence_maxsz + \
831 encode_putfh_maxsz + \
832 encode_layoutreturn_maxsz)
833#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
834 decode_sequence_maxsz + \
835 decode_putfh_maxsz + \
836 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400837#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
838 encode_sequence_maxsz + \
839 encode_putrootfh_maxsz +\
840 encode_secinfo_no_name_maxsz)
841#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
842 decode_sequence_maxsz + \
843 decode_putrootfh_maxsz + \
844 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400845#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
846 encode_sequence_maxsz + \
847 encode_test_stateid_maxsz)
848#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
849 decode_sequence_maxsz + \
850 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400851#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
852 encode_sequence_maxsz + \
853 encode_free_stateid_maxsz)
854#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
855 decode_sequence_maxsz + \
856 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500857
858const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
859 compound_encode_hdr_maxsz +
860 encode_sequence_maxsz +
861 encode_putfh_maxsz +
862 encode_getattr_maxsz) *
863 XDR_UNIT);
864
865const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
866 compound_decode_hdr_maxsz +
867 decode_sequence_maxsz +
868 decode_putfh_maxsz) *
869 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400870
871const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
872 compound_decode_hdr_maxsz +
873 decode_sequence_maxsz) *
874 XDR_UNIT);
875EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400876#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Trond Myklebustbca794782009-03-11 14:10:26 -0400878static const umode_t nfs_type2fmt[] = {
879 [NF4BAD] = 0,
880 [NF4REG] = S_IFREG,
881 [NF4DIR] = S_IFDIR,
882 [NF4BLK] = S_IFBLK,
883 [NF4CHR] = S_IFCHR,
884 [NF4LNK] = S_IFLNK,
885 [NF4SOCK] = S_IFSOCK,
886 [NF4FIFO] = S_IFIFO,
887 [NF4ATTRDIR] = 0,
888 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889};
890
891struct compound_hdr {
892 int32_t status;
893 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500894 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 uint32_t taglen;
896 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400897 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400898 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899};
900
Benny Halevy13c65ce2009-08-14 17:19:25 +0300901static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
902{
903 __be32 *p = xdr_reserve_space(xdr, nbytes);
904 BUG_ON(!p);
905 return p;
906}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Trond Myklebustcb17e552012-03-04 18:13:56 -0500908static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
909{
910 __be32 *p;
911
912 p = xdr_reserve_space(xdr, len);
913 xdr_encode_opaque_fixed(p, buf, len);
914}
915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
917{
Al Viro8687b632006-10-19 23:28:48 -0700918 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500920 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 xdr_encode_opaque(p, str, len);
922}
923
Trond Myklebust4ade9822012-03-04 18:13:57 -0500924static void encode_uint32(struct xdr_stream *xdr, u32 n)
925{
926 __be32 *p;
927
928 p = reserve_space(xdr, 4);
929 *p = cpu_to_be32(n);
930}
931
Trond Myklebustff2eb682012-03-05 11:40:12 -0500932static void encode_uint64(struct xdr_stream *xdr, u64 n)
933{
934 __be32 *p;
935
936 p = reserve_space(xdr, 8);
937 xdr_encode_hyper(p, n);
938}
939
Trond Myklebust4ade9822012-03-04 18:13:57 -0500940static void encode_nfs4_seqid(struct xdr_stream *xdr,
941 const struct nfs_seqid *seqid)
942{
943 encode_uint32(xdr, seqid->sequence->counter);
944}
945
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400946static void encode_compound_hdr(struct xdr_stream *xdr,
947 struct rpc_rqst *req,
948 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949{
Al Viro8687b632006-10-19 23:28:48 -0700950 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400951 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400952
953 /* initialize running count of expected bytes in reply.
954 * NOTE: the replied tag SHOULD be the same is the one sent,
955 * but this is not required as a MUST for the server to do so. */
956 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Trond Myklebust7fc38842012-10-15 11:51:21 -0400958 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500959 encode_string(xdr, hdr->taglen, hdr->tag);
960 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300961 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500962 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300963 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500964}
965
Trond Myklebustab19b482012-03-04 18:13:57 -0500966static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
967 uint32_t replen,
968 struct compound_hdr *hdr)
969{
970 encode_uint32(xdr, op);
971 hdr->nops++;
972 hdr->replen += replen;
973}
974
Andy Adamsond0179312008-12-23 16:06:17 -0500975static void encode_nops(struct compound_hdr *hdr)
976{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400977 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500978 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979}
980
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500981static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
982{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500983 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500984}
985
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
987{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500988 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
David Quigleyaa9c2662013-05-22 12:50:44 -0400991static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
992 const struct nfs4_label *label,
993 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
995 char owner_name[IDMAP_NAMESZ];
996 char owner_group[IDMAP_NAMESZ];
997 int owner_namelen = 0;
998 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700999 __be32 *p;
1000 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 int len;
Trond Myklebustb4a2cf72013-07-17 16:43:16 -04001002 uint32_t bmval_len = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 uint32_t bmval0 = 0;
1004 uint32_t bmval1 = 0;
David Quigleya09df2c2013-05-22 12:50:41 -04001005 uint32_t bmval2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 /*
1008 * We reserve enough space to write the entire attribute buffer at once.
1009 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001010 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1011 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001012 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 */
Trond Myklebustb4a2cf72013-07-17 16:43:16 -04001014 len = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 /* Sigh */
1017 if (iap->ia_valid & ATTR_SIZE)
1018 len += 8;
1019 if (iap->ia_valid & ATTR_MODE)
1020 len += 4;
1021 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001022 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001024 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001025 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 /* XXX */
1027 strcpy(owner_name, "nobody");
1028 owner_namelen = sizeof("nobody") - 1;
1029 /* goto out; */
1030 }
1031 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1032 }
1033 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001034 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001036 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001037 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 strcpy(owner_group, "nobody");
1039 owner_grouplen = sizeof("nobody") - 1;
1040 /* goto out; */
1041 }
1042 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1043 }
1044 if (iap->ia_valid & ATTR_ATIME_SET)
1045 len += 16;
1046 else if (iap->ia_valid & ATTR_ATIME)
1047 len += 4;
1048 if (iap->ia_valid & ATTR_MTIME_SET)
1049 len += 16;
1050 else if (iap->ia_valid & ATTR_MTIME)
1051 len += 4;
Trond Myklebustb4a2cf72013-07-17 16:43:16 -04001052 if (label) {
1053 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1054 bmval_len = 3;
1055 }
1056
1057 len += bmval_len << 2;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001058 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
1060 /*
1061 * We write the bitmap length now, but leave the bitmap and the attribute
1062 * buffer length to be backfilled at the end of this routine.
1063 */
Trond Myklebustb4a2cf72013-07-17 16:43:16 -04001064 *p++ = cpu_to_be32(bmval_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 q = p;
Trond Myklebustb4a2cf72013-07-17 16:43:16 -04001066 /* Skip bitmap entries + attrlen */
1067 p += bmval_len + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
1069 if (iap->ia_valid & ATTR_SIZE) {
1070 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001071 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 }
1073 if (iap->ia_valid & ATTR_MODE) {
1074 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001075 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 }
1077 if (iap->ia_valid & ATTR_UID) {
1078 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001079 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 }
1081 if (iap->ia_valid & ATTR_GID) {
1082 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001083 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 }
1085 if (iap->ia_valid & ATTR_ATIME_SET) {
1086 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001087 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Bryan Schumaker042ad0b2013-04-19 16:09:37 -04001088 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001089 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
1091 else if (iap->ia_valid & ATTR_ATIME) {
1092 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001093 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 }
1095 if (iap->ia_valid & ATTR_MTIME_SET) {
1096 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001097 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Bryan Schumaker042ad0b2013-04-19 16:09:37 -04001098 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001099 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 }
1101 else if (iap->ia_valid & ATTR_MTIME) {
1102 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001103 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001105 if (label) {
1106 bmval2 |= FATTR4_WORD2_SECURITY_LABEL;
1107 *p++ = cpu_to_be32(label->lfs);
1108 *p++ = cpu_to_be32(label->pi);
1109 *p++ = cpu_to_be32(label->len);
1110 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1111 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001112
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 /*
1114 * Now we backfill the bitmap and the attribute buffer length.
1115 */
1116 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001117 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 len, ((char *)p - (char *)q) + 4);
1119 BUG();
1120 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 *q++ = htonl(bmval0);
1122 *q++ = htonl(bmval1);
Trond Myklebustb4a2cf72013-07-17 16:43:16 -04001123 if (bmval_len == 3)
1124 *q++ = htonl(bmval2);
Trond Myklebust4f3cc482013-07-23 12:53:39 -04001125 len = (char *)p - (char *)(q + 1);
Benny Halevy34558512009-08-14 17:19:30 +03001126 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129}
1130
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001131static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001133 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1134 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135}
1136
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001137static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138{
Trond Myklebustab19b482012-03-04 18:13:57 -05001139 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001140 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001141 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
Fred Isaman0b7c0152012-04-20 14:47:39 -04001144static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Al Viro8687b632006-10-19 23:28:48 -07001146 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001147
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001148 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1149 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001150 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001151 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001154static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155{
Al Viro8687b632006-10-19 23:28:48 -07001156 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001157
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001158 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1159 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
1161 switch (create->ftype) {
1162 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001163 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001164 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001165 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 break;
1167
1168 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001169 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001170 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001171 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 break;
1173
1174 default:
1175 break;
1176 }
1177
Benny Halevy811652b2009-08-14 17:19:34 +03001178 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001179 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001182static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
Andy Adamson05d564f2008-12-23 16:06:15 -05001184 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001186 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1187 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001188 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001189 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190}
1191
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001192static 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 -07001193{
Andy Adamson05d564f2008-12-23 16:06:15 -05001194 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001196 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1197 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001198 *p++ = cpu_to_be32(2);
1199 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001200 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
Fred Isamandae100c2011-07-30 20:52:37 -04001203static void
1204encode_getattr_three(struct xdr_stream *xdr,
1205 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1206 struct compound_hdr *hdr)
1207{
1208 __be32 *p;
1209
Trond Myklebustab19b482012-03-04 18:13:57 -05001210 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001211 if (bm2) {
1212 p = reserve_space(xdr, 16);
1213 *p++ = cpu_to_be32(3);
1214 *p++ = cpu_to_be32(bm0);
1215 *p++ = cpu_to_be32(bm1);
1216 *p = cpu_to_be32(bm2);
1217 } else if (bm1) {
1218 p = reserve_space(xdr, 12);
1219 *p++ = cpu_to_be32(2);
1220 *p++ = cpu_to_be32(bm0);
1221 *p = cpu_to_be32(bm1);
1222 } else {
1223 p = reserve_space(xdr, 8);
1224 *p++ = cpu_to_be32(1);
1225 *p = cpu_to_be32(bm0);
1226 }
Fred Isamandae100c2011-07-30 20:52:37 -04001227}
1228
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001229static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
David Quigleya09df2c2013-05-22 12:50:41 -04001231 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1232 bitmask[1] & nfs4_fattr_bitmap[1],
1233 bitmask[2] & nfs4_fattr_bitmap[2],
1234 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235}
1236
Andy Adamson88034c32012-05-23 05:02:34 -04001237static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001238 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001239 struct compound_hdr *hdr)
1240{
1241 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001242 bitmask[0] & open_bitmap[0],
1243 bitmask[1] & open_bitmap[1],
1244 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001245 hdr);
1246}
1247
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001248static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Fred Isamandae100c2011-07-30 20:52:37 -04001250 encode_getattr_three(xdr,
1251 bitmask[0] & nfs4_fsinfo_bitmap[0],
1252 bitmask[1] & nfs4_fsinfo_bitmap[1],
1253 bitmask[2] & nfs4_fsinfo_bitmap[2],
1254 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255}
1256
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001257static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001258{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001259 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1260 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001261}
1262
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001263static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264{
Trond Myklebustab19b482012-03-04 18:13:57 -05001265 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266}
1267
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001268static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269{
Trond Myklebustab19b482012-03-04 18:13:57 -05001270 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001271 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272}
1273
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001274static inline int nfs4_lock_type(struct file_lock *fl, int block)
1275{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001276 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001277 return block ? NFS4_READW_LT : NFS4_READ_LT;
1278 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1279}
1280
1281static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1282{
1283 if (fl->fl_end == OFFSET_MAX)
1284 return ~(uint64_t)0;
1285 return fl->fl_end - fl->fl_start + 1;
1286}
1287
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001288static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1289{
1290 __be32 *p;
1291
Trond Myklebustd035c362010-12-21 10:45:27 -05001292 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001293 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001294 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001295 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001296 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001297 xdr_encode_hyper(p, lowner->id);
1298}
1299
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300/*
1301 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1302 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1303 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001304static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305{
Al Viro8687b632006-10-19 23:28:48 -07001306 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001308 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1309 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001310 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1311 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001312 p = xdr_encode_hyper(p, args->fl->fl_start);
1313 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001314 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001315 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001316 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001317 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001318 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001319 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 }
1321 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001322 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001323 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001327static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
Al Viro8687b632006-10-19 23:28:48 -07001329 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001331 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1332 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001333 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001334 p = xdr_encode_hyper(p, args->fl->fl_start);
1335 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001336 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001339static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
Al Viro8687b632006-10-19 23:28:48 -07001341 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001343 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1344 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001345 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001346 encode_nfs4_stateid(xdr, args->stateid);
1347 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001348 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001349 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350}
1351
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001352static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1353{
Trond Myklebustab19b482012-03-04 18:13:57 -05001354 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001355 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001356}
1357
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001358static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359{
Trond Myklebustab19b482012-03-04 18:13:57 -05001360 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001361 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362}
1363
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001364static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365{
Al Viro8687b632006-10-19 23:28:48 -07001366 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Benny Halevy13c65ce2009-08-14 17:19:25 +03001368 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001369 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001370 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001371 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001372 break;
1373 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001374 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001375 break;
1376 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001377 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001378 break;
1379 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001380 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 }
Benny Halevy34558512009-08-14 17:19:30 +03001382 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383}
1384
1385static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1386{
Al Viro8687b632006-10-19 23:28:48 -07001387 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 /*
1389 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1390 * owner 4 = 32
1391 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001392 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001393 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001394 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001395 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001396 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001397 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001398 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001399 *p++ = cpu_to_be32(arg->id.uniquifier);
1400 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401}
1402
1403static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1404{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001405 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001406 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Benny Halevy13c65ce2009-08-14 17:19:25 +03001408 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001409 switch(arg->createmode) {
1410 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001411 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001412 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001413 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001414 case NFS4_CREATE_GUARDED:
1415 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001416 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001417 break;
1418 case NFS4_CREATE_EXCLUSIVE:
1419 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1420 encode_nfs4_verifier(xdr, &arg->u.verifier);
1421 break;
1422 case NFS4_CREATE_EXCLUSIVE4_1:
1423 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1424 encode_nfs4_verifier(xdr, &arg->u.verifier);
1425 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001426 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
1428}
1429
1430static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1431{
Al Viro8687b632006-10-19 23:28:48 -07001432 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Benny Halevy13c65ce2009-08-14 17:19:25 +03001434 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001436 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001437 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 break;
1439 default:
Benny Halevy34558512009-08-14 17:19:30 +03001440 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001441 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 }
1443}
1444
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001445static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446{
Al Viro8687b632006-10-19 23:28:48 -07001447 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Benny Halevy13c65ce2009-08-14 17:19:25 +03001449 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001451 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001452 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001453 break;
1454 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001455 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001456 break;
1457 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001458 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001459 break;
1460 default:
1461 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 }
1463}
1464
1465static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1466{
Al Viro8687b632006-10-19 23:28:48 -07001467 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Benny Halevy13c65ce2009-08-14 17:19:25 +03001469 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001470 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 encode_string(xdr, name->len, name->name);
1472}
1473
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001474static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475{
Al Viro8687b632006-10-19 23:28:48 -07001476 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Benny Halevy13c65ce2009-08-14 17:19:25 +03001478 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001479 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 encode_delegation_type(xdr, type);
1481}
1482
1483static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1484{
Al Viro8687b632006-10-19 23:28:48 -07001485 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001487 p = reserve_space(xdr, 4);
1488 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1489 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 encode_string(xdr, name->len, name->name);
1491}
1492
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001493static inline void encode_claim_fh(struct xdr_stream *xdr)
1494{
1495 __be32 *p;
1496
1497 p = reserve_space(xdr, 4);
1498 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1499}
1500
1501static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1502{
1503 __be32 *p;
1504
1505 p = reserve_space(xdr, 4);
1506 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1507 encode_nfs4_stateid(xdr, stateid);
1508}
1509
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001510static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511{
Trond Myklebustab19b482012-03-04 18:13:57 -05001512 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 encode_openhdr(xdr, arg);
1514 encode_opentype(xdr, arg);
1515 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001516 case NFS4_OPEN_CLAIM_NULL:
1517 encode_claim_null(xdr, arg->name);
1518 break;
1519 case NFS4_OPEN_CLAIM_PREVIOUS:
1520 encode_claim_previous(xdr, arg->u.delegation_type);
1521 break;
1522 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1523 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1524 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001525 case NFS4_OPEN_CLAIM_FH:
1526 encode_claim_fh(xdr);
1527 break;
1528 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1529 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1530 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001531 default:
1532 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534}
1535
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001536static 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 -07001537{
Trond Myklebustab19b482012-03-04 18:13:57 -05001538 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001539 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001540 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
1542
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001543static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
Trond Myklebustab19b482012-03-04 18:13:57 -05001545 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001546 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001547 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001548 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549}
1550
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001551static void
Andy Adamsond0179312008-12-23 16:06:17 -05001552encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553{
Trond Myklebustab19b482012-03-04 18:13:57 -05001554 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001555 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556}
1557
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001558static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559{
Trond Myklebustab19b482012-03-04 18:13:57 -05001560 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
1562
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001563static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564{
Al Viro8687b632006-10-19 23:28:48 -07001565 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Trond Myklebustab19b482012-03-04 18:13:57 -05001567 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001568 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
Benny Halevy13c65ce2009-08-14 17:19:25 +03001570 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001571 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001572 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573}
1574
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001575static 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 -07001576{
David Quigleyaa9c2662013-05-22 12:50:44 -04001577 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001578 FATTR4_WORD0_RDATTR_ERROR,
1579 FATTR4_WORD1_MOUNTED_ON_FILEID,
1580 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001581 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001582 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001584 if (readdir->plus) {
1585 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001586 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001587 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1588 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1589 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1590 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001591 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001592 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001593 /* Use mounted_on_fileid only if the server supports it */
1594 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1595 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001596
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001597 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001598 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001599 encode_nfs4_verifier(xdr, &readdir->verifier);
David Quigleyaa9c2662013-05-22 12:50:44 -04001600 p = reserve_space(xdr, encode_readdir_space);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001601 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001602 *p++ = cpu_to_be32(readdir->count);
David Quigleyaa9c2662013-05-22 12:50:44 -04001603 *p++ = cpu_to_be32(encode_readdir_bitmask_sz);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001604 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
David Quigleyaa9c2662013-05-22 12:50:44 -04001605 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1606 if (encode_readdir_bitmask_sz > 2) {
1607 if (hdr->minorversion > 1)
1608 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1609 p++, *p++ = cpu_to_be32(attrs[2] & readdir->bitmask[2]);
1610 }
Chuck Levercd937102012-03-02 17:14:31 -05001611 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001612
1613 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001614 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001615 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001616 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001617 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001618 attrs[1] & readdir->bitmask[1],
1619 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
1621
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001622static 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 -07001623{
Trond Myklebustab19b482012-03-04 18:13:57 -05001624 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625}
1626
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001627static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Trond Myklebustab19b482012-03-04 18:13:57 -05001629 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001630 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001633static 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 -07001634{
Trond Myklebustab19b482012-03-04 18:13:57 -05001635 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001636 encode_string(xdr, oldname->len, oldname->name);
1637 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638}
1639
Chuck Leverbb4dae52012-03-01 17:01:48 -05001640static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1641 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001643 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001644 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
1646
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001647static void
Andy Adamsond0179312008-12-23 16:06:17 -05001648encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001649{
Trond Myklebustab19b482012-03-04 18:13:57 -05001650 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001651}
1652
Chuck Lever9f06c712010-12-14 14:59:18 +00001653static void
Andy Adamsond0179312008-12-23 16:06:17 -05001654encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001655{
Al Viro8687b632006-10-19 23:28:48 -07001656 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001657
Trond Myklebustab19b482012-03-04 18:13:57 -05001658 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001659 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001660 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001661 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001662 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001663 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001664 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001665 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001666}
1667
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001668static void
Andy Adamsond0179312008-12-23 16:06:17 -05001669encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670{
Trond Myklebustab19b482012-03-04 18:13:57 -05001671 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672}
1673
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001674static 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 -07001675{
Trond Myklebustab19b482012-03-04 18:13:57 -05001676 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001677 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001678 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679}
1680
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001681static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
Al Viro8687b632006-10-19 23:28:48 -07001683 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Trond Myklebust70019512012-03-04 20:49:32 -05001685 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001686 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
1688 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001689 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001690 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1692 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001693 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001694 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695}
1696
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001697static 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 -07001698{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001699 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1700 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001701 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001702 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001705static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706{
Al Viro8687b632006-10-19 23:28:48 -07001707 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Trond Myklebustab19b482012-03-04 18:13:57 -05001709 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001710 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
Benny Halevy13c65ce2009-08-14 17:19:25 +03001712 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001713 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001714 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001715 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
1717 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718}
1719
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001720static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
Trond Myklebustab19b482012-03-04 18:13:57 -05001722 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001723 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001725
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001726static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1727{
Trond Myklebustab19b482012-03-04 18:13:57 -05001728 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001729 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001730}
1731
Benny Halevy99fe60d2009-04-01 09:22:29 -04001732#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001733/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001734static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1735 struct nfs4_session *session,
1736 struct compound_hdr *hdr)
1737{
1738 __be32 *p;
1739
1740 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1741 decode_bind_conn_to_session_maxsz, hdr);
1742 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1743 p = xdr_reserve_space(xdr, 8);
1744 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1745 *p = 0; /* use_conn_in_rdma_mode = False */
1746}
1747
Benny Halevy99fe60d2009-04-01 09:22:29 -04001748static void encode_exchange_id(struct xdr_stream *xdr,
1749 struct nfs41_exchange_id_args *args,
1750 struct compound_hdr *hdr)
1751{
1752 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001753 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001754 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001755
Trond Myklebust70019512012-03-04 20:49:32 -05001756 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001757 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001758
1759 encode_string(xdr, args->id_len, args->id);
1760
Benny Halevy13c65ce2009-08-14 17:19:25 +03001761 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001762 *p++ = cpu_to_be32(args->flags);
1763 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001764
1765 if (send_implementation_id &&
1766 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1767 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001768 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001769 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1770 utsname()->sysname, utsname()->release,
1771 utsname()->version, utsname()->machine);
1772
1773 if (len > 0) {
1774 *p = cpu_to_be32(1); /* implementation id array length=1 */
1775
1776 encode_string(xdr,
1777 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1778 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1779 encode_string(xdr, len, impl_name);
1780 /* just send zeros for nii_date - the date is in nii_name */
1781 p = reserve_space(xdr, 12);
1782 p = xdr_encode_hyper(p, 0);
1783 *p = cpu_to_be32(0);
1784 } else
1785 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001786}
Andy Adamsonfc931582009-04-01 09:22:31 -04001787
1788static void encode_create_session(struct xdr_stream *xdr,
1789 struct nfs41_create_session_args *args,
1790 struct compound_hdr *hdr)
1791{
1792 __be32 *p;
1793 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1794 uint32_t len;
1795 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001796 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001797 u32 max_resp_sz_cached;
1798
1799 /*
1800 * Assumes OPEN is the biggest non-idempotent compound.
1801 * 2 is the verifier.
1802 */
1803 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1804 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001805
Andy Adamsonfc931582009-04-01 09:22:31 -04001806 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1807 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001808
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001809 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1810 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001811 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001812 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1813 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001814
Andy Adamsonfc931582009-04-01 09:22:31 -04001815 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001816 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001817 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1818 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001819 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001820 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1821 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1822 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001823
1824 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001825 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001826 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1827 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1828 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1829 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1830 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1831 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001832
Benny Halevye75bc1c2009-08-14 17:18:54 +03001833 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001834 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001835 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001836
1837 /* authsys_parms rfc1831 */
Chuck Leverf0920752012-05-21 22:45:41 -04001838 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001839 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001840 *p++ = cpu_to_be32(0); /* UID */
1841 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001842 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001843}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001844
1845static void encode_destroy_session(struct xdr_stream *xdr,
1846 struct nfs4_session *session,
1847 struct compound_hdr *hdr)
1848{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001849 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1850 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001851}
Ricardo Labiaga18019752009-12-05 16:08:40 -05001852
Trond Myklebust66245532012-05-25 17:18:09 -04001853static void encode_destroy_clientid(struct xdr_stream *xdr,
1854 uint64_t clientid,
1855 struct compound_hdr *hdr)
1856{
1857 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1858 encode_uint64(xdr, clientid);
1859}
1860
Ricardo Labiaga18019752009-12-05 16:08:40 -05001861static void encode_reclaim_complete(struct xdr_stream *xdr,
1862 struct nfs41_reclaim_complete_args *args,
1863 struct compound_hdr *hdr)
1864{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001865 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1866 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga18019752009-12-05 16:08:40 -05001867}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001868#endif /* CONFIG_NFS_V4_1 */
1869
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001870static void encode_sequence(struct xdr_stream *xdr,
1871 const struct nfs4_sequence_args *args,
1872 struct compound_hdr *hdr)
1873{
1874#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001875 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001876 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001877 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001878 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001879
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001880 if (slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001881 return;
1882
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001883 tp = slot->table;
1884 session = tp->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001885
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001886 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001887
1888 /*
1889 * Sessionid + seqid + slotid + max slotid + cache_this
1890 */
1891 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1892 "max_slotid=%d cache_this=%d\n",
1893 __func__,
1894 ((u32 *)session->sess_id.data)[0],
1895 ((u32 *)session->sess_id.data)[1],
1896 ((u32 *)session->sess_id.data)[2],
1897 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001898 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001899 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001900 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001901 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001902 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001903 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001904 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001905 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001906#endif /* CONFIG_NFS_V4_1 */
1907}
1908
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001909#ifdef CONFIG_NFS_V4_1
1910static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001911encode_getdevicelist(struct xdr_stream *xdr,
1912 const struct nfs4_getdevicelist_args *args,
1913 struct compound_hdr *hdr)
1914{
1915 __be32 *p;
1916 nfs4_verifier dummy = {
1917 .data = "dummmmmy",
1918 };
1919
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001920 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1921 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001922 *p++ = cpu_to_be32(args->layoutclass);
1923 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1924 xdr_encode_hyper(p, 0ULL); /* cookie */
1925 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001926}
1927
1928static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001929encode_getdeviceinfo(struct xdr_stream *xdr,
1930 const struct nfs4_getdeviceinfo_args *args,
1931 struct compound_hdr *hdr)
1932{
1933 __be32 *p;
1934
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001935 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1936 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001937 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1938 NFS4_DEVICEID4_SIZE);
1939 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001940 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001941 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001942}
1943
1944static void
1945encode_layoutget(struct xdr_stream *xdr,
1946 const struct nfs4_layoutget_args *args,
1947 struct compound_hdr *hdr)
1948{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001949 __be32 *p;
1950
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001951 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1952 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001953 *p++ = cpu_to_be32(0); /* Signal layout available */
1954 *p++ = cpu_to_be32(args->type);
1955 *p++ = cpu_to_be32(args->range.iomode);
1956 p = xdr_encode_hyper(p, args->range.offset);
1957 p = xdr_encode_hyper(p, args->range.length);
1958 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001959 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001960 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001961
1962 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1963 __func__,
1964 args->type,
1965 args->range.iomode,
1966 (unsigned long)args->range.offset,
1967 (unsigned long)args->range.length,
1968 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001969}
Andy Adamson863a3c62011-03-23 13:27:54 +00001970
1971static int
1972encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001973 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001974 const struct nfs4_layoutcommit_args *args,
1975 struct compound_hdr *hdr)
1976{
1977 __be32 *p;
1978
1979 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1980 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1981
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001982 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1983 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001984 /* Only whole file layouts */
1985 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001986 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001987 *p = cpu_to_be32(0); /* reclaim */
1988 encode_nfs4_stateid(xdr, &args->stateid);
1989 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001990 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1991 p = xdr_encode_hyper(p, args->lastbytewritten);
1992 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1993 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001994
1995 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1996 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1997 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001998 else
1999 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00002000
Andy Adamson863a3c62011-03-23 13:27:54 +00002001 return 0;
2002}
Benny Halevycbe82602011-05-22 19:52:37 +03002003
2004static void
2005encode_layoutreturn(struct xdr_stream *xdr,
2006 const struct nfs4_layoutreturn_args *args,
2007 struct compound_hdr *hdr)
2008{
2009 __be32 *p;
2010
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002011 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2012 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002013 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2014 *p++ = cpu_to_be32(args->layout_type);
2015 *p++ = cpu_to_be32(IOMODE_ANY);
2016 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002017 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002018 p = xdr_encode_hyper(p, 0);
2019 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2020 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002021 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002022 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002023 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2024 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2025 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002026 } else
2027 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002028}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002029
2030static int
2031encode_secinfo_no_name(struct xdr_stream *xdr,
2032 const struct nfs41_secinfo_no_name_args *args,
2033 struct compound_hdr *hdr)
2034{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002035 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2036 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002037 return 0;
2038}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002039
2040static void encode_test_stateid(struct xdr_stream *xdr,
2041 struct nfs41_test_stateid_args *args,
2042 struct compound_hdr *hdr)
2043{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002044 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2045 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002046 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002047}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002048
2049static void encode_free_stateid(struct xdr_stream *xdr,
2050 struct nfs41_free_stateid_args *args,
2051 struct compound_hdr *hdr)
2052{
Trond Myklebustab19b482012-03-04 18:13:57 -05002053 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002054 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002055}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002056#endif /* CONFIG_NFS_V4_1 */
2057
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058/*
2059 * END OF "GENERIC" ENCODE ROUTINES.
2060 */
2061
Benny Halevy66cc0422009-04-01 09:22:10 -04002062static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2063{
2064#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05002065
2066 if (args->sa_slot)
2067 return args->sa_slot->table->session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002068#endif /* CONFIG_NFS_V4_1 */
2069 return 0;
2070}
2071
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072/*
2073 * Encode an ACCESS request
2074 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002075static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2076 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002079 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Chuck Lever9f06c712010-12-14 14:59:18 +00002082 encode_compound_hdr(xdr, req, &hdr);
2083 encode_sequence(xdr, &args->seq_args, &hdr);
2084 encode_putfh(xdr, args->fh, &hdr);
2085 encode_access(xdr, args->access, &hdr);
2086 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002087 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088}
2089
2090/*
2091 * Encode LOOKUP request
2092 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002093static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2094 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002097 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Chuck Lever9f06c712010-12-14 14:59:18 +00002100 encode_compound_hdr(xdr, req, &hdr);
2101 encode_sequence(xdr, &args->seq_args, &hdr);
2102 encode_putfh(xdr, args->dir_fh, &hdr);
2103 encode_lookup(xdr, args->name, &hdr);
2104 encode_getfh(xdr, &hdr);
2105 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002106 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107}
2108
2109/*
2110 * Encode LOOKUP_ROOT request
2111 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002112static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2113 struct xdr_stream *xdr,
2114 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002117 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119
Chuck Lever9f06c712010-12-14 14:59:18 +00002120 encode_compound_hdr(xdr, req, &hdr);
2121 encode_sequence(xdr, &args->seq_args, &hdr);
2122 encode_putrootfh(xdr, &hdr);
2123 encode_getfh(xdr, &hdr);
2124 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002125 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126}
2127
2128/*
2129 * Encode REMOVE request
2130 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002131static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2132 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002135 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
Chuck Lever9f06c712010-12-14 14:59:18 +00002138 encode_compound_hdr(xdr, req, &hdr);
2139 encode_sequence(xdr, &args->seq_args, &hdr);
2140 encode_putfh(xdr, args->fh, &hdr);
2141 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002142 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143}
2144
2145/*
2146 * Encode RENAME request
2147 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002148static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2149 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002152 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154
Chuck Lever9f06c712010-12-14 14:59:18 +00002155 encode_compound_hdr(xdr, req, &hdr);
2156 encode_sequence(xdr, &args->seq_args, &hdr);
2157 encode_putfh(xdr, args->old_dir, &hdr);
2158 encode_savefh(xdr, &hdr);
2159 encode_putfh(xdr, args->new_dir, &hdr);
2160 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002161 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162}
2163
2164/*
2165 * Encode LINK request
2166 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002167static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2168 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002171 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
Chuck Lever9f06c712010-12-14 14:59:18 +00002174 encode_compound_hdr(xdr, req, &hdr);
2175 encode_sequence(xdr, &args->seq_args, &hdr);
2176 encode_putfh(xdr, args->fh, &hdr);
2177 encode_savefh(xdr, &hdr);
2178 encode_putfh(xdr, args->dir_fh, &hdr);
2179 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002180 encode_restorefh(xdr, &hdr);
2181 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002182 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183}
2184
2185/*
2186 * Encode CREATE request
2187 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002188static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2189 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002192 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Chuck Lever9f06c712010-12-14 14:59:18 +00002195 encode_compound_hdr(xdr, req, &hdr);
2196 encode_sequence(xdr, &args->seq_args, &hdr);
2197 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002198 encode_create(xdr, args, &hdr);
2199 encode_getfh(xdr, &hdr);
2200 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002201 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202}
2203
2204/*
2205 * Encode SYMLINK request
2206 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002207static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2208 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209{
Chuck Lever9f06c712010-12-14 14:59:18 +00002210 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211}
2212
2213/*
2214 * Encode GETATTR request
2215 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002216static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2217 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002220 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222
Chuck Lever9f06c712010-12-14 14:59:18 +00002223 encode_compound_hdr(xdr, req, &hdr);
2224 encode_sequence(xdr, &args->seq_args, &hdr);
2225 encode_putfh(xdr, args->fh, &hdr);
2226 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002227 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228}
2229
2230/*
2231 * Encode a CLOSE request
2232 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002233static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2234 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235{
Andy Adamson05d564f2008-12-23 16:06:15 -05002236 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002237 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002238 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
Chuck Lever9f06c712010-12-14 14:59:18 +00002240 encode_compound_hdr(xdr, req, &hdr);
2241 encode_sequence(xdr, &args->seq_args, &hdr);
2242 encode_putfh(xdr, args->fh, &hdr);
2243 encode_close(xdr, args, &hdr);
2244 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002245 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246}
2247
2248/*
2249 * Encode an OPEN request
2250 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002251static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2252 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002255 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
Chuck Lever9f06c712010-12-14 14:59:18 +00002258 encode_compound_hdr(xdr, req, &hdr);
2259 encode_sequence(xdr, &args->seq_args, &hdr);
2260 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002261 encode_open(xdr, args, &hdr);
2262 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002263 if (args->access)
2264 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002265 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002266 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267}
2268
2269/*
2270 * Encode an OPEN_CONFIRM request
2271 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002272static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2273 struct xdr_stream *xdr,
2274 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002277 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
Chuck Lever9f06c712010-12-14 14:59:18 +00002280 encode_compound_hdr(xdr, req, &hdr);
2281 encode_putfh(xdr, args->fh, &hdr);
2282 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002283 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284}
2285
2286/*
2287 * Encode an OPEN request with no attributes.
2288 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002289static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2290 struct xdr_stream *xdr,
2291 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002294 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296
Chuck Lever9f06c712010-12-14 14:59:18 +00002297 encode_compound_hdr(xdr, req, &hdr);
2298 encode_sequence(xdr, &args->seq_args, &hdr);
2299 encode_putfh(xdr, args->fh, &hdr);
2300 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002301 if (args->access)
2302 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002303 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002304 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305}
2306
2307/*
2308 * Encode an OPEN_DOWNGRADE request
2309 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002310static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2311 struct xdr_stream *xdr,
2312 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002315 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Chuck Lever9f06c712010-12-14 14:59:18 +00002318 encode_compound_hdr(xdr, req, &hdr);
2319 encode_sequence(xdr, &args->seq_args, &hdr);
2320 encode_putfh(xdr, args->fh, &hdr);
2321 encode_open_downgrade(xdr, args, &hdr);
2322 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002323 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324}
2325
2326/*
2327 * Encode a LOCK request
2328 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002329static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2330 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002333 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
Chuck Lever9f06c712010-12-14 14:59:18 +00002336 encode_compound_hdr(xdr, req, &hdr);
2337 encode_sequence(xdr, &args->seq_args, &hdr);
2338 encode_putfh(xdr, args->fh, &hdr);
2339 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002340 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341}
2342
2343/*
2344 * Encode a LOCKT request
2345 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002346static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2347 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002350 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352
Chuck Lever9f06c712010-12-14 14:59:18 +00002353 encode_compound_hdr(xdr, req, &hdr);
2354 encode_sequence(xdr, &args->seq_args, &hdr);
2355 encode_putfh(xdr, args->fh, &hdr);
2356 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002357 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358}
2359
2360/*
2361 * Encode a LOCKU request
2362 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002363static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2364 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002367 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369
Chuck Lever9f06c712010-12-14 14:59:18 +00002370 encode_compound_hdr(xdr, req, &hdr);
2371 encode_sequence(xdr, &args->seq_args, &hdr);
2372 encode_putfh(xdr, args->fh, &hdr);
2373 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002374 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375}
2376
Chuck Lever9f06c712010-12-14 14:59:18 +00002377static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2378 struct xdr_stream *xdr,
2379 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002380{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002381 struct compound_hdr hdr = {
2382 .minorversion = 0,
2383 };
2384
Chuck Lever9f06c712010-12-14 14:59:18 +00002385 encode_compound_hdr(xdr, req, &hdr);
2386 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002387 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002388}
2389
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390/*
2391 * Encode a READLINK request
2392 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002393static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2394 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002397 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
Chuck Lever9f06c712010-12-14 14:59:18 +00002400 encode_compound_hdr(xdr, req, &hdr);
2401 encode_sequence(xdr, &args->seq_args, &hdr);
2402 encode_putfh(xdr, args->fh, &hdr);
2403 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002404
Benny Halevy28f56692009-04-01 09:22:09 -04002405 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002406 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002407 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408}
2409
2410/*
2411 * Encode a READDIR request
2412 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002413static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2414 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002417 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Chuck Lever9f06c712010-12-14 14:59:18 +00002420 encode_compound_hdr(xdr, req, &hdr);
2421 encode_sequence(xdr, &args->seq_args, &hdr);
2422 encode_putfh(xdr, args->fh, &hdr);
2423 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002424
Benny Halevy28f56692009-04-01 09:22:09 -04002425 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002426 args->pgbase, args->count);
2427 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002428 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002429 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002430 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431}
2432
2433/*
2434 * Encode a READ request
2435 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002436static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2437 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002440 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442
Chuck Lever9f06c712010-12-14 14:59:18 +00002443 encode_compound_hdr(xdr, req, &hdr);
2444 encode_sequence(xdr, &args->seq_args, &hdr);
2445 encode_putfh(xdr, args->fh, &hdr);
2446 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447
Benny Halevy28f56692009-04-01 09:22:09 -04002448 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002450 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002451 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452}
2453
2454/*
2455 * Encode an SETATTR request
2456 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002457static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2458 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459{
Andy Adamson05d564f2008-12-23 16:06:15 -05002460 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002461 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002462 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463
Chuck Lever9f06c712010-12-14 14:59:18 +00002464 encode_compound_hdr(xdr, req, &hdr);
2465 encode_sequence(xdr, &args->seq_args, &hdr);
2466 encode_putfh(xdr, args->fh, &hdr);
2467 encode_setattr(xdr, args, args->server, &hdr);
2468 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002469 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470}
2471
2472/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002473 * Encode a GETACL request
2474 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002475static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2476 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002477{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002478 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002479 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002480 };
Benny Halevy28f56692009-04-01 09:22:09 -04002481 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002482
Chuck Lever9f06c712010-12-14 14:59:18 +00002483 encode_compound_hdr(xdr, req, &hdr);
2484 encode_sequence(xdr, &args->seq_args, &hdr);
2485 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002486 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002487 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002488
Benny Halevy28f56692009-04-01 09:22:09 -04002489 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002490 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002491
Andy Adamsond0179312008-12-23 16:06:17 -05002492 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002493}
2494
2495/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 * Encode a WRITE request
2497 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002498static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2499 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002502 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504
Chuck Lever9f06c712010-12-14 14:59:18 +00002505 encode_compound_hdr(xdr, req, &hdr);
2506 encode_sequence(xdr, &args->seq_args, &hdr);
2507 encode_putfh(xdr, args->fh, &hdr);
2508 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002509 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002510 if (args->bitmask)
2511 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002512 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513}
2514
2515/*
2516 * a COMMIT request
2517 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002518static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002519 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002522 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524
Chuck Lever9f06c712010-12-14 14:59:18 +00002525 encode_compound_hdr(xdr, req, &hdr);
2526 encode_sequence(xdr, &args->seq_args, &hdr);
2527 encode_putfh(xdr, args->fh, &hdr);
2528 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002529 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530}
2531
2532/*
2533 * FSINFO request
2534 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002535static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2536 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002539 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541
Chuck Lever9f06c712010-12-14 14:59:18 +00002542 encode_compound_hdr(xdr, req, &hdr);
2543 encode_sequence(xdr, &args->seq_args, &hdr);
2544 encode_putfh(xdr, args->fh, &hdr);
2545 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002546 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547}
2548
2549/*
2550 * a PATHCONF request
2551 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002552static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2553 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002556 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
Chuck Lever9f06c712010-12-14 14:59:18 +00002559 encode_compound_hdr(xdr, req, &hdr);
2560 encode_sequence(xdr, &args->seq_args, &hdr);
2561 encode_putfh(xdr, args->fh, &hdr);
2562 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002563 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002564 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565}
2566
2567/*
2568 * a STATFS request
2569 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002570static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2571 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002574 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576
Chuck Lever9f06c712010-12-14 14:59:18 +00002577 encode_compound_hdr(xdr, req, &hdr);
2578 encode_sequence(xdr, &args->seq_args, &hdr);
2579 encode_putfh(xdr, args->fh, &hdr);
2580 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002581 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002582 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583}
2584
2585/*
2586 * GETATTR_BITMAP request
2587 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002588static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2589 struct xdr_stream *xdr,
2590 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002593 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Chuck Lever9f06c712010-12-14 14:59:18 +00002596 encode_compound_hdr(xdr, req, &hdr);
2597 encode_sequence(xdr, &args->seq_args, &hdr);
2598 encode_putfh(xdr, args->fhandle, &hdr);
2599 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002600 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002601 FATTR4_WORD0_LINK_SUPPORT|
2602 FATTR4_WORD0_SYMLINK_SUPPORT|
2603 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002604 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605}
2606
2607/*
2608 * a RENEW request
2609 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002610static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2611 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002614 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 };
2616
Chuck Lever9f06c712010-12-14 14:59:18 +00002617 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002618 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002619 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620}
2621
2622/*
2623 * a SETCLIENTID request
2624 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002625static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2626 struct xdr_stream *xdr,
2627 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002630 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 };
2632
Chuck Lever9f06c712010-12-14 14:59:18 +00002633 encode_compound_hdr(xdr, req, &hdr);
2634 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002635 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636}
2637
2638/*
2639 * a SETCLIENTID_CONFIRM request
2640 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002641static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2642 struct xdr_stream *xdr,
2643 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002646 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648
Chuck Lever9f06c712010-12-14 14:59:18 +00002649 encode_compound_hdr(xdr, req, &hdr);
2650 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002651 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652}
2653
2654/*
2655 * DELEGRETURN request
2656 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002657static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2658 struct xdr_stream *xdr,
2659 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002662 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
Chuck Lever9f06c712010-12-14 14:59:18 +00002665 encode_compound_hdr(xdr, req, &hdr);
2666 encode_sequence(xdr, &args->seq_args, &hdr);
2667 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002668 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002669 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002670 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671}
2672
2673/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002674 * Encode FS_LOCATIONS request
2675 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002676static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2677 struct xdr_stream *xdr,
2678 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002679{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002680 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002681 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002682 };
Benny Halevy28f56692009-04-01 09:22:09 -04002683 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002684
Chuck Lever9f06c712010-12-14 14:59:18 +00002685 encode_compound_hdr(xdr, req, &hdr);
2686 encode_sequence(xdr, &args->seq_args, &hdr);
2687 encode_putfh(xdr, args->dir_fh, &hdr);
2688 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002689 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002690 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002691
Benny Halevy28f56692009-04-01 09:22:09 -04002692 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002693 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002694 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002695}
2696
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002697/*
2698 * Encode SECINFO request
2699 */
2700static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2701 struct xdr_stream *xdr,
2702 struct nfs4_secinfo_arg *args)
2703{
2704 struct compound_hdr hdr = {
2705 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2706 };
2707
2708 encode_compound_hdr(xdr, req, &hdr);
2709 encode_sequence(xdr, &args->seq_args, &hdr);
2710 encode_putfh(xdr, args->dir_fh, &hdr);
2711 encode_secinfo(xdr, args->name, &hdr);
2712 encode_nops(&hdr);
2713}
2714
Benny Halevy99fe60d2009-04-01 09:22:29 -04002715#if defined(CONFIG_NFS_V4_1)
2716/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002717 * BIND_CONN_TO_SESSION request
2718 */
2719static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2720 struct xdr_stream *xdr,
2721 struct nfs_client *clp)
2722{
2723 struct compound_hdr hdr = {
2724 .minorversion = clp->cl_mvops->minor_version,
2725 };
2726
2727 encode_compound_hdr(xdr, req, &hdr);
2728 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2729 encode_nops(&hdr);
2730}
2731
2732/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002733 * EXCHANGE_ID request
2734 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002735static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2736 struct xdr_stream *xdr,
2737 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002738{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002739 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002740 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002741 };
2742
Chuck Lever9f06c712010-12-14 14:59:18 +00002743 encode_compound_hdr(xdr, req, &hdr);
2744 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002745 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002746}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002747
2748/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002749 * a CREATE_SESSION request
2750 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002751static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2752 struct xdr_stream *xdr,
2753 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002754{
Andy Adamsonfc931582009-04-01 09:22:31 -04002755 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002756 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002757 };
2758
Chuck Lever9f06c712010-12-14 14:59:18 +00002759 encode_compound_hdr(xdr, req, &hdr);
2760 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002761 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002762}
2763
2764/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002765 * a DESTROY_SESSION request
2766 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002767static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2768 struct xdr_stream *xdr,
2769 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002770{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002771 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002772 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002773 };
2774
Chuck Lever9f06c712010-12-14 14:59:18 +00002775 encode_compound_hdr(xdr, req, &hdr);
2776 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002777 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002778}
2779
2780/*
Trond Myklebust66245532012-05-25 17:18:09 -04002781 * a DESTROY_CLIENTID request
2782 */
2783static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2784 struct xdr_stream *xdr,
2785 struct nfs_client *clp)
2786{
2787 struct compound_hdr hdr = {
2788 .minorversion = clp->cl_mvops->minor_version,
2789 };
2790
2791 encode_compound_hdr(xdr, req, &hdr);
2792 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2793 encode_nops(&hdr);
2794}
2795
2796/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002797 * a SEQUENCE request
2798 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002799static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2800 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002801{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002802 struct compound_hdr hdr = {
2803 .minorversion = nfs4_xdr_minorversion(args),
2804 };
2805
Chuck Lever9f06c712010-12-14 14:59:18 +00002806 encode_compound_hdr(xdr, req, &hdr);
2807 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002808 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002809}
2810
2811/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002812 * a GET_LEASE_TIME request
2813 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002814static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2815 struct xdr_stream *xdr,
2816 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002817{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002818 struct compound_hdr hdr = {
2819 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2820 };
Fred Isamandae100c2011-07-30 20:52:37 -04002821 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002822
Chuck Lever9f06c712010-12-14 14:59:18 +00002823 encode_compound_hdr(xdr, req, &hdr);
2824 encode_sequence(xdr, &args->la_seq_args, &hdr);
2825 encode_putrootfh(xdr, &hdr);
2826 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002827 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002828}
Ricardo Labiaga18019752009-12-05 16:08:40 -05002829
2830/*
2831 * a RECLAIM_COMPLETE request
2832 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002833static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2834 struct xdr_stream *xdr,
2835 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga18019752009-12-05 16:08:40 -05002836{
Ricardo Labiaga18019752009-12-05 16:08:40 -05002837 struct compound_hdr hdr = {
2838 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2839 };
2840
Chuck Lever9f06c712010-12-14 14:59:18 +00002841 encode_compound_hdr(xdr, req, &hdr);
2842 encode_sequence(xdr, &args->seq_args, &hdr);
2843 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002844 encode_nops(&hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002845}
2846
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002847/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002848 * Encode GETDEVICELIST request
2849 */
2850static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2851 struct xdr_stream *xdr,
2852 struct nfs4_getdevicelist_args *args)
2853{
2854 struct compound_hdr hdr = {
2855 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2856 };
2857
2858 encode_compound_hdr(xdr, req, &hdr);
2859 encode_sequence(xdr, &args->seq_args, &hdr);
2860 encode_putfh(xdr, args->fh, &hdr);
2861 encode_getdevicelist(xdr, args, &hdr);
2862 encode_nops(&hdr);
2863}
2864
2865/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002866 * Encode GETDEVICEINFO request
2867 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002868static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2869 struct xdr_stream *xdr,
2870 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002871{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002872 struct compound_hdr hdr = {
2873 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2874 };
2875
Chuck Lever9f06c712010-12-14 14:59:18 +00002876 encode_compound_hdr(xdr, req, &hdr);
2877 encode_sequence(xdr, &args->seq_args, &hdr);
2878 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002879
2880 /* set up reply kvec. Subtract notification bitmap max size (2)
2881 * so that notification bitmap is put in xdr_buf tail */
2882 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2883 args->pdev->pages, args->pdev->pgbase,
2884 args->pdev->pglen);
2885
2886 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002887}
2888
2889/*
2890 * Encode LAYOUTGET request
2891 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002892static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2893 struct xdr_stream *xdr,
2894 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002895{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002896 struct compound_hdr hdr = {
2897 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2898 };
2899
Chuck Lever9f06c712010-12-14 14:59:18 +00002900 encode_compound_hdr(xdr, req, &hdr);
2901 encode_sequence(xdr, &args->seq_args, &hdr);
2902 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2903 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002904
2905 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2906 args->layout.pages, 0, args->layout.pglen);
2907
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002908 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002909}
Andy Adamson863a3c62011-03-23 13:27:54 +00002910
2911/*
2912 * Encode LAYOUTCOMMIT request
2913 */
Benny Halevycbe82602011-05-22 19:52:37 +03002914static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2915 struct xdr_stream *xdr,
2916 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002917{
Benny Halevyac7db722011-05-22 19:53:48 +03002918 struct nfs4_layoutcommit_data *data =
2919 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002920 struct compound_hdr hdr = {
2921 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2922 };
2923
2924 encode_compound_hdr(xdr, req, &hdr);
2925 encode_sequence(xdr, &args->seq_args, &hdr);
2926 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002927 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002928 encode_getfattr(xdr, args->bitmask, &hdr);
2929 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002930}
2931
2932/*
2933 * Encode LAYOUTRETURN request
2934 */
2935static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2936 struct xdr_stream *xdr,
2937 struct nfs4_layoutreturn_args *args)
2938{
2939 struct compound_hdr hdr = {
2940 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2941 };
2942
2943 encode_compound_hdr(xdr, req, &hdr);
2944 encode_sequence(xdr, &args->seq_args, &hdr);
2945 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2946 encode_layoutreturn(xdr, args, &hdr);
2947 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002948}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002949
2950/*
2951 * Encode SECINFO_NO_NAME request
2952 */
2953static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2954 struct xdr_stream *xdr,
2955 struct nfs41_secinfo_no_name_args *args)
2956{
2957 struct compound_hdr hdr = {
2958 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2959 };
2960
2961 encode_compound_hdr(xdr, req, &hdr);
2962 encode_sequence(xdr, &args->seq_args, &hdr);
2963 encode_putrootfh(xdr, &hdr);
2964 encode_secinfo_no_name(xdr, args, &hdr);
2965 encode_nops(&hdr);
2966 return 0;
2967}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002968
2969/*
2970 * Encode TEST_STATEID request
2971 */
2972static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2973 struct xdr_stream *xdr,
2974 struct nfs41_test_stateid_args *args)
2975{
2976 struct compound_hdr hdr = {
2977 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2978 };
2979
2980 encode_compound_hdr(xdr, req, &hdr);
2981 encode_sequence(xdr, &args->seq_args, &hdr);
2982 encode_test_stateid(xdr, args, &hdr);
2983 encode_nops(&hdr);
2984}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002985
2986/*
2987 * Encode FREE_STATEID request
2988 */
2989static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2990 struct xdr_stream *xdr,
2991 struct nfs41_free_stateid_args *args)
2992{
2993 struct compound_hdr hdr = {
2994 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2995 };
2996
2997 encode_compound_hdr(xdr, req, &hdr);
2998 encode_sequence(xdr, &args->seq_args, &hdr);
2999 encode_free_stateid(xdr, args, &hdr);
3000 encode_nops(&hdr);
3001}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003002#endif /* CONFIG_NFS_V4_1 */
3003
Benny Halevy686841b2009-08-14 17:19:48 +03003004static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3005{
3006 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3007 "Remaining buffer length is %tu words.\n",
3008 func, xdr->end - xdr->p);
3009}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010
Trond Myklebust683b57b2006-06-09 09:34:22 -04003011static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012{
Al Viro8687b632006-10-19 23:28:48 -07003013 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014
Benny Halevyc0eae662009-08-14 17:20:14 +03003015 p = xdr_inline_decode(xdr, 4);
3016 if (unlikely(!p))
3017 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003018 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003019 p = xdr_inline_decode(xdr, *len);
3020 if (unlikely(!p))
3021 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 *string = (char *)p;
3023 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003024out_overflow:
3025 print_overflow_msg(__func__, xdr);
3026 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027}
3028
3029static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3030{
Al Viro8687b632006-10-19 23:28:48 -07003031 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032
Benny Halevyc0eae662009-08-14 17:20:14 +03003033 p = xdr_inline_decode(xdr, 8);
3034 if (unlikely(!p))
3035 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003036 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003037 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003038
Benny Halevyc0eae662009-08-14 17:20:14 +03003039 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3040 if (unlikely(!p))
3041 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 hdr->tag = (char *)p;
3043 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003044 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003045 if (unlikely(hdr->nops < 1))
3046 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003048out_overflow:
3049 print_overflow_msg(__func__, xdr);
3050 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051}
3052
3053static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3054{
Al Viro8687b632006-10-19 23:28:48 -07003055 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 uint32_t opnum;
3057 int32_t nfserr;
3058
Benny Halevyc0eae662009-08-14 17:20:14 +03003059 p = xdr_inline_decode(xdr, 8);
3060 if (unlikely(!p))
3061 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003062 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003064 dprintk("nfs: Server returned operation"
3065 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 opnum, expected);
3067 return -EIO;
3068 }
Benny Halevycccddf42009-08-14 17:20:19 +03003069 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003071 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003073out_overflow:
3074 print_overflow_msg(__func__, xdr);
3075 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076}
3077
3078/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003079static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080{
Al Viro8687b632006-10-19 23:28:48 -07003081 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003082 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 char *str;
3084
Benny Halevyc0eae662009-08-14 17:20:14 +03003085 p = xdr_inline_decode(xdr, 12);
3086 if (likely(p))
3087 return decode_opaque_inline(xdr, &strlen, &str);
3088 print_overflow_msg(__func__, xdr);
3089 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090}
3091
3092static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3093{
Al Viro8687b632006-10-19 23:28:48 -07003094 uint32_t bmlen;
3095 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096
Benny Halevyc0eae662009-08-14 17:20:14 +03003097 p = xdr_inline_decode(xdr, 4);
3098 if (unlikely(!p))
3099 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003100 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101
Fred Isamandae100c2011-07-30 20:52:37 -04003102 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003103 p = xdr_inline_decode(xdr, (bmlen << 2));
3104 if (unlikely(!p))
3105 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003107 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003108 if (bmlen > 1) {
3109 bitmap[1] = be32_to_cpup(p++);
3110 if (bmlen > 2)
3111 bitmap[2] = be32_to_cpup(p);
3112 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 }
3114 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003115out_overflow:
3116 print_overflow_msg(__func__, xdr);
3117 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118}
3119
Trond Myklebust256e48b2012-06-21 11:18:13 -04003120static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121{
Al Viro8687b632006-10-19 23:28:48 -07003122 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123
Benny Halevyc0eae662009-08-14 17:20:14 +03003124 p = xdr_inline_decode(xdr, 4);
3125 if (unlikely(!p))
3126 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003127 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003128 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003130out_overflow:
3131 print_overflow_msg(__func__, xdr);
3132 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133}
3134
3135static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3136{
3137 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003138 int ret;
3139 ret = decode_attr_bitmap(xdr, bitmask);
3140 if (unlikely(ret < 0))
3141 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3143 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003144 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3145 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3146 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 return 0;
3148}
3149
3150static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3151{
Al Viro8687b632006-10-19 23:28:48 -07003152 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003153 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154
3155 *type = 0;
3156 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3157 return -EIO;
3158 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003159 p = xdr_inline_decode(xdr, 4);
3160 if (unlikely(!p))
3161 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003162 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003164 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 return -EIO;
3166 }
3167 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003168 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 }
Trond Myklebustbca794782009-03-11 14:10:26 -04003170 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003171 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003172out_overflow:
3173 print_overflow_msg(__func__, xdr);
3174 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175}
3176
Chuck Lever264e6352012-03-01 17:02:05 -05003177static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3178 uint32_t *bitmap, uint32_t *type)
3179{
3180 __be32 *p;
3181
3182 *type = 0;
3183 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3184 return -EIO;
3185 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3186 p = xdr_inline_decode(xdr, 4);
3187 if (unlikely(!p))
3188 goto out_overflow;
3189 *type = be32_to_cpup(p);
3190 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3191 }
3192 dprintk("%s: expire type=0x%x\n", __func__, *type);
3193 return 0;
3194out_overflow:
3195 print_overflow_msg(__func__, xdr);
3196 return -EIO;
3197}
3198
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3200{
Al Viro8687b632006-10-19 23:28:48 -07003201 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003202 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203
3204 *change = 0;
3205 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3206 return -EIO;
3207 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003208 p = xdr_inline_decode(xdr, 8);
3209 if (unlikely(!p))
3210 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003211 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003213 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003215 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003217 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003218out_overflow:
3219 print_overflow_msg(__func__, xdr);
3220 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221}
3222
3223static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3224{
Al Viro8687b632006-10-19 23:28:48 -07003225 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003226 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227
3228 *size = 0;
3229 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3230 return -EIO;
3231 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003232 p = xdr_inline_decode(xdr, 8);
3233 if (unlikely(!p))
3234 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003235 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003237 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003239 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003240 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003241out_overflow:
3242 print_overflow_msg(__func__, xdr);
3243 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244}
3245
3246static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3247{
Al Viro8687b632006-10-19 23:28:48 -07003248 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249
3250 *res = 0;
3251 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3252 return -EIO;
3253 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003254 p = xdr_inline_decode(xdr, 4);
3255 if (unlikely(!p))
3256 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003257 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3259 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003260 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003262out_overflow:
3263 print_overflow_msg(__func__, xdr);
3264 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265}
3266
3267static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3268{
Al Viro8687b632006-10-19 23:28:48 -07003269 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270
3271 *res = 0;
3272 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3273 return -EIO;
3274 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003275 p = xdr_inline_decode(xdr, 4);
3276 if (unlikely(!p))
3277 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003278 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3280 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003281 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003283out_overflow:
3284 print_overflow_msg(__func__, xdr);
3285 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286}
3287
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003288static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289{
Al Viro8687b632006-10-19 23:28:48 -07003290 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003291 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292
3293 fsid->major = 0;
3294 fsid->minor = 0;
3295 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3296 return -EIO;
3297 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003298 p = xdr_inline_decode(xdr, 16);
3299 if (unlikely(!p))
3300 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003301 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003302 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003304 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003306 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 (unsigned long long)fsid->major,
3308 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003309 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003310out_overflow:
3311 print_overflow_msg(__func__, xdr);
3312 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313}
3314
3315static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3316{
Al Viro8687b632006-10-19 23:28:48 -07003317 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
3319 *res = 60;
3320 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3321 return -EIO;
3322 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003323 p = xdr_inline_decode(xdr, 4);
3324 if (unlikely(!p))
3325 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003326 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3328 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003329 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003331out_overflow:
3332 print_overflow_msg(__func__, xdr);
3333 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334}
3335
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003336static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003337{
3338 __be32 *p;
3339
3340 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3341 return -EIO;
3342 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3343 p = xdr_inline_decode(xdr, 4);
3344 if (unlikely(!p))
3345 goto out_overflow;
3346 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003347 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003348 }
3349 return 0;
3350out_overflow:
3351 print_overflow_msg(__func__, xdr);
3352 return -EIO;
3353}
3354
3355static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3356{
3357 __be32 *p;
3358 int len;
3359
Trond Myklebust7ad07352010-10-23 15:34:20 -04003360 if (fh != NULL)
3361 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003362
3363 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3364 return -EIO;
3365 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3366 p = xdr_inline_decode(xdr, 4);
3367 if (unlikely(!p))
3368 goto out_overflow;
3369 len = be32_to_cpup(p);
3370 if (len > NFS4_FHSIZE)
3371 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003372 p = xdr_inline_decode(xdr, len);
3373 if (unlikely(!p))
3374 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003375 if (fh != NULL) {
3376 memcpy(fh->data, p, len);
3377 fh->size = len;
3378 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003379 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3380 }
3381 return 0;
3382out_overflow:
3383 print_overflow_msg(__func__, xdr);
3384 return -EIO;
3385}
3386
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3388{
Al Viro8687b632006-10-19 23:28:48 -07003389 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390
3391 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3392 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3393 return -EIO;
3394 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003395 p = xdr_inline_decode(xdr, 4);
3396 if (unlikely(!p))
3397 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003398 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3400 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003401 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003403out_overflow:
3404 print_overflow_msg(__func__, xdr);
3405 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406}
3407
3408static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3409{
Al Viro8687b632006-10-19 23:28:48 -07003410 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003411 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412
3413 *fileid = 0;
3414 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3415 return -EIO;
3416 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003417 p = xdr_inline_decode(xdr, 8);
3418 if (unlikely(!p))
3419 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003420 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003422 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003424 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003425 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003426out_overflow:
3427 print_overflow_msg(__func__, xdr);
3428 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429}
3430
Manoj Naik99baf622006-06-09 09:34:24 -04003431static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3432{
Al Viro8687b632006-10-19 23:28:48 -07003433 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003434 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003435
3436 *fileid = 0;
3437 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3438 return -EIO;
3439 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003440 p = xdr_inline_decode(xdr, 8);
3441 if (unlikely(!p))
3442 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003443 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003444 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003445 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003446 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003447 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003448 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003449out_overflow:
3450 print_overflow_msg(__func__, xdr);
3451 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003452}
3453
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3455{
Al Viro8687b632006-10-19 23:28:48 -07003456 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 int status = 0;
3458
3459 *res = 0;
3460 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3461 return -EIO;
3462 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003463 p = xdr_inline_decode(xdr, 8);
3464 if (unlikely(!p))
3465 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003466 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3468 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003469 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003471out_overflow:
3472 print_overflow_msg(__func__, xdr);
3473 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474}
3475
3476static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3477{
Al Viro8687b632006-10-19 23:28:48 -07003478 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 int status = 0;
3480
3481 *res = 0;
3482 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3483 return -EIO;
3484 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003485 p = xdr_inline_decode(xdr, 8);
3486 if (unlikely(!p))
3487 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003488 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3490 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003491 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003493out_overflow:
3494 print_overflow_msg(__func__, xdr);
3495 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496}
3497
3498static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3499{
Al Viro8687b632006-10-19 23:28:48 -07003500 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 int status = 0;
3502
3503 *res = 0;
3504 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3505 return -EIO;
3506 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003507 p = xdr_inline_decode(xdr, 8);
3508 if (unlikely(!p))
3509 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003510 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3512 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003513 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003515out_overflow:
3516 print_overflow_msg(__func__, xdr);
3517 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518}
3519
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003520static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3521{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003522 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003523 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003524 int status = 0;
3525
Benny Halevyc0eae662009-08-14 17:20:14 +03003526 p = xdr_inline_decode(xdr, 4);
3527 if (unlikely(!p))
3528 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003529 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003530 if (n == 0)
3531 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003532 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003533 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3534 dprintk("cannot parse %d components in path\n", n);
3535 goto out_eio;
3536 }
3537 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003538 struct nfs4_string *component = &path->components[path->ncomponents];
3539 status = decode_opaque_inline(xdr, &component->len, &component->data);
3540 if (unlikely(status != 0))
3541 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003542 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003543 pr_cont("%s%.*s ",
3544 (path->ncomponents != n ? "/ " : ""),
3545 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003546 }
3547out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003548 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003549root_path:
3550/* a root pathname is sent as a zero component4 */
3551 path->ncomponents = 1;
3552 path->components[0].len=0;
3553 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003554 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003555 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003556out_eio:
3557 dprintk(" status %d", status);
3558 status = -EIO;
3559 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003560out_overflow:
3561 print_overflow_msg(__func__, xdr);
3562 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003563}
3564
3565static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003566{
3567 int n;
Al Viro8687b632006-10-19 23:28:48 -07003568 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003569 int status = -EIO;
3570
3571 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3572 goto out;
3573 status = 0;
3574 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3575 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003576 status = -EIO;
3577 /* Ignore borken servers that return unrequested attrs */
3578 if (unlikely(res == NULL))
3579 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003580 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003581 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003582 if (unlikely(status != 0))
3583 goto out;
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 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003588 if (n <= 0)
3589 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003590 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003591 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003592 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003593
Trond Myklebust809b4262013-03-27 11:54:45 -04003594 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3595 break;
3596 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003597 p = xdr_inline_decode(xdr, 4);
3598 if (unlikely(!p))
3599 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003600 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003601
Chuck Lever02a29762012-03-01 17:00:31 -05003602 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003603 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3604 struct nfs4_string *server;
3605
3606 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003607 unsigned int i;
3608 dprintk("%s: using first %u of %u servers "
3609 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003610 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003611 NFS4_FS_LOCATION_MAXSERVERS,
3612 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003613 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003614 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003615 char *data;
3616 status = decode_opaque_inline(xdr, &len, &data);
3617 if (unlikely(status != 0))
3618 goto out_eio;
3619 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003620 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003621 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003622 server = &loc->servers[loc->nservers];
3623 status = decode_opaque_inline(xdr, &server->len, &server->data);
3624 if (unlikely(status != 0))
3625 goto out_eio;
3626 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003627 }
3628 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003629 if (unlikely(status != 0))
3630 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003631 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003632 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003633 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003634out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003635 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003636 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003637out_overflow:
3638 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003639out_eio:
3640 status = -EIO;
3641 goto out;
3642}
3643
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3645{
Al Viro8687b632006-10-19 23:28:48 -07003646 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 int status = 0;
3648
3649 *res = 0;
3650 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3651 return -EIO;
3652 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003653 p = xdr_inline_decode(xdr, 8);
3654 if (unlikely(!p))
3655 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003656 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3658 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003659 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003661out_overflow:
3662 print_overflow_msg(__func__, xdr);
3663 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664}
3665
3666static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3667{
Al Viro8687b632006-10-19 23:28:48 -07003668 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 int status = 0;
3670
3671 *maxlink = 1;
3672 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3673 return -EIO;
3674 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003675 p = xdr_inline_decode(xdr, 4);
3676 if (unlikely(!p))
3677 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003678 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3680 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003681 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003683out_overflow:
3684 print_overflow_msg(__func__, xdr);
3685 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686}
3687
3688static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3689{
Al Viro8687b632006-10-19 23:28:48 -07003690 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 int status = 0;
3692
3693 *maxname = 1024;
3694 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3695 return -EIO;
3696 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003697 p = xdr_inline_decode(xdr, 4);
3698 if (unlikely(!p))
3699 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003700 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3702 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003703 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003705out_overflow:
3706 print_overflow_msg(__func__, xdr);
3707 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708}
3709
3710static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3711{
Al Viro8687b632006-10-19 23:28:48 -07003712 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 int status = 0;
3714
3715 *res = 1024;
3716 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3717 return -EIO;
3718 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3719 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003720 p = xdr_inline_decode(xdr, 8);
3721 if (unlikely(!p))
3722 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003723 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 if (maxread > 0x7FFFFFFF)
3725 maxread = 0x7FFFFFFF;
3726 *res = (uint32_t)maxread;
3727 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3728 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003729 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003731out_overflow:
3732 print_overflow_msg(__func__, xdr);
3733 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734}
3735
3736static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3737{
Al Viro8687b632006-10-19 23:28:48 -07003738 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 int status = 0;
3740
3741 *res = 1024;
3742 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3743 return -EIO;
3744 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3745 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003746 p = xdr_inline_decode(xdr, 8);
3747 if (unlikely(!p))
3748 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003749 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 if (maxwrite > 0x7FFFFFFF)
3751 maxwrite = 0x7FFFFFFF;
3752 *res = (uint32_t)maxwrite;
3753 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3754 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003755 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003757out_overflow:
3758 print_overflow_msg(__func__, xdr);
3759 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760}
3761
Trond Myklebustbca794782009-03-11 14:10:26 -04003762static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763{
Trond Myklebustbca794782009-03-11 14:10:26 -04003764 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003765 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003766 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767
3768 *mode = 0;
3769 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3770 return -EIO;
3771 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003772 p = xdr_inline_decode(xdr, 4);
3773 if (unlikely(!p))
3774 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003775 tmp = be32_to_cpup(p);
Trond Myklebustbca794782009-03-11 14:10:26 -04003776 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003778 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003780 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003781 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003782out_overflow:
3783 print_overflow_msg(__func__, xdr);
3784 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785}
3786
3787static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3788{
Al Viro8687b632006-10-19 23:28:48 -07003789 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003790 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791
3792 *nlink = 1;
3793 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3794 return -EIO;
3795 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003796 p = xdr_inline_decode(xdr, 4);
3797 if (unlikely(!p))
3798 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003799 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003801 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003803 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003804 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003805out_overflow:
3806 print_overflow_msg(__func__, xdr);
3807 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808}
3809
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003810static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003811 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003812 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813{
Al Viro8687b632006-10-19 23:28:48 -07003814 uint32_t len;
3815 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003816 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817
Eric W. Biedermane5782072013-02-01 14:22:02 -08003818 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3820 return -EIO;
3821 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003822 p = xdr_inline_decode(xdr, 4);
3823 if (unlikely(!p))
3824 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003825 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003826 p = xdr_inline_decode(xdr, len);
3827 if (unlikely(!p))
3828 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003829 if (owner_name != NULL) {
3830 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3831 if (owner_name->data != NULL) {
3832 owner_name->len = len;
3833 ret = NFS_ATTR_FATTR_OWNER_NAME;
3834 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003835 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003836 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003837 ret = NFS_ATTR_FATTR_OWNER;
3838 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003840 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003842 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003843 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3845 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003846 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003847 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003848out_overflow:
3849 print_overflow_msg(__func__, xdr);
3850 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851}
3852
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003853static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003854 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003855 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856{
Al Viro8687b632006-10-19 23:28:48 -07003857 uint32_t len;
3858 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003859 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860
Eric W. Biedermane5782072013-02-01 14:22:02 -08003861 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3863 return -EIO;
3864 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003865 p = xdr_inline_decode(xdr, 4);
3866 if (unlikely(!p))
3867 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003868 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003869 p = xdr_inline_decode(xdr, len);
3870 if (unlikely(!p))
3871 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003872 if (group_name != NULL) {
3873 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3874 if (group_name->data != NULL) {
3875 group_name->len = len;
3876 ret = NFS_ATTR_FATTR_GROUP_NAME;
3877 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003878 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003879 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003880 ret = NFS_ATTR_FATTR_GROUP;
3881 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003883 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003885 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003886 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3888 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003889 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003890 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003891out_overflow:
3892 print_overflow_msg(__func__, xdr);
3893 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894}
3895
3896static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3897{
Al Viro8687b632006-10-19 23:28:48 -07003898 uint32_t major = 0, minor = 0;
3899 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003900 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901
3902 *rdev = MKDEV(0,0);
3903 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3904 return -EIO;
3905 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3906 dev_t tmp;
3907
Benny Halevyc0eae662009-08-14 17:20:14 +03003908 p = xdr_inline_decode(xdr, 8);
3909 if (unlikely(!p))
3910 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003911 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003912 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 tmp = MKDEV(major, minor);
3914 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3915 *rdev = tmp;
3916 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003917 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003919 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003920 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003921out_overflow:
3922 print_overflow_msg(__func__, xdr);
3923 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924}
3925
3926static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3927{
Al Viro8687b632006-10-19 23:28:48 -07003928 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 int status = 0;
3930
3931 *res = 0;
3932 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3933 return -EIO;
3934 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003935 p = xdr_inline_decode(xdr, 8);
3936 if (unlikely(!p))
3937 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003938 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3940 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003941 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003943out_overflow:
3944 print_overflow_msg(__func__, xdr);
3945 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946}
3947
3948static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3949{
Al Viro8687b632006-10-19 23:28:48 -07003950 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 int status = 0;
3952
3953 *res = 0;
3954 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3955 return -EIO;
3956 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003957 p = xdr_inline_decode(xdr, 8);
3958 if (unlikely(!p))
3959 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003960 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3962 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003963 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003965out_overflow:
3966 print_overflow_msg(__func__, xdr);
3967 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968}
3969
3970static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3971{
Al Viro8687b632006-10-19 23:28:48 -07003972 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 int status = 0;
3974
3975 *res = 0;
3976 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3977 return -EIO;
3978 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003979 p = xdr_inline_decode(xdr, 8);
3980 if (unlikely(!p))
3981 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003982 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3984 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003985 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003987out_overflow:
3988 print_overflow_msg(__func__, xdr);
3989 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990}
3991
3992static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3993{
Al Viro8687b632006-10-19 23:28:48 -07003994 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003995 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996
3997 *used = 0;
3998 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3999 return -EIO;
4000 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004001 p = xdr_inline_decode(xdr, 8);
4002 if (unlikely(!p))
4003 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004004 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004006 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004008 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004010 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004011out_overflow:
4012 print_overflow_msg(__func__, xdr);
4013 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014}
4015
4016static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4017{
Al Viro8687b632006-10-19 23:28:48 -07004018 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 uint64_t sec;
4020 uint32_t nsec;
4021
Benny Halevyc0eae662009-08-14 17:20:14 +03004022 p = xdr_inline_decode(xdr, 12);
4023 if (unlikely(!p))
4024 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004025 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004026 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 time->tv_sec = (time_t)sec;
4028 time->tv_nsec = (long)nsec;
4029 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004030out_overflow:
4031 print_overflow_msg(__func__, xdr);
4032 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033}
4034
4035static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4036{
4037 int status = 0;
4038
4039 time->tv_sec = 0;
4040 time->tv_nsec = 0;
4041 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4042 return -EIO;
4043 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4044 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004045 if (status == 0)
4046 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4048 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004049 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 return status;
4051}
4052
4053static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4054{
4055 int status = 0;
4056
4057 time->tv_sec = 0;
4058 time->tv_nsec = 0;
4059 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4060 return -EIO;
4061 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4062 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004063 if (status == 0)
4064 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4066 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004067 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 return status;
4069}
4070
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004071static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4072 struct timespec *time)
4073{
4074 int status = 0;
4075
4076 time->tv_sec = 0;
4077 time->tv_nsec = 0;
4078 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4079 return -EIO;
4080 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4081 status = decode_attr_time(xdr, time);
4082 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4083 }
4084 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4085 (long)time->tv_nsec);
4086 return status;
4087}
4088
David Quigleyaa9c2662013-05-22 12:50:44 -04004089static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4090 struct nfs4_label *label)
4091{
4092 uint32_t pi = 0;
4093 uint32_t lfs = 0;
4094 __u32 len;
4095 __be32 *p;
4096 int status = 0;
4097
4098 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4099 return -EIO;
4100 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4101 p = xdr_inline_decode(xdr, 4);
4102 if (unlikely(!p))
4103 goto out_overflow;
4104 lfs = be32_to_cpup(p++);
4105 p = xdr_inline_decode(xdr, 4);
4106 if (unlikely(!p))
4107 goto out_overflow;
4108 pi = be32_to_cpup(p++);
4109 p = xdr_inline_decode(xdr, 4);
4110 if (unlikely(!p))
4111 goto out_overflow;
4112 len = be32_to_cpup(p++);
4113 p = xdr_inline_decode(xdr, len);
4114 if (unlikely(!p))
4115 goto out_overflow;
4116 if (len < NFS4_MAXLABELLEN) {
4117 if (label) {
4118 memcpy(label->label, p, len);
4119 label->len = len;
4120 label->pi = pi;
4121 label->lfs = lfs;
4122 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4123 }
4124 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4125 } else
4126 printk(KERN_WARNING "%s: label too long (%u)!\n",
4127 __func__, len);
4128 }
4129 if (label && label->label)
4130 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4131 (char *)label->label, label->len, label->pi, label->lfs);
4132 return status;
4133
4134out_overflow:
4135 print_overflow_msg(__func__, xdr);
4136 return -EIO;
4137}
4138
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4140{
4141 int status = 0;
4142
4143 time->tv_sec = 0;
4144 time->tv_nsec = 0;
4145 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4146 return -EIO;
4147 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4148 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004149 if (status == 0)
4150 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4152 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004153 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 return status;
4155}
4156
Trond Myklebust256e48b2012-06-21 11:18:13 -04004157static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158{
4159 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004160 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161
4162 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004163 dprintk("%s: server returned incorrect attribute length: "
4164 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004165 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 attrwords << 2,
4167 (attrwords < nwords) ? '<' : '>',
4168 nwords << 2);
4169 return -EIO;
4170 }
4171 return 0;
4172}
4173
4174static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4175{
Al Viro8687b632006-10-19 23:28:48 -07004176 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177
Benny Halevyc0eae662009-08-14 17:20:14 +03004178 p = xdr_inline_decode(xdr, 20);
4179 if (unlikely(!p))
4180 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004181 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004182 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004183 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004185out_overflow:
4186 print_overflow_msg(__func__, xdr);
4187 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188}
4189
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004190static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191{
Al Viro8687b632006-10-19 23:28:48 -07004192 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 uint32_t supp, acc;
4194 int status;
4195
4196 status = decode_op_hdr(xdr, OP_ACCESS);
4197 if (status)
4198 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004199 p = xdr_inline_decode(xdr, 8);
4200 if (unlikely(!p))
4201 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004202 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004203 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004204 *supported = supp;
4205 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004207out_overflow:
4208 print_overflow_msg(__func__, xdr);
4209 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210}
4211
Benny Halevy07d30432009-08-14 17:19:52 +03004212static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213{
Al Viro8687b632006-10-19 23:28:48 -07004214 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004215
4216 p = xdr_inline_decode(xdr, len);
4217 if (likely(p)) {
4218 memcpy(buf, p, len);
4219 return 0;
4220 }
4221 print_overflow_msg(__func__, xdr);
4222 return -EIO;
4223}
4224
4225static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4226{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004227 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228}
4229
4230static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4231{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 int status;
4233
4234 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004235 if (status != -EIO)
4236 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004237 if (!status)
4238 status = decode_stateid(xdr, &res->stateid);
4239 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240}
4241
Benny Halevydb942bb2009-08-14 17:19:56 +03004242static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4243{
Chuck Levercd937102012-03-02 17:14:31 -05004244 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245}
4246
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004247static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4248{
4249 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4250}
4251
Fred Isaman0b7c0152012-04-20 14:47:39 -04004252static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 int status;
4255
4256 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004257 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004258 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004259 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260}
4261
4262static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4263{
Al Viro8687b632006-10-19 23:28:48 -07004264 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265 uint32_t bmlen;
4266 int status;
4267
4268 status = decode_op_hdr(xdr, OP_CREATE);
4269 if (status)
4270 return status;
4271 if ((status = decode_change_info(xdr, cinfo)))
4272 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004273 p = xdr_inline_decode(xdr, 4);
4274 if (unlikely(!p))
4275 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004276 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004277 p = xdr_inline_decode(xdr, bmlen << 2);
4278 if (likely(p))
4279 return 0;
4280out_overflow:
4281 print_overflow_msg(__func__, xdr);
4282 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283}
4284
4285static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4286{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004287 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004288 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289 int status;
4290
4291 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4292 goto xdr_error;
4293 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4294 goto xdr_error;
4295 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4296 goto xdr_error;
4297 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4298 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004299 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4300 &res->fh_expire_type)) != 0)
4301 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4303 goto xdr_error;
4304 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4305 goto xdr_error;
4306 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4307 goto xdr_error;
4308 status = verify_attr_len(xdr, savep, attrlen);
4309xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004310 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311 return status;
4312}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004313
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4315{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004316 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004317 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004319
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4321 goto xdr_error;
4322 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4323 goto xdr_error;
4324 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4325 goto xdr_error;
4326
4327 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4328 goto xdr_error;
4329 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4330 goto xdr_error;
4331 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4332 goto xdr_error;
4333 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4334 goto xdr_error;
4335 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4336 goto xdr_error;
4337 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4338 goto xdr_error;
4339
4340 status = verify_attr_len(xdr, savep, attrlen);
4341xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004342 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 return status;
4344}
4345
4346static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4347{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004348 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004349 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004351
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4353 goto xdr_error;
4354 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4355 goto xdr_error;
4356 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4357 goto xdr_error;
4358
4359 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4360 goto xdr_error;
4361 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4362 goto xdr_error;
4363
4364 status = verify_attr_len(xdr, savep, attrlen);
4365xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004366 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367 return status;
4368}
4369
Andy Adamson88034c32012-05-23 05:02:34 -04004370static int decode_threshold_hint(struct xdr_stream *xdr,
4371 uint32_t *bitmap,
4372 uint64_t *res,
4373 uint32_t hint_bit)
4374{
4375 __be32 *p;
4376
4377 *res = 0;
4378 if (likely(bitmap[0] & hint_bit)) {
4379 p = xdr_inline_decode(xdr, 8);
4380 if (unlikely(!p))
4381 goto out_overflow;
4382 xdr_decode_hyper(p, res);
4383 }
4384 return 0;
4385out_overflow:
4386 print_overflow_msg(__func__, xdr);
4387 return -EIO;
4388}
4389
4390static int decode_first_threshold_item4(struct xdr_stream *xdr,
4391 struct nfs4_threshold *res)
4392{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004393 __be32 *p;
4394 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004395 uint32_t bitmap[3] = {0,}, attrlen;
4396 int status;
4397
4398 /* layout type */
4399 p = xdr_inline_decode(xdr, 4);
4400 if (unlikely(!p)) {
4401 print_overflow_msg(__func__, xdr);
4402 return -EIO;
4403 }
4404 res->l_type = be32_to_cpup(p);
4405
4406 /* thi_hintset bitmap */
4407 status = decode_attr_bitmap(xdr, bitmap);
4408 if (status < 0)
4409 goto xdr_error;
4410
4411 /* thi_hintlist length */
4412 status = decode_attr_length(xdr, &attrlen, &savep);
4413 if (status < 0)
4414 goto xdr_error;
4415 /* thi_hintlist */
4416 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4417 if (status < 0)
4418 goto xdr_error;
4419 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4420 if (status < 0)
4421 goto xdr_error;
4422 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4423 THRESHOLD_RD_IO);
4424 if (status < 0)
4425 goto xdr_error;
4426 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4427 THRESHOLD_WR_IO);
4428 if (status < 0)
4429 goto xdr_error;
4430
4431 status = verify_attr_len(xdr, savep, attrlen);
4432 res->bm = bitmap[0];
4433
4434 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4435 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4436 res->wr_io_sz);
4437xdr_error:
4438 dprintk("%s ret=%d!\n", __func__, status);
4439 return status;
4440}
4441
4442/*
4443 * Thresholds on pNFS direct I/O vrs MDS I/O
4444 */
4445static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4446 uint32_t *bitmap,
4447 struct nfs4_threshold *res)
4448{
4449 __be32 *p;
4450 int status = 0;
4451 uint32_t num;
4452
4453 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4454 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004455 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004456 /* Did the server return an unrequested attribute? */
4457 if (unlikely(res == NULL))
4458 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004459 p = xdr_inline_decode(xdr, 4);
4460 if (unlikely(!p))
4461 goto out_overflow;
4462 num = be32_to_cpup(p);
4463 if (num == 0)
4464 return 0;
4465 if (num > 1)
4466 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4467 "drivers per filesystem not supported\n",
4468 __func__);
4469
4470 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004471 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004472 }
4473 return status;
4474out_overflow:
4475 print_overflow_msg(__func__, xdr);
4476 return -EIO;
4477}
4478
Bryan Schumakerae42c702010-10-21 16:33:17 -04004479static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4480 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004481 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004482 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483{
Trond Myklebustbca794782009-03-11 14:10:26 -04004484 int status;
4485 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004486 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004487 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004489 status = decode_attr_type(xdr, bitmap, &type);
4490 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004492 fattr->mode = 0;
4493 if (status != 0) {
4494 fattr->mode |= nfs_type2fmt[type];
4495 fattr->valid |= status;
4496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004498 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4499 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004501 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004502
4503 status = decode_attr_size(xdr, bitmap, &fattr->size);
4504 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004506 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004507
4508 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4509 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004511 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004512
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004513 err = 0;
4514 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004515 if (status < 0)
4516 goto xdr_error;
4517
4518 status = decode_attr_filehandle(xdr, bitmap, fh);
4519 if (status < 0)
4520 goto xdr_error;
4521
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004522 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4523 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004525 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004526
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004527 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004528 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004529 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004530 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004531
4532 status = decode_attr_mode(xdr, bitmap, &fmode);
4533 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004535 if (status != 0) {
4536 fattr->mode |= fmode;
4537 fattr->valid |= status;
4538 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004539
4540 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4541 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004542 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004543 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004544
Trond Myklebust6926afd2012-01-07 13:22:46 -05004545 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004546 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004548 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004549
Trond Myklebust6926afd2012-01-07 13:22:46 -05004550 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004551 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004553 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004554
4555 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4556 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004558 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004559
4560 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4561 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004563 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004564
4565 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4566 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004568 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004569
4570 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4571 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004573 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004574
4575 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4576 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004578 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004579
Trond Myklebust28331a42011-04-27 13:47:52 -04004580 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004581 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004582 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004583 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004584
Andy Adamson88034c32012-05-23 05:02:34 -04004585 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4586 if (status < 0)
4587 goto xdr_error;
4588
David Quigleyaa9c2662013-05-22 12:50:44 -04004589 if (label) {
4590 status = decode_attr_security_label(xdr, bitmap, label);
4591 if (status < 0)
4592 goto xdr_error;
4593 fattr->valid |= status;
4594 }
4595
Bryan Schumakerae42c702010-10-21 16:33:17 -04004596xdr_error:
4597 dprintk("%s: xdr returned %d\n", __func__, -status);
4598 return status;
4599}
4600
4601static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004602 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004603 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004604{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004605 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004606 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004607 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004608 int status;
4609
4610 status = decode_op_hdr(xdr, OP_GETATTR);
4611 if (status < 0)
4612 goto xdr_error;
4613
4614 status = decode_attr_bitmap(xdr, bitmap);
4615 if (status < 0)
4616 goto xdr_error;
4617
4618 status = decode_attr_length(xdr, &attrlen, &savep);
4619 if (status < 0)
4620 goto xdr_error;
4621
David Quigleyaa9c2662013-05-22 12:50:44 -04004622 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4623 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004624 if (status < 0)
4625 goto xdr_error;
4626
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004627 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004629 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630 return status;
4631}
4632
David Quigleyaa9c2662013-05-22 12:50:44 -04004633static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4634 struct nfs4_label *label, const struct nfs_server *server)
4635{
4636 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4637}
4638
Bryan Schumakerae42c702010-10-21 16:33:17 -04004639static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004640 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004641{
David Quigleyaa9c2662013-05-22 12:50:44 -04004642 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004643}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644
Andy Adamson504913f2010-10-20 00:17:57 -04004645/*
4646 * Decode potentially multiple layout types. Currently we only support
4647 * one layout driver per file system.
4648 */
4649static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4650 uint32_t *layouttype)
4651{
4652 uint32_t *p;
4653 int num;
4654
4655 p = xdr_inline_decode(xdr, 4);
4656 if (unlikely(!p))
4657 goto out_overflow;
4658 num = be32_to_cpup(p);
4659
4660 /* pNFS is not supported by the underlying file system */
4661 if (num == 0) {
4662 *layouttype = 0;
4663 return 0;
4664 }
4665 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004666 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4667 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004668
4669 /* Decode and set first layout type, move xdr->p past unused types */
4670 p = xdr_inline_decode(xdr, num * 4);
4671 if (unlikely(!p))
4672 goto out_overflow;
4673 *layouttype = be32_to_cpup(p);
4674 return 0;
4675out_overflow:
4676 print_overflow_msg(__func__, xdr);
4677 return -EIO;
4678}
4679
4680/*
4681 * The type of file system exported.
4682 * Note we must ensure that layouttype is set in any non-error case.
4683 */
4684static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4685 uint32_t *layouttype)
4686{
4687 int status = 0;
4688
4689 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4690 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4691 return -EIO;
4692 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4693 status = decode_first_pnfs_layout_type(xdr, layouttype);
4694 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4695 } else
4696 *layouttype = 0;
4697 return status;
4698}
4699
Fred Isamandae100c2011-07-30 20:52:37 -04004700/*
4701 * The prefered block size for layout directed io
4702 */
4703static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4704 uint32_t *res)
4705{
4706 __be32 *p;
4707
4708 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4709 *res = 0;
4710 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4711 p = xdr_inline_decode(xdr, 4);
4712 if (unlikely(!p)) {
4713 print_overflow_msg(__func__, xdr);
4714 return -EIO;
4715 }
4716 *res = be32_to_cpup(p);
4717 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4718 }
4719 return 0;
4720}
4721
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4723{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004724 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004725 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726 int status;
4727
4728 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4729 goto xdr_error;
4730 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4731 goto xdr_error;
4732 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4733 goto xdr_error;
4734
4735 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4736
4737 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4738 goto xdr_error;
4739 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4740 goto xdr_error;
4741 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4742 goto xdr_error;
4743 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4744 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4745 goto xdr_error;
4746 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004747 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4748 if (status != 0)
4749 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004750 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4751 if (status != 0)
4752 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004753 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4754 if (status)
4755 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756
4757 status = verify_attr_len(xdr, savep, attrlen);
4758xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004759 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 return status;
4761}
4762
4763static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4764{
Al Viro8687b632006-10-19 23:28:48 -07004765 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 uint32_t len;
4767 int status;
4768
Trond Myklebust99367812007-07-17 21:52:41 -04004769 /* Zero handle first to allow comparisons */
4770 memset(fh, 0, sizeof(*fh));
4771
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772 status = decode_op_hdr(xdr, OP_GETFH);
4773 if (status)
4774 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775
Benny Halevyc0eae662009-08-14 17:20:14 +03004776 p = xdr_inline_decode(xdr, 4);
4777 if (unlikely(!p))
4778 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004779 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 if (len > NFS4_FHSIZE)
4781 return -EIO;
4782 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004783 p = xdr_inline_decode(xdr, len);
4784 if (unlikely(!p))
4785 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004786 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004788out_overflow:
4789 print_overflow_msg(__func__, xdr);
4790 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791}
4792
4793static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4794{
4795 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004796
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 status = decode_op_hdr(xdr, OP_LINK);
4798 if (status)
4799 return status;
4800 return decode_change_info(xdr, cinfo);
4801}
4802
4803/*
4804 * We create the owner, so we know a proper owner.id length is 4.
4805 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004806static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004808 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004809 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004810 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004812 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004813 if (unlikely(!p))
4814 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004815 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004816 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004817 type = be32_to_cpup(p++); /* 4 byte read */
4818 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004819 fl->fl_start = (loff_t)offset;
4820 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4821 if (length == ~(uint64_t)0)
4822 fl->fl_end = OFFSET_MAX;
4823 fl->fl_type = F_WRLCK;
4824 if (type & 1)
4825 fl->fl_type = F_RDLCK;
4826 fl->fl_pid = 0;
4827 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004828 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4829 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4830 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004831 if (likely(p))
4832 return -NFS4ERR_DENIED;
4833out_overflow:
4834 print_overflow_msg(__func__, xdr);
4835 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836}
4837
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004838static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840 int status;
4841
4842 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004843 if (status == -EIO)
4844 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004846 status = decode_stateid(xdr, &res->stateid);
4847 if (unlikely(status))
4848 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004850 status = decode_lock_denied(xdr, NULL);
4851 if (res->open_seqid != NULL)
4852 nfs_increment_open_seqid(status, res->open_seqid);
4853 nfs_increment_lock_seqid(status, res->lock_seqid);
4854out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 return status;
4856}
4857
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004858static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859{
4860 int status;
4861 status = decode_op_hdr(xdr, OP_LOCKT);
4862 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004863 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864 return status;
4865}
4866
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004867static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869 int status;
4870
4871 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004872 if (status != -EIO)
4873 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004874 if (status == 0)
4875 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876 return status;
4877}
4878
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004879static int decode_release_lockowner(struct xdr_stream *xdr)
4880{
4881 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4882}
4883
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884static int decode_lookup(struct xdr_stream *xdr)
4885{
4886 return decode_op_hdr(xdr, OP_LOOKUP);
4887}
4888
4889/* This is too sick! */
4890static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4891{
Andy Adamson05d564f2008-12-23 16:06:15 -05004892 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893 uint32_t limit_type, nblocks, blocksize;
4894
Benny Halevyc0eae662009-08-14 17:20:14 +03004895 p = xdr_inline_decode(xdr, 12);
4896 if (unlikely(!p))
4897 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004898 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004900 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004901 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004902 break;
4903 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004904 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004905 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004906 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907 }
4908 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004909out_overflow:
4910 print_overflow_msg(__func__, xdr);
4911 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912}
4913
4914static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4915{
Andy Adamson05d564f2008-12-23 16:06:15 -05004916 __be32 *p;
4917 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004918 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919
Benny Halevyc0eae662009-08-14 17:20:14 +03004920 p = xdr_inline_decode(xdr, 4);
4921 if (unlikely(!p))
4922 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004923 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4925 res->delegation_type = 0;
4926 return 0;
4927 }
Benny Halevy07d30432009-08-14 17:19:52 +03004928 status = decode_stateid(xdr, &res->delegation);
4929 if (unlikely(status))
4930 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004931 p = xdr_inline_decode(xdr, 4);
4932 if (unlikely(!p))
4933 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004934 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004935
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004937 case NFS4_OPEN_DELEGATE_READ:
4938 res->delegation_type = FMODE_READ;
4939 break;
4940 case NFS4_OPEN_DELEGATE_WRITE:
4941 res->delegation_type = FMODE_WRITE|FMODE_READ;
4942 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943 return -EIO;
4944 }
David Howells7539bba2006-08-22 20:06:09 -04004945 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004946out_overflow:
4947 print_overflow_msg(__func__, xdr);
4948 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004949}
4950
4951static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4952{
Andy Adamson05d564f2008-12-23 16:06:15 -05004953 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004954 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004955 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004956
Andy Adamson05d564f2008-12-23 16:06:15 -05004957 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004958 if (status != -EIO)
4959 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004960 if (!status)
4961 status = decode_stateid(xdr, &res->stateid);
4962 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004963 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964
Andy Adamson05d564f2008-12-23 16:06:15 -05004965 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966
Benny Halevyc0eae662009-08-14 17:20:14 +03004967 p = xdr_inline_decode(xdr, 8);
4968 if (unlikely(!p))
4969 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004970 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004971 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004972 if (bmlen > 10)
4973 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974
Benny Halevyc0eae662009-08-14 17:20:14 +03004975 p = xdr_inline_decode(xdr, bmlen << 2);
4976 if (unlikely(!p))
4977 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004978 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4979 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004980 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004981 for (; i < NFS4_BITMAP_SIZE; i++)
4982 res->attrset[i] = 0;
4983
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984 return decode_delegation(xdr, res);
4985xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004986 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004988out_overflow:
4989 print_overflow_msg(__func__, xdr);
4990 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991}
4992
4993static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4994{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995 int status;
4996
Andy Adamson05d564f2008-12-23 16:06:15 -05004997 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004998 if (status != -EIO)
4999 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005000 if (!status)
5001 status = decode_stateid(xdr, &res->stateid);
5002 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003}
5004
5005static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5006{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 int status;
5008
5009 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005010 if (status != -EIO)
5011 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005012 if (!status)
5013 status = decode_stateid(xdr, &res->stateid);
5014 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015}
5016
5017static int decode_putfh(struct xdr_stream *xdr)
5018{
5019 return decode_op_hdr(xdr, OP_PUTFH);
5020}
5021
5022static int decode_putrootfh(struct xdr_stream *xdr)
5023{
5024 return decode_op_hdr(xdr, OP_PUTROOTFH);
5025}
5026
5027static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
5028{
Al Viro8687b632006-10-19 23:28:48 -07005029 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005030 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031 int status;
5032
5033 status = decode_op_hdr(xdr, OP_READ);
5034 if (status)
5035 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005036 p = xdr_inline_decode(xdr, 8);
5037 if (unlikely(!p))
5038 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005039 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005040 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005041 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005043 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044 "count %u > recvd %u\n", count, recvd);
5045 count = recvd;
5046 eof = 0;
5047 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048 res->eof = eof;
5049 res->count = count;
5050 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005051out_overflow:
5052 print_overflow_msg(__func__, xdr);
5053 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054}
5055
5056static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5057{
Chuck Leverbcecff72007-10-26 13:32:03 -04005058 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005059 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005060
5061 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005062 if (!status)
5063 status = decode_verifier(xdr, readdir->verifier.data);
5064 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005066 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005067 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005068 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005069 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005070}
5071
5072static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5073{
5074 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005075 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005076 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077 int status;
5078
5079 status = decode_op_hdr(xdr, OP_READLINK);
5080 if (status)
5081 return status;
5082
5083 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005084 p = xdr_inline_decode(xdr, 4);
5085 if (unlikely(!p))
5086 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005087 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005089 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090 return -ENAMETOOLONG;
5091 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005092 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005094 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095 "count %u > recvd %u\n", len, recvd);
5096 return -EIO;
5097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098 /*
5099 * The XDR encode routine has set things up so that
5100 * the link text will be copied directly into the
5101 * buffer. We just have to do overflow-checking,
5102 * and and null-terminate the text (the VFS expects
5103 * null-termination).
5104 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005105 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005107out_overflow:
5108 print_overflow_msg(__func__, xdr);
5109 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005110}
5111
5112static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5113{
5114 int status;
5115
5116 status = decode_op_hdr(xdr, OP_REMOVE);
5117 if (status)
5118 goto out;
5119 status = decode_change_info(xdr, cinfo);
5120out:
5121 return status;
5122}
5123
5124static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5125 struct nfs4_change_info *new_cinfo)
5126{
5127 int status;
5128
5129 status = decode_op_hdr(xdr, OP_RENAME);
5130 if (status)
5131 goto out;
5132 if ((status = decode_change_info(xdr, old_cinfo)))
5133 goto out;
5134 status = decode_change_info(xdr, new_cinfo);
5135out:
5136 return status;
5137}
5138
5139static int decode_renew(struct xdr_stream *xdr)
5140{
5141 return decode_op_hdr(xdr, OP_RENEW);
5142}
5143
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005144static int
5145decode_restorefh(struct xdr_stream *xdr)
5146{
5147 return decode_op_hdr(xdr, OP_RESTOREFH);
5148}
5149
J. Bruce Fields029d1052005-06-22 17:16:22 +00005150static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005151 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005152{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005153 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005154 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005155 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005156 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005157 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005158
Andy Adamsonbf118a32011-12-07 11:55:27 -05005159 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005160 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5161 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005162
Trond Myklebust519d3952012-08-14 17:30:10 -04005163 xdr_enter_page(xdr, xdr->buf->page_len);
5164
Trond Myklebustcff298c2012-08-14 17:14:17 -04005165 /* Calculate the offset of the page data */
5166 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005167
J. Bruce Fields029d1052005-06-22 17:16:22 +00005168 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5169 goto out;
5170 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5171 goto out;
5172
5173 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5174 return -EIO;
5175 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005176
Andy Adamsonbf118a32011-12-07 11:55:27 -05005177 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5178 * are stored with the acl data to handle the problem of
5179 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005180 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005181 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005182
5183 /* Check for receive buffer overflow */
5184 if (res->acl_len > (xdr->nwords << 2) ||
5185 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5186 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005187 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005188 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005189 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005190 } else
5191 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005192
5193out:
5194 return status;
5195}
5196
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197static int
5198decode_savefh(struct xdr_stream *xdr)
5199{
5200 return decode_op_hdr(xdr, OP_SAVEFH);
5201}
5202
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005203static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204{
Al Viro8687b632006-10-19 23:28:48 -07005205 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206 uint32_t bmlen;
5207 int status;
5208
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209 status = decode_op_hdr(xdr, OP_SETATTR);
5210 if (status)
5211 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005212 p = xdr_inline_decode(xdr, 4);
5213 if (unlikely(!p))
5214 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005215 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005216 p = xdr_inline_decode(xdr, bmlen << 2);
5217 if (likely(p))
5218 return 0;
5219out_overflow:
5220 print_overflow_msg(__func__, xdr);
5221 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005222}
5223
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005224static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005225{
Al Viro8687b632006-10-19 23:28:48 -07005226 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227 uint32_t opnum;
5228 int32_t nfserr;
5229
Benny Halevyc0eae662009-08-14 17:20:14 +03005230 p = xdr_inline_decode(xdr, 8);
5231 if (unlikely(!p))
5232 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005233 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005235 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005236 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005237 return -EIO;
5238 }
Benny Halevycccddf42009-08-14 17:20:19 +03005239 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005241 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5242 if (unlikely(!p))
5243 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005244 p = xdr_decode_hyper(p, &res->clientid);
5245 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246 } else if (nfserr == NFSERR_CLID_INUSE) {
5247 uint32_t len;
5248
5249 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005250 p = xdr_inline_decode(xdr, 4);
5251 if (unlikely(!p))
5252 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005253 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005254 p = xdr_inline_decode(xdr, len);
5255 if (unlikely(!p))
5256 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257
5258 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005259 p = xdr_inline_decode(xdr, 4);
5260 if (unlikely(!p))
5261 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005262 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005263 p = xdr_inline_decode(xdr, len);
5264 if (unlikely(!p))
5265 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266 return -NFSERR_CLID_INUSE;
5267 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005268 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269
5270 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005271out_overflow:
5272 print_overflow_msg(__func__, xdr);
5273 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274}
5275
5276static int decode_setclientid_confirm(struct xdr_stream *xdr)
5277{
5278 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5279}
5280
5281static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5282{
Al Viro8687b632006-10-19 23:28:48 -07005283 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284 int status;
5285
5286 status = decode_op_hdr(xdr, OP_WRITE);
5287 if (status)
5288 return status;
5289
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005290 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005291 if (unlikely(!p))
5292 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005293 res->count = be32_to_cpup(p++);
5294 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005295 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005296out_overflow:
5297 print_overflow_msg(__func__, xdr);
5298 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299}
5300
5301static int decode_delegreturn(struct xdr_stream *xdr)
5302{
5303 return decode_op_hdr(xdr, OP_DELEGRETURN);
5304}
5305
Chuck Leverfb15b262013-03-16 15:54:34 -04005306static int decode_secinfo_gss(struct xdr_stream *xdr,
5307 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005308{
Chuck Leverfb15b262013-03-16 15:54:34 -04005309 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005310 __be32 *p;
5311
5312 p = xdr_inline_decode(xdr, 4);
5313 if (unlikely(!p))
5314 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005315 oid_len = be32_to_cpup(p);
5316 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005317 goto out_err;
5318
Chuck Leverfb15b262013-03-16 15:54:34 -04005319 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005320 if (unlikely(!p))
5321 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005322 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5323 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005324
5325 p = xdr_inline_decode(xdr, 8);
5326 if (unlikely(!p))
5327 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005328 flavor->flavor_info.qop = be32_to_cpup(p++);
5329 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005330
5331 return 0;
5332
5333out_overflow:
5334 print_overflow_msg(__func__, xdr);
5335 return -EIO;
5336out_err:
5337 return -EINVAL;
5338}
5339
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005340static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005341{
Chuck Leverfb15b262013-03-16 15:54:34 -04005342 struct nfs4_secinfo4 *sec_flavor;
5343 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005344 int status;
5345 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005346
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005347 p = xdr_inline_decode(xdr, 4);
5348 if (unlikely(!p))
5349 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005350
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005351 res->flavors->num_flavors = 0;
5352 num_flavors = be32_to_cpup(p);
5353
5354 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005355 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005356 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005357 break;
5358
5359 p = xdr_inline_decode(xdr, 4);
5360 if (unlikely(!p))
5361 goto out_overflow;
5362 sec_flavor->flavor = be32_to_cpup(p);
5363
5364 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005365 status = decode_secinfo_gss(xdr, sec_flavor);
5366 if (status)
5367 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005368 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005369 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005370 }
5371
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005372 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005373out:
5374 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005375out_overflow:
5376 print_overflow_msg(__func__, xdr);
5377 return -EIO;
5378}
5379
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005380static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5381{
5382 int status = decode_op_hdr(xdr, OP_SECINFO);
5383 if (status)
5384 return status;
5385 return decode_secinfo_common(xdr, res);
5386}
5387
Benny Halevy99fe60d2009-04-01 09:22:29 -04005388#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005389static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5390{
5391 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5392 if (status)
5393 return status;
5394 return decode_secinfo_common(xdr, res);
5395}
5396
Benny Halevy99fe60d2009-04-01 09:22:29 -04005397static int decode_exchange_id(struct xdr_stream *xdr,
5398 struct nfs41_exchange_id_res *res)
5399{
5400 __be32 *p;
5401 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005402 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005403 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005404 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005405
5406 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5407 if (status)
5408 return status;
5409
Benny Halevyc0eae662009-08-14 17:20:14 +03005410 p = xdr_inline_decode(xdr, 8);
5411 if (unlikely(!p))
5412 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005413 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005414 p = xdr_inline_decode(xdr, 12);
5415 if (unlikely(!p))
5416 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005417 res->seqid = be32_to_cpup(p++);
5418 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005419
5420 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005421 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005422 if (dummy != SP4_NONE)
5423 return -EIO;
5424
Chuck Leveracdeb692012-05-21 22:46:16 -04005425 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005426 p = xdr_inline_decode(xdr, 8);
5427 if (unlikely(!p))
5428 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005429 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005430
Chuck Leveracdeb692012-05-21 22:46:16 -04005431 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005432 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5433 if (unlikely(status))
5434 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005435 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5436 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005437 memcpy(res->server_owner->major_id, dummy_str, dummy);
5438 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005439
Chuck Leveracdeb692012-05-21 22:46:16 -04005440 /* server_scope4 */
5441 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5442 if (unlikely(status))
5443 return status;
5444 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5445 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005446 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5447 res->server_scope->server_scope_sz = dummy;
5448
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005449 /* Implementation Id */
5450 p = xdr_inline_decode(xdr, 4);
5451 if (unlikely(!p))
5452 goto out_overflow;
5453 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005454
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005455 if (impl_id_count) {
5456 /* nii_domain */
5457 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5458 if (unlikely(status))
5459 return status;
5460 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5461 return -EIO;
5462 memcpy(res->impl_id->domain, dummy_str, dummy);
5463
5464 /* nii_name */
5465 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5466 if (unlikely(status))
5467 return status;
5468 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5469 return -EIO;
5470 memcpy(res->impl_id->name, dummy_str, dummy);
5471
5472 /* nii_date */
5473 p = xdr_inline_decode(xdr, 12);
5474 if (unlikely(!p))
5475 goto out_overflow;
5476 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5477 res->impl_id->date.nseconds = be32_to_cpup(p);
5478
5479 /* if there's more than one entry, ignore the rest */
5480 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005481 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005482out_overflow:
5483 print_overflow_msg(__func__, xdr);
5484 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005485}
Andy Adamsonfc931582009-04-01 09:22:31 -04005486
5487static int decode_chan_attrs(struct xdr_stream *xdr,
5488 struct nfs4_channel_attrs *attrs)
5489{
5490 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005491 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005492
Benny Halevyc0eae662009-08-14 17:20:14 +03005493 p = xdr_inline_decode(xdr, 28);
5494 if (unlikely(!p))
5495 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005496 val = be32_to_cpup(p++); /* headerpadsz */
5497 if (val)
5498 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005499 attrs->max_rqst_sz = be32_to_cpup(p++);
5500 attrs->max_resp_sz = be32_to_cpup(p++);
5501 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5502 attrs->max_ops = be32_to_cpup(p++);
5503 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005504 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005505 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005506 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5507 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005508 return -EINVAL;
5509 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005510 if (nr_attrs == 1) {
5511 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5512 if (unlikely(!p))
5513 goto out_overflow;
5514 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005515 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005516out_overflow:
5517 print_overflow_msg(__func__, xdr);
5518 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005519}
5520
Benny Halevye78291e2009-08-14 17:20:00 +03005521static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5522{
5523 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005524}
5525
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005526static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5527 struct nfs41_bind_conn_to_session_res *res)
5528{
5529 __be32 *p;
5530 int status;
5531
5532 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5533 if (!status)
5534 status = decode_sessionid(xdr, &res->session->sess_id);
5535 if (unlikely(status))
5536 return status;
5537
5538 /* dir flags, rdma mode bool */
5539 p = xdr_inline_decode(xdr, 8);
5540 if (unlikely(!p))
5541 goto out_overflow;
5542
5543 res->dir = be32_to_cpup(p++);
5544 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5545 return -EIO;
5546 if (be32_to_cpup(p) == 0)
5547 res->use_conn_in_rdma_mode = false;
5548 else
5549 res->use_conn_in_rdma_mode = true;
5550
5551 return 0;
5552out_overflow:
5553 print_overflow_msg(__func__, xdr);
5554 return -EIO;
5555}
5556
Andy Adamsonfc931582009-04-01 09:22:31 -04005557static int decode_create_session(struct xdr_stream *xdr,
5558 struct nfs41_create_session_res *res)
5559{
5560 __be32 *p;
5561 int status;
5562 struct nfs_client *clp = res->client;
5563 struct nfs4_session *session = clp->cl_session;
5564
5565 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005566 if (!status)
5567 status = decode_sessionid(xdr, &session->sess_id);
5568 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005569 return status;
5570
Andy Adamsonfc931582009-04-01 09:22:31 -04005571 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005572 p = xdr_inline_decode(xdr, 8);
5573 if (unlikely(!p))
5574 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005575 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005576 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005577
5578 /* Channel attributes */
5579 status = decode_chan_attrs(xdr, &session->fc_attrs);
5580 if (!status)
5581 status = decode_chan_attrs(xdr, &session->bc_attrs);
5582 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005583out_overflow:
5584 print_overflow_msg(__func__, xdr);
5585 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005586}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005587
5588static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5589{
5590 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5591}
Ricardo Labiaga18019752009-12-05 16:08:40 -05005592
Trond Myklebust66245532012-05-25 17:18:09 -04005593static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5594{
5595 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5596}
5597
Ricardo Labiaga18019752009-12-05 16:08:40 -05005598static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5599{
5600 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5601}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005602#endif /* CONFIG_NFS_V4_1 */
5603
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005604static int decode_sequence(struct xdr_stream *xdr,
5605 struct nfs4_sequence_res *res,
5606 struct rpc_rqst *rqstp)
5607{
5608#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005609 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005610 struct nfs4_sessionid id;
5611 u32 dummy;
5612 int status;
5613 __be32 *p;
5614
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005615 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005616 return 0;
5617
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005618 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005619 if (!status)
5620 status = decode_sessionid(xdr, &id);
5621 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005622 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005623
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005624 /*
5625 * If the server returns different values for sessionID, slotID or
5626 * sequence number, the server is looney tunes.
5627 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005628 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005629 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005630
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005631 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005632 NFS4_MAX_SESSIONID_LEN)) {
5633 dprintk("%s Invalid session id\n", __func__);
5634 goto out_err;
5635 }
Benny Halevye78291e2009-08-14 17:20:00 +03005636
Benny Halevyc0eae662009-08-14 17:20:14 +03005637 p = xdr_inline_decode(xdr, 20);
5638 if (unlikely(!p))
5639 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005640
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005641 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005642 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005643 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005644 dprintk("%s Invalid sequence number\n", __func__);
5645 goto out_err;
5646 }
5647 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005648 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005649 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005650 dprintk("%s Invalid slot id\n", __func__);
5651 goto out_err;
5652 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005653 /* highest slot id */
5654 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005655 /* target highest slot id */
5656 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005657 /* result flags */
5658 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005659 status = 0;
5660out_err:
5661 res->sr_status = status;
5662 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005663out_overflow:
5664 print_overflow_msg(__func__, xdr);
5665 status = -EIO;
5666 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005667#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005668 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005669#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005670}
5671
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005672#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005673/*
5674 * TODO: Need to handle case when EOF != true;
5675 */
5676static int decode_getdevicelist(struct xdr_stream *xdr,
5677 struct pnfs_devicelist *res)
5678{
5679 __be32 *p;
5680 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005681 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005682
5683 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5684 if (status)
5685 return status;
5686
5687 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5688 if (unlikely(!p))
5689 goto out_overflow;
5690
5691 /* TODO: Skip cookie for now */
5692 p += 2;
5693
5694 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005695 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005696
5697 res->num_devs = be32_to_cpup(p);
5698
5699 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5700
5701 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005702 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005703 __func__, res->num_devs);
5704 return -EIO;
5705 }
5706
5707 p = xdr_inline_decode(xdr,
5708 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5709 if (unlikely(!p))
5710 goto out_overflow;
5711 for (i = 0; i < res->num_devs; i++)
5712 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5713 NFS4_DEVICEID4_SIZE);
5714 res->eof = be32_to_cpup(p);
5715 return 0;
5716out_overflow:
5717 print_overflow_msg(__func__, xdr);
5718 return -EIO;
5719}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005720
5721static int decode_getdeviceinfo(struct xdr_stream *xdr,
5722 struct pnfs_device *pdev)
5723{
5724 __be32 *p;
5725 uint32_t len, type;
5726 int status;
5727
5728 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5729 if (status) {
5730 if (status == -ETOOSMALL) {
5731 p = xdr_inline_decode(xdr, 4);
5732 if (unlikely(!p))
5733 goto out_overflow;
5734 pdev->mincount = be32_to_cpup(p);
5735 dprintk("%s: Min count too small. mincnt = %u\n",
5736 __func__, pdev->mincount);
5737 }
5738 return status;
5739 }
5740
5741 p = xdr_inline_decode(xdr, 8);
5742 if (unlikely(!p))
5743 goto out_overflow;
5744 type = be32_to_cpup(p++);
5745 if (type != pdev->layout_type) {
5746 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5747 __func__, pdev->layout_type, type);
5748 return -EINVAL;
5749 }
5750 /*
5751 * Get the length of the opaque device_addr4. xdr_read_pages places
5752 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5753 * and places the remaining xdr data in xdr_buf->tail
5754 */
5755 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005756 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5757 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005758
5759 /* Parse notification bitmap, verifying that it is zero. */
5760 p = xdr_inline_decode(xdr, 4);
5761 if (unlikely(!p))
5762 goto out_overflow;
5763 len = be32_to_cpup(p);
5764 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005765 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005766
5767 p = xdr_inline_decode(xdr, 4 * len);
5768 if (unlikely(!p))
5769 goto out_overflow;
5770 for (i = 0; i < len; i++, p++) {
5771 if (be32_to_cpup(p)) {
5772 dprintk("%s: notifications not supported\n",
5773 __func__);
5774 return -EIO;
5775 }
5776 }
5777 }
5778 return 0;
5779out_overflow:
5780 print_overflow_msg(__func__, xdr);
5781 return -EIO;
5782}
5783
5784static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5785 struct nfs4_layoutget_res *res)
5786{
5787 __be32 *p;
5788 int status;
5789 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005790 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005791
5792 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5793 if (status)
5794 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005795 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005796 if (unlikely(!p))
5797 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005798 res->return_on_close = be32_to_cpup(p);
5799 decode_stateid(xdr, &res->stateid);
5800 p = xdr_inline_decode(xdr, 4);
5801 if (unlikely(!p))
5802 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005803 layout_count = be32_to_cpup(p);
5804 if (!layout_count) {
5805 dprintk("%s: server responded with empty layout array\n",
5806 __func__);
5807 return -EINVAL;
5808 }
5809
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005810 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005811 if (unlikely(!p))
5812 goto out_overflow;
5813 p = xdr_decode_hyper(p, &res->range.offset);
5814 p = xdr_decode_hyper(p, &res->range.length);
5815 res->range.iomode = be32_to_cpup(p++);
5816 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005817 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005818
5819 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5820 __func__,
5821 (unsigned long)res->range.offset,
5822 (unsigned long)res->range.length,
5823 res->range.iomode,
5824 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005825 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005826
Trond Myklebust64bd5772012-06-20 22:35:05 -04005827 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005828 if (res->layoutp->len > recvd) {
5829 dprintk("NFS: server cheating in layoutget reply: "
5830 "layout len %u > recvd %u\n",
5831 res->layoutp->len, recvd);
5832 return -EINVAL;
5833 }
5834
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005835 if (layout_count > 1) {
5836 /* We only handle a length one array at the moment. Any
5837 * further entries are just ignored. Note that this means
5838 * the client may see a response that is less than the
5839 * minimum it requested.
5840 */
5841 dprintk("%s: server responded with %d layouts, dropping tail\n",
5842 __func__, layout_count);
5843 }
5844
5845 return 0;
5846out_overflow:
5847 print_overflow_msg(__func__, xdr);
5848 return -EIO;
5849}
Andy Adamson863a3c62011-03-23 13:27:54 +00005850
Benny Halevycbe82602011-05-22 19:52:37 +03005851static int decode_layoutreturn(struct xdr_stream *xdr,
5852 struct nfs4_layoutreturn_res *res)
5853{
5854 __be32 *p;
5855 int status;
5856
5857 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5858 if (status)
5859 return status;
5860 p = xdr_inline_decode(xdr, 4);
5861 if (unlikely(!p))
5862 goto out_overflow;
5863 res->lrs_present = be32_to_cpup(p);
5864 if (res->lrs_present)
5865 status = decode_stateid(xdr, &res->stateid);
5866 return status;
5867out_overflow:
5868 print_overflow_msg(__func__, xdr);
5869 return -EIO;
5870}
5871
Andy Adamson863a3c62011-03-23 13:27:54 +00005872static int decode_layoutcommit(struct xdr_stream *xdr,
5873 struct rpc_rqst *req,
5874 struct nfs4_layoutcommit_res *res)
5875{
5876 __be32 *p;
5877 __u32 sizechanged;
5878 int status;
5879
5880 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005881 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005882 if (status)
5883 return status;
5884
5885 p = xdr_inline_decode(xdr, 4);
5886 if (unlikely(!p))
5887 goto out_overflow;
5888 sizechanged = be32_to_cpup(p);
5889
5890 if (sizechanged) {
5891 /* throw away new size */
5892 p = xdr_inline_decode(xdr, 8);
5893 if (unlikely(!p))
5894 goto out_overflow;
5895 }
5896 return 0;
5897out_overflow:
5898 print_overflow_msg(__func__, xdr);
5899 return -EIO;
5900}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005901
5902static int decode_test_stateid(struct xdr_stream *xdr,
5903 struct nfs41_test_stateid_res *res)
5904{
5905 __be32 *p;
5906 int status;
5907 int num_res;
5908
5909 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5910 if (status)
5911 return status;
5912
5913 p = xdr_inline_decode(xdr, 4);
5914 if (unlikely(!p))
5915 goto out_overflow;
5916 num_res = be32_to_cpup(p++);
5917 if (num_res != 1)
5918 goto out;
5919
5920 p = xdr_inline_decode(xdr, 4);
5921 if (unlikely(!p))
5922 goto out_overflow;
5923 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005924
5925 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005926out_overflow:
5927 print_overflow_msg(__func__, xdr);
5928out:
5929 return -EIO;
5930}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005931
5932static int decode_free_stateid(struct xdr_stream *xdr,
5933 struct nfs41_free_stateid_res *res)
5934{
5935 __be32 *p;
5936 int status;
5937
5938 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5939 if (status)
5940 return status;
5941
5942 p = xdr_inline_decode(xdr, 4);
5943 if (unlikely(!p))
5944 goto out_overflow;
5945 res->status = be32_to_cpup(p++);
5946 return res->status;
5947out_overflow:
5948 print_overflow_msg(__func__, xdr);
5949 return -EIO;
5950}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005951#endif /* CONFIG_NFS_V4_1 */
5952
Linus Torvalds1da177e2005-04-16 15:20:36 -07005953/*
Benny Halevy49c25592008-12-23 16:06:16 -05005954 * END OF "GENERIC" DECODE ROUTINES.
5955 */
5956
5957/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005958 * Decode OPEN_DOWNGRADE response
5959 */
Chuck Leverbf269552010-12-14 14:59:29 +00005960static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5961 struct xdr_stream *xdr,
5962 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963{
Andy Adamson05d564f2008-12-23 16:06:15 -05005964 struct compound_hdr hdr;
5965 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966
Chuck Leverbf269552010-12-14 14:59:29 +00005967 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005968 if (status)
5969 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005970 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005971 if (status)
5972 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005973 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005974 if (status)
5975 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005976 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005977 if (status != 0)
5978 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005979 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005980out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005981 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982}
5983
5984/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985 * Decode ACCESS response
5986 */
Chuck Leverbf269552010-12-14 14:59:29 +00005987static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5988 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005990 struct compound_hdr hdr;
5991 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005992
Chuck Leverbf269552010-12-14 14:59:29 +00005993 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005994 if (status)
5995 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005996 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005997 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005998 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005999 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006000 if (status != 0)
6001 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006002 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006003 if (status != 0)
6004 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006005 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006006out:
6007 return status;
6008}
6009
6010/*
6011 * Decode LOOKUP response
6012 */
Chuck Leverbf269552010-12-14 14:59:29 +00006013static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6014 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006016 struct compound_hdr hdr;
6017 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006018
Chuck Leverbf269552010-12-14 14:59:29 +00006019 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006020 if (status)
6021 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006022 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006023 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006024 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006025 status = decode_putfh(xdr);
6026 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006027 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006028 status = decode_lookup(xdr);
6029 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_getfh(xdr, res->fh);
6032 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006034 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006035out:
6036 return status;
6037}
6038
6039/*
6040 * Decode LOOKUP_ROOT response
6041 */
Chuck Leverbf269552010-12-14 14:59:29 +00006042static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6043 struct xdr_stream *xdr,
6044 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006045{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046 struct compound_hdr hdr;
6047 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006048
Chuck Leverbf269552010-12-14 14:59:29 +00006049 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006050 if (status)
6051 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006052 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006053 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006055 status = decode_putrootfh(xdr);
6056 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006057 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006058 status = decode_getfh(xdr, res->fh);
6059 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006060 status = decode_getfattr_label(xdr, res->fattr,
6061 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062out:
6063 return status;
6064}
6065
6066/*
6067 * Decode REMOVE response
6068 */
Chuck Leverbf269552010-12-14 14:59:29 +00006069static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6070 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072 struct compound_hdr hdr;
6073 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006074
Chuck Leverbf269552010-12-14 14:59:29 +00006075 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006076 if (status)
6077 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006078 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006079 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006080 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006081 status = decode_putfh(xdr);
6082 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006083 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006084 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085out:
6086 return status;
6087}
6088
6089/*
6090 * Decode RENAME response
6091 */
Chuck Leverbf269552010-12-14 14:59:29 +00006092static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6093 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095 struct compound_hdr hdr;
6096 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006097
Chuck Leverbf269552010-12-14 14:59:29 +00006098 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006099 if (status)
6100 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006101 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006102 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006104 status = decode_putfh(xdr);
6105 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006107 status = decode_savefh(xdr);
6108 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006110 status = decode_putfh(xdr);
6111 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006112 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006113 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114out:
6115 return status;
6116}
6117
6118/*
6119 * Decode LINK response
6120 */
Chuck Leverbf269552010-12-14 14:59:29 +00006121static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6122 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006124 struct compound_hdr hdr;
6125 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006126
Chuck Leverbf269552010-12-14 14:59:29 +00006127 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006128 if (status)
6129 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006131 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006132 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_putfh(xdr);
6134 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_savefh(xdr);
6137 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_putfh(xdr);
6140 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_link(xdr, &res->cinfo);
6143 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006144 goto out;
6145 /*
6146 * Note order: OP_LINK leaves the directory as the current
6147 * filehandle.
6148 */
Chuck Leverbf269552010-12-14 14:59:29 +00006149 status = decode_restorefh(xdr);
6150 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006151 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006152 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153out:
6154 return status;
6155}
6156
6157/*
6158 * Decode CREATE response
6159 */
Chuck Leverbf269552010-12-14 14:59:29 +00006160static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6161 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163 struct compound_hdr hdr;
6164 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006165
Chuck Leverbf269552010-12-14 14:59:29 +00006166 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006167 if (status)
6168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006170 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006172 status = decode_putfh(xdr);
6173 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006175 status = decode_create(xdr, &res->dir_cinfo);
6176 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006177 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006178 status = decode_getfh(xdr, res->fh);
6179 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006181 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182out:
6183 return status;
6184}
6185
6186/*
6187 * Decode SYMLINK response
6188 */
Chuck Leverbf269552010-12-14 14:59:29 +00006189static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6190 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191{
Chuck Leverbf269552010-12-14 14:59:29 +00006192 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193}
6194
6195/*
6196 * Decode GETATTR response
6197 */
Chuck Leverbf269552010-12-14 14:59:29 +00006198static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6199 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201 struct compound_hdr hdr;
6202 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006203
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205 if (status)
6206 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006207 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006208 if (status)
6209 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006210 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211 if (status)
6212 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006213 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214out:
6215 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216}
6217
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006218/*
6219 * Encode an SETACL request
6220 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006221static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6222 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006223{
Andy Adamson05d564f2008-12-23 16:06:15 -05006224 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006225 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006226 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006227
Chuck Lever9f06c712010-12-14 14:59:18 +00006228 encode_compound_hdr(xdr, req, &hdr);
6229 encode_sequence(xdr, &args->seq_args, &hdr);
6230 encode_putfh(xdr, args->fh, &hdr);
6231 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006232 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006233}
Andy Adamson05d564f2008-12-23 16:06:15 -05006234
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006235/*
6236 * Decode SETACL response
6237 */
6238static int
Chuck Leverbf269552010-12-14 14:59:29 +00006239nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006240 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006241{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006242 struct compound_hdr hdr;
6243 int status;
6244
Chuck Leverbf269552010-12-14 14:59:29 +00006245 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006246 if (status)
6247 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006248 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006249 if (status)
6250 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006251 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006252 if (status)
6253 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006254 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006255out:
6256 return status;
6257}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258
6259/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006260 * Decode GETACL response
6261 */
6262static int
Chuck Leverbf269552010-12-14 14:59:29 +00006263nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006264 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006265{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006266 struct compound_hdr hdr;
6267 int status;
6268
Trond Myklebust331818f2012-02-03 18:30:53 -05006269 if (res->acl_scratch != NULL) {
6270 void *p = page_address(res->acl_scratch);
6271 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6272 }
Chuck Leverbf269552010-12-14 14:59:29 +00006273 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006274 if (status)
6275 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006277 if (status)
6278 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006279 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006280 if (status)
6281 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006282 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006283
6284out:
6285 return status;
6286}
6287
6288/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289 * Decode CLOSE response
6290 */
Chuck Leverbf269552010-12-14 14:59:29 +00006291static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6292 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006293{
Andy Adamson05d564f2008-12-23 16:06:15 -05006294 struct compound_hdr hdr;
6295 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296
Chuck Leverbf269552010-12-14 14:59:29 +00006297 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006298 if (status)
6299 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006300 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006301 if (status)
6302 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006303 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006304 if (status)
6305 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006306 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006307 if (status != 0)
6308 goto out;
6309 /*
6310 * Note: Server may do delete on close for this file
6311 * in which case the getattr call will fail with
6312 * an ESTALE error. Shouldn't be a problem,
6313 * though, since fattr->valid will remain unset.
6314 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006315 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006316out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006317 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318}
6319
6320/*
6321 * Decode OPEN response
6322 */
Chuck Leverbf269552010-12-14 14:59:29 +00006323static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6324 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325{
Andy Adamson05d564f2008-12-23 16:06:15 -05006326 struct compound_hdr hdr;
6327 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328
Chuck Leverbf269552010-12-14 14:59:29 +00006329 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006330 if (status)
6331 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006332 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006333 if (status)
6334 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006335 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006336 if (status)
6337 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006338 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006339 if (status)
6340 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006341 status = decode_getfh(xdr, &res->fh);
6342 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006343 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006344 if (res->access_request)
6345 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006346 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006347out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006348 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349}
6350
6351/*
6352 * Decode OPEN_CONFIRM response
6353 */
Chuck Leverbf269552010-12-14 14:59:29 +00006354static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6355 struct xdr_stream *xdr,
6356 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357{
Andy Adamson05d564f2008-12-23 16:06:15 -05006358 struct compound_hdr hdr;
6359 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006360
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006362 if (status)
6363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006365 if (status)
6366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006369 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006370}
6371
6372/*
6373 * Decode OPEN response
6374 */
Chuck Leverbf269552010-12-14 14:59:29 +00006375static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6376 struct xdr_stream *xdr,
6377 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378{
Andy Adamson05d564f2008-12-23 16:06:15 -05006379 struct compound_hdr hdr;
6380 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381
Chuck Leverbf269552010-12-14 14:59:29 +00006382 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006383 if (status)
6384 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006386 if (status)
6387 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006388 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006389 if (status)
6390 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006391 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006392 if (status)
6393 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006394 if (res->access_request)
6395 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006396 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006397out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006398 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006399}
6400
6401/*
6402 * Decode SETATTR response
6403 */
Chuck Leverbf269552010-12-14 14:59:29 +00006404static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6405 struct xdr_stream *xdr,
6406 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407{
Andy Adamson05d564f2008-12-23 16:06:15 -05006408 struct compound_hdr hdr;
6409 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006410
Chuck Leverbf269552010-12-14 14:59:29 +00006411 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006412 if (status)
6413 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006414 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006415 if (status)
6416 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006417 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006418 if (status)
6419 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006420 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006421 if (status)
6422 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006423 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006424out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006425 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426}
6427
6428/*
6429 * Decode LOCK response
6430 */
Chuck Leverbf269552010-12-14 14:59:29 +00006431static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6432 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006434 struct compound_hdr hdr;
6435 int status;
6436
Chuck Leverbf269552010-12-14 14:59:29 +00006437 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438 if (status)
6439 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006440 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006441 if (status)
6442 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 if (status)
6445 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006446 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006447out:
6448 return status;
6449}
6450
6451/*
6452 * Decode LOCKT response
6453 */
Chuck Leverbf269552010-12-14 14:59:29 +00006454static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6455 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457 struct compound_hdr hdr;
6458 int status;
6459
Chuck Leverbf269552010-12-14 14:59:29 +00006460 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461 if (status)
6462 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006463 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006464 if (status)
6465 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006466 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467 if (status)
6468 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006469 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470out:
6471 return status;
6472}
6473
6474/*
6475 * Decode LOCKU response
6476 */
Chuck Leverbf269552010-12-14 14:59:29 +00006477static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6478 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480 struct compound_hdr hdr;
6481 int status;
6482
Chuck Leverbf269552010-12-14 14:59:29 +00006483 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484 if (status)
6485 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006487 if (status)
6488 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006489 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490 if (status)
6491 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493out:
6494 return status;
6495}
6496
Chuck Leverbf269552010-12-14 14:59:29 +00006497static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6498 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006499{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006500 struct compound_hdr hdr;
6501 int status;
6502
Chuck Leverbf269552010-12-14 14:59:29 +00006503 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006504 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006505 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006506 return status;
6507}
6508
Linus Torvalds1da177e2005-04-16 15:20:36 -07006509/*
6510 * Decode READLINK response
6511 */
Chuck Leverbf269552010-12-14 14:59:29 +00006512static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6513 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006514 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006515{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516 struct compound_hdr hdr;
6517 int status;
6518
Chuck Leverbf269552010-12-14 14:59:29 +00006519 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520 if (status)
6521 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006522 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006523 if (status)
6524 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006525 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526 if (status)
6527 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006528 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529out:
6530 return status;
6531}
6532
6533/*
6534 * Decode READDIR response
6535 */
Chuck Leverbf269552010-12-14 14:59:29 +00006536static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6537 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006538{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539 struct compound_hdr hdr;
6540 int status;
6541
Chuck Leverbf269552010-12-14 14:59:29 +00006542 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543 if (status)
6544 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006545 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006546 if (status)
6547 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006548 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006549 if (status)
6550 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552out:
6553 return status;
6554}
6555
6556/*
6557 * Decode Read response
6558 */
Chuck Leverbf269552010-12-14 14:59:29 +00006559static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6560 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006561{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562 struct compound_hdr hdr;
6563 int status;
6564
Chuck Leverbf269552010-12-14 14:59:29 +00006565 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566 if (status)
6567 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006568 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006569 if (status)
6570 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006571 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572 if (status)
6573 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006574 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575 if (!status)
6576 status = res->count;
6577out:
6578 return status;
6579}
6580
6581/*
6582 * Decode WRITE response
6583 */
Chuck Leverbf269552010-12-14 14:59:29 +00006584static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6585 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006586{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006587 struct compound_hdr hdr;
6588 int status;
6589
Chuck Leverbf269552010-12-14 14:59:29 +00006590 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006591 if (status)
6592 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006593 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006594 if (status)
6595 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006596 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597 if (status)
6598 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006599 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006600 if (status)
6601 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006602 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006603 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604 if (!status)
6605 status = res->count;
6606out:
6607 return status;
6608}
6609
6610/*
6611 * Decode COMMIT response
6612 */
Chuck Leverbf269552010-12-14 14:59:29 +00006613static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006614 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616 struct compound_hdr hdr;
6617 int status;
6618
Chuck Leverbf269552010-12-14 14:59:29 +00006619 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620 if (status)
6621 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006622 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006623 if (status)
6624 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006625 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006626 if (status)
6627 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006628 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629out:
6630 return status;
6631}
6632
6633/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006634 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006635 */
Chuck Leverbf269552010-12-14 14:59:29 +00006636static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006637 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639 struct compound_hdr hdr;
6640 int status;
6641
Chuck Leverbf269552010-12-14 14:59:29 +00006642 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006644 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006645 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006646 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006648 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649 return status;
6650}
6651
6652/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006653 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006654 */
Chuck Leverbf269552010-12-14 14:59:29 +00006655static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006656 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006657{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006658 struct compound_hdr hdr;
6659 int status;
6660
Chuck Leverbf269552010-12-14 14:59:29 +00006661 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006662 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006663 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006664 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006665 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006668 return status;
6669}
6670
6671/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006672 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006673 */
Chuck Leverbf269552010-12-14 14:59:29 +00006674static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006675 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006676{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677 struct compound_hdr hdr;
6678 int status;
6679
Chuck Leverbf269552010-12-14 14:59:29 +00006680 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006681 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006682 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006683 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006684 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006685 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006686 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006687 return status;
6688}
6689
6690/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006691 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006692 */
Chuck Leverbf269552010-12-14 14:59:29 +00006693static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6694 struct xdr_stream *xdr,
6695 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006697 struct compound_hdr hdr;
6698 int status;
6699
Chuck Leverbf269552010-12-14 14:59:29 +00006700 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006701 if (status)
6702 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006703 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006704 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006705 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006706 status = decode_putfh(xdr);
6707 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006708 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006709 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006710out:
6711 return status;
6712}
6713
6714/*
6715 * Decode RENEW response
6716 */
Chuck Leverbf269552010-12-14 14:59:29 +00006717static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6718 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006719{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006720 struct compound_hdr hdr;
6721 int status;
6722
Chuck Leverbf269552010-12-14 14:59:29 +00006723 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006725 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726 return status;
6727}
6728
6729/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006730 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006731 */
Chuck Leverbf269552010-12-14 14:59:29 +00006732static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6733 struct xdr_stream *xdr,
6734 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006735{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 struct compound_hdr hdr;
6737 int status;
6738
Chuck Leverbf269552010-12-14 14:59:29 +00006739 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006740 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006741 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742 return status;
6743}
6744
6745/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006746 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006747 */
Chuck Leverbf269552010-12-14 14:59:29 +00006748static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006749 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006750{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006751 struct compound_hdr hdr;
6752 int status;
6753
Chuck Leverbf269552010-12-14 14:59:29 +00006754 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006755 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006756 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 return status;
6758}
6759
6760/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006761 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006762 */
Chuck Leverbf269552010-12-14 14:59:29 +00006763static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6764 struct xdr_stream *xdr,
6765 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006767 struct compound_hdr hdr;
6768 int status;
6769
Chuck Leverbf269552010-12-14 14:59:29 +00006770 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006771 if (status)
6772 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006773 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006774 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006775 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006776 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006777 if (status != 0)
6778 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006779 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006780 if (status != 0)
6781 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006782 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006783out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006784 return status;
6785}
6786
Trond Myklebust683b57b2006-06-09 09:34:22 -04006787/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006788 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006789 */
Chuck Leverbf269552010-12-14 14:59:29 +00006790static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6791 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006792 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006793{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006794 struct compound_hdr hdr;
6795 int status;
6796
Chuck Leverbf269552010-12-14 14:59:29 +00006797 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006798 if (status)
6799 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006800 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006801 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006802 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006803 status = decode_putfh(xdr);
6804 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006805 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006806 status = decode_lookup(xdr);
6807 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006808 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006809 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006810 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6811 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006812 NULL, res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006813out:
6814 return status;
6815}
6816
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006817/*
6818 * Decode SECINFO response
6819 */
6820static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6821 struct xdr_stream *xdr,
6822 struct nfs4_secinfo_res *res)
6823{
6824 struct compound_hdr hdr;
6825 int status;
6826
6827 status = decode_compound_hdr(xdr, &hdr);
6828 if (status)
6829 goto out;
6830 status = decode_sequence(xdr, &res->seq_res, rqstp);
6831 if (status)
6832 goto out;
6833 status = decode_putfh(xdr);
6834 if (status)
6835 goto out;
6836 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006837out:
6838 return status;
6839}
6840
Benny Halevy99fe60d2009-04-01 09:22:29 -04006841#if defined(CONFIG_NFS_V4_1)
6842/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006843 * Decode BIND_CONN_TO_SESSION response
6844 */
6845static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6846 struct xdr_stream *xdr,
6847 void *res)
6848{
6849 struct compound_hdr hdr;
6850 int status;
6851
6852 status = decode_compound_hdr(xdr, &hdr);
6853 if (!status)
6854 status = decode_bind_conn_to_session(xdr, res);
6855 return status;
6856}
6857
6858/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006859 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006860 */
Chuck Leverbf269552010-12-14 14:59:29 +00006861static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6862 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006863 void *res)
6864{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006865 struct compound_hdr hdr;
6866 int status;
6867
Chuck Leverbf269552010-12-14 14:59:29 +00006868 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006869 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006870 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006871 return status;
6872}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006873
6874/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006875 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006876 */
Chuck Leverbf269552010-12-14 14:59:29 +00006877static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6878 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006879 struct nfs41_create_session_res *res)
6880{
Andy Adamsonfc931582009-04-01 09:22:31 -04006881 struct compound_hdr hdr;
6882 int status;
6883
Chuck Leverbf269552010-12-14 14:59:29 +00006884 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006885 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006886 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006887 return status;
6888}
6889
6890/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006891 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006892 */
Chuck Leverbf269552010-12-14 14:59:29 +00006893static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6894 struct xdr_stream *xdr,
6895 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006896{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006897 struct compound_hdr hdr;
6898 int status;
6899
Chuck Leverbf269552010-12-14 14:59:29 +00006900 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006901 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006902 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006903 return status;
6904}
6905
6906/*
Trond Myklebust66245532012-05-25 17:18:09 -04006907 * Decode DESTROY_CLIENTID response
6908 */
6909static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6910 struct xdr_stream *xdr,
6911 void *res)
6912{
6913 struct compound_hdr hdr;
6914 int status;
6915
6916 status = decode_compound_hdr(xdr, &hdr);
6917 if (!status)
6918 status = decode_destroy_clientid(xdr, res);
6919 return status;
6920}
6921
6922/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006923 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006924 */
Chuck Leverbf269552010-12-14 14:59:29 +00006925static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6926 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006927 struct nfs4_sequence_res *res)
6928{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006929 struct compound_hdr hdr;
6930 int status;
6931
Chuck Leverbf269552010-12-14 14:59:29 +00006932 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006933 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006934 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006935 return status;
6936}
6937
6938/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006939 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006940 */
Chuck Leverbf269552010-12-14 14:59:29 +00006941static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6942 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006943 struct nfs4_get_lease_time_res *res)
6944{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006945 struct compound_hdr hdr;
6946 int status;
6947
Chuck Leverbf269552010-12-14 14:59:29 +00006948 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006949 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006950 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006951 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006952 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006953 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006954 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006955 return status;
6956}
Ricardo Labiaga18019752009-12-05 16:08:40 -05006957
6958/*
6959 * Decode RECLAIM_COMPLETE response
6960 */
Chuck Leverbf269552010-12-14 14:59:29 +00006961static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6962 struct xdr_stream *xdr,
Ricardo Labiaga18019752009-12-05 16:08:40 -05006963 struct nfs41_reclaim_complete_res *res)
6964{
Ricardo Labiaga18019752009-12-05 16:08:40 -05006965 struct compound_hdr hdr;
6966 int status;
6967
Chuck Leverbf269552010-12-14 14:59:29 +00006968 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006969 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006970 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006971 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006972 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006973 return status;
6974}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006975
6976/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006977 * Decode GETDEVICELIST response
6978 */
6979static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6980 struct xdr_stream *xdr,
6981 struct nfs4_getdevicelist_res *res)
6982{
6983 struct compound_hdr hdr;
6984 int status;
6985
6986 dprintk("encoding getdevicelist!\n");
6987
6988 status = decode_compound_hdr(xdr, &hdr);
6989 if (status != 0)
6990 goto out;
6991 status = decode_sequence(xdr, &res->seq_res, rqstp);
6992 if (status != 0)
6993 goto out;
6994 status = decode_putfh(xdr);
6995 if (status != 0)
6996 goto out;
6997 status = decode_getdevicelist(xdr, res->devlist);
6998out:
6999 return status;
7000}
7001
7002/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007003 * Decode GETDEVINFO response
7004 */
Chuck Leverbf269552010-12-14 14:59:29 +00007005static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7006 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007007 struct nfs4_getdeviceinfo_res *res)
7008{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007009 struct compound_hdr hdr;
7010 int status;
7011
Chuck Leverbf269552010-12-14 14:59:29 +00007012 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007013 if (status != 0)
7014 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007015 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007016 if (status != 0)
7017 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007018 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007019out:
7020 return status;
7021}
7022
7023/*
7024 * Decode LAYOUTGET response
7025 */
Chuck Leverbf269552010-12-14 14:59:29 +00007026static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7027 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007028 struct nfs4_layoutget_res *res)
7029{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007030 struct compound_hdr hdr;
7031 int status;
7032
Chuck Leverbf269552010-12-14 14:59:29 +00007033 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007034 if (status)
7035 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007036 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007037 if (status)
7038 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007039 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007040 if (status)
7041 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007042 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007043out:
7044 return status;
7045}
Andy Adamson863a3c62011-03-23 13:27:54 +00007046
7047/*
Benny Halevycbe82602011-05-22 19:52:37 +03007048 * Decode LAYOUTRETURN response
7049 */
7050static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7051 struct xdr_stream *xdr,
7052 struct nfs4_layoutreturn_res *res)
7053{
7054 struct compound_hdr hdr;
7055 int status;
7056
7057 status = decode_compound_hdr(xdr, &hdr);
7058 if (status)
7059 goto out;
7060 status = decode_sequence(xdr, &res->seq_res, rqstp);
7061 if (status)
7062 goto out;
7063 status = decode_putfh(xdr);
7064 if (status)
7065 goto out;
7066 status = decode_layoutreturn(xdr, res);
7067out:
7068 return status;
7069}
7070
7071/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007072 * Decode LAYOUTCOMMIT response
7073 */
7074static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7075 struct xdr_stream *xdr,
7076 struct nfs4_layoutcommit_res *res)
7077{
7078 struct compound_hdr hdr;
7079 int status;
7080
7081 status = decode_compound_hdr(xdr, &hdr);
7082 if (status)
7083 goto out;
7084 status = decode_sequence(xdr, &res->seq_res, rqstp);
7085 if (status)
7086 goto out;
7087 status = decode_putfh(xdr);
7088 if (status)
7089 goto out;
7090 status = decode_layoutcommit(xdr, rqstp, res);
7091 if (status)
7092 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007093 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007094out:
7095 return status;
7096}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007097
7098/*
7099 * Decode SECINFO_NO_NAME response
7100 */
7101static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7102 struct xdr_stream *xdr,
7103 struct nfs4_secinfo_res *res)
7104{
7105 struct compound_hdr hdr;
7106 int status;
7107
7108 status = decode_compound_hdr(xdr, &hdr);
7109 if (status)
7110 goto out;
7111 status = decode_sequence(xdr, &res->seq_res, rqstp);
7112 if (status)
7113 goto out;
7114 status = decode_putrootfh(xdr);
7115 if (status)
7116 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007117 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007118out:
7119 return status;
7120}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007121
7122/*
7123 * Decode TEST_STATEID response
7124 */
7125static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7126 struct xdr_stream *xdr,
7127 struct nfs41_test_stateid_res *res)
7128{
7129 struct compound_hdr hdr;
7130 int status;
7131
7132 status = decode_compound_hdr(xdr, &hdr);
7133 if (status)
7134 goto out;
7135 status = decode_sequence(xdr, &res->seq_res, rqstp);
7136 if (status)
7137 goto out;
7138 status = decode_test_stateid(xdr, res);
7139out:
7140 return status;
7141}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007142
7143/*
7144 * Decode FREE_STATEID response
7145 */
7146static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7147 struct xdr_stream *xdr,
7148 struct nfs41_free_stateid_res *res)
7149{
7150 struct compound_hdr hdr;
7151 int status;
7152
7153 status = decode_compound_hdr(xdr, &hdr);
7154 if (status)
7155 goto out;
7156 status = decode_sequence(xdr, &res->seq_res, rqstp);
7157 if (status)
7158 goto out;
7159 status = decode_free_stateid(xdr, res);
7160out:
7161 return status;
7162}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007163#endif /* CONFIG_NFS_V4_1 */
7164
Chuck Lever573c4e12010-12-14 14:58:11 +00007165/**
7166 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7167 * the local page cache.
7168 * @xdr: XDR stream where entry resides
7169 * @entry: buffer to fill in with entry data
7170 * @plus: boolean indicating whether this should be a readdirplus entry
7171 *
7172 * Returns zero if successful, otherwise a negative errno value is
7173 * returned.
7174 *
7175 * This function is not invoked during READDIR reply decoding, but
7176 * rather whenever an application invokes the getdents(2) system call
7177 * on a directory already in our cache.
7178 */
7179int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7180 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007181{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007182 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007183 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007184 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007185 __be32 *p = xdr_inline_decode(xdr, 4);
7186 if (unlikely(!p))
7187 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007188 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007189 p = xdr_inline_decode(xdr, 4);
7190 if (unlikely(!p))
7191 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007192 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007193 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007194 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007195 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007196 }
7197
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007198 p = xdr_inline_decode(xdr, 12);
7199 if (unlikely(!p))
7200 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007201 entry->prev_cookie = entry->cookie;
7202 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007203 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007204
Trond Myklebust9af8c222010-10-24 11:52:55 -04007205 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007206 if (unlikely(!p))
7207 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007208 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007209
7210 /*
7211 * In case the server doesn't return an inode number,
7212 * we fake one here. (We don't use inode number 0,
7213 * since glibc seems to choke on it...)
7214 */
7215 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007216 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007217
Trond Myklebust9af8c222010-10-24 11:52:55 -04007218 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007219 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007220
Trond Myklebust256e48b2012-06-21 11:18:13 -04007221 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007222 goto out_overflow;
7223
Chuck Lever573c4e12010-12-14 14:58:11 +00007224 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007225 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007226 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007227 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7228 entry->ino = entry->fattr->mounted_on_fileid;
7229 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007230 entry->ino = entry->fattr->fileid;
7231
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007232 entry->d_type = DT_UNKNOWN;
7233 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7234 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7235
Chuck Lever573c4e12010-12-14 14:58:11 +00007236 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007237
7238out_overflow:
7239 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007240 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007241}
7242
7243/*
7244 * We need to translate between nfs status return values and
7245 * the local errno values which may not be the same.
7246 */
7247static struct {
7248 int stat;
7249 int errno;
7250} nfs_errtbl[] = {
7251 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007252 { NFS4ERR_PERM, -EPERM },
7253 { NFS4ERR_NOENT, -ENOENT },
7254 { NFS4ERR_IO, -errno_NFSERR_IO},
7255 { NFS4ERR_NXIO, -ENXIO },
7256 { NFS4ERR_ACCESS, -EACCES },
7257 { NFS4ERR_EXIST, -EEXIST },
7258 { NFS4ERR_XDEV, -EXDEV },
7259 { NFS4ERR_NOTDIR, -ENOTDIR },
7260 { NFS4ERR_ISDIR, -EISDIR },
7261 { NFS4ERR_INVAL, -EINVAL },
7262 { NFS4ERR_FBIG, -EFBIG },
7263 { NFS4ERR_NOSPC, -ENOSPC },
7264 { NFS4ERR_ROFS, -EROFS },
7265 { NFS4ERR_MLINK, -EMLINK },
7266 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7267 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7268 { NFS4ERR_DQUOT, -EDQUOT },
7269 { NFS4ERR_STALE, -ESTALE },
7270 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007271 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7272 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7273 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007274 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007275 { NFS4ERR_BADTYPE, -EBADTYPE },
7276 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007277 { NFS4ERR_SYMLINK, -ELOOP },
7278 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7279 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007280 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007281};
7282
7283/*
7284 * Convert an NFS error code to a local one.
7285 * This one is used jointly by NFSv2 and NFSv3.
7286 */
7287static int
David Howells0a8ea432006-08-22 20:06:08 -04007288nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007289{
7290 int i;
7291 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7292 if (nfs_errtbl[i].stat == stat)
7293 return nfs_errtbl[i].errno;
7294 }
7295 if (stat <= 10000 || stat > 10100) {
7296 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007297 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007298 }
7299 /* If we cannot translate the error, the recovery routines should
7300 * handle it.
7301 * Note: remaining NFSv4 error codes have values > 10000, so should
7302 * not conflict with native Linux error codes.
7303 */
Benny Halevy856dff32008-03-31 17:39:06 +03007304 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007305}
7306
Linus Torvalds1da177e2005-04-16 15:20:36 -07007307#define PROC(proc, argtype, restype) \
7308[NFSPROC4_CLNT_##proc] = { \
7309 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007310 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007311 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007312 .p_arglen = NFS4_##argtype##_sz, \
7313 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007314 .p_statidx = NFSPROC4_CLNT_##proc, \
7315 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007316}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007317
7318struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007319 PROC(READ, enc_read, dec_read),
7320 PROC(WRITE, enc_write, dec_write),
7321 PROC(COMMIT, enc_commit, dec_commit),
7322 PROC(OPEN, enc_open, dec_open),
7323 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7324 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7325 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7326 PROC(CLOSE, enc_close, dec_close),
7327 PROC(SETATTR, enc_setattr, dec_setattr),
7328 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7329 PROC(RENEW, enc_renew, dec_renew),
7330 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7331 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7332 PROC(LOCK, enc_lock, dec_lock),
7333 PROC(LOCKT, enc_lockt, dec_lockt),
7334 PROC(LOCKU, enc_locku, dec_locku),
7335 PROC(ACCESS, enc_access, dec_access),
7336 PROC(GETATTR, enc_getattr, dec_getattr),
7337 PROC(LOOKUP, enc_lookup, dec_lookup),
7338 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7339 PROC(REMOVE, enc_remove, dec_remove),
7340 PROC(RENAME, enc_rename, dec_rename),
7341 PROC(LINK, enc_link, dec_link),
7342 PROC(SYMLINK, enc_symlink, dec_symlink),
7343 PROC(CREATE, enc_create, dec_create),
7344 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7345 PROC(STATFS, enc_statfs, dec_statfs),
7346 PROC(READLINK, enc_readlink, dec_readlink),
7347 PROC(READDIR, enc_readdir, dec_readdir),
7348 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7349 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7350 PROC(GETACL, enc_getacl, dec_getacl),
7351 PROC(SETACL, enc_setacl, dec_setacl),
7352 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7353 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007354 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007355#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007356 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7357 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7358 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7359 PROC(SEQUENCE, enc_sequence, dec_sequence),
7360 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7361 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7362 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7363 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007364 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007365 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007366 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007367 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007368 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007369 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007370 PROC(BIND_CONN_TO_SESSION,
7371 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007372 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007373#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007374};
7375
Trond Myklebusta613fa12012-01-20 13:53:56 -05007376const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007377 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007378 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007379 .procs = nfs4_procedures
7380};
7381
7382/*
7383 * Local variables:
7384 * c-basic-offset: 8
7385 * End:
7386 */