blob: ad8dde12f23bc85aeff71b272b9743ff538b52bc [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 Lever2fcc2132015-08-03 13:04:26 -04001157 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1158 create->u.symlink.len);
1159 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 break;
1161
1162 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001163 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001164 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001165 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 break;
1167
1168 default:
1169 break;
1170 }
1171
Benny Halevy811652b2009-08-14 17:19:34 +03001172 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001173 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174}
1175
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001176static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177{
Andy Adamson05d564f2008-12-23 16:06:15 -05001178 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001180 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1181 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001182 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001183 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184}
1185
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001186static 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 -07001187{
Andy Adamson05d564f2008-12-23 16:06:15 -05001188 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001190 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1191 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001192 *p++ = cpu_to_be32(2);
1193 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001194 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195}
1196
Fred Isamandae100c2011-07-30 20:52:37 -04001197static void
1198encode_getattr_three(struct xdr_stream *xdr,
1199 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1200 struct compound_hdr *hdr)
1201{
1202 __be32 *p;
1203
Trond Myklebustab19b482012-03-04 18:13:57 -05001204 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001205 if (bm2) {
1206 p = reserve_space(xdr, 16);
1207 *p++ = cpu_to_be32(3);
1208 *p++ = cpu_to_be32(bm0);
1209 *p++ = cpu_to_be32(bm1);
1210 *p = cpu_to_be32(bm2);
1211 } else if (bm1) {
1212 p = reserve_space(xdr, 12);
1213 *p++ = cpu_to_be32(2);
1214 *p++ = cpu_to_be32(bm0);
1215 *p = cpu_to_be32(bm1);
1216 } else {
1217 p = reserve_space(xdr, 8);
1218 *p++ = cpu_to_be32(1);
1219 *p = cpu_to_be32(bm0);
1220 }
Fred Isamandae100c2011-07-30 20:52:37 -04001221}
1222
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001223static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
David Quigleya09df2c2013-05-22 12:50:41 -04001225 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1226 bitmask[1] & nfs4_fattr_bitmap[1],
1227 bitmask[2] & nfs4_fattr_bitmap[2],
1228 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229}
1230
Andy Adamson88034c32012-05-23 05:02:34 -04001231static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001232 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001233 struct compound_hdr *hdr)
1234{
1235 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001236 bitmask[0] & open_bitmap[0],
1237 bitmask[1] & open_bitmap[1],
1238 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001239 hdr);
1240}
1241
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001242static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
Fred Isamandae100c2011-07-30 20:52:37 -04001244 encode_getattr_three(xdr,
1245 bitmask[0] & nfs4_fsinfo_bitmap[0],
1246 bitmask[1] & nfs4_fsinfo_bitmap[1],
1247 bitmask[2] & nfs4_fsinfo_bitmap[2],
1248 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249}
1250
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001251static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001252{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001253 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1254 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001255}
1256
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001257static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
Trond Myklebustab19b482012-03-04 18:13:57 -05001259 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260}
1261
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001262static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
Trond Myklebustab19b482012-03-04 18:13:57 -05001264 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001265 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266}
1267
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001268static inline int nfs4_lock_type(struct file_lock *fl, int block)
1269{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001270 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001271 return block ? NFS4_READW_LT : NFS4_READ_LT;
1272 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1273}
1274
1275static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1276{
1277 if (fl->fl_end == OFFSET_MAX)
1278 return ~(uint64_t)0;
1279 return fl->fl_end - fl->fl_start + 1;
1280}
1281
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001282static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1283{
1284 __be32 *p;
1285
Trond Myklebustd035c362010-12-21 10:45:27 -05001286 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001287 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001288 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001289 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001290 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001291 xdr_encode_hyper(p, lowner->id);
1292}
1293
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294/*
1295 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1296 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1297 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001298static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
Al Viro8687b632006-10-19 23:28:48 -07001300 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001302 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1303 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001304 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1305 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001306 p = xdr_encode_hyper(p, args->fl->fl_start);
1307 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001308 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001309 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001310 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001311 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001312 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001313 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 }
1315 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001316 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001317 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319}
1320
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001321static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322{
Al Viro8687b632006-10-19 23:28:48 -07001323 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001325 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1326 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001327 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001328 p = xdr_encode_hyper(p, args->fl->fl_start);
1329 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001330 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001333static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334{
Al Viro8687b632006-10-19 23:28:48 -07001335 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001337 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1338 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001339 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001340 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001341 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001342 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001343 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344}
1345
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001346static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1347{
Trond Myklebustab19b482012-03-04 18:13:57 -05001348 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001349 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001350}
1351
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001352static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353{
Trond Myklebustab19b482012-03-04 18:13:57 -05001354 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001355 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356}
1357
Trond Myklebust6ae37332015-01-30 14:21:14 -05001358static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359{
Al Viro8687b632006-10-19 23:28:48 -07001360 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Benny Halevy13c65ce2009-08-14 17:19:25 +03001362 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001363 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001364 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365}
1366
1367static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1368{
Al Viro8687b632006-10-19 23:28:48 -07001369 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 /*
1371 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1372 * owner 4 = 32
1373 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001374 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001375 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001376 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001377 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001378 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001379 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001380 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001381 *p++ = cpu_to_be32(arg->id.uniquifier);
1382 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383}
1384
1385static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1386{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001387 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001388 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Benny Halevy13c65ce2009-08-14 17:19:25 +03001390 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001391 switch(arg->createmode) {
1392 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001393 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001394 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001395 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001396 case NFS4_CREATE_GUARDED:
1397 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001398 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001399 break;
1400 case NFS4_CREATE_EXCLUSIVE:
1401 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1402 encode_nfs4_verifier(xdr, &arg->u.verifier);
1403 break;
1404 case NFS4_CREATE_EXCLUSIVE4_1:
1405 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1406 encode_nfs4_verifier(xdr, &arg->u.verifier);
1407 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001408 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 }
1410}
1411
1412static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1413{
Al Viro8687b632006-10-19 23:28:48 -07001414 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
Benny Halevy13c65ce2009-08-14 17:19:25 +03001416 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001418 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001419 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001420 break;
1421 default:
Benny Halevy34558512009-08-14 17:19:30 +03001422 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001423 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 }
1425}
1426
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001427static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428{
Al Viro8687b632006-10-19 23:28:48 -07001429 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Benny Halevy13c65ce2009-08-14 17:19:25 +03001431 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001433 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001434 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001435 break;
1436 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001437 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 break;
1439 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001440 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001441 break;
1442 default:
1443 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 }
1445}
1446
1447static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1448{
Al Viro8687b632006-10-19 23:28:48 -07001449 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Benny Halevy13c65ce2009-08-14 17:19:25 +03001451 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001452 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 encode_string(xdr, name->len, name->name);
1454}
1455
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001456static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457{
Al Viro8687b632006-10-19 23:28:48 -07001458 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Benny Halevy13c65ce2009-08-14 17:19:25 +03001460 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001461 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 encode_delegation_type(xdr, type);
1463}
1464
1465static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1466{
Al Viro8687b632006-10-19 23:28:48 -07001467 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001469 p = reserve_space(xdr, 4);
1470 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1471 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 encode_string(xdr, name->len, name->name);
1473}
1474
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001475static inline void encode_claim_fh(struct xdr_stream *xdr)
1476{
1477 __be32 *p;
1478
1479 p = reserve_space(xdr, 4);
1480 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1481}
1482
1483static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1484{
1485 __be32 *p;
1486
1487 p = reserve_space(xdr, 4);
1488 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1489 encode_nfs4_stateid(xdr, stateid);
1490}
1491
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001492static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493{
Trond Myklebustab19b482012-03-04 18:13:57 -05001494 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 encode_openhdr(xdr, arg);
1496 encode_opentype(xdr, arg);
1497 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001498 case NFS4_OPEN_CLAIM_NULL:
1499 encode_claim_null(xdr, arg->name);
1500 break;
1501 case NFS4_OPEN_CLAIM_PREVIOUS:
1502 encode_claim_previous(xdr, arg->u.delegation_type);
1503 break;
1504 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1505 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1506 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001507 case NFS4_OPEN_CLAIM_FH:
1508 encode_claim_fh(xdr);
1509 break;
1510 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1511 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1512 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001513 default:
1514 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516}
1517
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001518static 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 -07001519{
Trond Myklebustab19b482012-03-04 18:13:57 -05001520 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001521 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001522 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523}
1524
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001525static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
Trond Myklebustab19b482012-03-04 18:13:57 -05001527 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001528 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001529 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001530 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531}
1532
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001533static void
Andy Adamsond0179312008-12-23 16:06:17 -05001534encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535{
Trond Myklebustab19b482012-03-04 18:13:57 -05001536 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001537 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538}
1539
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001540static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
Trond Myklebustab19b482012-03-04 18:13:57 -05001542 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001545static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1546 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547{
Al Viro8687b632006-10-19 23:28:48 -07001548 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Trond Myklebustab19b482012-03-04 18:13:57 -05001550 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001551 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Benny Halevy13c65ce2009-08-14 17:19:25 +03001553 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001554 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001555 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556}
1557
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001558static 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 -07001559{
David Quigleyaa9c2662013-05-22 12:50:44 -04001560 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001561 FATTR4_WORD0_RDATTR_ERROR,
1562 FATTR4_WORD1_MOUNTED_ON_FILEID,
1563 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001564 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001565 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001566 uint32_t attrlen = 0;
1567 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001569 if (readdir->plus) {
1570 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001571 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001572 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1573 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1574 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1575 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001576 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001577 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001578 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001579 /* Use mounted_on_fileid only if the server supports it */
1580 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1581 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001582 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1583 attrs[i] &= readdir->bitmask[i];
1584 if (attrs[i] != 0)
1585 attrlen = i+1;
1586 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001587
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001588 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001589 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001590 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001591 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001592 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001593 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001594 *p++ = cpu_to_be32(attrlen);
1595 for (i = 0; i < attrlen; i++)
1596 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001597 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001598
1599 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001600 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001601 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001602 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001603 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001604 attrs[1] & readdir->bitmask[1],
1605 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606}
1607
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001608static 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 -07001609{
Trond Myklebustab19b482012-03-04 18:13:57 -05001610 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611}
1612
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001613static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614{
Trond Myklebustab19b482012-03-04 18:13:57 -05001615 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001616 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617}
1618
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001619static 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 -07001620{
Trond Myklebustab19b482012-03-04 18:13:57 -05001621 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001622 encode_string(xdr, oldname->len, oldname->name);
1623 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624}
1625
Chuck Leverbb4dae52012-03-01 17:01:48 -05001626static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1627 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001629 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001630 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001633static void
Andy Adamsond0179312008-12-23 16:06:17 -05001634encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001635{
Trond Myklebustab19b482012-03-04 18:13:57 -05001636 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001637}
1638
Chuck Lever9f06c712010-12-14 14:59:18 +00001639static void
Andy Adamsond0179312008-12-23 16:06:17 -05001640encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001641{
Al Viro8687b632006-10-19 23:28:48 -07001642 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001643
Trond Myklebustab19b482012-03-04 18:13:57 -05001644 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001645 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001646 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001647 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001648 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001649 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001650 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001651 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001652}
1653
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001654static void
Andy Adamsond0179312008-12-23 16:06:17 -05001655encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
Trond Myklebustab19b482012-03-04 18:13:57 -05001657 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
1659
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001660static 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 -07001661{
Trond Myklebustab19b482012-03-04 18:13:57 -05001662 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001663 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001664 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
1666
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001667static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668{
Al Viro8687b632006-10-19 23:28:48 -07001669 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
Trond Myklebust70019512012-03-04 20:49:32 -05001671 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001672 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Jeff Layton3a6bb732015-06-09 19:43:57 -04001674 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1675 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001676 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001677 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1679 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001680 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001681 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682}
1683
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001684static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001686 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1687 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001688 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001689 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690}
1691
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001692static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1693 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
Al Viro8687b632006-10-19 23:28:48 -07001695 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
Trond Myklebustab19b482012-03-04 18:13:57 -05001697 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001698 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
Benny Halevy13c65ce2009-08-14 17:19:25 +03001700 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001701 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001702 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001703 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
1705 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706}
1707
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001708static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709{
Trond Myklebustab19b482012-03-04 18:13:57 -05001710 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001711 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001713
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001714static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1715{
Trond Myklebustab19b482012-03-04 18:13:57 -05001716 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001717 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001718}
1719
Benny Halevy99fe60d2009-04-01 09:22:29 -04001720#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001721/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001722static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08001723 struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001724 struct compound_hdr *hdr)
1725{
1726 __be32 *p;
1727
1728 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1729 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001730 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001731 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001732 *p++ = cpu_to_be32(args->dir);
1733 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001734}
1735
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001736static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1737{
1738 unsigned int i;
1739 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1740 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1741 encode_uint32(xdr, op_map->u.words[i]);
1742}
1743
Benny Halevy99fe60d2009-04-01 09:22:29 -04001744static void encode_exchange_id(struct xdr_stream *xdr,
1745 struct nfs41_exchange_id_args *args,
1746 struct compound_hdr *hdr)
1747{
1748 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001749 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001750 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001751
Trond Myklebust70019512012-03-04 20:49:32 -05001752 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001753 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001754
Jeff Layton3a6bb732015-06-09 19:43:57 -04001755 encode_string(xdr, strlen(args->client->cl_owner_id),
1756 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001757
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001758 encode_uint32(xdr, args->flags);
1759 encode_uint32(xdr, args->state_protect.how);
1760
1761 switch (args->state_protect.how) {
1762 case SP4_NONE:
1763 break;
1764 case SP4_MACH_CRED:
1765 encode_op_map(xdr, &args->state_protect.enforce);
1766 encode_op_map(xdr, &args->state_protect.allow);
1767 break;
1768 default:
1769 WARN_ON_ONCE(1);
1770 break;
1771 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001772
1773 if (send_implementation_id &&
1774 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1775 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001776 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001777 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1778 utsname()->sysname, utsname()->release,
1779 utsname()->version, utsname()->machine);
1780
1781 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001782 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001783
1784 encode_string(xdr,
1785 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1786 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1787 encode_string(xdr, len, impl_name);
1788 /* just send zeros for nii_date - the date is in nii_name */
1789 p = reserve_space(xdr, 12);
1790 p = xdr_encode_hyper(p, 0);
1791 *p = cpu_to_be32(0);
1792 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001793 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001794}
Andy Adamsonfc931582009-04-01 09:22:31 -04001795
1796static void encode_create_session(struct xdr_stream *xdr,
1797 struct nfs41_create_session_args *args,
1798 struct compound_hdr *hdr)
1799{
1800 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001801 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001802 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001803 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001804 u32 max_resp_sz_cached;
1805
1806 /*
1807 * Assumes OPEN is the biggest non-idempotent compound.
1808 * 2 is the verifier.
1809 */
1810 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1811 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001812
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001813 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001814 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001815 p = xdr_encode_hyper(p, args->clientid);
1816 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001817 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001818
Andy Adamsonfc931582009-04-01 09:22:31 -04001819 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001820 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001821 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1822 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001823 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001824 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1825 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1826 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001827
1828 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001829 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001830 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1831 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1832 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1833 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1834 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1835 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001836
Benny Halevye75bc1c2009-08-14 17:18:54 +03001837 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001838 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001839 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001840
1841 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001842 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001843 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001844 *p++ = cpu_to_be32(0); /* UID */
1845 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001846 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001847}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001848
1849static void encode_destroy_session(struct xdr_stream *xdr,
1850 struct nfs4_session *session,
1851 struct compound_hdr *hdr)
1852{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001853 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1854 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001855}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001856
Trond Myklebust66245532012-05-25 17:18:09 -04001857static void encode_destroy_clientid(struct xdr_stream *xdr,
1858 uint64_t clientid,
1859 struct compound_hdr *hdr)
1860{
1861 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1862 encode_uint64(xdr, clientid);
1863}
1864
Ricardo Labiaga180197532009-12-05 16:08:40 -05001865static void encode_reclaim_complete(struct xdr_stream *xdr,
1866 struct nfs41_reclaim_complete_args *args,
1867 struct compound_hdr *hdr)
1868{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001869 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1870 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001871}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001872#endif /* CONFIG_NFS_V4_1 */
1873
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001874static void encode_sequence(struct xdr_stream *xdr,
1875 const struct nfs4_sequence_args *args,
1876 struct compound_hdr *hdr)
1877{
1878#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001879 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001880 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001881 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001882 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001883
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001884 tp = slot->table;
1885 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001886 if (!session)
1887 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001888
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001889 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001890
1891 /*
1892 * Sessionid + seqid + slotid + max slotid + cache_this
1893 */
1894 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1895 "max_slotid=%d cache_this=%d\n",
1896 __func__,
1897 ((u32 *)session->sess_id.data)[0],
1898 ((u32 *)session->sess_id.data)[1],
1899 ((u32 *)session->sess_id.data)[2],
1900 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001901 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001902 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001903 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001904 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001905 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001906 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001907 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001908 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001909#endif /* CONFIG_NFS_V4_1 */
1910}
1911
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001912#ifdef CONFIG_NFS_V4_1
1913static void
1914encode_getdeviceinfo(struct xdr_stream *xdr,
1915 const struct nfs4_getdeviceinfo_args *args,
1916 struct compound_hdr *hdr)
1917{
1918 __be32 *p;
1919
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001920 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001921 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001922 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1923 NFS4_DEVICEID4_SIZE);
1924 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001925 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001926
1927 p = reserve_space(xdr, 4 + 4);
1928 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001929 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001930}
1931
1932static void
1933encode_layoutget(struct xdr_stream *xdr,
1934 const struct nfs4_layoutget_args *args,
1935 struct compound_hdr *hdr)
1936{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001937 __be32 *p;
1938
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001939 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1940 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001941 *p++ = cpu_to_be32(0); /* Signal layout available */
1942 *p++ = cpu_to_be32(args->type);
1943 *p++ = cpu_to_be32(args->range.iomode);
1944 p = xdr_encode_hyper(p, args->range.offset);
1945 p = xdr_encode_hyper(p, args->range.length);
1946 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001947 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001948 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001949
1950 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1951 __func__,
1952 args->type,
1953 args->range.iomode,
1954 (unsigned long)args->range.offset,
1955 (unsigned long)args->range.length,
1956 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001957}
Andy Adamson863a3c62011-03-23 13:27:54 +00001958
1959static int
1960encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001961 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001962 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001963 struct compound_hdr *hdr)
1964{
1965 __be32 *p;
1966
1967 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1968 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1969
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001970 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1971 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001972 /* Only whole file layouts */
1973 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001974 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001975 *p = cpu_to_be32(0); /* reclaim */
1976 encode_nfs4_stateid(xdr, &args->stateid);
1977 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001978 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1979 p = xdr_encode_hyper(p, args->lastbytewritten);
1980 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1981 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001982
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001983 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03001984 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1985 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001986 } else {
1987 encode_uint32(xdr, args->layoutupdate_len);
1988 if (args->layoutupdate_pages) {
1989 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
1990 args->layoutupdate_len);
1991 }
1992 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001993
Andy Adamson863a3c62011-03-23 13:27:54 +00001994 return 0;
1995}
Benny Halevycbe82602011-05-22 19:52:37 +03001996
1997static void
1998encode_layoutreturn(struct xdr_stream *xdr,
1999 const struct nfs4_layoutreturn_args *args,
2000 struct compound_hdr *hdr)
2001{
2002 __be32 *p;
2003
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002004 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2005 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002006 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2007 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002008 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002009 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002010 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002011 p = xdr_encode_hyper(p, args->range.offset);
2012 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002013 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002014 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002015 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002016 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2017 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2018 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002019 } else
2020 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002021}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002022
2023static int
2024encode_secinfo_no_name(struct xdr_stream *xdr,
2025 const struct nfs41_secinfo_no_name_args *args,
2026 struct compound_hdr *hdr)
2027{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002028 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2029 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002030 return 0;
2031}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002032
2033static void encode_test_stateid(struct xdr_stream *xdr,
2034 struct nfs41_test_stateid_args *args,
2035 struct compound_hdr *hdr)
2036{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002037 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2038 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002039 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002040}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002041
2042static void encode_free_stateid(struct xdr_stream *xdr,
2043 struct nfs41_free_stateid_args *args,
2044 struct compound_hdr *hdr)
2045{
Trond Myklebustab19b482012-03-04 18:13:57 -05002046 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002047 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002048}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002049#endif /* CONFIG_NFS_V4_1 */
2050
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051/*
2052 * END OF "GENERIC" ENCODE ROUTINES.
2053 */
2054
Benny Halevy66cc0422009-04-01 09:22:10 -04002055static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2056{
2057#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002058 struct nfs4_session *session = args->sa_slot->table->session;
2059 if (session)
2060 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002061#endif /* CONFIG_NFS_V4_1 */
2062 return 0;
2063}
2064
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065/*
2066 * Encode an ACCESS request
2067 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002068static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2069 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002072 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Chuck Lever9f06c712010-12-14 14:59:18 +00002075 encode_compound_hdr(xdr, req, &hdr);
2076 encode_sequence(xdr, &args->seq_args, &hdr);
2077 encode_putfh(xdr, args->fh, &hdr);
2078 encode_access(xdr, args->access, &hdr);
2079 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002080 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081}
2082
2083/*
2084 * Encode LOOKUP request
2085 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002086static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2087 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002090 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
Chuck Lever9f06c712010-12-14 14:59:18 +00002093 encode_compound_hdr(xdr, req, &hdr);
2094 encode_sequence(xdr, &args->seq_args, &hdr);
2095 encode_putfh(xdr, args->dir_fh, &hdr);
2096 encode_lookup(xdr, args->name, &hdr);
2097 encode_getfh(xdr, &hdr);
2098 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002099 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100}
2101
2102/*
2103 * Encode LOOKUP_ROOT request
2104 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002105static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2106 struct xdr_stream *xdr,
2107 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002110 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
Chuck Lever9f06c712010-12-14 14:59:18 +00002113 encode_compound_hdr(xdr, req, &hdr);
2114 encode_sequence(xdr, &args->seq_args, &hdr);
2115 encode_putrootfh(xdr, &hdr);
2116 encode_getfh(xdr, &hdr);
2117 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002118 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119}
2120
2121/*
2122 * Encode REMOVE request
2123 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002124static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2125 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002128 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
Chuck Lever9f06c712010-12-14 14:59:18 +00002131 encode_compound_hdr(xdr, req, &hdr);
2132 encode_sequence(xdr, &args->seq_args, &hdr);
2133 encode_putfh(xdr, args->fh, &hdr);
2134 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002135 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136}
2137
2138/*
2139 * Encode RENAME request
2140 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002141static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2142 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002145 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
Chuck Lever9f06c712010-12-14 14:59:18 +00002148 encode_compound_hdr(xdr, req, &hdr);
2149 encode_sequence(xdr, &args->seq_args, &hdr);
2150 encode_putfh(xdr, args->old_dir, &hdr);
2151 encode_savefh(xdr, &hdr);
2152 encode_putfh(xdr, args->new_dir, &hdr);
2153 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002154 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155}
2156
2157/*
2158 * Encode LINK request
2159 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002160static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2161 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002164 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
Chuck Lever9f06c712010-12-14 14:59:18 +00002167 encode_compound_hdr(xdr, req, &hdr);
2168 encode_sequence(xdr, &args->seq_args, &hdr);
2169 encode_putfh(xdr, args->fh, &hdr);
2170 encode_savefh(xdr, &hdr);
2171 encode_putfh(xdr, args->dir_fh, &hdr);
2172 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002173 encode_restorefh(xdr, &hdr);
2174 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002175 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176}
2177
2178/*
2179 * Encode CREATE request
2180 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002181static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2182 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002185 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
Chuck Lever9f06c712010-12-14 14:59:18 +00002188 encode_compound_hdr(xdr, req, &hdr);
2189 encode_sequence(xdr, &args->seq_args, &hdr);
2190 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002191 encode_create(xdr, args, &hdr);
2192 encode_getfh(xdr, &hdr);
2193 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002194 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195}
2196
2197/*
2198 * Encode SYMLINK request
2199 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002200static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2201 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202{
Chuck Lever9f06c712010-12-14 14:59:18 +00002203 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204}
2205
2206/*
2207 * Encode GETATTR request
2208 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002209static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2210 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002213 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
Chuck Lever9f06c712010-12-14 14:59:18 +00002216 encode_compound_hdr(xdr, req, &hdr);
2217 encode_sequence(xdr, &args->seq_args, &hdr);
2218 encode_putfh(xdr, args->fh, &hdr);
2219 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002220 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221}
2222
2223/*
2224 * Encode a CLOSE request
2225 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002226static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2227 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228{
Andy Adamson05d564f2008-12-23 16:06:15 -05002229 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002230 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002231 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
Chuck Lever9f06c712010-12-14 14:59:18 +00002233 encode_compound_hdr(xdr, req, &hdr);
2234 encode_sequence(xdr, &args->seq_args, &hdr);
2235 encode_putfh(xdr, args->fh, &hdr);
2236 encode_close(xdr, args, &hdr);
2237 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002238 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239}
2240
2241/*
2242 * Encode an OPEN request
2243 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002244static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2245 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002248 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
Chuck Lever9f06c712010-12-14 14:59:18 +00002251 encode_compound_hdr(xdr, req, &hdr);
2252 encode_sequence(xdr, &args->seq_args, &hdr);
2253 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002254 encode_open(xdr, args, &hdr);
2255 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002256 if (args->access)
2257 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002258 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002259 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260}
2261
2262/*
2263 * Encode an OPEN_CONFIRM request
2264 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002265static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2266 struct xdr_stream *xdr,
2267 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002270 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
Chuck Lever9f06c712010-12-14 14:59:18 +00002273 encode_compound_hdr(xdr, req, &hdr);
2274 encode_putfh(xdr, args->fh, &hdr);
2275 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002276 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277}
2278
2279/*
2280 * Encode an OPEN request with no attributes.
2281 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002282static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2283 struct xdr_stream *xdr,
2284 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002287 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Chuck Lever9f06c712010-12-14 14:59:18 +00002290 encode_compound_hdr(xdr, req, &hdr);
2291 encode_sequence(xdr, &args->seq_args, &hdr);
2292 encode_putfh(xdr, args->fh, &hdr);
2293 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002294 if (args->access)
2295 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002296 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002297 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298}
2299
2300/*
2301 * Encode an OPEN_DOWNGRADE request
2302 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002303static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2304 struct xdr_stream *xdr,
2305 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002308 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Chuck Lever9f06c712010-12-14 14:59:18 +00002311 encode_compound_hdr(xdr, req, &hdr);
2312 encode_sequence(xdr, &args->seq_args, &hdr);
2313 encode_putfh(xdr, args->fh, &hdr);
2314 encode_open_downgrade(xdr, args, &hdr);
2315 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002316 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317}
2318
2319/*
2320 * Encode a LOCK request
2321 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002322static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2323 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002326 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
Chuck Lever9f06c712010-12-14 14:59:18 +00002329 encode_compound_hdr(xdr, req, &hdr);
2330 encode_sequence(xdr, &args->seq_args, &hdr);
2331 encode_putfh(xdr, args->fh, &hdr);
2332 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002333 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334}
2335
2336/*
2337 * Encode a LOCKT request
2338 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002339static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2340 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002343 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
Chuck Lever9f06c712010-12-14 14:59:18 +00002346 encode_compound_hdr(xdr, req, &hdr);
2347 encode_sequence(xdr, &args->seq_args, &hdr);
2348 encode_putfh(xdr, args->fh, &hdr);
2349 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002350 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351}
2352
2353/*
2354 * Encode a LOCKU request
2355 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002356static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2357 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002360 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Chuck Lever9f06c712010-12-14 14:59:18 +00002363 encode_compound_hdr(xdr, req, &hdr);
2364 encode_sequence(xdr, &args->seq_args, &hdr);
2365 encode_putfh(xdr, args->fh, &hdr);
2366 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002367 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368}
2369
Chuck Lever9f06c712010-12-14 14:59:18 +00002370static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2371 struct xdr_stream *xdr,
2372 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002373{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002374 struct compound_hdr hdr = {
2375 .minorversion = 0,
2376 };
2377
Chuck Lever9f06c712010-12-14 14:59:18 +00002378 encode_compound_hdr(xdr, req, &hdr);
2379 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002380 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002381}
2382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383/*
2384 * Encode a READLINK request
2385 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002386static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2387 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002390 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
Chuck Lever9f06c712010-12-14 14:59:18 +00002393 encode_compound_hdr(xdr, req, &hdr);
2394 encode_sequence(xdr, &args->seq_args, &hdr);
2395 encode_putfh(xdr, args->fh, &hdr);
2396 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002397
Benny Halevy28f56692009-04-01 09:22:09 -04002398 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002399 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002400 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401}
2402
2403/*
2404 * Encode a READDIR request
2405 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002406static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2407 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002410 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412
Chuck Lever9f06c712010-12-14 14:59:18 +00002413 encode_compound_hdr(xdr, req, &hdr);
2414 encode_sequence(xdr, &args->seq_args, &hdr);
2415 encode_putfh(xdr, args->fh, &hdr);
2416 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002417
Benny Halevy28f56692009-04-01 09:22:09 -04002418 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002419 args->pgbase, args->count);
2420 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002421 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002422 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002423 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424}
2425
2426/*
2427 * Encode a READ request
2428 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002429static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002430 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002433 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
Chuck Lever9f06c712010-12-14 14:59:18 +00002436 encode_compound_hdr(xdr, req, &hdr);
2437 encode_sequence(xdr, &args->seq_args, &hdr);
2438 encode_putfh(xdr, args->fh, &hdr);
2439 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
Benny Halevy28f56692009-04-01 09:22:09 -04002441 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002443 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002444 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445}
2446
2447/*
2448 * Encode an SETATTR request
2449 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002450static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2451 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452{
Andy Adamson05d564f2008-12-23 16:06:15 -05002453 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002454 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002455 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Chuck Lever9f06c712010-12-14 14:59:18 +00002457 encode_compound_hdr(xdr, req, &hdr);
2458 encode_sequence(xdr, &args->seq_args, &hdr);
2459 encode_putfh(xdr, args->fh, &hdr);
2460 encode_setattr(xdr, args, args->server, &hdr);
2461 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002462 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463}
2464
2465/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002466 * Encode a GETACL request
2467 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002468static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2469 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002470{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002471 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002472 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002473 };
Benny Halevy28f56692009-04-01 09:22:09 -04002474 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002475
Chuck Lever9f06c712010-12-14 14:59:18 +00002476 encode_compound_hdr(xdr, req, &hdr);
2477 encode_sequence(xdr, &args->seq_args, &hdr);
2478 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002479 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002480 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002481
Benny Halevy28f56692009-04-01 09:22:09 -04002482 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002483 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002484
Andy Adamsond0179312008-12-23 16:06:17 -05002485 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002486}
2487
2488/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 * Encode a WRITE request
2490 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002491static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002492 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
Chuck Lever9f06c712010-12-14 14:59:18 +00002498 encode_compound_hdr(xdr, req, &hdr);
2499 encode_sequence(xdr, &args->seq_args, &hdr);
2500 encode_putfh(xdr, args->fh, &hdr);
2501 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002502 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002503 if (args->bitmask)
2504 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002505 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506}
2507
2508/*
2509 * a COMMIT request
2510 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002511static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002512 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002515 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
Chuck Lever9f06c712010-12-14 14:59:18 +00002518 encode_compound_hdr(xdr, req, &hdr);
2519 encode_sequence(xdr, &args->seq_args, &hdr);
2520 encode_putfh(xdr, args->fh, &hdr);
2521 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002522 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523}
2524
2525/*
2526 * FSINFO request
2527 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002528static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2529 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002532 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
Chuck Lever9f06c712010-12-14 14:59:18 +00002535 encode_compound_hdr(xdr, req, &hdr);
2536 encode_sequence(xdr, &args->seq_args, &hdr);
2537 encode_putfh(xdr, args->fh, &hdr);
2538 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002539 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540}
2541
2542/*
2543 * a PATHCONF request
2544 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002545static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2546 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002549 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551
Chuck Lever9f06c712010-12-14 14:59:18 +00002552 encode_compound_hdr(xdr, req, &hdr);
2553 encode_sequence(xdr, &args->seq_args, &hdr);
2554 encode_putfh(xdr, args->fh, &hdr);
2555 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002556 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002557 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558}
2559
2560/*
2561 * a STATFS request
2562 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002563static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2564 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002567 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
Chuck Lever9f06c712010-12-14 14:59:18 +00002570 encode_compound_hdr(xdr, req, &hdr);
2571 encode_sequence(xdr, &args->seq_args, &hdr);
2572 encode_putfh(xdr, args->fh, &hdr);
2573 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002574 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002575 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576}
2577
2578/*
2579 * GETATTR_BITMAP request
2580 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002581static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2582 struct xdr_stream *xdr,
2583 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584{
Kinglong Mee8c612822015-08-26 21:12:58 +08002585 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002587 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589
Chuck Lever9f06c712010-12-14 14:59:18 +00002590 encode_compound_hdr(xdr, req, &hdr);
2591 encode_sequence(xdr, &args->seq_args, &hdr);
2592 encode_putfh(xdr, args->fhandle, &hdr);
Kinglong Mee8c612822015-08-26 21:12:58 +08002593 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002594 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595}
2596
2597/*
2598 * a RENEW request
2599 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002600static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2601 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002604 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 };
2606
Chuck Lever9f06c712010-12-14 14:59:18 +00002607 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002608 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002609 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610}
2611
2612/*
2613 * a SETCLIENTID request
2614 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002615static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2616 struct xdr_stream *xdr,
2617 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002620 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 };
2622
Chuck Lever9f06c712010-12-14 14:59:18 +00002623 encode_compound_hdr(xdr, req, &hdr);
2624 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002625 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626}
2627
2628/*
2629 * a SETCLIENTID_CONFIRM request
2630 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002631static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2632 struct xdr_stream *xdr,
2633 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002636 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638
Chuck Lever9f06c712010-12-14 14:59:18 +00002639 encode_compound_hdr(xdr, req, &hdr);
2640 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002641 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642}
2643
2644/*
2645 * DELEGRETURN request
2646 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002647static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2648 struct xdr_stream *xdr,
2649 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002652 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
Chuck Lever9f06c712010-12-14 14:59:18 +00002655 encode_compound_hdr(xdr, req, &hdr);
2656 encode_sequence(xdr, &args->seq_args, &hdr);
2657 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002658 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002659 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002660 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661}
2662
2663/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002664 * Encode FS_LOCATIONS request
2665 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002666static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2667 struct xdr_stream *xdr,
2668 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002669{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002670 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002671 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002672 };
Benny Halevy28f56692009-04-01 09:22:09 -04002673 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002674
Chuck Lever9f06c712010-12-14 14:59:18 +00002675 encode_compound_hdr(xdr, req, &hdr);
2676 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002677 if (args->migration) {
2678 encode_putfh(xdr, args->fh, &hdr);
2679 replen = hdr.replen;
2680 encode_fs_locations(xdr, args->bitmask, &hdr);
2681 if (args->renew)
2682 encode_renew(xdr, args->clientid, &hdr);
2683 } else {
2684 encode_putfh(xdr, args->dir_fh, &hdr);
2685 encode_lookup(xdr, args->name, &hdr);
2686 replen = hdr.replen;
2687 encode_fs_locations(xdr, args->bitmask, &hdr);
2688 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002689
Chuck Leverb03d7352013-10-17 14:12:50 -04002690 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002691 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002692 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002693 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002694}
2695
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002696/*
2697 * Encode SECINFO request
2698 */
2699static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2700 struct xdr_stream *xdr,
2701 struct nfs4_secinfo_arg *args)
2702{
2703 struct compound_hdr hdr = {
2704 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2705 };
2706
2707 encode_compound_hdr(xdr, req, &hdr);
2708 encode_sequence(xdr, &args->seq_args, &hdr);
2709 encode_putfh(xdr, args->dir_fh, &hdr);
2710 encode_secinfo(xdr, args->name, &hdr);
2711 encode_nops(&hdr);
2712}
2713
Chuck Lever44c99932013-10-17 14:13:30 -04002714/*
2715 * Encode FSID_PRESENT request
2716 */
2717static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2718 struct xdr_stream *xdr,
2719 struct nfs4_fsid_present_arg *args)
2720{
2721 struct compound_hdr hdr = {
2722 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2723 };
2724
2725 encode_compound_hdr(xdr, req, &hdr);
2726 encode_sequence(xdr, &args->seq_args, &hdr);
2727 encode_putfh(xdr, args->fh, &hdr);
2728 encode_getfh(xdr, &hdr);
2729 if (args->renew)
2730 encode_renew(xdr, args->clientid, &hdr);
2731 encode_nops(&hdr);
2732}
2733
Benny Halevy99fe60d2009-04-01 09:22:29 -04002734#if defined(CONFIG_NFS_V4_1)
2735/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002736 * BIND_CONN_TO_SESSION request
2737 */
2738static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2739 struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08002740 struct nfs41_bind_conn_to_session_args *args)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002741{
2742 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002743 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002744 };
2745
2746 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002747 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002748 encode_nops(&hdr);
2749}
2750
2751/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002752 * EXCHANGE_ID request
2753 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002754static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2755 struct xdr_stream *xdr,
2756 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002757{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002758 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002759 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002760 };
2761
Chuck Lever9f06c712010-12-14 14:59:18 +00002762 encode_compound_hdr(xdr, req, &hdr);
2763 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002764 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002765}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002766
2767/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002768 * a CREATE_SESSION request
2769 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002770static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2771 struct xdr_stream *xdr,
2772 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002773{
Andy Adamsonfc931582009-04-01 09:22:31 -04002774 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002775 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002776 };
2777
Chuck Lever9f06c712010-12-14 14:59:18 +00002778 encode_compound_hdr(xdr, req, &hdr);
2779 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002780 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002781}
2782
2783/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002784 * a DESTROY_SESSION request
2785 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002786static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2787 struct xdr_stream *xdr,
2788 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002789{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002790 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002791 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002792 };
2793
Chuck Lever9f06c712010-12-14 14:59:18 +00002794 encode_compound_hdr(xdr, req, &hdr);
2795 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002796 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002797}
2798
2799/*
Trond Myklebust66245532012-05-25 17:18:09 -04002800 * a DESTROY_CLIENTID request
2801 */
2802static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2803 struct xdr_stream *xdr,
2804 struct nfs_client *clp)
2805{
2806 struct compound_hdr hdr = {
2807 .minorversion = clp->cl_mvops->minor_version,
2808 };
2809
2810 encode_compound_hdr(xdr, req, &hdr);
2811 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2812 encode_nops(&hdr);
2813}
2814
2815/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002816 * a SEQUENCE request
2817 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002818static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2819 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002820{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002821 struct compound_hdr hdr = {
2822 .minorversion = nfs4_xdr_minorversion(args),
2823 };
2824
Chuck Lever9f06c712010-12-14 14:59:18 +00002825 encode_compound_hdr(xdr, req, &hdr);
2826 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002827 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002828}
2829
2830/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002831 * a GET_LEASE_TIME request
2832 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002833static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2834 struct xdr_stream *xdr,
2835 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002836{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002837 struct compound_hdr hdr = {
2838 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2839 };
Fred Isamandae100c2011-07-30 20:52:37 -04002840 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002841
Chuck Lever9f06c712010-12-14 14:59:18 +00002842 encode_compound_hdr(xdr, req, &hdr);
2843 encode_sequence(xdr, &args->la_seq_args, &hdr);
2844 encode_putrootfh(xdr, &hdr);
2845 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002846 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002847}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002848
2849/*
2850 * a RECLAIM_COMPLETE request
2851 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002852static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2853 struct xdr_stream *xdr,
2854 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002855{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002856 struct compound_hdr hdr = {
2857 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2858 };
2859
Chuck Lever9f06c712010-12-14 14:59:18 +00002860 encode_compound_hdr(xdr, req, &hdr);
2861 encode_sequence(xdr, &args->seq_args, &hdr);
2862 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002863 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002864}
2865
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002866/*
2867 * Encode GETDEVICEINFO request
2868 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002869static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2870 struct xdr_stream *xdr,
2871 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002872{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002873 struct compound_hdr hdr = {
2874 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2875 };
2876
Chuck Lever9f06c712010-12-14 14:59:18 +00002877 encode_compound_hdr(xdr, req, &hdr);
2878 encode_sequence(xdr, &args->seq_args, &hdr);
2879 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002880
2881 /* set up reply kvec. Subtract notification bitmap max size (2)
2882 * so that notification bitmap is put in xdr_buf tail */
2883 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2884 args->pdev->pages, args->pdev->pgbase,
2885 args->pdev->pglen);
2886
2887 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002888}
2889
2890/*
2891 * Encode LAYOUTGET request
2892 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002893static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2894 struct xdr_stream *xdr,
2895 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002896{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002897 struct compound_hdr hdr = {
2898 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2899 };
2900
Chuck Lever9f06c712010-12-14 14:59:18 +00002901 encode_compound_hdr(xdr, req, &hdr);
2902 encode_sequence(xdr, &args->seq_args, &hdr);
2903 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2904 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002905
2906 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2907 args->layout.pages, 0, args->layout.pglen);
2908
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002909 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002910}
Andy Adamson863a3c62011-03-23 13:27:54 +00002911
2912/*
2913 * Encode LAYOUTCOMMIT request
2914 */
Benny Halevycbe82602011-05-22 19:52:37 +03002915static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2916 struct xdr_stream *xdr,
2917 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002918{
Benny Halevyac7db722011-05-22 19:53:48 +03002919 struct nfs4_layoutcommit_data *data =
2920 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002921 struct compound_hdr hdr = {
2922 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2923 };
2924
2925 encode_compound_hdr(xdr, req, &hdr);
2926 encode_sequence(xdr, &args->seq_args, &hdr);
2927 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002928 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002929 encode_getfattr(xdr, args->bitmask, &hdr);
2930 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002931}
2932
2933/*
2934 * Encode LAYOUTRETURN request
2935 */
2936static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2937 struct xdr_stream *xdr,
2938 struct nfs4_layoutreturn_args *args)
2939{
2940 struct compound_hdr hdr = {
2941 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2942 };
2943
2944 encode_compound_hdr(xdr, req, &hdr);
2945 encode_sequence(xdr, &args->seq_args, &hdr);
2946 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2947 encode_layoutreturn(xdr, args, &hdr);
2948 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002949}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002950
2951/*
2952 * Encode SECINFO_NO_NAME request
2953 */
2954static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2955 struct xdr_stream *xdr,
2956 struct nfs41_secinfo_no_name_args *args)
2957{
2958 struct compound_hdr hdr = {
2959 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2960 };
2961
2962 encode_compound_hdr(xdr, req, &hdr);
2963 encode_sequence(xdr, &args->seq_args, &hdr);
2964 encode_putrootfh(xdr, &hdr);
2965 encode_secinfo_no_name(xdr, args, &hdr);
2966 encode_nops(&hdr);
2967 return 0;
2968}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002969
2970/*
2971 * Encode TEST_STATEID request
2972 */
2973static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2974 struct xdr_stream *xdr,
2975 struct nfs41_test_stateid_args *args)
2976{
2977 struct compound_hdr hdr = {
2978 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2979 };
2980
2981 encode_compound_hdr(xdr, req, &hdr);
2982 encode_sequence(xdr, &args->seq_args, &hdr);
2983 encode_test_stateid(xdr, args, &hdr);
2984 encode_nops(&hdr);
2985}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002986
2987/*
2988 * Encode FREE_STATEID request
2989 */
2990static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2991 struct xdr_stream *xdr,
2992 struct nfs41_free_stateid_args *args)
2993{
2994 struct compound_hdr hdr = {
2995 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2996 };
2997
2998 encode_compound_hdr(xdr, req, &hdr);
2999 encode_sequence(xdr, &args->seq_args, &hdr);
3000 encode_free_stateid(xdr, args, &hdr);
3001 encode_nops(&hdr);
3002}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003003#endif /* CONFIG_NFS_V4_1 */
3004
Benny Halevy686841b2009-08-14 17:19:48 +03003005static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3006{
3007 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3008 "Remaining buffer length is %tu words.\n",
3009 func, xdr->end - xdr->p);
3010}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011
Trond Myklebust683b57b2006-06-09 09:34:22 -04003012static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013{
Al Viro8687b632006-10-19 23:28:48 -07003014 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
Benny Halevyc0eae662009-08-14 17:20:14 +03003016 p = xdr_inline_decode(xdr, 4);
3017 if (unlikely(!p))
3018 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003019 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003020 p = xdr_inline_decode(xdr, *len);
3021 if (unlikely(!p))
3022 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 *string = (char *)p;
3024 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003025out_overflow:
3026 print_overflow_msg(__func__, xdr);
3027 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028}
3029
3030static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3031{
Al Viro8687b632006-10-19 23:28:48 -07003032 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033
Benny Halevyc0eae662009-08-14 17:20:14 +03003034 p = xdr_inline_decode(xdr, 8);
3035 if (unlikely(!p))
3036 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003037 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003038 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003039
Benny Halevyc0eae662009-08-14 17:20:14 +03003040 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3041 if (unlikely(!p))
3042 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 hdr->tag = (char *)p;
3044 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003045 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003046 if (unlikely(hdr->nops < 1))
3047 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003049out_overflow:
3050 print_overflow_msg(__func__, xdr);
3051 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052}
3053
Trond Myklebustc7848f62013-12-04 17:39:23 -05003054static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3055 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056{
Al Viro8687b632006-10-19 23:28:48 -07003057 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 uint32_t opnum;
3059 int32_t nfserr;
3060
Benny Halevyc0eae662009-08-14 17:20:14 +03003061 p = xdr_inline_decode(xdr, 8);
3062 if (unlikely(!p))
3063 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003064 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003065 if (unlikely(opnum != expected))
3066 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003067 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003068 if (nfserr == NFS_OK)
3069 *nfs_retval = 0;
3070 else
3071 *nfs_retval = nfs4_stat_to_errno(nfserr);
3072 return true;
3073out_bad_operation:
3074 dprintk("nfs: Server returned operation"
3075 " %d but we issued a request for %d\n",
3076 opnum, expected);
3077 *nfs_retval = -EREMOTEIO;
3078 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003079out_overflow:
3080 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003081 *nfs_retval = -EIO;
3082 return false;
3083}
3084
3085static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3086{
3087 int retval;
3088
3089 __decode_op_hdr(xdr, expected, &retval);
3090 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091}
3092
3093/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003094static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095{
Al Viro8687b632006-10-19 23:28:48 -07003096 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003097 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 char *str;
3099
Benny Halevyc0eae662009-08-14 17:20:14 +03003100 p = xdr_inline_decode(xdr, 12);
3101 if (likely(p))
3102 return decode_opaque_inline(xdr, &strlen, &str);
3103 print_overflow_msg(__func__, xdr);
3104 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105}
3106
3107static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3108{
Al Viro8687b632006-10-19 23:28:48 -07003109 uint32_t bmlen;
3110 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111
Benny Halevyc0eae662009-08-14 17:20:14 +03003112 p = xdr_inline_decode(xdr, 4);
3113 if (unlikely(!p))
3114 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003115 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116
Fred Isamandae100c2011-07-30 20:52:37 -04003117 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003118 p = xdr_inline_decode(xdr, (bmlen << 2));
3119 if (unlikely(!p))
3120 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003122 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003123 if (bmlen > 1) {
3124 bitmap[1] = be32_to_cpup(p++);
3125 if (bmlen > 2)
3126 bitmap[2] = be32_to_cpup(p);
3127 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 }
3129 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003130out_overflow:
3131 print_overflow_msg(__func__, xdr);
3132 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133}
3134
Trond Myklebust256e48b2012-06-21 11:18:13 -04003135static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136{
Al Viro8687b632006-10-19 23:28:48 -07003137 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138
Benny Halevyc0eae662009-08-14 17:20:14 +03003139 p = xdr_inline_decode(xdr, 4);
3140 if (unlikely(!p))
3141 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003142 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003143 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003145out_overflow:
3146 print_overflow_msg(__func__, xdr);
3147 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148}
3149
3150static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3151{
3152 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003153 int ret;
3154 ret = decode_attr_bitmap(xdr, bitmask);
3155 if (unlikely(ret < 0))
3156 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3158 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003159 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3160 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3161 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 return 0;
3163}
3164
3165static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3166{
Al Viro8687b632006-10-19 23:28:48 -07003167 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003168 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
3170 *type = 0;
3171 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3172 return -EIO;
3173 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003174 p = xdr_inline_decode(xdr, 4);
3175 if (unlikely(!p))
3176 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003177 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003179 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 return -EIO;
3181 }
3182 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003183 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003185 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003186 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003187out_overflow:
3188 print_overflow_msg(__func__, xdr);
3189 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190}
3191
Chuck Lever264e6352012-03-01 17:02:05 -05003192static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3193 uint32_t *bitmap, uint32_t *type)
3194{
3195 __be32 *p;
3196
3197 *type = 0;
3198 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3199 return -EIO;
3200 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3201 p = xdr_inline_decode(xdr, 4);
3202 if (unlikely(!p))
3203 goto out_overflow;
3204 *type = be32_to_cpup(p);
3205 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3206 }
3207 dprintk("%s: expire type=0x%x\n", __func__, *type);
3208 return 0;
3209out_overflow:
3210 print_overflow_msg(__func__, xdr);
3211 return -EIO;
3212}
3213
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3215{
Al Viro8687b632006-10-19 23:28:48 -07003216 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003217 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218
3219 *change = 0;
3220 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3221 return -EIO;
3222 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003223 p = xdr_inline_decode(xdr, 8);
3224 if (unlikely(!p))
3225 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003226 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003228 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003230 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003232 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003233out_overflow:
3234 print_overflow_msg(__func__, xdr);
3235 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236}
3237
3238static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3239{
Al Viro8687b632006-10-19 23:28:48 -07003240 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003241 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242
3243 *size = 0;
3244 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3245 return -EIO;
3246 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003247 p = xdr_inline_decode(xdr, 8);
3248 if (unlikely(!p))
3249 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003250 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003252 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003254 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003255 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003256out_overflow:
3257 print_overflow_msg(__func__, xdr);
3258 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259}
3260
3261static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3262{
Al Viro8687b632006-10-19 23:28:48 -07003263 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264
3265 *res = 0;
3266 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3267 return -EIO;
3268 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003269 p = xdr_inline_decode(xdr, 4);
3270 if (unlikely(!p))
3271 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003272 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3274 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003275 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003277out_overflow:
3278 print_overflow_msg(__func__, xdr);
3279 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280}
3281
3282static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3283{
Al Viro8687b632006-10-19 23:28:48 -07003284 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
3286 *res = 0;
3287 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3288 return -EIO;
3289 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003290 p = xdr_inline_decode(xdr, 4);
3291 if (unlikely(!p))
3292 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003293 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3295 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003296 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003298out_overflow:
3299 print_overflow_msg(__func__, xdr);
3300 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301}
3302
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003303static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304{
Al Viro8687b632006-10-19 23:28:48 -07003305 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003306 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307
3308 fsid->major = 0;
3309 fsid->minor = 0;
3310 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3311 return -EIO;
3312 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003313 p = xdr_inline_decode(xdr, 16);
3314 if (unlikely(!p))
3315 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003316 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003317 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003319 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003321 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 (unsigned long long)fsid->major,
3323 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003324 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003325out_overflow:
3326 print_overflow_msg(__func__, xdr);
3327 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328}
3329
3330static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3331{
Al Viro8687b632006-10-19 23:28:48 -07003332 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333
3334 *res = 60;
3335 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3336 return -EIO;
3337 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003338 p = xdr_inline_decode(xdr, 4);
3339 if (unlikely(!p))
3340 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003341 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3343 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003344 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003346out_overflow:
3347 print_overflow_msg(__func__, xdr);
3348 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349}
3350
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003351static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003352{
3353 __be32 *p;
3354
3355 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3356 return -EIO;
3357 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3358 p = xdr_inline_decode(xdr, 4);
3359 if (unlikely(!p))
3360 goto out_overflow;
3361 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003362 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003363 }
3364 return 0;
3365out_overflow:
3366 print_overflow_msg(__func__, xdr);
3367 return -EIO;
3368}
3369
Kinglong Mee8c612822015-08-26 21:12:58 +08003370static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3371 uint32_t *bitmap, uint32_t *bitmask)
3372{
3373 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3374 int ret;
3375 ret = decode_attr_bitmap(xdr, bitmask);
3376 if (unlikely(ret < 0))
3377 return ret;
3378 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3379 } else
3380 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3381 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3382 bitmask[0], bitmask[1], bitmask[2]);
3383 return 0;
3384}
3385
Bryan Schumakerae42c702010-10-21 16:33:17 -04003386static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3387{
3388 __be32 *p;
3389 int len;
3390
Trond Myklebust7ad07352010-10-23 15:34:20 -04003391 if (fh != NULL)
3392 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003393
3394 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3395 return -EIO;
3396 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3397 p = xdr_inline_decode(xdr, 4);
3398 if (unlikely(!p))
3399 goto out_overflow;
3400 len = be32_to_cpup(p);
3401 if (len > NFS4_FHSIZE)
3402 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003403 p = xdr_inline_decode(xdr, len);
3404 if (unlikely(!p))
3405 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003406 if (fh != NULL) {
3407 memcpy(fh->data, p, len);
3408 fh->size = len;
3409 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003410 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3411 }
3412 return 0;
3413out_overflow:
3414 print_overflow_msg(__func__, xdr);
3415 return -EIO;
3416}
3417
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3419{
Al Viro8687b632006-10-19 23:28:48 -07003420 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003422 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3424 return -EIO;
3425 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003426 p = xdr_inline_decode(xdr, 4);
3427 if (unlikely(!p))
3428 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003429 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3431 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003432 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003434out_overflow:
3435 print_overflow_msg(__func__, xdr);
3436 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437}
3438
3439static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3440{
Al Viro8687b632006-10-19 23:28:48 -07003441 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003442 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443
3444 *fileid = 0;
3445 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3446 return -EIO;
3447 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003448 p = xdr_inline_decode(xdr, 8);
3449 if (unlikely(!p))
3450 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003451 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003453 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003455 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003456 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003457out_overflow:
3458 print_overflow_msg(__func__, xdr);
3459 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460}
3461
Manoj Naik99baf622006-06-09 09:34:24 -04003462static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3463{
Al Viro8687b632006-10-19 23:28:48 -07003464 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003465 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003466
3467 *fileid = 0;
3468 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3469 return -EIO;
3470 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003471 p = xdr_inline_decode(xdr, 8);
3472 if (unlikely(!p))
3473 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003474 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003475 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003476 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003477 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003478 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003479 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003480out_overflow:
3481 print_overflow_msg(__func__, xdr);
3482 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003483}
3484
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3486{
Al Viro8687b632006-10-19 23:28:48 -07003487 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 int status = 0;
3489
3490 *res = 0;
3491 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3492 return -EIO;
3493 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003494 p = xdr_inline_decode(xdr, 8);
3495 if (unlikely(!p))
3496 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003497 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3499 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003500 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003502out_overflow:
3503 print_overflow_msg(__func__, xdr);
3504 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505}
3506
3507static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3508{
Al Viro8687b632006-10-19 23:28:48 -07003509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 int status = 0;
3511
3512 *res = 0;
3513 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3514 return -EIO;
3515 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003516 p = xdr_inline_decode(xdr, 8);
3517 if (unlikely(!p))
3518 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003519 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3521 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003522 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003524out_overflow:
3525 print_overflow_msg(__func__, xdr);
3526 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527}
3528
3529static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3530{
Al Viro8687b632006-10-19 23:28:48 -07003531 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 int status = 0;
3533
3534 *res = 0;
3535 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3536 return -EIO;
3537 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003538 p = xdr_inline_decode(xdr, 8);
3539 if (unlikely(!p))
3540 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003541 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3543 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003544 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003546out_overflow:
3547 print_overflow_msg(__func__, xdr);
3548 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549}
3550
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003551static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3552{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003553 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003554 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003555 int status = 0;
3556
Benny Halevyc0eae662009-08-14 17:20:14 +03003557 p = xdr_inline_decode(xdr, 4);
3558 if (unlikely(!p))
3559 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003560 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003561 if (n == 0)
3562 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003563 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003564 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3565 dprintk("cannot parse %d components in path\n", n);
3566 goto out_eio;
3567 }
3568 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003569 struct nfs4_string *component = &path->components[path->ncomponents];
3570 status = decode_opaque_inline(xdr, &component->len, &component->data);
3571 if (unlikely(status != 0))
3572 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003573 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003574 pr_cont("%s%.*s ",
3575 (path->ncomponents != n ? "/ " : ""),
3576 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003577 }
3578out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003579 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003580root_path:
3581/* a root pathname is sent as a zero component4 */
3582 path->ncomponents = 1;
3583 path->components[0].len=0;
3584 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003585 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003586 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003587out_eio:
3588 dprintk(" status %d", status);
3589 status = -EIO;
3590 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003591out_overflow:
3592 print_overflow_msg(__func__, xdr);
3593 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003594}
3595
3596static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003597{
3598 int n;
Al Viro8687b632006-10-19 23:28:48 -07003599 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003600 int status = -EIO;
3601
3602 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3603 goto out;
3604 status = 0;
3605 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3606 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003607 status = -EIO;
3608 /* Ignore borken servers that return unrequested attrs */
3609 if (unlikely(res == NULL))
3610 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003611 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003612 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003613 if (unlikely(status != 0))
3614 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003615 p = xdr_inline_decode(xdr, 4);
3616 if (unlikely(!p))
3617 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003618 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003619 if (n <= 0)
3620 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003621 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003622 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003623 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003624
Trond Myklebust809b4262013-03-27 11:54:45 -04003625 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3626 break;
3627 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003628 p = xdr_inline_decode(xdr, 4);
3629 if (unlikely(!p))
3630 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003631 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003632
Chuck Lever02a29762012-03-01 17:00:31 -05003633 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003634 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3635 struct nfs4_string *server;
3636
3637 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003638 unsigned int i;
3639 dprintk("%s: using first %u of %u servers "
3640 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003641 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003642 NFS4_FS_LOCATION_MAXSERVERS,
3643 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003644 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003645 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003646 char *data;
3647 status = decode_opaque_inline(xdr, &len, &data);
3648 if (unlikely(status != 0))
3649 goto out_eio;
3650 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003651 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003652 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003653 server = &loc->servers[loc->nservers];
3654 status = decode_opaque_inline(xdr, &server->len, &server->data);
3655 if (unlikely(status != 0))
3656 goto out_eio;
3657 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003658 }
3659 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003660 if (unlikely(status != 0))
3661 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003662 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003663 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003664 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003665out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003666 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003667 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003668out_overflow:
3669 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003670out_eio:
3671 status = -EIO;
3672 goto out;
3673}
3674
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3676{
Al Viro8687b632006-10-19 23:28:48 -07003677 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 int status = 0;
3679
3680 *res = 0;
3681 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3682 return -EIO;
3683 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003684 p = xdr_inline_decode(xdr, 8);
3685 if (unlikely(!p))
3686 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003687 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3689 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003690 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003692out_overflow:
3693 print_overflow_msg(__func__, xdr);
3694 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695}
3696
3697static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3698{
Al Viro8687b632006-10-19 23:28:48 -07003699 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 int status = 0;
3701
3702 *maxlink = 1;
3703 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3704 return -EIO;
3705 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003706 p = xdr_inline_decode(xdr, 4);
3707 if (unlikely(!p))
3708 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003709 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3711 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003712 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003714out_overflow:
3715 print_overflow_msg(__func__, xdr);
3716 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717}
3718
3719static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3720{
Al Viro8687b632006-10-19 23:28:48 -07003721 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 int status = 0;
3723
3724 *maxname = 1024;
3725 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3726 return -EIO;
3727 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003728 p = xdr_inline_decode(xdr, 4);
3729 if (unlikely(!p))
3730 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003731 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3733 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003734 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003736out_overflow:
3737 print_overflow_msg(__func__, xdr);
3738 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739}
3740
3741static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3742{
Al Viro8687b632006-10-19 23:28:48 -07003743 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 int status = 0;
3745
3746 *res = 1024;
3747 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3748 return -EIO;
3749 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3750 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003751 p = xdr_inline_decode(xdr, 8);
3752 if (unlikely(!p))
3753 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003754 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 if (maxread > 0x7FFFFFFF)
3756 maxread = 0x7FFFFFFF;
3757 *res = (uint32_t)maxread;
3758 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3759 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003760 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003762out_overflow:
3763 print_overflow_msg(__func__, xdr);
3764 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765}
3766
3767static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3768{
Al Viro8687b632006-10-19 23:28:48 -07003769 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 int status = 0;
3771
3772 *res = 1024;
3773 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3774 return -EIO;
3775 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3776 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003777 p = xdr_inline_decode(xdr, 8);
3778 if (unlikely(!p))
3779 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003780 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 if (maxwrite > 0x7FFFFFFF)
3782 maxwrite = 0x7FFFFFFF;
3783 *res = (uint32_t)maxwrite;
3784 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3785 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003786 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003788out_overflow:
3789 print_overflow_msg(__func__, xdr);
3790 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791}
3792
Trond Myklebustbca79472009-03-11 14:10:26 -04003793static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794{
Trond Myklebustbca79472009-03-11 14:10:26 -04003795 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003796 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003797 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798
3799 *mode = 0;
3800 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3801 return -EIO;
3802 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003803 p = xdr_inline_decode(xdr, 4);
3804 if (unlikely(!p))
3805 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003806 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003807 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003809 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003811 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003812 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003813out_overflow:
3814 print_overflow_msg(__func__, xdr);
3815 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816}
3817
3818static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3819{
Al Viro8687b632006-10-19 23:28:48 -07003820 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003821 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822
3823 *nlink = 1;
3824 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3825 return -EIO;
3826 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003827 p = xdr_inline_decode(xdr, 4);
3828 if (unlikely(!p))
3829 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003830 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003832 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003834 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003835 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003836out_overflow:
3837 print_overflow_msg(__func__, xdr);
3838 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839}
3840
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003841static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003842 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003843 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844{
Al Viro8687b632006-10-19 23:28:48 -07003845 uint32_t len;
3846 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003847 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848
Eric W. Biedermane5782072013-02-01 14:22:02 -08003849 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3851 return -EIO;
3852 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003853 p = xdr_inline_decode(xdr, 4);
3854 if (unlikely(!p))
3855 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003856 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003857 p = xdr_inline_decode(xdr, len);
3858 if (unlikely(!p))
3859 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003860 if (owner_name != NULL) {
3861 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3862 if (owner_name->data != NULL) {
3863 owner_name->len = len;
3864 ret = NFS_ATTR_FATTR_OWNER_NAME;
3865 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003866 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003867 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003868 ret = NFS_ATTR_FATTR_OWNER;
3869 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003871 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003873 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003874 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3876 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003877 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003878 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003879out_overflow:
3880 print_overflow_msg(__func__, xdr);
3881 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882}
3883
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003884static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003885 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003886 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887{
Al Viro8687b632006-10-19 23:28:48 -07003888 uint32_t len;
3889 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003890 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891
Eric W. Biedermane5782072013-02-01 14:22:02 -08003892 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3894 return -EIO;
3895 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003896 p = xdr_inline_decode(xdr, 4);
3897 if (unlikely(!p))
3898 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003899 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003900 p = xdr_inline_decode(xdr, len);
3901 if (unlikely(!p))
3902 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003903 if (group_name != NULL) {
3904 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3905 if (group_name->data != NULL) {
3906 group_name->len = len;
3907 ret = NFS_ATTR_FATTR_GROUP_NAME;
3908 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003909 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003910 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003911 ret = NFS_ATTR_FATTR_GROUP;
3912 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003914 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003916 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003917 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3919 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003920 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003921 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003922out_overflow:
3923 print_overflow_msg(__func__, xdr);
3924 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925}
3926
3927static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3928{
Al Viro8687b632006-10-19 23:28:48 -07003929 uint32_t major = 0, minor = 0;
3930 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003931 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932
3933 *rdev = MKDEV(0,0);
3934 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3935 return -EIO;
3936 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3937 dev_t tmp;
3938
Benny Halevyc0eae662009-08-14 17:20:14 +03003939 p = xdr_inline_decode(xdr, 8);
3940 if (unlikely(!p))
3941 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003942 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003943 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 tmp = MKDEV(major, minor);
3945 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3946 *rdev = tmp;
3947 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003948 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003950 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003951 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003952out_overflow:
3953 print_overflow_msg(__func__, xdr);
3954 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955}
3956
3957static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3958{
Al Viro8687b632006-10-19 23:28:48 -07003959 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960 int status = 0;
3961
3962 *res = 0;
3963 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3964 return -EIO;
3965 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003966 p = xdr_inline_decode(xdr, 8);
3967 if (unlikely(!p))
3968 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003969 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3971 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003972 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003974out_overflow:
3975 print_overflow_msg(__func__, xdr);
3976 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977}
3978
3979static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3980{
Al Viro8687b632006-10-19 23:28:48 -07003981 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 int status = 0;
3983
3984 *res = 0;
3985 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3986 return -EIO;
3987 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003988 p = xdr_inline_decode(xdr, 8);
3989 if (unlikely(!p))
3990 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003991 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3993 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003994 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003996out_overflow:
3997 print_overflow_msg(__func__, xdr);
3998 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999}
4000
4001static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4002{
Al Viro8687b632006-10-19 23:28:48 -07004003 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 int status = 0;
4005
4006 *res = 0;
4007 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4008 return -EIO;
4009 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004010 p = xdr_inline_decode(xdr, 8);
4011 if (unlikely(!p))
4012 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004013 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4015 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004016 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004018out_overflow:
4019 print_overflow_msg(__func__, xdr);
4020 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021}
4022
4023static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4024{
Al Viro8687b632006-10-19 23:28:48 -07004025 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004026 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027
4028 *used = 0;
4029 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4030 return -EIO;
4031 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004032 p = xdr_inline_decode(xdr, 8);
4033 if (unlikely(!p))
4034 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004035 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004037 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004039 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004041 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004042out_overflow:
4043 print_overflow_msg(__func__, xdr);
4044 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045}
4046
4047static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4048{
Al Viro8687b632006-10-19 23:28:48 -07004049 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 uint64_t sec;
4051 uint32_t nsec;
4052
Benny Halevyc0eae662009-08-14 17:20:14 +03004053 p = xdr_inline_decode(xdr, 12);
4054 if (unlikely(!p))
4055 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004056 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004057 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 time->tv_sec = (time_t)sec;
4059 time->tv_nsec = (long)nsec;
4060 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004061out_overflow:
4062 print_overflow_msg(__func__, xdr);
4063 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064}
4065
4066static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4067{
4068 int status = 0;
4069
4070 time->tv_sec = 0;
4071 time->tv_nsec = 0;
4072 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4073 return -EIO;
4074 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4075 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004076 if (status == 0)
4077 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4079 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004080 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 return status;
4082}
4083
4084static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4085{
4086 int status = 0;
4087
4088 time->tv_sec = 0;
4089 time->tv_nsec = 0;
4090 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4091 return -EIO;
4092 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4093 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004094 if (status == 0)
4095 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4097 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004098 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 return status;
4100}
4101
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004102static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4103 struct timespec *time)
4104{
4105 int status = 0;
4106
4107 time->tv_sec = 0;
4108 time->tv_nsec = 0;
4109 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4110 return -EIO;
4111 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4112 status = decode_attr_time(xdr, time);
4113 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4114 }
4115 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4116 (long)time->tv_nsec);
4117 return status;
4118}
4119
David Quigleyaa9c2662013-05-22 12:50:44 -04004120static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4121 struct nfs4_label *label)
4122{
4123 uint32_t pi = 0;
4124 uint32_t lfs = 0;
4125 __u32 len;
4126 __be32 *p;
4127 int status = 0;
4128
4129 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4130 return -EIO;
4131 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4132 p = xdr_inline_decode(xdr, 4);
4133 if (unlikely(!p))
4134 goto out_overflow;
4135 lfs = be32_to_cpup(p++);
4136 p = xdr_inline_decode(xdr, 4);
4137 if (unlikely(!p))
4138 goto out_overflow;
4139 pi = be32_to_cpup(p++);
4140 p = xdr_inline_decode(xdr, 4);
4141 if (unlikely(!p))
4142 goto out_overflow;
4143 len = be32_to_cpup(p++);
4144 p = xdr_inline_decode(xdr, len);
4145 if (unlikely(!p))
4146 goto out_overflow;
4147 if (len < NFS4_MAXLABELLEN) {
4148 if (label) {
4149 memcpy(label->label, p, len);
4150 label->len = len;
4151 label->pi = pi;
4152 label->lfs = lfs;
4153 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4154 }
4155 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4156 } else
4157 printk(KERN_WARNING "%s: label too long (%u)!\n",
4158 __func__, len);
4159 }
4160 if (label && label->label)
4161 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4162 (char *)label->label, label->len, label->pi, label->lfs);
4163 return status;
4164
4165out_overflow:
4166 print_overflow_msg(__func__, xdr);
4167 return -EIO;
4168}
4169
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4171{
4172 int status = 0;
4173
4174 time->tv_sec = 0;
4175 time->tv_nsec = 0;
4176 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4177 return -EIO;
4178 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4179 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004180 if (status == 0)
4181 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4183 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004184 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 return status;
4186}
4187
Trond Myklebust256e48b2012-06-21 11:18:13 -04004188static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189{
4190 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004191 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192
4193 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004194 dprintk("%s: server returned incorrect attribute length: "
4195 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004196 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197 attrwords << 2,
4198 (attrwords < nwords) ? '<' : '>',
4199 nwords << 2);
4200 return -EIO;
4201 }
4202 return 0;
4203}
4204
4205static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4206{
Al Viro8687b632006-10-19 23:28:48 -07004207 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208
Benny Halevyc0eae662009-08-14 17:20:14 +03004209 p = xdr_inline_decode(xdr, 20);
4210 if (unlikely(!p))
4211 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004212 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004213 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004214 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004216out_overflow:
4217 print_overflow_msg(__func__, xdr);
4218 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219}
4220
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004221static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222{
Al Viro8687b632006-10-19 23:28:48 -07004223 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 uint32_t supp, acc;
4225 int status;
4226
4227 status = decode_op_hdr(xdr, OP_ACCESS);
4228 if (status)
4229 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004230 p = xdr_inline_decode(xdr, 8);
4231 if (unlikely(!p))
4232 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004233 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004234 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004235 *supported = supp;
4236 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004238out_overflow:
4239 print_overflow_msg(__func__, xdr);
4240 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241}
4242
Benny Halevy07d30432009-08-14 17:19:52 +03004243static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244{
Al Viro8687b632006-10-19 23:28:48 -07004245 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004246
4247 p = xdr_inline_decode(xdr, len);
4248 if (likely(p)) {
4249 memcpy(buf, p, len);
4250 return 0;
4251 }
4252 print_overflow_msg(__func__, xdr);
4253 return -EIO;
4254}
4255
4256static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4257{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004258 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259}
4260
4261static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4262{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 int status;
4264
4265 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004266 if (status != -EIO)
4267 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004268 if (!status)
4269 status = decode_stateid(xdr, &res->stateid);
4270 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271}
4272
Benny Halevydb942bb2009-08-14 17:19:56 +03004273static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4274{
Chuck Levercd937102012-03-02 17:14:31 -05004275 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276}
4277
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004278static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4279{
4280 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4281}
4282
Fred Isaman0b7c0152012-04-20 14:47:39 -04004283static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285 int status;
4286
4287 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004288 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004289 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004290 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291}
4292
4293static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4294{
Al Viro8687b632006-10-19 23:28:48 -07004295 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296 uint32_t bmlen;
4297 int status;
4298
4299 status = decode_op_hdr(xdr, OP_CREATE);
4300 if (status)
4301 return status;
4302 if ((status = decode_change_info(xdr, cinfo)))
4303 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004304 p = xdr_inline_decode(xdr, 4);
4305 if (unlikely(!p))
4306 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004307 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004308 p = xdr_inline_decode(xdr, bmlen << 2);
4309 if (likely(p))
4310 return 0;
4311out_overflow:
4312 print_overflow_msg(__func__, xdr);
4313 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314}
4315
4316static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4317{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004318 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004319 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320 int status;
4321
4322 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4323 goto xdr_error;
4324 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4325 goto xdr_error;
4326 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4327 goto xdr_error;
4328 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4329 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004330 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4331 &res->fh_expire_type)) != 0)
4332 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4334 goto xdr_error;
4335 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4336 goto xdr_error;
4337 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4338 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004339 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4340 res->exclcreat_bitmask)) != 0)
4341 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342 status = verify_attr_len(xdr, savep, attrlen);
4343xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004344 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 return status;
4346}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004347
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4349{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004350 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004351 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004353
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4355 goto xdr_error;
4356 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4357 goto xdr_error;
4358 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4359 goto xdr_error;
4360
4361 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4362 goto xdr_error;
4363 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4364 goto xdr_error;
4365 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4366 goto xdr_error;
4367 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4368 goto xdr_error;
4369 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4370 goto xdr_error;
4371 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4372 goto xdr_error;
4373
4374 status = verify_attr_len(xdr, savep, attrlen);
4375xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004376 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377 return status;
4378}
4379
4380static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4381{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004382 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004383 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004385
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4387 goto xdr_error;
4388 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4389 goto xdr_error;
4390 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4391 goto xdr_error;
4392
4393 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4394 goto xdr_error;
4395 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4396 goto xdr_error;
4397
4398 status = verify_attr_len(xdr, savep, attrlen);
4399xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004400 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 return status;
4402}
4403
Andy Adamson88034c32012-05-23 05:02:34 -04004404static int decode_threshold_hint(struct xdr_stream *xdr,
4405 uint32_t *bitmap,
4406 uint64_t *res,
4407 uint32_t hint_bit)
4408{
4409 __be32 *p;
4410
4411 *res = 0;
4412 if (likely(bitmap[0] & hint_bit)) {
4413 p = xdr_inline_decode(xdr, 8);
4414 if (unlikely(!p))
4415 goto out_overflow;
4416 xdr_decode_hyper(p, res);
4417 }
4418 return 0;
4419out_overflow:
4420 print_overflow_msg(__func__, xdr);
4421 return -EIO;
4422}
4423
4424static int decode_first_threshold_item4(struct xdr_stream *xdr,
4425 struct nfs4_threshold *res)
4426{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004427 __be32 *p;
4428 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004429 uint32_t bitmap[3] = {0,}, attrlen;
4430 int status;
4431
4432 /* layout type */
4433 p = xdr_inline_decode(xdr, 4);
4434 if (unlikely(!p)) {
4435 print_overflow_msg(__func__, xdr);
4436 return -EIO;
4437 }
4438 res->l_type = be32_to_cpup(p);
4439
4440 /* thi_hintset bitmap */
4441 status = decode_attr_bitmap(xdr, bitmap);
4442 if (status < 0)
4443 goto xdr_error;
4444
4445 /* thi_hintlist length */
4446 status = decode_attr_length(xdr, &attrlen, &savep);
4447 if (status < 0)
4448 goto xdr_error;
4449 /* thi_hintlist */
4450 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4451 if (status < 0)
4452 goto xdr_error;
4453 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4454 if (status < 0)
4455 goto xdr_error;
4456 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4457 THRESHOLD_RD_IO);
4458 if (status < 0)
4459 goto xdr_error;
4460 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4461 THRESHOLD_WR_IO);
4462 if (status < 0)
4463 goto xdr_error;
4464
4465 status = verify_attr_len(xdr, savep, attrlen);
4466 res->bm = bitmap[0];
4467
4468 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4469 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4470 res->wr_io_sz);
4471xdr_error:
4472 dprintk("%s ret=%d!\n", __func__, status);
4473 return status;
4474}
4475
4476/*
4477 * Thresholds on pNFS direct I/O vrs MDS I/O
4478 */
4479static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4480 uint32_t *bitmap,
4481 struct nfs4_threshold *res)
4482{
4483 __be32 *p;
4484 int status = 0;
4485 uint32_t num;
4486
4487 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4488 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004489 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004490 /* Did the server return an unrequested attribute? */
4491 if (unlikely(res == NULL))
4492 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004493 p = xdr_inline_decode(xdr, 4);
4494 if (unlikely(!p))
4495 goto out_overflow;
4496 num = be32_to_cpup(p);
4497 if (num == 0)
4498 return 0;
4499 if (num > 1)
4500 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4501 "drivers per filesystem not supported\n",
4502 __func__);
4503
4504 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004505 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004506 }
4507 return status;
4508out_overflow:
4509 print_overflow_msg(__func__, xdr);
4510 return -EIO;
4511}
4512
Bryan Schumakerae42c702010-10-21 16:33:17 -04004513static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4514 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004515 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004516 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517{
Trond Myklebustbca79472009-03-11 14:10:26 -04004518 int status;
4519 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004520 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004521 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004523 status = decode_attr_type(xdr, bitmap, &type);
4524 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004526 fattr->mode = 0;
4527 if (status != 0) {
4528 fattr->mode |= nfs_type2fmt[type];
4529 fattr->valid |= status;
4530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004532 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4533 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004535 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004536
4537 status = decode_attr_size(xdr, bitmap, &fattr->size);
4538 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004540 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004541
4542 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4543 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004545 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004546
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004547 err = 0;
4548 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004549 if (status < 0)
4550 goto xdr_error;
4551
4552 status = decode_attr_filehandle(xdr, bitmap, fh);
4553 if (status < 0)
4554 goto xdr_error;
4555
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004556 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
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 Myklebust8b7e3f42012-01-30 15:43:56 -05004561 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004562 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004563 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004564 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004565
4566 status = decode_attr_mode(xdr, bitmap, &fmode);
4567 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004569 if (status != 0) {
4570 fattr->mode |= fmode;
4571 fattr->valid |= status;
4572 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004573
4574 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4575 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004577 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004578
Trond Myklebust6926afd2012-01-07 13:22:46 -05004579 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004580 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004582 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004583
Trond Myklebust6926afd2012-01-07 13:22:46 -05004584 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004585 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004586 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004587 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004588
4589 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4590 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004592 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004593
4594 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4595 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004597 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004598
4599 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4600 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004602 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004603
4604 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4605 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004607 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004608
4609 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4610 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004612 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004613
Trond Myklebust28331a42011-04-27 13:47:52 -04004614 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004615 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004616 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004617 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004618
Andy Adamson88034c32012-05-23 05:02:34 -04004619 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4620 if (status < 0)
4621 goto xdr_error;
4622
David Quigleyaa9c2662013-05-22 12:50:44 -04004623 if (label) {
4624 status = decode_attr_security_label(xdr, bitmap, label);
4625 if (status < 0)
4626 goto xdr_error;
4627 fattr->valid |= status;
4628 }
4629
Bryan Schumakerae42c702010-10-21 16:33:17 -04004630xdr_error:
4631 dprintk("%s: xdr returned %d\n", __func__, -status);
4632 return status;
4633}
4634
4635static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004636 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004637 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004638{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004639 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004640 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004641 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004642 int status;
4643
4644 status = decode_op_hdr(xdr, OP_GETATTR);
4645 if (status < 0)
4646 goto xdr_error;
4647
4648 status = decode_attr_bitmap(xdr, bitmap);
4649 if (status < 0)
4650 goto xdr_error;
4651
4652 status = decode_attr_length(xdr, &attrlen, &savep);
4653 if (status < 0)
4654 goto xdr_error;
4655
David Quigleyaa9c2662013-05-22 12:50:44 -04004656 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4657 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004658 if (status < 0)
4659 goto xdr_error;
4660
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004661 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004663 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664 return status;
4665}
4666
David Quigleyaa9c2662013-05-22 12:50:44 -04004667static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4668 struct nfs4_label *label, const struct nfs_server *server)
4669{
4670 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4671}
4672
Bryan Schumakerae42c702010-10-21 16:33:17 -04004673static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004674 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004675{
David Quigleyaa9c2662013-05-22 12:50:44 -04004676 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004677}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678
Andy Adamson504913f2010-10-20 00:17:57 -04004679/*
4680 * Decode potentially multiple layout types. Currently we only support
4681 * one layout driver per file system.
4682 */
4683static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4684 uint32_t *layouttype)
4685{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004686 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004687 int num;
4688
4689 p = xdr_inline_decode(xdr, 4);
4690 if (unlikely(!p))
4691 goto out_overflow;
4692 num = be32_to_cpup(p);
4693
4694 /* pNFS is not supported by the underlying file system */
4695 if (num == 0) {
4696 *layouttype = 0;
4697 return 0;
4698 }
4699 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004700 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4701 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004702
4703 /* Decode and set first layout type, move xdr->p past unused types */
4704 p = xdr_inline_decode(xdr, num * 4);
4705 if (unlikely(!p))
4706 goto out_overflow;
4707 *layouttype = be32_to_cpup(p);
4708 return 0;
4709out_overflow:
4710 print_overflow_msg(__func__, xdr);
4711 return -EIO;
4712}
4713
4714/*
4715 * The type of file system exported.
4716 * Note we must ensure that layouttype is set in any non-error case.
4717 */
4718static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4719 uint32_t *layouttype)
4720{
4721 int status = 0;
4722
4723 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4724 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4725 return -EIO;
4726 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4727 status = decode_first_pnfs_layout_type(xdr, layouttype);
4728 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4729 } else
4730 *layouttype = 0;
4731 return status;
4732}
4733
Fred Isamandae100c2011-07-30 20:52:37 -04004734/*
4735 * The prefered block size for layout directed io
4736 */
4737static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4738 uint32_t *res)
4739{
4740 __be32 *p;
4741
4742 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4743 *res = 0;
4744 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4745 p = xdr_inline_decode(xdr, 4);
4746 if (unlikely(!p)) {
4747 print_overflow_msg(__func__, xdr);
4748 return -EIO;
4749 }
4750 *res = be32_to_cpup(p);
4751 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4752 }
4753 return 0;
4754}
4755
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4757{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004758 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004759 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 int status;
4761
4762 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4763 goto xdr_error;
4764 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4765 goto xdr_error;
4766 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4767 goto xdr_error;
4768
4769 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4770
4771 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4772 goto xdr_error;
4773 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4774 goto xdr_error;
4775 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4776 goto xdr_error;
4777 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4778 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4779 goto xdr_error;
4780 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004781 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4782 if (status != 0)
4783 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004784 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4785 if (status != 0)
4786 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004787 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4788 if (status)
4789 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790
4791 status = verify_attr_len(xdr, savep, attrlen);
4792xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004793 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 return status;
4795}
4796
4797static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4798{
Al Viro8687b632006-10-19 23:28:48 -07004799 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800 uint32_t len;
4801 int status;
4802
Trond Myklebust99367812007-07-17 21:52:41 -04004803 /* Zero handle first to allow comparisons */
4804 memset(fh, 0, sizeof(*fh));
4805
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806 status = decode_op_hdr(xdr, OP_GETFH);
4807 if (status)
4808 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809
Benny Halevyc0eae662009-08-14 17:20:14 +03004810 p = xdr_inline_decode(xdr, 4);
4811 if (unlikely(!p))
4812 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004813 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 if (len > NFS4_FHSIZE)
4815 return -EIO;
4816 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004817 p = xdr_inline_decode(xdr, len);
4818 if (unlikely(!p))
4819 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004820 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004822out_overflow:
4823 print_overflow_msg(__func__, xdr);
4824 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825}
4826
4827static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4828{
4829 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004830
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831 status = decode_op_hdr(xdr, OP_LINK);
4832 if (status)
4833 return status;
4834 return decode_change_info(xdr, cinfo);
4835}
4836
4837/*
4838 * We create the owner, so we know a proper owner.id length is 4.
4839 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004840static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004842 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004843 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004844 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004846 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004847 if (unlikely(!p))
4848 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004849 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004850 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004851 type = be32_to_cpup(p++); /* 4 byte read */
4852 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004853 fl->fl_start = (loff_t)offset;
4854 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4855 if (length == ~(uint64_t)0)
4856 fl->fl_end = OFFSET_MAX;
4857 fl->fl_type = F_WRLCK;
4858 if (type & 1)
4859 fl->fl_type = F_RDLCK;
4860 fl->fl_pid = 0;
4861 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004862 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4863 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4864 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004865 if (likely(p))
4866 return -NFS4ERR_DENIED;
4867out_overflow:
4868 print_overflow_msg(__func__, xdr);
4869 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870}
4871
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004872static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004874 int status;
4875
4876 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004877 if (status == -EIO)
4878 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004880 status = decode_stateid(xdr, &res->stateid);
4881 if (unlikely(status))
4882 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004884 status = decode_lock_denied(xdr, NULL);
4885 if (res->open_seqid != NULL)
4886 nfs_increment_open_seqid(status, res->open_seqid);
4887 nfs_increment_lock_seqid(status, res->lock_seqid);
4888out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 return status;
4890}
4891
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004892static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893{
4894 int status;
4895 status = decode_op_hdr(xdr, OP_LOCKT);
4896 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004897 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 return status;
4899}
4900
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004901static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903 int status;
4904
4905 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004906 if (status != -EIO)
4907 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004908 if (status == 0)
4909 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910 return status;
4911}
4912
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004913static int decode_release_lockowner(struct xdr_stream *xdr)
4914{
4915 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4916}
4917
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918static int decode_lookup(struct xdr_stream *xdr)
4919{
4920 return decode_op_hdr(xdr, OP_LOOKUP);
4921}
4922
4923/* This is too sick! */
4924static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4925{
Andy Adamson05d564f2008-12-23 16:06:15 -05004926 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004927 uint32_t limit_type, nblocks, blocksize;
4928
Benny Halevyc0eae662009-08-14 17:20:14 +03004929 p = xdr_inline_decode(xdr, 12);
4930 if (unlikely(!p))
4931 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004932 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004934 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004935 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004936 break;
4937 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004938 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004939 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004940 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004941 }
4942 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004943out_overflow:
4944 print_overflow_msg(__func__, xdr);
4945 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946}
4947
Trond Myklebust6ae37332015-01-30 14:21:14 -05004948static int decode_rw_delegation(struct xdr_stream *xdr,
4949 uint32_t delegation_type,
4950 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951{
Andy Adamson05d564f2008-12-23 16:06:15 -05004952 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004953 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954
Benny Halevy07d30432009-08-14 17:19:52 +03004955 status = decode_stateid(xdr, &res->delegation);
4956 if (unlikely(status))
4957 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004958 p = xdr_inline_decode(xdr, 4);
4959 if (unlikely(!p))
4960 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004961 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004962
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004964 case NFS4_OPEN_DELEGATE_READ:
4965 res->delegation_type = FMODE_READ;
4966 break;
4967 case NFS4_OPEN_DELEGATE_WRITE:
4968 res->delegation_type = FMODE_WRITE|FMODE_READ;
4969 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970 return -EIO;
4971 }
David Howells7539bba2006-08-22 20:06:09 -04004972 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004973out_overflow:
4974 print_overflow_msg(__func__, xdr);
4975 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976}
4977
Trond Myklebust6ae37332015-01-30 14:21:14 -05004978static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4979{
4980 __be32 *p;
4981 uint32_t why_no_delegation;
4982
4983 p = xdr_inline_decode(xdr, 4);
4984 if (unlikely(!p))
4985 goto out_overflow;
4986 why_no_delegation = be32_to_cpup(p);
4987 switch (why_no_delegation) {
4988 case WND4_CONTENTION:
4989 case WND4_RESOURCE:
4990 xdr_inline_decode(xdr, 4);
4991 /* Ignore for now */
4992 }
4993 return 0;
4994out_overflow:
4995 print_overflow_msg(__func__, xdr);
4996 return -EIO;
4997}
4998
4999static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5000{
5001 __be32 *p;
5002 uint32_t delegation_type;
5003
5004 p = xdr_inline_decode(xdr, 4);
5005 if (unlikely(!p))
5006 goto out_overflow;
5007 delegation_type = be32_to_cpup(p);
5008 res->delegation_type = 0;
5009 switch (delegation_type) {
5010 case NFS4_OPEN_DELEGATE_NONE:
5011 return 0;
5012 case NFS4_OPEN_DELEGATE_READ:
5013 case NFS4_OPEN_DELEGATE_WRITE:
5014 return decode_rw_delegation(xdr, delegation_type, res);
5015 case NFS4_OPEN_DELEGATE_NONE_EXT:
5016 return decode_no_delegation(xdr, res);
5017 }
5018 return -EIO;
5019out_overflow:
5020 print_overflow_msg(__func__, xdr);
5021 return -EIO;
5022}
5023
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5025{
Andy Adamson05d564f2008-12-23 16:06:15 -05005026 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005027 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005028 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029
Trond Myklebustc7848f62013-12-04 17:39:23 -05005030 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5031 return status;
5032 nfs_increment_open_seqid(status, res->seqid);
5033 if (status)
5034 return status;
5035 status = decode_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005036 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005037 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038
Andy Adamson05d564f2008-12-23 16:06:15 -05005039 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005040
Benny Halevyc0eae662009-08-14 17:20:14 +03005041 p = xdr_inline_decode(xdr, 8);
5042 if (unlikely(!p))
5043 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005044 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005045 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005046 if (bmlen > 10)
5047 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048
Benny Halevyc0eae662009-08-14 17:20:14 +03005049 p = xdr_inline_decode(xdr, bmlen << 2);
5050 if (unlikely(!p))
5051 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005052 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5053 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005054 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005055 for (; i < NFS4_BITMAP_SIZE; i++)
5056 res->attrset[i] = 0;
5057
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058 return decode_delegation(xdr, res);
5059xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005060 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005062out_overflow:
5063 print_overflow_msg(__func__, xdr);
5064 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065}
5066
5067static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5068{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 int status;
5070
Andy Adamson05d564f2008-12-23 16:06:15 -05005071 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005072 if (status != -EIO)
5073 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005074 if (!status)
5075 status = decode_stateid(xdr, &res->stateid);
5076 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077}
5078
5079static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5080{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081 int status;
5082
5083 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005084 if (status != -EIO)
5085 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005086 if (!status)
5087 status = decode_stateid(xdr, &res->stateid);
5088 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089}
5090
5091static int decode_putfh(struct xdr_stream *xdr)
5092{
5093 return decode_op_hdr(xdr, OP_PUTFH);
5094}
5095
5096static int decode_putrootfh(struct xdr_stream *xdr)
5097{
5098 return decode_op_hdr(xdr, OP_PUTROOTFH);
5099}
5100
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005101static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5102 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103{
Al Viro8687b632006-10-19 23:28:48 -07005104 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005105 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106 int status;
5107
5108 status = decode_op_hdr(xdr, OP_READ);
5109 if (status)
5110 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005111 p = xdr_inline_decode(xdr, 8);
5112 if (unlikely(!p))
5113 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005114 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005115 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005116 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005118 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119 "count %u > recvd %u\n", count, recvd);
5120 count = recvd;
5121 eof = 0;
5122 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123 res->eof = eof;
5124 res->count = count;
5125 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005126out_overflow:
5127 print_overflow_msg(__func__, xdr);
5128 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129}
5130
5131static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5132{
Chuck Leverbcecff72007-10-26 13:32:03 -04005133 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005134 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005135
5136 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005137 if (!status)
5138 status = decode_verifier(xdr, readdir->verifier.data);
5139 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005141 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005142 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005143 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005144 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145}
5146
5147static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5148{
5149 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005150 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005151 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152 int status;
5153
5154 status = decode_op_hdr(xdr, OP_READLINK);
5155 if (status)
5156 return status;
5157
5158 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005159 p = xdr_inline_decode(xdr, 4);
5160 if (unlikely(!p))
5161 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005162 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005164 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165 return -ENAMETOOLONG;
5166 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005167 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005169 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170 "count %u > recvd %u\n", len, recvd);
5171 return -EIO;
5172 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 /*
5174 * The XDR encode routine has set things up so that
5175 * the link text will be copied directly into the
5176 * buffer. We just have to do overflow-checking,
5177 * and and null-terminate the text (the VFS expects
5178 * null-termination).
5179 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005180 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005182out_overflow:
5183 print_overflow_msg(__func__, xdr);
5184 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185}
5186
5187static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5188{
5189 int status;
5190
5191 status = decode_op_hdr(xdr, OP_REMOVE);
5192 if (status)
5193 goto out;
5194 status = decode_change_info(xdr, cinfo);
5195out:
5196 return status;
5197}
5198
5199static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5200 struct nfs4_change_info *new_cinfo)
5201{
5202 int status;
5203
5204 status = decode_op_hdr(xdr, OP_RENAME);
5205 if (status)
5206 goto out;
5207 if ((status = decode_change_info(xdr, old_cinfo)))
5208 goto out;
5209 status = decode_change_info(xdr, new_cinfo);
5210out:
5211 return status;
5212}
5213
5214static int decode_renew(struct xdr_stream *xdr)
5215{
5216 return decode_op_hdr(xdr, OP_RENEW);
5217}
5218
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005219static int
5220decode_restorefh(struct xdr_stream *xdr)
5221{
5222 return decode_op_hdr(xdr, OP_RESTOREFH);
5223}
5224
J. Bruce Fields029d1052005-06-22 17:16:22 +00005225static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005226 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005227{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005228 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005229 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005230 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005231 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005232 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005233
Andy Adamsonbf118a32011-12-07 11:55:27 -05005234 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005235 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5236 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005237
Trond Myklebust519d3952012-08-14 17:30:10 -04005238 xdr_enter_page(xdr, xdr->buf->page_len);
5239
Trond Myklebustcff298c2012-08-14 17:14:17 -04005240 /* Calculate the offset of the page data */
5241 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005242
J. Bruce Fields029d1052005-06-22 17:16:22 +00005243 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5244 goto out;
5245 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5246 goto out;
5247
5248 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5249 return -EIO;
5250 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005251
Andy Adamsonbf118a32011-12-07 11:55:27 -05005252 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5253 * are stored with the acl data to handle the problem of
5254 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005255 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005256 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005257
5258 /* Check for receive buffer overflow */
5259 if (res->acl_len > (xdr->nwords << 2) ||
5260 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5261 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005262 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005263 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005264 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005265 } else
5266 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005267
5268out:
5269 return status;
5270}
5271
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272static int
5273decode_savefh(struct xdr_stream *xdr)
5274{
5275 return decode_op_hdr(xdr, OP_SAVEFH);
5276}
5277
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005278static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279{
Al Viro8687b632006-10-19 23:28:48 -07005280 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005281 uint32_t bmlen;
5282 int status;
5283
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284 status = decode_op_hdr(xdr, OP_SETATTR);
5285 if (status)
5286 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005287 p = xdr_inline_decode(xdr, 4);
5288 if (unlikely(!p))
5289 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005290 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005291 p = xdr_inline_decode(xdr, bmlen << 2);
5292 if (likely(p))
5293 return 0;
5294out_overflow:
5295 print_overflow_msg(__func__, xdr);
5296 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297}
5298
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005299static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300{
Al Viro8687b632006-10-19 23:28:48 -07005301 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302 uint32_t opnum;
5303 int32_t nfserr;
5304
Benny Halevyc0eae662009-08-14 17:20:14 +03005305 p = xdr_inline_decode(xdr, 8);
5306 if (unlikely(!p))
5307 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005308 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005310 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005311 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312 return -EIO;
5313 }
Benny Halevycccddf42009-08-14 17:20:19 +03005314 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005316 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5317 if (unlikely(!p))
5318 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005319 p = xdr_decode_hyper(p, &res->clientid);
5320 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321 } else if (nfserr == NFSERR_CLID_INUSE) {
5322 uint32_t len;
5323
5324 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005325 p = xdr_inline_decode(xdr, 4);
5326 if (unlikely(!p))
5327 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005328 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005329 p = xdr_inline_decode(xdr, len);
5330 if (unlikely(!p))
5331 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332
5333 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005334 p = xdr_inline_decode(xdr, 4);
5335 if (unlikely(!p))
5336 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005337 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005338 p = xdr_inline_decode(xdr, len);
5339 if (unlikely(!p))
5340 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005341 return -NFSERR_CLID_INUSE;
5342 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005343 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344
5345 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005346out_overflow:
5347 print_overflow_msg(__func__, xdr);
5348 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005349}
5350
5351static int decode_setclientid_confirm(struct xdr_stream *xdr)
5352{
5353 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5354}
5355
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005356static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005357{
Al Viro8687b632006-10-19 23:28:48 -07005358 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005359 int status;
5360
5361 status = decode_op_hdr(xdr, OP_WRITE);
5362 if (status)
5363 return status;
5364
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005365 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005366 if (unlikely(!p))
5367 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005368 res->count = be32_to_cpup(p++);
5369 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005370 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005371out_overflow:
5372 print_overflow_msg(__func__, xdr);
5373 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005374}
5375
5376static int decode_delegreturn(struct xdr_stream *xdr)
5377{
5378 return decode_op_hdr(xdr, OP_DELEGRETURN);
5379}
5380
Chuck Leverfb15b262013-03-16 15:54:34 -04005381static int decode_secinfo_gss(struct xdr_stream *xdr,
5382 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005383{
Chuck Leverfb15b262013-03-16 15:54:34 -04005384 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005385 __be32 *p;
5386
5387 p = xdr_inline_decode(xdr, 4);
5388 if (unlikely(!p))
5389 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005390 oid_len = be32_to_cpup(p);
5391 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005392 goto out_err;
5393
Chuck Leverfb15b262013-03-16 15:54:34 -04005394 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005395 if (unlikely(!p))
5396 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005397 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5398 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005399
5400 p = xdr_inline_decode(xdr, 8);
5401 if (unlikely(!p))
5402 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005403 flavor->flavor_info.qop = be32_to_cpup(p++);
5404 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005405
5406 return 0;
5407
5408out_overflow:
5409 print_overflow_msg(__func__, xdr);
5410 return -EIO;
5411out_err:
5412 return -EINVAL;
5413}
5414
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005415static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005416{
Chuck Leverfb15b262013-03-16 15:54:34 -04005417 struct nfs4_secinfo4 *sec_flavor;
5418 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005419 int status;
5420 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005421
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005422 p = xdr_inline_decode(xdr, 4);
5423 if (unlikely(!p))
5424 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005425
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005426 res->flavors->num_flavors = 0;
5427 num_flavors = be32_to_cpup(p);
5428
5429 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005430 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005431 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005432 break;
5433
5434 p = xdr_inline_decode(xdr, 4);
5435 if (unlikely(!p))
5436 goto out_overflow;
5437 sec_flavor->flavor = be32_to_cpup(p);
5438
5439 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005440 status = decode_secinfo_gss(xdr, sec_flavor);
5441 if (status)
5442 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005443 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005444 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005445 }
5446
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005447 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005448out:
5449 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005450out_overflow:
5451 print_overflow_msg(__func__, xdr);
5452 return -EIO;
5453}
5454
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005455static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5456{
5457 int status = decode_op_hdr(xdr, OP_SECINFO);
5458 if (status)
5459 return status;
5460 return decode_secinfo_common(xdr, res);
5461}
5462
Benny Halevy99fe60d2009-04-01 09:22:29 -04005463#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005464static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5465{
5466 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5467 if (status)
5468 return status;
5469 return decode_secinfo_common(xdr, res);
5470}
5471
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005472static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5473{
5474 __be32 *p;
5475 uint32_t bitmap_words;
5476 unsigned int i;
5477
5478 p = xdr_inline_decode(xdr, 4);
5479 bitmap_words = be32_to_cpup(p++);
5480 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5481 return -EIO;
5482 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5483 for (i = 0; i < bitmap_words; i++)
5484 op_map->u.words[i] = be32_to_cpup(p++);
5485
5486 return 0;
5487}
5488
Benny Halevy99fe60d2009-04-01 09:22:29 -04005489static int decode_exchange_id(struct xdr_stream *xdr,
5490 struct nfs41_exchange_id_res *res)
5491{
5492 __be32 *p;
5493 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005494 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005495 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005496 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005497
5498 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5499 if (status)
5500 return status;
5501
Benny Halevyc0eae662009-08-14 17:20:14 +03005502 p = xdr_inline_decode(xdr, 8);
5503 if (unlikely(!p))
5504 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005505 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005506 p = xdr_inline_decode(xdr, 12);
5507 if (unlikely(!p))
5508 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005509 res->seqid = be32_to_cpup(p++);
5510 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005511
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005512 res->state_protect.how = be32_to_cpup(p);
5513 switch (res->state_protect.how) {
5514 case SP4_NONE:
5515 break;
5516 case SP4_MACH_CRED:
5517 status = decode_op_map(xdr, &res->state_protect.enforce);
5518 if (status)
5519 return status;
5520 status = decode_op_map(xdr, &res->state_protect.allow);
5521 if (status)
5522 return status;
5523 break;
5524 default:
5525 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005526 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005527 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005528
Chuck Leveracdeb692012-05-21 22:46:16 -04005529 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005530 p = xdr_inline_decode(xdr, 8);
5531 if (unlikely(!p))
5532 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005533 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005534
Chuck Leveracdeb692012-05-21 22:46:16 -04005535 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005536 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5537 if (unlikely(status))
5538 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005539 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5540 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005541 memcpy(res->server_owner->major_id, dummy_str, dummy);
5542 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005543
Chuck Leveracdeb692012-05-21 22:46:16 -04005544 /* server_scope4 */
5545 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5546 if (unlikely(status))
5547 return status;
5548 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5549 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005550 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5551 res->server_scope->server_scope_sz = dummy;
5552
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005553 /* Implementation Id */
5554 p = xdr_inline_decode(xdr, 4);
5555 if (unlikely(!p))
5556 goto out_overflow;
5557 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005558
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005559 if (impl_id_count) {
5560 /* nii_domain */
5561 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5562 if (unlikely(status))
5563 return status;
5564 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5565 return -EIO;
5566 memcpy(res->impl_id->domain, dummy_str, dummy);
5567
5568 /* nii_name */
5569 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5570 if (unlikely(status))
5571 return status;
5572 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5573 return -EIO;
5574 memcpy(res->impl_id->name, dummy_str, dummy);
5575
5576 /* nii_date */
5577 p = xdr_inline_decode(xdr, 12);
5578 if (unlikely(!p))
5579 goto out_overflow;
5580 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5581 res->impl_id->date.nseconds = be32_to_cpup(p);
5582
5583 /* if there's more than one entry, ignore the rest */
5584 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005585 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005586out_overflow:
5587 print_overflow_msg(__func__, xdr);
5588 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005589}
Andy Adamsonfc931582009-04-01 09:22:31 -04005590
5591static int decode_chan_attrs(struct xdr_stream *xdr,
5592 struct nfs4_channel_attrs *attrs)
5593{
5594 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005595 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005596
Benny Halevyc0eae662009-08-14 17:20:14 +03005597 p = xdr_inline_decode(xdr, 28);
5598 if (unlikely(!p))
5599 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005600 val = be32_to_cpup(p++); /* headerpadsz */
5601 if (val)
5602 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005603 attrs->max_rqst_sz = be32_to_cpup(p++);
5604 attrs->max_resp_sz = be32_to_cpup(p++);
5605 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5606 attrs->max_ops = be32_to_cpup(p++);
5607 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005608 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005609 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005610 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5611 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005612 return -EINVAL;
5613 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005614 if (nr_attrs == 1) {
5615 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5616 if (unlikely(!p))
5617 goto out_overflow;
5618 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005619 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005620out_overflow:
5621 print_overflow_msg(__func__, xdr);
5622 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005623}
5624
Benny Halevye78291e2009-08-14 17:20:00 +03005625static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5626{
5627 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005628}
5629
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005630static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5631 struct nfs41_bind_conn_to_session_res *res)
5632{
5633 __be32 *p;
5634 int status;
5635
5636 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5637 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005638 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005639 if (unlikely(status))
5640 return status;
5641
5642 /* dir flags, rdma mode bool */
5643 p = xdr_inline_decode(xdr, 8);
5644 if (unlikely(!p))
5645 goto out_overflow;
5646
5647 res->dir = be32_to_cpup(p++);
5648 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5649 return -EIO;
5650 if (be32_to_cpup(p) == 0)
5651 res->use_conn_in_rdma_mode = false;
5652 else
5653 res->use_conn_in_rdma_mode = true;
5654
5655 return 0;
5656out_overflow:
5657 print_overflow_msg(__func__, xdr);
5658 return -EIO;
5659}
5660
Andy Adamsonfc931582009-04-01 09:22:31 -04005661static int decode_create_session(struct xdr_stream *xdr,
5662 struct nfs41_create_session_res *res)
5663{
5664 __be32 *p;
5665 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005666
5667 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005668 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005669 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005670 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005671 return status;
5672
Andy Adamsonfc931582009-04-01 09:22:31 -04005673 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005674 p = xdr_inline_decode(xdr, 8);
5675 if (unlikely(!p))
5676 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005677 res->seqid = be32_to_cpup(p++);
5678 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005679
5680 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005681 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005682 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005683 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005684 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005685out_overflow:
5686 print_overflow_msg(__func__, xdr);
5687 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005688}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005689
5690static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5691{
5692 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5693}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005694
Trond Myklebust66245532012-05-25 17:18:09 -04005695static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5696{
5697 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5698}
5699
Ricardo Labiaga180197532009-12-05 16:08:40 -05005700static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5701{
5702 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5703}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005704#endif /* CONFIG_NFS_V4_1 */
5705
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005706static int decode_sequence(struct xdr_stream *xdr,
5707 struct nfs4_sequence_res *res,
5708 struct rpc_rqst *rqstp)
5709{
5710#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005711 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005712 struct nfs4_sessionid id;
5713 u32 dummy;
5714 int status;
5715 __be32 *p;
5716
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005717 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005718 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005719 if (!res->sr_slot->table->session)
5720 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005721
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005722 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005723 if (!status)
5724 status = decode_sessionid(xdr, &id);
5725 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005726 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005727
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005728 /*
5729 * If the server returns different values for sessionID, slotID or
5730 * sequence number, the server is looney tunes.
5731 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005732 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005733 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005734
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005735 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005736 NFS4_MAX_SESSIONID_LEN)) {
5737 dprintk("%s Invalid session id\n", __func__);
5738 goto out_err;
5739 }
Benny Halevye78291e2009-08-14 17:20:00 +03005740
Benny Halevyc0eae662009-08-14 17:20:14 +03005741 p = xdr_inline_decode(xdr, 20);
5742 if (unlikely(!p))
5743 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005744
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005745 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005746 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005747 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005748 dprintk("%s Invalid sequence number\n", __func__);
5749 goto out_err;
5750 }
5751 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005752 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005753 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005754 dprintk("%s Invalid slot id\n", __func__);
5755 goto out_err;
5756 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005757 /* highest slot id */
5758 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005759 /* target highest slot id */
5760 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005761 /* result flags */
5762 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005763 status = 0;
5764out_err:
5765 res->sr_status = status;
5766 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005767out_overflow:
5768 print_overflow_msg(__func__, xdr);
5769 status = -EIO;
5770 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005771#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005772 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005773#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005774}
5775
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005776#if defined(CONFIG_NFS_V4_1)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005777static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005778 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005779{
Trond Myklebust4e590802015-03-09 14:01:25 -04005780 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005781 __be32 *p;
5782 uint32_t len, type;
5783 int status;
5784
5785 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5786 if (status) {
5787 if (status == -ETOOSMALL) {
5788 p = xdr_inline_decode(xdr, 4);
5789 if (unlikely(!p))
5790 goto out_overflow;
5791 pdev->mincount = be32_to_cpup(p);
5792 dprintk("%s: Min count too small. mincnt = %u\n",
5793 __func__, pdev->mincount);
5794 }
5795 return status;
5796 }
5797
5798 p = xdr_inline_decode(xdr, 8);
5799 if (unlikely(!p))
5800 goto out_overflow;
5801 type = be32_to_cpup(p++);
5802 if (type != pdev->layout_type) {
5803 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5804 __func__, pdev->layout_type, type);
5805 return -EINVAL;
5806 }
5807 /*
5808 * Get the length of the opaque device_addr4. xdr_read_pages places
5809 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5810 * and places the remaining xdr data in xdr_buf->tail
5811 */
5812 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005813 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5814 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005815
5816 /* Parse notification bitmap, verifying that it is zero. */
5817 p = xdr_inline_decode(xdr, 4);
5818 if (unlikely(!p))
5819 goto out_overflow;
5820 len = be32_to_cpup(p);
5821 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005822 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005823
5824 p = xdr_inline_decode(xdr, 4 * len);
5825 if (unlikely(!p))
5826 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005827
Trond Myklebust4e590802015-03-09 14:01:25 -04005828 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005829 for (i = 1; i < len; i++) {
5830 if (be32_to_cpup(p++)) {
5831 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005832 __func__);
5833 return -EIO;
5834 }
5835 }
5836 }
5837 return 0;
5838out_overflow:
5839 print_overflow_msg(__func__, xdr);
5840 return -EIO;
5841}
5842
5843static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5844 struct nfs4_layoutget_res *res)
5845{
5846 __be32 *p;
5847 int status;
5848 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005849 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005850
5851 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5852 if (status)
5853 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005854 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005855 if (unlikely(!p))
5856 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005857 res->return_on_close = be32_to_cpup(p);
5858 decode_stateid(xdr, &res->stateid);
5859 p = xdr_inline_decode(xdr, 4);
5860 if (unlikely(!p))
5861 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005862 layout_count = be32_to_cpup(p);
5863 if (!layout_count) {
5864 dprintk("%s: server responded with empty layout array\n",
5865 __func__);
5866 return -EINVAL;
5867 }
5868
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005869 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005870 if (unlikely(!p))
5871 goto out_overflow;
5872 p = xdr_decode_hyper(p, &res->range.offset);
5873 p = xdr_decode_hyper(p, &res->range.length);
5874 res->range.iomode = be32_to_cpup(p++);
5875 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005876 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005877
5878 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5879 __func__,
5880 (unsigned long)res->range.offset,
5881 (unsigned long)res->range.length,
5882 res->range.iomode,
5883 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005884 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005885
Trond Myklebust64bd5772012-06-20 22:35:05 -04005886 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005887 if (res->layoutp->len > recvd) {
5888 dprintk("NFS: server cheating in layoutget reply: "
5889 "layout len %u > recvd %u\n",
5890 res->layoutp->len, recvd);
5891 return -EINVAL;
5892 }
5893
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005894 if (layout_count > 1) {
5895 /* We only handle a length one array at the moment. Any
5896 * further entries are just ignored. Note that this means
5897 * the client may see a response that is less than the
5898 * minimum it requested.
5899 */
5900 dprintk("%s: server responded with %d layouts, dropping tail\n",
5901 __func__, layout_count);
5902 }
5903
5904 return 0;
5905out_overflow:
5906 print_overflow_msg(__func__, xdr);
5907 return -EIO;
5908}
Andy Adamson863a3c62011-03-23 13:27:54 +00005909
Benny Halevycbe82602011-05-22 19:52:37 +03005910static int decode_layoutreturn(struct xdr_stream *xdr,
5911 struct nfs4_layoutreturn_res *res)
5912{
5913 __be32 *p;
5914 int status;
5915
5916 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5917 if (status)
5918 return status;
5919 p = xdr_inline_decode(xdr, 4);
5920 if (unlikely(!p))
5921 goto out_overflow;
5922 res->lrs_present = be32_to_cpup(p);
5923 if (res->lrs_present)
5924 status = decode_stateid(xdr, &res->stateid);
5925 return status;
5926out_overflow:
5927 print_overflow_msg(__func__, xdr);
5928 return -EIO;
5929}
5930
Andy Adamson863a3c62011-03-23 13:27:54 +00005931static int decode_layoutcommit(struct xdr_stream *xdr,
5932 struct rpc_rqst *req,
5933 struct nfs4_layoutcommit_res *res)
5934{
5935 __be32 *p;
5936 __u32 sizechanged;
5937 int status;
5938
5939 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005940 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005941 if (status)
5942 return status;
5943
5944 p = xdr_inline_decode(xdr, 4);
5945 if (unlikely(!p))
5946 goto out_overflow;
5947 sizechanged = be32_to_cpup(p);
5948
5949 if (sizechanged) {
5950 /* throw away new size */
5951 p = xdr_inline_decode(xdr, 8);
5952 if (unlikely(!p))
5953 goto out_overflow;
5954 }
5955 return 0;
5956out_overflow:
5957 print_overflow_msg(__func__, xdr);
5958 return -EIO;
5959}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005960
5961static int decode_test_stateid(struct xdr_stream *xdr,
5962 struct nfs41_test_stateid_res *res)
5963{
5964 __be32 *p;
5965 int status;
5966 int num_res;
5967
5968 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5969 if (status)
5970 return status;
5971
5972 p = xdr_inline_decode(xdr, 4);
5973 if (unlikely(!p))
5974 goto out_overflow;
5975 num_res = be32_to_cpup(p++);
5976 if (num_res != 1)
5977 goto out;
5978
5979 p = xdr_inline_decode(xdr, 4);
5980 if (unlikely(!p))
5981 goto out_overflow;
5982 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005983
5984 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005985out_overflow:
5986 print_overflow_msg(__func__, xdr);
5987out:
5988 return -EIO;
5989}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005990
5991static int decode_free_stateid(struct xdr_stream *xdr,
5992 struct nfs41_free_stateid_res *res)
5993{
Andy Adamson9f79fb42013-09-10 12:56:29 -04005994 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005995 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005996}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005997#endif /* CONFIG_NFS_V4_1 */
5998
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999/*
Benny Halevy49c25592008-12-23 16:06:16 -05006000 * END OF "GENERIC" DECODE ROUTINES.
6001 */
6002
6003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006004 * Decode OPEN_DOWNGRADE response
6005 */
Chuck Leverbf269552010-12-14 14:59:29 +00006006static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6007 struct xdr_stream *xdr,
6008 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006009{
Andy Adamson05d564f2008-12-23 16:06:15 -05006010 struct compound_hdr hdr;
6011 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012
Chuck Leverbf269552010-12-14 14:59:29 +00006013 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006014 if (status)
6015 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006016 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006017 if (status)
6018 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006019 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006020 if (status)
6021 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006022 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006023 if (status != 0)
6024 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006025 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006026out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006027 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006028}
6029
6030/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006031 * Decode ACCESS response
6032 */
Chuck Leverbf269552010-12-14 14:59:29 +00006033static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6034 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006035{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006036 struct compound_hdr hdr;
6037 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006038
Chuck Leverbf269552010-12-14 14:59:29 +00006039 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006040 if (status)
6041 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006042 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006043 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006045 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006046 if (status != 0)
6047 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006048 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006049 if (status != 0)
6050 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006051 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052out:
6053 return status;
6054}
6055
6056/*
6057 * Decode LOOKUP response
6058 */
Chuck Leverbf269552010-12-14 14:59:29 +00006059static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6060 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062 struct compound_hdr hdr;
6063 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006064
Chuck Leverbf269552010-12-14 14:59:29 +00006065 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006066 if (status)
6067 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006068 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006069 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006071 status = decode_putfh(xdr);
6072 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006074 status = decode_lookup(xdr);
6075 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006076 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006077 status = decode_getfh(xdr, res->fh);
6078 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006080 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081out:
6082 return status;
6083}
6084
6085/*
6086 * Decode LOOKUP_ROOT response
6087 */
Chuck Leverbf269552010-12-14 14:59:29 +00006088static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6089 struct xdr_stream *xdr,
6090 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006091{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092 struct compound_hdr hdr;
6093 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006094
Chuck Leverbf269552010-12-14 14:59:29 +00006095 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006096 if (status)
6097 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006098 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006099 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006101 status = decode_putrootfh(xdr);
6102 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006104 status = decode_getfh(xdr, res->fh);
6105 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006106 status = decode_getfattr_label(xdr, res->fattr,
6107 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108out:
6109 return status;
6110}
6111
6112/*
6113 * Decode REMOVE response
6114 */
Chuck Leverbf269552010-12-14 14:59:29 +00006115static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6116 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118 struct compound_hdr hdr;
6119 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006120
Chuck Leverbf269552010-12-14 14:59:29 +00006121 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006122 if (status)
6123 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006124 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006125 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006127 status = decode_putfh(xdr);
6128 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006129 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006131out:
6132 return status;
6133}
6134
6135/*
6136 * Decode RENAME response
6137 */
Chuck Leverbf269552010-12-14 14:59:29 +00006138static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6139 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006140{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141 struct compound_hdr hdr;
6142 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006143
Chuck Leverbf269552010-12-14 14:59:29 +00006144 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006145 if (status)
6146 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006147 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006148 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006149 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006150 status = decode_putfh(xdr);
6151 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_savefh(xdr);
6154 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_putfh(xdr);
6157 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160out:
6161 return status;
6162}
6163
6164/*
6165 * Decode LINK response
6166 */
Chuck Leverbf269552010-12-14 14:59:29 +00006167static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6168 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170 struct compound_hdr hdr;
6171 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006172
Chuck Leverbf269552010-12-14 14:59:29 +00006173 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006174 if (status)
6175 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006176 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006177 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006178 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_putfh(xdr);
6180 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_savefh(xdr);
6183 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_putfh(xdr);
6186 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006188 status = decode_link(xdr, &res->cinfo);
6189 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006190 goto out;
6191 /*
6192 * Note order: OP_LINK leaves the directory as the current
6193 * filehandle.
6194 */
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_restorefh(xdr);
6196 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006197 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006198 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006199out:
6200 return status;
6201}
6202
6203/*
6204 * Decode CREATE response
6205 */
Chuck Leverbf269552010-12-14 14:59:29 +00006206static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6207 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209 struct compound_hdr hdr;
6210 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006211
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006213 if (status)
6214 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006215 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006216 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006218 status = decode_putfh(xdr);
6219 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006220 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006221 status = decode_create(xdr, &res->dir_cinfo);
6222 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006223 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006224 status = decode_getfh(xdr, res->fh);
6225 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006227 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228out:
6229 return status;
6230}
6231
6232/*
6233 * Decode SYMLINK response
6234 */
Chuck Leverbf269552010-12-14 14:59:29 +00006235static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6236 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237{
Chuck Leverbf269552010-12-14 14:59:29 +00006238 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239}
6240
6241/*
6242 * Decode GETATTR response
6243 */
Chuck Leverbf269552010-12-14 14:59:29 +00006244static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6245 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006247 struct compound_hdr hdr;
6248 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006249
Chuck Leverbf269552010-12-14 14:59:29 +00006250 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251 if (status)
6252 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006253 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006254 if (status)
6255 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006256 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257 if (status)
6258 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006259 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260out:
6261 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262}
6263
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006264/*
6265 * Encode an SETACL request
6266 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006267static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6268 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006269{
Andy Adamson05d564f2008-12-23 16:06:15 -05006270 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006271 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006272 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006273
Chuck Lever9f06c712010-12-14 14:59:18 +00006274 encode_compound_hdr(xdr, req, &hdr);
6275 encode_sequence(xdr, &args->seq_args, &hdr);
6276 encode_putfh(xdr, args->fh, &hdr);
6277 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006278 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006279}
Andy Adamson05d564f2008-12-23 16:06:15 -05006280
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006281/*
6282 * Decode SETACL response
6283 */
6284static int
Chuck Leverbf269552010-12-14 14:59:29 +00006285nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006286 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006287{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006288 struct compound_hdr hdr;
6289 int status;
6290
Chuck Leverbf269552010-12-14 14:59:29 +00006291 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006292 if (status)
6293 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006294 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006295 if (status)
6296 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006297 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006298 if (status)
6299 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006300 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006301out:
6302 return status;
6303}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006304
6305/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006306 * Decode GETACL response
6307 */
6308static int
Chuck Leverbf269552010-12-14 14:59:29 +00006309nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006310 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006311{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006312 struct compound_hdr hdr;
6313 int status;
6314
Trond Myklebust331818f2012-02-03 18:30:53 -05006315 if (res->acl_scratch != NULL) {
6316 void *p = page_address(res->acl_scratch);
6317 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6318 }
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006320 if (status)
6321 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006322 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006323 if (status)
6324 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006326 if (status)
6327 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006328 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006329
6330out:
6331 return status;
6332}
6333
6334/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335 * Decode CLOSE response
6336 */
Chuck Leverbf269552010-12-14 14:59:29 +00006337static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6338 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339{
Andy Adamson05d564f2008-12-23 16:06:15 -05006340 struct compound_hdr hdr;
6341 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342
Chuck Leverbf269552010-12-14 14:59:29 +00006343 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006344 if (status)
6345 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006346 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006347 if (status)
6348 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006349 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006350 if (status)
6351 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006352 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006353 if (status != 0)
6354 goto out;
6355 /*
6356 * Note: Server may do delete on close for this file
6357 * in which case the getattr call will fail with
6358 * an ESTALE error. Shouldn't be a problem,
6359 * though, since fattr->valid will remain unset.
6360 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006361 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006363 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364}
6365
6366/*
6367 * Decode OPEN response
6368 */
Chuck Leverbf269552010-12-14 14:59:29 +00006369static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6370 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371{
Andy Adamson05d564f2008-12-23 16:06:15 -05006372 struct compound_hdr hdr;
6373 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374
Chuck Leverbf269552010-12-14 14:59:29 +00006375 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006376 if (status)
6377 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006378 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006379 if (status)
6380 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006381 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006382 if (status)
6383 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006384 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006385 if (status)
6386 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006387 status = decode_getfh(xdr, &res->fh);
6388 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006389 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006390 if (res->access_request)
6391 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006392 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006393out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006394 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006395}
6396
6397/*
6398 * Decode OPEN_CONFIRM response
6399 */
Chuck Leverbf269552010-12-14 14:59:29 +00006400static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6401 struct xdr_stream *xdr,
6402 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006403{
Andy Adamson05d564f2008-12-23 16:06:15 -05006404 struct compound_hdr hdr;
6405 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406
Chuck Leverbf269552010-12-14 14:59:29 +00006407 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006408 if (status)
6409 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006411 if (status)
6412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006415 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416}
6417
6418/*
6419 * Decode OPEN response
6420 */
Chuck Leverbf269552010-12-14 14:59:29 +00006421static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6422 struct xdr_stream *xdr,
6423 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006424{
Andy Adamson05d564f2008-12-23 16:06:15 -05006425 struct compound_hdr hdr;
6426 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427
Chuck Leverbf269552010-12-14 14:59:29 +00006428 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006429 if (status)
6430 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006431 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006432 if (status)
6433 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006434 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006435 if (status)
6436 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006437 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006438 if (status)
6439 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006440 if (res->access_request)
6441 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006442 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006444 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006445}
6446
6447/*
6448 * Decode SETATTR response
6449 */
Chuck Leverbf269552010-12-14 14:59:29 +00006450static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6451 struct xdr_stream *xdr,
6452 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453{
Andy Adamson05d564f2008-12-23 16:06:15 -05006454 struct compound_hdr hdr;
6455 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456
Chuck Leverbf269552010-12-14 14:59:29 +00006457 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006458 if (status)
6459 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006460 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006461 if (status)
6462 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006463 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006464 if (status)
6465 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006466 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006467 if (status)
6468 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006469 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006471 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472}
6473
6474/*
6475 * Decode LOCK response
6476 */
Chuck Leverbf269552010-12-14 14:59:29 +00006477static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6478 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480 struct compound_hdr hdr;
6481 int status;
6482
Chuck Leverbf269552010-12-14 14:59:29 +00006483 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484 if (status)
6485 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006487 if (status)
6488 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006489 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490 if (status)
6491 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493out:
6494 return status;
6495}
6496
6497/*
6498 * Decode LOCKT response
6499 */
Chuck Leverbf269552010-12-14 14:59:29 +00006500static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6501 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006503 struct compound_hdr hdr;
6504 int status;
6505
Chuck Leverbf269552010-12-14 14:59:29 +00006506 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507 if (status)
6508 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006509 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006510 if (status)
6511 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006512 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513 if (status)
6514 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006515 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516out:
6517 return status;
6518}
6519
6520/*
6521 * Decode LOCKU response
6522 */
Chuck Leverbf269552010-12-14 14:59:29 +00006523static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6524 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006525{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526 struct compound_hdr hdr;
6527 int status;
6528
Chuck Leverbf269552010-12-14 14:59:29 +00006529 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530 if (status)
6531 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006533 if (status)
6534 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 if (status)
6537 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006538 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539out:
6540 return status;
6541}
6542
Chuck Leverbf269552010-12-14 14:59:29 +00006543static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6544 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006545{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006546 struct compound_hdr hdr;
6547 int status;
6548
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006550 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006552 return status;
6553}
6554
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555/*
6556 * Decode READLINK response
6557 */
Chuck Leverbf269552010-12-14 14:59:29 +00006558static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6559 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006560 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006561{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006562 struct compound_hdr hdr;
6563 int status;
6564
Chuck Leverbf269552010-12-14 14:59:29 +00006565 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566 if (status)
6567 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006568 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006569 if (status)
6570 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006571 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572 if (status)
6573 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006574 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575out:
6576 return status;
6577}
6578
6579/*
6580 * Decode READDIR response
6581 */
Chuck Leverbf269552010-12-14 14:59:29 +00006582static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6583 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585 struct compound_hdr hdr;
6586 int status;
6587
Chuck Leverbf269552010-12-14 14:59:29 +00006588 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589 if (status)
6590 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006591 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006592 if (status)
6593 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006594 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595 if (status)
6596 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006597 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006598out:
6599 return status;
6600}
6601
6602/*
6603 * Decode Read response
6604 */
Chuck Leverbf269552010-12-14 14:59:29 +00006605static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006606 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006608 struct compound_hdr hdr;
6609 int status;
6610
Chuck Leverbf269552010-12-14 14:59:29 +00006611 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006612 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613 if (status)
6614 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006615 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006616 if (status)
6617 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006618 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619 if (status)
6620 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622 if (!status)
6623 status = res->count;
6624out:
6625 return status;
6626}
6627
6628/*
6629 * Decode WRITE response
6630 */
Chuck Leverbf269552010-12-14 14:59:29 +00006631static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006632 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634 struct compound_hdr hdr;
6635 int status;
6636
Chuck Leverbf269552010-12-14 14:59:29 +00006637 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006638 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639 if (status)
6640 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006641 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006642 if (status)
6643 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006644 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006645 if (status)
6646 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006648 if (status)
6649 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006650 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006651 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006652 if (!status)
6653 status = res->count;
6654out:
6655 return status;
6656}
6657
6658/*
6659 * Decode COMMIT response
6660 */
Chuck Leverbf269552010-12-14 14:59:29 +00006661static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006662 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006663{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664 struct compound_hdr hdr;
6665 int status;
6666
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006668 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669 if (status)
6670 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006671 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006672 if (status)
6673 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006674 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675 if (status)
6676 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006677 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006678out:
6679 return status;
6680}
6681
6682/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006683 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006684 */
Chuck Leverbf269552010-12-14 14:59:29 +00006685static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006686 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006687{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006688 struct compound_hdr hdr;
6689 int status;
6690
Chuck Leverbf269552010-12-14 14:59:29 +00006691 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006692 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006693 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006694 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006695 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006697 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006698 return status;
6699}
6700
6701/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006702 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006703 */
Chuck Leverbf269552010-12-14 14:59:29 +00006704static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006705 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006706{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006707 struct compound_hdr hdr;
6708 int status;
6709
Chuck Leverbf269552010-12-14 14:59:29 +00006710 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006712 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006713 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006714 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006715 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006716 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006717 return status;
6718}
6719
6720/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006721 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006722 */
Chuck Leverbf269552010-12-14 14:59:29 +00006723static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006724 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006725{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726 struct compound_hdr hdr;
6727 int status;
6728
Chuck Leverbf269552010-12-14 14:59:29 +00006729 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006730 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006731 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006732 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006733 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006734 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006735 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 return status;
6737}
6738
6739/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006740 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006741 */
Chuck Leverbf269552010-12-14 14:59:29 +00006742static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6743 struct xdr_stream *xdr,
6744 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006745{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006746 struct compound_hdr hdr;
6747 int status;
6748
Chuck Leverbf269552010-12-14 14:59:29 +00006749 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006750 if (status)
6751 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006752 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006753 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006754 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006755 status = decode_putfh(xdr);
6756 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006758 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759out:
6760 return status;
6761}
6762
6763/*
6764 * Decode RENEW response
6765 */
Chuck Leverbf269552010-12-14 14:59:29 +00006766static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6767 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769 struct compound_hdr hdr;
6770 int status;
6771
Chuck Leverbf269552010-12-14 14:59:29 +00006772 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006773 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006774 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006775 return status;
6776}
6777
6778/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006779 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006780 */
Chuck Leverbf269552010-12-14 14:59:29 +00006781static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6782 struct xdr_stream *xdr,
6783 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006784{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006785 struct compound_hdr hdr;
6786 int status;
6787
Chuck Leverbf269552010-12-14 14:59:29 +00006788 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006789 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006790 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006791 return status;
6792}
6793
6794/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006795 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006796 */
Chuck Leverbf269552010-12-14 14:59:29 +00006797static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006798 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006799{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006800 struct compound_hdr hdr;
6801 int status;
6802
Chuck Leverbf269552010-12-14 14:59:29 +00006803 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006804 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006805 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006806 return status;
6807}
6808
6809/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006810 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006811 */
Chuck Leverbf269552010-12-14 14:59:29 +00006812static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6813 struct xdr_stream *xdr,
6814 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006815{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006816 struct compound_hdr hdr;
6817 int status;
6818
Chuck Leverbf269552010-12-14 14:59:29 +00006819 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006820 if (status)
6821 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006822 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006823 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006824 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006825 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006826 if (status != 0)
6827 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006828 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006829 if (status != 0)
6830 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006831 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006832out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006833 return status;
6834}
6835
Trond Myklebust683b57b2006-06-09 09:34:22 -04006836/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006837 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006838 */
Chuck Leverbf269552010-12-14 14:59:29 +00006839static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6840 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006841 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006842{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006843 struct compound_hdr hdr;
6844 int status;
6845
Chuck Leverbf269552010-12-14 14:59:29 +00006846 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006847 if (status)
6848 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006849 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006850 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006851 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006852 status = decode_putfh(xdr);
6853 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006854 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006855 if (res->migration) {
6856 xdr_enter_page(xdr, PAGE_SIZE);
6857 status = decode_getfattr_generic(xdr,
6858 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006859 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006860 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006861 if (status)
6862 goto out;
6863 if (res->renew)
6864 status = decode_renew(xdr);
6865 } else {
6866 status = decode_lookup(xdr);
6867 if (status)
6868 goto out;
6869 xdr_enter_page(xdr, PAGE_SIZE);
6870 status = decode_getfattr_generic(xdr,
6871 &res->fs_locations->fattr,
6872 NULL, res->fs_locations,
6873 NULL, res->fs_locations->server);
6874 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006875out:
6876 return status;
6877}
6878
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006879/*
6880 * Decode SECINFO response
6881 */
6882static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6883 struct xdr_stream *xdr,
6884 struct nfs4_secinfo_res *res)
6885{
6886 struct compound_hdr hdr;
6887 int status;
6888
6889 status = decode_compound_hdr(xdr, &hdr);
6890 if (status)
6891 goto out;
6892 status = decode_sequence(xdr, &res->seq_res, rqstp);
6893 if (status)
6894 goto out;
6895 status = decode_putfh(xdr);
6896 if (status)
6897 goto out;
6898 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006899out:
6900 return status;
6901}
6902
Chuck Lever44c99932013-10-17 14:13:30 -04006903/*
6904 * Decode FSID_PRESENT response
6905 */
6906static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6907 struct xdr_stream *xdr,
6908 struct nfs4_fsid_present_res *res)
6909{
6910 struct compound_hdr hdr;
6911 int status;
6912
6913 status = decode_compound_hdr(xdr, &hdr);
6914 if (status)
6915 goto out;
6916 status = decode_sequence(xdr, &res->seq_res, rqstp);
6917 if (status)
6918 goto out;
6919 status = decode_putfh(xdr);
6920 if (status)
6921 goto out;
6922 status = decode_getfh(xdr, res->fh);
6923 if (status)
6924 goto out;
6925 if (res->renew)
6926 status = decode_renew(xdr);
6927out:
6928 return status;
6929}
6930
Benny Halevy99fe60d2009-04-01 09:22:29 -04006931#if defined(CONFIG_NFS_V4_1)
6932/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006933 * Decode BIND_CONN_TO_SESSION response
6934 */
6935static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6936 struct xdr_stream *xdr,
6937 void *res)
6938{
6939 struct compound_hdr hdr;
6940 int status;
6941
6942 status = decode_compound_hdr(xdr, &hdr);
6943 if (!status)
6944 status = decode_bind_conn_to_session(xdr, res);
6945 return status;
6946}
6947
6948/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006949 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006950 */
Chuck Leverbf269552010-12-14 14:59:29 +00006951static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6952 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006953 void *res)
6954{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006955 struct compound_hdr hdr;
6956 int status;
6957
Chuck Leverbf269552010-12-14 14:59:29 +00006958 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006959 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006960 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006961 return status;
6962}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006963
6964/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006965 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006966 */
Chuck Leverbf269552010-12-14 14:59:29 +00006967static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6968 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006969 struct nfs41_create_session_res *res)
6970{
Andy Adamsonfc931582009-04-01 09:22:31 -04006971 struct compound_hdr hdr;
6972 int status;
6973
Chuck Leverbf269552010-12-14 14:59:29 +00006974 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006975 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006976 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006977 return status;
6978}
6979
6980/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006981 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006982 */
Chuck Leverbf269552010-12-14 14:59:29 +00006983static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6984 struct xdr_stream *xdr,
6985 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006986{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006987 struct compound_hdr hdr;
6988 int status;
6989
Chuck Leverbf269552010-12-14 14:59:29 +00006990 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006991 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006992 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006993 return status;
6994}
6995
6996/*
Trond Myklebust66245532012-05-25 17:18:09 -04006997 * Decode DESTROY_CLIENTID response
6998 */
6999static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7000 struct xdr_stream *xdr,
7001 void *res)
7002{
7003 struct compound_hdr hdr;
7004 int status;
7005
7006 status = decode_compound_hdr(xdr, &hdr);
7007 if (!status)
7008 status = decode_destroy_clientid(xdr, res);
7009 return status;
7010}
7011
7012/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007013 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007014 */
Chuck Leverbf269552010-12-14 14:59:29 +00007015static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7016 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007017 struct nfs4_sequence_res *res)
7018{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007019 struct compound_hdr hdr;
7020 int status;
7021
Chuck Leverbf269552010-12-14 14:59:29 +00007022 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007023 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007024 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007025 return status;
7026}
7027
7028/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007029 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007030 */
Chuck Leverbf269552010-12-14 14:59:29 +00007031static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7032 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007033 struct nfs4_get_lease_time_res *res)
7034{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007035 struct compound_hdr hdr;
7036 int status;
7037
Chuck Leverbf269552010-12-14 14:59:29 +00007038 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007039 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007040 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007041 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007042 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007043 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007044 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007045 return status;
7046}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007047
7048/*
7049 * Decode RECLAIM_COMPLETE response
7050 */
Chuck Leverbf269552010-12-14 14:59:29 +00007051static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7052 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007053 struct nfs41_reclaim_complete_res *res)
7054{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007055 struct compound_hdr hdr;
7056 int status;
7057
Chuck Leverbf269552010-12-14 14:59:29 +00007058 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007059 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007060 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007061 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307062 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007063 return status;
7064}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007065
7066/*
7067 * Decode GETDEVINFO response
7068 */
Chuck Leverbf269552010-12-14 14:59:29 +00007069static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7070 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007071 struct nfs4_getdeviceinfo_res *res)
7072{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007073 struct compound_hdr hdr;
7074 int status;
7075
Chuck Leverbf269552010-12-14 14:59:29 +00007076 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007077 if (status != 0)
7078 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007079 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007080 if (status != 0)
7081 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007082 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007083out:
7084 return status;
7085}
7086
7087/*
7088 * Decode LAYOUTGET response
7089 */
Chuck Leverbf269552010-12-14 14:59:29 +00007090static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7091 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007092 struct nfs4_layoutget_res *res)
7093{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007094 struct compound_hdr hdr;
7095 int status;
7096
Chuck Leverbf269552010-12-14 14:59:29 +00007097 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007098 if (status)
7099 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007100 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007101 if (status)
7102 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007103 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007104 if (status)
7105 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007106 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007107out:
7108 return status;
7109}
Andy Adamson863a3c62011-03-23 13:27:54 +00007110
7111/*
Benny Halevycbe82602011-05-22 19:52:37 +03007112 * Decode LAYOUTRETURN response
7113 */
7114static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7115 struct xdr_stream *xdr,
7116 struct nfs4_layoutreturn_res *res)
7117{
7118 struct compound_hdr hdr;
7119 int status;
7120
7121 status = decode_compound_hdr(xdr, &hdr);
7122 if (status)
7123 goto out;
7124 status = decode_sequence(xdr, &res->seq_res, rqstp);
7125 if (status)
7126 goto out;
7127 status = decode_putfh(xdr);
7128 if (status)
7129 goto out;
7130 status = decode_layoutreturn(xdr, res);
7131out:
7132 return status;
7133}
7134
7135/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007136 * Decode LAYOUTCOMMIT response
7137 */
7138static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7139 struct xdr_stream *xdr,
7140 struct nfs4_layoutcommit_res *res)
7141{
7142 struct compound_hdr hdr;
7143 int status;
7144
7145 status = decode_compound_hdr(xdr, &hdr);
7146 if (status)
7147 goto out;
7148 status = decode_sequence(xdr, &res->seq_res, rqstp);
7149 if (status)
7150 goto out;
7151 status = decode_putfh(xdr);
7152 if (status)
7153 goto out;
7154 status = decode_layoutcommit(xdr, rqstp, res);
7155 if (status)
7156 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007157 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007158out:
7159 return status;
7160}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007161
7162/*
7163 * Decode SECINFO_NO_NAME response
7164 */
7165static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7166 struct xdr_stream *xdr,
7167 struct nfs4_secinfo_res *res)
7168{
7169 struct compound_hdr hdr;
7170 int status;
7171
7172 status = decode_compound_hdr(xdr, &hdr);
7173 if (status)
7174 goto out;
7175 status = decode_sequence(xdr, &res->seq_res, rqstp);
7176 if (status)
7177 goto out;
7178 status = decode_putrootfh(xdr);
7179 if (status)
7180 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007181 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007182out:
7183 return status;
7184}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007185
7186/*
7187 * Decode TEST_STATEID response
7188 */
7189static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7190 struct xdr_stream *xdr,
7191 struct nfs41_test_stateid_res *res)
7192{
7193 struct compound_hdr hdr;
7194 int status;
7195
7196 status = decode_compound_hdr(xdr, &hdr);
7197 if (status)
7198 goto out;
7199 status = decode_sequence(xdr, &res->seq_res, rqstp);
7200 if (status)
7201 goto out;
7202 status = decode_test_stateid(xdr, res);
7203out:
7204 return status;
7205}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007206
7207/*
7208 * Decode FREE_STATEID response
7209 */
7210static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7211 struct xdr_stream *xdr,
7212 struct nfs41_free_stateid_res *res)
7213{
7214 struct compound_hdr hdr;
7215 int status;
7216
7217 status = decode_compound_hdr(xdr, &hdr);
7218 if (status)
7219 goto out;
7220 status = decode_sequence(xdr, &res->seq_res, rqstp);
7221 if (status)
7222 goto out;
7223 status = decode_free_stateid(xdr, res);
7224out:
7225 return status;
7226}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007227#endif /* CONFIG_NFS_V4_1 */
7228
Chuck Lever573c4e12010-12-14 14:58:11 +00007229/**
7230 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7231 * the local page cache.
7232 * @xdr: XDR stream where entry resides
7233 * @entry: buffer to fill in with entry data
7234 * @plus: boolean indicating whether this should be a readdirplus entry
7235 *
7236 * Returns zero if successful, otherwise a negative errno value is
7237 * returned.
7238 *
7239 * This function is not invoked during READDIR reply decoding, but
7240 * rather whenever an application invokes the getdents(2) system call
7241 * on a directory already in our cache.
7242 */
7243int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7244 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007245{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007246 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007247 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007248 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007249 __be32 *p = xdr_inline_decode(xdr, 4);
7250 if (unlikely(!p))
7251 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007252 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007253 p = xdr_inline_decode(xdr, 4);
7254 if (unlikely(!p))
7255 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007256 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007257 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007258 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007259 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007260 }
7261
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007262 p = xdr_inline_decode(xdr, 12);
7263 if (unlikely(!p))
7264 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007265 entry->prev_cookie = entry->cookie;
7266 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007267 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007268
Trond Myklebust9af8c222010-10-24 11:52:55 -04007269 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007270 if (unlikely(!p))
7271 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007272 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007273
7274 /*
7275 * In case the server doesn't return an inode number,
7276 * we fake one here. (We don't use inode number 0,
7277 * since glibc seems to choke on it...)
7278 */
7279 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007280 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007281
Trond Myklebust9af8c222010-10-24 11:52:55 -04007282 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007283 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007284
Trond Myklebust256e48b2012-06-21 11:18:13 -04007285 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007286 goto out_overflow;
7287
Chuck Lever573c4e12010-12-14 14:58:11 +00007288 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007289 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007290 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007291 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7292 entry->ino = entry->fattr->mounted_on_fileid;
7293 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007294 entry->ino = entry->fattr->fileid;
7295
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007296 entry->d_type = DT_UNKNOWN;
7297 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7298 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7299
Chuck Lever573c4e12010-12-14 14:58:11 +00007300 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007301
7302out_overflow:
7303 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007304 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007305}
7306
7307/*
7308 * We need to translate between nfs status return values and
7309 * the local errno values which may not be the same.
7310 */
7311static struct {
7312 int stat;
7313 int errno;
7314} nfs_errtbl[] = {
7315 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007316 { NFS4ERR_PERM, -EPERM },
7317 { NFS4ERR_NOENT, -ENOENT },
7318 { NFS4ERR_IO, -errno_NFSERR_IO},
7319 { NFS4ERR_NXIO, -ENXIO },
7320 { NFS4ERR_ACCESS, -EACCES },
7321 { NFS4ERR_EXIST, -EEXIST },
7322 { NFS4ERR_XDEV, -EXDEV },
7323 { NFS4ERR_NOTDIR, -ENOTDIR },
7324 { NFS4ERR_ISDIR, -EISDIR },
7325 { NFS4ERR_INVAL, -EINVAL },
7326 { NFS4ERR_FBIG, -EFBIG },
7327 { NFS4ERR_NOSPC, -ENOSPC },
7328 { NFS4ERR_ROFS, -EROFS },
7329 { NFS4ERR_MLINK, -EMLINK },
7330 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7331 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7332 { NFS4ERR_DQUOT, -EDQUOT },
7333 { NFS4ERR_STALE, -ESTALE },
7334 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007335 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7336 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7337 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007338 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007339 { NFS4ERR_BADTYPE, -EBADTYPE },
7340 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007341 { NFS4ERR_SYMLINK, -ELOOP },
7342 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7343 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007344 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007345};
7346
7347/*
7348 * Convert an NFS error code to a local one.
7349 * This one is used jointly by NFSv2 and NFSv3.
7350 */
7351static int
David Howells0a8ea432006-08-22 20:06:08 -04007352nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007353{
7354 int i;
7355 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7356 if (nfs_errtbl[i].stat == stat)
7357 return nfs_errtbl[i].errno;
7358 }
7359 if (stat <= 10000 || stat > 10100) {
7360 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007361 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007362 }
7363 /* If we cannot translate the error, the recovery routines should
7364 * handle it.
7365 * Note: remaining NFSv4 error codes have values > 10000, so should
7366 * not conflict with native Linux error codes.
7367 */
Benny Halevy856dff32008-03-31 17:39:06 +03007368 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007369}
7370
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007371#ifdef CONFIG_NFS_V4_2
7372#include "nfs42xdr.c"
7373#endif /* CONFIG_NFS_V4_2 */
7374
Linus Torvalds1da177e2005-04-16 15:20:36 -07007375#define PROC(proc, argtype, restype) \
7376[NFSPROC4_CLNT_##proc] = { \
7377 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007378 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007379 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007380 .p_arglen = NFS4_##argtype##_sz, \
7381 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007382 .p_statidx = NFSPROC4_CLNT_##proc, \
7383 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007384}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007385
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007386#define STUB(proc) \
7387[NFSPROC4_CLNT_##proc] = { \
7388 .p_name = #proc, \
7389}
7390
Linus Torvalds1da177e2005-04-16 15:20:36 -07007391struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007392 PROC(READ, enc_read, dec_read),
7393 PROC(WRITE, enc_write, dec_write),
7394 PROC(COMMIT, enc_commit, dec_commit),
7395 PROC(OPEN, enc_open, dec_open),
7396 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7397 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7398 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7399 PROC(CLOSE, enc_close, dec_close),
7400 PROC(SETATTR, enc_setattr, dec_setattr),
7401 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7402 PROC(RENEW, enc_renew, dec_renew),
7403 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7404 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7405 PROC(LOCK, enc_lock, dec_lock),
7406 PROC(LOCKT, enc_lockt, dec_lockt),
7407 PROC(LOCKU, enc_locku, dec_locku),
7408 PROC(ACCESS, enc_access, dec_access),
7409 PROC(GETATTR, enc_getattr, dec_getattr),
7410 PROC(LOOKUP, enc_lookup, dec_lookup),
7411 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7412 PROC(REMOVE, enc_remove, dec_remove),
7413 PROC(RENAME, enc_rename, dec_rename),
7414 PROC(LINK, enc_link, dec_link),
7415 PROC(SYMLINK, enc_symlink, dec_symlink),
7416 PROC(CREATE, enc_create, dec_create),
7417 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7418 PROC(STATFS, enc_statfs, dec_statfs),
7419 PROC(READLINK, enc_readlink, dec_readlink),
7420 PROC(READDIR, enc_readdir, dec_readdir),
7421 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7422 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7423 PROC(GETACL, enc_getacl, dec_getacl),
7424 PROC(SETACL, enc_setacl, dec_setacl),
7425 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7426 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007427 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007428 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007429#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007430 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7431 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7432 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7433 PROC(SEQUENCE, enc_sequence, dec_sequence),
7434 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7435 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7436 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7437 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007438 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007439 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007440 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007441 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007442 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007443 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007444 PROC(BIND_CONN_TO_SESSION,
7445 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007446 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007447#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007448#ifdef CONFIG_NFS_V4_2
7449 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007450 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007451 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007452 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007453#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007454};
7455
Trond Myklebusta613fa12012-01-20 13:53:56 -05007456const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007457 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007458 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007459 .procs = nfs4_procedures
7460};
7461
7462/*
7463 * Local variables:
7464 * c-basic-offset: 8
7465 * End:
7466 */