blob: b8165eab0a322e427cf096ca3f5fbeeb821b2904 [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))
David Quigleyaa9c2662013-05-22 12:50:44 -0400108#else
109#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400110#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400111/* We support only one layout type per file system */
112#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000113/* This is based on getfattr, which uses the most attributes: */
114#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400115 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400116 nfs4_group_maxsz + nfs4_label_maxsz + \
117 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000118#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
119 nfs4_fattr_value_maxsz)
120#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400121#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
122 1 + 2 + 1 + \
123 nfs4_owner_maxsz + \
124 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400125 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400126 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define encode_savefh_maxsz (op_encode_hdr_maxsz)
128#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400129#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
130#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200131#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400132/* The 5 accounts for the PNFS attributes, and assumes that at most three
133 * layout types will be returned.
134 */
135#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
136 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
138#define decode_renew_maxsz (op_decode_hdr_maxsz)
139#define encode_setclientid_maxsz \
140 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500141 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
142 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
143 1 /* sc_prog */ + \
144 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
145 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
146 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#define decode_setclientid_maxsz \
148 (op_decode_hdr_maxsz + \
149 2 + \
150 1024) /* large value for CLID_INUSE */
151#define encode_setclientid_confirm_maxsz \
152 (op_encode_hdr_maxsz + \
153 3 + (NFS4_VERIFIER_SIZE >> 2))
154#define decode_setclientid_confirm_maxsz \
155 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400156#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
157#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400158#define encode_share_access_maxsz \
159 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500160#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400161#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
162#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
163#define encode_open_maxsz (op_encode_hdr_maxsz + \
164 2 + encode_share_access_maxsz + 2 + \
165 open_owner_id_maxsz + \
166 encode_opentype_maxsz + \
167 encode_claim_null_maxsz)
168#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400169#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400170 decode_ace_maxsz)
171#define decode_change_info_maxsz (5)
172#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400173 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400174 decode_change_info_maxsz + 1 + \
175 nfs4_fattr_bitmap_maxsz + \
176 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400177#define encode_open_confirm_maxsz \
178 (op_encode_hdr_maxsz + \
179 encode_stateid_maxsz + 1)
180#define decode_open_confirm_maxsz \
181 (op_decode_hdr_maxsz + \
182 decode_stateid_maxsz)
183#define encode_open_downgrade_maxsz \
184 (op_encode_hdr_maxsz + \
185 encode_stateid_maxsz + 1 + \
186 encode_share_access_maxsz)
187#define decode_open_downgrade_maxsz \
188 (op_decode_hdr_maxsz + \
189 decode_stateid_maxsz)
190#define encode_close_maxsz (op_encode_hdr_maxsz + \
191 1 + encode_stateid_maxsz)
192#define decode_close_maxsz (op_decode_hdr_maxsz + \
193 decode_stateid_maxsz)
194#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + \
196 encode_attrs_maxsz)
197#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
198 nfs4_fattr_bitmap_maxsz)
199#define encode_read_maxsz (op_encode_hdr_maxsz + \
200 encode_stateid_maxsz + 3)
201#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
202#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400203 2 + encode_verifier_maxsz + 5 + \
204 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400205#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400206 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400207#define encode_readlink_maxsz (op_encode_hdr_maxsz)
208#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
209#define encode_write_maxsz (op_encode_hdr_maxsz + \
210 encode_stateid_maxsz + 4)
211#define decode_write_maxsz (op_decode_hdr_maxsz + \
212 2 + decode_verifier_maxsz)
213#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
214#define decode_commit_maxsz (op_decode_hdr_maxsz + \
215 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#define encode_remove_maxsz (op_encode_hdr_maxsz + \
217 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400218#define decode_remove_maxsz (op_decode_hdr_maxsz + \
219 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#define encode_rename_maxsz (op_encode_hdr_maxsz + \
221 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400222#define decode_rename_maxsz (op_decode_hdr_maxsz + \
223 decode_change_info_maxsz + \
224 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#define encode_link_maxsz (op_encode_hdr_maxsz + \
226 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400227#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400228#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400229#define encode_lock_maxsz (op_encode_hdr_maxsz + \
230 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400231 1 + encode_stateid_maxsz + 1 + \
232 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400233#define decode_lock_denied_maxsz \
234 (8 + decode_lockowner_maxsz)
235#define decode_lock_maxsz (op_decode_hdr_maxsz + \
236 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400237#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
238 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400239#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
240 decode_lock_denied_maxsz)
241#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
242 encode_stateid_maxsz + \
243 4)
244#define decode_locku_maxsz (op_decode_hdr_maxsz + \
245 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400246#define encode_release_lockowner_maxsz \
247 (op_encode_hdr_maxsz + \
248 encode_lockowner_maxsz)
249#define decode_release_lockowner_maxsz \
250 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400251#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
252#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
254 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400255 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000256 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
258#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400259 1 + 2 + nfs4_name_maxsz + \
260 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400261#define decode_create_maxsz (op_decode_hdr_maxsz + \
262 decode_change_info_maxsz + \
263 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400264#define encode_statfs_maxsz (encode_getattr_maxsz)
265#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
267#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400268#define encode_getacl_maxsz (encode_getattr_maxsz)
269#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
270 nfs4_fattr_bitmap_maxsz + 1)
271#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
272 encode_stateid_maxsz + 3)
273#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400274#define encode_fs_locations_maxsz \
275 (encode_getattr_maxsz)
276#define decode_fs_locations_maxsz \
277 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000278#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400279#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 -0400280
281#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400282#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500283#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
284 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400285
Benny Halevy99fe60d2009-04-01 09:22:29 -0400286#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
287 encode_verifier_maxsz + \
288 1 /* co_ownerid.len */ + \
289 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
290 1 /* flags */ + \
291 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400292 /* max is SP4_MACH_CRED (for now) */ + \
293 1 + NFS4_OP_MAP_NUM_WORDS + \
294 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500295 1 /* implementation id array of size 1 */ + \
296 1 /* nii_domain */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500299 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500300 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400301#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
302 2 /* eir_clientid */ + \
303 1 /* eir_sequenceid */ + \
304 1 /* eir_flags */ + \
305 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400306 /* max is SP4_MACH_CRED (for now) */ + \
307 1 + NFS4_OP_MAP_NUM_WORDS + \
308 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400309 2 /* eir_server_owner.so_minor_id */ + \
310 /* eir_server_owner.so_major_id<> */ \
311 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
312 /* eir_server_scope<> */ \
313 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
314 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500315 1 /* nii_domain */ + \
316 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
317 1 /* nii_name */ + \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
319 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400320#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
321#define decode_channel_attrs_maxsz (6 + \
322 1 /* ca_rdma_ird.len */ + \
323 1 /* ca_rdma_ird */)
324#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
325 2 /* csa_clientid */ + \
326 1 /* csa_sequence */ + \
327 1 /* csa_flags */ + \
328 encode_channel_attrs_maxsz + \
329 encode_channel_attrs_maxsz + \
330 1 /* csa_cb_program */ + \
331 1 /* csa_sec_parms.len (1) */ + \
332 1 /* cb_secflavor (AUTH_SYS) */ + \
333 1 /* stamp */ + \
334 1 /* machinename.len */ + \
335 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
336 1 /* uid */ + \
337 1 /* gid */ + \
338 1 /* gids.len (0) */)
339#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
340 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
341 1 /* csr_sequence */ + \
342 1 /* csr_flags */ + \
343 decode_channel_attrs_maxsz + \
344 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400345#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
346 /* bctsa_sessid */ \
347 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
348 1 /* bctsa_dir */ + \
349 1 /* bctsa_use_conn_in_rdma_mode */)
350#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
351 /* bctsr_sessid */ \
352 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
353 1 /* bctsr_dir */ + \
354 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400355#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
356#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400357#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
358#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400359#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
360 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
361#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
362 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500363#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
364#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400365#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
366 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
367#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
368 1 /* layout type */ + \
369 1 /* opaque devaddr4 length */ + \
370 /* devaddr4 payload is read into page */ \
371 1 /* notification bitmap length */ + \
372 1 /* notification bitmap */)
373#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
374 encode_stateid_maxsz)
375#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
376 decode_stateid_maxsz + \
377 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000378#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
379 2 /* offset */ + \
380 2 /* length */ + \
381 1 /* reclaim */ + \
382 encode_stateid_maxsz + \
383 1 /* new offset (true) */ + \
384 2 /* last byte written */ + \
385 1 /* nt_timechanged (false) */ + \
386 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500387 1 /* layoutupdate4 opaqueue len */)
388 /* the actual content of layoutupdate4 should
389 be allocated by drivers and spliced in
390 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000391#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300392#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
393 encode_stateid_maxsz + \
394 1 /* FIXME: opaque lrf_body always empty at the moment */)
395#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
396 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400397#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
398#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400399#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
400 XDR_QUADLEN(NFS4_STATEID_SIZE))
401#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400402#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
403 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400404#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400405#else /* CONFIG_NFS_V4_1 */
406#define encode_sequence_maxsz 0
407#define decode_sequence_maxsz 0
408#endif /* CONFIG_NFS_V4_1 */
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
411#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
412#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400413 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400415 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400419 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400421 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400423 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400425 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400427 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400429 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400431 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400433 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400435 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400439 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400440 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_dec_write_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_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400445 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400447 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400449 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#define NFS4_dec_commit_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 Myklebust85827152012-04-29 10:44:42 -0400453 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400455 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400456 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400457 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400458 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400459 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400460 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400462 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400463 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400464 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400465 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400466 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400467 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400468#define NFS4_enc_open_confirm_sz \
469 (compound_encode_hdr_maxsz + \
470 encode_putfh_maxsz + \
471 encode_open_confirm_maxsz)
472#define NFS4_dec_open_confirm_sz \
473 (compound_decode_hdr_maxsz + \
474 decode_putfh_maxsz + \
475 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400477 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400479 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400480 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400481 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400483 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400485 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400486 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400487 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#define NFS4_enc_open_downgrade_sz \
489 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400491 encode_putfh_maxsz + \
492 encode_open_downgrade_maxsz + \
493 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494#define NFS4_dec_open_downgrade_sz \
495 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400497 decode_putfh_maxsz + \
498 decode_open_downgrade_maxsz + \
499 decode_getattr_maxsz)
500#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400501 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400502 encode_putfh_maxsz + \
503 encode_close_maxsz + \
504 encode_getattr_maxsz)
505#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400506 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400507 decode_putfh_maxsz + \
508 decode_close_maxsz + \
509 decode_getattr_maxsz)
510#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400511 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400512 encode_putfh_maxsz + \
513 encode_setattr_maxsz + \
514 encode_getattr_maxsz)
515#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400516 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400517 decode_putfh_maxsz + \
518 decode_setattr_maxsz + \
519 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400521 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 encode_putfh_maxsz + \
523 encode_fsinfo_maxsz)
524#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400525 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 decode_putfh_maxsz + \
527 decode_fsinfo_maxsz)
528#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
529 encode_renew_maxsz)
530#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
531 decode_renew_maxsz)
532#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
533 encode_setclientid_maxsz)
534#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
535 decode_setclientid_maxsz)
536#define NFS4_enc_setclientid_confirm_sz \
537 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400538 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539#define NFS4_dec_setclientid_confirm_sz \
540 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400541 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400543 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400545 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400547 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400549 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400551 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400553 encode_lockt_maxsz)
554#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400555 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400556 decode_putfh_maxsz + \
557 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400559 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400561 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400563 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400565 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400566#define NFS4_enc_release_lockowner_sz \
567 (compound_encode_hdr_maxsz + \
568 encode_lockowner_maxsz)
569#define NFS4_dec_release_lockowner_sz \
570 (compound_decode_hdr_maxsz + \
571 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400573 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400575 encode_access_maxsz + \
576 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400578 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400580 decode_access_maxsz + \
581 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400583 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400585 encode_getattr_maxsz + \
586 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400588 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400590 decode_getattr_maxsz + \
591 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400593 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 encode_putfh_maxsz + \
595 encode_lookup_maxsz + \
596 encode_getattr_maxsz + \
597 encode_getfh_maxsz)
598#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400599 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400601 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 decode_getattr_maxsz + \
603 decode_getfh_maxsz)
604#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400605 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 encode_putrootfh_maxsz + \
607 encode_getattr_maxsz + \
608 encode_getfh_maxsz)
609#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 decode_putrootfh_maxsz + \
612 decode_getattr_maxsz + \
613 decode_getfh_maxsz)
614#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400615 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400617 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400619 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400621 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400623 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 encode_putfh_maxsz + \
625 encode_savefh_maxsz + \
626 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400627 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400629 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 decode_putfh_maxsz + \
631 decode_savefh_maxsz + \
632 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400633 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400635 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 encode_putfh_maxsz + \
637 encode_savefh_maxsz + \
638 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400639 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400640 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400641 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400643 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 decode_putfh_maxsz + \
645 decode_savefh_maxsz + \
646 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400647 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400648 decode_restorefh_maxsz + \
649 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400651 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 encode_putfh_maxsz + \
653 encode_symlink_maxsz + \
654 encode_getattr_maxsz + \
655 encode_getfh_maxsz)
656#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400657 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 decode_putfh_maxsz + \
659 decode_symlink_maxsz + \
660 decode_getattr_maxsz + \
661 decode_getfh_maxsz)
662#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 encode_putfh_maxsz + \
665 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400666 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400667 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400669 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 decode_putfh_maxsz + \
671 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400672 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400673 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400675 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 encode_putfh_maxsz + \
677 encode_getattr_maxsz)
678#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400679 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 decode_putfh_maxsz + \
681 decode_getattr_maxsz)
682#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400683 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400685 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400687 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400689 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400691 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800692 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 encode_getattr_maxsz)
694#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400695 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800696 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 decode_getattr_maxsz)
698#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400699 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100701 encode_delegreturn_maxsz + \
702 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400704 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100705 decode_delegreturn_maxsz + \
706 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000707#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400708 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000709 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400710 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000711#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400712 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000713 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400714 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000715#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400716 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000717 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400718 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000719#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400720 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000721 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400722 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400723#define NFS4_enc_fs_locations_sz \
724 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400725 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400726 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400727 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400728 encode_fs_locations_maxsz + \
729 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400730#define NFS4_dec_fs_locations_sz \
731 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400732 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400733 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400734 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400735 decode_fs_locations_maxsz + \
736 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000737#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
738 encode_sequence_maxsz + \
739 encode_putfh_maxsz + \
740 encode_secinfo_maxsz)
741#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
742 decode_sequence_maxsz + \
743 decode_putfh_maxsz + \
744 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400745#define NFS4_enc_fsid_present_sz \
746 (compound_encode_hdr_maxsz + \
747 encode_sequence_maxsz + \
748 encode_putfh_maxsz + \
749 encode_getfh_maxsz + \
750 encode_renew_maxsz)
751#define NFS4_dec_fsid_present_sz \
752 (compound_decode_hdr_maxsz + \
753 decode_sequence_maxsz + \
754 decode_putfh_maxsz + \
755 decode_getfh_maxsz + \
756 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400757#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400758#define NFS4_enc_bind_conn_to_session_sz \
759 (compound_encode_hdr_maxsz + \
760 encode_bind_conn_to_session_maxsz)
761#define NFS4_dec_bind_conn_to_session_sz \
762 (compound_decode_hdr_maxsz + \
763 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400764#define NFS4_enc_exchange_id_sz \
765 (compound_encode_hdr_maxsz + \
766 encode_exchange_id_maxsz)
767#define NFS4_dec_exchange_id_sz \
768 (compound_decode_hdr_maxsz + \
769 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400770#define NFS4_enc_create_session_sz \
771 (compound_encode_hdr_maxsz + \
772 encode_create_session_maxsz)
773#define NFS4_dec_create_session_sz \
774 (compound_decode_hdr_maxsz + \
775 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400776#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
777 encode_destroy_session_maxsz)
778#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
779 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400780#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
781 encode_destroy_clientid_maxsz)
782#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
783 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400784#define NFS4_enc_sequence_sz \
785 (compound_decode_hdr_maxsz + \
786 encode_sequence_maxsz)
787#define NFS4_dec_sequence_sz \
788 (compound_decode_hdr_maxsz + \
789 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400790#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
791 encode_sequence_maxsz + \
792 encode_putrootfh_maxsz + \
793 encode_fsinfo_maxsz)
794#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
795 decode_sequence_maxsz + \
796 decode_putrootfh_maxsz + \
797 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500798#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
799 encode_sequence_maxsz + \
800 encode_reclaim_complete_maxsz)
801#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400804#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
805 encode_sequence_maxsz +\
806 encode_getdeviceinfo_maxsz)
807#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
808 decode_sequence_maxsz + \
809 decode_getdeviceinfo_maxsz)
810#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
811 encode_sequence_maxsz + \
812 encode_putfh_maxsz + \
813 encode_layoutget_maxsz)
814#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_putfh_maxsz + \
817 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000818#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
819 encode_sequence_maxsz +\
820 encode_putfh_maxsz + \
821 encode_layoutcommit_maxsz + \
822 encode_getattr_maxsz)
823#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
824 decode_sequence_maxsz + \
825 decode_putfh_maxsz + \
826 decode_layoutcommit_maxsz + \
827 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300828#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
829 encode_sequence_maxsz + \
830 encode_putfh_maxsz + \
831 encode_layoutreturn_maxsz)
832#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
833 decode_sequence_maxsz + \
834 decode_putfh_maxsz + \
835 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400836#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
837 encode_sequence_maxsz + \
838 encode_putrootfh_maxsz +\
839 encode_secinfo_no_name_maxsz)
840#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
841 decode_sequence_maxsz + \
842 decode_putrootfh_maxsz + \
843 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400844#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
845 encode_sequence_maxsz + \
846 encode_test_stateid_maxsz)
847#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
848 decode_sequence_maxsz + \
849 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400850#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
851 encode_sequence_maxsz + \
852 encode_free_stateid_maxsz)
853#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
854 decode_sequence_maxsz + \
855 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500856
857const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
858 compound_encode_hdr_maxsz +
859 encode_sequence_maxsz +
860 encode_putfh_maxsz +
861 encode_getattr_maxsz) *
862 XDR_UNIT);
863
864const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
865 compound_decode_hdr_maxsz +
866 decode_sequence_maxsz +
867 decode_putfh_maxsz) *
868 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400869
870const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
871 compound_decode_hdr_maxsz +
872 decode_sequence_maxsz) *
873 XDR_UNIT);
874EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400875#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Trond Myklebustbca79472009-03-11 14:10:26 -0400877static const umode_t nfs_type2fmt[] = {
878 [NF4BAD] = 0,
879 [NF4REG] = S_IFREG,
880 [NF4DIR] = S_IFDIR,
881 [NF4BLK] = S_IFBLK,
882 [NF4CHR] = S_IFCHR,
883 [NF4LNK] = S_IFLNK,
884 [NF4SOCK] = S_IFSOCK,
885 [NF4FIFO] = S_IFIFO,
886 [NF4ATTRDIR] = 0,
887 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888};
889
890struct compound_hdr {
891 int32_t status;
892 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500893 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 uint32_t taglen;
895 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400896 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400897 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898};
899
Benny Halevy13c65ce2009-08-14 17:19:25 +0300900static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
901{
902 __be32 *p = xdr_reserve_space(xdr, nbytes);
903 BUG_ON(!p);
904 return p;
905}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Trond Myklebustcb17e552012-03-04 18:13:56 -0500907static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
908{
909 __be32 *p;
910
911 p = xdr_reserve_space(xdr, len);
912 xdr_encode_opaque_fixed(p, buf, len);
913}
914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
916{
Al Viro8687b632006-10-19 23:28:48 -0700917 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500919 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 xdr_encode_opaque(p, str, len);
921}
922
Trond Myklebust4ade9822012-03-04 18:13:57 -0500923static void encode_uint32(struct xdr_stream *xdr, u32 n)
924{
925 __be32 *p;
926
927 p = reserve_space(xdr, 4);
928 *p = cpu_to_be32(n);
929}
930
Trond Myklebustff2eb682012-03-05 11:40:12 -0500931static void encode_uint64(struct xdr_stream *xdr, u64 n)
932{
933 __be32 *p;
934
935 p = reserve_space(xdr, 8);
936 xdr_encode_hyper(p, n);
937}
938
Trond Myklebust4ade9822012-03-04 18:13:57 -0500939static void encode_nfs4_seqid(struct xdr_stream *xdr,
940 const struct nfs_seqid *seqid)
941{
942 encode_uint32(xdr, seqid->sequence->counter);
943}
944
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400945static void encode_compound_hdr(struct xdr_stream *xdr,
946 struct rpc_rqst *req,
947 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948{
Al Viro8687b632006-10-19 23:28:48 -0700949 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400950 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400951
952 /* initialize running count of expected bytes in reply.
953 * NOTE: the replied tag SHOULD be the same is the one sent,
954 * but this is not required as a MUST for the server to do so. */
955 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Trond Myklebust7fc38842012-10-15 11:51:21 -0400957 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500958 encode_string(xdr, hdr->taglen, hdr->tag);
959 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300960 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500961 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300962 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500963}
964
Trond Myklebustab19b482012-03-04 18:13:57 -0500965static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
966 uint32_t replen,
967 struct compound_hdr *hdr)
968{
969 encode_uint32(xdr, op);
970 hdr->nops++;
971 hdr->replen += replen;
972}
973
Andy Adamsond0179312008-12-23 16:06:17 -0500974static void encode_nops(struct compound_hdr *hdr)
975{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400976 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500977 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978}
979
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500980static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
981{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500982 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500983}
984
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
986{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500987 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988}
989
David Quigleyaa9c2662013-05-22 12:50:44 -0400990static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
991 const struct nfs4_label *label,
992 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
994 char owner_name[IDMAP_NAMESZ];
995 char owner_group[IDMAP_NAMESZ];
996 int owner_namelen = 0;
997 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700998 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -0400999 unsigned i;
1000 uint32_t len = 0;
1001 uint32_t bmval_len;
1002 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 /*
1005 * We reserve enough space to write the entire attribute buffer at once.
1006 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001007 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1008 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001009 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001011 if (iap->ia_valid & ATTR_SIZE) {
1012 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001014 }
1015 if (iap->ia_valid & ATTR_MODE) {
1016 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001020 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001022 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001023 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 /* XXX */
1025 strcpy(owner_name, "nobody");
1026 owner_namelen = sizeof("nobody") - 1;
1027 /* goto out; */
1028 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001029 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1031 }
1032 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001033 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001035 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001036 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 strcpy(owner_group, "nobody");
1038 owner_grouplen = sizeof("nobody") - 1;
1039 /* goto out; */
1040 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001041 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1043 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001045 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1046 len += 16;
1047 } else if (iap->ia_valid & ATTR_ATIME) {
1048 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1049 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 }
1051 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001052 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1053 len += 16;
1054 } else if (iap->ia_valid & ATTR_MTIME) {
1055 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1056 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001058 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001059 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1060 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1061 }
1062
1063 if (bmval[2] != 0)
1064 bmval_len = 3;
1065 else if (bmval[1] != 0)
1066 bmval_len = 2;
1067 else
1068 bmval_len = 1;
1069
1070 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1071
1072 *p++ = cpu_to_be32(bmval_len);
1073 for (i = 0; i < bmval_len; i++)
1074 *p++ = cpu_to_be32(bmval[i]);
1075 *p++ = cpu_to_be32(len);
1076
1077 if (bmval[0] & FATTR4_WORD0_SIZE)
1078 p = xdr_encode_hyper(p, iap->ia_size);
1079 if (bmval[1] & FATTR4_WORD1_MODE)
1080 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1081 if (bmval[1] & FATTR4_WORD1_OWNER)
1082 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1083 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1084 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1085 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1086 if (iap->ia_valid & ATTR_ATIME_SET) {
1087 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1088 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1089 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1090 } else
1091 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1092 }
1093 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1094 if (iap->ia_valid & ATTR_MTIME_SET) {
1095 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1096 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1097 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1098 } else
1099 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1100 }
1101 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001102 *p++ = cpu_to_be32(label->lfs);
1103 *p++ = cpu_to_be32(label->pi);
1104 *p++ = cpu_to_be32(label->len);
1105 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1106 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001107
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109}
1110
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001111static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001113 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1114 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115}
1116
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001117static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118{
Trond Myklebustab19b482012-03-04 18:13:57 -05001119 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001120 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001121 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
Fred Isaman0b7c0152012-04-20 14:47:39 -04001124static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
Al Viro8687b632006-10-19 23:28:48 -07001126 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001127
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001128 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1129 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001130 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001131 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001134static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
Al Viro8687b632006-10-19 23:28:48 -07001136 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001137
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001138 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1139 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141 switch (create->ftype) {
1142 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001143 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001144 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001145 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 break;
1147
1148 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001149 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001150 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001151 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 break;
1153
1154 default:
1155 break;
1156 }
1157
Benny Halevy811652b2009-08-14 17:19:34 +03001158 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001159 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001162static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163{
Andy Adamson05d564f2008-12-23 16:06:15 -05001164 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001166 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1167 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001168 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001169 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170}
1171
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001172static 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 -07001173{
Andy Adamson05d564f2008-12-23 16:06:15 -05001174 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001176 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1177 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001178 *p++ = cpu_to_be32(2);
1179 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001180 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181}
1182
Fred Isamandae100c2011-07-30 20:52:37 -04001183static void
1184encode_getattr_three(struct xdr_stream *xdr,
1185 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1186 struct compound_hdr *hdr)
1187{
1188 __be32 *p;
1189
Trond Myklebustab19b482012-03-04 18:13:57 -05001190 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001191 if (bm2) {
1192 p = reserve_space(xdr, 16);
1193 *p++ = cpu_to_be32(3);
1194 *p++ = cpu_to_be32(bm0);
1195 *p++ = cpu_to_be32(bm1);
1196 *p = cpu_to_be32(bm2);
1197 } else if (bm1) {
1198 p = reserve_space(xdr, 12);
1199 *p++ = cpu_to_be32(2);
1200 *p++ = cpu_to_be32(bm0);
1201 *p = cpu_to_be32(bm1);
1202 } else {
1203 p = reserve_space(xdr, 8);
1204 *p++ = cpu_to_be32(1);
1205 *p = cpu_to_be32(bm0);
1206 }
Fred Isamandae100c2011-07-30 20:52:37 -04001207}
1208
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001209static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210{
David Quigleya09df2c2013-05-22 12:50:41 -04001211 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1212 bitmask[1] & nfs4_fattr_bitmap[1],
1213 bitmask[2] & nfs4_fattr_bitmap[2],
1214 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
Andy Adamson88034c32012-05-23 05:02:34 -04001217static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001218 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001219 struct compound_hdr *hdr)
1220{
1221 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001222 bitmask[0] & open_bitmap[0],
1223 bitmask[1] & open_bitmap[1],
1224 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001225 hdr);
1226}
1227
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001228static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229{
Fred Isamandae100c2011-07-30 20:52:37 -04001230 encode_getattr_three(xdr,
1231 bitmask[0] & nfs4_fsinfo_bitmap[0],
1232 bitmask[1] & nfs4_fsinfo_bitmap[1],
1233 bitmask[2] & nfs4_fsinfo_bitmap[2],
1234 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235}
1236
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001237static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001238{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001239 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1240 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001241}
1242
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001243static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244{
Trond Myklebustab19b482012-03-04 18:13:57 -05001245 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246}
1247
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001248static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Trond Myklebustab19b482012-03-04 18:13:57 -05001250 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001251 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001254static inline int nfs4_lock_type(struct file_lock *fl, int block)
1255{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001256 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001257 return block ? NFS4_READW_LT : NFS4_READ_LT;
1258 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1259}
1260
1261static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1262{
1263 if (fl->fl_end == OFFSET_MAX)
1264 return ~(uint64_t)0;
1265 return fl->fl_end - fl->fl_start + 1;
1266}
1267
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001268static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1269{
1270 __be32 *p;
1271
Trond Myklebustd035c362010-12-21 10:45:27 -05001272 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001273 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001274 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001275 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001276 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001277 xdr_encode_hyper(p, lowner->id);
1278}
1279
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280/*
1281 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1282 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1283 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001284static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285{
Al Viro8687b632006-10-19 23:28:48 -07001286 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001288 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1289 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001290 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1291 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001292 p = xdr_encode_hyper(p, args->fl->fl_start);
1293 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001294 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001295 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001296 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001297 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001298 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001299 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 }
1301 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001302 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001303 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305}
1306
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001307static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308{
Al Viro8687b632006-10-19 23:28:48 -07001309 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001311 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1312 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001313 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001314 p = xdr_encode_hyper(p, args->fl->fl_start);
1315 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001316 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317}
1318
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001319static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320{
Al Viro8687b632006-10-19 23:28:48 -07001321 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001323 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1324 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001325 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001326 encode_nfs4_stateid(xdr, args->stateid);
1327 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001328 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001329 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330}
1331
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001332static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1333{
Trond Myklebustab19b482012-03-04 18:13:57 -05001334 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001335 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001336}
1337
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001338static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339{
Trond Myklebustab19b482012-03-04 18:13:57 -05001340 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001341 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342}
1343
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001344static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345{
Al Viro8687b632006-10-19 23:28:48 -07001346 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Benny Halevy13c65ce2009-08-14 17:19:25 +03001348 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001349 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001350 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001351 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001352 break;
1353 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001354 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001355 break;
1356 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001357 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001358 break;
1359 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001360 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 }
Benny Halevy34558512009-08-14 17:19:30 +03001362 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363}
1364
1365static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1366{
Al Viro8687b632006-10-19 23:28:48 -07001367 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 /*
1369 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1370 * owner 4 = 32
1371 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001372 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001373 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001374 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001375 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001376 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001377 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001378 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001379 *p++ = cpu_to_be32(arg->id.uniquifier);
1380 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381}
1382
1383static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1384{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001385 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001386 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Benny Halevy13c65ce2009-08-14 17:19:25 +03001388 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001389 switch(arg->createmode) {
1390 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001391 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001392 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001393 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001394 case NFS4_CREATE_GUARDED:
1395 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001396 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001397 break;
1398 case NFS4_CREATE_EXCLUSIVE:
1399 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1400 encode_nfs4_verifier(xdr, &arg->u.verifier);
1401 break;
1402 case NFS4_CREATE_EXCLUSIVE4_1:
1403 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1404 encode_nfs4_verifier(xdr, &arg->u.verifier);
1405 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001406 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 }
1408}
1409
1410static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1411{
Al Viro8687b632006-10-19 23:28:48 -07001412 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
Benny Halevy13c65ce2009-08-14 17:19:25 +03001414 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001416 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001417 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001418 break;
1419 default:
Benny Halevy34558512009-08-14 17:19:30 +03001420 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001421 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 }
1423}
1424
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001425static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426{
Al Viro8687b632006-10-19 23:28:48 -07001427 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Benny Halevy13c65ce2009-08-14 17:19:25 +03001429 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001431 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001432 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001433 break;
1434 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001435 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001436 break;
1437 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001438 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001439 break;
1440 default:
1441 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 }
1443}
1444
1445static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1446{
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);
Benny Halevy34558512009-08-14 17:19:30 +03001450 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 encode_string(xdr, name->len, name->name);
1452}
1453
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001454static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455{
Al Viro8687b632006-10-19 23:28:48 -07001456 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Benny Halevy13c65ce2009-08-14 17:19:25 +03001458 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001459 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 encode_delegation_type(xdr, type);
1461}
1462
1463static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1464{
Al Viro8687b632006-10-19 23:28:48 -07001465 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001467 p = reserve_space(xdr, 4);
1468 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1469 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 encode_string(xdr, name->len, name->name);
1471}
1472
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001473static inline void encode_claim_fh(struct xdr_stream *xdr)
1474{
1475 __be32 *p;
1476
1477 p = reserve_space(xdr, 4);
1478 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1479}
1480
1481static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1482{
1483 __be32 *p;
1484
1485 p = reserve_space(xdr, 4);
1486 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1487 encode_nfs4_stateid(xdr, stateid);
1488}
1489
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001490static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Trond Myklebustab19b482012-03-04 18:13:57 -05001492 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 encode_openhdr(xdr, arg);
1494 encode_opentype(xdr, arg);
1495 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001496 case NFS4_OPEN_CLAIM_NULL:
1497 encode_claim_null(xdr, arg->name);
1498 break;
1499 case NFS4_OPEN_CLAIM_PREVIOUS:
1500 encode_claim_previous(xdr, arg->u.delegation_type);
1501 break;
1502 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1503 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1504 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001505 case NFS4_OPEN_CLAIM_FH:
1506 encode_claim_fh(xdr);
1507 break;
1508 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1509 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1510 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001511 default:
1512 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514}
1515
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001516static 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 -07001517{
Trond Myklebustab19b482012-03-04 18:13:57 -05001518 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001519 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001520 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521}
1522
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001523static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524{
Trond Myklebustab19b482012-03-04 18:13:57 -05001525 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001526 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001527 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001528 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529}
1530
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001531static void
Andy Adamsond0179312008-12-23 16:06:17 -05001532encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533{
Trond Myklebustab19b482012-03-04 18:13:57 -05001534 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001535 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536}
1537
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001538static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539{
Trond Myklebustab19b482012-03-04 18:13:57 -05001540 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
1542
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001543static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1544 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
Al Viro8687b632006-10-19 23:28:48 -07001546 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Trond Myklebustab19b482012-03-04 18:13:57 -05001548 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001549 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Benny Halevy13c65ce2009-08-14 17:19:25 +03001551 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001552 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001553 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001556static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
David Quigleyaa9c2662013-05-22 12:50:44 -04001558 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001559 FATTR4_WORD0_RDATTR_ERROR,
1560 FATTR4_WORD1_MOUNTED_ON_FILEID,
1561 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001562 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001563 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001564 uint32_t attrlen = 0;
1565 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001567 if (readdir->plus) {
1568 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001569 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001570 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1571 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1572 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1573 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001574 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001575 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001576 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001577 /* Use mounted_on_fileid only if the server supports it */
1578 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1579 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001580 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1581 attrs[i] &= readdir->bitmask[i];
1582 if (attrs[i] != 0)
1583 attrlen = i+1;
1584 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001585
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001586 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001587 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001588 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001589 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001590 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001591 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001592 *p++ = cpu_to_be32(attrlen);
1593 for (i = 0; i < attrlen; i++)
1594 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001595 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001596
1597 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001598 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001599 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001600 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001601 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001602 attrs[1] & readdir->bitmask[1],
1603 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604}
1605
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001606static 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 -07001607{
Trond Myklebustab19b482012-03-04 18:13:57 -05001608 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609}
1610
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001611static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612{
Trond Myklebustab19b482012-03-04 18:13:57 -05001613 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001614 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
1616
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001617static 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 -07001618{
Trond Myklebustab19b482012-03-04 18:13:57 -05001619 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001620 encode_string(xdr, oldname->len, oldname->name);
1621 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622}
1623
Chuck Leverbb4dae52012-03-01 17:01:48 -05001624static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1625 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001627 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001628 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629}
1630
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001631static void
Andy Adamsond0179312008-12-23 16:06:17 -05001632encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001633{
Trond Myklebustab19b482012-03-04 18:13:57 -05001634 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001635}
1636
Chuck Lever9f06c712010-12-14 14:59:18 +00001637static void
Andy Adamsond0179312008-12-23 16:06:17 -05001638encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001639{
Al Viro8687b632006-10-19 23:28:48 -07001640 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001641
Trond Myklebustab19b482012-03-04 18:13:57 -05001642 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001643 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001644 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001645 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001646 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001647 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001648 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001649 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001650}
1651
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001652static void
Andy Adamsond0179312008-12-23 16:06:17 -05001653encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654{
Trond Myklebustab19b482012-03-04 18:13:57 -05001655 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
1657
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001658static 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 -07001659{
Trond Myklebustab19b482012-03-04 18:13:57 -05001660 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001661 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001662 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663}
1664
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001665static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666{
Al Viro8687b632006-10-19 23:28:48 -07001667 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
Trond Myklebust70019512012-03-04 20:49:32 -05001669 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001670 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
1672 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001673 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001674 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1676 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001677 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001678 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679}
1680
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001681static 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 -07001682{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001683 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1684 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001685 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001686 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687}
1688
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001689static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1690 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
Al Viro8687b632006-10-19 23:28:48 -07001692 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
Trond Myklebustab19b482012-03-04 18:13:57 -05001694 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001695 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
Benny Halevy13c65ce2009-08-14 17:19:25 +03001697 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001698 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001699 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001700 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
1702 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001705static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706{
Trond Myklebustab19b482012-03-04 18:13:57 -05001707 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001708 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001710
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001711static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1712{
Trond Myklebustab19b482012-03-04 18:13:57 -05001713 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001714 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001715}
1716
Benny Halevy99fe60d2009-04-01 09:22:29 -04001717#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001718/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001719static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1720 struct nfs4_session *session,
1721 struct compound_hdr *hdr)
1722{
1723 __be32 *p;
1724
1725 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1726 decode_bind_conn_to_session_maxsz, hdr);
1727 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1728 p = xdr_reserve_space(xdr, 8);
1729 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1730 *p = 0; /* use_conn_in_rdma_mode = False */
1731}
1732
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001733static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1734{
1735 unsigned int i;
1736 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1737 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1738 encode_uint32(xdr, op_map->u.words[i]);
1739}
1740
Benny Halevy99fe60d2009-04-01 09:22:29 -04001741static void encode_exchange_id(struct xdr_stream *xdr,
1742 struct nfs41_exchange_id_args *args,
1743 struct compound_hdr *hdr)
1744{
1745 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001746 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001747 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001748
Trond Myklebust70019512012-03-04 20:49:32 -05001749 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001750 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001751
1752 encode_string(xdr, args->id_len, args->id);
1753
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001754 encode_uint32(xdr, args->flags);
1755 encode_uint32(xdr, args->state_protect.how);
1756
1757 switch (args->state_protect.how) {
1758 case SP4_NONE:
1759 break;
1760 case SP4_MACH_CRED:
1761 encode_op_map(xdr, &args->state_protect.enforce);
1762 encode_op_map(xdr, &args->state_protect.allow);
1763 break;
1764 default:
1765 WARN_ON_ONCE(1);
1766 break;
1767 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001768
1769 if (send_implementation_id &&
1770 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1771 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001772 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001773 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1774 utsname()->sysname, utsname()->release,
1775 utsname()->version, utsname()->machine);
1776
1777 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001778 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001779
1780 encode_string(xdr,
1781 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1782 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1783 encode_string(xdr, len, impl_name);
1784 /* just send zeros for nii_date - the date is in nii_name */
1785 p = reserve_space(xdr, 12);
1786 p = xdr_encode_hyper(p, 0);
1787 *p = cpu_to_be32(0);
1788 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001789 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001790}
Andy Adamsonfc931582009-04-01 09:22:31 -04001791
1792static void encode_create_session(struct xdr_stream *xdr,
1793 struct nfs41_create_session_args *args,
1794 struct compound_hdr *hdr)
1795{
1796 __be32 *p;
1797 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1798 uint32_t len;
1799 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001800 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001801 u32 max_resp_sz_cached;
1802
1803 /*
1804 * Assumes OPEN is the biggest non-idempotent compound.
1805 * 2 is the verifier.
1806 */
1807 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1808 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001809
Andy Adamsonfc931582009-04-01 09:22:31 -04001810 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1811 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001812
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001813 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1814 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001815 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001816 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1817 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001818
Andy Adamsonfc931582009-04-01 09:22:31 -04001819 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001820 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001821 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1822 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001823 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001824 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1825 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1826 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001827
1828 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001829 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001830 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1831 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1832 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1833 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1834 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1835 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001836
Benny Halevye75bc1c2009-08-14 17:18:54 +03001837 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001838 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001839 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001840
1841 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001842 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001843 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001844 *p++ = cpu_to_be32(0); /* UID */
1845 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001846 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001847}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001848
1849static void encode_destroy_session(struct xdr_stream *xdr,
1850 struct nfs4_session *session,
1851 struct compound_hdr *hdr)
1852{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001853 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1854 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001855}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001856
Trond Myklebust66245532012-05-25 17:18:09 -04001857static void encode_destroy_clientid(struct xdr_stream *xdr,
1858 uint64_t clientid,
1859 struct compound_hdr *hdr)
1860{
1861 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1862 encode_uint64(xdr, clientid);
1863}
1864
Ricardo Labiaga180197532009-12-05 16:08:40 -05001865static void encode_reclaim_complete(struct xdr_stream *xdr,
1866 struct nfs41_reclaim_complete_args *args,
1867 struct compound_hdr *hdr)
1868{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001869 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1870 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001871}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001872#endif /* CONFIG_NFS_V4_1 */
1873
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001874static void encode_sequence(struct xdr_stream *xdr,
1875 const struct nfs4_sequence_args *args,
1876 struct compound_hdr *hdr)
1877{
1878#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001879 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001880 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001881 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001882 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001883
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001884 tp = slot->table;
1885 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001886 if (!session)
1887 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001888
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001889 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001890
1891 /*
1892 * Sessionid + seqid + slotid + max slotid + cache_this
1893 */
1894 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1895 "max_slotid=%d cache_this=%d\n",
1896 __func__,
1897 ((u32 *)session->sess_id.data)[0],
1898 ((u32 *)session->sess_id.data)[1],
1899 ((u32 *)session->sess_id.data)[2],
1900 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001901 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001902 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001903 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001904 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001905 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001906 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001907 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001908 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001909#endif /* CONFIG_NFS_V4_1 */
1910}
1911
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001912#ifdef CONFIG_NFS_V4_1
1913static void
1914encode_getdeviceinfo(struct xdr_stream *xdr,
1915 const struct nfs4_getdeviceinfo_args *args,
1916 struct compound_hdr *hdr)
1917{
1918 __be32 *p;
1919
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001920 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1921 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001922 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1923 NFS4_DEVICEID4_SIZE);
1924 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001925 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001926 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001927}
1928
1929static void
1930encode_layoutget(struct xdr_stream *xdr,
1931 const struct nfs4_layoutget_args *args,
1932 struct compound_hdr *hdr)
1933{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001934 __be32 *p;
1935
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001936 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1937 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001938 *p++ = cpu_to_be32(0); /* Signal layout available */
1939 *p++ = cpu_to_be32(args->type);
1940 *p++ = cpu_to_be32(args->range.iomode);
1941 p = xdr_encode_hyper(p, args->range.offset);
1942 p = xdr_encode_hyper(p, args->range.length);
1943 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001944 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001945 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001946
1947 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1948 __func__,
1949 args->type,
1950 args->range.iomode,
1951 (unsigned long)args->range.offset,
1952 (unsigned long)args->range.length,
1953 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001954}
Andy Adamson863a3c62011-03-23 13:27:54 +00001955
1956static int
1957encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001958 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001959 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001960 struct compound_hdr *hdr)
1961{
1962 __be32 *p;
1963
1964 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1965 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1966
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001967 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1968 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001969 /* Only whole file layouts */
1970 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001971 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001972 *p = cpu_to_be32(0); /* reclaim */
1973 encode_nfs4_stateid(xdr, &args->stateid);
1974 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001975 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1976 p = xdr_encode_hyper(p, args->lastbytewritten);
1977 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1978 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001979
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001980 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03001981 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1982 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001983 } else {
1984 encode_uint32(xdr, args->layoutupdate_len);
1985 if (args->layoutupdate_pages) {
1986 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
1987 args->layoutupdate_len);
1988 }
1989 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001990
Andy Adamson863a3c62011-03-23 13:27:54 +00001991 return 0;
1992}
Benny Halevycbe82602011-05-22 19:52:37 +03001993
1994static void
1995encode_layoutreturn(struct xdr_stream *xdr,
1996 const struct nfs4_layoutreturn_args *args,
1997 struct compound_hdr *hdr)
1998{
1999 __be32 *p;
2000
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002001 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2002 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002003 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2004 *p++ = cpu_to_be32(args->layout_type);
2005 *p++ = cpu_to_be32(IOMODE_ANY);
2006 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002007 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002008 p = xdr_encode_hyper(p, 0);
2009 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2010 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002011 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002012 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002013 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2014 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2015 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002016 } else
2017 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002018}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002019
2020static int
2021encode_secinfo_no_name(struct xdr_stream *xdr,
2022 const struct nfs41_secinfo_no_name_args *args,
2023 struct compound_hdr *hdr)
2024{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002025 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2026 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002027 return 0;
2028}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002029
2030static void encode_test_stateid(struct xdr_stream *xdr,
2031 struct nfs41_test_stateid_args *args,
2032 struct compound_hdr *hdr)
2033{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002034 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2035 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002036 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002037}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002038
2039static void encode_free_stateid(struct xdr_stream *xdr,
2040 struct nfs41_free_stateid_args *args,
2041 struct compound_hdr *hdr)
2042{
Trond Myklebustab19b482012-03-04 18:13:57 -05002043 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002044 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002045}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002046#endif /* CONFIG_NFS_V4_1 */
2047
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048/*
2049 * END OF "GENERIC" ENCODE ROUTINES.
2050 */
2051
Benny Halevy66cc0422009-04-01 09:22:10 -04002052static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2053{
2054#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002055 struct nfs4_session *session = args->sa_slot->table->session;
2056 if (session)
2057 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002058#endif /* CONFIG_NFS_V4_1 */
2059 return 0;
2060}
2061
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062/*
2063 * Encode an ACCESS request
2064 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002065static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2066 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002069 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Chuck Lever9f06c712010-12-14 14:59:18 +00002072 encode_compound_hdr(xdr, req, &hdr);
2073 encode_sequence(xdr, &args->seq_args, &hdr);
2074 encode_putfh(xdr, args->fh, &hdr);
2075 encode_access(xdr, args->access, &hdr);
2076 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002077 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078}
2079
2080/*
2081 * Encode LOOKUP request
2082 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002083static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2084 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002087 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
Chuck Lever9f06c712010-12-14 14:59:18 +00002090 encode_compound_hdr(xdr, req, &hdr);
2091 encode_sequence(xdr, &args->seq_args, &hdr);
2092 encode_putfh(xdr, args->dir_fh, &hdr);
2093 encode_lookup(xdr, args->name, &hdr);
2094 encode_getfh(xdr, &hdr);
2095 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002096 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097}
2098
2099/*
2100 * Encode LOOKUP_ROOT request
2101 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002102static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2103 struct xdr_stream *xdr,
2104 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002107 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
Chuck Lever9f06c712010-12-14 14:59:18 +00002110 encode_compound_hdr(xdr, req, &hdr);
2111 encode_sequence(xdr, &args->seq_args, &hdr);
2112 encode_putrootfh(xdr, &hdr);
2113 encode_getfh(xdr, &hdr);
2114 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002115 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116}
2117
2118/*
2119 * Encode REMOVE request
2120 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002121static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2122 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002125 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
Chuck Lever9f06c712010-12-14 14:59:18 +00002128 encode_compound_hdr(xdr, req, &hdr);
2129 encode_sequence(xdr, &args->seq_args, &hdr);
2130 encode_putfh(xdr, args->fh, &hdr);
2131 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002132 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133}
2134
2135/*
2136 * Encode RENAME request
2137 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002138static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2139 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002142 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
Chuck Lever9f06c712010-12-14 14:59:18 +00002145 encode_compound_hdr(xdr, req, &hdr);
2146 encode_sequence(xdr, &args->seq_args, &hdr);
2147 encode_putfh(xdr, args->old_dir, &hdr);
2148 encode_savefh(xdr, &hdr);
2149 encode_putfh(xdr, args->new_dir, &hdr);
2150 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002151 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152}
2153
2154/*
2155 * Encode LINK request
2156 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002157static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2158 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002161 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
Chuck Lever9f06c712010-12-14 14:59:18 +00002164 encode_compound_hdr(xdr, req, &hdr);
2165 encode_sequence(xdr, &args->seq_args, &hdr);
2166 encode_putfh(xdr, args->fh, &hdr);
2167 encode_savefh(xdr, &hdr);
2168 encode_putfh(xdr, args->dir_fh, &hdr);
2169 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002170 encode_restorefh(xdr, &hdr);
2171 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002172 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173}
2174
2175/*
2176 * Encode CREATE request
2177 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002178static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2179 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002182 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
Chuck Lever9f06c712010-12-14 14:59:18 +00002185 encode_compound_hdr(xdr, req, &hdr);
2186 encode_sequence(xdr, &args->seq_args, &hdr);
2187 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002188 encode_create(xdr, args, &hdr);
2189 encode_getfh(xdr, &hdr);
2190 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002191 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192}
2193
2194/*
2195 * Encode SYMLINK request
2196 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002197static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2198 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
Chuck Lever9f06c712010-12-14 14:59:18 +00002200 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201}
2202
2203/*
2204 * Encode GETATTR request
2205 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002206static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2207 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002210 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
Chuck Lever9f06c712010-12-14 14:59:18 +00002213 encode_compound_hdr(xdr, req, &hdr);
2214 encode_sequence(xdr, &args->seq_args, &hdr);
2215 encode_putfh(xdr, args->fh, &hdr);
2216 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002217 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218}
2219
2220/*
2221 * Encode a CLOSE request
2222 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002223static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2224 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225{
Andy Adamson05d564f2008-12-23 16:06:15 -05002226 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002227 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002228 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229
Chuck Lever9f06c712010-12-14 14:59:18 +00002230 encode_compound_hdr(xdr, req, &hdr);
2231 encode_sequence(xdr, &args->seq_args, &hdr);
2232 encode_putfh(xdr, args->fh, &hdr);
2233 encode_close(xdr, args, &hdr);
2234 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002235 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236}
2237
2238/*
2239 * Encode an OPEN request
2240 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002241static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2242 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002245 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
Chuck Lever9f06c712010-12-14 14:59:18 +00002248 encode_compound_hdr(xdr, req, &hdr);
2249 encode_sequence(xdr, &args->seq_args, &hdr);
2250 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002251 encode_open(xdr, args, &hdr);
2252 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002253 if (args->access)
2254 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002255 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002256 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257}
2258
2259/*
2260 * Encode an OPEN_CONFIRM request
2261 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002262static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2263 struct xdr_stream *xdr,
2264 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002267 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
Chuck Lever9f06c712010-12-14 14:59:18 +00002270 encode_compound_hdr(xdr, req, &hdr);
2271 encode_putfh(xdr, args->fh, &hdr);
2272 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002273 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274}
2275
2276/*
2277 * Encode an OPEN request with no attributes.
2278 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002279static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2280 struct xdr_stream *xdr,
2281 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002284 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286
Chuck Lever9f06c712010-12-14 14:59:18 +00002287 encode_compound_hdr(xdr, req, &hdr);
2288 encode_sequence(xdr, &args->seq_args, &hdr);
2289 encode_putfh(xdr, args->fh, &hdr);
2290 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002291 if (args->access)
2292 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002293 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002294 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295}
2296
2297/*
2298 * Encode an OPEN_DOWNGRADE request
2299 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002300static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2301 struct xdr_stream *xdr,
2302 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002305 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
Chuck Lever9f06c712010-12-14 14:59:18 +00002308 encode_compound_hdr(xdr, req, &hdr);
2309 encode_sequence(xdr, &args->seq_args, &hdr);
2310 encode_putfh(xdr, args->fh, &hdr);
2311 encode_open_downgrade(xdr, args, &hdr);
2312 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002313 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314}
2315
2316/*
2317 * Encode a LOCK request
2318 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002319static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2320 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002323 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
Chuck Lever9f06c712010-12-14 14:59:18 +00002326 encode_compound_hdr(xdr, req, &hdr);
2327 encode_sequence(xdr, &args->seq_args, &hdr);
2328 encode_putfh(xdr, args->fh, &hdr);
2329 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002330 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331}
2332
2333/*
2334 * Encode a LOCKT request
2335 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002336static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2337 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002340 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
Chuck Lever9f06c712010-12-14 14:59:18 +00002343 encode_compound_hdr(xdr, req, &hdr);
2344 encode_sequence(xdr, &args->seq_args, &hdr);
2345 encode_putfh(xdr, args->fh, &hdr);
2346 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002347 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348}
2349
2350/*
2351 * Encode a LOCKU request
2352 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002353static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2354 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002357 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359
Chuck Lever9f06c712010-12-14 14:59:18 +00002360 encode_compound_hdr(xdr, req, &hdr);
2361 encode_sequence(xdr, &args->seq_args, &hdr);
2362 encode_putfh(xdr, args->fh, &hdr);
2363 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002364 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365}
2366
Chuck Lever9f06c712010-12-14 14:59:18 +00002367static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2368 struct xdr_stream *xdr,
2369 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002370{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002371 struct compound_hdr hdr = {
2372 .minorversion = 0,
2373 };
2374
Chuck Lever9f06c712010-12-14 14:59:18 +00002375 encode_compound_hdr(xdr, req, &hdr);
2376 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002377 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002378}
2379
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380/*
2381 * Encode a READLINK request
2382 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002383static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2384 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002387 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389
Chuck Lever9f06c712010-12-14 14:59:18 +00002390 encode_compound_hdr(xdr, req, &hdr);
2391 encode_sequence(xdr, &args->seq_args, &hdr);
2392 encode_putfh(xdr, args->fh, &hdr);
2393 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002394
Benny Halevy28f56692009-04-01 09:22:09 -04002395 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002396 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002397 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398}
2399
2400/*
2401 * Encode a READDIR request
2402 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002403static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2404 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002407 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409
Chuck Lever9f06c712010-12-14 14:59:18 +00002410 encode_compound_hdr(xdr, req, &hdr);
2411 encode_sequence(xdr, &args->seq_args, &hdr);
2412 encode_putfh(xdr, args->fh, &hdr);
2413 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002414
Benny Halevy28f56692009-04-01 09:22:09 -04002415 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002416 args->pgbase, args->count);
2417 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002418 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002419 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002420 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421}
2422
2423/*
2424 * Encode a READ request
2425 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002426static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002427 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002430 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432
Chuck Lever9f06c712010-12-14 14:59:18 +00002433 encode_compound_hdr(xdr, req, &hdr);
2434 encode_sequence(xdr, &args->seq_args, &hdr);
2435 encode_putfh(xdr, args->fh, &hdr);
2436 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437
Benny Halevy28f56692009-04-01 09:22:09 -04002438 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002440 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002441 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442}
2443
2444/*
2445 * Encode an SETATTR request
2446 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002447static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2448 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449{
Andy Adamson05d564f2008-12-23 16:06:15 -05002450 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002451 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002452 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453
Chuck Lever9f06c712010-12-14 14:59:18 +00002454 encode_compound_hdr(xdr, req, &hdr);
2455 encode_sequence(xdr, &args->seq_args, &hdr);
2456 encode_putfh(xdr, args->fh, &hdr);
2457 encode_setattr(xdr, args, args->server, &hdr);
2458 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002459 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460}
2461
2462/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002463 * Encode a GETACL request
2464 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002465static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2466 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002467{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002468 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002469 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002470 };
Benny Halevy28f56692009-04-01 09:22:09 -04002471 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002472
Chuck Lever9f06c712010-12-14 14:59:18 +00002473 encode_compound_hdr(xdr, req, &hdr);
2474 encode_sequence(xdr, &args->seq_args, &hdr);
2475 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002476 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002477 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002478
Benny Halevy28f56692009-04-01 09:22:09 -04002479 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002480 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002481
Andy Adamsond0179312008-12-23 16:06:17 -05002482 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002483}
2484
2485/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 * Encode a WRITE request
2487 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002488static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002489 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002492 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494
Chuck Lever9f06c712010-12-14 14:59:18 +00002495 encode_compound_hdr(xdr, req, &hdr);
2496 encode_sequence(xdr, &args->seq_args, &hdr);
2497 encode_putfh(xdr, args->fh, &hdr);
2498 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002499 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002500 if (args->bitmask)
2501 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002502 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503}
2504
2505/*
2506 * a COMMIT request
2507 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002508static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002509 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002512 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514
Chuck Lever9f06c712010-12-14 14:59:18 +00002515 encode_compound_hdr(xdr, req, &hdr);
2516 encode_sequence(xdr, &args->seq_args, &hdr);
2517 encode_putfh(xdr, args->fh, &hdr);
2518 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002519 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520}
2521
2522/*
2523 * FSINFO request
2524 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002525static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2526 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002529 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
Chuck Lever9f06c712010-12-14 14:59:18 +00002532 encode_compound_hdr(xdr, req, &hdr);
2533 encode_sequence(xdr, &args->seq_args, &hdr);
2534 encode_putfh(xdr, args->fh, &hdr);
2535 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002536 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537}
2538
2539/*
2540 * a PATHCONF request
2541 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002542static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2543 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002546 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548
Chuck Lever9f06c712010-12-14 14:59:18 +00002549 encode_compound_hdr(xdr, req, &hdr);
2550 encode_sequence(xdr, &args->seq_args, &hdr);
2551 encode_putfh(xdr, args->fh, &hdr);
2552 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002553 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002554 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555}
2556
2557/*
2558 * a STATFS request
2559 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002560static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2561 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002564 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
Chuck Lever9f06c712010-12-14 14:59:18 +00002567 encode_compound_hdr(xdr, req, &hdr);
2568 encode_sequence(xdr, &args->seq_args, &hdr);
2569 encode_putfh(xdr, args->fh, &hdr);
2570 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002571 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002572 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573}
2574
2575/*
2576 * GETATTR_BITMAP request
2577 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002578static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2579 struct xdr_stream *xdr,
2580 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002583 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585
Chuck Lever9f06c712010-12-14 14:59:18 +00002586 encode_compound_hdr(xdr, req, &hdr);
2587 encode_sequence(xdr, &args->seq_args, &hdr);
2588 encode_putfh(xdr, args->fhandle, &hdr);
2589 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002590 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002591 FATTR4_WORD0_LINK_SUPPORT|
2592 FATTR4_WORD0_SYMLINK_SUPPORT|
2593 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002594 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595}
2596
2597/*
2598 * a RENEW request
2599 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002600static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2601 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002604 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 };
2606
Chuck Lever9f06c712010-12-14 14:59:18 +00002607 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002608 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002609 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610}
2611
2612/*
2613 * a SETCLIENTID request
2614 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002615static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2616 struct xdr_stream *xdr,
2617 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002620 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 };
2622
Chuck Lever9f06c712010-12-14 14:59:18 +00002623 encode_compound_hdr(xdr, req, &hdr);
2624 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002625 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626}
2627
2628/*
2629 * a SETCLIENTID_CONFIRM request
2630 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002631static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2632 struct xdr_stream *xdr,
2633 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002636 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638
Chuck Lever9f06c712010-12-14 14:59:18 +00002639 encode_compound_hdr(xdr, req, &hdr);
2640 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002641 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642}
2643
2644/*
2645 * DELEGRETURN request
2646 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002647static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2648 struct xdr_stream *xdr,
2649 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002652 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
Chuck Lever9f06c712010-12-14 14:59:18 +00002655 encode_compound_hdr(xdr, req, &hdr);
2656 encode_sequence(xdr, &args->seq_args, &hdr);
2657 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002658 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002659 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002660 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661}
2662
2663/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002664 * Encode FS_LOCATIONS request
2665 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002666static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2667 struct xdr_stream *xdr,
2668 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002669{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002670 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002671 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002672 };
Benny Halevy28f56692009-04-01 09:22:09 -04002673 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002674
Chuck Lever9f06c712010-12-14 14:59:18 +00002675 encode_compound_hdr(xdr, req, &hdr);
2676 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002677 if (args->migration) {
2678 encode_putfh(xdr, args->fh, &hdr);
2679 replen = hdr.replen;
2680 encode_fs_locations(xdr, args->bitmask, &hdr);
2681 if (args->renew)
2682 encode_renew(xdr, args->clientid, &hdr);
2683 } else {
2684 encode_putfh(xdr, args->dir_fh, &hdr);
2685 encode_lookup(xdr, args->name, &hdr);
2686 replen = hdr.replen;
2687 encode_fs_locations(xdr, args->bitmask, &hdr);
2688 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002689
Chuck Leverb03d7352013-10-17 14:12:50 -04002690 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002691 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002692 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002693 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002694}
2695
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002696/*
2697 * Encode SECINFO request
2698 */
2699static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2700 struct xdr_stream *xdr,
2701 struct nfs4_secinfo_arg *args)
2702{
2703 struct compound_hdr hdr = {
2704 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2705 };
2706
2707 encode_compound_hdr(xdr, req, &hdr);
2708 encode_sequence(xdr, &args->seq_args, &hdr);
2709 encode_putfh(xdr, args->dir_fh, &hdr);
2710 encode_secinfo(xdr, args->name, &hdr);
2711 encode_nops(&hdr);
2712}
2713
Chuck Lever44c99932013-10-17 14:13:30 -04002714/*
2715 * Encode FSID_PRESENT request
2716 */
2717static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2718 struct xdr_stream *xdr,
2719 struct nfs4_fsid_present_arg *args)
2720{
2721 struct compound_hdr hdr = {
2722 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2723 };
2724
2725 encode_compound_hdr(xdr, req, &hdr);
2726 encode_sequence(xdr, &args->seq_args, &hdr);
2727 encode_putfh(xdr, args->fh, &hdr);
2728 encode_getfh(xdr, &hdr);
2729 if (args->renew)
2730 encode_renew(xdr, args->clientid, &hdr);
2731 encode_nops(&hdr);
2732}
2733
Benny Halevy99fe60d2009-04-01 09:22:29 -04002734#if defined(CONFIG_NFS_V4_1)
2735/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002736 * BIND_CONN_TO_SESSION request
2737 */
2738static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2739 struct xdr_stream *xdr,
2740 struct nfs_client *clp)
2741{
2742 struct compound_hdr hdr = {
2743 .minorversion = clp->cl_mvops->minor_version,
2744 };
2745
2746 encode_compound_hdr(xdr, req, &hdr);
2747 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2748 encode_nops(&hdr);
2749}
2750
2751/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002752 * EXCHANGE_ID request
2753 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002754static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2755 struct xdr_stream *xdr,
2756 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002757{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002758 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002759 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002760 };
2761
Chuck Lever9f06c712010-12-14 14:59:18 +00002762 encode_compound_hdr(xdr, req, &hdr);
2763 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002764 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002765}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002766
2767/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002768 * a CREATE_SESSION request
2769 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002770static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2771 struct xdr_stream *xdr,
2772 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002773{
Andy Adamsonfc931582009-04-01 09:22:31 -04002774 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002775 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002776 };
2777
Chuck Lever9f06c712010-12-14 14:59:18 +00002778 encode_compound_hdr(xdr, req, &hdr);
2779 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002780 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002781}
2782
2783/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002784 * a DESTROY_SESSION request
2785 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002786static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2787 struct xdr_stream *xdr,
2788 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002789{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002790 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002791 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002792 };
2793
Chuck Lever9f06c712010-12-14 14:59:18 +00002794 encode_compound_hdr(xdr, req, &hdr);
2795 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002796 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002797}
2798
2799/*
Trond Myklebust66245532012-05-25 17:18:09 -04002800 * a DESTROY_CLIENTID request
2801 */
2802static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2803 struct xdr_stream *xdr,
2804 struct nfs_client *clp)
2805{
2806 struct compound_hdr hdr = {
2807 .minorversion = clp->cl_mvops->minor_version,
2808 };
2809
2810 encode_compound_hdr(xdr, req, &hdr);
2811 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2812 encode_nops(&hdr);
2813}
2814
2815/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002816 * a SEQUENCE request
2817 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002818static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2819 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002820{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002821 struct compound_hdr hdr = {
2822 .minorversion = nfs4_xdr_minorversion(args),
2823 };
2824
Chuck Lever9f06c712010-12-14 14:59:18 +00002825 encode_compound_hdr(xdr, req, &hdr);
2826 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002827 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002828}
2829
2830/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002831 * a GET_LEASE_TIME request
2832 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002833static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2834 struct xdr_stream *xdr,
2835 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002836{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002837 struct compound_hdr hdr = {
2838 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2839 };
Fred Isamandae100c2011-07-30 20:52:37 -04002840 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002841
Chuck Lever9f06c712010-12-14 14:59:18 +00002842 encode_compound_hdr(xdr, req, &hdr);
2843 encode_sequence(xdr, &args->la_seq_args, &hdr);
2844 encode_putrootfh(xdr, &hdr);
2845 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002846 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002847}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002848
2849/*
2850 * a RECLAIM_COMPLETE request
2851 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002852static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2853 struct xdr_stream *xdr,
2854 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002855{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002856 struct compound_hdr hdr = {
2857 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2858 };
2859
Chuck Lever9f06c712010-12-14 14:59:18 +00002860 encode_compound_hdr(xdr, req, &hdr);
2861 encode_sequence(xdr, &args->seq_args, &hdr);
2862 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002863 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002864}
2865
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002866/*
2867 * Encode GETDEVICEINFO request
2868 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002869static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2870 struct xdr_stream *xdr,
2871 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002872{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002873 struct compound_hdr hdr = {
2874 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2875 };
2876
Chuck Lever9f06c712010-12-14 14:59:18 +00002877 encode_compound_hdr(xdr, req, &hdr);
2878 encode_sequence(xdr, &args->seq_args, &hdr);
2879 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002880
2881 /* set up reply kvec. Subtract notification bitmap max size (2)
2882 * so that notification bitmap is put in xdr_buf tail */
2883 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2884 args->pdev->pages, args->pdev->pgbase,
2885 args->pdev->pglen);
2886
2887 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002888}
2889
2890/*
2891 * Encode LAYOUTGET request
2892 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002893static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2894 struct xdr_stream *xdr,
2895 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002896{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002897 struct compound_hdr hdr = {
2898 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2899 };
2900
Chuck Lever9f06c712010-12-14 14:59:18 +00002901 encode_compound_hdr(xdr, req, &hdr);
2902 encode_sequence(xdr, &args->seq_args, &hdr);
2903 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2904 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002905
2906 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2907 args->layout.pages, 0, args->layout.pglen);
2908
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002909 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002910}
Andy Adamson863a3c62011-03-23 13:27:54 +00002911
2912/*
2913 * Encode LAYOUTCOMMIT request
2914 */
Benny Halevycbe82602011-05-22 19:52:37 +03002915static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2916 struct xdr_stream *xdr,
2917 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002918{
Benny Halevyac7db722011-05-22 19:53:48 +03002919 struct nfs4_layoutcommit_data *data =
2920 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002921 struct compound_hdr hdr = {
2922 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2923 };
2924
2925 encode_compound_hdr(xdr, req, &hdr);
2926 encode_sequence(xdr, &args->seq_args, &hdr);
2927 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002928 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002929 encode_getfattr(xdr, args->bitmask, &hdr);
2930 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002931}
2932
2933/*
2934 * Encode LAYOUTRETURN request
2935 */
2936static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2937 struct xdr_stream *xdr,
2938 struct nfs4_layoutreturn_args *args)
2939{
2940 struct compound_hdr hdr = {
2941 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2942 };
2943
2944 encode_compound_hdr(xdr, req, &hdr);
2945 encode_sequence(xdr, &args->seq_args, &hdr);
2946 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2947 encode_layoutreturn(xdr, args, &hdr);
2948 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002949}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002950
2951/*
2952 * Encode SECINFO_NO_NAME request
2953 */
2954static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2955 struct xdr_stream *xdr,
2956 struct nfs41_secinfo_no_name_args *args)
2957{
2958 struct compound_hdr hdr = {
2959 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2960 };
2961
2962 encode_compound_hdr(xdr, req, &hdr);
2963 encode_sequence(xdr, &args->seq_args, &hdr);
2964 encode_putrootfh(xdr, &hdr);
2965 encode_secinfo_no_name(xdr, args, &hdr);
2966 encode_nops(&hdr);
2967 return 0;
2968}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002969
2970/*
2971 * Encode TEST_STATEID request
2972 */
2973static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2974 struct xdr_stream *xdr,
2975 struct nfs41_test_stateid_args *args)
2976{
2977 struct compound_hdr hdr = {
2978 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2979 };
2980
2981 encode_compound_hdr(xdr, req, &hdr);
2982 encode_sequence(xdr, &args->seq_args, &hdr);
2983 encode_test_stateid(xdr, args, &hdr);
2984 encode_nops(&hdr);
2985}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002986
2987/*
2988 * Encode FREE_STATEID request
2989 */
2990static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2991 struct xdr_stream *xdr,
2992 struct nfs41_free_stateid_args *args)
2993{
2994 struct compound_hdr hdr = {
2995 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2996 };
2997
2998 encode_compound_hdr(xdr, req, &hdr);
2999 encode_sequence(xdr, &args->seq_args, &hdr);
3000 encode_free_stateid(xdr, args, &hdr);
3001 encode_nops(&hdr);
3002}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003003#endif /* CONFIG_NFS_V4_1 */
3004
Benny Halevy686841b2009-08-14 17:19:48 +03003005static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3006{
3007 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3008 "Remaining buffer length is %tu words.\n",
3009 func, xdr->end - xdr->p);
3010}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011
Trond Myklebust683b57b2006-06-09 09:34:22 -04003012static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013{
Al Viro8687b632006-10-19 23:28:48 -07003014 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
Benny Halevyc0eae662009-08-14 17:20:14 +03003016 p = xdr_inline_decode(xdr, 4);
3017 if (unlikely(!p))
3018 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003019 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003020 p = xdr_inline_decode(xdr, *len);
3021 if (unlikely(!p))
3022 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 *string = (char *)p;
3024 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003025out_overflow:
3026 print_overflow_msg(__func__, xdr);
3027 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028}
3029
3030static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3031{
Al Viro8687b632006-10-19 23:28:48 -07003032 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033
Benny Halevyc0eae662009-08-14 17:20:14 +03003034 p = xdr_inline_decode(xdr, 8);
3035 if (unlikely(!p))
3036 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003037 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003038 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003039
Benny Halevyc0eae662009-08-14 17:20:14 +03003040 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3041 if (unlikely(!p))
3042 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 hdr->tag = (char *)p;
3044 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003045 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003046 if (unlikely(hdr->nops < 1))
3047 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003049out_overflow:
3050 print_overflow_msg(__func__, xdr);
3051 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052}
3053
Trond Myklebustc7848f62013-12-04 17:39:23 -05003054static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3055 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056{
Al Viro8687b632006-10-19 23:28:48 -07003057 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 uint32_t opnum;
3059 int32_t nfserr;
3060
Benny Halevyc0eae662009-08-14 17:20:14 +03003061 p = xdr_inline_decode(xdr, 8);
3062 if (unlikely(!p))
3063 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003064 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003065 if (unlikely(opnum != expected))
3066 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003067 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003068 if (nfserr == NFS_OK)
3069 *nfs_retval = 0;
3070 else
3071 *nfs_retval = nfs4_stat_to_errno(nfserr);
3072 return true;
3073out_bad_operation:
3074 dprintk("nfs: Server returned operation"
3075 " %d but we issued a request for %d\n",
3076 opnum, expected);
3077 *nfs_retval = -EREMOTEIO;
3078 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003079out_overflow:
3080 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003081 *nfs_retval = -EIO;
3082 return false;
3083}
3084
3085static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3086{
3087 int retval;
3088
3089 __decode_op_hdr(xdr, expected, &retval);
3090 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091}
3092
3093/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003094static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095{
Al Viro8687b632006-10-19 23:28:48 -07003096 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003097 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 char *str;
3099
Benny Halevyc0eae662009-08-14 17:20:14 +03003100 p = xdr_inline_decode(xdr, 12);
3101 if (likely(p))
3102 return decode_opaque_inline(xdr, &strlen, &str);
3103 print_overflow_msg(__func__, xdr);
3104 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105}
3106
3107static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3108{
Al Viro8687b632006-10-19 23:28:48 -07003109 uint32_t bmlen;
3110 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111
Benny Halevyc0eae662009-08-14 17:20:14 +03003112 p = xdr_inline_decode(xdr, 4);
3113 if (unlikely(!p))
3114 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003115 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116
Fred Isamandae100c2011-07-30 20:52:37 -04003117 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003118 p = xdr_inline_decode(xdr, (bmlen << 2));
3119 if (unlikely(!p))
3120 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003122 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003123 if (bmlen > 1) {
3124 bitmap[1] = be32_to_cpup(p++);
3125 if (bmlen > 2)
3126 bitmap[2] = be32_to_cpup(p);
3127 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 }
3129 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
Trond Myklebust256e48b2012-06-21 11:18:13 -04003135static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136{
Al Viro8687b632006-10-19 23:28:48 -07003137 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138
Benny Halevyc0eae662009-08-14 17:20:14 +03003139 p = xdr_inline_decode(xdr, 4);
3140 if (unlikely(!p))
3141 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003142 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003143 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003145out_overflow:
3146 print_overflow_msg(__func__, xdr);
3147 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148}
3149
3150static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3151{
3152 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003153 int ret;
3154 ret = decode_attr_bitmap(xdr, bitmask);
3155 if (unlikely(ret < 0))
3156 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3158 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003159 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3160 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3161 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 return 0;
3163}
3164
3165static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3166{
Al Viro8687b632006-10-19 23:28:48 -07003167 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003168 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
3170 *type = 0;
3171 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3172 return -EIO;
3173 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003174 p = xdr_inline_decode(xdr, 4);
3175 if (unlikely(!p))
3176 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003177 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003179 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 return -EIO;
3181 }
3182 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003183 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003185 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003186 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003187out_overflow:
3188 print_overflow_msg(__func__, xdr);
3189 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190}
3191
Chuck Lever264e6352012-03-01 17:02:05 -05003192static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3193 uint32_t *bitmap, uint32_t *type)
3194{
3195 __be32 *p;
3196
3197 *type = 0;
3198 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3199 return -EIO;
3200 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3201 p = xdr_inline_decode(xdr, 4);
3202 if (unlikely(!p))
3203 goto out_overflow;
3204 *type = be32_to_cpup(p);
3205 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3206 }
3207 dprintk("%s: expire type=0x%x\n", __func__, *type);
3208 return 0;
3209out_overflow:
3210 print_overflow_msg(__func__, xdr);
3211 return -EIO;
3212}
3213
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3215{
Al Viro8687b632006-10-19 23:28:48 -07003216 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003217 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218
3219 *change = 0;
3220 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3221 return -EIO;
3222 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003223 p = xdr_inline_decode(xdr, 8);
3224 if (unlikely(!p))
3225 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003226 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003228 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003230 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003232 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003233out_overflow:
3234 print_overflow_msg(__func__, xdr);
3235 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236}
3237
3238static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3239{
Al Viro8687b632006-10-19 23:28:48 -07003240 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003241 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242
3243 *size = 0;
3244 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3245 return -EIO;
3246 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003247 p = xdr_inline_decode(xdr, 8);
3248 if (unlikely(!p))
3249 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003250 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003252 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003254 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003255 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003256out_overflow:
3257 print_overflow_msg(__func__, xdr);
3258 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259}
3260
3261static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3262{
Al Viro8687b632006-10-19 23:28:48 -07003263 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264
3265 *res = 0;
3266 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3267 return -EIO;
3268 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003269 p = xdr_inline_decode(xdr, 4);
3270 if (unlikely(!p))
3271 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003272 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3274 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003275 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003277out_overflow:
3278 print_overflow_msg(__func__, xdr);
3279 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280}
3281
3282static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3283{
Al Viro8687b632006-10-19 23:28:48 -07003284 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
3286 *res = 0;
3287 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3288 return -EIO;
3289 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003290 p = xdr_inline_decode(xdr, 4);
3291 if (unlikely(!p))
3292 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003293 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3295 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003296 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003298out_overflow:
3299 print_overflow_msg(__func__, xdr);
3300 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301}
3302
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003303static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304{
Al Viro8687b632006-10-19 23:28:48 -07003305 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003306 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307
3308 fsid->major = 0;
3309 fsid->minor = 0;
3310 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3311 return -EIO;
3312 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003313 p = xdr_inline_decode(xdr, 16);
3314 if (unlikely(!p))
3315 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003316 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003317 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003319 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003321 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 (unsigned long long)fsid->major,
3323 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003324 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003325out_overflow:
3326 print_overflow_msg(__func__, xdr);
3327 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328}
3329
3330static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3331{
Al Viro8687b632006-10-19 23:28:48 -07003332 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333
3334 *res = 60;
3335 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3336 return -EIO;
3337 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003338 p = xdr_inline_decode(xdr, 4);
3339 if (unlikely(!p))
3340 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003341 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3343 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003344 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003346out_overflow:
3347 print_overflow_msg(__func__, xdr);
3348 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349}
3350
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003351static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003352{
3353 __be32 *p;
3354
3355 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3356 return -EIO;
3357 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3358 p = xdr_inline_decode(xdr, 4);
3359 if (unlikely(!p))
3360 goto out_overflow;
3361 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003362 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003363 }
3364 return 0;
3365out_overflow:
3366 print_overflow_msg(__func__, xdr);
3367 return -EIO;
3368}
3369
3370static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3371{
3372 __be32 *p;
3373 int len;
3374
Trond Myklebust7ad07352010-10-23 15:34:20 -04003375 if (fh != NULL)
3376 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003377
3378 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3379 return -EIO;
3380 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3381 p = xdr_inline_decode(xdr, 4);
3382 if (unlikely(!p))
3383 goto out_overflow;
3384 len = be32_to_cpup(p);
3385 if (len > NFS4_FHSIZE)
3386 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003387 p = xdr_inline_decode(xdr, len);
3388 if (unlikely(!p))
3389 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003390 if (fh != NULL) {
3391 memcpy(fh->data, p, len);
3392 fh->size = len;
3393 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003394 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3395 }
3396 return 0;
3397out_overflow:
3398 print_overflow_msg(__func__, xdr);
3399 return -EIO;
3400}
3401
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3403{
Al Viro8687b632006-10-19 23:28:48 -07003404 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003406 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3408 return -EIO;
3409 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003410 p = xdr_inline_decode(xdr, 4);
3411 if (unlikely(!p))
3412 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003413 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3415 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003416 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003418out_overflow:
3419 print_overflow_msg(__func__, xdr);
3420 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421}
3422
3423static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3424{
Al Viro8687b632006-10-19 23:28:48 -07003425 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003426 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427
3428 *fileid = 0;
3429 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3430 return -EIO;
3431 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003432 p = xdr_inline_decode(xdr, 8);
3433 if (unlikely(!p))
3434 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003435 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003437 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003439 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003440 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003441out_overflow:
3442 print_overflow_msg(__func__, xdr);
3443 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444}
3445
Manoj Naik99baf622006-06-09 09:34:24 -04003446static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3447{
Al Viro8687b632006-10-19 23:28:48 -07003448 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003449 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003450
3451 *fileid = 0;
3452 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3453 return -EIO;
3454 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003455 p = xdr_inline_decode(xdr, 8);
3456 if (unlikely(!p))
3457 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003458 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003459 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003460 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003461 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003462 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003463 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003464out_overflow:
3465 print_overflow_msg(__func__, xdr);
3466 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003467}
3468
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3470{
Al Viro8687b632006-10-19 23:28:48 -07003471 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 int status = 0;
3473
3474 *res = 0;
3475 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3476 return -EIO;
3477 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003478 p = xdr_inline_decode(xdr, 8);
3479 if (unlikely(!p))
3480 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003481 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3483 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003484 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003486out_overflow:
3487 print_overflow_msg(__func__, xdr);
3488 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489}
3490
3491static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3492{
Al Viro8687b632006-10-19 23:28:48 -07003493 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 int status = 0;
3495
3496 *res = 0;
3497 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3498 return -EIO;
3499 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003500 p = xdr_inline_decode(xdr, 8);
3501 if (unlikely(!p))
3502 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003503 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3505 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003506 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003508out_overflow:
3509 print_overflow_msg(__func__, xdr);
3510 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511}
3512
3513static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3514{
Al Viro8687b632006-10-19 23:28:48 -07003515 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 int status = 0;
3517
3518 *res = 0;
3519 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3520 return -EIO;
3521 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003522 p = xdr_inline_decode(xdr, 8);
3523 if (unlikely(!p))
3524 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003525 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3527 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003528 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003530out_overflow:
3531 print_overflow_msg(__func__, xdr);
3532 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533}
3534
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003535static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3536{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003537 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003538 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003539 int status = 0;
3540
Benny Halevyc0eae662009-08-14 17:20:14 +03003541 p = xdr_inline_decode(xdr, 4);
3542 if (unlikely(!p))
3543 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003544 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003545 if (n == 0)
3546 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003547 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003548 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3549 dprintk("cannot parse %d components in path\n", n);
3550 goto out_eio;
3551 }
3552 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003553 struct nfs4_string *component = &path->components[path->ncomponents];
3554 status = decode_opaque_inline(xdr, &component->len, &component->data);
3555 if (unlikely(status != 0))
3556 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003557 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003558 pr_cont("%s%.*s ",
3559 (path->ncomponents != n ? "/ " : ""),
3560 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003561 }
3562out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003563 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003564root_path:
3565/* a root pathname is sent as a zero component4 */
3566 path->ncomponents = 1;
3567 path->components[0].len=0;
3568 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003569 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003570 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003571out_eio:
3572 dprintk(" status %d", status);
3573 status = -EIO;
3574 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003575out_overflow:
3576 print_overflow_msg(__func__, xdr);
3577 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003578}
3579
3580static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003581{
3582 int n;
Al Viro8687b632006-10-19 23:28:48 -07003583 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003584 int status = -EIO;
3585
3586 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3587 goto out;
3588 status = 0;
3589 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3590 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003591 status = -EIO;
3592 /* Ignore borken servers that return unrequested attrs */
3593 if (unlikely(res == NULL))
3594 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003595 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003596 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003597 if (unlikely(status != 0))
3598 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003599 p = xdr_inline_decode(xdr, 4);
3600 if (unlikely(!p))
3601 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003602 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003603 if (n <= 0)
3604 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003605 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003606 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003607 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003608
Trond Myklebust809b4262013-03-27 11:54:45 -04003609 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3610 break;
3611 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003612 p = xdr_inline_decode(xdr, 4);
3613 if (unlikely(!p))
3614 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003615 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003616
Chuck Lever02a29762012-03-01 17:00:31 -05003617 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003618 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3619 struct nfs4_string *server;
3620
3621 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003622 unsigned int i;
3623 dprintk("%s: using first %u of %u servers "
3624 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003625 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003626 NFS4_FS_LOCATION_MAXSERVERS,
3627 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003628 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003629 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003630 char *data;
3631 status = decode_opaque_inline(xdr, &len, &data);
3632 if (unlikely(status != 0))
3633 goto out_eio;
3634 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003635 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003636 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003637 server = &loc->servers[loc->nservers];
3638 status = decode_opaque_inline(xdr, &server->len, &server->data);
3639 if (unlikely(status != 0))
3640 goto out_eio;
3641 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003642 }
3643 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003644 if (unlikely(status != 0))
3645 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003646 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003647 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003648 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003649out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003650 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003651 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003652out_overflow:
3653 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003654out_eio:
3655 status = -EIO;
3656 goto out;
3657}
3658
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3660{
Al Viro8687b632006-10-19 23:28:48 -07003661 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 int status = 0;
3663
3664 *res = 0;
3665 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3666 return -EIO;
3667 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003668 p = xdr_inline_decode(xdr, 8);
3669 if (unlikely(!p))
3670 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003671 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3673 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003674 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003676out_overflow:
3677 print_overflow_msg(__func__, xdr);
3678 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679}
3680
3681static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3682{
Al Viro8687b632006-10-19 23:28:48 -07003683 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 int status = 0;
3685
3686 *maxlink = 1;
3687 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3688 return -EIO;
3689 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003690 p = xdr_inline_decode(xdr, 4);
3691 if (unlikely(!p))
3692 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003693 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3695 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003696 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003698out_overflow:
3699 print_overflow_msg(__func__, xdr);
3700 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701}
3702
3703static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3704{
Al Viro8687b632006-10-19 23:28:48 -07003705 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706 int status = 0;
3707
3708 *maxname = 1024;
3709 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3710 return -EIO;
3711 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003712 p = xdr_inline_decode(xdr, 4);
3713 if (unlikely(!p))
3714 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003715 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3717 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003718 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003720out_overflow:
3721 print_overflow_msg(__func__, xdr);
3722 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723}
3724
3725static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3726{
Al Viro8687b632006-10-19 23:28:48 -07003727 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 int status = 0;
3729
3730 *res = 1024;
3731 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3732 return -EIO;
3733 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3734 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003735 p = xdr_inline_decode(xdr, 8);
3736 if (unlikely(!p))
3737 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003738 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 if (maxread > 0x7FFFFFFF)
3740 maxread = 0x7FFFFFFF;
3741 *res = (uint32_t)maxread;
3742 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3743 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003744 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003746out_overflow:
3747 print_overflow_msg(__func__, xdr);
3748 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749}
3750
3751static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3752{
Al Viro8687b632006-10-19 23:28:48 -07003753 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 int status = 0;
3755
3756 *res = 1024;
3757 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3758 return -EIO;
3759 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3760 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003761 p = xdr_inline_decode(xdr, 8);
3762 if (unlikely(!p))
3763 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003764 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 if (maxwrite > 0x7FFFFFFF)
3766 maxwrite = 0x7FFFFFFF;
3767 *res = (uint32_t)maxwrite;
3768 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3769 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003770 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003772out_overflow:
3773 print_overflow_msg(__func__, xdr);
3774 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775}
3776
Trond Myklebustbca79472009-03-11 14:10:26 -04003777static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778{
Trond Myklebustbca79472009-03-11 14:10:26 -04003779 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003780 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003781 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782
3783 *mode = 0;
3784 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3785 return -EIO;
3786 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003787 p = xdr_inline_decode(xdr, 4);
3788 if (unlikely(!p))
3789 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003790 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003791 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003793 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003795 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003796 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003797out_overflow:
3798 print_overflow_msg(__func__, xdr);
3799 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800}
3801
3802static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3803{
Al Viro8687b632006-10-19 23:28:48 -07003804 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003805 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806
3807 *nlink = 1;
3808 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3809 return -EIO;
3810 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003811 p = xdr_inline_decode(xdr, 4);
3812 if (unlikely(!p))
3813 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003814 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003816 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003818 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003819 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003820out_overflow:
3821 print_overflow_msg(__func__, xdr);
3822 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823}
3824
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003825static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003826 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003827 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828{
Al Viro8687b632006-10-19 23:28:48 -07003829 uint32_t len;
3830 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003831 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832
Eric W. Biedermane5782072013-02-01 14:22:02 -08003833 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3835 return -EIO;
3836 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003837 p = xdr_inline_decode(xdr, 4);
3838 if (unlikely(!p))
3839 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003840 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003841 p = xdr_inline_decode(xdr, len);
3842 if (unlikely(!p))
3843 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003844 if (owner_name != NULL) {
3845 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3846 if (owner_name->data != NULL) {
3847 owner_name->len = len;
3848 ret = NFS_ATTR_FATTR_OWNER_NAME;
3849 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003850 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003851 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003852 ret = NFS_ATTR_FATTR_OWNER;
3853 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003855 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003857 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003858 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3860 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003861 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003862 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003863out_overflow:
3864 print_overflow_msg(__func__, xdr);
3865 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866}
3867
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003868static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003869 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003870 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871{
Al Viro8687b632006-10-19 23:28:48 -07003872 uint32_t len;
3873 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003874 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875
Eric W. Biedermane5782072013-02-01 14:22:02 -08003876 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3878 return -EIO;
3879 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003880 p = xdr_inline_decode(xdr, 4);
3881 if (unlikely(!p))
3882 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003883 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003884 p = xdr_inline_decode(xdr, len);
3885 if (unlikely(!p))
3886 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003887 if (group_name != NULL) {
3888 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3889 if (group_name->data != NULL) {
3890 group_name->len = len;
3891 ret = NFS_ATTR_FATTR_GROUP_NAME;
3892 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003893 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003894 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003895 ret = NFS_ATTR_FATTR_GROUP;
3896 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003898 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003900 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003901 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3903 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003904 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003905 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003906out_overflow:
3907 print_overflow_msg(__func__, xdr);
3908 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909}
3910
3911static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3912{
Al Viro8687b632006-10-19 23:28:48 -07003913 uint32_t major = 0, minor = 0;
3914 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003915 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916
3917 *rdev = MKDEV(0,0);
3918 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3919 return -EIO;
3920 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3921 dev_t tmp;
3922
Benny Halevyc0eae662009-08-14 17:20:14 +03003923 p = xdr_inline_decode(xdr, 8);
3924 if (unlikely(!p))
3925 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003926 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003927 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928 tmp = MKDEV(major, minor);
3929 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3930 *rdev = tmp;
3931 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003932 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003934 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003935 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003936out_overflow:
3937 print_overflow_msg(__func__, xdr);
3938 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939}
3940
3941static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3942{
Al Viro8687b632006-10-19 23:28:48 -07003943 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 int status = 0;
3945
3946 *res = 0;
3947 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3948 return -EIO;
3949 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003950 p = xdr_inline_decode(xdr, 8);
3951 if (unlikely(!p))
3952 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003953 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3955 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003956 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003958out_overflow:
3959 print_overflow_msg(__func__, xdr);
3960 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961}
3962
3963static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3964{
Al Viro8687b632006-10-19 23:28:48 -07003965 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 int status = 0;
3967
3968 *res = 0;
3969 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3970 return -EIO;
3971 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003972 p = xdr_inline_decode(xdr, 8);
3973 if (unlikely(!p))
3974 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003975 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3977 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003978 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003980out_overflow:
3981 print_overflow_msg(__func__, xdr);
3982 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983}
3984
3985static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3986{
Al Viro8687b632006-10-19 23:28:48 -07003987 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 int status = 0;
3989
3990 *res = 0;
3991 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3992 return -EIO;
3993 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003994 p = xdr_inline_decode(xdr, 8);
3995 if (unlikely(!p))
3996 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003997 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3999 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004000 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004002out_overflow:
4003 print_overflow_msg(__func__, xdr);
4004 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005}
4006
4007static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4008{
Al Viro8687b632006-10-19 23:28:48 -07004009 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004010 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011
4012 *used = 0;
4013 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4014 return -EIO;
4015 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004016 p = xdr_inline_decode(xdr, 8);
4017 if (unlikely(!p))
4018 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004019 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004021 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004023 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004025 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004026out_overflow:
4027 print_overflow_msg(__func__, xdr);
4028 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029}
4030
4031static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4032{
Al Viro8687b632006-10-19 23:28:48 -07004033 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 uint64_t sec;
4035 uint32_t nsec;
4036
Benny Halevyc0eae662009-08-14 17:20:14 +03004037 p = xdr_inline_decode(xdr, 12);
4038 if (unlikely(!p))
4039 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004040 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004041 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 time->tv_sec = (time_t)sec;
4043 time->tv_nsec = (long)nsec;
4044 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004045out_overflow:
4046 print_overflow_msg(__func__, xdr);
4047 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048}
4049
4050static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4051{
4052 int status = 0;
4053
4054 time->tv_sec = 0;
4055 time->tv_nsec = 0;
4056 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4057 return -EIO;
4058 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4059 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004060 if (status == 0)
4061 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4063 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004064 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065 return status;
4066}
4067
4068static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4069{
4070 int status = 0;
4071
4072 time->tv_sec = 0;
4073 time->tv_nsec = 0;
4074 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4075 return -EIO;
4076 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4077 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004078 if (status == 0)
4079 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4081 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004082 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083 return status;
4084}
4085
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004086static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4087 struct timespec *time)
4088{
4089 int status = 0;
4090
4091 time->tv_sec = 0;
4092 time->tv_nsec = 0;
4093 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4094 return -EIO;
4095 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4096 status = decode_attr_time(xdr, time);
4097 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4098 }
4099 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4100 (long)time->tv_nsec);
4101 return status;
4102}
4103
David Quigleyaa9c2662013-05-22 12:50:44 -04004104static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4105 struct nfs4_label *label)
4106{
4107 uint32_t pi = 0;
4108 uint32_t lfs = 0;
4109 __u32 len;
4110 __be32 *p;
4111 int status = 0;
4112
4113 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4114 return -EIO;
4115 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4116 p = xdr_inline_decode(xdr, 4);
4117 if (unlikely(!p))
4118 goto out_overflow;
4119 lfs = be32_to_cpup(p++);
4120 p = xdr_inline_decode(xdr, 4);
4121 if (unlikely(!p))
4122 goto out_overflow;
4123 pi = be32_to_cpup(p++);
4124 p = xdr_inline_decode(xdr, 4);
4125 if (unlikely(!p))
4126 goto out_overflow;
4127 len = be32_to_cpup(p++);
4128 p = xdr_inline_decode(xdr, len);
4129 if (unlikely(!p))
4130 goto out_overflow;
4131 if (len < NFS4_MAXLABELLEN) {
4132 if (label) {
4133 memcpy(label->label, p, len);
4134 label->len = len;
4135 label->pi = pi;
4136 label->lfs = lfs;
4137 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4138 }
4139 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4140 } else
4141 printk(KERN_WARNING "%s: label too long (%u)!\n",
4142 __func__, len);
4143 }
4144 if (label && label->label)
4145 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4146 (char *)label->label, label->len, label->pi, label->lfs);
4147 return status;
4148
4149out_overflow:
4150 print_overflow_msg(__func__, xdr);
4151 return -EIO;
4152}
4153
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4155{
4156 int status = 0;
4157
4158 time->tv_sec = 0;
4159 time->tv_nsec = 0;
4160 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4161 return -EIO;
4162 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4163 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004164 if (status == 0)
4165 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4167 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004168 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 return status;
4170}
4171
Trond Myklebust256e48b2012-06-21 11:18:13 -04004172static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173{
4174 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004175 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176
4177 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004178 dprintk("%s: server returned incorrect attribute length: "
4179 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004180 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181 attrwords << 2,
4182 (attrwords < nwords) ? '<' : '>',
4183 nwords << 2);
4184 return -EIO;
4185 }
4186 return 0;
4187}
4188
4189static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4190{
Al Viro8687b632006-10-19 23:28:48 -07004191 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192
Benny Halevyc0eae662009-08-14 17:20:14 +03004193 p = xdr_inline_decode(xdr, 20);
4194 if (unlikely(!p))
4195 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004196 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004197 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004198 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004200out_overflow:
4201 print_overflow_msg(__func__, xdr);
4202 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203}
4204
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004205static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206{
Al Viro8687b632006-10-19 23:28:48 -07004207 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 uint32_t supp, acc;
4209 int status;
4210
4211 status = decode_op_hdr(xdr, OP_ACCESS);
4212 if (status)
4213 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004214 p = xdr_inline_decode(xdr, 8);
4215 if (unlikely(!p))
4216 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004217 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004218 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004219 *supported = supp;
4220 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004222out_overflow:
4223 print_overflow_msg(__func__, xdr);
4224 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225}
4226
Benny Halevy07d30432009-08-14 17:19:52 +03004227static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228{
Al Viro8687b632006-10-19 23:28:48 -07004229 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004230
4231 p = xdr_inline_decode(xdr, len);
4232 if (likely(p)) {
4233 memcpy(buf, p, len);
4234 return 0;
4235 }
4236 print_overflow_msg(__func__, xdr);
4237 return -EIO;
4238}
4239
4240static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4241{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004242 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243}
4244
4245static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4246{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 int status;
4248
4249 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004250 if (status != -EIO)
4251 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004252 if (!status)
4253 status = decode_stateid(xdr, &res->stateid);
4254 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004255}
4256
Benny Halevydb942bb2009-08-14 17:19:56 +03004257static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4258{
Chuck Levercd937102012-03-02 17:14:31 -05004259 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260}
4261
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004262static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4263{
4264 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4265}
4266
Fred Isaman0b7c0152012-04-20 14:47:39 -04004267static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 int status;
4270
4271 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004272 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004273 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004274 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275}
4276
4277static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4278{
Al Viro8687b632006-10-19 23:28:48 -07004279 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280 uint32_t bmlen;
4281 int status;
4282
4283 status = decode_op_hdr(xdr, OP_CREATE);
4284 if (status)
4285 return status;
4286 if ((status = decode_change_info(xdr, cinfo)))
4287 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004288 p = xdr_inline_decode(xdr, 4);
4289 if (unlikely(!p))
4290 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004291 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004292 p = xdr_inline_decode(xdr, bmlen << 2);
4293 if (likely(p))
4294 return 0;
4295out_overflow:
4296 print_overflow_msg(__func__, xdr);
4297 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298}
4299
4300static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4301{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004302 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004303 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304 int status;
4305
4306 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4307 goto xdr_error;
4308 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4309 goto xdr_error;
4310 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4311 goto xdr_error;
4312 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4313 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004314 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4315 &res->fh_expire_type)) != 0)
4316 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4318 goto xdr_error;
4319 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4320 goto xdr_error;
4321 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4322 goto xdr_error;
4323 status = verify_attr_len(xdr, savep, attrlen);
4324xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004325 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 return status;
4327}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004328
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4330{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004331 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004332 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004334
Linus Torvalds1da177e2005-04-16 15:20:36 -07004335 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4336 goto xdr_error;
4337 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4338 goto xdr_error;
4339 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4340 goto xdr_error;
4341
4342 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4343 goto xdr_error;
4344 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4345 goto xdr_error;
4346 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4347 goto xdr_error;
4348 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4349 goto xdr_error;
4350 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4351 goto xdr_error;
4352 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4353 goto xdr_error;
4354
4355 status = verify_attr_len(xdr, savep, attrlen);
4356xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004357 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358 return status;
4359}
4360
4361static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4362{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004363 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004364 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004366
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4368 goto xdr_error;
4369 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4370 goto xdr_error;
4371 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4372 goto xdr_error;
4373
4374 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4375 goto xdr_error;
4376 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4377 goto xdr_error;
4378
4379 status = verify_attr_len(xdr, savep, attrlen);
4380xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004381 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 return status;
4383}
4384
Andy Adamson88034c32012-05-23 05:02:34 -04004385static int decode_threshold_hint(struct xdr_stream *xdr,
4386 uint32_t *bitmap,
4387 uint64_t *res,
4388 uint32_t hint_bit)
4389{
4390 __be32 *p;
4391
4392 *res = 0;
4393 if (likely(bitmap[0] & hint_bit)) {
4394 p = xdr_inline_decode(xdr, 8);
4395 if (unlikely(!p))
4396 goto out_overflow;
4397 xdr_decode_hyper(p, res);
4398 }
4399 return 0;
4400out_overflow:
4401 print_overflow_msg(__func__, xdr);
4402 return -EIO;
4403}
4404
4405static int decode_first_threshold_item4(struct xdr_stream *xdr,
4406 struct nfs4_threshold *res)
4407{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004408 __be32 *p;
4409 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004410 uint32_t bitmap[3] = {0,}, attrlen;
4411 int status;
4412
4413 /* layout type */
4414 p = xdr_inline_decode(xdr, 4);
4415 if (unlikely(!p)) {
4416 print_overflow_msg(__func__, xdr);
4417 return -EIO;
4418 }
4419 res->l_type = be32_to_cpup(p);
4420
4421 /* thi_hintset bitmap */
4422 status = decode_attr_bitmap(xdr, bitmap);
4423 if (status < 0)
4424 goto xdr_error;
4425
4426 /* thi_hintlist length */
4427 status = decode_attr_length(xdr, &attrlen, &savep);
4428 if (status < 0)
4429 goto xdr_error;
4430 /* thi_hintlist */
4431 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4432 if (status < 0)
4433 goto xdr_error;
4434 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4435 if (status < 0)
4436 goto xdr_error;
4437 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4438 THRESHOLD_RD_IO);
4439 if (status < 0)
4440 goto xdr_error;
4441 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4442 THRESHOLD_WR_IO);
4443 if (status < 0)
4444 goto xdr_error;
4445
4446 status = verify_attr_len(xdr, savep, attrlen);
4447 res->bm = bitmap[0];
4448
4449 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4450 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4451 res->wr_io_sz);
4452xdr_error:
4453 dprintk("%s ret=%d!\n", __func__, status);
4454 return status;
4455}
4456
4457/*
4458 * Thresholds on pNFS direct I/O vrs MDS I/O
4459 */
4460static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4461 uint32_t *bitmap,
4462 struct nfs4_threshold *res)
4463{
4464 __be32 *p;
4465 int status = 0;
4466 uint32_t num;
4467
4468 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4469 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004470 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004471 /* Did the server return an unrequested attribute? */
4472 if (unlikely(res == NULL))
4473 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004474 p = xdr_inline_decode(xdr, 4);
4475 if (unlikely(!p))
4476 goto out_overflow;
4477 num = be32_to_cpup(p);
4478 if (num == 0)
4479 return 0;
4480 if (num > 1)
4481 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4482 "drivers per filesystem not supported\n",
4483 __func__);
4484
4485 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004486 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004487 }
4488 return status;
4489out_overflow:
4490 print_overflow_msg(__func__, xdr);
4491 return -EIO;
4492}
4493
Bryan Schumakerae42c702010-10-21 16:33:17 -04004494static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4495 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004496 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004497 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004498{
Trond Myklebustbca79472009-03-11 14:10:26 -04004499 int status;
4500 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004501 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004502 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004504 status = decode_attr_type(xdr, bitmap, &type);
4505 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004507 fattr->mode = 0;
4508 if (status != 0) {
4509 fattr->mode |= nfs_type2fmt[type];
4510 fattr->valid |= status;
4511 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004513 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4514 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004516 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004517
4518 status = decode_attr_size(xdr, bitmap, &fattr->size);
4519 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004520 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004521 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004522
4523 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4524 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004526 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004527
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004528 err = 0;
4529 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004530 if (status < 0)
4531 goto xdr_error;
4532
4533 status = decode_attr_filehandle(xdr, bitmap, fh);
4534 if (status < 0)
4535 goto xdr_error;
4536
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004537 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4538 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004540 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004541
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004542 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004543 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004544 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004545 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004546
4547 status = decode_attr_mode(xdr, bitmap, &fmode);
4548 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004550 if (status != 0) {
4551 fattr->mode |= fmode;
4552 fattr->valid |= status;
4553 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004554
4555 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4556 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004558 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004559
Trond Myklebust6926afd2012-01-07 13:22:46 -05004560 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004561 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
Trond Myklebust6926afd2012-01-07 13:22:46 -05004565 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004566 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_rdev(xdr, bitmap, &fattr->rdev);
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_space_used(xdr, bitmap, &fattr->du.nfs3.used);
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
4580 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4581 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004583 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004584
4585 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4586 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004588 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004589
4590 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4591 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004593 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004594
Trond Myklebust28331a42011-04-27 13:47:52 -04004595 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004596 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004597 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004598 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004599
Andy Adamson88034c32012-05-23 05:02:34 -04004600 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4601 if (status < 0)
4602 goto xdr_error;
4603
David Quigleyaa9c2662013-05-22 12:50:44 -04004604 if (label) {
4605 status = decode_attr_security_label(xdr, bitmap, label);
4606 if (status < 0)
4607 goto xdr_error;
4608 fattr->valid |= status;
4609 }
4610
Bryan Schumakerae42c702010-10-21 16:33:17 -04004611xdr_error:
4612 dprintk("%s: xdr returned %d\n", __func__, -status);
4613 return status;
4614}
4615
4616static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004617 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004618 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004619{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004620 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004621 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004622 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004623 int status;
4624
4625 status = decode_op_hdr(xdr, OP_GETATTR);
4626 if (status < 0)
4627 goto xdr_error;
4628
4629 status = decode_attr_bitmap(xdr, bitmap);
4630 if (status < 0)
4631 goto xdr_error;
4632
4633 status = decode_attr_length(xdr, &attrlen, &savep);
4634 if (status < 0)
4635 goto xdr_error;
4636
David Quigleyaa9c2662013-05-22 12:50:44 -04004637 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4638 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004639 if (status < 0)
4640 goto xdr_error;
4641
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004642 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004643xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004644 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 return status;
4646}
4647
David Quigleyaa9c2662013-05-22 12:50:44 -04004648static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4649 struct nfs4_label *label, const struct nfs_server *server)
4650{
4651 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4652}
4653
Bryan Schumakerae42c702010-10-21 16:33:17 -04004654static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004655 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004656{
David Quigleyaa9c2662013-05-22 12:50:44 -04004657 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004658}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659
Andy Adamson504913f2010-10-20 00:17:57 -04004660/*
4661 * Decode potentially multiple layout types. Currently we only support
4662 * one layout driver per file system.
4663 */
4664static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4665 uint32_t *layouttype)
4666{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004667 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004668 int num;
4669
4670 p = xdr_inline_decode(xdr, 4);
4671 if (unlikely(!p))
4672 goto out_overflow;
4673 num = be32_to_cpup(p);
4674
4675 /* pNFS is not supported by the underlying file system */
4676 if (num == 0) {
4677 *layouttype = 0;
4678 return 0;
4679 }
4680 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004681 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4682 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004683
4684 /* Decode and set first layout type, move xdr->p past unused types */
4685 p = xdr_inline_decode(xdr, num * 4);
4686 if (unlikely(!p))
4687 goto out_overflow;
4688 *layouttype = be32_to_cpup(p);
4689 return 0;
4690out_overflow:
4691 print_overflow_msg(__func__, xdr);
4692 return -EIO;
4693}
4694
4695/*
4696 * The type of file system exported.
4697 * Note we must ensure that layouttype is set in any non-error case.
4698 */
4699static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4700 uint32_t *layouttype)
4701{
4702 int status = 0;
4703
4704 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4705 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4706 return -EIO;
4707 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4708 status = decode_first_pnfs_layout_type(xdr, layouttype);
4709 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4710 } else
4711 *layouttype = 0;
4712 return status;
4713}
4714
Fred Isamandae100c2011-07-30 20:52:37 -04004715/*
4716 * The prefered block size for layout directed io
4717 */
4718static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4719 uint32_t *res)
4720{
4721 __be32 *p;
4722
4723 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4724 *res = 0;
4725 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4726 p = xdr_inline_decode(xdr, 4);
4727 if (unlikely(!p)) {
4728 print_overflow_msg(__func__, xdr);
4729 return -EIO;
4730 }
4731 *res = be32_to_cpup(p);
4732 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4733 }
4734 return 0;
4735}
4736
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4738{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004739 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004740 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 int status;
4742
4743 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4744 goto xdr_error;
4745 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4746 goto xdr_error;
4747 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4748 goto xdr_error;
4749
4750 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4751
4752 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4753 goto xdr_error;
4754 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4755 goto xdr_error;
4756 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4757 goto xdr_error;
4758 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4759 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4760 goto xdr_error;
4761 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004762 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4763 if (status != 0)
4764 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004765 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4766 if (status != 0)
4767 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004768 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4769 if (status)
4770 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771
4772 status = verify_attr_len(xdr, savep, attrlen);
4773xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004774 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775 return status;
4776}
4777
4778static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4779{
Al Viro8687b632006-10-19 23:28:48 -07004780 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781 uint32_t len;
4782 int status;
4783
Trond Myklebust99367812007-07-17 21:52:41 -04004784 /* Zero handle first to allow comparisons */
4785 memset(fh, 0, sizeof(*fh));
4786
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 status = decode_op_hdr(xdr, OP_GETFH);
4788 if (status)
4789 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790
Benny Halevyc0eae662009-08-14 17:20:14 +03004791 p = xdr_inline_decode(xdr, 4);
4792 if (unlikely(!p))
4793 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004794 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 if (len > NFS4_FHSIZE)
4796 return -EIO;
4797 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004798 p = xdr_inline_decode(xdr, len);
4799 if (unlikely(!p))
4800 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004801 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004803out_overflow:
4804 print_overflow_msg(__func__, xdr);
4805 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806}
4807
4808static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4809{
4810 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004811
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812 status = decode_op_hdr(xdr, OP_LINK);
4813 if (status)
4814 return status;
4815 return decode_change_info(xdr, cinfo);
4816}
4817
4818/*
4819 * We create the owner, so we know a proper owner.id length is 4.
4820 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004821static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004823 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004824 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004825 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004827 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004828 if (unlikely(!p))
4829 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004830 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004831 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004832 type = be32_to_cpup(p++); /* 4 byte read */
4833 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004834 fl->fl_start = (loff_t)offset;
4835 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4836 if (length == ~(uint64_t)0)
4837 fl->fl_end = OFFSET_MAX;
4838 fl->fl_type = F_WRLCK;
4839 if (type & 1)
4840 fl->fl_type = F_RDLCK;
4841 fl->fl_pid = 0;
4842 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004843 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4844 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4845 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004846 if (likely(p))
4847 return -NFS4ERR_DENIED;
4848out_overflow:
4849 print_overflow_msg(__func__, xdr);
4850 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851}
4852
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004853static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 int status;
4856
4857 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004858 if (status == -EIO)
4859 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004861 status = decode_stateid(xdr, &res->stateid);
4862 if (unlikely(status))
4863 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004865 status = decode_lock_denied(xdr, NULL);
4866 if (res->open_seqid != NULL)
4867 nfs_increment_open_seqid(status, res->open_seqid);
4868 nfs_increment_lock_seqid(status, res->lock_seqid);
4869out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870 return status;
4871}
4872
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004873static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874{
4875 int status;
4876 status = decode_op_hdr(xdr, OP_LOCKT);
4877 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004878 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 return status;
4880}
4881
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004882static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884 int status;
4885
4886 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004887 if (status != -EIO)
4888 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004889 if (status == 0)
4890 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891 return status;
4892}
4893
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004894static int decode_release_lockowner(struct xdr_stream *xdr)
4895{
4896 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4897}
4898
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899static int decode_lookup(struct xdr_stream *xdr)
4900{
4901 return decode_op_hdr(xdr, OP_LOOKUP);
4902}
4903
4904/* This is too sick! */
4905static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4906{
Andy Adamson05d564f2008-12-23 16:06:15 -05004907 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908 uint32_t limit_type, nblocks, blocksize;
4909
Benny Halevyc0eae662009-08-14 17:20:14 +03004910 p = xdr_inline_decode(xdr, 12);
4911 if (unlikely(!p))
4912 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004913 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004915 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004916 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004917 break;
4918 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004919 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004920 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004921 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922 }
4923 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004924out_overflow:
4925 print_overflow_msg(__func__, xdr);
4926 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004927}
4928
4929static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4930{
Andy Adamson05d564f2008-12-23 16:06:15 -05004931 __be32 *p;
4932 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004933 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004934
Benny Halevyc0eae662009-08-14 17:20:14 +03004935 p = xdr_inline_decode(xdr, 4);
4936 if (unlikely(!p))
4937 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004938 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4940 res->delegation_type = 0;
4941 return 0;
4942 }
Benny Halevy07d30432009-08-14 17:19:52 +03004943 status = decode_stateid(xdr, &res->delegation);
4944 if (unlikely(status))
4945 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004946 p = xdr_inline_decode(xdr, 4);
4947 if (unlikely(!p))
4948 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004949 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004950
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004952 case NFS4_OPEN_DELEGATE_READ:
4953 res->delegation_type = FMODE_READ;
4954 break;
4955 case NFS4_OPEN_DELEGATE_WRITE:
4956 res->delegation_type = FMODE_WRITE|FMODE_READ;
4957 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 return -EIO;
4959 }
David Howells7539bba2006-08-22 20:06:09 -04004960 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004961out_overflow:
4962 print_overflow_msg(__func__, xdr);
4963 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964}
4965
4966static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4967{
Andy Adamson05d564f2008-12-23 16:06:15 -05004968 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004969 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004970 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971
Trond Myklebustc7848f62013-12-04 17:39:23 -05004972 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
4973 return status;
4974 nfs_increment_open_seqid(status, res->seqid);
4975 if (status)
4976 return status;
4977 status = decode_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004978 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004979 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980
Andy Adamson05d564f2008-12-23 16:06:15 -05004981 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982
Benny Halevyc0eae662009-08-14 17:20:14 +03004983 p = xdr_inline_decode(xdr, 8);
4984 if (unlikely(!p))
4985 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004986 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004987 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004988 if (bmlen > 10)
4989 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990
Benny Halevyc0eae662009-08-14 17:20:14 +03004991 p = xdr_inline_decode(xdr, bmlen << 2);
4992 if (unlikely(!p))
4993 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004994 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4995 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004996 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004997 for (; i < NFS4_BITMAP_SIZE; i++)
4998 res->attrset[i] = 0;
4999
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000 return decode_delegation(xdr, res);
5001xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005002 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005004out_overflow:
5005 print_overflow_msg(__func__, xdr);
5006 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007}
5008
5009static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5010{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011 int status;
5012
Andy Adamson05d564f2008-12-23 16:06:15 -05005013 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005014 if (status != -EIO)
5015 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005016 if (!status)
5017 status = decode_stateid(xdr, &res->stateid);
5018 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019}
5020
5021static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5022{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023 int status;
5024
5025 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005026 if (status != -EIO)
5027 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005028 if (!status)
5029 status = decode_stateid(xdr, &res->stateid);
5030 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031}
5032
5033static int decode_putfh(struct xdr_stream *xdr)
5034{
5035 return decode_op_hdr(xdr, OP_PUTFH);
5036}
5037
5038static int decode_putrootfh(struct xdr_stream *xdr)
5039{
5040 return decode_op_hdr(xdr, OP_PUTROOTFH);
5041}
5042
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005043static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5044 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045{
Al Viro8687b632006-10-19 23:28:48 -07005046 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005047 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048 int status;
5049
5050 status = decode_op_hdr(xdr, OP_READ);
5051 if (status)
5052 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005053 p = xdr_inline_decode(xdr, 8);
5054 if (unlikely(!p))
5055 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005056 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005057 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005058 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005059 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005060 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061 "count %u > recvd %u\n", count, recvd);
5062 count = recvd;
5063 eof = 0;
5064 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065 res->eof = eof;
5066 res->count = count;
5067 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005068out_overflow:
5069 print_overflow_msg(__func__, xdr);
5070 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071}
5072
5073static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5074{
Chuck Leverbcecff72007-10-26 13:32:03 -04005075 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005076 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077
5078 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005079 if (!status)
5080 status = decode_verifier(xdr, readdir->verifier.data);
5081 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005083 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005084 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005085 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005086 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087}
5088
5089static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5090{
5091 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005092 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005093 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094 int status;
5095
5096 status = decode_op_hdr(xdr, OP_READLINK);
5097 if (status)
5098 return status;
5099
5100 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005101 p = xdr_inline_decode(xdr, 4);
5102 if (unlikely(!p))
5103 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005104 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005105 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005106 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107 return -ENAMETOOLONG;
5108 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005109 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005110 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005111 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112 "count %u > recvd %u\n", len, recvd);
5113 return -EIO;
5114 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115 /*
5116 * The XDR encode routine has set things up so that
5117 * the link text will be copied directly into the
5118 * buffer. We just have to do overflow-checking,
5119 * and and null-terminate the text (the VFS expects
5120 * null-termination).
5121 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005122 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005124out_overflow:
5125 print_overflow_msg(__func__, xdr);
5126 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127}
5128
5129static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5130{
5131 int status;
5132
5133 status = decode_op_hdr(xdr, OP_REMOVE);
5134 if (status)
5135 goto out;
5136 status = decode_change_info(xdr, cinfo);
5137out:
5138 return status;
5139}
5140
5141static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5142 struct nfs4_change_info *new_cinfo)
5143{
5144 int status;
5145
5146 status = decode_op_hdr(xdr, OP_RENAME);
5147 if (status)
5148 goto out;
5149 if ((status = decode_change_info(xdr, old_cinfo)))
5150 goto out;
5151 status = decode_change_info(xdr, new_cinfo);
5152out:
5153 return status;
5154}
5155
5156static int decode_renew(struct xdr_stream *xdr)
5157{
5158 return decode_op_hdr(xdr, OP_RENEW);
5159}
5160
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005161static int
5162decode_restorefh(struct xdr_stream *xdr)
5163{
5164 return decode_op_hdr(xdr, OP_RESTOREFH);
5165}
5166
J. Bruce Fields029d1052005-06-22 17:16:22 +00005167static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005168 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005169{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005170 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005171 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005172 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005173 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005174 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005175
Andy Adamsonbf118a32011-12-07 11:55:27 -05005176 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005177 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5178 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005179
Trond Myklebust519d3952012-08-14 17:30:10 -04005180 xdr_enter_page(xdr, xdr->buf->page_len);
5181
Trond Myklebustcff298c2012-08-14 17:14:17 -04005182 /* Calculate the offset of the page data */
5183 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005184
J. Bruce Fields029d1052005-06-22 17:16:22 +00005185 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5186 goto out;
5187 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5188 goto out;
5189
5190 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5191 return -EIO;
5192 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005193
Andy Adamsonbf118a32011-12-07 11:55:27 -05005194 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5195 * are stored with the acl data to handle the problem of
5196 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005197 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005198 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005199
5200 /* Check for receive buffer overflow */
5201 if (res->acl_len > (xdr->nwords << 2) ||
5202 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5203 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005204 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005205 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005206 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005207 } else
5208 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005209
5210out:
5211 return status;
5212}
5213
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214static int
5215decode_savefh(struct xdr_stream *xdr)
5216{
5217 return decode_op_hdr(xdr, OP_SAVEFH);
5218}
5219
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005220static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005221{
Al Viro8687b632006-10-19 23:28:48 -07005222 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 uint32_t bmlen;
5224 int status;
5225
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226 status = decode_op_hdr(xdr, OP_SETATTR);
5227 if (status)
5228 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005229 p = xdr_inline_decode(xdr, 4);
5230 if (unlikely(!p))
5231 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005232 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005233 p = xdr_inline_decode(xdr, bmlen << 2);
5234 if (likely(p))
5235 return 0;
5236out_overflow:
5237 print_overflow_msg(__func__, xdr);
5238 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239}
5240
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005241static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005242{
Al Viro8687b632006-10-19 23:28:48 -07005243 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005244 uint32_t opnum;
5245 int32_t nfserr;
5246
Benny Halevyc0eae662009-08-14 17:20:14 +03005247 p = xdr_inline_decode(xdr, 8);
5248 if (unlikely(!p))
5249 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005250 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005252 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005253 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254 return -EIO;
5255 }
Benny Halevycccddf42009-08-14 17:20:19 +03005256 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005258 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5259 if (unlikely(!p))
5260 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005261 p = xdr_decode_hyper(p, &res->clientid);
5262 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263 } else if (nfserr == NFSERR_CLID_INUSE) {
5264 uint32_t len;
5265
5266 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005267 p = xdr_inline_decode(xdr, 4);
5268 if (unlikely(!p))
5269 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005270 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005271 p = xdr_inline_decode(xdr, len);
5272 if (unlikely(!p))
5273 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274
5275 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005276 p = xdr_inline_decode(xdr, 4);
5277 if (unlikely(!p))
5278 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005279 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005280 p = xdr_inline_decode(xdr, len);
5281 if (unlikely(!p))
5282 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005283 return -NFSERR_CLID_INUSE;
5284 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005285 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286
5287 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005288out_overflow:
5289 print_overflow_msg(__func__, xdr);
5290 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005291}
5292
5293static int decode_setclientid_confirm(struct xdr_stream *xdr)
5294{
5295 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5296}
5297
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005298static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299{
Al Viro8687b632006-10-19 23:28:48 -07005300 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301 int status;
5302
5303 status = decode_op_hdr(xdr, OP_WRITE);
5304 if (status)
5305 return status;
5306
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005307 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005308 if (unlikely(!p))
5309 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005310 res->count = be32_to_cpup(p++);
5311 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005312 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005313out_overflow:
5314 print_overflow_msg(__func__, xdr);
5315 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316}
5317
5318static int decode_delegreturn(struct xdr_stream *xdr)
5319{
5320 return decode_op_hdr(xdr, OP_DELEGRETURN);
5321}
5322
Chuck Leverfb15b262013-03-16 15:54:34 -04005323static int decode_secinfo_gss(struct xdr_stream *xdr,
5324 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005325{
Chuck Leverfb15b262013-03-16 15:54:34 -04005326 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005327 __be32 *p;
5328
5329 p = xdr_inline_decode(xdr, 4);
5330 if (unlikely(!p))
5331 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005332 oid_len = be32_to_cpup(p);
5333 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005334 goto out_err;
5335
Chuck Leverfb15b262013-03-16 15:54:34 -04005336 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005337 if (unlikely(!p))
5338 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005339 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5340 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005341
5342 p = xdr_inline_decode(xdr, 8);
5343 if (unlikely(!p))
5344 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005345 flavor->flavor_info.qop = be32_to_cpup(p++);
5346 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005347
5348 return 0;
5349
5350out_overflow:
5351 print_overflow_msg(__func__, xdr);
5352 return -EIO;
5353out_err:
5354 return -EINVAL;
5355}
5356
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005357static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005358{
Chuck Leverfb15b262013-03-16 15:54:34 -04005359 struct nfs4_secinfo4 *sec_flavor;
5360 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005361 int status;
5362 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005363
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005364 p = xdr_inline_decode(xdr, 4);
5365 if (unlikely(!p))
5366 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005367
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005368 res->flavors->num_flavors = 0;
5369 num_flavors = be32_to_cpup(p);
5370
5371 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005372 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005373 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005374 break;
5375
5376 p = xdr_inline_decode(xdr, 4);
5377 if (unlikely(!p))
5378 goto out_overflow;
5379 sec_flavor->flavor = be32_to_cpup(p);
5380
5381 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005382 status = decode_secinfo_gss(xdr, sec_flavor);
5383 if (status)
5384 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005385 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005386 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005387 }
5388
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005389 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005390out:
5391 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005392out_overflow:
5393 print_overflow_msg(__func__, xdr);
5394 return -EIO;
5395}
5396
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005397static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5398{
5399 int status = decode_op_hdr(xdr, OP_SECINFO);
5400 if (status)
5401 return status;
5402 return decode_secinfo_common(xdr, res);
5403}
5404
Benny Halevy99fe60d2009-04-01 09:22:29 -04005405#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005406static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5407{
5408 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5409 if (status)
5410 return status;
5411 return decode_secinfo_common(xdr, res);
5412}
5413
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005414static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5415{
5416 __be32 *p;
5417 uint32_t bitmap_words;
5418 unsigned int i;
5419
5420 p = xdr_inline_decode(xdr, 4);
5421 bitmap_words = be32_to_cpup(p++);
5422 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5423 return -EIO;
5424 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5425 for (i = 0; i < bitmap_words; i++)
5426 op_map->u.words[i] = be32_to_cpup(p++);
5427
5428 return 0;
5429}
5430
Benny Halevy99fe60d2009-04-01 09:22:29 -04005431static int decode_exchange_id(struct xdr_stream *xdr,
5432 struct nfs41_exchange_id_res *res)
5433{
5434 __be32 *p;
5435 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005436 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005437 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005438 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005439
5440 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5441 if (status)
5442 return status;
5443
Benny Halevyc0eae662009-08-14 17:20:14 +03005444 p = xdr_inline_decode(xdr, 8);
5445 if (unlikely(!p))
5446 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005447 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005448 p = xdr_inline_decode(xdr, 12);
5449 if (unlikely(!p))
5450 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005451 res->seqid = be32_to_cpup(p++);
5452 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005453
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005454 res->state_protect.how = be32_to_cpup(p);
5455 switch (res->state_protect.how) {
5456 case SP4_NONE:
5457 break;
5458 case SP4_MACH_CRED:
5459 status = decode_op_map(xdr, &res->state_protect.enforce);
5460 if (status)
5461 return status;
5462 status = decode_op_map(xdr, &res->state_protect.allow);
5463 if (status)
5464 return status;
5465 break;
5466 default:
5467 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005468 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005469 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005470
Chuck Leveracdeb692012-05-21 22:46:16 -04005471 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005472 p = xdr_inline_decode(xdr, 8);
5473 if (unlikely(!p))
5474 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005475 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005476
Chuck Leveracdeb692012-05-21 22:46:16 -04005477 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005478 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5479 if (unlikely(status))
5480 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005481 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5482 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005483 memcpy(res->server_owner->major_id, dummy_str, dummy);
5484 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005485
Chuck Leveracdeb692012-05-21 22:46:16 -04005486 /* server_scope4 */
5487 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5488 if (unlikely(status))
5489 return status;
5490 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5491 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005492 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5493 res->server_scope->server_scope_sz = dummy;
5494
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005495 /* Implementation Id */
5496 p = xdr_inline_decode(xdr, 4);
5497 if (unlikely(!p))
5498 goto out_overflow;
5499 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005500
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005501 if (impl_id_count) {
5502 /* nii_domain */
5503 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5504 if (unlikely(status))
5505 return status;
5506 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5507 return -EIO;
5508 memcpy(res->impl_id->domain, dummy_str, dummy);
5509
5510 /* nii_name */
5511 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5512 if (unlikely(status))
5513 return status;
5514 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5515 return -EIO;
5516 memcpy(res->impl_id->name, dummy_str, dummy);
5517
5518 /* nii_date */
5519 p = xdr_inline_decode(xdr, 12);
5520 if (unlikely(!p))
5521 goto out_overflow;
5522 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5523 res->impl_id->date.nseconds = be32_to_cpup(p);
5524
5525 /* if there's more than one entry, ignore the rest */
5526 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005527 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005528out_overflow:
5529 print_overflow_msg(__func__, xdr);
5530 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005531}
Andy Adamsonfc931582009-04-01 09:22:31 -04005532
5533static int decode_chan_attrs(struct xdr_stream *xdr,
5534 struct nfs4_channel_attrs *attrs)
5535{
5536 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005537 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005538
Benny Halevyc0eae662009-08-14 17:20:14 +03005539 p = xdr_inline_decode(xdr, 28);
5540 if (unlikely(!p))
5541 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005542 val = be32_to_cpup(p++); /* headerpadsz */
5543 if (val)
5544 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005545 attrs->max_rqst_sz = be32_to_cpup(p++);
5546 attrs->max_resp_sz = be32_to_cpup(p++);
5547 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5548 attrs->max_ops = be32_to_cpup(p++);
5549 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005550 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005551 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005552 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5553 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005554 return -EINVAL;
5555 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005556 if (nr_attrs == 1) {
5557 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5558 if (unlikely(!p))
5559 goto out_overflow;
5560 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005561 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005562out_overflow:
5563 print_overflow_msg(__func__, xdr);
5564 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005565}
5566
Benny Halevye78291e2009-08-14 17:20:00 +03005567static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5568{
5569 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005570}
5571
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005572static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5573 struct nfs41_bind_conn_to_session_res *res)
5574{
5575 __be32 *p;
5576 int status;
5577
5578 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5579 if (!status)
5580 status = decode_sessionid(xdr, &res->session->sess_id);
5581 if (unlikely(status))
5582 return status;
5583
5584 /* dir flags, rdma mode bool */
5585 p = xdr_inline_decode(xdr, 8);
5586 if (unlikely(!p))
5587 goto out_overflow;
5588
5589 res->dir = be32_to_cpup(p++);
5590 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5591 return -EIO;
5592 if (be32_to_cpup(p) == 0)
5593 res->use_conn_in_rdma_mode = false;
5594 else
5595 res->use_conn_in_rdma_mode = true;
5596
5597 return 0;
5598out_overflow:
5599 print_overflow_msg(__func__, xdr);
5600 return -EIO;
5601}
5602
Andy Adamsonfc931582009-04-01 09:22:31 -04005603static int decode_create_session(struct xdr_stream *xdr,
5604 struct nfs41_create_session_res *res)
5605{
5606 __be32 *p;
5607 int status;
5608 struct nfs_client *clp = res->client;
5609 struct nfs4_session *session = clp->cl_session;
5610
5611 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005612 if (!status)
5613 status = decode_sessionid(xdr, &session->sess_id);
5614 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005615 return status;
5616
Andy Adamsonfc931582009-04-01 09:22:31 -04005617 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005618 p = xdr_inline_decode(xdr, 8);
5619 if (unlikely(!p))
5620 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005621 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005622 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005623
5624 /* Channel attributes */
5625 status = decode_chan_attrs(xdr, &session->fc_attrs);
5626 if (!status)
5627 status = decode_chan_attrs(xdr, &session->bc_attrs);
5628 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005629out_overflow:
5630 print_overflow_msg(__func__, xdr);
5631 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005632}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005633
5634static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5635{
5636 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5637}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005638
Trond Myklebust66245532012-05-25 17:18:09 -04005639static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5640{
5641 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5642}
5643
Ricardo Labiaga180197532009-12-05 16:08:40 -05005644static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5645{
5646 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5647}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005648#endif /* CONFIG_NFS_V4_1 */
5649
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005650static int decode_sequence(struct xdr_stream *xdr,
5651 struct nfs4_sequence_res *res,
5652 struct rpc_rqst *rqstp)
5653{
5654#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005655 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005656 struct nfs4_sessionid id;
5657 u32 dummy;
5658 int status;
5659 __be32 *p;
5660
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005661 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005662 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005663 if (!res->sr_slot->table->session)
5664 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005665
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005666 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005667 if (!status)
5668 status = decode_sessionid(xdr, &id);
5669 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005670 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005671
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005672 /*
5673 * If the server returns different values for sessionID, slotID or
5674 * sequence number, the server is looney tunes.
5675 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005676 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005677 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005678
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005679 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005680 NFS4_MAX_SESSIONID_LEN)) {
5681 dprintk("%s Invalid session id\n", __func__);
5682 goto out_err;
5683 }
Benny Halevye78291e2009-08-14 17:20:00 +03005684
Benny Halevyc0eae662009-08-14 17:20:14 +03005685 p = xdr_inline_decode(xdr, 20);
5686 if (unlikely(!p))
5687 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005688
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005689 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005690 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005691 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005692 dprintk("%s Invalid sequence number\n", __func__);
5693 goto out_err;
5694 }
5695 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005696 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005697 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005698 dprintk("%s Invalid slot id\n", __func__);
5699 goto out_err;
5700 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005701 /* highest slot id */
5702 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005703 /* target highest slot id */
5704 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005705 /* result flags */
5706 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005707 status = 0;
5708out_err:
5709 res->sr_status = status;
5710 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005711out_overflow:
5712 print_overflow_msg(__func__, xdr);
5713 status = -EIO;
5714 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005715#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005716 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005717#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005718}
5719
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005720#if defined(CONFIG_NFS_V4_1)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005721static 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{
Andy Adamson9f79fb42013-09-10 12:56:29 -04005935 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005936 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005937}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005938#endif /* CONFIG_NFS_V4_1 */
5939
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940/*
Benny Halevy49c25592008-12-23 16:06:16 -05005941 * END OF "GENERIC" DECODE ROUTINES.
5942 */
5943
5944/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945 * Decode OPEN_DOWNGRADE response
5946 */
Chuck Leverbf269552010-12-14 14:59:29 +00005947static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5948 struct xdr_stream *xdr,
5949 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005950{
Andy Adamson05d564f2008-12-23 16:06:15 -05005951 struct compound_hdr hdr;
5952 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005953
Chuck Leverbf269552010-12-14 14:59:29 +00005954 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005955 if (status)
5956 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005957 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005958 if (status)
5959 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005960 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005961 if (status)
5962 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005963 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005964 if (status != 0)
5965 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005966 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005968 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969}
5970
5971/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972 * Decode ACCESS response
5973 */
Chuck Leverbf269552010-12-14 14:59:29 +00005974static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5975 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005977 struct compound_hdr hdr;
5978 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005979
Chuck Leverbf269552010-12-14 14:59:29 +00005980 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005981 if (status)
5982 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005983 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005984 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005986 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005987 if (status != 0)
5988 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04005989 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04005990 if (status != 0)
5991 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005992 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005993out:
5994 return status;
5995}
5996
5997/*
5998 * Decode LOOKUP response
5999 */
Chuck Leverbf269552010-12-14 14:59:29 +00006000static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6001 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003 struct compound_hdr hdr;
6004 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006005
Chuck Leverbf269552010-12-14 14:59:29 +00006006 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006007 if (status)
6008 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006009 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006010 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006012 status = decode_putfh(xdr);
6013 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006015 status = decode_lookup(xdr);
6016 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006017 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006018 status = decode_getfh(xdr, res->fh);
6019 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006021 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022out:
6023 return status;
6024}
6025
6026/*
6027 * Decode LOOKUP_ROOT response
6028 */
Chuck Leverbf269552010-12-14 14:59:29 +00006029static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6030 struct xdr_stream *xdr,
6031 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033 struct compound_hdr hdr;
6034 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006035
Chuck Leverbf269552010-12-14 14:59:29 +00006036 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006037 if (status)
6038 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006039 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006040 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006041 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006042 status = decode_putrootfh(xdr);
6043 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006045 status = decode_getfh(xdr, res->fh);
6046 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006047 status = decode_getfattr_label(xdr, res->fattr,
6048 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006049out:
6050 return status;
6051}
6052
6053/*
6054 * Decode REMOVE response
6055 */
Chuck Leverbf269552010-12-14 14:59:29 +00006056static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6057 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006059 struct compound_hdr hdr;
6060 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006061
Chuck Leverbf269552010-12-14 14:59:29 +00006062 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006063 if (status)
6064 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006065 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006066 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006068 status = decode_putfh(xdr);
6069 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006070 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006071 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072out:
6073 return status;
6074}
6075
6076/*
6077 * Decode RENAME response
6078 */
Chuck Leverbf269552010-12-14 14:59:29 +00006079static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6080 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006082 struct compound_hdr hdr;
6083 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006084
Chuck Leverbf269552010-12-14 14:59:29 +00006085 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006086 if (status)
6087 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006089 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006091 status = decode_putfh(xdr);
6092 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006093 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006094 status = decode_savefh(xdr);
6095 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006097 status = decode_putfh(xdr);
6098 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006100 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101out:
6102 return status;
6103}
6104
6105/*
6106 * Decode LINK response
6107 */
Chuck Leverbf269552010-12-14 14:59:29 +00006108static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6109 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006111 struct compound_hdr hdr;
6112 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006113
Chuck Leverbf269552010-12-14 14:59:29 +00006114 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006115 if (status)
6116 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006117 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006118 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006119 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006120 status = decode_putfh(xdr);
6121 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006123 status = decode_savefh(xdr);
6124 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006126 status = decode_putfh(xdr);
6127 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006129 status = decode_link(xdr, &res->cinfo);
6130 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006131 goto out;
6132 /*
6133 * Note order: OP_LINK leaves the directory as the current
6134 * filehandle.
6135 */
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_restorefh(xdr);
6137 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006138 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006139 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006140out:
6141 return status;
6142}
6143
6144/*
6145 * Decode CREATE response
6146 */
Chuck Leverbf269552010-12-14 14:59:29 +00006147static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6148 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006149{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150 struct compound_hdr hdr;
6151 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006152
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006154 if (status)
6155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006157 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_putfh(xdr);
6160 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006162 status = decode_create(xdr, &res->dir_cinfo);
6163 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_getfh(xdr, res->fh);
6166 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006168 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169out:
6170 return status;
6171}
6172
6173/*
6174 * Decode SYMLINK response
6175 */
Chuck Leverbf269552010-12-14 14:59:29 +00006176static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6177 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006178{
Chuck Leverbf269552010-12-14 14:59:29 +00006179 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180}
6181
6182/*
6183 * Decode GETATTR response
6184 */
Chuck Leverbf269552010-12-14 14:59:29 +00006185static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6186 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188 struct compound_hdr hdr;
6189 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006190
Chuck Leverbf269552010-12-14 14:59:29 +00006191 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 if (status)
6193 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006194 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006195 if (status)
6196 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006197 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198 if (status)
6199 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006200 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201out:
6202 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203}
6204
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006205/*
6206 * Encode an SETACL request
6207 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006208static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6209 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006210{
Andy Adamson05d564f2008-12-23 16:06:15 -05006211 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006212 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006213 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006214
Chuck Lever9f06c712010-12-14 14:59:18 +00006215 encode_compound_hdr(xdr, req, &hdr);
6216 encode_sequence(xdr, &args->seq_args, &hdr);
6217 encode_putfh(xdr, args->fh, &hdr);
6218 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006219 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006220}
Andy Adamson05d564f2008-12-23 16:06:15 -05006221
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006222/*
6223 * Decode SETACL response
6224 */
6225static int
Chuck Leverbf269552010-12-14 14:59:29 +00006226nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006227 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006228{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006229 struct compound_hdr hdr;
6230 int status;
6231
Chuck Leverbf269552010-12-14 14:59:29 +00006232 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006233 if (status)
6234 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006235 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006236 if (status)
6237 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006239 if (status)
6240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006242out:
6243 return status;
6244}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245
6246/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006247 * Decode GETACL response
6248 */
6249static int
Chuck Leverbf269552010-12-14 14:59:29 +00006250nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006251 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006252{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006253 struct compound_hdr hdr;
6254 int status;
6255
Trond Myklebust331818f2012-02-03 18:30:53 -05006256 if (res->acl_scratch != NULL) {
6257 void *p = page_address(res->acl_scratch);
6258 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6259 }
Chuck Leverbf269552010-12-14 14:59:29 +00006260 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006261 if (status)
6262 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006263 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006264 if (status)
6265 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006266 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006267 if (status)
6268 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006269 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006270
6271out:
6272 return status;
6273}
6274
6275/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276 * Decode CLOSE response
6277 */
Chuck Leverbf269552010-12-14 14:59:29 +00006278static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6279 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280{
Andy Adamson05d564f2008-12-23 16:06:15 -05006281 struct compound_hdr hdr;
6282 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006283
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006285 if (status)
6286 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006287 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006288 if (status)
6289 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006290 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006291 if (status)
6292 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006293 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006294 if (status != 0)
6295 goto out;
6296 /*
6297 * Note: Server may do delete on close for this file
6298 * in which case the getattr call will fail with
6299 * an ESTALE error. Shouldn't be a problem,
6300 * though, since fattr->valid will remain unset.
6301 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006302 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006304 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305}
6306
6307/*
6308 * Decode OPEN response
6309 */
Chuck Leverbf269552010-12-14 14:59:29 +00006310static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6311 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312{
Andy Adamson05d564f2008-12-23 16:06:15 -05006313 struct compound_hdr hdr;
6314 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006315
Chuck Leverbf269552010-12-14 14:59:29 +00006316 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006317 if (status)
6318 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006320 if (status)
6321 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006322 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006323 if (status)
6324 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006326 if (status)
6327 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006328 status = decode_getfh(xdr, &res->fh);
6329 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006331 if (res->access_request)
6332 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006333 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006335 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006336}
6337
6338/*
6339 * Decode OPEN_CONFIRM response
6340 */
Chuck Leverbf269552010-12-14 14:59:29 +00006341static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6342 struct xdr_stream *xdr,
6343 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006344{
Andy Adamson05d564f2008-12-23 16:06:15 -05006345 struct compound_hdr hdr;
6346 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006347
Chuck Leverbf269552010-12-14 14:59:29 +00006348 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006349 if (status)
6350 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006351 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006352 if (status)
6353 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006354 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006356 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357}
6358
6359/*
6360 * Decode OPEN response
6361 */
Chuck Leverbf269552010-12-14 14:59:29 +00006362static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6363 struct xdr_stream *xdr,
6364 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006365{
Andy Adamson05d564f2008-12-23 16:06:15 -05006366 struct compound_hdr hdr;
6367 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368
Chuck Leverbf269552010-12-14 14:59:29 +00006369 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006370 if (status)
6371 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006372 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006373 if (status)
6374 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006375 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006376 if (status)
6377 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006378 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006379 if (status)
6380 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006381 if (res->access_request)
6382 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006383 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006384out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006385 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386}
6387
6388/*
6389 * Decode SETATTR response
6390 */
Chuck Leverbf269552010-12-14 14:59:29 +00006391static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6392 struct xdr_stream *xdr,
6393 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394{
Andy Adamson05d564f2008-12-23 16:06:15 -05006395 struct compound_hdr hdr;
6396 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006397
Chuck Leverbf269552010-12-14 14:59:29 +00006398 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006399 if (status)
6400 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006401 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006402 if (status)
6403 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006404 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006405 if (status)
6406 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006407 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006408 if (status)
6409 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006410 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006412 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006413}
6414
6415/*
6416 * Decode LOCK response
6417 */
Chuck Leverbf269552010-12-14 14:59:29 +00006418static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6419 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421 struct compound_hdr hdr;
6422 int status;
6423
Chuck Leverbf269552010-12-14 14:59:29 +00006424 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006425 if (status)
6426 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006427 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006428 if (status)
6429 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006430 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 if (status)
6432 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006434out:
6435 return status;
6436}
6437
6438/*
6439 * Decode LOCKT response
6440 */
Chuck Leverbf269552010-12-14 14:59:29 +00006441static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6442 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 struct compound_hdr hdr;
6445 int status;
6446
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448 if (status)
6449 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006450 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006451 if (status)
6452 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006453 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 if (status)
6455 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006456 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457out:
6458 return status;
6459}
6460
6461/*
6462 * Decode LOCKU response
6463 */
Chuck Leverbf269552010-12-14 14:59:29 +00006464static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6465 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467 struct compound_hdr hdr;
6468 int status;
6469
Chuck Leverbf269552010-12-14 14:59:29 +00006470 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 if (status)
6472 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006473 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006474 if (status)
6475 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006476 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477 if (status)
6478 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006479 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480out:
6481 return status;
6482}
6483
Chuck Leverbf269552010-12-14 14:59:29 +00006484static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6485 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006486{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006487 struct compound_hdr hdr;
6488 int status;
6489
Chuck Leverbf269552010-12-14 14:59:29 +00006490 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006491 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006493 return status;
6494}
6495
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496/*
6497 * Decode READLINK response
6498 */
Chuck Leverbf269552010-12-14 14:59:29 +00006499static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6500 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006501 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006503 struct compound_hdr hdr;
6504 int status;
6505
Chuck Leverbf269552010-12-14 14:59:29 +00006506 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507 if (status)
6508 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006509 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006510 if (status)
6511 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006512 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513 if (status)
6514 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006515 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516out:
6517 return status;
6518}
6519
6520/*
6521 * Decode READDIR response
6522 */
Chuck Leverbf269552010-12-14 14:59:29 +00006523static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6524 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526 struct compound_hdr hdr;
6527 int status;
6528
Chuck Leverbf269552010-12-14 14:59:29 +00006529 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530 if (status)
6531 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006533 if (status)
6534 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 if (status)
6537 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006538 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539out:
6540 return status;
6541}
6542
6543/*
6544 * Decode Read response
6545 */
Chuck Leverbf269552010-12-14 14:59:29 +00006546static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006547 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006549 struct compound_hdr hdr;
6550 int status;
6551
Chuck Leverbf269552010-12-14 14:59:29 +00006552 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553 if (status)
6554 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006556 if (status)
6557 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 if (status)
6560 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562 if (!status)
6563 status = res->count;
6564out:
6565 return status;
6566}
6567
6568/*
6569 * Decode WRITE response
6570 */
Chuck Leverbf269552010-12-14 14:59:29 +00006571static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006572 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574 struct compound_hdr hdr;
6575 int status;
6576
Chuck Leverbf269552010-12-14 14:59:29 +00006577 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578 if (status)
6579 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006581 if (status)
6582 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584 if (status)
6585 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006586 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006587 if (status)
6588 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006589 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006590 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006591 if (!status)
6592 status = res->count;
6593out:
6594 return status;
6595}
6596
6597/*
6598 * Decode COMMIT response
6599 */
Chuck Leverbf269552010-12-14 14:59:29 +00006600static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006601 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006602{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006603 struct compound_hdr hdr;
6604 int status;
6605
Chuck Leverbf269552010-12-14 14:59:29 +00006606 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607 if (status)
6608 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006609 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006610 if (status)
6611 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006612 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613 if (status)
6614 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006615 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616out:
6617 return status;
6618}
6619
6620/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006621 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622 */
Chuck Leverbf269552010-12-14 14:59:29 +00006623static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006624 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006626 struct compound_hdr hdr;
6627 int status;
6628
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006631 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006632 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006633 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006635 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636 return status;
6637}
6638
6639/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006640 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006641 */
Chuck Leverbf269552010-12-14 14:59:29 +00006642static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006643 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006645 struct compound_hdr hdr;
6646 int status;
6647
Chuck Leverbf269552010-12-14 14:59:29 +00006648 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006651 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006652 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006654 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655 return status;
6656}
6657
6658/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006659 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660 */
Chuck Leverbf269552010-12-14 14:59:29 +00006661static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006662 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006663{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664 struct compound_hdr hdr;
6665 int status;
6666
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006668 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006670 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006671 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006673 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674 return status;
6675}
6676
6677/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006678 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006679 */
Chuck Leverbf269552010-12-14 14:59:29 +00006680static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6681 struct xdr_stream *xdr,
6682 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006683{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006684 struct compound_hdr hdr;
6685 int status;
6686
Chuck Leverbf269552010-12-14 14:59:29 +00006687 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006688 if (status)
6689 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006690 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006691 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006692 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006693 status = decode_putfh(xdr);
6694 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006695 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006696 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006697out:
6698 return status;
6699}
6700
6701/*
6702 * Decode RENEW response
6703 */
Chuck Leverbf269552010-12-14 14:59:29 +00006704static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6705 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006706{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006707 struct compound_hdr hdr;
6708 int status;
6709
Chuck Leverbf269552010-12-14 14:59:29 +00006710 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006712 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006713 return status;
6714}
6715
6716/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006717 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006718 */
Chuck Leverbf269552010-12-14 14:59:29 +00006719static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6720 struct xdr_stream *xdr,
6721 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006722{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723 struct compound_hdr hdr;
6724 int status;
6725
Chuck Leverbf269552010-12-14 14:59:29 +00006726 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006727 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006729 return status;
6730}
6731
6732/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006733 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006734 */
Chuck Leverbf269552010-12-14 14:59:29 +00006735static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006736 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006737{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006738 struct compound_hdr hdr;
6739 int status;
6740
Chuck Leverbf269552010-12-14 14:59:29 +00006741 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006743 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744 return status;
6745}
6746
6747/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006748 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 */
Chuck Leverbf269552010-12-14 14:59:29 +00006750static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6751 struct xdr_stream *xdr,
6752 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754 struct compound_hdr hdr;
6755 int status;
6756
Chuck Leverbf269552010-12-14 14:59:29 +00006757 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006758 if (status)
6759 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006760 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006761 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006762 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006763 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006764 if (status != 0)
6765 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006766 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006767 if (status != 0)
6768 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006769 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006770out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006771 return status;
6772}
6773
Trond Myklebust683b57b2006-06-09 09:34:22 -04006774/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006775 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006776 */
Chuck Leverbf269552010-12-14 14:59:29 +00006777static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6778 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006779 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006780{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006781 struct compound_hdr hdr;
6782 int status;
6783
Chuck Leverbf269552010-12-14 14:59:29 +00006784 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006785 if (status)
6786 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006788 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006789 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006790 status = decode_putfh(xdr);
6791 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006792 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006793 if (res->migration) {
6794 xdr_enter_page(xdr, PAGE_SIZE);
6795 status = decode_getfattr_generic(xdr,
6796 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006797 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006798 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006799 if (status)
6800 goto out;
6801 if (res->renew)
6802 status = decode_renew(xdr);
6803 } else {
6804 status = decode_lookup(xdr);
6805 if (status)
6806 goto out;
6807 xdr_enter_page(xdr, PAGE_SIZE);
6808 status = decode_getfattr_generic(xdr,
6809 &res->fs_locations->fattr,
6810 NULL, res->fs_locations,
6811 NULL, res->fs_locations->server);
6812 }
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
Chuck Lever44c99932013-10-17 14:13:30 -04006841/*
6842 * Decode FSID_PRESENT response
6843 */
6844static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6845 struct xdr_stream *xdr,
6846 struct nfs4_fsid_present_res *res)
6847{
6848 struct compound_hdr hdr;
6849 int status;
6850
6851 status = decode_compound_hdr(xdr, &hdr);
6852 if (status)
6853 goto out;
6854 status = decode_sequence(xdr, &res->seq_res, rqstp);
6855 if (status)
6856 goto out;
6857 status = decode_putfh(xdr);
6858 if (status)
6859 goto out;
6860 status = decode_getfh(xdr, res->fh);
6861 if (status)
6862 goto out;
6863 if (res->renew)
6864 status = decode_renew(xdr);
6865out:
6866 return status;
6867}
6868
Benny Halevy99fe60d2009-04-01 09:22:29 -04006869#if defined(CONFIG_NFS_V4_1)
6870/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006871 * Decode BIND_CONN_TO_SESSION response
6872 */
6873static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6874 struct xdr_stream *xdr,
6875 void *res)
6876{
6877 struct compound_hdr hdr;
6878 int status;
6879
6880 status = decode_compound_hdr(xdr, &hdr);
6881 if (!status)
6882 status = decode_bind_conn_to_session(xdr, res);
6883 return status;
6884}
6885
6886/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006887 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006888 */
Chuck Leverbf269552010-12-14 14:59:29 +00006889static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6890 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006891 void *res)
6892{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006893 struct compound_hdr hdr;
6894 int status;
6895
Chuck Leverbf269552010-12-14 14:59:29 +00006896 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006897 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006898 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006899 return status;
6900}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006901
6902/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006903 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006904 */
Chuck Leverbf269552010-12-14 14:59:29 +00006905static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6906 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006907 struct nfs41_create_session_res *res)
6908{
Andy Adamsonfc931582009-04-01 09:22:31 -04006909 struct compound_hdr hdr;
6910 int status;
6911
Chuck Leverbf269552010-12-14 14:59:29 +00006912 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006913 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006914 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006915 return status;
6916}
6917
6918/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006919 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006920 */
Chuck Leverbf269552010-12-14 14:59:29 +00006921static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6922 struct xdr_stream *xdr,
6923 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006924{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006925 struct compound_hdr hdr;
6926 int status;
6927
Chuck Leverbf269552010-12-14 14:59:29 +00006928 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006929 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006930 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006931 return status;
6932}
6933
6934/*
Trond Myklebust66245532012-05-25 17:18:09 -04006935 * Decode DESTROY_CLIENTID response
6936 */
6937static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6938 struct xdr_stream *xdr,
6939 void *res)
6940{
6941 struct compound_hdr hdr;
6942 int status;
6943
6944 status = decode_compound_hdr(xdr, &hdr);
6945 if (!status)
6946 status = decode_destroy_clientid(xdr, res);
6947 return status;
6948}
6949
6950/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006951 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006952 */
Chuck Leverbf269552010-12-14 14:59:29 +00006953static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6954 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006955 struct nfs4_sequence_res *res)
6956{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006957 struct compound_hdr hdr;
6958 int status;
6959
Chuck Leverbf269552010-12-14 14:59:29 +00006960 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006961 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006962 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006963 return status;
6964}
6965
6966/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006967 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006968 */
Chuck Leverbf269552010-12-14 14:59:29 +00006969static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6970 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006971 struct nfs4_get_lease_time_res *res)
6972{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006973 struct compound_hdr hdr;
6974 int status;
6975
Chuck Leverbf269552010-12-14 14:59:29 +00006976 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006977 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006978 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006979 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006980 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006981 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006982 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006983 return status;
6984}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006985
6986/*
6987 * Decode RECLAIM_COMPLETE response
6988 */
Chuck Leverbf269552010-12-14 14:59:29 +00006989static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6990 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006991 struct nfs41_reclaim_complete_res *res)
6992{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006993 struct compound_hdr hdr;
6994 int status;
6995
Chuck Leverbf269552010-12-14 14:59:29 +00006996 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006997 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006998 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006999 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307000 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007001 return status;
7002}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007003
7004/*
7005 * Decode GETDEVINFO response
7006 */
Chuck Leverbf269552010-12-14 14:59:29 +00007007static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7008 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007009 struct nfs4_getdeviceinfo_res *res)
7010{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007011 struct compound_hdr hdr;
7012 int status;
7013
Chuck Leverbf269552010-12-14 14:59:29 +00007014 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007015 if (status != 0)
7016 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007017 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007018 if (status != 0)
7019 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007020 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007021out:
7022 return status;
7023}
7024
7025/*
7026 * Decode LAYOUTGET response
7027 */
Chuck Leverbf269552010-12-14 14:59:29 +00007028static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7029 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007030 struct nfs4_layoutget_res *res)
7031{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007032 struct compound_hdr hdr;
7033 int status;
7034
Chuck Leverbf269552010-12-14 14:59:29 +00007035 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007036 if (status)
7037 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007038 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007039 if (status)
7040 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007041 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007042 if (status)
7043 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007044 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007045out:
7046 return status;
7047}
Andy Adamson863a3c62011-03-23 13:27:54 +00007048
7049/*
Benny Halevycbe82602011-05-22 19:52:37 +03007050 * Decode LAYOUTRETURN response
7051 */
7052static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7053 struct xdr_stream *xdr,
7054 struct nfs4_layoutreturn_res *res)
7055{
7056 struct compound_hdr hdr;
7057 int status;
7058
7059 status = decode_compound_hdr(xdr, &hdr);
7060 if (status)
7061 goto out;
7062 status = decode_sequence(xdr, &res->seq_res, rqstp);
7063 if (status)
7064 goto out;
7065 status = decode_putfh(xdr);
7066 if (status)
7067 goto out;
7068 status = decode_layoutreturn(xdr, res);
7069out:
7070 return status;
7071}
7072
7073/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007074 * Decode LAYOUTCOMMIT response
7075 */
7076static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7077 struct xdr_stream *xdr,
7078 struct nfs4_layoutcommit_res *res)
7079{
7080 struct compound_hdr hdr;
7081 int status;
7082
7083 status = decode_compound_hdr(xdr, &hdr);
7084 if (status)
7085 goto out;
7086 status = decode_sequence(xdr, &res->seq_res, rqstp);
7087 if (status)
7088 goto out;
7089 status = decode_putfh(xdr);
7090 if (status)
7091 goto out;
7092 status = decode_layoutcommit(xdr, rqstp, res);
7093 if (status)
7094 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007095 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007096out:
7097 return status;
7098}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007099
7100/*
7101 * Decode SECINFO_NO_NAME response
7102 */
7103static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7104 struct xdr_stream *xdr,
7105 struct nfs4_secinfo_res *res)
7106{
7107 struct compound_hdr hdr;
7108 int status;
7109
7110 status = decode_compound_hdr(xdr, &hdr);
7111 if (status)
7112 goto out;
7113 status = decode_sequence(xdr, &res->seq_res, rqstp);
7114 if (status)
7115 goto out;
7116 status = decode_putrootfh(xdr);
7117 if (status)
7118 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007119 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007120out:
7121 return status;
7122}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007123
7124/*
7125 * Decode TEST_STATEID response
7126 */
7127static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7128 struct xdr_stream *xdr,
7129 struct nfs41_test_stateid_res *res)
7130{
7131 struct compound_hdr hdr;
7132 int status;
7133
7134 status = decode_compound_hdr(xdr, &hdr);
7135 if (status)
7136 goto out;
7137 status = decode_sequence(xdr, &res->seq_res, rqstp);
7138 if (status)
7139 goto out;
7140 status = decode_test_stateid(xdr, res);
7141out:
7142 return status;
7143}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007144
7145/*
7146 * Decode FREE_STATEID response
7147 */
7148static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7149 struct xdr_stream *xdr,
7150 struct nfs41_free_stateid_res *res)
7151{
7152 struct compound_hdr hdr;
7153 int status;
7154
7155 status = decode_compound_hdr(xdr, &hdr);
7156 if (status)
7157 goto out;
7158 status = decode_sequence(xdr, &res->seq_res, rqstp);
7159 if (status)
7160 goto out;
7161 status = decode_free_stateid(xdr, res);
7162out:
7163 return status;
7164}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007165#endif /* CONFIG_NFS_V4_1 */
7166
Chuck Lever573c4e12010-12-14 14:58:11 +00007167/**
7168 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7169 * the local page cache.
7170 * @xdr: XDR stream where entry resides
7171 * @entry: buffer to fill in with entry data
7172 * @plus: boolean indicating whether this should be a readdirplus entry
7173 *
7174 * Returns zero if successful, otherwise a negative errno value is
7175 * returned.
7176 *
7177 * This function is not invoked during READDIR reply decoding, but
7178 * rather whenever an application invokes the getdents(2) system call
7179 * on a directory already in our cache.
7180 */
7181int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7182 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007183{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007184 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007185 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007186 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007187 __be32 *p = xdr_inline_decode(xdr, 4);
7188 if (unlikely(!p))
7189 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007190 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007191 p = xdr_inline_decode(xdr, 4);
7192 if (unlikely(!p))
7193 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007194 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007195 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007196 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007197 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007198 }
7199
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007200 p = xdr_inline_decode(xdr, 12);
7201 if (unlikely(!p))
7202 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007203 entry->prev_cookie = entry->cookie;
7204 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007205 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007206
Trond Myklebust9af8c222010-10-24 11:52:55 -04007207 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007208 if (unlikely(!p))
7209 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007210 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007211
7212 /*
7213 * In case the server doesn't return an inode number,
7214 * we fake one here. (We don't use inode number 0,
7215 * since glibc seems to choke on it...)
7216 */
7217 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007218 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007219
Trond Myklebust9af8c222010-10-24 11:52:55 -04007220 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007221 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007222
Trond Myklebust256e48b2012-06-21 11:18:13 -04007223 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007224 goto out_overflow;
7225
Chuck Lever573c4e12010-12-14 14:58:11 +00007226 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007227 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007228 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007229 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7230 entry->ino = entry->fattr->mounted_on_fileid;
7231 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007232 entry->ino = entry->fattr->fileid;
7233
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007234 entry->d_type = DT_UNKNOWN;
7235 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7236 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7237
Chuck Lever573c4e12010-12-14 14:58:11 +00007238 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007239
7240out_overflow:
7241 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007242 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007243}
7244
7245/*
7246 * We need to translate between nfs status return values and
7247 * the local errno values which may not be the same.
7248 */
7249static struct {
7250 int stat;
7251 int errno;
7252} nfs_errtbl[] = {
7253 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007254 { NFS4ERR_PERM, -EPERM },
7255 { NFS4ERR_NOENT, -ENOENT },
7256 { NFS4ERR_IO, -errno_NFSERR_IO},
7257 { NFS4ERR_NXIO, -ENXIO },
7258 { NFS4ERR_ACCESS, -EACCES },
7259 { NFS4ERR_EXIST, -EEXIST },
7260 { NFS4ERR_XDEV, -EXDEV },
7261 { NFS4ERR_NOTDIR, -ENOTDIR },
7262 { NFS4ERR_ISDIR, -EISDIR },
7263 { NFS4ERR_INVAL, -EINVAL },
7264 { NFS4ERR_FBIG, -EFBIG },
7265 { NFS4ERR_NOSPC, -ENOSPC },
7266 { NFS4ERR_ROFS, -EROFS },
7267 { NFS4ERR_MLINK, -EMLINK },
7268 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7269 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7270 { NFS4ERR_DQUOT, -EDQUOT },
7271 { NFS4ERR_STALE, -ESTALE },
7272 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007273 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7274 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7275 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007276 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007277 { NFS4ERR_BADTYPE, -EBADTYPE },
7278 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007279 { NFS4ERR_SYMLINK, -ELOOP },
7280 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7281 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007282 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007283};
7284
7285/*
7286 * Convert an NFS error code to a local one.
7287 * This one is used jointly by NFSv2 and NFSv3.
7288 */
7289static int
David Howells0a8ea432006-08-22 20:06:08 -04007290nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007291{
7292 int i;
7293 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7294 if (nfs_errtbl[i].stat == stat)
7295 return nfs_errtbl[i].errno;
7296 }
7297 if (stat <= 10000 || stat > 10100) {
7298 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007299 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007300 }
7301 /* If we cannot translate the error, the recovery routines should
7302 * handle it.
7303 * Note: remaining NFSv4 error codes have values > 10000, so should
7304 * not conflict with native Linux error codes.
7305 */
Benny Halevy856dff32008-03-31 17:39:06 +03007306 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007307}
7308
Linus Torvalds1da177e2005-04-16 15:20:36 -07007309#define PROC(proc, argtype, restype) \
7310[NFSPROC4_CLNT_##proc] = { \
7311 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007312 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007313 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007314 .p_arglen = NFS4_##argtype##_sz, \
7315 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007316 .p_statidx = NFSPROC4_CLNT_##proc, \
7317 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007318}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007319
7320struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007321 PROC(READ, enc_read, dec_read),
7322 PROC(WRITE, enc_write, dec_write),
7323 PROC(COMMIT, enc_commit, dec_commit),
7324 PROC(OPEN, enc_open, dec_open),
7325 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7326 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7327 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7328 PROC(CLOSE, enc_close, dec_close),
7329 PROC(SETATTR, enc_setattr, dec_setattr),
7330 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7331 PROC(RENEW, enc_renew, dec_renew),
7332 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7333 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7334 PROC(LOCK, enc_lock, dec_lock),
7335 PROC(LOCKT, enc_lockt, dec_lockt),
7336 PROC(LOCKU, enc_locku, dec_locku),
7337 PROC(ACCESS, enc_access, dec_access),
7338 PROC(GETATTR, enc_getattr, dec_getattr),
7339 PROC(LOOKUP, enc_lookup, dec_lookup),
7340 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7341 PROC(REMOVE, enc_remove, dec_remove),
7342 PROC(RENAME, enc_rename, dec_rename),
7343 PROC(LINK, enc_link, dec_link),
7344 PROC(SYMLINK, enc_symlink, dec_symlink),
7345 PROC(CREATE, enc_create, dec_create),
7346 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7347 PROC(STATFS, enc_statfs, dec_statfs),
7348 PROC(READLINK, enc_readlink, dec_readlink),
7349 PROC(READDIR, enc_readdir, dec_readdir),
7350 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7351 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7352 PROC(GETACL, enc_getacl, dec_getacl),
7353 PROC(SETACL, enc_setacl, dec_setacl),
7354 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7355 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007356 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007357 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007358#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007359 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7360 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7361 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7362 PROC(SEQUENCE, enc_sequence, dec_sequence),
7363 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7364 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7365 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7366 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007367 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007368 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007369 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007370 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007371 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007372 PROC(BIND_CONN_TO_SESSION,
7373 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007374 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007375#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007376};
7377
Trond Myklebusta613fa12012-01-20 13:53:56 -05007378const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007379 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007380 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007381 .procs = nfs4_procedures
7382};
7383
7384/*
7385 * Local variables:
7386 * c-basic-offset: 8
7387 * End:
7388 */