blob: a07555d6968c4c1dde12f599912160ce61af6098 [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>
Chuck Leverf0920752012-05-21 22:45:41 -040055
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Anna Schumaker40c64c22015-04-15 13:00:05 -040058#include "nfs4idmap.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) + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400142 /* client name */ \
143 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500144 1 /* sc_prog */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500145 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
146 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500147 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define decode_setclientid_maxsz \
149 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500150 2 /* clientid */ + \
151 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
152 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
153 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#define encode_setclientid_confirm_maxsz \
155 (op_encode_hdr_maxsz + \
156 3 + (NFS4_VERIFIER_SIZE >> 2))
157#define decode_setclientid_confirm_maxsz \
158 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400159#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
160#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400161#define encode_share_access_maxsz \
162 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500163#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400164#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
165#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
166#define encode_open_maxsz (op_encode_hdr_maxsz + \
167 2 + encode_share_access_maxsz + 2 + \
168 open_owner_id_maxsz + \
169 encode_opentype_maxsz + \
170 encode_claim_null_maxsz)
171#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400172#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400173 decode_ace_maxsz)
174#define decode_change_info_maxsz (5)
175#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400176 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400177 decode_change_info_maxsz + 1 + \
178 nfs4_fattr_bitmap_maxsz + \
179 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400180#define encode_open_confirm_maxsz \
181 (op_encode_hdr_maxsz + \
182 encode_stateid_maxsz + 1)
183#define decode_open_confirm_maxsz \
184 (op_decode_hdr_maxsz + \
185 decode_stateid_maxsz)
186#define encode_open_downgrade_maxsz \
187 (op_encode_hdr_maxsz + \
188 encode_stateid_maxsz + 1 + \
189 encode_share_access_maxsz)
190#define decode_open_downgrade_maxsz \
191 (op_decode_hdr_maxsz + \
192 decode_stateid_maxsz)
193#define encode_close_maxsz (op_encode_hdr_maxsz + \
194 1 + encode_stateid_maxsz)
195#define decode_close_maxsz (op_decode_hdr_maxsz + \
196 decode_stateid_maxsz)
197#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
198 encode_stateid_maxsz + \
199 encode_attrs_maxsz)
200#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
201 nfs4_fattr_bitmap_maxsz)
202#define encode_read_maxsz (op_encode_hdr_maxsz + \
203 encode_stateid_maxsz + 3)
204#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
205#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400206 2 + encode_verifier_maxsz + 5 + \
207 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400208#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400209 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400210#define encode_readlink_maxsz (op_encode_hdr_maxsz)
211#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
212#define encode_write_maxsz (op_encode_hdr_maxsz + \
213 encode_stateid_maxsz + 4)
214#define decode_write_maxsz (op_decode_hdr_maxsz + \
215 2 + decode_verifier_maxsz)
216#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
217#define decode_commit_maxsz (op_decode_hdr_maxsz + \
218 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219#define encode_remove_maxsz (op_encode_hdr_maxsz + \
220 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400221#define decode_remove_maxsz (op_decode_hdr_maxsz + \
222 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#define encode_rename_maxsz (op_encode_hdr_maxsz + \
224 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400225#define decode_rename_maxsz (op_decode_hdr_maxsz + \
226 decode_change_info_maxsz + \
227 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228#define encode_link_maxsz (op_encode_hdr_maxsz + \
229 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400230#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400231#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400232#define encode_lock_maxsz (op_encode_hdr_maxsz + \
233 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400234 1 + encode_stateid_maxsz + 1 + \
235 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define decode_lock_denied_maxsz \
237 (8 + decode_lockowner_maxsz)
238#define decode_lock_maxsz (op_decode_hdr_maxsz + \
239 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400240#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
241 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400242#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
243 decode_lock_denied_maxsz)
244#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
245 encode_stateid_maxsz + \
246 4)
247#define decode_locku_maxsz (op_decode_hdr_maxsz + \
248 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400249#define encode_release_lockowner_maxsz \
250 (op_encode_hdr_maxsz + \
251 encode_lockowner_maxsz)
252#define decode_release_lockowner_maxsz \
253 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400254#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
255#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
257 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400258 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000259 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
261#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400262 1 + 2 + nfs4_name_maxsz + \
263 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400264#define decode_create_maxsz (op_decode_hdr_maxsz + \
265 decode_change_info_maxsz + \
266 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400267#define encode_statfs_maxsz (encode_getattr_maxsz)
268#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
270#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400271#define encode_getacl_maxsz (encode_getattr_maxsz)
272#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
273 nfs4_fattr_bitmap_maxsz + 1)
274#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
275 encode_stateid_maxsz + 3)
276#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400277#define encode_fs_locations_maxsz \
278 (encode_getattr_maxsz)
279#define decode_fs_locations_maxsz \
280 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000281#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400282#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 -0400283
284#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400285#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500286#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
287 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400288
Benny Halevy99fe60d2009-04-01 09:22:29 -0400289#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
290 encode_verifier_maxsz + \
291 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400292 /* eia_clientowner */ \
293 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400294 1 /* flags */ + \
295 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400296 /* max is SP4_MACH_CRED (for now) */ + \
297 1 + NFS4_OP_MAP_NUM_WORDS + \
298 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500299 1 /* implementation id array of size 1 */ + \
300 1 /* nii_domain */ + \
301 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
302 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500303 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500304 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400305#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
306 2 /* eir_clientid */ + \
307 1 /* eir_sequenceid */ + \
308 1 /* eir_flags */ + \
309 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400310 /* max is SP4_MACH_CRED (for now) */ + \
311 1 + NFS4_OP_MAP_NUM_WORDS + \
312 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400313 2 /* eir_server_owner.so_minor_id */ + \
314 /* eir_server_owner.so_major_id<> */ \
315 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
316 /* eir_server_scope<> */ \
317 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
318 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500319 1 /* nii_domain */ + \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
321 1 /* nii_name */ + \
322 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
323 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400324#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
325#define decode_channel_attrs_maxsz (6 + \
326 1 /* ca_rdma_ird.len */ + \
327 1 /* ca_rdma_ird */)
328#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
329 2 /* csa_clientid */ + \
330 1 /* csa_sequence */ + \
331 1 /* csa_flags */ + \
332 encode_channel_attrs_maxsz + \
333 encode_channel_attrs_maxsz + \
334 1 /* csa_cb_program */ + \
335 1 /* csa_sec_parms.len (1) */ + \
336 1 /* cb_secflavor (AUTH_SYS) */ + \
337 1 /* stamp */ + \
338 1 /* machinename.len */ + \
339 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
340 1 /* uid */ + \
341 1 /* gid */ + \
342 1 /* gids.len (0) */)
343#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
344 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
345 1 /* csr_sequence */ + \
346 1 /* csr_flags */ + \
347 decode_channel_attrs_maxsz + \
348 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400349#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
350 /* bctsa_sessid */ \
351 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
352 1 /* bctsa_dir */ + \
353 1 /* bctsa_use_conn_in_rdma_mode */)
354#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
355 /* bctsr_sessid */ \
356 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
357 1 /* bctsr_dir */ + \
358 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400359#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
360#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400361#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
362#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400363#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
364 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
365#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
366 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500367#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
368#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700369#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
370 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
371 1 /* layout type */ + \
372 1 /* maxcount */ + \
373 1 /* bitmap size */ + \
374 1 /* notification bitmap length */ + \
375 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400376#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
377 1 /* layout type */ + \
378 1 /* opaque devaddr4 length */ + \
379 /* devaddr4 payload is read into page */ \
380 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700381 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400382#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
383 encode_stateid_maxsz)
384#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
385 decode_stateid_maxsz + \
386 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000387#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
388 2 /* offset */ + \
389 2 /* length */ + \
390 1 /* reclaim */ + \
391 encode_stateid_maxsz + \
392 1 /* new offset (true) */ + \
393 2 /* last byte written */ + \
394 1 /* nt_timechanged (false) */ + \
395 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500396 1 /* layoutupdate4 opaqueue len */)
397 /* the actual content of layoutupdate4 should
398 be allocated by drivers and spliced in
399 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000400#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300401#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
402 encode_stateid_maxsz + \
403 1 /* FIXME: opaque lrf_body always empty at the moment */)
404#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
405 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400406#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
407#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400408#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
409 XDR_QUADLEN(NFS4_STATEID_SIZE))
410#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400411#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
412 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400413#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400414#else /* CONFIG_NFS_V4_1 */
415#define encode_sequence_maxsz 0
416#define decode_sequence_maxsz 0
417#endif /* CONFIG_NFS_V4_1 */
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
420#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
421#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400432 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400444 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400448 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400449 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400453 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400454 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400458 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400462 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400466 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400467 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400468 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400469 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400474 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400475 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400477#define NFS4_enc_open_confirm_sz \
478 (compound_encode_hdr_maxsz + \
479 encode_putfh_maxsz + \
480 encode_open_confirm_maxsz)
481#define NFS4_dec_open_confirm_sz \
482 (compound_decode_hdr_maxsz + \
483 decode_putfh_maxsz + \
484 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400486 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400488 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400489 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400490 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400495 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400496 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497#define NFS4_enc_open_downgrade_sz \
498 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400499 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400500 encode_putfh_maxsz + \
501 encode_open_downgrade_maxsz + \
502 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#define NFS4_dec_open_downgrade_sz \
504 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400505 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400506 decode_putfh_maxsz + \
507 decode_open_downgrade_maxsz + \
508 decode_getattr_maxsz)
509#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400510 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400511 encode_putfh_maxsz + \
512 encode_close_maxsz + \
513 encode_getattr_maxsz)
514#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400515 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400516 decode_putfh_maxsz + \
517 decode_close_maxsz + \
518 decode_getattr_maxsz)
519#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400521 encode_putfh_maxsz + \
522 encode_setattr_maxsz + \
523 encode_getattr_maxsz)
524#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400525 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400526 decode_putfh_maxsz + \
527 decode_setattr_maxsz + \
528 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 encode_putfh_maxsz + \
532 encode_fsinfo_maxsz)
533#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 decode_putfh_maxsz + \
536 decode_fsinfo_maxsz)
537#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
538 encode_renew_maxsz)
539#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
540 decode_renew_maxsz)
541#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
542 encode_setclientid_maxsz)
543#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
544 decode_setclientid_maxsz)
545#define NFS4_enc_setclientid_confirm_sz \
546 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400547 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#define NFS4_dec_setclientid_confirm_sz \
549 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400550 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400552 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400554 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400558 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400562 encode_lockt_maxsz)
563#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400565 decode_putfh_maxsz + \
566 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400570 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400574 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400575#define NFS4_enc_release_lockowner_sz \
576 (compound_encode_hdr_maxsz + \
577 encode_lockowner_maxsz)
578#define NFS4_dec_release_lockowner_sz \
579 (compound_decode_hdr_maxsz + \
580 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400584 encode_access_maxsz + \
585 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400587 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400589 decode_access_maxsz + \
590 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400594 encode_getattr_maxsz + \
595 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400597 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400599 decode_getattr_maxsz + \
600 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400602 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 encode_putfh_maxsz + \
604 encode_lookup_maxsz + \
605 encode_getattr_maxsz + \
606 encode_getfh_maxsz)
607#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400608 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400610 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 decode_getattr_maxsz + \
612 decode_getfh_maxsz)
613#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400614 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 encode_putrootfh_maxsz + \
616 encode_getattr_maxsz + \
617 encode_getfh_maxsz)
618#define NFS4_dec_lookup_root_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_putrootfh_maxsz + \
621 decode_getattr_maxsz + \
622 decode_getfh_maxsz)
623#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400626 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400628 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400630 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400632 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 encode_putfh_maxsz + \
634 encode_savefh_maxsz + \
635 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400636 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 decode_putfh_maxsz + \
640 decode_savefh_maxsz + \
641 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400642 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400644 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 encode_putfh_maxsz + \
646 encode_savefh_maxsz + \
647 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400648 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400649 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400650 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400652 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 decode_putfh_maxsz + \
654 decode_savefh_maxsz + \
655 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400656 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400657 decode_restorefh_maxsz + \
658 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 encode_putfh_maxsz + \
662 encode_symlink_maxsz + \
663 encode_getattr_maxsz + \
664 encode_getfh_maxsz)
665#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 decode_putfh_maxsz + \
668 decode_symlink_maxsz + \
669 decode_getattr_maxsz + \
670 decode_getfh_maxsz)
671#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
674 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400675 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400676 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400678 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 decode_putfh_maxsz + \
680 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400681 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400682 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 encode_putfh_maxsz + \
686 encode_getattr_maxsz)
687#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 decode_putfh_maxsz + \
690 decode_getattr_maxsz)
691#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400694 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400698 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400700 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800701 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 encode_getattr_maxsz)
703#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400704 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800705 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 decode_getattr_maxsz)
707#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400708 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100710 encode_delegreturn_maxsz + \
711 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100714 decode_delegreturn_maxsz + \
715 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000716#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000718 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000720#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400721 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000722 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400723 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000724#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400725 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000726 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400727 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000728#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400729 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000730 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400731 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400732#define NFS4_enc_fs_locations_sz \
733 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400734 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400735 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400736 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400737 encode_fs_locations_maxsz + \
738 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400739#define NFS4_dec_fs_locations_sz \
740 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400741 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400742 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400743 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400744 decode_fs_locations_maxsz + \
745 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000746#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
747 encode_sequence_maxsz + \
748 encode_putfh_maxsz + \
749 encode_secinfo_maxsz)
750#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
751 decode_sequence_maxsz + \
752 decode_putfh_maxsz + \
753 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400754#define NFS4_enc_fsid_present_sz \
755 (compound_encode_hdr_maxsz + \
756 encode_sequence_maxsz + \
757 encode_putfh_maxsz + \
758 encode_getfh_maxsz + \
759 encode_renew_maxsz)
760#define NFS4_dec_fsid_present_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz + \
763 decode_putfh_maxsz + \
764 decode_getfh_maxsz + \
765 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400766#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400767#define NFS4_enc_bind_conn_to_session_sz \
768 (compound_encode_hdr_maxsz + \
769 encode_bind_conn_to_session_maxsz)
770#define NFS4_dec_bind_conn_to_session_sz \
771 (compound_decode_hdr_maxsz + \
772 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400773#define NFS4_enc_exchange_id_sz \
774 (compound_encode_hdr_maxsz + \
775 encode_exchange_id_maxsz)
776#define NFS4_dec_exchange_id_sz \
777 (compound_decode_hdr_maxsz + \
778 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400779#define NFS4_enc_create_session_sz \
780 (compound_encode_hdr_maxsz + \
781 encode_create_session_maxsz)
782#define NFS4_dec_create_session_sz \
783 (compound_decode_hdr_maxsz + \
784 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400785#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
786 encode_destroy_session_maxsz)
787#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
788 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400789#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
790 encode_destroy_clientid_maxsz)
791#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
792 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400793#define NFS4_enc_sequence_sz \
794 (compound_decode_hdr_maxsz + \
795 encode_sequence_maxsz)
796#define NFS4_dec_sequence_sz \
797 (compound_decode_hdr_maxsz + \
798 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400799#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
800 encode_sequence_maxsz + \
801 encode_putrootfh_maxsz + \
802 encode_fsinfo_maxsz)
803#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
804 decode_sequence_maxsz + \
805 decode_putrootfh_maxsz + \
806 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500807#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
808 encode_sequence_maxsz + \
809 encode_reclaim_complete_maxsz)
810#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
811 decode_sequence_maxsz + \
812 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400813#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
814 encode_sequence_maxsz +\
815 encode_getdeviceinfo_maxsz)
816#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
817 decode_sequence_maxsz + \
818 decode_getdeviceinfo_maxsz)
819#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz + \
821 encode_putfh_maxsz + \
822 encode_layoutget_maxsz)
823#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
824 decode_sequence_maxsz + \
825 decode_putfh_maxsz + \
826 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000827#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
828 encode_sequence_maxsz +\
829 encode_putfh_maxsz + \
830 encode_layoutcommit_maxsz + \
831 encode_getattr_maxsz)
832#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
833 decode_sequence_maxsz + \
834 decode_putfh_maxsz + \
835 decode_layoutcommit_maxsz + \
836 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300837#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
838 encode_sequence_maxsz + \
839 encode_putfh_maxsz + \
840 encode_layoutreturn_maxsz)
841#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
842 decode_sequence_maxsz + \
843 decode_putfh_maxsz + \
844 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400845#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
846 encode_sequence_maxsz + \
847 encode_putrootfh_maxsz +\
848 encode_secinfo_no_name_maxsz)
849#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
850 decode_sequence_maxsz + \
851 decode_putrootfh_maxsz + \
852 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400853#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
854 encode_sequence_maxsz + \
855 encode_test_stateid_maxsz)
856#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
857 decode_sequence_maxsz + \
858 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400859#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
860 encode_sequence_maxsz + \
861 encode_free_stateid_maxsz)
862#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
863 decode_sequence_maxsz + \
864 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500865
866const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
867 compound_encode_hdr_maxsz +
868 encode_sequence_maxsz +
869 encode_putfh_maxsz +
870 encode_getattr_maxsz) *
871 XDR_UNIT);
872
873const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
874 compound_decode_hdr_maxsz +
875 decode_sequence_maxsz +
876 decode_putfh_maxsz) *
877 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400878
879const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
880 compound_decode_hdr_maxsz +
881 decode_sequence_maxsz) *
882 XDR_UNIT);
883EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400884#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Trond Myklebustbca79472009-03-11 14:10:26 -0400886static const umode_t nfs_type2fmt[] = {
887 [NF4BAD] = 0,
888 [NF4REG] = S_IFREG,
889 [NF4DIR] = S_IFDIR,
890 [NF4BLK] = S_IFBLK,
891 [NF4CHR] = S_IFCHR,
892 [NF4LNK] = S_IFLNK,
893 [NF4SOCK] = S_IFSOCK,
894 [NF4FIFO] = S_IFIFO,
895 [NF4ATTRDIR] = 0,
896 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897};
898
899struct compound_hdr {
900 int32_t status;
901 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500902 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 uint32_t taglen;
904 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400905 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400906 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907};
908
Benny Halevy13c65ce2009-08-14 17:19:25 +0300909static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
910{
911 __be32 *p = xdr_reserve_space(xdr, nbytes);
912 BUG_ON(!p);
913 return p;
914}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Trond Myklebustcb17e552012-03-04 18:13:56 -0500916static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
917{
918 __be32 *p;
919
920 p = xdr_reserve_space(xdr, len);
921 xdr_encode_opaque_fixed(p, buf, len);
922}
923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
925{
Al Viro8687b632006-10-19 23:28:48 -0700926 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500928 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 xdr_encode_opaque(p, str, len);
930}
931
Trond Myklebust4ade9822012-03-04 18:13:57 -0500932static void encode_uint32(struct xdr_stream *xdr, u32 n)
933{
934 __be32 *p;
935
936 p = reserve_space(xdr, 4);
937 *p = cpu_to_be32(n);
938}
939
Trond Myklebustff2eb682012-03-05 11:40:12 -0500940static void encode_uint64(struct xdr_stream *xdr, u64 n)
941{
942 __be32 *p;
943
944 p = reserve_space(xdr, 8);
945 xdr_encode_hyper(p, n);
946}
947
Trond Myklebust4ade9822012-03-04 18:13:57 -0500948static void encode_nfs4_seqid(struct xdr_stream *xdr,
949 const struct nfs_seqid *seqid)
950{
Trond Myklebusta6796412015-01-23 19:04:44 -0500951 if (seqid != NULL)
952 encode_uint32(xdr, seqid->sequence->counter);
953 else
954 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500955}
956
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400957static void encode_compound_hdr(struct xdr_stream *xdr,
958 struct rpc_rqst *req,
959 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
Al Viro8687b632006-10-19 23:28:48 -0700961 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400962 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400963
964 /* initialize running count of expected bytes in reply.
965 * NOTE: the replied tag SHOULD be the same is the one sent,
966 * but this is not required as a MUST for the server to do so. */
967 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Trond Myklebust7fc38842012-10-15 11:51:21 -0400969 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500970 encode_string(xdr, hdr->taglen, hdr->tag);
971 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300972 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500973 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300974 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500975}
976
Trond Myklebustab19b482012-03-04 18:13:57 -0500977static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
978 uint32_t replen,
979 struct compound_hdr *hdr)
980{
981 encode_uint32(xdr, op);
982 hdr->nops++;
983 hdr->replen += replen;
984}
985
Andy Adamsond0179312008-12-23 16:06:17 -0500986static void encode_nops(struct compound_hdr *hdr)
987{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400988 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500989 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990}
991
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500992static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
993{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500994 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500995}
996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
998{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500999 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000}
1001
David Quigleyaa9c2662013-05-22 12:50:44 -04001002static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1003 const struct nfs4_label *label,
1004 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005{
1006 char owner_name[IDMAP_NAMESZ];
1007 char owner_group[IDMAP_NAMESZ];
1008 int owner_namelen = 0;
1009 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001010 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001011 unsigned i;
1012 uint32_t len = 0;
1013 uint32_t bmval_len;
1014 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 /*
1017 * We reserve enough space to write the entire attribute buffer at once.
1018 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001019 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1020 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001021 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001023 if (iap->ia_valid & ATTR_SIZE) {
1024 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001026 }
1027 if (iap->ia_valid & ATTR_MODE) {
1028 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001032 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001034 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001035 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 /* XXX */
1037 strcpy(owner_name, "nobody");
1038 owner_namelen = sizeof("nobody") - 1;
1039 /* goto out; */
1040 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001041 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1043 }
1044 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001045 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001047 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001048 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 strcpy(owner_group, "nobody");
1050 owner_grouplen = sizeof("nobody") - 1;
1051 /* goto out; */
1052 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001053 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1055 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001057 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1058 len += 16;
1059 } else if (iap->ia_valid & ATTR_ATIME) {
1060 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1061 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
1063 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001064 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1065 len += 16;
1066 } else if (iap->ia_valid & ATTR_MTIME) {
1067 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1068 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001070 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001071 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1072 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1073 }
1074
1075 if (bmval[2] != 0)
1076 bmval_len = 3;
1077 else if (bmval[1] != 0)
1078 bmval_len = 2;
1079 else
1080 bmval_len = 1;
1081
1082 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1083
1084 *p++ = cpu_to_be32(bmval_len);
1085 for (i = 0; i < bmval_len; i++)
1086 *p++ = cpu_to_be32(bmval[i]);
1087 *p++ = cpu_to_be32(len);
1088
1089 if (bmval[0] & FATTR4_WORD0_SIZE)
1090 p = xdr_encode_hyper(p, iap->ia_size);
1091 if (bmval[1] & FATTR4_WORD1_MODE)
1092 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1093 if (bmval[1] & FATTR4_WORD1_OWNER)
1094 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1095 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1096 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1097 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1098 if (iap->ia_valid & ATTR_ATIME_SET) {
1099 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1100 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1101 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1102 } else
1103 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1104 }
1105 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1106 if (iap->ia_valid & ATTR_MTIME_SET) {
1107 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1108 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1109 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1110 } else
1111 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1112 }
1113 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001114 *p++ = cpu_to_be32(label->lfs);
1115 *p++ = cpu_to_be32(label->pi);
1116 *p++ = cpu_to_be32(label->len);
1117 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1118 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121}
1122
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001123static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001125 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1126 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001129static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
Trond Myklebustab19b482012-03-04 18:13:57 -05001131 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001132 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001133 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134}
1135
Fred Isaman0b7c0152012-04-20 14:47:39 -04001136static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137{
Al Viro8687b632006-10-19 23:28:48 -07001138 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001139
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001140 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1141 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001142 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001143 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001146static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147{
Al Viro8687b632006-10-19 23:28:48 -07001148 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001149
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001150 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1151 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
1153 switch (create->ftype) {
1154 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001155 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001156 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001157 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 break;
1159
1160 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001161 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001162 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001163 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 break;
1165
1166 default:
1167 break;
1168 }
1169
Benny Halevy811652b2009-08-14 17:19:34 +03001170 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001171 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172}
1173
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001174static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175{
Andy Adamson05d564f2008-12-23 16:06:15 -05001176 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001178 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1179 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001180 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001181 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182}
1183
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001184static 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 -07001185{
Andy Adamson05d564f2008-12-23 16:06:15 -05001186 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001188 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1189 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001190 *p++ = cpu_to_be32(2);
1191 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001192 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193}
1194
Fred Isamandae100c2011-07-30 20:52:37 -04001195static void
1196encode_getattr_three(struct xdr_stream *xdr,
1197 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1198 struct compound_hdr *hdr)
1199{
1200 __be32 *p;
1201
Trond Myklebustab19b482012-03-04 18:13:57 -05001202 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001203 if (bm2) {
1204 p = reserve_space(xdr, 16);
1205 *p++ = cpu_to_be32(3);
1206 *p++ = cpu_to_be32(bm0);
1207 *p++ = cpu_to_be32(bm1);
1208 *p = cpu_to_be32(bm2);
1209 } else if (bm1) {
1210 p = reserve_space(xdr, 12);
1211 *p++ = cpu_to_be32(2);
1212 *p++ = cpu_to_be32(bm0);
1213 *p = cpu_to_be32(bm1);
1214 } else {
1215 p = reserve_space(xdr, 8);
1216 *p++ = cpu_to_be32(1);
1217 *p = cpu_to_be32(bm0);
1218 }
Fred Isamandae100c2011-07-30 20:52:37 -04001219}
1220
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001221static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222{
David Quigleya09df2c2013-05-22 12:50:41 -04001223 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1224 bitmask[1] & nfs4_fattr_bitmap[1],
1225 bitmask[2] & nfs4_fattr_bitmap[2],
1226 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227}
1228
Andy Adamson88034c32012-05-23 05:02:34 -04001229static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001230 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001231 struct compound_hdr *hdr)
1232{
1233 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001234 bitmask[0] & open_bitmap[0],
1235 bitmask[1] & open_bitmap[1],
1236 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001237 hdr);
1238}
1239
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001240static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241{
Fred Isamandae100c2011-07-30 20:52:37 -04001242 encode_getattr_three(xdr,
1243 bitmask[0] & nfs4_fsinfo_bitmap[0],
1244 bitmask[1] & nfs4_fsinfo_bitmap[1],
1245 bitmask[2] & nfs4_fsinfo_bitmap[2],
1246 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247}
1248
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001249static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001250{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001251 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1252 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001253}
1254
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001255static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256{
Trond Myklebustab19b482012-03-04 18:13:57 -05001257 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258}
1259
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001260static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
Trond Myklebustab19b482012-03-04 18:13:57 -05001262 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001263 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264}
1265
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001266static inline int nfs4_lock_type(struct file_lock *fl, int block)
1267{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001268 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001269 return block ? NFS4_READW_LT : NFS4_READ_LT;
1270 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1271}
1272
1273static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1274{
1275 if (fl->fl_end == OFFSET_MAX)
1276 return ~(uint64_t)0;
1277 return fl->fl_end - fl->fl_start + 1;
1278}
1279
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001280static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1281{
1282 __be32 *p;
1283
Trond Myklebustd035c362010-12-21 10:45:27 -05001284 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001285 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001286 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001287 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001288 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001289 xdr_encode_hyper(p, lowner->id);
1290}
1291
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292/*
1293 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1294 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1295 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001296static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297{
Al Viro8687b632006-10-19 23:28:48 -07001298 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001300 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1301 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001302 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1303 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001304 p = xdr_encode_hyper(p, args->fl->fl_start);
1305 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001306 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001307 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001308 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001309 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001310 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001311 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 }
1313 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001314 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001315 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317}
1318
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001319static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_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_LOCKT, decode_lockt_maxsz, hdr);
1324 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001325 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001326 p = xdr_encode_hyper(p, args->fl->fl_start);
1327 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001328 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329}
1330
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001331static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332{
Al Viro8687b632006-10-19 23:28:48 -07001333 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001335 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1336 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001337 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001338 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001339 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001340 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001341 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342}
1343
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001344static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1345{
Trond Myklebustab19b482012-03-04 18:13:57 -05001346 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001347 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001348}
1349
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001350static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351{
Trond Myklebustab19b482012-03-04 18:13:57 -05001352 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001353 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354}
1355
Trond Myklebust6ae37332015-01-30 14:21:14 -05001356static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357{
Al Viro8687b632006-10-19 23:28:48 -07001358 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
Benny Halevy13c65ce2009-08-14 17:19:25 +03001360 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001361 *p++ = cpu_to_be32(share_access);
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 Myklebust6ae37332015-01-30 14:21:14 -05001373 encode_share_access(xdr, arg->share_access);
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 Myklebust566fcec2015-01-23 15:32:46 -05001526 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001527 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001528 encode_share_access(xdr, arg->share_access);
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
Jeff Layton3a6bb732015-06-09 19:43:57 -04001672 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1673 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001674 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001675 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1677 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001678 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001679 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680}
1681
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001682static 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 -07001683{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001684 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1685 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001686 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001687 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688}
1689
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001690static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1691 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692{
Al Viro8687b632006-10-19 23:28:48 -07001693 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
Trond Myklebustab19b482012-03-04 18:13:57 -05001695 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001696 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Benny Halevy13c65ce2009-08-14 17:19:25 +03001698 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001699 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001700 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001701 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
1703 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704}
1705
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001706static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707{
Trond Myklebustab19b482012-03-04 18:13:57 -05001708 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001709 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001711
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001712static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1713{
Trond Myklebustab19b482012-03-04 18:13:57 -05001714 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001715 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001716}
1717
Benny Halevy99fe60d2009-04-01 09:22:29 -04001718#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001719/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001720static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08001721 struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001722 struct compound_hdr *hdr)
1723{
1724 __be32 *p;
1725
1726 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1727 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001728 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001729 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001730 *p++ = cpu_to_be32(args->dir);
1731 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001732}
1733
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001734static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1735{
1736 unsigned int i;
1737 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1738 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1739 encode_uint32(xdr, op_map->u.words[i]);
1740}
1741
Benny Halevy99fe60d2009-04-01 09:22:29 -04001742static void encode_exchange_id(struct xdr_stream *xdr,
1743 struct nfs41_exchange_id_args *args,
1744 struct compound_hdr *hdr)
1745{
1746 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001747 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001748 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001749
Trond Myklebust70019512012-03-04 20:49:32 -05001750 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001751 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001752
Jeff Layton3a6bb732015-06-09 19:43:57 -04001753 encode_string(xdr, strlen(args->client->cl_owner_id),
1754 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001755
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001756 encode_uint32(xdr, args->flags);
1757 encode_uint32(xdr, args->state_protect.how);
1758
1759 switch (args->state_protect.how) {
1760 case SP4_NONE:
1761 break;
1762 case SP4_MACH_CRED:
1763 encode_op_map(xdr, &args->state_protect.enforce);
1764 encode_op_map(xdr, &args->state_protect.allow);
1765 break;
1766 default:
1767 WARN_ON_ONCE(1);
1768 break;
1769 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001770
1771 if (send_implementation_id &&
1772 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1773 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001774 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001775 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1776 utsname()->sysname, utsname()->release,
1777 utsname()->version, utsname()->machine);
1778
1779 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001780 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001781
1782 encode_string(xdr,
1783 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1784 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1785 encode_string(xdr, len, impl_name);
1786 /* just send zeros for nii_date - the date is in nii_name */
1787 p = reserve_space(xdr, 12);
1788 p = xdr_encode_hyper(p, 0);
1789 *p = cpu_to_be32(0);
1790 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001791 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001792}
Andy Adamsonfc931582009-04-01 09:22:31 -04001793
1794static void encode_create_session(struct xdr_stream *xdr,
1795 struct nfs41_create_session_args *args,
1796 struct compound_hdr *hdr)
1797{
1798 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001799 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001800 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001801 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001802 u32 max_resp_sz_cached;
1803
1804 /*
1805 * Assumes OPEN is the biggest non-idempotent compound.
1806 * 2 is the verifier.
1807 */
1808 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1809 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001810
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001811 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001812 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001813 p = xdr_encode_hyper(p, args->clientid);
1814 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001815 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001816
Andy Adamsonfc931582009-04-01 09:22:31 -04001817 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001818 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001819 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1820 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001821 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001822 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1823 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1824 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001825
1826 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001827 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001828 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1829 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1830 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1831 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1832 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1833 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001834
Benny Halevye75bc1c2009-08-14 17:18:54 +03001835 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001836 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001837 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001838
1839 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001840 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001841 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001842 *p++ = cpu_to_be32(0); /* UID */
1843 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001844 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001845}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001846
1847static void encode_destroy_session(struct xdr_stream *xdr,
1848 struct nfs4_session *session,
1849 struct compound_hdr *hdr)
1850{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001851 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1852 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001853}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001854
Trond Myklebust66245532012-05-25 17:18:09 -04001855static void encode_destroy_clientid(struct xdr_stream *xdr,
1856 uint64_t clientid,
1857 struct compound_hdr *hdr)
1858{
1859 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1860 encode_uint64(xdr, clientid);
1861}
1862
Ricardo Labiaga180197532009-12-05 16:08:40 -05001863static void encode_reclaim_complete(struct xdr_stream *xdr,
1864 struct nfs41_reclaim_complete_args *args,
1865 struct compound_hdr *hdr)
1866{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001867 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1868 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001869}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001870#endif /* CONFIG_NFS_V4_1 */
1871
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001872static void encode_sequence(struct xdr_stream *xdr,
1873 const struct nfs4_sequence_args *args,
1874 struct compound_hdr *hdr)
1875{
1876#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001877 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001878 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001879 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001880 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001881
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001882 tp = slot->table;
1883 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001884 if (!session)
1885 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001886
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001887 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001888
1889 /*
1890 * Sessionid + seqid + slotid + max slotid + cache_this
1891 */
1892 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1893 "max_slotid=%d cache_this=%d\n",
1894 __func__,
1895 ((u32 *)session->sess_id.data)[0],
1896 ((u32 *)session->sess_id.data)[1],
1897 ((u32 *)session->sess_id.data)[2],
1898 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001899 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001900 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001901 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001902 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001903 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001904 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001905 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001906 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001907#endif /* CONFIG_NFS_V4_1 */
1908}
1909
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001910#ifdef CONFIG_NFS_V4_1
1911static void
1912encode_getdeviceinfo(struct xdr_stream *xdr,
1913 const struct nfs4_getdeviceinfo_args *args,
1914 struct compound_hdr *hdr)
1915{
1916 __be32 *p;
1917
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001918 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001919 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001920 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1921 NFS4_DEVICEID4_SIZE);
1922 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001923 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001924
1925 p = reserve_space(xdr, 4 + 4);
1926 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001927 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001928}
1929
1930static void
1931encode_layoutget(struct xdr_stream *xdr,
1932 const struct nfs4_layoutget_args *args,
1933 struct compound_hdr *hdr)
1934{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001935 __be32 *p;
1936
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001937 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1938 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001939 *p++ = cpu_to_be32(0); /* Signal layout available */
1940 *p++ = cpu_to_be32(args->type);
1941 *p++ = cpu_to_be32(args->range.iomode);
1942 p = xdr_encode_hyper(p, args->range.offset);
1943 p = xdr_encode_hyper(p, args->range.length);
1944 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001945 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001946 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001947
1948 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1949 __func__,
1950 args->type,
1951 args->range.iomode,
1952 (unsigned long)args->range.offset,
1953 (unsigned long)args->range.length,
1954 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001955}
Andy Adamson863a3c62011-03-23 13:27:54 +00001956
1957static int
1958encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001959 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001960 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001961 struct compound_hdr *hdr)
1962{
1963 __be32 *p;
1964
1965 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1966 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1967
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001968 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1969 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001970 /* Only whole file layouts */
1971 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001972 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001973 *p = cpu_to_be32(0); /* reclaim */
1974 encode_nfs4_stateid(xdr, &args->stateid);
1975 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001976 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1977 p = xdr_encode_hyper(p, args->lastbytewritten);
1978 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1979 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001980
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001981 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03001982 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1983 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001984 } else {
1985 encode_uint32(xdr, args->layoutupdate_len);
1986 if (args->layoutupdate_pages) {
1987 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
1988 args->layoutupdate_len);
1989 }
1990 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001991
Andy Adamson863a3c62011-03-23 13:27:54 +00001992 return 0;
1993}
Benny Halevycbe82602011-05-22 19:52:37 +03001994
1995static void
1996encode_layoutreturn(struct xdr_stream *xdr,
1997 const struct nfs4_layoutreturn_args *args,
1998 struct compound_hdr *hdr)
1999{
2000 __be32 *p;
2001
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002002 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2003 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002004 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2005 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002006 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002007 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002008 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002009 p = xdr_encode_hyper(p, args->range.offset);
2010 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002011 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002012 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002013 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002014 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2015 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2016 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002017 } else
2018 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002019}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002020
2021static int
2022encode_secinfo_no_name(struct xdr_stream *xdr,
2023 const struct nfs41_secinfo_no_name_args *args,
2024 struct compound_hdr *hdr)
2025{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002026 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2027 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002028 return 0;
2029}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002030
2031static void encode_test_stateid(struct xdr_stream *xdr,
2032 struct nfs41_test_stateid_args *args,
2033 struct compound_hdr *hdr)
2034{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002035 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2036 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002037 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002038}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002039
2040static void encode_free_stateid(struct xdr_stream *xdr,
2041 struct nfs41_free_stateid_args *args,
2042 struct compound_hdr *hdr)
2043{
Trond Myklebustab19b482012-03-04 18:13:57 -05002044 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002045 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002046}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002047#endif /* CONFIG_NFS_V4_1 */
2048
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049/*
2050 * END OF "GENERIC" ENCODE ROUTINES.
2051 */
2052
Benny Halevy66cc0422009-04-01 09:22:10 -04002053static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2054{
2055#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002056 struct nfs4_session *session = args->sa_slot->table->session;
2057 if (session)
2058 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002059#endif /* CONFIG_NFS_V4_1 */
2060 return 0;
2061}
2062
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063/*
2064 * Encode an ACCESS request
2065 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002066static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2067 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002070 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072
Chuck Lever9f06c712010-12-14 14:59:18 +00002073 encode_compound_hdr(xdr, req, &hdr);
2074 encode_sequence(xdr, &args->seq_args, &hdr);
2075 encode_putfh(xdr, args->fh, &hdr);
2076 encode_access(xdr, args->access, &hdr);
2077 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002078 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079}
2080
2081/*
2082 * Encode LOOKUP request
2083 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002084static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2085 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002088 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
Chuck Lever9f06c712010-12-14 14:59:18 +00002091 encode_compound_hdr(xdr, req, &hdr);
2092 encode_sequence(xdr, &args->seq_args, &hdr);
2093 encode_putfh(xdr, args->dir_fh, &hdr);
2094 encode_lookup(xdr, args->name, &hdr);
2095 encode_getfh(xdr, &hdr);
2096 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002097 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098}
2099
2100/*
2101 * Encode LOOKUP_ROOT request
2102 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002103static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2104 struct xdr_stream *xdr,
2105 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002108 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110
Chuck Lever9f06c712010-12-14 14:59:18 +00002111 encode_compound_hdr(xdr, req, &hdr);
2112 encode_sequence(xdr, &args->seq_args, &hdr);
2113 encode_putrootfh(xdr, &hdr);
2114 encode_getfh(xdr, &hdr);
2115 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002116 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117}
2118
2119/*
2120 * Encode REMOVE request
2121 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002122static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2123 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002126 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128
Chuck Lever9f06c712010-12-14 14:59:18 +00002129 encode_compound_hdr(xdr, req, &hdr);
2130 encode_sequence(xdr, &args->seq_args, &hdr);
2131 encode_putfh(xdr, args->fh, &hdr);
2132 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002133 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134}
2135
2136/*
2137 * Encode RENAME request
2138 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002139static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2140 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002143 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
Chuck Lever9f06c712010-12-14 14:59:18 +00002146 encode_compound_hdr(xdr, req, &hdr);
2147 encode_sequence(xdr, &args->seq_args, &hdr);
2148 encode_putfh(xdr, args->old_dir, &hdr);
2149 encode_savefh(xdr, &hdr);
2150 encode_putfh(xdr, args->new_dir, &hdr);
2151 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002152 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153}
2154
2155/*
2156 * Encode LINK request
2157 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002158static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2159 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002162 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164
Chuck Lever9f06c712010-12-14 14:59:18 +00002165 encode_compound_hdr(xdr, req, &hdr);
2166 encode_sequence(xdr, &args->seq_args, &hdr);
2167 encode_putfh(xdr, args->fh, &hdr);
2168 encode_savefh(xdr, &hdr);
2169 encode_putfh(xdr, args->dir_fh, &hdr);
2170 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002171 encode_restorefh(xdr, &hdr);
2172 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002173 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174}
2175
2176/*
2177 * Encode CREATE request
2178 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002179static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2180 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002183 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
Chuck Lever9f06c712010-12-14 14:59:18 +00002186 encode_compound_hdr(xdr, req, &hdr);
2187 encode_sequence(xdr, &args->seq_args, &hdr);
2188 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002189 encode_create(xdr, args, &hdr);
2190 encode_getfh(xdr, &hdr);
2191 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002192 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193}
2194
2195/*
2196 * Encode SYMLINK request
2197 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002198static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2199 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200{
Chuck Lever9f06c712010-12-14 14:59:18 +00002201 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202}
2203
2204/*
2205 * Encode GETATTR request
2206 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002207static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2208 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002211 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Chuck Lever9f06c712010-12-14 14:59:18 +00002214 encode_compound_hdr(xdr, req, &hdr);
2215 encode_sequence(xdr, &args->seq_args, &hdr);
2216 encode_putfh(xdr, args->fh, &hdr);
2217 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002218 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219}
2220
2221/*
2222 * Encode a CLOSE request
2223 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002224static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2225 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
Andy Adamson05d564f2008-12-23 16:06:15 -05002227 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002228 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002229 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
Chuck Lever9f06c712010-12-14 14:59:18 +00002231 encode_compound_hdr(xdr, req, &hdr);
2232 encode_sequence(xdr, &args->seq_args, &hdr);
2233 encode_putfh(xdr, args->fh, &hdr);
2234 encode_close(xdr, args, &hdr);
2235 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002236 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237}
2238
2239/*
2240 * Encode an OPEN request
2241 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002242static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2243 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002246 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
Chuck Lever9f06c712010-12-14 14:59:18 +00002249 encode_compound_hdr(xdr, req, &hdr);
2250 encode_sequence(xdr, &args->seq_args, &hdr);
2251 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002252 encode_open(xdr, args, &hdr);
2253 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002254 if (args->access)
2255 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002256 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002257 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258}
2259
2260/*
2261 * Encode an OPEN_CONFIRM request
2262 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002263static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2264 struct xdr_stream *xdr,
2265 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002268 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
Chuck Lever9f06c712010-12-14 14:59:18 +00002271 encode_compound_hdr(xdr, req, &hdr);
2272 encode_putfh(xdr, args->fh, &hdr);
2273 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002274 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275}
2276
2277/*
2278 * Encode an OPEN request with no attributes.
2279 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002280static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2281 struct xdr_stream *xdr,
2282 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002285 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
Chuck Lever9f06c712010-12-14 14:59:18 +00002288 encode_compound_hdr(xdr, req, &hdr);
2289 encode_sequence(xdr, &args->seq_args, &hdr);
2290 encode_putfh(xdr, args->fh, &hdr);
2291 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002292 if (args->access)
2293 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002294 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002295 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296}
2297
2298/*
2299 * Encode an OPEN_DOWNGRADE request
2300 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002301static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2302 struct xdr_stream *xdr,
2303 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002306 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308
Chuck Lever9f06c712010-12-14 14:59:18 +00002309 encode_compound_hdr(xdr, req, &hdr);
2310 encode_sequence(xdr, &args->seq_args, &hdr);
2311 encode_putfh(xdr, args->fh, &hdr);
2312 encode_open_downgrade(xdr, args, &hdr);
2313 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002314 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315}
2316
2317/*
2318 * Encode a LOCK request
2319 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002320static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2321 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002324 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326
Chuck Lever9f06c712010-12-14 14:59:18 +00002327 encode_compound_hdr(xdr, req, &hdr);
2328 encode_sequence(xdr, &args->seq_args, &hdr);
2329 encode_putfh(xdr, args->fh, &hdr);
2330 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002331 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332}
2333
2334/*
2335 * Encode a LOCKT request
2336 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002337static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2338 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002341 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
Chuck Lever9f06c712010-12-14 14:59:18 +00002344 encode_compound_hdr(xdr, req, &hdr);
2345 encode_sequence(xdr, &args->seq_args, &hdr);
2346 encode_putfh(xdr, args->fh, &hdr);
2347 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002348 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349}
2350
2351/*
2352 * Encode a LOCKU request
2353 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002354static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2355 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002358 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
Chuck Lever9f06c712010-12-14 14:59:18 +00002361 encode_compound_hdr(xdr, req, &hdr);
2362 encode_sequence(xdr, &args->seq_args, &hdr);
2363 encode_putfh(xdr, args->fh, &hdr);
2364 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002365 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366}
2367
Chuck Lever9f06c712010-12-14 14:59:18 +00002368static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2369 struct xdr_stream *xdr,
2370 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002371{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002372 struct compound_hdr hdr = {
2373 .minorversion = 0,
2374 };
2375
Chuck Lever9f06c712010-12-14 14:59:18 +00002376 encode_compound_hdr(xdr, req, &hdr);
2377 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002378 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002379}
2380
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381/*
2382 * Encode a READLINK request
2383 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002384static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2385 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002388 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
Chuck Lever9f06c712010-12-14 14:59:18 +00002391 encode_compound_hdr(xdr, req, &hdr);
2392 encode_sequence(xdr, &args->seq_args, &hdr);
2393 encode_putfh(xdr, args->fh, &hdr);
2394 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002395
Benny Halevy28f56692009-04-01 09:22:09 -04002396 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002397 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002398 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399}
2400
2401/*
2402 * Encode a READDIR request
2403 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002404static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2405 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002408 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
Chuck Lever9f06c712010-12-14 14:59:18 +00002411 encode_compound_hdr(xdr, req, &hdr);
2412 encode_sequence(xdr, &args->seq_args, &hdr);
2413 encode_putfh(xdr, args->fh, &hdr);
2414 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002415
Benny Halevy28f56692009-04-01 09:22:09 -04002416 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002417 args->pgbase, args->count);
2418 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002419 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002420 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002421 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422}
2423
2424/*
2425 * Encode a READ request
2426 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002427static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002428 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002431 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433
Chuck Lever9f06c712010-12-14 14:59:18 +00002434 encode_compound_hdr(xdr, req, &hdr);
2435 encode_sequence(xdr, &args->seq_args, &hdr);
2436 encode_putfh(xdr, args->fh, &hdr);
2437 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438
Benny Halevy28f56692009-04-01 09:22:09 -04002439 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002441 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002442 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443}
2444
2445/*
2446 * Encode an SETATTR request
2447 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002448static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2449 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450{
Andy Adamson05d564f2008-12-23 16:06:15 -05002451 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002452 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002453 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454
Chuck Lever9f06c712010-12-14 14:59:18 +00002455 encode_compound_hdr(xdr, req, &hdr);
2456 encode_sequence(xdr, &args->seq_args, &hdr);
2457 encode_putfh(xdr, args->fh, &hdr);
2458 encode_setattr(xdr, args, args->server, &hdr);
2459 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002460 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461}
2462
2463/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002464 * Encode a GETACL request
2465 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002466static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2467 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002468{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002469 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002470 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002471 };
Benny Halevy28f56692009-04-01 09:22:09 -04002472 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002473
Chuck Lever9f06c712010-12-14 14:59:18 +00002474 encode_compound_hdr(xdr, req, &hdr);
2475 encode_sequence(xdr, &args->seq_args, &hdr);
2476 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002477 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002478 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002479
Benny Halevy28f56692009-04-01 09:22:09 -04002480 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002481 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002482
Andy Adamsond0179312008-12-23 16:06:17 -05002483 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002484}
2485
2486/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 * Encode a WRITE request
2488 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002489static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002490 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002493 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
Chuck Lever9f06c712010-12-14 14:59:18 +00002496 encode_compound_hdr(xdr, req, &hdr);
2497 encode_sequence(xdr, &args->seq_args, &hdr);
2498 encode_putfh(xdr, args->fh, &hdr);
2499 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002500 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002501 if (args->bitmask)
2502 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002503 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504}
2505
2506/*
2507 * a COMMIT request
2508 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002509static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002510 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002513 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515
Chuck Lever9f06c712010-12-14 14:59:18 +00002516 encode_compound_hdr(xdr, req, &hdr);
2517 encode_sequence(xdr, &args->seq_args, &hdr);
2518 encode_putfh(xdr, args->fh, &hdr);
2519 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002520 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521}
2522
2523/*
2524 * FSINFO request
2525 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002526static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2527 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002530 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Chuck Lever9f06c712010-12-14 14:59:18 +00002533 encode_compound_hdr(xdr, req, &hdr);
2534 encode_sequence(xdr, &args->seq_args, &hdr);
2535 encode_putfh(xdr, args->fh, &hdr);
2536 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002537 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538}
2539
2540/*
2541 * a PATHCONF request
2542 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002543static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2544 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002547 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
Chuck Lever9f06c712010-12-14 14:59:18 +00002550 encode_compound_hdr(xdr, req, &hdr);
2551 encode_sequence(xdr, &args->seq_args, &hdr);
2552 encode_putfh(xdr, args->fh, &hdr);
2553 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002554 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002555 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556}
2557
2558/*
2559 * a STATFS request
2560 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002561static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2562 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002565 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567
Chuck Lever9f06c712010-12-14 14:59:18 +00002568 encode_compound_hdr(xdr, req, &hdr);
2569 encode_sequence(xdr, &args->seq_args, &hdr);
2570 encode_putfh(xdr, args->fh, &hdr);
2571 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002572 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002573 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574}
2575
2576/*
2577 * GETATTR_BITMAP request
2578 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002579static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2580 struct xdr_stream *xdr,
2581 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002584 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
Chuck Lever9f06c712010-12-14 14:59:18 +00002587 encode_compound_hdr(xdr, req, &hdr);
2588 encode_sequence(xdr, &args->seq_args, &hdr);
2589 encode_putfh(xdr, args->fhandle, &hdr);
2590 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002591 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002592 FATTR4_WORD0_LINK_SUPPORT|
2593 FATTR4_WORD0_SYMLINK_SUPPORT|
2594 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002595 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596}
2597
2598/*
2599 * a RENEW request
2600 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002601static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2602 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002605 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 };
2607
Chuck Lever9f06c712010-12-14 14:59:18 +00002608 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002609 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002610 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611}
2612
2613/*
2614 * a SETCLIENTID request
2615 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002616static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2617 struct xdr_stream *xdr,
2618 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002621 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 };
2623
Chuck Lever9f06c712010-12-14 14:59:18 +00002624 encode_compound_hdr(xdr, req, &hdr);
2625 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002626 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627}
2628
2629/*
2630 * a SETCLIENTID_CONFIRM request
2631 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002632static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2633 struct xdr_stream *xdr,
2634 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002637 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639
Chuck Lever9f06c712010-12-14 14:59:18 +00002640 encode_compound_hdr(xdr, req, &hdr);
2641 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002642 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643}
2644
2645/*
2646 * DELEGRETURN request
2647 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002648static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2649 struct xdr_stream *xdr,
2650 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002653 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
Chuck Lever9f06c712010-12-14 14:59:18 +00002656 encode_compound_hdr(xdr, req, &hdr);
2657 encode_sequence(xdr, &args->seq_args, &hdr);
2658 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002659 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002660 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002661 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662}
2663
2664/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002665 * Encode FS_LOCATIONS request
2666 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002667static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2668 struct xdr_stream *xdr,
2669 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002670{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002671 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002672 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002673 };
Benny Halevy28f56692009-04-01 09:22:09 -04002674 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002675
Chuck Lever9f06c712010-12-14 14:59:18 +00002676 encode_compound_hdr(xdr, req, &hdr);
2677 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002678 if (args->migration) {
2679 encode_putfh(xdr, args->fh, &hdr);
2680 replen = hdr.replen;
2681 encode_fs_locations(xdr, args->bitmask, &hdr);
2682 if (args->renew)
2683 encode_renew(xdr, args->clientid, &hdr);
2684 } else {
2685 encode_putfh(xdr, args->dir_fh, &hdr);
2686 encode_lookup(xdr, args->name, &hdr);
2687 replen = hdr.replen;
2688 encode_fs_locations(xdr, args->bitmask, &hdr);
2689 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002690
Chuck Leverb03d7352013-10-17 14:12:50 -04002691 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002692 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002693 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002694 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002695}
2696
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002697/*
2698 * Encode SECINFO request
2699 */
2700static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2701 struct xdr_stream *xdr,
2702 struct nfs4_secinfo_arg *args)
2703{
2704 struct compound_hdr hdr = {
2705 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2706 };
2707
2708 encode_compound_hdr(xdr, req, &hdr);
2709 encode_sequence(xdr, &args->seq_args, &hdr);
2710 encode_putfh(xdr, args->dir_fh, &hdr);
2711 encode_secinfo(xdr, args->name, &hdr);
2712 encode_nops(&hdr);
2713}
2714
Chuck Lever44c99932013-10-17 14:13:30 -04002715/*
2716 * Encode FSID_PRESENT request
2717 */
2718static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2719 struct xdr_stream *xdr,
2720 struct nfs4_fsid_present_arg *args)
2721{
2722 struct compound_hdr hdr = {
2723 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2724 };
2725
2726 encode_compound_hdr(xdr, req, &hdr);
2727 encode_sequence(xdr, &args->seq_args, &hdr);
2728 encode_putfh(xdr, args->fh, &hdr);
2729 encode_getfh(xdr, &hdr);
2730 if (args->renew)
2731 encode_renew(xdr, args->clientid, &hdr);
2732 encode_nops(&hdr);
2733}
2734
Benny Halevy99fe60d2009-04-01 09:22:29 -04002735#if defined(CONFIG_NFS_V4_1)
2736/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002737 * BIND_CONN_TO_SESSION request
2738 */
2739static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2740 struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08002741 struct nfs41_bind_conn_to_session_args *args)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002742{
2743 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002744 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002745 };
2746
2747 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002748 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002749 encode_nops(&hdr);
2750}
2751
2752/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002753 * EXCHANGE_ID request
2754 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002755static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2756 struct xdr_stream *xdr,
2757 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002758{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002759 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002760 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002761 };
2762
Chuck Lever9f06c712010-12-14 14:59:18 +00002763 encode_compound_hdr(xdr, req, &hdr);
2764 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002765 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002766}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002767
2768/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002769 * a CREATE_SESSION request
2770 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002771static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2772 struct xdr_stream *xdr,
2773 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002774{
Andy Adamsonfc931582009-04-01 09:22:31 -04002775 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002776 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002777 };
2778
Chuck Lever9f06c712010-12-14 14:59:18 +00002779 encode_compound_hdr(xdr, req, &hdr);
2780 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002781 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002782}
2783
2784/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002785 * a DESTROY_SESSION request
2786 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002787static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2788 struct xdr_stream *xdr,
2789 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002790{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002791 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002792 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002793 };
2794
Chuck Lever9f06c712010-12-14 14:59:18 +00002795 encode_compound_hdr(xdr, req, &hdr);
2796 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002797 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002798}
2799
2800/*
Trond Myklebust66245532012-05-25 17:18:09 -04002801 * a DESTROY_CLIENTID request
2802 */
2803static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2804 struct xdr_stream *xdr,
2805 struct nfs_client *clp)
2806{
2807 struct compound_hdr hdr = {
2808 .minorversion = clp->cl_mvops->minor_version,
2809 };
2810
2811 encode_compound_hdr(xdr, req, &hdr);
2812 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2813 encode_nops(&hdr);
2814}
2815
2816/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002817 * a SEQUENCE request
2818 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002819static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2820 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002821{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002822 struct compound_hdr hdr = {
2823 .minorversion = nfs4_xdr_minorversion(args),
2824 };
2825
Chuck Lever9f06c712010-12-14 14:59:18 +00002826 encode_compound_hdr(xdr, req, &hdr);
2827 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002828 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002829}
2830
2831/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002832 * a GET_LEASE_TIME request
2833 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002834static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2835 struct xdr_stream *xdr,
2836 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002837{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002838 struct compound_hdr hdr = {
2839 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2840 };
Fred Isamandae100c2011-07-30 20:52:37 -04002841 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002842
Chuck Lever9f06c712010-12-14 14:59:18 +00002843 encode_compound_hdr(xdr, req, &hdr);
2844 encode_sequence(xdr, &args->la_seq_args, &hdr);
2845 encode_putrootfh(xdr, &hdr);
2846 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002847 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002848}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002849
2850/*
2851 * a RECLAIM_COMPLETE request
2852 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002853static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2854 struct xdr_stream *xdr,
2855 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002856{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002857 struct compound_hdr hdr = {
2858 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2859 };
2860
Chuck Lever9f06c712010-12-14 14:59:18 +00002861 encode_compound_hdr(xdr, req, &hdr);
2862 encode_sequence(xdr, &args->seq_args, &hdr);
2863 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002864 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002865}
2866
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002867/*
2868 * Encode GETDEVICEINFO request
2869 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002870static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2871 struct xdr_stream *xdr,
2872 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002873{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002874 struct compound_hdr hdr = {
2875 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2876 };
2877
Chuck Lever9f06c712010-12-14 14:59:18 +00002878 encode_compound_hdr(xdr, req, &hdr);
2879 encode_sequence(xdr, &args->seq_args, &hdr);
2880 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002881
2882 /* set up reply kvec. Subtract notification bitmap max size (2)
2883 * so that notification bitmap is put in xdr_buf tail */
2884 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2885 args->pdev->pages, args->pdev->pgbase,
2886 args->pdev->pglen);
2887
2888 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002889}
2890
2891/*
2892 * Encode LAYOUTGET request
2893 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002894static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2895 struct xdr_stream *xdr,
2896 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002897{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002898 struct compound_hdr hdr = {
2899 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2900 };
2901
Chuck Lever9f06c712010-12-14 14:59:18 +00002902 encode_compound_hdr(xdr, req, &hdr);
2903 encode_sequence(xdr, &args->seq_args, &hdr);
2904 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2905 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002906
2907 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2908 args->layout.pages, 0, args->layout.pglen);
2909
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002910 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002911}
Andy Adamson863a3c62011-03-23 13:27:54 +00002912
2913/*
2914 * Encode LAYOUTCOMMIT request
2915 */
Benny Halevycbe82602011-05-22 19:52:37 +03002916static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2917 struct xdr_stream *xdr,
2918 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002919{
Benny Halevyac7db722011-05-22 19:53:48 +03002920 struct nfs4_layoutcommit_data *data =
2921 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002922 struct compound_hdr hdr = {
2923 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2924 };
2925
2926 encode_compound_hdr(xdr, req, &hdr);
2927 encode_sequence(xdr, &args->seq_args, &hdr);
2928 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002929 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002930 encode_getfattr(xdr, args->bitmask, &hdr);
2931 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002932}
2933
2934/*
2935 * Encode LAYOUTRETURN request
2936 */
2937static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2938 struct xdr_stream *xdr,
2939 struct nfs4_layoutreturn_args *args)
2940{
2941 struct compound_hdr hdr = {
2942 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2943 };
2944
2945 encode_compound_hdr(xdr, req, &hdr);
2946 encode_sequence(xdr, &args->seq_args, &hdr);
2947 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2948 encode_layoutreturn(xdr, args, &hdr);
2949 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002950}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002951
2952/*
2953 * Encode SECINFO_NO_NAME request
2954 */
2955static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2956 struct xdr_stream *xdr,
2957 struct nfs41_secinfo_no_name_args *args)
2958{
2959 struct compound_hdr hdr = {
2960 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2961 };
2962
2963 encode_compound_hdr(xdr, req, &hdr);
2964 encode_sequence(xdr, &args->seq_args, &hdr);
2965 encode_putrootfh(xdr, &hdr);
2966 encode_secinfo_no_name(xdr, args, &hdr);
2967 encode_nops(&hdr);
2968 return 0;
2969}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002970
2971/*
2972 * Encode TEST_STATEID request
2973 */
2974static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2975 struct xdr_stream *xdr,
2976 struct nfs41_test_stateid_args *args)
2977{
2978 struct compound_hdr hdr = {
2979 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2980 };
2981
2982 encode_compound_hdr(xdr, req, &hdr);
2983 encode_sequence(xdr, &args->seq_args, &hdr);
2984 encode_test_stateid(xdr, args, &hdr);
2985 encode_nops(&hdr);
2986}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002987
2988/*
2989 * Encode FREE_STATEID request
2990 */
2991static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2992 struct xdr_stream *xdr,
2993 struct nfs41_free_stateid_args *args)
2994{
2995 struct compound_hdr hdr = {
2996 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2997 };
2998
2999 encode_compound_hdr(xdr, req, &hdr);
3000 encode_sequence(xdr, &args->seq_args, &hdr);
3001 encode_free_stateid(xdr, args, &hdr);
3002 encode_nops(&hdr);
3003}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003004#endif /* CONFIG_NFS_V4_1 */
3005
Benny Halevy686841b2009-08-14 17:19:48 +03003006static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3007{
3008 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3009 "Remaining buffer length is %tu words.\n",
3010 func, xdr->end - xdr->p);
3011}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012
Trond Myklebust683b57b2006-06-09 09:34:22 -04003013static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014{
Al Viro8687b632006-10-19 23:28:48 -07003015 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016
Benny Halevyc0eae662009-08-14 17:20:14 +03003017 p = xdr_inline_decode(xdr, 4);
3018 if (unlikely(!p))
3019 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003020 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003021 p = xdr_inline_decode(xdr, *len);
3022 if (unlikely(!p))
3023 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 *string = (char *)p;
3025 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003026out_overflow:
3027 print_overflow_msg(__func__, xdr);
3028 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029}
3030
3031static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3032{
Al Viro8687b632006-10-19 23:28:48 -07003033 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034
Benny Halevyc0eae662009-08-14 17:20:14 +03003035 p = xdr_inline_decode(xdr, 8);
3036 if (unlikely(!p))
3037 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003038 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003039 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003040
Benny Halevyc0eae662009-08-14 17:20:14 +03003041 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3042 if (unlikely(!p))
3043 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 hdr->tag = (char *)p;
3045 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003046 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003047 if (unlikely(hdr->nops < 1))
3048 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003050out_overflow:
3051 print_overflow_msg(__func__, xdr);
3052 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053}
3054
Trond Myklebustc7848f62013-12-04 17:39:23 -05003055static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3056 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057{
Al Viro8687b632006-10-19 23:28:48 -07003058 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 uint32_t opnum;
3060 int32_t nfserr;
3061
Benny Halevyc0eae662009-08-14 17:20:14 +03003062 p = xdr_inline_decode(xdr, 8);
3063 if (unlikely(!p))
3064 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003065 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003066 if (unlikely(opnum != expected))
3067 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003068 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003069 if (nfserr == NFS_OK)
3070 *nfs_retval = 0;
3071 else
3072 *nfs_retval = nfs4_stat_to_errno(nfserr);
3073 return true;
3074out_bad_operation:
3075 dprintk("nfs: Server returned operation"
3076 " %d but we issued a request for %d\n",
3077 opnum, expected);
3078 *nfs_retval = -EREMOTEIO;
3079 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003080out_overflow:
3081 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003082 *nfs_retval = -EIO;
3083 return false;
3084}
3085
3086static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3087{
3088 int retval;
3089
3090 __decode_op_hdr(xdr, expected, &retval);
3091 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092}
3093
3094/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003095static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096{
Al Viro8687b632006-10-19 23:28:48 -07003097 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003098 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 char *str;
3100
Benny Halevyc0eae662009-08-14 17:20:14 +03003101 p = xdr_inline_decode(xdr, 12);
3102 if (likely(p))
3103 return decode_opaque_inline(xdr, &strlen, &str);
3104 print_overflow_msg(__func__, xdr);
3105 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106}
3107
3108static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3109{
Al Viro8687b632006-10-19 23:28:48 -07003110 uint32_t bmlen;
3111 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112
Benny Halevyc0eae662009-08-14 17:20:14 +03003113 p = xdr_inline_decode(xdr, 4);
3114 if (unlikely(!p))
3115 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003116 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117
Fred Isamandae100c2011-07-30 20:52:37 -04003118 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003119 p = xdr_inline_decode(xdr, (bmlen << 2));
3120 if (unlikely(!p))
3121 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003123 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003124 if (bmlen > 1) {
3125 bitmap[1] = be32_to_cpup(p++);
3126 if (bmlen > 2)
3127 bitmap[2] = be32_to_cpup(p);
3128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 }
3130 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003131out_overflow:
3132 print_overflow_msg(__func__, xdr);
3133 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134}
3135
Trond Myklebust256e48b2012-06-21 11:18:13 -04003136static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137{
Al Viro8687b632006-10-19 23:28:48 -07003138 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139
Benny Halevyc0eae662009-08-14 17:20:14 +03003140 p = xdr_inline_decode(xdr, 4);
3141 if (unlikely(!p))
3142 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003143 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003144 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003146out_overflow:
3147 print_overflow_msg(__func__, xdr);
3148 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149}
3150
3151static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3152{
3153 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003154 int ret;
3155 ret = decode_attr_bitmap(xdr, bitmask);
3156 if (unlikely(ret < 0))
3157 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3159 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003160 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3161 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3162 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 return 0;
3164}
3165
3166static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3167{
Al Viro8687b632006-10-19 23:28:48 -07003168 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003169 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170
3171 *type = 0;
3172 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3173 return -EIO;
3174 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003175 p = xdr_inline_decode(xdr, 4);
3176 if (unlikely(!p))
3177 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003178 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003180 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 return -EIO;
3182 }
3183 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003184 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003186 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003187 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003188out_overflow:
3189 print_overflow_msg(__func__, xdr);
3190 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191}
3192
Chuck Lever264e6352012-03-01 17:02:05 -05003193static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3194 uint32_t *bitmap, uint32_t *type)
3195{
3196 __be32 *p;
3197
3198 *type = 0;
3199 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3200 return -EIO;
3201 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3202 p = xdr_inline_decode(xdr, 4);
3203 if (unlikely(!p))
3204 goto out_overflow;
3205 *type = be32_to_cpup(p);
3206 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3207 }
3208 dprintk("%s: expire type=0x%x\n", __func__, *type);
3209 return 0;
3210out_overflow:
3211 print_overflow_msg(__func__, xdr);
3212 return -EIO;
3213}
3214
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3216{
Al Viro8687b632006-10-19 23:28:48 -07003217 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003218 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219
3220 *change = 0;
3221 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3222 return -EIO;
3223 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003224 p = xdr_inline_decode(xdr, 8);
3225 if (unlikely(!p))
3226 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003227 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003229 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003231 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003233 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003234out_overflow:
3235 print_overflow_msg(__func__, xdr);
3236 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237}
3238
3239static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3240{
Al Viro8687b632006-10-19 23:28:48 -07003241 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003242 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243
3244 *size = 0;
3245 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3246 return -EIO;
3247 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003248 p = xdr_inline_decode(xdr, 8);
3249 if (unlikely(!p))
3250 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003251 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003253 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003255 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003256 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003257out_overflow:
3258 print_overflow_msg(__func__, xdr);
3259 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260}
3261
3262static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3263{
Al Viro8687b632006-10-19 23:28:48 -07003264 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265
3266 *res = 0;
3267 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3268 return -EIO;
3269 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003270 p = xdr_inline_decode(xdr, 4);
3271 if (unlikely(!p))
3272 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003273 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3275 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003276 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003278out_overflow:
3279 print_overflow_msg(__func__, xdr);
3280 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281}
3282
3283static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3284{
Al Viro8687b632006-10-19 23:28:48 -07003285 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286
3287 *res = 0;
3288 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3289 return -EIO;
3290 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003291 p = xdr_inline_decode(xdr, 4);
3292 if (unlikely(!p))
3293 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003294 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3296 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003297 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003299out_overflow:
3300 print_overflow_msg(__func__, xdr);
3301 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302}
3303
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003304static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305{
Al Viro8687b632006-10-19 23:28:48 -07003306 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003307 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308
3309 fsid->major = 0;
3310 fsid->minor = 0;
3311 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3312 return -EIO;
3313 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003314 p = xdr_inline_decode(xdr, 16);
3315 if (unlikely(!p))
3316 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003317 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003318 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003320 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003322 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 (unsigned long long)fsid->major,
3324 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003325 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003326out_overflow:
3327 print_overflow_msg(__func__, xdr);
3328 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329}
3330
3331static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3332{
Al Viro8687b632006-10-19 23:28:48 -07003333 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334
3335 *res = 60;
3336 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3337 return -EIO;
3338 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003339 p = xdr_inline_decode(xdr, 4);
3340 if (unlikely(!p))
3341 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003342 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3344 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003345 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003347out_overflow:
3348 print_overflow_msg(__func__, xdr);
3349 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350}
3351
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003352static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003353{
3354 __be32 *p;
3355
3356 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3357 return -EIO;
3358 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3359 p = xdr_inline_decode(xdr, 4);
3360 if (unlikely(!p))
3361 goto out_overflow;
3362 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003363 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003364 }
3365 return 0;
3366out_overflow:
3367 print_overflow_msg(__func__, xdr);
3368 return -EIO;
3369}
3370
3371static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3372{
3373 __be32 *p;
3374 int len;
3375
Trond Myklebust7ad07352010-10-23 15:34:20 -04003376 if (fh != NULL)
3377 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003378
3379 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3380 return -EIO;
3381 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3382 p = xdr_inline_decode(xdr, 4);
3383 if (unlikely(!p))
3384 goto out_overflow;
3385 len = be32_to_cpup(p);
3386 if (len > NFS4_FHSIZE)
3387 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003388 p = xdr_inline_decode(xdr, len);
3389 if (unlikely(!p))
3390 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003391 if (fh != NULL) {
3392 memcpy(fh->data, p, len);
3393 fh->size = len;
3394 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003395 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3396 }
3397 return 0;
3398out_overflow:
3399 print_overflow_msg(__func__, xdr);
3400 return -EIO;
3401}
3402
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3404{
Al Viro8687b632006-10-19 23:28:48 -07003405 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003407 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3409 return -EIO;
3410 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003411 p = xdr_inline_decode(xdr, 4);
3412 if (unlikely(!p))
3413 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003414 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3416 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003417 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003419out_overflow:
3420 print_overflow_msg(__func__, xdr);
3421 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422}
3423
3424static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3425{
Al Viro8687b632006-10-19 23:28:48 -07003426 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003427 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428
3429 *fileid = 0;
3430 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3431 return -EIO;
3432 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003433 p = xdr_inline_decode(xdr, 8);
3434 if (unlikely(!p))
3435 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003436 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003438 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003440 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003441 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003442out_overflow:
3443 print_overflow_msg(__func__, xdr);
3444 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445}
3446
Manoj Naik99baf622006-06-09 09:34:24 -04003447static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3448{
Al Viro8687b632006-10-19 23:28:48 -07003449 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003450 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003451
3452 *fileid = 0;
3453 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3454 return -EIO;
3455 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003456 p = xdr_inline_decode(xdr, 8);
3457 if (unlikely(!p))
3458 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003459 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003460 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003461 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003462 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003463 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003464 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003465out_overflow:
3466 print_overflow_msg(__func__, xdr);
3467 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003468}
3469
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3471{
Al Viro8687b632006-10-19 23:28:48 -07003472 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 int status = 0;
3474
3475 *res = 0;
3476 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3477 return -EIO;
3478 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003479 p = xdr_inline_decode(xdr, 8);
3480 if (unlikely(!p))
3481 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003482 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3484 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003485 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003487out_overflow:
3488 print_overflow_msg(__func__, xdr);
3489 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490}
3491
3492static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3493{
Al Viro8687b632006-10-19 23:28:48 -07003494 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 int status = 0;
3496
3497 *res = 0;
3498 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3499 return -EIO;
3500 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003501 p = xdr_inline_decode(xdr, 8);
3502 if (unlikely(!p))
3503 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003504 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3506 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003507 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003509out_overflow:
3510 print_overflow_msg(__func__, xdr);
3511 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512}
3513
3514static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3515{
Al Viro8687b632006-10-19 23:28:48 -07003516 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 int status = 0;
3518
3519 *res = 0;
3520 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3521 return -EIO;
3522 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003523 p = xdr_inline_decode(xdr, 8);
3524 if (unlikely(!p))
3525 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003526 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3528 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003529 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003531out_overflow:
3532 print_overflow_msg(__func__, xdr);
3533 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534}
3535
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003536static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3537{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003538 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003539 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003540 int status = 0;
3541
Benny Halevyc0eae662009-08-14 17:20:14 +03003542 p = xdr_inline_decode(xdr, 4);
3543 if (unlikely(!p))
3544 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003545 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003546 if (n == 0)
3547 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003548 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003549 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3550 dprintk("cannot parse %d components in path\n", n);
3551 goto out_eio;
3552 }
3553 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003554 struct nfs4_string *component = &path->components[path->ncomponents];
3555 status = decode_opaque_inline(xdr, &component->len, &component->data);
3556 if (unlikely(status != 0))
3557 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003558 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003559 pr_cont("%s%.*s ",
3560 (path->ncomponents != n ? "/ " : ""),
3561 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003562 }
3563out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003564 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003565root_path:
3566/* a root pathname is sent as a zero component4 */
3567 path->ncomponents = 1;
3568 path->components[0].len=0;
3569 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003570 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003571 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003572out_eio:
3573 dprintk(" status %d", status);
3574 status = -EIO;
3575 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003576out_overflow:
3577 print_overflow_msg(__func__, xdr);
3578 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003579}
3580
3581static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003582{
3583 int n;
Al Viro8687b632006-10-19 23:28:48 -07003584 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003585 int status = -EIO;
3586
3587 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3588 goto out;
3589 status = 0;
3590 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3591 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003592 status = -EIO;
3593 /* Ignore borken servers that return unrequested attrs */
3594 if (unlikely(res == NULL))
3595 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003596 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003597 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003598 if (unlikely(status != 0))
3599 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003600 p = xdr_inline_decode(xdr, 4);
3601 if (unlikely(!p))
3602 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003603 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003604 if (n <= 0)
3605 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003606 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003607 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003608 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003609
Trond Myklebust809b4262013-03-27 11:54:45 -04003610 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3611 break;
3612 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003613 p = xdr_inline_decode(xdr, 4);
3614 if (unlikely(!p))
3615 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003616 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003617
Chuck Lever02a29762012-03-01 17:00:31 -05003618 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003619 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3620 struct nfs4_string *server;
3621
3622 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003623 unsigned int i;
3624 dprintk("%s: using first %u of %u servers "
3625 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003626 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003627 NFS4_FS_LOCATION_MAXSERVERS,
3628 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003629 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003630 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003631 char *data;
3632 status = decode_opaque_inline(xdr, &len, &data);
3633 if (unlikely(status != 0))
3634 goto out_eio;
3635 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003636 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003637 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003638 server = &loc->servers[loc->nservers];
3639 status = decode_opaque_inline(xdr, &server->len, &server->data);
3640 if (unlikely(status != 0))
3641 goto out_eio;
3642 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003643 }
3644 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003645 if (unlikely(status != 0))
3646 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003647 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003648 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003649 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003650out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003651 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003652 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003653out_overflow:
3654 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003655out_eio:
3656 status = -EIO;
3657 goto out;
3658}
3659
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3661{
Al Viro8687b632006-10-19 23:28:48 -07003662 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 int status = 0;
3664
3665 *res = 0;
3666 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3667 return -EIO;
3668 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003669 p = xdr_inline_decode(xdr, 8);
3670 if (unlikely(!p))
3671 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003672 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3674 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003675 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003677out_overflow:
3678 print_overflow_msg(__func__, xdr);
3679 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680}
3681
3682static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3683{
Al Viro8687b632006-10-19 23:28:48 -07003684 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 int status = 0;
3686
3687 *maxlink = 1;
3688 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3689 return -EIO;
3690 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003691 p = xdr_inline_decode(xdr, 4);
3692 if (unlikely(!p))
3693 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003694 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3696 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003697 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003699out_overflow:
3700 print_overflow_msg(__func__, xdr);
3701 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702}
3703
3704static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3705{
Al Viro8687b632006-10-19 23:28:48 -07003706 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 int status = 0;
3708
3709 *maxname = 1024;
3710 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3711 return -EIO;
3712 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003713 p = xdr_inline_decode(xdr, 4);
3714 if (unlikely(!p))
3715 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003716 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3718 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003719 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003721out_overflow:
3722 print_overflow_msg(__func__, xdr);
3723 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724}
3725
3726static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3727{
Al Viro8687b632006-10-19 23:28:48 -07003728 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 int status = 0;
3730
3731 *res = 1024;
3732 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3733 return -EIO;
3734 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3735 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003736 p = xdr_inline_decode(xdr, 8);
3737 if (unlikely(!p))
3738 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003739 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 if (maxread > 0x7FFFFFFF)
3741 maxread = 0x7FFFFFFF;
3742 *res = (uint32_t)maxread;
3743 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3744 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003745 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003747out_overflow:
3748 print_overflow_msg(__func__, xdr);
3749 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750}
3751
3752static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3753{
Al Viro8687b632006-10-19 23:28:48 -07003754 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 int status = 0;
3756
3757 *res = 1024;
3758 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3759 return -EIO;
3760 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3761 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003762 p = xdr_inline_decode(xdr, 8);
3763 if (unlikely(!p))
3764 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003765 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 if (maxwrite > 0x7FFFFFFF)
3767 maxwrite = 0x7FFFFFFF;
3768 *res = (uint32_t)maxwrite;
3769 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3770 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003771 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003773out_overflow:
3774 print_overflow_msg(__func__, xdr);
3775 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776}
3777
Trond Myklebustbca79472009-03-11 14:10:26 -04003778static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779{
Trond Myklebustbca79472009-03-11 14:10:26 -04003780 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003781 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003782 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783
3784 *mode = 0;
3785 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3786 return -EIO;
3787 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003788 p = xdr_inline_decode(xdr, 4);
3789 if (unlikely(!p))
3790 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003791 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003792 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003794 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003796 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003797 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003798out_overflow:
3799 print_overflow_msg(__func__, xdr);
3800 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801}
3802
3803static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3804{
Al Viro8687b632006-10-19 23:28:48 -07003805 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003806 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807
3808 *nlink = 1;
3809 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3810 return -EIO;
3811 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003812 p = xdr_inline_decode(xdr, 4);
3813 if (unlikely(!p))
3814 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003815 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003817 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003819 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003820 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003821out_overflow:
3822 print_overflow_msg(__func__, xdr);
3823 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824}
3825
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003826static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003827 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003828 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829{
Al Viro8687b632006-10-19 23:28:48 -07003830 uint32_t len;
3831 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003832 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833
Eric W. Biedermane5782072013-02-01 14:22:02 -08003834 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3836 return -EIO;
3837 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003838 p = xdr_inline_decode(xdr, 4);
3839 if (unlikely(!p))
3840 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003841 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003842 p = xdr_inline_decode(xdr, len);
3843 if (unlikely(!p))
3844 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003845 if (owner_name != NULL) {
3846 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3847 if (owner_name->data != NULL) {
3848 owner_name->len = len;
3849 ret = NFS_ATTR_FATTR_OWNER_NAME;
3850 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003851 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003852 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003853 ret = NFS_ATTR_FATTR_OWNER;
3854 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003856 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003858 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003859 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3861 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003862 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003863 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003864out_overflow:
3865 print_overflow_msg(__func__, xdr);
3866 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867}
3868
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003869static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003870 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003871 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872{
Al Viro8687b632006-10-19 23:28:48 -07003873 uint32_t len;
3874 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003875 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876
Eric W. Biedermane5782072013-02-01 14:22:02 -08003877 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3879 return -EIO;
3880 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003881 p = xdr_inline_decode(xdr, 4);
3882 if (unlikely(!p))
3883 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003884 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003885 p = xdr_inline_decode(xdr, len);
3886 if (unlikely(!p))
3887 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003888 if (group_name != NULL) {
3889 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3890 if (group_name->data != NULL) {
3891 group_name->len = len;
3892 ret = NFS_ATTR_FATTR_GROUP_NAME;
3893 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003894 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003895 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003896 ret = NFS_ATTR_FATTR_GROUP;
3897 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003899 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003901 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003902 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3904 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003905 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003906 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003907out_overflow:
3908 print_overflow_msg(__func__, xdr);
3909 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910}
3911
3912static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3913{
Al Viro8687b632006-10-19 23:28:48 -07003914 uint32_t major = 0, minor = 0;
3915 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003916 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917
3918 *rdev = MKDEV(0,0);
3919 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3920 return -EIO;
3921 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3922 dev_t tmp;
3923
Benny Halevyc0eae662009-08-14 17:20:14 +03003924 p = xdr_inline_decode(xdr, 8);
3925 if (unlikely(!p))
3926 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003927 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003928 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 tmp = MKDEV(major, minor);
3930 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3931 *rdev = tmp;
3932 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003933 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003935 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003936 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003937out_overflow:
3938 print_overflow_msg(__func__, xdr);
3939 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940}
3941
3942static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3943{
Al Viro8687b632006-10-19 23:28:48 -07003944 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945 int status = 0;
3946
3947 *res = 0;
3948 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3949 return -EIO;
3950 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003951 p = xdr_inline_decode(xdr, 8);
3952 if (unlikely(!p))
3953 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003954 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3956 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003957 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003959out_overflow:
3960 print_overflow_msg(__func__, xdr);
3961 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962}
3963
3964static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3965{
Al Viro8687b632006-10-19 23:28:48 -07003966 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 int status = 0;
3968
3969 *res = 0;
3970 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3971 return -EIO;
3972 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003973 p = xdr_inline_decode(xdr, 8);
3974 if (unlikely(!p))
3975 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003976 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3978 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003979 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003981out_overflow:
3982 print_overflow_msg(__func__, xdr);
3983 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984}
3985
3986static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3987{
Al Viro8687b632006-10-19 23:28:48 -07003988 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 int status = 0;
3990
3991 *res = 0;
3992 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3993 return -EIO;
3994 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003995 p = xdr_inline_decode(xdr, 8);
3996 if (unlikely(!p))
3997 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003998 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4000 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004001 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004003out_overflow:
4004 print_overflow_msg(__func__, xdr);
4005 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006}
4007
4008static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4009{
Al Viro8687b632006-10-19 23:28:48 -07004010 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004011 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012
4013 *used = 0;
4014 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4015 return -EIO;
4016 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004017 p = xdr_inline_decode(xdr, 8);
4018 if (unlikely(!p))
4019 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004020 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004022 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004024 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004026 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004027out_overflow:
4028 print_overflow_msg(__func__, xdr);
4029 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030}
4031
4032static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4033{
Al Viro8687b632006-10-19 23:28:48 -07004034 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035 uint64_t sec;
4036 uint32_t nsec;
4037
Benny Halevyc0eae662009-08-14 17:20:14 +03004038 p = xdr_inline_decode(xdr, 12);
4039 if (unlikely(!p))
4040 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004041 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004042 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 time->tv_sec = (time_t)sec;
4044 time->tv_nsec = (long)nsec;
4045 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004046out_overflow:
4047 print_overflow_msg(__func__, xdr);
4048 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049}
4050
4051static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4052{
4053 int status = 0;
4054
4055 time->tv_sec = 0;
4056 time->tv_nsec = 0;
4057 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4058 return -EIO;
4059 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4060 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004061 if (status == 0)
4062 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4064 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004065 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 return status;
4067}
4068
4069static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4070{
4071 int status = 0;
4072
4073 time->tv_sec = 0;
4074 time->tv_nsec = 0;
4075 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4076 return -EIO;
4077 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4078 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004079 if (status == 0)
4080 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4082 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004083 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 return status;
4085}
4086
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004087static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4088 struct timespec *time)
4089{
4090 int status = 0;
4091
4092 time->tv_sec = 0;
4093 time->tv_nsec = 0;
4094 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4095 return -EIO;
4096 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4097 status = decode_attr_time(xdr, time);
4098 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4099 }
4100 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4101 (long)time->tv_nsec);
4102 return status;
4103}
4104
David Quigleyaa9c2662013-05-22 12:50:44 -04004105static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4106 struct nfs4_label *label)
4107{
4108 uint32_t pi = 0;
4109 uint32_t lfs = 0;
4110 __u32 len;
4111 __be32 *p;
4112 int status = 0;
4113
4114 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4115 return -EIO;
4116 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4117 p = xdr_inline_decode(xdr, 4);
4118 if (unlikely(!p))
4119 goto out_overflow;
4120 lfs = be32_to_cpup(p++);
4121 p = xdr_inline_decode(xdr, 4);
4122 if (unlikely(!p))
4123 goto out_overflow;
4124 pi = be32_to_cpup(p++);
4125 p = xdr_inline_decode(xdr, 4);
4126 if (unlikely(!p))
4127 goto out_overflow;
4128 len = be32_to_cpup(p++);
4129 p = xdr_inline_decode(xdr, len);
4130 if (unlikely(!p))
4131 goto out_overflow;
4132 if (len < NFS4_MAXLABELLEN) {
4133 if (label) {
4134 memcpy(label->label, p, len);
4135 label->len = len;
4136 label->pi = pi;
4137 label->lfs = lfs;
4138 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4139 }
4140 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4141 } else
4142 printk(KERN_WARNING "%s: label too long (%u)!\n",
4143 __func__, len);
4144 }
4145 if (label && label->label)
4146 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4147 (char *)label->label, label->len, label->pi, label->lfs);
4148 return status;
4149
4150out_overflow:
4151 print_overflow_msg(__func__, xdr);
4152 return -EIO;
4153}
4154
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4156{
4157 int status = 0;
4158
4159 time->tv_sec = 0;
4160 time->tv_nsec = 0;
4161 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4162 return -EIO;
4163 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4164 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004165 if (status == 0)
4166 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4168 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004169 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 return status;
4171}
4172
Trond Myklebust256e48b2012-06-21 11:18:13 -04004173static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174{
4175 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004176 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177
4178 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004179 dprintk("%s: server returned incorrect attribute length: "
4180 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004181 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 attrwords << 2,
4183 (attrwords < nwords) ? '<' : '>',
4184 nwords << 2);
4185 return -EIO;
4186 }
4187 return 0;
4188}
4189
4190static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4191{
Al Viro8687b632006-10-19 23:28:48 -07004192 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193
Benny Halevyc0eae662009-08-14 17:20:14 +03004194 p = xdr_inline_decode(xdr, 20);
4195 if (unlikely(!p))
4196 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004197 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004198 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004199 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004201out_overflow:
4202 print_overflow_msg(__func__, xdr);
4203 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204}
4205
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004206static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207{
Al Viro8687b632006-10-19 23:28:48 -07004208 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 uint32_t supp, acc;
4210 int status;
4211
4212 status = decode_op_hdr(xdr, OP_ACCESS);
4213 if (status)
4214 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004215 p = xdr_inline_decode(xdr, 8);
4216 if (unlikely(!p))
4217 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004218 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004219 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004220 *supported = supp;
4221 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004223out_overflow:
4224 print_overflow_msg(__func__, xdr);
4225 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226}
4227
Benny Halevy07d30432009-08-14 17:19:52 +03004228static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229{
Al Viro8687b632006-10-19 23:28:48 -07004230 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004231
4232 p = xdr_inline_decode(xdr, len);
4233 if (likely(p)) {
4234 memcpy(buf, p, len);
4235 return 0;
4236 }
4237 print_overflow_msg(__func__, xdr);
4238 return -EIO;
4239}
4240
4241static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4242{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004243 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244}
4245
4246static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4247{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248 int status;
4249
4250 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004251 if (status != -EIO)
4252 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004253 if (!status)
4254 status = decode_stateid(xdr, &res->stateid);
4255 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256}
4257
Benny Halevydb942bb2009-08-14 17:19:56 +03004258static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4259{
Chuck Levercd937102012-03-02 17:14:31 -05004260 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261}
4262
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004263static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4264{
4265 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4266}
4267
Fred Isaman0b7c0152012-04-20 14:47:39 -04004268static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270 int status;
4271
4272 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004273 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004274 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004275 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276}
4277
4278static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4279{
Al Viro8687b632006-10-19 23:28:48 -07004280 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281 uint32_t bmlen;
4282 int status;
4283
4284 status = decode_op_hdr(xdr, OP_CREATE);
4285 if (status)
4286 return status;
4287 if ((status = decode_change_info(xdr, cinfo)))
4288 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004289 p = xdr_inline_decode(xdr, 4);
4290 if (unlikely(!p))
4291 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004292 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004293 p = xdr_inline_decode(xdr, bmlen << 2);
4294 if (likely(p))
4295 return 0;
4296out_overflow:
4297 print_overflow_msg(__func__, xdr);
4298 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299}
4300
4301static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4302{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004303 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004304 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305 int status;
4306
4307 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4308 goto xdr_error;
4309 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4310 goto xdr_error;
4311 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4312 goto xdr_error;
4313 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4314 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004315 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4316 &res->fh_expire_type)) != 0)
4317 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4319 goto xdr_error;
4320 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4321 goto xdr_error;
4322 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4323 goto xdr_error;
4324 status = verify_attr_len(xdr, savep, attrlen);
4325xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004326 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 return status;
4328}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004329
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4331{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004332 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004333 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004335
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4337 goto xdr_error;
4338 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4339 goto xdr_error;
4340 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4341 goto xdr_error;
4342
4343 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4344 goto xdr_error;
4345 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4346 goto xdr_error;
4347 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4348 goto xdr_error;
4349 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4350 goto xdr_error;
4351 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4352 goto xdr_error;
4353 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4354 goto xdr_error;
4355
4356 status = verify_attr_len(xdr, savep, attrlen);
4357xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004358 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359 return status;
4360}
4361
4362static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4363{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004364 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004365 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004367
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4369 goto xdr_error;
4370 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4371 goto xdr_error;
4372 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4373 goto xdr_error;
4374
4375 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4376 goto xdr_error;
4377 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4378 goto xdr_error;
4379
4380 status = verify_attr_len(xdr, savep, attrlen);
4381xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004382 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383 return status;
4384}
4385
Andy Adamson88034c32012-05-23 05:02:34 -04004386static int decode_threshold_hint(struct xdr_stream *xdr,
4387 uint32_t *bitmap,
4388 uint64_t *res,
4389 uint32_t hint_bit)
4390{
4391 __be32 *p;
4392
4393 *res = 0;
4394 if (likely(bitmap[0] & hint_bit)) {
4395 p = xdr_inline_decode(xdr, 8);
4396 if (unlikely(!p))
4397 goto out_overflow;
4398 xdr_decode_hyper(p, res);
4399 }
4400 return 0;
4401out_overflow:
4402 print_overflow_msg(__func__, xdr);
4403 return -EIO;
4404}
4405
4406static int decode_first_threshold_item4(struct xdr_stream *xdr,
4407 struct nfs4_threshold *res)
4408{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004409 __be32 *p;
4410 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004411 uint32_t bitmap[3] = {0,}, attrlen;
4412 int status;
4413
4414 /* layout type */
4415 p = xdr_inline_decode(xdr, 4);
4416 if (unlikely(!p)) {
4417 print_overflow_msg(__func__, xdr);
4418 return -EIO;
4419 }
4420 res->l_type = be32_to_cpup(p);
4421
4422 /* thi_hintset bitmap */
4423 status = decode_attr_bitmap(xdr, bitmap);
4424 if (status < 0)
4425 goto xdr_error;
4426
4427 /* thi_hintlist length */
4428 status = decode_attr_length(xdr, &attrlen, &savep);
4429 if (status < 0)
4430 goto xdr_error;
4431 /* thi_hintlist */
4432 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4433 if (status < 0)
4434 goto xdr_error;
4435 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4436 if (status < 0)
4437 goto xdr_error;
4438 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4439 THRESHOLD_RD_IO);
4440 if (status < 0)
4441 goto xdr_error;
4442 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4443 THRESHOLD_WR_IO);
4444 if (status < 0)
4445 goto xdr_error;
4446
4447 status = verify_attr_len(xdr, savep, attrlen);
4448 res->bm = bitmap[0];
4449
4450 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4451 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4452 res->wr_io_sz);
4453xdr_error:
4454 dprintk("%s ret=%d!\n", __func__, status);
4455 return status;
4456}
4457
4458/*
4459 * Thresholds on pNFS direct I/O vrs MDS I/O
4460 */
4461static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4462 uint32_t *bitmap,
4463 struct nfs4_threshold *res)
4464{
4465 __be32 *p;
4466 int status = 0;
4467 uint32_t num;
4468
4469 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4470 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004471 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004472 /* Did the server return an unrequested attribute? */
4473 if (unlikely(res == NULL))
4474 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004475 p = xdr_inline_decode(xdr, 4);
4476 if (unlikely(!p))
4477 goto out_overflow;
4478 num = be32_to_cpup(p);
4479 if (num == 0)
4480 return 0;
4481 if (num > 1)
4482 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4483 "drivers per filesystem not supported\n",
4484 __func__);
4485
4486 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004487 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004488 }
4489 return status;
4490out_overflow:
4491 print_overflow_msg(__func__, xdr);
4492 return -EIO;
4493}
4494
Bryan Schumakerae42c702010-10-21 16:33:17 -04004495static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4496 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004497 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004498 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499{
Trond Myklebustbca79472009-03-11 14:10:26 -04004500 int status;
4501 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004502 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004503 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004504
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004505 status = decode_attr_type(xdr, bitmap, &type);
4506 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004508 fattr->mode = 0;
4509 if (status != 0) {
4510 fattr->mode |= nfs_type2fmt[type];
4511 fattr->valid |= status;
4512 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004514 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4515 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004517 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004518
4519 status = decode_attr_size(xdr, bitmap, &fattr->size);
4520 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004522 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004523
4524 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4525 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004526 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004527 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004528
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004529 err = 0;
4530 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004531 if (status < 0)
4532 goto xdr_error;
4533
4534 status = decode_attr_filehandle(xdr, bitmap, fh);
4535 if (status < 0)
4536 goto xdr_error;
4537
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004538 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4539 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004541 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004542
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004543 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004544 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004545 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004546 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004547
4548 status = decode_attr_mode(xdr, bitmap, &fmode);
4549 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004550 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004551 if (status != 0) {
4552 fattr->mode |= fmode;
4553 fattr->valid |= status;
4554 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004555
4556 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4557 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004559 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004560
Trond Myklebust6926afd2012-01-07 13:22:46 -05004561 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004562 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004564 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004565
Trond Myklebust6926afd2012-01-07 13:22:46 -05004566 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004567 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004569 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004570
4571 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4572 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004574 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004575
4576 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4577 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004578 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004579 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004580
4581 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4582 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004584 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004585
4586 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4587 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004589 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004590
4591 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4592 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004594 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004595
Trond Myklebust28331a42011-04-27 13:47:52 -04004596 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004597 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004598 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004599 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004600
Andy Adamson88034c32012-05-23 05:02:34 -04004601 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4602 if (status < 0)
4603 goto xdr_error;
4604
David Quigleyaa9c2662013-05-22 12:50:44 -04004605 if (label) {
4606 status = decode_attr_security_label(xdr, bitmap, label);
4607 if (status < 0)
4608 goto xdr_error;
4609 fattr->valid |= status;
4610 }
4611
Bryan Schumakerae42c702010-10-21 16:33:17 -04004612xdr_error:
4613 dprintk("%s: xdr returned %d\n", __func__, -status);
4614 return status;
4615}
4616
4617static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004618 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004619 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004620{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004621 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004622 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004623 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004624 int status;
4625
4626 status = decode_op_hdr(xdr, OP_GETATTR);
4627 if (status < 0)
4628 goto xdr_error;
4629
4630 status = decode_attr_bitmap(xdr, bitmap);
4631 if (status < 0)
4632 goto xdr_error;
4633
4634 status = decode_attr_length(xdr, &attrlen, &savep);
4635 if (status < 0)
4636 goto xdr_error;
4637
David Quigleyaa9c2662013-05-22 12:50:44 -04004638 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4639 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004640 if (status < 0)
4641 goto xdr_error;
4642
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004643 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004645 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646 return status;
4647}
4648
David Quigleyaa9c2662013-05-22 12:50:44 -04004649static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4650 struct nfs4_label *label, const struct nfs_server *server)
4651{
4652 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4653}
4654
Bryan Schumakerae42c702010-10-21 16:33:17 -04004655static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004656 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004657{
David Quigleyaa9c2662013-05-22 12:50:44 -04004658 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004659}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660
Andy Adamson504913f2010-10-20 00:17:57 -04004661/*
4662 * Decode potentially multiple layout types. Currently we only support
4663 * one layout driver per file system.
4664 */
4665static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4666 uint32_t *layouttype)
4667{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004668 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004669 int num;
4670
4671 p = xdr_inline_decode(xdr, 4);
4672 if (unlikely(!p))
4673 goto out_overflow;
4674 num = be32_to_cpup(p);
4675
4676 /* pNFS is not supported by the underlying file system */
4677 if (num == 0) {
4678 *layouttype = 0;
4679 return 0;
4680 }
4681 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004682 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4683 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004684
4685 /* Decode and set first layout type, move xdr->p past unused types */
4686 p = xdr_inline_decode(xdr, num * 4);
4687 if (unlikely(!p))
4688 goto out_overflow;
4689 *layouttype = be32_to_cpup(p);
4690 return 0;
4691out_overflow:
4692 print_overflow_msg(__func__, xdr);
4693 return -EIO;
4694}
4695
4696/*
4697 * The type of file system exported.
4698 * Note we must ensure that layouttype is set in any non-error case.
4699 */
4700static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4701 uint32_t *layouttype)
4702{
4703 int status = 0;
4704
4705 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4706 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4707 return -EIO;
4708 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4709 status = decode_first_pnfs_layout_type(xdr, layouttype);
4710 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4711 } else
4712 *layouttype = 0;
4713 return status;
4714}
4715
Fred Isamandae100c2011-07-30 20:52:37 -04004716/*
4717 * The prefered block size for layout directed io
4718 */
4719static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4720 uint32_t *res)
4721{
4722 __be32 *p;
4723
4724 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4725 *res = 0;
4726 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4727 p = xdr_inline_decode(xdr, 4);
4728 if (unlikely(!p)) {
4729 print_overflow_msg(__func__, xdr);
4730 return -EIO;
4731 }
4732 *res = be32_to_cpup(p);
4733 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4734 }
4735 return 0;
4736}
4737
Linus Torvalds1da177e2005-04-16 15:20:36 -07004738static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4739{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004740 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004741 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742 int status;
4743
4744 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4745 goto xdr_error;
4746 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4747 goto xdr_error;
4748 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4749 goto xdr_error;
4750
4751 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4752
4753 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4754 goto xdr_error;
4755 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4756 goto xdr_error;
4757 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4758 goto xdr_error;
4759 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4760 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4761 goto xdr_error;
4762 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004763 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4764 if (status != 0)
4765 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004766 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4767 if (status != 0)
4768 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004769 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4770 if (status)
4771 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772
4773 status = verify_attr_len(xdr, savep, attrlen);
4774xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004775 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776 return status;
4777}
4778
4779static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4780{
Al Viro8687b632006-10-19 23:28:48 -07004781 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782 uint32_t len;
4783 int status;
4784
Trond Myklebust99367812007-07-17 21:52:41 -04004785 /* Zero handle first to allow comparisons */
4786 memset(fh, 0, sizeof(*fh));
4787
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788 status = decode_op_hdr(xdr, OP_GETFH);
4789 if (status)
4790 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791
Benny Halevyc0eae662009-08-14 17:20:14 +03004792 p = xdr_inline_decode(xdr, 4);
4793 if (unlikely(!p))
4794 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004795 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796 if (len > NFS4_FHSIZE)
4797 return -EIO;
4798 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004799 p = xdr_inline_decode(xdr, len);
4800 if (unlikely(!p))
4801 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004802 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004804out_overflow:
4805 print_overflow_msg(__func__, xdr);
4806 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807}
4808
4809static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4810{
4811 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004812
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 status = decode_op_hdr(xdr, OP_LINK);
4814 if (status)
4815 return status;
4816 return decode_change_info(xdr, cinfo);
4817}
4818
4819/*
4820 * We create the owner, so we know a proper owner.id length is 4.
4821 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004822static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004823{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004824 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004825 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004826 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004828 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004829 if (unlikely(!p))
4830 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004831 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004832 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004833 type = be32_to_cpup(p++); /* 4 byte read */
4834 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004835 fl->fl_start = (loff_t)offset;
4836 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4837 if (length == ~(uint64_t)0)
4838 fl->fl_end = OFFSET_MAX;
4839 fl->fl_type = F_WRLCK;
4840 if (type & 1)
4841 fl->fl_type = F_RDLCK;
4842 fl->fl_pid = 0;
4843 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004844 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4845 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4846 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004847 if (likely(p))
4848 return -NFS4ERR_DENIED;
4849out_overflow:
4850 print_overflow_msg(__func__, xdr);
4851 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852}
4853
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004854static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856 int status;
4857
4858 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004859 if (status == -EIO)
4860 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004862 status = decode_stateid(xdr, &res->stateid);
4863 if (unlikely(status))
4864 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004866 status = decode_lock_denied(xdr, NULL);
4867 if (res->open_seqid != NULL)
4868 nfs_increment_open_seqid(status, res->open_seqid);
4869 nfs_increment_lock_seqid(status, res->lock_seqid);
4870out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871 return status;
4872}
4873
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004874static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004875{
4876 int status;
4877 status = decode_op_hdr(xdr, OP_LOCKT);
4878 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004879 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880 return status;
4881}
4882
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004883static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 int status;
4886
4887 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004888 if (status != -EIO)
4889 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004890 if (status == 0)
4891 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892 return status;
4893}
4894
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004895static int decode_release_lockowner(struct xdr_stream *xdr)
4896{
4897 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4898}
4899
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900static int decode_lookup(struct xdr_stream *xdr)
4901{
4902 return decode_op_hdr(xdr, OP_LOOKUP);
4903}
4904
4905/* This is too sick! */
4906static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4907{
Andy Adamson05d564f2008-12-23 16:06:15 -05004908 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004909 uint32_t limit_type, nblocks, blocksize;
4910
Benny Halevyc0eae662009-08-14 17:20:14 +03004911 p = xdr_inline_decode(xdr, 12);
4912 if (unlikely(!p))
4913 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004914 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004915 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004916 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004917 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004918 break;
4919 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004920 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004921 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004922 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923 }
4924 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004925out_overflow:
4926 print_overflow_msg(__func__, xdr);
4927 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928}
4929
Trond Myklebust6ae37332015-01-30 14:21:14 -05004930static int decode_rw_delegation(struct xdr_stream *xdr,
4931 uint32_t delegation_type,
4932 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933{
Andy Adamson05d564f2008-12-23 16:06:15 -05004934 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004935 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936
Benny Halevy07d30432009-08-14 17:19:52 +03004937 status = decode_stateid(xdr, &res->delegation);
4938 if (unlikely(status))
4939 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004940 p = xdr_inline_decode(xdr, 4);
4941 if (unlikely(!p))
4942 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004943 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004944
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004946 case NFS4_OPEN_DELEGATE_READ:
4947 res->delegation_type = FMODE_READ;
4948 break;
4949 case NFS4_OPEN_DELEGATE_WRITE:
4950 res->delegation_type = FMODE_WRITE|FMODE_READ;
4951 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952 return -EIO;
4953 }
David Howells7539bba2006-08-22 20:06:09 -04004954 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004955out_overflow:
4956 print_overflow_msg(__func__, xdr);
4957 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958}
4959
Trond Myklebust6ae37332015-01-30 14:21:14 -05004960static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4961{
4962 __be32 *p;
4963 uint32_t why_no_delegation;
4964
4965 p = xdr_inline_decode(xdr, 4);
4966 if (unlikely(!p))
4967 goto out_overflow;
4968 why_no_delegation = be32_to_cpup(p);
4969 switch (why_no_delegation) {
4970 case WND4_CONTENTION:
4971 case WND4_RESOURCE:
4972 xdr_inline_decode(xdr, 4);
4973 /* Ignore for now */
4974 }
4975 return 0;
4976out_overflow:
4977 print_overflow_msg(__func__, xdr);
4978 return -EIO;
4979}
4980
4981static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4982{
4983 __be32 *p;
4984 uint32_t delegation_type;
4985
4986 p = xdr_inline_decode(xdr, 4);
4987 if (unlikely(!p))
4988 goto out_overflow;
4989 delegation_type = be32_to_cpup(p);
4990 res->delegation_type = 0;
4991 switch (delegation_type) {
4992 case NFS4_OPEN_DELEGATE_NONE:
4993 return 0;
4994 case NFS4_OPEN_DELEGATE_READ:
4995 case NFS4_OPEN_DELEGATE_WRITE:
4996 return decode_rw_delegation(xdr, delegation_type, res);
4997 case NFS4_OPEN_DELEGATE_NONE_EXT:
4998 return decode_no_delegation(xdr, res);
4999 }
5000 return -EIO;
5001out_overflow:
5002 print_overflow_msg(__func__, xdr);
5003 return -EIO;
5004}
5005
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5007{
Andy Adamson05d564f2008-12-23 16:06:15 -05005008 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005009 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005010 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011
Trond Myklebustc7848f62013-12-04 17:39:23 -05005012 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5013 return status;
5014 nfs_increment_open_seqid(status, res->seqid);
5015 if (status)
5016 return status;
5017 status = decode_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005018 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005019 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020
Andy Adamson05d564f2008-12-23 16:06:15 -05005021 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022
Benny Halevyc0eae662009-08-14 17:20:14 +03005023 p = xdr_inline_decode(xdr, 8);
5024 if (unlikely(!p))
5025 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005026 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005027 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005028 if (bmlen > 10)
5029 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030
Benny Halevyc0eae662009-08-14 17:20:14 +03005031 p = xdr_inline_decode(xdr, bmlen << 2);
5032 if (unlikely(!p))
5033 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005034 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5035 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005036 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005037 for (; i < NFS4_BITMAP_SIZE; i++)
5038 res->attrset[i] = 0;
5039
Linus Torvalds1da177e2005-04-16 15:20:36 -07005040 return decode_delegation(xdr, res);
5041xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005042 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005044out_overflow:
5045 print_overflow_msg(__func__, xdr);
5046 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047}
5048
5049static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5050{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051 int status;
5052
Andy Adamson05d564f2008-12-23 16:06:15 -05005053 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005054 if (status != -EIO)
5055 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005056 if (!status)
5057 status = decode_stateid(xdr, &res->stateid);
5058 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005059}
5060
5061static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5062{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063 int status;
5064
5065 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005066 if (status != -EIO)
5067 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005068 if (!status)
5069 status = decode_stateid(xdr, &res->stateid);
5070 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071}
5072
5073static int decode_putfh(struct xdr_stream *xdr)
5074{
5075 return decode_op_hdr(xdr, OP_PUTFH);
5076}
5077
5078static int decode_putrootfh(struct xdr_stream *xdr)
5079{
5080 return decode_op_hdr(xdr, OP_PUTROOTFH);
5081}
5082
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005083static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5084 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085{
Al Viro8687b632006-10-19 23:28:48 -07005086 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005087 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 int status;
5089
5090 status = decode_op_hdr(xdr, OP_READ);
5091 if (status)
5092 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005093 p = xdr_inline_decode(xdr, 8);
5094 if (unlikely(!p))
5095 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005096 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005097 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005098 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005100 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101 "count %u > recvd %u\n", count, recvd);
5102 count = recvd;
5103 eof = 0;
5104 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005105 res->eof = eof;
5106 res->count = count;
5107 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005108out_overflow:
5109 print_overflow_msg(__func__, xdr);
5110 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111}
5112
5113static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5114{
Chuck Leverbcecff72007-10-26 13:32:03 -04005115 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005116 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117
5118 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005119 if (!status)
5120 status = decode_verifier(xdr, readdir->verifier.data);
5121 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005123 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005124 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005125 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005126 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127}
5128
5129static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5130{
5131 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005132 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005133 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134 int status;
5135
5136 status = decode_op_hdr(xdr, OP_READLINK);
5137 if (status)
5138 return status;
5139
5140 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005141 p = xdr_inline_decode(xdr, 4);
5142 if (unlikely(!p))
5143 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005144 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005146 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147 return -ENAMETOOLONG;
5148 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005149 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005150 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005151 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152 "count %u > recvd %u\n", len, recvd);
5153 return -EIO;
5154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 /*
5156 * The XDR encode routine has set things up so that
5157 * the link text will be copied directly into the
5158 * buffer. We just have to do overflow-checking,
5159 * and and null-terminate the text (the VFS expects
5160 * null-termination).
5161 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005162 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005164out_overflow:
5165 print_overflow_msg(__func__, xdr);
5166 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005167}
5168
5169static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5170{
5171 int status;
5172
5173 status = decode_op_hdr(xdr, OP_REMOVE);
5174 if (status)
5175 goto out;
5176 status = decode_change_info(xdr, cinfo);
5177out:
5178 return status;
5179}
5180
5181static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5182 struct nfs4_change_info *new_cinfo)
5183{
5184 int status;
5185
5186 status = decode_op_hdr(xdr, OP_RENAME);
5187 if (status)
5188 goto out;
5189 if ((status = decode_change_info(xdr, old_cinfo)))
5190 goto out;
5191 status = decode_change_info(xdr, new_cinfo);
5192out:
5193 return status;
5194}
5195
5196static int decode_renew(struct xdr_stream *xdr)
5197{
5198 return decode_op_hdr(xdr, OP_RENEW);
5199}
5200
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005201static int
5202decode_restorefh(struct xdr_stream *xdr)
5203{
5204 return decode_op_hdr(xdr, OP_RESTOREFH);
5205}
5206
J. Bruce Fields029d1052005-06-22 17:16:22 +00005207static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005208 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005209{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005210 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005211 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005212 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005213 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005214 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005215
Andy Adamsonbf118a32011-12-07 11:55:27 -05005216 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005217 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5218 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005219
Trond Myklebust519d3952012-08-14 17:30:10 -04005220 xdr_enter_page(xdr, xdr->buf->page_len);
5221
Trond Myklebustcff298c2012-08-14 17:14:17 -04005222 /* Calculate the offset of the page data */
5223 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005224
J. Bruce Fields029d1052005-06-22 17:16:22 +00005225 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5226 goto out;
5227 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5228 goto out;
5229
5230 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5231 return -EIO;
5232 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005233
Andy Adamsonbf118a32011-12-07 11:55:27 -05005234 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5235 * are stored with the acl data to handle the problem of
5236 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005237 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005238 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005239
5240 /* Check for receive buffer overflow */
5241 if (res->acl_len > (xdr->nwords << 2) ||
5242 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5243 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005244 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005245 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005246 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005247 } else
5248 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005249
5250out:
5251 return status;
5252}
5253
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254static int
5255decode_savefh(struct xdr_stream *xdr)
5256{
5257 return decode_op_hdr(xdr, OP_SAVEFH);
5258}
5259
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005260static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261{
Al Viro8687b632006-10-19 23:28:48 -07005262 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263 uint32_t bmlen;
5264 int status;
5265
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266 status = decode_op_hdr(xdr, OP_SETATTR);
5267 if (status)
5268 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005269 p = xdr_inline_decode(xdr, 4);
5270 if (unlikely(!p))
5271 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005272 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005273 p = xdr_inline_decode(xdr, bmlen << 2);
5274 if (likely(p))
5275 return 0;
5276out_overflow:
5277 print_overflow_msg(__func__, xdr);
5278 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279}
5280
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005281static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282{
Al Viro8687b632006-10-19 23:28:48 -07005283 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284 uint32_t opnum;
5285 int32_t nfserr;
5286
Benny Halevyc0eae662009-08-14 17:20:14 +03005287 p = xdr_inline_decode(xdr, 8);
5288 if (unlikely(!p))
5289 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005290 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005291 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005292 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005293 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005294 return -EIO;
5295 }
Benny Halevycccddf42009-08-14 17:20:19 +03005296 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005298 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5299 if (unlikely(!p))
5300 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005301 p = xdr_decode_hyper(p, &res->clientid);
5302 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303 } else if (nfserr == NFSERR_CLID_INUSE) {
5304 uint32_t len;
5305
5306 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005307 p = xdr_inline_decode(xdr, 4);
5308 if (unlikely(!p))
5309 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005310 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005311 p = xdr_inline_decode(xdr, len);
5312 if (unlikely(!p))
5313 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005314
5315 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005316 p = xdr_inline_decode(xdr, 4);
5317 if (unlikely(!p))
5318 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005319 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005320 p = xdr_inline_decode(xdr, len);
5321 if (unlikely(!p))
5322 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323 return -NFSERR_CLID_INUSE;
5324 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005325 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326
5327 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005328out_overflow:
5329 print_overflow_msg(__func__, xdr);
5330 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005331}
5332
5333static int decode_setclientid_confirm(struct xdr_stream *xdr)
5334{
5335 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5336}
5337
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005338static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005339{
Al Viro8687b632006-10-19 23:28:48 -07005340 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005341 int status;
5342
5343 status = decode_op_hdr(xdr, OP_WRITE);
5344 if (status)
5345 return status;
5346
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005347 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005348 if (unlikely(!p))
5349 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005350 res->count = be32_to_cpup(p++);
5351 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005352 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005353out_overflow:
5354 print_overflow_msg(__func__, xdr);
5355 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005356}
5357
5358static int decode_delegreturn(struct xdr_stream *xdr)
5359{
5360 return decode_op_hdr(xdr, OP_DELEGRETURN);
5361}
5362
Chuck Leverfb15b262013-03-16 15:54:34 -04005363static int decode_secinfo_gss(struct xdr_stream *xdr,
5364 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005365{
Chuck Leverfb15b262013-03-16 15:54:34 -04005366 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005367 __be32 *p;
5368
5369 p = xdr_inline_decode(xdr, 4);
5370 if (unlikely(!p))
5371 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005372 oid_len = be32_to_cpup(p);
5373 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005374 goto out_err;
5375
Chuck Leverfb15b262013-03-16 15:54:34 -04005376 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005377 if (unlikely(!p))
5378 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005379 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5380 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005381
5382 p = xdr_inline_decode(xdr, 8);
5383 if (unlikely(!p))
5384 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005385 flavor->flavor_info.qop = be32_to_cpup(p++);
5386 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005387
5388 return 0;
5389
5390out_overflow:
5391 print_overflow_msg(__func__, xdr);
5392 return -EIO;
5393out_err:
5394 return -EINVAL;
5395}
5396
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005397static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005398{
Chuck Leverfb15b262013-03-16 15:54:34 -04005399 struct nfs4_secinfo4 *sec_flavor;
5400 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005401 int status;
5402 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005403
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005404 p = xdr_inline_decode(xdr, 4);
5405 if (unlikely(!p))
5406 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005407
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005408 res->flavors->num_flavors = 0;
5409 num_flavors = be32_to_cpup(p);
5410
5411 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005412 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005413 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005414 break;
5415
5416 p = xdr_inline_decode(xdr, 4);
5417 if (unlikely(!p))
5418 goto out_overflow;
5419 sec_flavor->flavor = be32_to_cpup(p);
5420
5421 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005422 status = decode_secinfo_gss(xdr, sec_flavor);
5423 if (status)
5424 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005425 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005426 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005427 }
5428
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005429 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005430out:
5431 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005432out_overflow:
5433 print_overflow_msg(__func__, xdr);
5434 return -EIO;
5435}
5436
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005437static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5438{
5439 int status = decode_op_hdr(xdr, OP_SECINFO);
5440 if (status)
5441 return status;
5442 return decode_secinfo_common(xdr, res);
5443}
5444
Benny Halevy99fe60d2009-04-01 09:22:29 -04005445#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005446static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5447{
5448 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5449 if (status)
5450 return status;
5451 return decode_secinfo_common(xdr, res);
5452}
5453
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005454static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5455{
5456 __be32 *p;
5457 uint32_t bitmap_words;
5458 unsigned int i;
5459
5460 p = xdr_inline_decode(xdr, 4);
5461 bitmap_words = be32_to_cpup(p++);
5462 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5463 return -EIO;
5464 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5465 for (i = 0; i < bitmap_words; i++)
5466 op_map->u.words[i] = be32_to_cpup(p++);
5467
5468 return 0;
5469}
5470
Benny Halevy99fe60d2009-04-01 09:22:29 -04005471static int decode_exchange_id(struct xdr_stream *xdr,
5472 struct nfs41_exchange_id_res *res)
5473{
5474 __be32 *p;
5475 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005476 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005477 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005478 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005479
5480 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5481 if (status)
5482 return status;
5483
Benny Halevyc0eae662009-08-14 17:20:14 +03005484 p = xdr_inline_decode(xdr, 8);
5485 if (unlikely(!p))
5486 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005487 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005488 p = xdr_inline_decode(xdr, 12);
5489 if (unlikely(!p))
5490 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005491 res->seqid = be32_to_cpup(p++);
5492 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005493
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005494 res->state_protect.how = be32_to_cpup(p);
5495 switch (res->state_protect.how) {
5496 case SP4_NONE:
5497 break;
5498 case SP4_MACH_CRED:
5499 status = decode_op_map(xdr, &res->state_protect.enforce);
5500 if (status)
5501 return status;
5502 status = decode_op_map(xdr, &res->state_protect.allow);
5503 if (status)
5504 return status;
5505 break;
5506 default:
5507 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005508 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005509 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005510
Chuck Leveracdeb692012-05-21 22:46:16 -04005511 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005512 p = xdr_inline_decode(xdr, 8);
5513 if (unlikely(!p))
5514 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005515 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005516
Chuck Leveracdeb692012-05-21 22:46:16 -04005517 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005518 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5519 if (unlikely(status))
5520 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005521 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5522 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005523 memcpy(res->server_owner->major_id, dummy_str, dummy);
5524 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005525
Chuck Leveracdeb692012-05-21 22:46:16 -04005526 /* server_scope4 */
5527 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5528 if (unlikely(status))
5529 return status;
5530 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5531 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005532 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5533 res->server_scope->server_scope_sz = dummy;
5534
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005535 /* Implementation Id */
5536 p = xdr_inline_decode(xdr, 4);
5537 if (unlikely(!p))
5538 goto out_overflow;
5539 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005540
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005541 if (impl_id_count) {
5542 /* nii_domain */
5543 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5544 if (unlikely(status))
5545 return status;
5546 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5547 return -EIO;
5548 memcpy(res->impl_id->domain, dummy_str, dummy);
5549
5550 /* nii_name */
5551 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5552 if (unlikely(status))
5553 return status;
5554 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5555 return -EIO;
5556 memcpy(res->impl_id->name, dummy_str, dummy);
5557
5558 /* nii_date */
5559 p = xdr_inline_decode(xdr, 12);
5560 if (unlikely(!p))
5561 goto out_overflow;
5562 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5563 res->impl_id->date.nseconds = be32_to_cpup(p);
5564
5565 /* if there's more than one entry, ignore the rest */
5566 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005567 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005568out_overflow:
5569 print_overflow_msg(__func__, xdr);
5570 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005571}
Andy Adamsonfc931582009-04-01 09:22:31 -04005572
5573static int decode_chan_attrs(struct xdr_stream *xdr,
5574 struct nfs4_channel_attrs *attrs)
5575{
5576 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005577 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005578
Benny Halevyc0eae662009-08-14 17:20:14 +03005579 p = xdr_inline_decode(xdr, 28);
5580 if (unlikely(!p))
5581 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005582 val = be32_to_cpup(p++); /* headerpadsz */
5583 if (val)
5584 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005585 attrs->max_rqst_sz = be32_to_cpup(p++);
5586 attrs->max_resp_sz = be32_to_cpup(p++);
5587 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5588 attrs->max_ops = be32_to_cpup(p++);
5589 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005590 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005591 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005592 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5593 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005594 return -EINVAL;
5595 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005596 if (nr_attrs == 1) {
5597 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5598 if (unlikely(!p))
5599 goto out_overflow;
5600 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005601 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005602out_overflow:
5603 print_overflow_msg(__func__, xdr);
5604 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005605}
5606
Benny Halevye78291e2009-08-14 17:20:00 +03005607static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5608{
5609 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005610}
5611
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005612static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5613 struct nfs41_bind_conn_to_session_res *res)
5614{
5615 __be32 *p;
5616 int status;
5617
5618 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5619 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005620 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005621 if (unlikely(status))
5622 return status;
5623
5624 /* dir flags, rdma mode bool */
5625 p = xdr_inline_decode(xdr, 8);
5626 if (unlikely(!p))
5627 goto out_overflow;
5628
5629 res->dir = be32_to_cpup(p++);
5630 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5631 return -EIO;
5632 if (be32_to_cpup(p) == 0)
5633 res->use_conn_in_rdma_mode = false;
5634 else
5635 res->use_conn_in_rdma_mode = true;
5636
5637 return 0;
5638out_overflow:
5639 print_overflow_msg(__func__, xdr);
5640 return -EIO;
5641}
5642
Andy Adamsonfc931582009-04-01 09:22:31 -04005643static int decode_create_session(struct xdr_stream *xdr,
5644 struct nfs41_create_session_res *res)
5645{
5646 __be32 *p;
5647 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005648
5649 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005650 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005651 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005652 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005653 return status;
5654
Andy Adamsonfc931582009-04-01 09:22:31 -04005655 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005656 p = xdr_inline_decode(xdr, 8);
5657 if (unlikely(!p))
5658 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005659 res->seqid = be32_to_cpup(p++);
5660 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005661
5662 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005663 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005664 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005665 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005666 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005667out_overflow:
5668 print_overflow_msg(__func__, xdr);
5669 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005670}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005671
5672static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5673{
5674 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5675}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005676
Trond Myklebust66245532012-05-25 17:18:09 -04005677static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5678{
5679 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5680}
5681
Ricardo Labiaga180197532009-12-05 16:08:40 -05005682static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5683{
5684 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5685}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005686#endif /* CONFIG_NFS_V4_1 */
5687
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005688static int decode_sequence(struct xdr_stream *xdr,
5689 struct nfs4_sequence_res *res,
5690 struct rpc_rqst *rqstp)
5691{
5692#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005693 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005694 struct nfs4_sessionid id;
5695 u32 dummy;
5696 int status;
5697 __be32 *p;
5698
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005699 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005700 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005701 if (!res->sr_slot->table->session)
5702 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005703
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005704 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005705 if (!status)
5706 status = decode_sessionid(xdr, &id);
5707 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005708 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005709
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005710 /*
5711 * If the server returns different values for sessionID, slotID or
5712 * sequence number, the server is looney tunes.
5713 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005714 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005715 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005716
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005717 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005718 NFS4_MAX_SESSIONID_LEN)) {
5719 dprintk("%s Invalid session id\n", __func__);
5720 goto out_err;
5721 }
Benny Halevye78291e2009-08-14 17:20:00 +03005722
Benny Halevyc0eae662009-08-14 17:20:14 +03005723 p = xdr_inline_decode(xdr, 20);
5724 if (unlikely(!p))
5725 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005726
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005727 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005728 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005729 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005730 dprintk("%s Invalid sequence number\n", __func__);
5731 goto out_err;
5732 }
5733 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005734 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005735 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005736 dprintk("%s Invalid slot id\n", __func__);
5737 goto out_err;
5738 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005739 /* highest slot id */
5740 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005741 /* target highest slot id */
5742 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005743 /* result flags */
5744 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005745 status = 0;
5746out_err:
5747 res->sr_status = status;
5748 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005749out_overflow:
5750 print_overflow_msg(__func__, xdr);
5751 status = -EIO;
5752 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005753#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005754 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005755#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005756}
5757
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005758#if defined(CONFIG_NFS_V4_1)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005759static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005760 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005761{
Trond Myklebust4e590802015-03-09 14:01:25 -04005762 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005763 __be32 *p;
5764 uint32_t len, type;
5765 int status;
5766
5767 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5768 if (status) {
5769 if (status == -ETOOSMALL) {
5770 p = xdr_inline_decode(xdr, 4);
5771 if (unlikely(!p))
5772 goto out_overflow;
5773 pdev->mincount = be32_to_cpup(p);
5774 dprintk("%s: Min count too small. mincnt = %u\n",
5775 __func__, pdev->mincount);
5776 }
5777 return status;
5778 }
5779
5780 p = xdr_inline_decode(xdr, 8);
5781 if (unlikely(!p))
5782 goto out_overflow;
5783 type = be32_to_cpup(p++);
5784 if (type != pdev->layout_type) {
5785 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5786 __func__, pdev->layout_type, type);
5787 return -EINVAL;
5788 }
5789 /*
5790 * Get the length of the opaque device_addr4. xdr_read_pages places
5791 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5792 * and places the remaining xdr data in xdr_buf->tail
5793 */
5794 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005795 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5796 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005797
5798 /* Parse notification bitmap, verifying that it is zero. */
5799 p = xdr_inline_decode(xdr, 4);
5800 if (unlikely(!p))
5801 goto out_overflow;
5802 len = be32_to_cpup(p);
5803 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005804 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005805
5806 p = xdr_inline_decode(xdr, 4 * len);
5807 if (unlikely(!p))
5808 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005809
Trond Myklebust4e590802015-03-09 14:01:25 -04005810 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005811 for (i = 1; i < len; i++) {
5812 if (be32_to_cpup(p++)) {
5813 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005814 __func__);
5815 return -EIO;
5816 }
5817 }
5818 }
5819 return 0;
5820out_overflow:
5821 print_overflow_msg(__func__, xdr);
5822 return -EIO;
5823}
5824
5825static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5826 struct nfs4_layoutget_res *res)
5827{
5828 __be32 *p;
5829 int status;
5830 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005831 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005832
5833 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5834 if (status)
5835 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005836 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005837 if (unlikely(!p))
5838 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005839 res->return_on_close = be32_to_cpup(p);
5840 decode_stateid(xdr, &res->stateid);
5841 p = xdr_inline_decode(xdr, 4);
5842 if (unlikely(!p))
5843 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005844 layout_count = be32_to_cpup(p);
5845 if (!layout_count) {
5846 dprintk("%s: server responded with empty layout array\n",
5847 __func__);
5848 return -EINVAL;
5849 }
5850
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005851 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005852 if (unlikely(!p))
5853 goto out_overflow;
5854 p = xdr_decode_hyper(p, &res->range.offset);
5855 p = xdr_decode_hyper(p, &res->range.length);
5856 res->range.iomode = be32_to_cpup(p++);
5857 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005858 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005859
5860 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5861 __func__,
5862 (unsigned long)res->range.offset,
5863 (unsigned long)res->range.length,
5864 res->range.iomode,
5865 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005866 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005867
Trond Myklebust64bd5772012-06-20 22:35:05 -04005868 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005869 if (res->layoutp->len > recvd) {
5870 dprintk("NFS: server cheating in layoutget reply: "
5871 "layout len %u > recvd %u\n",
5872 res->layoutp->len, recvd);
5873 return -EINVAL;
5874 }
5875
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005876 if (layout_count > 1) {
5877 /* We only handle a length one array at the moment. Any
5878 * further entries are just ignored. Note that this means
5879 * the client may see a response that is less than the
5880 * minimum it requested.
5881 */
5882 dprintk("%s: server responded with %d layouts, dropping tail\n",
5883 __func__, layout_count);
5884 }
5885
5886 return 0;
5887out_overflow:
5888 print_overflow_msg(__func__, xdr);
5889 return -EIO;
5890}
Andy Adamson863a3c62011-03-23 13:27:54 +00005891
Benny Halevycbe82602011-05-22 19:52:37 +03005892static int decode_layoutreturn(struct xdr_stream *xdr,
5893 struct nfs4_layoutreturn_res *res)
5894{
5895 __be32 *p;
5896 int status;
5897
5898 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5899 if (status)
5900 return status;
5901 p = xdr_inline_decode(xdr, 4);
5902 if (unlikely(!p))
5903 goto out_overflow;
5904 res->lrs_present = be32_to_cpup(p);
5905 if (res->lrs_present)
5906 status = decode_stateid(xdr, &res->stateid);
5907 return status;
5908out_overflow:
5909 print_overflow_msg(__func__, xdr);
5910 return -EIO;
5911}
5912
Andy Adamson863a3c62011-03-23 13:27:54 +00005913static int decode_layoutcommit(struct xdr_stream *xdr,
5914 struct rpc_rqst *req,
5915 struct nfs4_layoutcommit_res *res)
5916{
5917 __be32 *p;
5918 __u32 sizechanged;
5919 int status;
5920
5921 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005922 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005923 if (status)
5924 return status;
5925
5926 p = xdr_inline_decode(xdr, 4);
5927 if (unlikely(!p))
5928 goto out_overflow;
5929 sizechanged = be32_to_cpup(p);
5930
5931 if (sizechanged) {
5932 /* throw away new size */
5933 p = xdr_inline_decode(xdr, 8);
5934 if (unlikely(!p))
5935 goto out_overflow;
5936 }
5937 return 0;
5938out_overflow:
5939 print_overflow_msg(__func__, xdr);
5940 return -EIO;
5941}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005942
5943static int decode_test_stateid(struct xdr_stream *xdr,
5944 struct nfs41_test_stateid_res *res)
5945{
5946 __be32 *p;
5947 int status;
5948 int num_res;
5949
5950 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5951 if (status)
5952 return status;
5953
5954 p = xdr_inline_decode(xdr, 4);
5955 if (unlikely(!p))
5956 goto out_overflow;
5957 num_res = be32_to_cpup(p++);
5958 if (num_res != 1)
5959 goto out;
5960
5961 p = xdr_inline_decode(xdr, 4);
5962 if (unlikely(!p))
5963 goto out_overflow;
5964 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005965
5966 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005967out_overflow:
5968 print_overflow_msg(__func__, xdr);
5969out:
5970 return -EIO;
5971}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005972
5973static int decode_free_stateid(struct xdr_stream *xdr,
5974 struct nfs41_free_stateid_res *res)
5975{
Andy Adamson9f79fb42013-09-10 12:56:29 -04005976 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005977 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005978}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005979#endif /* CONFIG_NFS_V4_1 */
5980
Linus Torvalds1da177e2005-04-16 15:20:36 -07005981/*
Benny Halevy49c25592008-12-23 16:06:16 -05005982 * END OF "GENERIC" DECODE ROUTINES.
5983 */
5984
5985/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005986 * Decode OPEN_DOWNGRADE response
5987 */
Chuck Leverbf269552010-12-14 14:59:29 +00005988static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5989 struct xdr_stream *xdr,
5990 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005991{
Andy Adamson05d564f2008-12-23 16:06:15 -05005992 struct compound_hdr hdr;
5993 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005994
Chuck Leverbf269552010-12-14 14:59:29 +00005995 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005996 if (status)
5997 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005998 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005999 if (status)
6000 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006001 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006002 if (status)
6003 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006004 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006005 if (status != 0)
6006 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006007 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006009 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010}
6011
6012/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013 * Decode ACCESS response
6014 */
Chuck Leverbf269552010-12-14 14:59:29 +00006015static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6016 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006017{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006018 struct compound_hdr hdr;
6019 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006020
Chuck Leverbf269552010-12-14 14:59:29 +00006021 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006022 if (status)
6023 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006024 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006025 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006026 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006027 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006028 if (status != 0)
6029 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006030 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006031 if (status != 0)
6032 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006033 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034out:
6035 return status;
6036}
6037
6038/*
6039 * Decode LOOKUP response
6040 */
Chuck Leverbf269552010-12-14 14:59:29 +00006041static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6042 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044 struct compound_hdr hdr;
6045 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006046
Chuck Leverbf269552010-12-14 14:59:29 +00006047 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006048 if (status)
6049 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006050 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006051 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006053 status = decode_putfh(xdr);
6054 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006056 status = decode_lookup(xdr);
6057 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006059 status = decode_getfh(xdr, res->fh);
6060 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006062 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006063out:
6064 return status;
6065}
6066
6067/*
6068 * Decode LOOKUP_ROOT response
6069 */
Chuck Leverbf269552010-12-14 14:59:29 +00006070static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6071 struct xdr_stream *xdr,
6072 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006074 struct compound_hdr hdr;
6075 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006076
Chuck Leverbf269552010-12-14 14:59:29 +00006077 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006078 if (status)
6079 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006080 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006081 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006082 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006083 status = decode_putrootfh(xdr);
6084 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006086 status = decode_getfh(xdr, res->fh);
6087 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006088 status = decode_getfattr_label(xdr, res->fattr,
6089 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090out:
6091 return status;
6092}
6093
6094/*
6095 * Decode REMOVE response
6096 */
Chuck Leverbf269552010-12-14 14:59:29 +00006097static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6098 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100 struct compound_hdr hdr;
6101 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006102
Chuck Leverbf269552010-12-14 14:59:29 +00006103 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006104 if (status)
6105 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006106 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006107 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006109 status = decode_putfh(xdr);
6110 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006111 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006112 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113out:
6114 return status;
6115}
6116
6117/*
6118 * Decode RENAME response
6119 */
Chuck Leverbf269552010-12-14 14:59:29 +00006120static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6121 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123 struct compound_hdr hdr;
6124 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006125
Chuck Leverbf269552010-12-14 14:59:29 +00006126 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006127 if (status)
6128 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006129 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006130 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006131 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006132 status = decode_putfh(xdr);
6133 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006134 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006135 status = decode_savefh(xdr);
6136 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006138 status = decode_putfh(xdr);
6139 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006140 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006141 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006142out:
6143 return status;
6144}
6145
6146/*
6147 * Decode LINK response
6148 */
Chuck Leverbf269552010-12-14 14:59:29 +00006149static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6150 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 struct compound_hdr hdr;
6153 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006154
Chuck Leverbf269552010-12-14 14:59:29 +00006155 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006156 if (status)
6157 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006158 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006159 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006161 status = decode_putfh(xdr);
6162 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006164 status = decode_savefh(xdr);
6165 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006166 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006167 status = decode_putfh(xdr);
6168 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006170 status = decode_link(xdr, &res->cinfo);
6171 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006172 goto out;
6173 /*
6174 * Note order: OP_LINK leaves the directory as the current
6175 * filehandle.
6176 */
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_restorefh(xdr);
6178 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006179 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006180 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181out:
6182 return status;
6183}
6184
6185/*
6186 * Decode CREATE response
6187 */
Chuck Leverbf269552010-12-14 14:59:29 +00006188static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6189 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191 struct compound_hdr hdr;
6192 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006193
Chuck Leverbf269552010-12-14 14:59:29 +00006194 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006195 if (status)
6196 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006197 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006198 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006199 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006200 status = decode_putfh(xdr);
6201 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006203 status = decode_create(xdr, &res->dir_cinfo);
6204 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006206 status = decode_getfh(xdr, res->fh);
6207 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006209 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210out:
6211 return status;
6212}
6213
6214/*
6215 * Decode SYMLINK response
6216 */
Chuck Leverbf269552010-12-14 14:59:29 +00006217static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6218 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219{
Chuck Leverbf269552010-12-14 14:59:29 +00006220 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221}
6222
6223/*
6224 * Decode GETATTR response
6225 */
Chuck Leverbf269552010-12-14 14:59:29 +00006226static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6227 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229 struct compound_hdr hdr;
6230 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006231
Chuck Leverbf269552010-12-14 14:59:29 +00006232 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 if (status)
6240 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006241 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242out:
6243 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006244}
6245
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006246/*
6247 * Encode an SETACL request
6248 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006249static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6250 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006251{
Andy Adamson05d564f2008-12-23 16:06:15 -05006252 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006253 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006254 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006255
Chuck Lever9f06c712010-12-14 14:59:18 +00006256 encode_compound_hdr(xdr, req, &hdr);
6257 encode_sequence(xdr, &args->seq_args, &hdr);
6258 encode_putfh(xdr, args->fh, &hdr);
6259 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006260 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006261}
Andy Adamson05d564f2008-12-23 16:06:15 -05006262
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006263/*
6264 * Decode SETACL response
6265 */
6266static int
Chuck Leverbf269552010-12-14 14:59:29 +00006267nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006268 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006269{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006270 struct compound_hdr hdr;
6271 int status;
6272
Chuck Leverbf269552010-12-14 14:59:29 +00006273 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006274 if (status)
6275 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006277 if (status)
6278 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006279 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006280 if (status)
6281 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006282 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006283out:
6284 return status;
6285}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006286
6287/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006288 * Decode GETACL response
6289 */
6290static int
Chuck Leverbf269552010-12-14 14:59:29 +00006291nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006292 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006293{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006294 struct compound_hdr hdr;
6295 int status;
6296
Trond Myklebust331818f2012-02-03 18:30:53 -05006297 if (res->acl_scratch != NULL) {
6298 void *p = page_address(res->acl_scratch);
6299 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6300 }
Chuck Leverbf269552010-12-14 14:59:29 +00006301 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006302 if (status)
6303 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006304 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006305 if (status)
6306 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006308 if (status)
6309 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006310 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006311
6312out:
6313 return status;
6314}
6315
6316/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317 * Decode CLOSE response
6318 */
Chuck Leverbf269552010-12-14 14:59:29 +00006319static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6320 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321{
Andy Adamson05d564f2008-12-23 16:06:15 -05006322 struct compound_hdr hdr;
6323 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006326 if (status)
6327 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006329 if (status)
6330 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006332 if (status)
6333 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006334 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006335 if (status != 0)
6336 goto out;
6337 /*
6338 * Note: Server may do delete on close for this file
6339 * in which case the getattr call will fail with
6340 * an ESTALE error. Shouldn't be a problem,
6341 * though, since fattr->valid will remain unset.
6342 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006343 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006344out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006345 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006346}
6347
6348/*
6349 * Decode OPEN response
6350 */
Chuck Leverbf269552010-12-14 14:59:29 +00006351static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6352 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353{
Andy Adamson05d564f2008-12-23 16:06:15 -05006354 struct compound_hdr hdr;
6355 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356
Chuck Leverbf269552010-12-14 14:59:29 +00006357 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006358 if (status)
6359 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006360 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006361 if (status)
6362 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006363 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006364 if (status)
6365 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006366 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006367 if (status)
6368 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006369 status = decode_getfh(xdr, &res->fh);
6370 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006372 if (res->access_request)
6373 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006374 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006376 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377}
6378
6379/*
6380 * Decode OPEN_CONFIRM response
6381 */
Chuck Leverbf269552010-12-14 14:59:29 +00006382static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6383 struct xdr_stream *xdr,
6384 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006385{
Andy Adamson05d564f2008-12-23 16:06:15 -05006386 struct compound_hdr hdr;
6387 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388
Chuck Leverbf269552010-12-14 14:59:29 +00006389 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006390 if (status)
6391 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006392 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006393 if (status)
6394 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006395 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006397 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398}
6399
6400/*
6401 * Decode OPEN response
6402 */
Chuck Leverbf269552010-12-14 14:59:29 +00006403static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6404 struct xdr_stream *xdr,
6405 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406{
Andy Adamson05d564f2008-12-23 16:06:15 -05006407 struct compound_hdr hdr;
6408 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006409
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006411 if (status)
6412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006414 if (status)
6415 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006417 if (status)
6418 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006420 if (status)
6421 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006422 if (res->access_request)
6423 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006424 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006425out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006426 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427}
6428
6429/*
6430 * Decode SETATTR response
6431 */
Chuck Leverbf269552010-12-14 14:59:29 +00006432static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6433 struct xdr_stream *xdr,
6434 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435{
Andy Adamson05d564f2008-12-23 16:06:15 -05006436 struct compound_hdr hdr;
6437 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438
Chuck Leverbf269552010-12-14 14:59:29 +00006439 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006440 if (status)
6441 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006442 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006443 if (status)
6444 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006445 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006446 if (status)
6447 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006449 if (status)
6450 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006451 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006452out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006453 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454}
6455
6456/*
6457 * Decode LOCK response
6458 */
Chuck Leverbf269552010-12-14 14:59:29 +00006459static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6460 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006462 struct compound_hdr hdr;
6463 int status;
6464
Chuck Leverbf269552010-12-14 14:59:29 +00006465 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466 if (status)
6467 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006468 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006469 if (status)
6470 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472 if (status)
6473 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006474 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475out:
6476 return status;
6477}
6478
6479/*
6480 * Decode LOCKT response
6481 */
Chuck Leverbf269552010-12-14 14:59:29 +00006482static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6483 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485 struct compound_hdr hdr;
6486 int status;
6487
Chuck Leverbf269552010-12-14 14:59:29 +00006488 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489 if (status)
6490 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006491 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006492 if (status)
6493 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006494 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495 if (status)
6496 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006497 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006498out:
6499 return status;
6500}
6501
6502/*
6503 * Decode LOCKU response
6504 */
Chuck Leverbf269552010-12-14 14:59:29 +00006505static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6506 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 struct compound_hdr hdr;
6509 int status;
6510
Chuck Leverbf269552010-12-14 14:59:29 +00006511 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006512 if (status)
6513 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006514 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006515 if (status)
6516 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006517 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 if (status)
6519 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006520 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006521out:
6522 return status;
6523}
6524
Chuck Leverbf269552010-12-14 14:59:29 +00006525static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6526 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006527{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006528 struct compound_hdr hdr;
6529 int status;
6530
Chuck Leverbf269552010-12-14 14:59:29 +00006531 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006532 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006533 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006534 return status;
6535}
6536
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537/*
6538 * Decode READLINK response
6539 */
Chuck Leverbf269552010-12-14 14:59:29 +00006540static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6541 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006542 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006543{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544 struct compound_hdr hdr;
6545 int status;
6546
Chuck Leverbf269552010-12-14 14:59:29 +00006547 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 if (status)
6549 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006550 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006551 if (status)
6552 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006553 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554 if (status)
6555 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006556 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006557out:
6558 return status;
6559}
6560
6561/*
6562 * Decode READDIR response
6563 */
Chuck Leverbf269552010-12-14 14:59:29 +00006564static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6565 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567 struct compound_hdr hdr;
6568 int status;
6569
Chuck Leverbf269552010-12-14 14:59:29 +00006570 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006571 if (status)
6572 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006573 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006574 if (status)
6575 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006576 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006577 if (status)
6578 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006579 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006580out:
6581 return status;
6582}
6583
6584/*
6585 * Decode Read response
6586 */
Chuck Leverbf269552010-12-14 14:59:29 +00006587static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006588 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590 struct compound_hdr hdr;
6591 int status;
6592
Chuck Leverbf269552010-12-14 14:59:29 +00006593 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006594 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595 if (status)
6596 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006597 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006598 if (status)
6599 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006600 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006601 if (status)
6602 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604 if (!status)
6605 status = res->count;
6606out:
6607 return status;
6608}
6609
6610/*
6611 * Decode WRITE response
6612 */
Chuck Leverbf269552010-12-14 14:59:29 +00006613static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006614 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006616 struct compound_hdr hdr;
6617 int status;
6618
Chuck Leverbf269552010-12-14 14:59:29 +00006619 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006620 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006621 if (status)
6622 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006623 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006624 if (status)
6625 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627 if (status)
6628 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006629 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006630 if (status)
6631 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006632 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006633 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634 if (!status)
6635 status = res->count;
6636out:
6637 return status;
6638}
6639
6640/*
6641 * Decode COMMIT response
6642 */
Chuck Leverbf269552010-12-14 14:59:29 +00006643static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006644 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006645{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006646 struct compound_hdr hdr;
6647 int status;
6648
Chuck Leverbf269552010-12-14 14:59:29 +00006649 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006650 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006651 if (status)
6652 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006654 if (status)
6655 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006656 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006657 if (status)
6658 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006659 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660out:
6661 return status;
6662}
6663
6664/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006665 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666 */
Chuck Leverbf269552010-12-14 14:59:29 +00006667static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006668 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006670 struct compound_hdr hdr;
6671 int status;
6672
Chuck Leverbf269552010-12-14 14:59:29 +00006673 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006675 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006676 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006677 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006678 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006679 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680 return status;
6681}
6682
6683/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006684 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006685 */
Chuck Leverbf269552010-12-14 14:59:29 +00006686static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006687 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006688{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689 struct compound_hdr hdr;
6690 int status;
6691
Chuck Leverbf269552010-12-14 14:59:29 +00006692 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006693 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006694 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006695 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006696 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006697 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006698 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 return status;
6700}
6701
6702/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006703 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006704 */
Chuck Leverbf269552010-12-14 14:59:29 +00006705static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006706 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006707{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006708 struct compound_hdr hdr;
6709 int status;
6710
Chuck Leverbf269552010-12-14 14:59:29 +00006711 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006713 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006714 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006715 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006716 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006717 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006718 return status;
6719}
6720
6721/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006722 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723 */
Chuck Leverbf269552010-12-14 14:59:29 +00006724static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6725 struct xdr_stream *xdr,
6726 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006727{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006728 struct compound_hdr hdr;
6729 int status;
6730
Chuck Leverbf269552010-12-14 14:59:29 +00006731 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006732 if (status)
6733 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006734 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006735 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006737 status = decode_putfh(xdr);
6738 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006739 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006740 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006741out:
6742 return status;
6743}
6744
6745/*
6746 * Decode RENEW response
6747 */
Chuck Leverbf269552010-12-14 14:59:29 +00006748static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6749 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006750{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006751 struct compound_hdr hdr;
6752 int status;
6753
Chuck Leverbf269552010-12-14 14:59:29 +00006754 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006755 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006756 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 return status;
6758}
6759
6760/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006761 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006762 */
Chuck Leverbf269552010-12-14 14:59:29 +00006763static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6764 struct xdr_stream *xdr,
6765 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006767 struct compound_hdr hdr;
6768 int status;
6769
Chuck Leverbf269552010-12-14 14:59:29 +00006770 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006771 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006772 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006773 return status;
6774}
6775
6776/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006777 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778 */
Chuck Leverbf269552010-12-14 14:59:29 +00006779static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006780 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006781{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006782 struct compound_hdr hdr;
6783 int status;
6784
Chuck Leverbf269552010-12-14 14:59:29 +00006785 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006786 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006788 return status;
6789}
6790
6791/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006792 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006793 */
Chuck Leverbf269552010-12-14 14:59:29 +00006794static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6795 struct xdr_stream *xdr,
6796 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006797{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006798 struct compound_hdr hdr;
6799 int status;
6800
Chuck Leverbf269552010-12-14 14:59:29 +00006801 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006802 if (status)
6803 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006804 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006805 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006806 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006807 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006808 if (status != 0)
6809 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006810 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006811 if (status != 0)
6812 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006813 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006814out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006815 return status;
6816}
6817
Trond Myklebust683b57b2006-06-09 09:34:22 -04006818/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006819 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006820 */
Chuck Leverbf269552010-12-14 14:59:29 +00006821static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6822 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006823 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006824{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006825 struct compound_hdr hdr;
6826 int status;
6827
Chuck Leverbf269552010-12-14 14:59:29 +00006828 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006829 if (status)
6830 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006831 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006832 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006833 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006834 status = decode_putfh(xdr);
6835 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006836 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006837 if (res->migration) {
6838 xdr_enter_page(xdr, PAGE_SIZE);
6839 status = decode_getfattr_generic(xdr,
6840 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006841 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006842 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006843 if (status)
6844 goto out;
6845 if (res->renew)
6846 status = decode_renew(xdr);
6847 } else {
6848 status = decode_lookup(xdr);
6849 if (status)
6850 goto out;
6851 xdr_enter_page(xdr, PAGE_SIZE);
6852 status = decode_getfattr_generic(xdr,
6853 &res->fs_locations->fattr,
6854 NULL, res->fs_locations,
6855 NULL, res->fs_locations->server);
6856 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006857out:
6858 return status;
6859}
6860
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006861/*
6862 * Decode SECINFO response
6863 */
6864static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6865 struct xdr_stream *xdr,
6866 struct nfs4_secinfo_res *res)
6867{
6868 struct compound_hdr hdr;
6869 int status;
6870
6871 status = decode_compound_hdr(xdr, &hdr);
6872 if (status)
6873 goto out;
6874 status = decode_sequence(xdr, &res->seq_res, rqstp);
6875 if (status)
6876 goto out;
6877 status = decode_putfh(xdr);
6878 if (status)
6879 goto out;
6880 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006881out:
6882 return status;
6883}
6884
Chuck Lever44c99932013-10-17 14:13:30 -04006885/*
6886 * Decode FSID_PRESENT response
6887 */
6888static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6889 struct xdr_stream *xdr,
6890 struct nfs4_fsid_present_res *res)
6891{
6892 struct compound_hdr hdr;
6893 int status;
6894
6895 status = decode_compound_hdr(xdr, &hdr);
6896 if (status)
6897 goto out;
6898 status = decode_sequence(xdr, &res->seq_res, rqstp);
6899 if (status)
6900 goto out;
6901 status = decode_putfh(xdr);
6902 if (status)
6903 goto out;
6904 status = decode_getfh(xdr, res->fh);
6905 if (status)
6906 goto out;
6907 if (res->renew)
6908 status = decode_renew(xdr);
6909out:
6910 return status;
6911}
6912
Benny Halevy99fe60d2009-04-01 09:22:29 -04006913#if defined(CONFIG_NFS_V4_1)
6914/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006915 * Decode BIND_CONN_TO_SESSION response
6916 */
6917static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6918 struct xdr_stream *xdr,
6919 void *res)
6920{
6921 struct compound_hdr hdr;
6922 int status;
6923
6924 status = decode_compound_hdr(xdr, &hdr);
6925 if (!status)
6926 status = decode_bind_conn_to_session(xdr, res);
6927 return status;
6928}
6929
6930/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006931 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006932 */
Chuck Leverbf269552010-12-14 14:59:29 +00006933static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6934 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006935 void *res)
6936{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006937 struct compound_hdr hdr;
6938 int status;
6939
Chuck Leverbf269552010-12-14 14:59:29 +00006940 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006941 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006942 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006943 return status;
6944}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006945
6946/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006947 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006948 */
Chuck Leverbf269552010-12-14 14:59:29 +00006949static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6950 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006951 struct nfs41_create_session_res *res)
6952{
Andy Adamsonfc931582009-04-01 09:22:31 -04006953 struct compound_hdr hdr;
6954 int status;
6955
Chuck Leverbf269552010-12-14 14:59:29 +00006956 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006957 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006958 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006959 return status;
6960}
6961
6962/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006963 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006964 */
Chuck Leverbf269552010-12-14 14:59:29 +00006965static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6966 struct xdr_stream *xdr,
6967 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006968{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006969 struct compound_hdr hdr;
6970 int status;
6971
Chuck Leverbf269552010-12-14 14:59:29 +00006972 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006973 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006974 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006975 return status;
6976}
6977
6978/*
Trond Myklebust66245532012-05-25 17:18:09 -04006979 * Decode DESTROY_CLIENTID response
6980 */
6981static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6982 struct xdr_stream *xdr,
6983 void *res)
6984{
6985 struct compound_hdr hdr;
6986 int status;
6987
6988 status = decode_compound_hdr(xdr, &hdr);
6989 if (!status)
6990 status = decode_destroy_clientid(xdr, res);
6991 return status;
6992}
6993
6994/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006995 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006996 */
Chuck Leverbf269552010-12-14 14:59:29 +00006997static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6998 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006999 struct nfs4_sequence_res *res)
7000{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007001 struct compound_hdr hdr;
7002 int status;
7003
Chuck Leverbf269552010-12-14 14:59:29 +00007004 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007005 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007006 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007007 return status;
7008}
7009
7010/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007011 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007012 */
Chuck Leverbf269552010-12-14 14:59:29 +00007013static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7014 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007015 struct nfs4_get_lease_time_res *res)
7016{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007017 struct compound_hdr hdr;
7018 int status;
7019
Chuck Leverbf269552010-12-14 14:59:29 +00007020 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007021 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007022 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007023 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007024 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007025 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007026 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007027 return status;
7028}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007029
7030/*
7031 * Decode RECLAIM_COMPLETE response
7032 */
Chuck Leverbf269552010-12-14 14:59:29 +00007033static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7034 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007035 struct nfs41_reclaim_complete_res *res)
7036{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007037 struct compound_hdr hdr;
7038 int status;
7039
Chuck Leverbf269552010-12-14 14:59:29 +00007040 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007041 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007042 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007043 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307044 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007045 return status;
7046}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007047
7048/*
7049 * Decode GETDEVINFO response
7050 */
Chuck Leverbf269552010-12-14 14:59:29 +00007051static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7052 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007053 struct nfs4_getdeviceinfo_res *res)
7054{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007055 struct compound_hdr hdr;
7056 int status;
7057
Chuck Leverbf269552010-12-14 14:59:29 +00007058 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007059 if (status != 0)
7060 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007061 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007062 if (status != 0)
7063 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007064 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007065out:
7066 return status;
7067}
7068
7069/*
7070 * Decode LAYOUTGET response
7071 */
Chuck Leverbf269552010-12-14 14:59:29 +00007072static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7073 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007074 struct nfs4_layoutget_res *res)
7075{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007076 struct compound_hdr hdr;
7077 int status;
7078
Chuck Leverbf269552010-12-14 14:59:29 +00007079 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007080 if (status)
7081 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007082 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007083 if (status)
7084 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007085 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007086 if (status)
7087 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007088 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007089out:
7090 return status;
7091}
Andy Adamson863a3c62011-03-23 13:27:54 +00007092
7093/*
Benny Halevycbe82602011-05-22 19:52:37 +03007094 * Decode LAYOUTRETURN response
7095 */
7096static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7097 struct xdr_stream *xdr,
7098 struct nfs4_layoutreturn_res *res)
7099{
7100 struct compound_hdr hdr;
7101 int status;
7102
7103 status = decode_compound_hdr(xdr, &hdr);
7104 if (status)
7105 goto out;
7106 status = decode_sequence(xdr, &res->seq_res, rqstp);
7107 if (status)
7108 goto out;
7109 status = decode_putfh(xdr);
7110 if (status)
7111 goto out;
7112 status = decode_layoutreturn(xdr, res);
7113out:
7114 return status;
7115}
7116
7117/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007118 * Decode LAYOUTCOMMIT response
7119 */
7120static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7121 struct xdr_stream *xdr,
7122 struct nfs4_layoutcommit_res *res)
7123{
7124 struct compound_hdr hdr;
7125 int status;
7126
7127 status = decode_compound_hdr(xdr, &hdr);
7128 if (status)
7129 goto out;
7130 status = decode_sequence(xdr, &res->seq_res, rqstp);
7131 if (status)
7132 goto out;
7133 status = decode_putfh(xdr);
7134 if (status)
7135 goto out;
7136 status = decode_layoutcommit(xdr, rqstp, res);
7137 if (status)
7138 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007139 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007140out:
7141 return status;
7142}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007143
7144/*
7145 * Decode SECINFO_NO_NAME response
7146 */
7147static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7148 struct xdr_stream *xdr,
7149 struct nfs4_secinfo_res *res)
7150{
7151 struct compound_hdr hdr;
7152 int status;
7153
7154 status = decode_compound_hdr(xdr, &hdr);
7155 if (status)
7156 goto out;
7157 status = decode_sequence(xdr, &res->seq_res, rqstp);
7158 if (status)
7159 goto out;
7160 status = decode_putrootfh(xdr);
7161 if (status)
7162 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007163 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007164out:
7165 return status;
7166}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007167
7168/*
7169 * Decode TEST_STATEID response
7170 */
7171static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7172 struct xdr_stream *xdr,
7173 struct nfs41_test_stateid_res *res)
7174{
7175 struct compound_hdr hdr;
7176 int status;
7177
7178 status = decode_compound_hdr(xdr, &hdr);
7179 if (status)
7180 goto out;
7181 status = decode_sequence(xdr, &res->seq_res, rqstp);
7182 if (status)
7183 goto out;
7184 status = decode_test_stateid(xdr, res);
7185out:
7186 return status;
7187}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007188
7189/*
7190 * Decode FREE_STATEID response
7191 */
7192static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7193 struct xdr_stream *xdr,
7194 struct nfs41_free_stateid_res *res)
7195{
7196 struct compound_hdr hdr;
7197 int status;
7198
7199 status = decode_compound_hdr(xdr, &hdr);
7200 if (status)
7201 goto out;
7202 status = decode_sequence(xdr, &res->seq_res, rqstp);
7203 if (status)
7204 goto out;
7205 status = decode_free_stateid(xdr, res);
7206out:
7207 return status;
7208}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007209#endif /* CONFIG_NFS_V4_1 */
7210
Chuck Lever573c4e12010-12-14 14:58:11 +00007211/**
7212 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7213 * the local page cache.
7214 * @xdr: XDR stream where entry resides
7215 * @entry: buffer to fill in with entry data
7216 * @plus: boolean indicating whether this should be a readdirplus entry
7217 *
7218 * Returns zero if successful, otherwise a negative errno value is
7219 * returned.
7220 *
7221 * This function is not invoked during READDIR reply decoding, but
7222 * rather whenever an application invokes the getdents(2) system call
7223 * on a directory already in our cache.
7224 */
7225int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7226 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007227{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007228 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007229 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007230 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007231 __be32 *p = xdr_inline_decode(xdr, 4);
7232 if (unlikely(!p))
7233 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007234 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007235 p = xdr_inline_decode(xdr, 4);
7236 if (unlikely(!p))
7237 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007238 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007239 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007240 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007241 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007242 }
7243
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007244 p = xdr_inline_decode(xdr, 12);
7245 if (unlikely(!p))
7246 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007247 entry->prev_cookie = entry->cookie;
7248 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007249 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007250
Trond Myklebust9af8c222010-10-24 11:52:55 -04007251 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007252 if (unlikely(!p))
7253 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007254 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007255
7256 /*
7257 * In case the server doesn't return an inode number,
7258 * we fake one here. (We don't use inode number 0,
7259 * since glibc seems to choke on it...)
7260 */
7261 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007262 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007263
Trond Myklebust9af8c222010-10-24 11:52:55 -04007264 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007265 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007266
Trond Myklebust256e48b2012-06-21 11:18:13 -04007267 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007268 goto out_overflow;
7269
Chuck Lever573c4e12010-12-14 14:58:11 +00007270 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007271 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007272 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007273 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7274 entry->ino = entry->fattr->mounted_on_fileid;
7275 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007276 entry->ino = entry->fattr->fileid;
7277
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007278 entry->d_type = DT_UNKNOWN;
7279 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7280 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7281
Chuck Lever573c4e12010-12-14 14:58:11 +00007282 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007283
7284out_overflow:
7285 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007286 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007287}
7288
7289/*
7290 * We need to translate between nfs status return values and
7291 * the local errno values which may not be the same.
7292 */
7293static struct {
7294 int stat;
7295 int errno;
7296} nfs_errtbl[] = {
7297 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007298 { NFS4ERR_PERM, -EPERM },
7299 { NFS4ERR_NOENT, -ENOENT },
7300 { NFS4ERR_IO, -errno_NFSERR_IO},
7301 { NFS4ERR_NXIO, -ENXIO },
7302 { NFS4ERR_ACCESS, -EACCES },
7303 { NFS4ERR_EXIST, -EEXIST },
7304 { NFS4ERR_XDEV, -EXDEV },
7305 { NFS4ERR_NOTDIR, -ENOTDIR },
7306 { NFS4ERR_ISDIR, -EISDIR },
7307 { NFS4ERR_INVAL, -EINVAL },
7308 { NFS4ERR_FBIG, -EFBIG },
7309 { NFS4ERR_NOSPC, -ENOSPC },
7310 { NFS4ERR_ROFS, -EROFS },
7311 { NFS4ERR_MLINK, -EMLINK },
7312 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7313 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7314 { NFS4ERR_DQUOT, -EDQUOT },
7315 { NFS4ERR_STALE, -ESTALE },
7316 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007317 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7318 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7319 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007320 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007321 { NFS4ERR_BADTYPE, -EBADTYPE },
7322 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007323 { NFS4ERR_SYMLINK, -ELOOP },
7324 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7325 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007326 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007327};
7328
7329/*
7330 * Convert an NFS error code to a local one.
7331 * This one is used jointly by NFSv2 and NFSv3.
7332 */
7333static int
David Howells0a8ea432006-08-22 20:06:08 -04007334nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007335{
7336 int i;
7337 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7338 if (nfs_errtbl[i].stat == stat)
7339 return nfs_errtbl[i].errno;
7340 }
7341 if (stat <= 10000 || stat > 10100) {
7342 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007343 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007344 }
7345 /* If we cannot translate the error, the recovery routines should
7346 * handle it.
7347 * Note: remaining NFSv4 error codes have values > 10000, so should
7348 * not conflict with native Linux error codes.
7349 */
Benny Halevy856dff32008-03-31 17:39:06 +03007350 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007351}
7352
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007353#ifdef CONFIG_NFS_V4_2
7354#include "nfs42xdr.c"
7355#endif /* CONFIG_NFS_V4_2 */
7356
Linus Torvalds1da177e2005-04-16 15:20:36 -07007357#define PROC(proc, argtype, restype) \
7358[NFSPROC4_CLNT_##proc] = { \
7359 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007360 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007361 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007362 .p_arglen = NFS4_##argtype##_sz, \
7363 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007364 .p_statidx = NFSPROC4_CLNT_##proc, \
7365 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007366}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007367
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007368#define STUB(proc) \
7369[NFSPROC4_CLNT_##proc] = { \
7370 .p_name = #proc, \
7371}
7372
Linus Torvalds1da177e2005-04-16 15:20:36 -07007373struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007374 PROC(READ, enc_read, dec_read),
7375 PROC(WRITE, enc_write, dec_write),
7376 PROC(COMMIT, enc_commit, dec_commit),
7377 PROC(OPEN, enc_open, dec_open),
7378 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7379 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7380 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7381 PROC(CLOSE, enc_close, dec_close),
7382 PROC(SETATTR, enc_setattr, dec_setattr),
7383 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7384 PROC(RENEW, enc_renew, dec_renew),
7385 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7386 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7387 PROC(LOCK, enc_lock, dec_lock),
7388 PROC(LOCKT, enc_lockt, dec_lockt),
7389 PROC(LOCKU, enc_locku, dec_locku),
7390 PROC(ACCESS, enc_access, dec_access),
7391 PROC(GETATTR, enc_getattr, dec_getattr),
7392 PROC(LOOKUP, enc_lookup, dec_lookup),
7393 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7394 PROC(REMOVE, enc_remove, dec_remove),
7395 PROC(RENAME, enc_rename, dec_rename),
7396 PROC(LINK, enc_link, dec_link),
7397 PROC(SYMLINK, enc_symlink, dec_symlink),
7398 PROC(CREATE, enc_create, dec_create),
7399 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7400 PROC(STATFS, enc_statfs, dec_statfs),
7401 PROC(READLINK, enc_readlink, dec_readlink),
7402 PROC(READDIR, enc_readdir, dec_readdir),
7403 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7404 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7405 PROC(GETACL, enc_getacl, dec_getacl),
7406 PROC(SETACL, enc_setacl, dec_setacl),
7407 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7408 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007409 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007410 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007411#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007412 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7413 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7414 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7415 PROC(SEQUENCE, enc_sequence, dec_sequence),
7416 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7417 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7418 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7419 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007420 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007421 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007422 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007423 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007424 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007425 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007426 PROC(BIND_CONN_TO_SESSION,
7427 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007428 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007429#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007430#ifdef CONFIG_NFS_V4_2
7431 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007432 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007433 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007434#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007435};
7436
Trond Myklebusta613fa12012-01-20 13:53:56 -05007437const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007438 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007439 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007440 .procs = nfs4_procedures
7441};
7442
7443/*
7444 * Local variables:
7445 * c-basic-offset: 8
7446 * End:
7447 */