blob: a7be571c1666bb858298b46d874149308031ddbf [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,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001004 const struct nfs_server *server,
1005 bool excl_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006{
1007 char owner_name[IDMAP_NAMESZ];
1008 char owner_group[IDMAP_NAMESZ];
1009 int owner_namelen = 0;
1010 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001011 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001012 unsigned i;
1013 uint32_t len = 0;
1014 uint32_t bmval_len;
1015 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017 /*
1018 * We reserve enough space to write the entire attribute buffer at once.
1019 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001020 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1021 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001022 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001024 if (iap->ia_valid & ATTR_SIZE) {
1025 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001027 }
1028 if (iap->ia_valid & ATTR_MODE) {
1029 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001031 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001033 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001035 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001036 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 /* XXX */
1038 strcpy(owner_name, "nobody");
1039 owner_namelen = sizeof("nobody") - 1;
1040 /* goto out; */
1041 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001042 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1044 }
1045 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001046 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001048 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001049 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 strcpy(owner_group, "nobody");
1051 owner_grouplen = sizeof("nobody") - 1;
1052 /* goto out; */
1053 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001054 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001058 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1059 len += 16;
1060 } else if (iap->ia_valid & ATTR_ATIME) {
1061 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1062 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 }
1064 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001065 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1066 len += 16;
1067 } else if (iap->ia_valid & ATTR_MTIME) {
1068 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1069 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001071
1072 if (excl_check) {
1073 const u32 *excl_bmval = server->exclcreat_bitmask;
1074 bmval[0] &= excl_bmval[0];
1075 bmval[1] &= excl_bmval[1];
1076 bmval[2] &= excl_bmval[2];
1077
1078 if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL))
1079 label = NULL;
1080 }
1081
David Quigleyaa9c2662013-05-22 12:50:44 -04001082 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001083 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1084 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1085 }
1086
1087 if (bmval[2] != 0)
1088 bmval_len = 3;
1089 else if (bmval[1] != 0)
1090 bmval_len = 2;
1091 else
1092 bmval_len = 1;
1093
1094 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1095
1096 *p++ = cpu_to_be32(bmval_len);
1097 for (i = 0; i < bmval_len; i++)
1098 *p++ = cpu_to_be32(bmval[i]);
1099 *p++ = cpu_to_be32(len);
1100
1101 if (bmval[0] & FATTR4_WORD0_SIZE)
1102 p = xdr_encode_hyper(p, iap->ia_size);
1103 if (bmval[1] & FATTR4_WORD1_MODE)
1104 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1105 if (bmval[1] & FATTR4_WORD1_OWNER)
1106 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1107 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1108 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1109 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1110 if (iap->ia_valid & ATTR_ATIME_SET) {
1111 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1112 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1113 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1114 } else
1115 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1116 }
1117 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1118 if (iap->ia_valid & ATTR_MTIME_SET) {
1119 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1120 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1121 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1122 } else
1123 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1124 }
1125 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001126 *p++ = cpu_to_be32(label->lfs);
1127 *p++ = cpu_to_be32(label->pi);
1128 *p++ = cpu_to_be32(label->len);
1129 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1130 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133}
1134
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001135static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001137 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1138 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Trond Myklebustab19b482012-03-04 18:13:57 -05001143 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001144 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001145 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
Fred Isaman0b7c0152012-04-20 14:47:39 -04001148static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Al Viro8687b632006-10-19 23:28:48 -07001150 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001151
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001152 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1153 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001154 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001155 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156}
1157
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001158static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159{
Al Viro8687b632006-10-19 23:28:48 -07001160 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001161
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001162 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1163 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
1165 switch (create->ftype) {
1166 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001167 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001168 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001169 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1170 create->u.symlink.len);
1171 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 break;
1173
1174 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001175 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001176 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001177 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 break;
1179
1180 default:
1181 break;
1182 }
1183
Benny Halevy811652b2009-08-14 17:19:34 +03001184 encode_string(xdr, create->name->len, create->name->name);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001185 encode_attrs(xdr, create->attrs, create->label, create->server, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186}
1187
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001188static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
Andy Adamson05d564f2008-12-23 16:06:15 -05001190 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001192 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1193 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001194 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001195 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196}
1197
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001198static 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 -07001199{
Andy Adamson05d564f2008-12-23 16:06:15 -05001200 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001202 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1203 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001204 *p++ = cpu_to_be32(2);
1205 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001206 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207}
1208
Fred Isamandae100c2011-07-30 20:52:37 -04001209static void
1210encode_getattr_three(struct xdr_stream *xdr,
1211 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1212 struct compound_hdr *hdr)
1213{
1214 __be32 *p;
1215
Trond Myklebustab19b482012-03-04 18:13:57 -05001216 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001217 if (bm2) {
1218 p = reserve_space(xdr, 16);
1219 *p++ = cpu_to_be32(3);
1220 *p++ = cpu_to_be32(bm0);
1221 *p++ = cpu_to_be32(bm1);
1222 *p = cpu_to_be32(bm2);
1223 } else if (bm1) {
1224 p = reserve_space(xdr, 12);
1225 *p++ = cpu_to_be32(2);
1226 *p++ = cpu_to_be32(bm0);
1227 *p = cpu_to_be32(bm1);
1228 } else {
1229 p = reserve_space(xdr, 8);
1230 *p++ = cpu_to_be32(1);
1231 *p = cpu_to_be32(bm0);
1232 }
Fred Isamandae100c2011-07-30 20:52:37 -04001233}
1234
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001235static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236{
David Quigleya09df2c2013-05-22 12:50:41 -04001237 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1238 bitmask[1] & nfs4_fattr_bitmap[1],
1239 bitmask[2] & nfs4_fattr_bitmap[2],
1240 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241}
1242
Andy Adamson88034c32012-05-23 05:02:34 -04001243static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001244 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001245 struct compound_hdr *hdr)
1246{
1247 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001248 bitmask[0] & open_bitmap[0],
1249 bitmask[1] & open_bitmap[1],
1250 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001251 hdr);
1252}
1253
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001254static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255{
Fred Isamandae100c2011-07-30 20:52:37 -04001256 encode_getattr_three(xdr,
1257 bitmask[0] & nfs4_fsinfo_bitmap[0],
1258 bitmask[1] & nfs4_fsinfo_bitmap[1],
1259 bitmask[2] & nfs4_fsinfo_bitmap[2],
1260 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261}
1262
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001263static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001264{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001265 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1266 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001267}
1268
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001269static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
Trond Myklebustab19b482012-03-04 18:13:57 -05001271 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272}
1273
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001274static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275{
Trond Myklebustab19b482012-03-04 18:13:57 -05001276 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001277 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278}
1279
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001280static inline int nfs4_lock_type(struct file_lock *fl, int block)
1281{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001282 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001283 return block ? NFS4_READW_LT : NFS4_READ_LT;
1284 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1285}
1286
1287static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1288{
1289 if (fl->fl_end == OFFSET_MAX)
1290 return ~(uint64_t)0;
1291 return fl->fl_end - fl->fl_start + 1;
1292}
1293
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001294static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1295{
1296 __be32 *p;
1297
Trond Myklebustd035c362010-12-21 10:45:27 -05001298 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001299 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001300 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001301 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001302 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001303 xdr_encode_hyper(p, lowner->id);
1304}
1305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306/*
1307 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1308 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1309 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001310static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311{
Al Viro8687b632006-10-19 23:28:48 -07001312 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001314 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1315 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001316 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1317 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001318 p = xdr_encode_hyper(p, args->fl->fl_start);
1319 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001320 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001321 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001322 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001323 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001324 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001325 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 }
1327 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001328 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001329 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001333static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_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_LOCKT, decode_lockt_maxsz, hdr);
1338 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001339 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001340 p = xdr_encode_hyper(p, args->fl->fl_start);
1341 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001342 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343}
1344
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001345static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
Al Viro8687b632006-10-19 23:28:48 -07001347 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001349 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1350 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001351 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001352 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001353 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001354 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001355 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356}
1357
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001358static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1359{
Trond Myklebustab19b482012-03-04 18:13:57 -05001360 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001361 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001362}
1363
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001364static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365{
Trond Myklebustab19b482012-03-04 18:13:57 -05001366 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001367 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368}
1369
Trond Myklebust6ae37332015-01-30 14:21:14 -05001370static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371{
Al Viro8687b632006-10-19 23:28:48 -07001372 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
Benny Halevy13c65ce2009-08-14 17:19:25 +03001374 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001375 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001376 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377}
1378
1379static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1380{
Al Viro8687b632006-10-19 23:28:48 -07001381 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 /*
1383 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1384 * owner 4 = 32
1385 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001386 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001387 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001388 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001389 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001390 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001391 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001392 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001393 *p++ = cpu_to_be32(arg->id.uniquifier);
1394 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395}
1396
1397static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1398{
Al Viro8687b632006-10-19 23:28:48 -07001399 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Benny Halevy13c65ce2009-08-14 17:19:25 +03001401 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001402 switch(arg->createmode) {
1403 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001404 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001405 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false);
Andy Adamson05d564f2008-12-23 16:06:15 -05001406 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001407 case NFS4_CREATE_GUARDED:
1408 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001409 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001410 break;
1411 case NFS4_CREATE_EXCLUSIVE:
1412 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1413 encode_nfs4_verifier(xdr, &arg->u.verifier);
1414 break;
1415 case NFS4_CREATE_EXCLUSIVE4_1:
1416 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1417 encode_nfs4_verifier(xdr, &arg->u.verifier);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001418 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 }
1420}
1421
1422static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1423{
Al Viro8687b632006-10-19 23:28:48 -07001424 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Benny Halevy13c65ce2009-08-14 17:19:25 +03001426 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001428 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001429 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001430 break;
1431 default:
Benny Halevy34558512009-08-14 17:19:30 +03001432 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001433 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 }
1435}
1436
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001437static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438{
Al Viro8687b632006-10-19 23:28:48 -07001439 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Benny Halevy13c65ce2009-08-14 17:19:25 +03001441 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001443 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001444 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001445 break;
1446 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001447 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001448 break;
1449 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001450 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001451 break;
1452 default:
1453 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 }
1455}
1456
1457static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1458{
Al Viro8687b632006-10-19 23:28:48 -07001459 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
Benny Halevy13c65ce2009-08-14 17:19:25 +03001461 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001462 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 encode_string(xdr, name->len, name->name);
1464}
1465
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001466static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
Al Viro8687b632006-10-19 23:28:48 -07001468 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Benny Halevy13c65ce2009-08-14 17:19:25 +03001470 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001471 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 encode_delegation_type(xdr, type);
1473}
1474
1475static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1476{
Al Viro8687b632006-10-19 23:28:48 -07001477 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001479 p = reserve_space(xdr, 4);
1480 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1481 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 encode_string(xdr, name->len, name->name);
1483}
1484
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001485static inline void encode_claim_fh(struct xdr_stream *xdr)
1486{
1487 __be32 *p;
1488
1489 p = reserve_space(xdr, 4);
1490 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1491}
1492
1493static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1494{
1495 __be32 *p;
1496
1497 p = reserve_space(xdr, 4);
1498 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1499 encode_nfs4_stateid(xdr, stateid);
1500}
1501
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001502static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503{
Trond Myklebustab19b482012-03-04 18:13:57 -05001504 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 encode_openhdr(xdr, arg);
1506 encode_opentype(xdr, arg);
1507 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001508 case NFS4_OPEN_CLAIM_NULL:
1509 encode_claim_null(xdr, arg->name);
1510 break;
1511 case NFS4_OPEN_CLAIM_PREVIOUS:
1512 encode_claim_previous(xdr, arg->u.delegation_type);
1513 break;
1514 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1515 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1516 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001517 case NFS4_OPEN_CLAIM_FH:
1518 encode_claim_fh(xdr);
1519 break;
1520 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1521 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1522 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001523 default:
1524 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526}
1527
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001528static 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 -07001529{
Trond Myklebustab19b482012-03-04 18:13:57 -05001530 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001531 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001532 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533}
1534
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001535static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536{
Trond Myklebustab19b482012-03-04 18:13:57 -05001537 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001538 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001539 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001540 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
1542
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001543static void
Andy Adamsond0179312008-12-23 16:06:17 -05001544encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
Trond Myklebustab19b482012-03-04 18:13:57 -05001546 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001547 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001550static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
Trond Myklebustab19b482012-03-04 18:13:57 -05001552 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553}
1554
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001555static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1556 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Al Viro8687b632006-10-19 23:28:48 -07001558 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Trond Myklebustab19b482012-03-04 18:13:57 -05001560 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001561 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Benny Halevy13c65ce2009-08-14 17:19:25 +03001563 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001564 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001565 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566}
1567
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001568static 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 -07001569{
David Quigleyaa9c2662013-05-22 12:50:44 -04001570 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001571 FATTR4_WORD0_RDATTR_ERROR,
1572 FATTR4_WORD1_MOUNTED_ON_FILEID,
1573 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001574 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001575 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001576 uint32_t attrlen = 0;
1577 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001579 if (readdir->plus) {
1580 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001581 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001582 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1583 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1584 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1585 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001586 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001587 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001588 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001589 /* Use mounted_on_fileid only if the server supports it */
1590 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1591 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001592 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1593 attrs[i] &= readdir->bitmask[i];
1594 if (attrs[i] != 0)
1595 attrlen = i+1;
1596 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001597
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001598 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001599 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001600 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001601 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001602 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001603 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001604 *p++ = cpu_to_be32(attrlen);
1605 for (i = 0; i < attrlen; i++)
1606 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001607 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001608
1609 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001610 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001611 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001612 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001613 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001614 attrs[1] & readdir->bitmask[1],
1615 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616}
1617
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001618static 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 -07001619{
Trond Myklebustab19b482012-03-04 18:13:57 -05001620 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001623static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
Trond Myklebustab19b482012-03-04 18:13:57 -05001625 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001626 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001629static 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 -07001630{
Trond Myklebustab19b482012-03-04 18:13:57 -05001631 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001632 encode_string(xdr, oldname->len, oldname->name);
1633 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634}
1635
Chuck Leverbb4dae52012-03-01 17:01:48 -05001636static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1637 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001639 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001640 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641}
1642
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001643static void
Andy Adamsond0179312008-12-23 16:06:17 -05001644encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001645{
Trond Myklebustab19b482012-03-04 18:13:57 -05001646 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001647}
1648
Chuck Lever9f06c712010-12-14 14:59:18 +00001649static void
Andy Adamsond0179312008-12-23 16:06:17 -05001650encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001651{
Al Viro8687b632006-10-19 23:28:48 -07001652 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001653
Trond Myklebustab19b482012-03-04 18:13:57 -05001654 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001655 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001656 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001657 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001658 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001659 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001660 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001661 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001662}
1663
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001664static void
Andy Adamsond0179312008-12-23 16:06:17 -05001665encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666{
Trond Myklebustab19b482012-03-04 18:13:57 -05001667 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668}
1669
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001670static 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 -07001671{
Trond Myklebustab19b482012-03-04 18:13:57 -05001672 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001673 encode_nfs4_stateid(xdr, &arg->stateid);
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001674 encode_attrs(xdr, arg->iap, arg->label, server, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675}
1676
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001677static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678{
Al Viro8687b632006-10-19 23:28:48 -07001679 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
Trond Myklebust70019512012-03-04 20:49:32 -05001681 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001682 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683
Jeff Layton3a6bb732015-06-09 19:43:57 -04001684 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1685 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001686 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001687 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1689 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001690 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001691 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692}
1693
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001694static 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 -07001695{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001696 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1697 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001698 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001699 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
1701
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001702static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1703 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704{
Al Viro8687b632006-10-19 23:28:48 -07001705 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Trond Myklebustab19b482012-03-04 18:13:57 -05001707 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001708 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Benny Halevy13c65ce2009-08-14 17:19:25 +03001710 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001711 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001712 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001713 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
1715 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
1717
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001718static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719{
Trond Myklebustab19b482012-03-04 18:13:57 -05001720 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001721 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001723
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001724static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1725{
Trond Myklebustab19b482012-03-04 18:13:57 -05001726 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001727 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001728}
1729
Benny Halevy99fe60d2009-04-01 09:22:29 -04001730#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001731/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001732static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08001733 struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001734 struct compound_hdr *hdr)
1735{
1736 __be32 *p;
1737
1738 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1739 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001740 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001741 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001742 *p++ = cpu_to_be32(args->dir);
1743 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001744}
1745
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001746static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1747{
1748 unsigned int i;
1749 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1750 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1751 encode_uint32(xdr, op_map->u.words[i]);
1752}
1753
Benny Halevy99fe60d2009-04-01 09:22:29 -04001754static void encode_exchange_id(struct xdr_stream *xdr,
1755 struct nfs41_exchange_id_args *args,
1756 struct compound_hdr *hdr)
1757{
1758 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001759 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001760 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001761
Trond Myklebust70019512012-03-04 20:49:32 -05001762 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001763 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001764
Jeff Layton3a6bb732015-06-09 19:43:57 -04001765 encode_string(xdr, strlen(args->client->cl_owner_id),
1766 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001767
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001768 encode_uint32(xdr, args->flags);
1769 encode_uint32(xdr, args->state_protect.how);
1770
1771 switch (args->state_protect.how) {
1772 case SP4_NONE:
1773 break;
1774 case SP4_MACH_CRED:
1775 encode_op_map(xdr, &args->state_protect.enforce);
1776 encode_op_map(xdr, &args->state_protect.allow);
1777 break;
1778 default:
1779 WARN_ON_ONCE(1);
1780 break;
1781 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001782
1783 if (send_implementation_id &&
1784 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1785 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001786 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001787 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1788 utsname()->sysname, utsname()->release,
1789 utsname()->version, utsname()->machine);
1790
1791 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001792 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001793
1794 encode_string(xdr,
1795 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1796 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1797 encode_string(xdr, len, impl_name);
1798 /* just send zeros for nii_date - the date is in nii_name */
1799 p = reserve_space(xdr, 12);
1800 p = xdr_encode_hyper(p, 0);
1801 *p = cpu_to_be32(0);
1802 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001803 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001804}
Andy Adamsonfc931582009-04-01 09:22:31 -04001805
1806static void encode_create_session(struct xdr_stream *xdr,
1807 struct nfs41_create_session_args *args,
1808 struct compound_hdr *hdr)
1809{
1810 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001811 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001812 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001813 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001814 u32 max_resp_sz_cached;
1815
1816 /*
1817 * Assumes OPEN is the biggest non-idempotent compound.
1818 * 2 is the verifier.
1819 */
1820 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1821 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001822
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001823 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001824 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001825 p = xdr_encode_hyper(p, args->clientid);
1826 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001827 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001828
Andy Adamsonfc931582009-04-01 09:22:31 -04001829 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001830 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001831 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1832 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001833 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001834 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1835 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1836 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001837
1838 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001839 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001840 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1841 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1842 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1843 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1844 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1845 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001846
Benny Halevye75bc1c2009-08-14 17:18:54 +03001847 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001848 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001849 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001850
1851 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001852 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001853 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001854 *p++ = cpu_to_be32(0); /* UID */
1855 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001856 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001857}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001858
1859static void encode_destroy_session(struct xdr_stream *xdr,
1860 struct nfs4_session *session,
1861 struct compound_hdr *hdr)
1862{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001863 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1864 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001865}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001866
Trond Myklebust66245532012-05-25 17:18:09 -04001867static void encode_destroy_clientid(struct xdr_stream *xdr,
1868 uint64_t clientid,
1869 struct compound_hdr *hdr)
1870{
1871 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1872 encode_uint64(xdr, clientid);
1873}
1874
Ricardo Labiaga180197532009-12-05 16:08:40 -05001875static void encode_reclaim_complete(struct xdr_stream *xdr,
1876 struct nfs41_reclaim_complete_args *args,
1877 struct compound_hdr *hdr)
1878{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001879 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1880 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001881}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001882#endif /* CONFIG_NFS_V4_1 */
1883
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001884static void encode_sequence(struct xdr_stream *xdr,
1885 const struct nfs4_sequence_args *args,
1886 struct compound_hdr *hdr)
1887{
1888#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001889 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001890 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001891 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001892 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001893
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001894 tp = slot->table;
1895 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001896 if (!session)
1897 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001898
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001899 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001900
1901 /*
1902 * Sessionid + seqid + slotid + max slotid + cache_this
1903 */
1904 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1905 "max_slotid=%d cache_this=%d\n",
1906 __func__,
1907 ((u32 *)session->sess_id.data)[0],
1908 ((u32 *)session->sess_id.data)[1],
1909 ((u32 *)session->sess_id.data)[2],
1910 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001911 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001912 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001913 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001914 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001915 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001916 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001917 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001918 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001919#endif /* CONFIG_NFS_V4_1 */
1920}
1921
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001922#ifdef CONFIG_NFS_V4_1
1923static void
1924encode_getdeviceinfo(struct xdr_stream *xdr,
1925 const struct nfs4_getdeviceinfo_args *args,
1926 struct compound_hdr *hdr)
1927{
1928 __be32 *p;
1929
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001930 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001931 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001932 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1933 NFS4_DEVICEID4_SIZE);
1934 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001935 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001936
1937 p = reserve_space(xdr, 4 + 4);
1938 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001939 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001940}
1941
1942static void
1943encode_layoutget(struct xdr_stream *xdr,
1944 const struct nfs4_layoutget_args *args,
1945 struct compound_hdr *hdr)
1946{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001947 __be32 *p;
1948
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001949 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1950 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001951 *p++ = cpu_to_be32(0); /* Signal layout available */
1952 *p++ = cpu_to_be32(args->type);
1953 *p++ = cpu_to_be32(args->range.iomode);
1954 p = xdr_encode_hyper(p, args->range.offset);
1955 p = xdr_encode_hyper(p, args->range.length);
1956 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001957 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001958 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001959
1960 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1961 __func__,
1962 args->type,
1963 args->range.iomode,
1964 (unsigned long)args->range.offset,
1965 (unsigned long)args->range.length,
1966 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001967}
Andy Adamson863a3c62011-03-23 13:27:54 +00001968
1969static int
1970encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001971 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001972 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001973 struct compound_hdr *hdr)
1974{
1975 __be32 *p;
1976
1977 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1978 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1979
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001980 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1981 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001982 /* Only whole file layouts */
1983 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001984 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001985 *p = cpu_to_be32(0); /* reclaim */
1986 encode_nfs4_stateid(xdr, &args->stateid);
1987 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001988 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1989 p = xdr_encode_hyper(p, args->lastbytewritten);
1990 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1991 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001992
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001993 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03001994 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1995 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001996 } else {
1997 encode_uint32(xdr, args->layoutupdate_len);
1998 if (args->layoutupdate_pages) {
1999 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2000 args->layoutupdate_len);
2001 }
2002 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002003
Andy Adamson863a3c62011-03-23 13:27:54 +00002004 return 0;
2005}
Benny Halevycbe82602011-05-22 19:52:37 +03002006
2007static void
2008encode_layoutreturn(struct xdr_stream *xdr,
2009 const struct nfs4_layoutreturn_args *args,
2010 struct compound_hdr *hdr)
2011{
2012 __be32 *p;
2013
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002014 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2015 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002016 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2017 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002018 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002019 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002020 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002021 p = xdr_encode_hyper(p, args->range.offset);
2022 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002023 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002024 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002025 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002026 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2027 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2028 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002029 } else
2030 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002031}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002032
2033static int
2034encode_secinfo_no_name(struct xdr_stream *xdr,
2035 const struct nfs41_secinfo_no_name_args *args,
2036 struct compound_hdr *hdr)
2037{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002038 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2039 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002040 return 0;
2041}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002042
2043static void encode_test_stateid(struct xdr_stream *xdr,
2044 struct nfs41_test_stateid_args *args,
2045 struct compound_hdr *hdr)
2046{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002047 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2048 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002049 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002050}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002051
2052static void encode_free_stateid(struct xdr_stream *xdr,
2053 struct nfs41_free_stateid_args *args,
2054 struct compound_hdr *hdr)
2055{
Trond Myklebustab19b482012-03-04 18:13:57 -05002056 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002057 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002058}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002059#endif /* CONFIG_NFS_V4_1 */
2060
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061/*
2062 * END OF "GENERIC" ENCODE ROUTINES.
2063 */
2064
Benny Halevy66cc0422009-04-01 09:22:10 -04002065static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2066{
2067#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002068 struct nfs4_session *session = args->sa_slot->table->session;
2069 if (session)
2070 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002071#endif /* CONFIG_NFS_V4_1 */
2072 return 0;
2073}
2074
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075/*
2076 * Encode an ACCESS request
2077 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002078static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2079 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002082 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
Chuck Lever9f06c712010-12-14 14:59:18 +00002085 encode_compound_hdr(xdr, req, &hdr);
2086 encode_sequence(xdr, &args->seq_args, &hdr);
2087 encode_putfh(xdr, args->fh, &hdr);
2088 encode_access(xdr, args->access, &hdr);
2089 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002090 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091}
2092
2093/*
2094 * Encode LOOKUP request
2095 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002096static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2097 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002100 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
Chuck Lever9f06c712010-12-14 14:59:18 +00002103 encode_compound_hdr(xdr, req, &hdr);
2104 encode_sequence(xdr, &args->seq_args, &hdr);
2105 encode_putfh(xdr, args->dir_fh, &hdr);
2106 encode_lookup(xdr, args->name, &hdr);
2107 encode_getfh(xdr, &hdr);
2108 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002109 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110}
2111
2112/*
2113 * Encode LOOKUP_ROOT request
2114 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002115static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2116 struct xdr_stream *xdr,
2117 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002120 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
Chuck Lever9f06c712010-12-14 14:59:18 +00002123 encode_compound_hdr(xdr, req, &hdr);
2124 encode_sequence(xdr, &args->seq_args, &hdr);
2125 encode_putrootfh(xdr, &hdr);
2126 encode_getfh(xdr, &hdr);
2127 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002128 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129}
2130
2131/*
2132 * Encode REMOVE request
2133 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002134static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2135 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002138 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Chuck Lever9f06c712010-12-14 14:59:18 +00002141 encode_compound_hdr(xdr, req, &hdr);
2142 encode_sequence(xdr, &args->seq_args, &hdr);
2143 encode_putfh(xdr, args->fh, &hdr);
2144 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002145 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146}
2147
2148/*
2149 * Encode RENAME request
2150 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002151static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2152 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002155 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
Chuck Lever9f06c712010-12-14 14:59:18 +00002158 encode_compound_hdr(xdr, req, &hdr);
2159 encode_sequence(xdr, &args->seq_args, &hdr);
2160 encode_putfh(xdr, args->old_dir, &hdr);
2161 encode_savefh(xdr, &hdr);
2162 encode_putfh(xdr, args->new_dir, &hdr);
2163 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002164 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165}
2166
2167/*
2168 * Encode LINK request
2169 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002170static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2171 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002174 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
Chuck Lever9f06c712010-12-14 14:59:18 +00002177 encode_compound_hdr(xdr, req, &hdr);
2178 encode_sequence(xdr, &args->seq_args, &hdr);
2179 encode_putfh(xdr, args->fh, &hdr);
2180 encode_savefh(xdr, &hdr);
2181 encode_putfh(xdr, args->dir_fh, &hdr);
2182 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002183 encode_restorefh(xdr, &hdr);
2184 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002185 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
2188/*
2189 * Encode CREATE request
2190 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002191static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2192 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002195 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
Chuck Lever9f06c712010-12-14 14:59:18 +00002198 encode_compound_hdr(xdr, req, &hdr);
2199 encode_sequence(xdr, &args->seq_args, &hdr);
2200 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002201 encode_create(xdr, args, &hdr);
2202 encode_getfh(xdr, &hdr);
2203 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002204 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205}
2206
2207/*
2208 * Encode SYMLINK request
2209 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002210static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2211 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212{
Chuck Lever9f06c712010-12-14 14:59:18 +00002213 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214}
2215
2216/*
2217 * Encode GETATTR request
2218 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002219static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2220 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002223 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
Chuck Lever9f06c712010-12-14 14:59:18 +00002226 encode_compound_hdr(xdr, req, &hdr);
2227 encode_sequence(xdr, &args->seq_args, &hdr);
2228 encode_putfh(xdr, args->fh, &hdr);
2229 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002230 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231}
2232
2233/*
2234 * Encode a CLOSE request
2235 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002236static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2237 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238{
Andy Adamson05d564f2008-12-23 16:06:15 -05002239 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002240 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002241 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Chuck Lever9f06c712010-12-14 14:59:18 +00002243 encode_compound_hdr(xdr, req, &hdr);
2244 encode_sequence(xdr, &args->seq_args, &hdr);
2245 encode_putfh(xdr, args->fh, &hdr);
2246 encode_close(xdr, args, &hdr);
2247 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002248 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249}
2250
2251/*
2252 * Encode an OPEN request
2253 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002254static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2255 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002258 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
Chuck Lever9f06c712010-12-14 14:59:18 +00002261 encode_compound_hdr(xdr, req, &hdr);
2262 encode_sequence(xdr, &args->seq_args, &hdr);
2263 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002264 encode_open(xdr, args, &hdr);
2265 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002266 if (args->access)
2267 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002268 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002269 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270}
2271
2272/*
2273 * Encode an OPEN_CONFIRM request
2274 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002275static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2276 struct xdr_stream *xdr,
2277 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002280 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282
Chuck Lever9f06c712010-12-14 14:59:18 +00002283 encode_compound_hdr(xdr, req, &hdr);
2284 encode_putfh(xdr, args->fh, &hdr);
2285 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002286 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287}
2288
2289/*
2290 * Encode an OPEN request with no attributes.
2291 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002292static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2293 struct xdr_stream *xdr,
2294 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002297 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
Chuck Lever9f06c712010-12-14 14:59:18 +00002300 encode_compound_hdr(xdr, req, &hdr);
2301 encode_sequence(xdr, &args->seq_args, &hdr);
2302 encode_putfh(xdr, args->fh, &hdr);
2303 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002304 if (args->access)
2305 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002306 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002307 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308}
2309
2310/*
2311 * Encode an OPEN_DOWNGRADE request
2312 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002313static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2314 struct xdr_stream *xdr,
2315 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002318 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Chuck Lever9f06c712010-12-14 14:59:18 +00002321 encode_compound_hdr(xdr, req, &hdr);
2322 encode_sequence(xdr, &args->seq_args, &hdr);
2323 encode_putfh(xdr, args->fh, &hdr);
2324 encode_open_downgrade(xdr, args, &hdr);
2325 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002326 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327}
2328
2329/*
2330 * Encode a LOCK request
2331 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002332static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2333 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002336 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Chuck Lever9f06c712010-12-14 14:59:18 +00002339 encode_compound_hdr(xdr, req, &hdr);
2340 encode_sequence(xdr, &args->seq_args, &hdr);
2341 encode_putfh(xdr, args->fh, &hdr);
2342 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002343 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344}
2345
2346/*
2347 * Encode a LOCKT request
2348 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002349static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2350 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002353 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Chuck Lever9f06c712010-12-14 14:59:18 +00002356 encode_compound_hdr(xdr, req, &hdr);
2357 encode_sequence(xdr, &args->seq_args, &hdr);
2358 encode_putfh(xdr, args->fh, &hdr);
2359 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002360 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361}
2362
2363/*
2364 * Encode a LOCKU request
2365 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002366static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2367 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002370 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372
Chuck Lever9f06c712010-12-14 14:59:18 +00002373 encode_compound_hdr(xdr, req, &hdr);
2374 encode_sequence(xdr, &args->seq_args, &hdr);
2375 encode_putfh(xdr, args->fh, &hdr);
2376 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002377 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378}
2379
Chuck Lever9f06c712010-12-14 14:59:18 +00002380static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2381 struct xdr_stream *xdr,
2382 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002383{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002384 struct compound_hdr hdr = {
2385 .minorversion = 0,
2386 };
2387
Chuck Lever9f06c712010-12-14 14:59:18 +00002388 encode_compound_hdr(xdr, req, &hdr);
2389 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002390 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002391}
2392
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393/*
2394 * Encode a READLINK request
2395 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002396static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2397 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002400 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
Chuck Lever9f06c712010-12-14 14:59:18 +00002403 encode_compound_hdr(xdr, req, &hdr);
2404 encode_sequence(xdr, &args->seq_args, &hdr);
2405 encode_putfh(xdr, args->fh, &hdr);
2406 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002407
Benny Halevy28f56692009-04-01 09:22:09 -04002408 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002409 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002410 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411}
2412
2413/*
2414 * Encode a READDIR request
2415 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002416static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2417 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002420 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422
Chuck Lever9f06c712010-12-14 14:59:18 +00002423 encode_compound_hdr(xdr, req, &hdr);
2424 encode_sequence(xdr, &args->seq_args, &hdr);
2425 encode_putfh(xdr, args->fh, &hdr);
2426 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002427
Benny Halevy28f56692009-04-01 09:22:09 -04002428 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002429 args->pgbase, args->count);
2430 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002431 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002432 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002433 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434}
2435
2436/*
2437 * Encode a READ request
2438 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002439static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002440 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002443 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Chuck Lever9f06c712010-12-14 14:59:18 +00002446 encode_compound_hdr(xdr, req, &hdr);
2447 encode_sequence(xdr, &args->seq_args, &hdr);
2448 encode_putfh(xdr, args->fh, &hdr);
2449 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Benny Halevy28f56692009-04-01 09:22:09 -04002451 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002453 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002454 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455}
2456
2457/*
2458 * Encode an SETATTR request
2459 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002460static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2461 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462{
Andy Adamson05d564f2008-12-23 16:06:15 -05002463 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002464 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002465 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466
Chuck Lever9f06c712010-12-14 14:59:18 +00002467 encode_compound_hdr(xdr, req, &hdr);
2468 encode_sequence(xdr, &args->seq_args, &hdr);
2469 encode_putfh(xdr, args->fh, &hdr);
2470 encode_setattr(xdr, args, args->server, &hdr);
2471 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002472 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473}
2474
2475/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002476 * Encode a GETACL request
2477 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002478static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2479 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002480{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002481 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002482 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002483 };
Benny Halevy28f56692009-04-01 09:22:09 -04002484 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002485
Chuck Lever9f06c712010-12-14 14:59:18 +00002486 encode_compound_hdr(xdr, req, &hdr);
2487 encode_sequence(xdr, &args->seq_args, &hdr);
2488 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002489 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002490 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002491
Benny Halevy28f56692009-04-01 09:22:09 -04002492 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002493 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002494
Andy Adamsond0179312008-12-23 16:06:17 -05002495 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002496}
2497
2498/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 * Encode a WRITE request
2500 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002501static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002502 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002505 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507
Chuck Lever9f06c712010-12-14 14:59:18 +00002508 encode_compound_hdr(xdr, req, &hdr);
2509 encode_sequence(xdr, &args->seq_args, &hdr);
2510 encode_putfh(xdr, args->fh, &hdr);
2511 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002512 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002513 if (args->bitmask)
2514 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002515 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516}
2517
2518/*
2519 * a COMMIT request
2520 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002521static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002522 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002525 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527
Chuck Lever9f06c712010-12-14 14:59:18 +00002528 encode_compound_hdr(xdr, req, &hdr);
2529 encode_sequence(xdr, &args->seq_args, &hdr);
2530 encode_putfh(xdr, args->fh, &hdr);
2531 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002532 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533}
2534
2535/*
2536 * FSINFO request
2537 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002538static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2539 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002542 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544
Chuck Lever9f06c712010-12-14 14:59:18 +00002545 encode_compound_hdr(xdr, req, &hdr);
2546 encode_sequence(xdr, &args->seq_args, &hdr);
2547 encode_putfh(xdr, args->fh, &hdr);
2548 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002549 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550}
2551
2552/*
2553 * a PATHCONF request
2554 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002555static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2556 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002559 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
Chuck Lever9f06c712010-12-14 14:59:18 +00002562 encode_compound_hdr(xdr, req, &hdr);
2563 encode_sequence(xdr, &args->seq_args, &hdr);
2564 encode_putfh(xdr, args->fh, &hdr);
2565 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002566 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002567 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568}
2569
2570/*
2571 * a STATFS request
2572 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002573static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2574 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002577 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579
Chuck Lever9f06c712010-12-14 14:59:18 +00002580 encode_compound_hdr(xdr, req, &hdr);
2581 encode_sequence(xdr, &args->seq_args, &hdr);
2582 encode_putfh(xdr, args->fh, &hdr);
2583 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002584 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002585 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586}
2587
2588/*
2589 * GETATTR_BITMAP request
2590 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002591static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2592 struct xdr_stream *xdr,
2593 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594{
Kinglong Mee8c612822015-08-26 21:12:58 +08002595 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002597 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
Chuck Lever9f06c712010-12-14 14:59:18 +00002600 encode_compound_hdr(xdr, req, &hdr);
2601 encode_sequence(xdr, &args->seq_args, &hdr);
2602 encode_putfh(xdr, args->fhandle, &hdr);
Kinglong Mee8c612822015-08-26 21:12:58 +08002603 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002604 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605}
2606
2607/*
2608 * a RENEW request
2609 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002610static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2611 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002614 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 };
2616
Chuck Lever9f06c712010-12-14 14:59:18 +00002617 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002618 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002619 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620}
2621
2622/*
2623 * a SETCLIENTID request
2624 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002625static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2626 struct xdr_stream *xdr,
2627 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002630 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 };
2632
Chuck Lever9f06c712010-12-14 14:59:18 +00002633 encode_compound_hdr(xdr, req, &hdr);
2634 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002635 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636}
2637
2638/*
2639 * a SETCLIENTID_CONFIRM request
2640 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002641static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2642 struct xdr_stream *xdr,
2643 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002646 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648
Chuck Lever9f06c712010-12-14 14:59:18 +00002649 encode_compound_hdr(xdr, req, &hdr);
2650 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002651 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652}
2653
2654/*
2655 * DELEGRETURN request
2656 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002657static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2658 struct xdr_stream *xdr,
2659 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002662 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
Chuck Lever9f06c712010-12-14 14:59:18 +00002665 encode_compound_hdr(xdr, req, &hdr);
2666 encode_sequence(xdr, &args->seq_args, &hdr);
2667 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002668 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002669 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002670 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671}
2672
2673/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002674 * Encode FS_LOCATIONS request
2675 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002676static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2677 struct xdr_stream *xdr,
2678 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002679{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002680 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002681 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002682 };
Benny Halevy28f56692009-04-01 09:22:09 -04002683 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002684
Chuck Lever9f06c712010-12-14 14:59:18 +00002685 encode_compound_hdr(xdr, req, &hdr);
2686 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002687 if (args->migration) {
2688 encode_putfh(xdr, args->fh, &hdr);
2689 replen = hdr.replen;
2690 encode_fs_locations(xdr, args->bitmask, &hdr);
2691 if (args->renew)
2692 encode_renew(xdr, args->clientid, &hdr);
2693 } else {
2694 encode_putfh(xdr, args->dir_fh, &hdr);
2695 encode_lookup(xdr, args->name, &hdr);
2696 replen = hdr.replen;
2697 encode_fs_locations(xdr, args->bitmask, &hdr);
2698 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002699
Chuck Leverb03d7352013-10-17 14:12:50 -04002700 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002701 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002702 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002703 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002704}
2705
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002706/*
2707 * Encode SECINFO request
2708 */
2709static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2710 struct xdr_stream *xdr,
2711 struct nfs4_secinfo_arg *args)
2712{
2713 struct compound_hdr hdr = {
2714 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2715 };
2716
2717 encode_compound_hdr(xdr, req, &hdr);
2718 encode_sequence(xdr, &args->seq_args, &hdr);
2719 encode_putfh(xdr, args->dir_fh, &hdr);
2720 encode_secinfo(xdr, args->name, &hdr);
2721 encode_nops(&hdr);
2722}
2723
Chuck Lever44c99932013-10-17 14:13:30 -04002724/*
2725 * Encode FSID_PRESENT request
2726 */
2727static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2728 struct xdr_stream *xdr,
2729 struct nfs4_fsid_present_arg *args)
2730{
2731 struct compound_hdr hdr = {
2732 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2733 };
2734
2735 encode_compound_hdr(xdr, req, &hdr);
2736 encode_sequence(xdr, &args->seq_args, &hdr);
2737 encode_putfh(xdr, args->fh, &hdr);
2738 encode_getfh(xdr, &hdr);
2739 if (args->renew)
2740 encode_renew(xdr, args->clientid, &hdr);
2741 encode_nops(&hdr);
2742}
2743
Benny Halevy99fe60d2009-04-01 09:22:29 -04002744#if defined(CONFIG_NFS_V4_1)
2745/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002746 * BIND_CONN_TO_SESSION request
2747 */
2748static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2749 struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08002750 struct nfs41_bind_conn_to_session_args *args)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002751{
2752 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002753 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002754 };
2755
2756 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002757 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002758 encode_nops(&hdr);
2759}
2760
2761/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002762 * EXCHANGE_ID request
2763 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002764static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2765 struct xdr_stream *xdr,
2766 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002767{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002768 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002769 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002770 };
2771
Chuck Lever9f06c712010-12-14 14:59:18 +00002772 encode_compound_hdr(xdr, req, &hdr);
2773 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002774 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002775}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002776
2777/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002778 * a CREATE_SESSION request
2779 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002780static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2781 struct xdr_stream *xdr,
2782 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002783{
Andy Adamsonfc931582009-04-01 09:22:31 -04002784 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002785 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002786 };
2787
Chuck Lever9f06c712010-12-14 14:59:18 +00002788 encode_compound_hdr(xdr, req, &hdr);
2789 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002790 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002791}
2792
2793/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002794 * a DESTROY_SESSION request
2795 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002796static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2797 struct xdr_stream *xdr,
2798 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002799{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002800 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002801 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002802 };
2803
Chuck Lever9f06c712010-12-14 14:59:18 +00002804 encode_compound_hdr(xdr, req, &hdr);
2805 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002806 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002807}
2808
2809/*
Trond Myklebust66245532012-05-25 17:18:09 -04002810 * a DESTROY_CLIENTID request
2811 */
2812static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2813 struct xdr_stream *xdr,
2814 struct nfs_client *clp)
2815{
2816 struct compound_hdr hdr = {
2817 .minorversion = clp->cl_mvops->minor_version,
2818 };
2819
2820 encode_compound_hdr(xdr, req, &hdr);
2821 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2822 encode_nops(&hdr);
2823}
2824
2825/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002826 * a SEQUENCE request
2827 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002828static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2829 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002830{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002831 struct compound_hdr hdr = {
2832 .minorversion = nfs4_xdr_minorversion(args),
2833 };
2834
Chuck Lever9f06c712010-12-14 14:59:18 +00002835 encode_compound_hdr(xdr, req, &hdr);
2836 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002837 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002838}
2839
2840/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002841 * a GET_LEASE_TIME request
2842 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002843static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2844 struct xdr_stream *xdr,
2845 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002846{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002847 struct compound_hdr hdr = {
2848 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2849 };
Fred Isamandae100c2011-07-30 20:52:37 -04002850 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002851
Chuck Lever9f06c712010-12-14 14:59:18 +00002852 encode_compound_hdr(xdr, req, &hdr);
2853 encode_sequence(xdr, &args->la_seq_args, &hdr);
2854 encode_putrootfh(xdr, &hdr);
2855 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002856 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002857}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002858
2859/*
2860 * a RECLAIM_COMPLETE request
2861 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002862static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2863 struct xdr_stream *xdr,
2864 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002865{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002866 struct compound_hdr hdr = {
2867 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2868 };
2869
Chuck Lever9f06c712010-12-14 14:59:18 +00002870 encode_compound_hdr(xdr, req, &hdr);
2871 encode_sequence(xdr, &args->seq_args, &hdr);
2872 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002873 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002874}
2875
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002876/*
2877 * Encode GETDEVICEINFO request
2878 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002879static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2880 struct xdr_stream *xdr,
2881 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002882{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002883 struct compound_hdr hdr = {
2884 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2885 };
2886
Chuck Lever9f06c712010-12-14 14:59:18 +00002887 encode_compound_hdr(xdr, req, &hdr);
2888 encode_sequence(xdr, &args->seq_args, &hdr);
2889 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002890
2891 /* set up reply kvec. Subtract notification bitmap max size (2)
2892 * so that notification bitmap is put in xdr_buf tail */
2893 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2894 args->pdev->pages, args->pdev->pgbase,
2895 args->pdev->pglen);
2896
2897 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002898}
2899
2900/*
2901 * Encode LAYOUTGET request
2902 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002903static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2904 struct xdr_stream *xdr,
2905 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002906{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002907 struct compound_hdr hdr = {
2908 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2909 };
2910
Chuck Lever9f06c712010-12-14 14:59:18 +00002911 encode_compound_hdr(xdr, req, &hdr);
2912 encode_sequence(xdr, &args->seq_args, &hdr);
2913 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2914 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002915
2916 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2917 args->layout.pages, 0, args->layout.pglen);
2918
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002919 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002920}
Andy Adamson863a3c62011-03-23 13:27:54 +00002921
2922/*
2923 * Encode LAYOUTCOMMIT request
2924 */
Benny Halevycbe82602011-05-22 19:52:37 +03002925static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2926 struct xdr_stream *xdr,
2927 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002928{
Benny Halevyac7db722011-05-22 19:53:48 +03002929 struct nfs4_layoutcommit_data *data =
2930 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002931 struct compound_hdr hdr = {
2932 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2933 };
2934
2935 encode_compound_hdr(xdr, req, &hdr);
2936 encode_sequence(xdr, &args->seq_args, &hdr);
2937 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002938 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002939 encode_getfattr(xdr, args->bitmask, &hdr);
2940 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002941}
2942
2943/*
2944 * Encode LAYOUTRETURN request
2945 */
2946static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2947 struct xdr_stream *xdr,
2948 struct nfs4_layoutreturn_args *args)
2949{
2950 struct compound_hdr hdr = {
2951 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2952 };
2953
2954 encode_compound_hdr(xdr, req, &hdr);
2955 encode_sequence(xdr, &args->seq_args, &hdr);
2956 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2957 encode_layoutreturn(xdr, args, &hdr);
2958 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002959}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002960
2961/*
2962 * Encode SECINFO_NO_NAME request
2963 */
2964static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2965 struct xdr_stream *xdr,
2966 struct nfs41_secinfo_no_name_args *args)
2967{
2968 struct compound_hdr hdr = {
2969 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2970 };
2971
2972 encode_compound_hdr(xdr, req, &hdr);
2973 encode_sequence(xdr, &args->seq_args, &hdr);
2974 encode_putrootfh(xdr, &hdr);
2975 encode_secinfo_no_name(xdr, args, &hdr);
2976 encode_nops(&hdr);
2977 return 0;
2978}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002979
2980/*
2981 * Encode TEST_STATEID request
2982 */
2983static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2984 struct xdr_stream *xdr,
2985 struct nfs41_test_stateid_args *args)
2986{
2987 struct compound_hdr hdr = {
2988 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2989 };
2990
2991 encode_compound_hdr(xdr, req, &hdr);
2992 encode_sequence(xdr, &args->seq_args, &hdr);
2993 encode_test_stateid(xdr, args, &hdr);
2994 encode_nops(&hdr);
2995}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002996
2997/*
2998 * Encode FREE_STATEID request
2999 */
3000static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3001 struct xdr_stream *xdr,
3002 struct nfs41_free_stateid_args *args)
3003{
3004 struct compound_hdr hdr = {
3005 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3006 };
3007
3008 encode_compound_hdr(xdr, req, &hdr);
3009 encode_sequence(xdr, &args->seq_args, &hdr);
3010 encode_free_stateid(xdr, args, &hdr);
3011 encode_nops(&hdr);
3012}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003013#endif /* CONFIG_NFS_V4_1 */
3014
Benny Halevy686841b2009-08-14 17:19:48 +03003015static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3016{
3017 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3018 "Remaining buffer length is %tu words.\n",
3019 func, xdr->end - xdr->p);
3020}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021
Trond Myklebust683b57b2006-06-09 09:34:22 -04003022static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023{
Al Viro8687b632006-10-19 23:28:48 -07003024 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025
Benny Halevyc0eae662009-08-14 17:20:14 +03003026 p = xdr_inline_decode(xdr, 4);
3027 if (unlikely(!p))
3028 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003029 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003030 p = xdr_inline_decode(xdr, *len);
3031 if (unlikely(!p))
3032 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 *string = (char *)p;
3034 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003035out_overflow:
3036 print_overflow_msg(__func__, xdr);
3037 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038}
3039
3040static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3041{
Al Viro8687b632006-10-19 23:28:48 -07003042 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
Benny Halevyc0eae662009-08-14 17:20:14 +03003044 p = xdr_inline_decode(xdr, 8);
3045 if (unlikely(!p))
3046 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003047 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003048 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003049
Benny Halevyc0eae662009-08-14 17:20:14 +03003050 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3051 if (unlikely(!p))
3052 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 hdr->tag = (char *)p;
3054 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003055 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003056 if (unlikely(hdr->nops < 1))
3057 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003059out_overflow:
3060 print_overflow_msg(__func__, xdr);
3061 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062}
3063
Trond Myklebustc7848f62013-12-04 17:39:23 -05003064static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3065 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066{
Al Viro8687b632006-10-19 23:28:48 -07003067 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 uint32_t opnum;
3069 int32_t nfserr;
3070
Benny Halevyc0eae662009-08-14 17:20:14 +03003071 p = xdr_inline_decode(xdr, 8);
3072 if (unlikely(!p))
3073 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003074 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003075 if (unlikely(opnum != expected))
3076 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003077 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003078 if (nfserr == NFS_OK)
3079 *nfs_retval = 0;
3080 else
3081 *nfs_retval = nfs4_stat_to_errno(nfserr);
3082 return true;
3083out_bad_operation:
3084 dprintk("nfs: Server returned operation"
3085 " %d but we issued a request for %d\n",
3086 opnum, expected);
3087 *nfs_retval = -EREMOTEIO;
3088 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003089out_overflow:
3090 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003091 *nfs_retval = -EIO;
3092 return false;
3093}
3094
3095static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3096{
3097 int retval;
3098
3099 __decode_op_hdr(xdr, expected, &retval);
3100 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101}
3102
3103/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003104static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105{
Al Viro8687b632006-10-19 23:28:48 -07003106 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003107 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 char *str;
3109
Benny Halevyc0eae662009-08-14 17:20:14 +03003110 p = xdr_inline_decode(xdr, 12);
3111 if (likely(p))
3112 return decode_opaque_inline(xdr, &strlen, &str);
3113 print_overflow_msg(__func__, xdr);
3114 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115}
3116
3117static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3118{
Al Viro8687b632006-10-19 23:28:48 -07003119 uint32_t bmlen;
3120 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121
Benny Halevyc0eae662009-08-14 17:20:14 +03003122 p = xdr_inline_decode(xdr, 4);
3123 if (unlikely(!p))
3124 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003125 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126
Fred Isamandae100c2011-07-30 20:52:37 -04003127 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003128 p = xdr_inline_decode(xdr, (bmlen << 2));
3129 if (unlikely(!p))
3130 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003132 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003133 if (bmlen > 1) {
3134 bitmap[1] = be32_to_cpup(p++);
3135 if (bmlen > 2)
3136 bitmap[2] = be32_to_cpup(p);
3137 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 }
3139 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003140out_overflow:
3141 print_overflow_msg(__func__, xdr);
3142 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143}
3144
Trond Myklebust256e48b2012-06-21 11:18:13 -04003145static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146{
Al Viro8687b632006-10-19 23:28:48 -07003147 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
Benny Halevyc0eae662009-08-14 17:20:14 +03003149 p = xdr_inline_decode(xdr, 4);
3150 if (unlikely(!p))
3151 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003152 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003153 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003155out_overflow:
3156 print_overflow_msg(__func__, xdr);
3157 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158}
3159
3160static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3161{
3162 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003163 int ret;
3164 ret = decode_attr_bitmap(xdr, bitmask);
3165 if (unlikely(ret < 0))
3166 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3168 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003169 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3170 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3171 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 return 0;
3173}
3174
3175static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3176{
Al Viro8687b632006-10-19 23:28:48 -07003177 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003178 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179
3180 *type = 0;
3181 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3182 return -EIO;
3183 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003184 p = xdr_inline_decode(xdr, 4);
3185 if (unlikely(!p))
3186 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003187 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003189 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 return -EIO;
3191 }
3192 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003193 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003195 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003196 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003197out_overflow:
3198 print_overflow_msg(__func__, xdr);
3199 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200}
3201
Chuck Lever264e6352012-03-01 17:02:05 -05003202static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3203 uint32_t *bitmap, uint32_t *type)
3204{
3205 __be32 *p;
3206
3207 *type = 0;
3208 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3209 return -EIO;
3210 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3211 p = xdr_inline_decode(xdr, 4);
3212 if (unlikely(!p))
3213 goto out_overflow;
3214 *type = be32_to_cpup(p);
3215 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3216 }
3217 dprintk("%s: expire type=0x%x\n", __func__, *type);
3218 return 0;
3219out_overflow:
3220 print_overflow_msg(__func__, xdr);
3221 return -EIO;
3222}
3223
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3225{
Al Viro8687b632006-10-19 23:28:48 -07003226 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003227 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228
3229 *change = 0;
3230 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3231 return -EIO;
3232 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003233 p = xdr_inline_decode(xdr, 8);
3234 if (unlikely(!p))
3235 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003236 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003238 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003240 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003242 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003243out_overflow:
3244 print_overflow_msg(__func__, xdr);
3245 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246}
3247
3248static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3249{
Al Viro8687b632006-10-19 23:28:48 -07003250 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003251 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
3253 *size = 0;
3254 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3255 return -EIO;
3256 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003257 p = xdr_inline_decode(xdr, 8);
3258 if (unlikely(!p))
3259 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003260 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003262 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003264 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003265 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003266out_overflow:
3267 print_overflow_msg(__func__, xdr);
3268 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269}
3270
3271static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3272{
Al Viro8687b632006-10-19 23:28:48 -07003273 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
3275 *res = 0;
3276 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3277 return -EIO;
3278 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003279 p = xdr_inline_decode(xdr, 4);
3280 if (unlikely(!p))
3281 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003282 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3284 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003285 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003287out_overflow:
3288 print_overflow_msg(__func__, xdr);
3289 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290}
3291
3292static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3293{
Al Viro8687b632006-10-19 23:28:48 -07003294 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295
3296 *res = 0;
3297 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3298 return -EIO;
3299 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003300 p = xdr_inline_decode(xdr, 4);
3301 if (unlikely(!p))
3302 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003303 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3305 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003306 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003308out_overflow:
3309 print_overflow_msg(__func__, xdr);
3310 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311}
3312
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003313static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314{
Al Viro8687b632006-10-19 23:28:48 -07003315 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003316 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317
3318 fsid->major = 0;
3319 fsid->minor = 0;
3320 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3321 return -EIO;
3322 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003323 p = xdr_inline_decode(xdr, 16);
3324 if (unlikely(!p))
3325 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003326 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003327 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003329 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003331 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 (unsigned long long)fsid->major,
3333 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003334 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003335out_overflow:
3336 print_overflow_msg(__func__, xdr);
3337 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338}
3339
3340static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3341{
Al Viro8687b632006-10-19 23:28:48 -07003342 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343
3344 *res = 60;
3345 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3346 return -EIO;
3347 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003348 p = xdr_inline_decode(xdr, 4);
3349 if (unlikely(!p))
3350 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003351 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3353 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003354 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003356out_overflow:
3357 print_overflow_msg(__func__, xdr);
3358 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359}
3360
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003361static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003362{
3363 __be32 *p;
3364
3365 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3366 return -EIO;
3367 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3368 p = xdr_inline_decode(xdr, 4);
3369 if (unlikely(!p))
3370 goto out_overflow;
3371 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003372 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003373 }
3374 return 0;
3375out_overflow:
3376 print_overflow_msg(__func__, xdr);
3377 return -EIO;
3378}
3379
Kinglong Mee8c612822015-08-26 21:12:58 +08003380static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3381 uint32_t *bitmap, uint32_t *bitmask)
3382{
3383 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3384 int ret;
3385 ret = decode_attr_bitmap(xdr, bitmask);
3386 if (unlikely(ret < 0))
3387 return ret;
3388 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3389 } else
3390 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3391 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3392 bitmask[0], bitmask[1], bitmask[2]);
3393 return 0;
3394}
3395
Bryan Schumakerae42c702010-10-21 16:33:17 -04003396static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3397{
3398 __be32 *p;
3399 int len;
3400
Trond Myklebust7ad07352010-10-23 15:34:20 -04003401 if (fh != NULL)
3402 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003403
3404 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3405 return -EIO;
3406 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3407 p = xdr_inline_decode(xdr, 4);
3408 if (unlikely(!p))
3409 goto out_overflow;
3410 len = be32_to_cpup(p);
3411 if (len > NFS4_FHSIZE)
3412 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003413 p = xdr_inline_decode(xdr, len);
3414 if (unlikely(!p))
3415 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003416 if (fh != NULL) {
3417 memcpy(fh->data, p, len);
3418 fh->size = len;
3419 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003420 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3421 }
3422 return 0;
3423out_overflow:
3424 print_overflow_msg(__func__, xdr);
3425 return -EIO;
3426}
3427
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3429{
Al Viro8687b632006-10-19 23:28:48 -07003430 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003432 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3434 return -EIO;
3435 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003436 p = xdr_inline_decode(xdr, 4);
3437 if (unlikely(!p))
3438 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003439 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3441 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003442 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003444out_overflow:
3445 print_overflow_msg(__func__, xdr);
3446 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447}
3448
3449static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3450{
Al Viro8687b632006-10-19 23:28:48 -07003451 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003452 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453
3454 *fileid = 0;
3455 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3456 return -EIO;
3457 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003458 p = xdr_inline_decode(xdr, 8);
3459 if (unlikely(!p))
3460 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003461 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003463 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003465 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003466 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003467out_overflow:
3468 print_overflow_msg(__func__, xdr);
3469 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470}
3471
Manoj Naik99baf622006-06-09 09:34:24 -04003472static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3473{
Al Viro8687b632006-10-19 23:28:48 -07003474 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003475 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003476
3477 *fileid = 0;
3478 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3479 return -EIO;
3480 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003481 p = xdr_inline_decode(xdr, 8);
3482 if (unlikely(!p))
3483 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003484 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003485 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003486 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003487 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003488 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003489 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003490out_overflow:
3491 print_overflow_msg(__func__, xdr);
3492 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003493}
3494
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3496{
Al Viro8687b632006-10-19 23:28:48 -07003497 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 int status = 0;
3499
3500 *res = 0;
3501 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3502 return -EIO;
3503 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003504 p = xdr_inline_decode(xdr, 8);
3505 if (unlikely(!p))
3506 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003507 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3509 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003510 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003512out_overflow:
3513 print_overflow_msg(__func__, xdr);
3514 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515}
3516
3517static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3518{
Al Viro8687b632006-10-19 23:28:48 -07003519 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 int status = 0;
3521
3522 *res = 0;
3523 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3524 return -EIO;
3525 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003526 p = xdr_inline_decode(xdr, 8);
3527 if (unlikely(!p))
3528 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003529 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3531 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003532 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003534out_overflow:
3535 print_overflow_msg(__func__, xdr);
3536 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537}
3538
3539static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3540{
Al Viro8687b632006-10-19 23:28:48 -07003541 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 int status = 0;
3543
3544 *res = 0;
3545 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3546 return -EIO;
3547 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003548 p = xdr_inline_decode(xdr, 8);
3549 if (unlikely(!p))
3550 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003551 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3553 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003554 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003556out_overflow:
3557 print_overflow_msg(__func__, xdr);
3558 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559}
3560
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003561static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3562{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003563 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003564 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003565 int status = 0;
3566
Benny Halevyc0eae662009-08-14 17:20:14 +03003567 p = xdr_inline_decode(xdr, 4);
3568 if (unlikely(!p))
3569 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003570 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003571 if (n == 0)
3572 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003573 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003574 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3575 dprintk("cannot parse %d components in path\n", n);
3576 goto out_eio;
3577 }
3578 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003579 struct nfs4_string *component = &path->components[path->ncomponents];
3580 status = decode_opaque_inline(xdr, &component->len, &component->data);
3581 if (unlikely(status != 0))
3582 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003583 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003584 pr_cont("%s%.*s ",
3585 (path->ncomponents != n ? "/ " : ""),
3586 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003587 }
3588out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003589 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003590root_path:
3591/* a root pathname is sent as a zero component4 */
3592 path->ncomponents = 1;
3593 path->components[0].len=0;
3594 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003595 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003596 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003597out_eio:
3598 dprintk(" status %d", status);
3599 status = -EIO;
3600 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003601out_overflow:
3602 print_overflow_msg(__func__, xdr);
3603 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003604}
3605
3606static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003607{
3608 int n;
Al Viro8687b632006-10-19 23:28:48 -07003609 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003610 int status = -EIO;
3611
3612 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3613 goto out;
3614 status = 0;
3615 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3616 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003617 status = -EIO;
3618 /* Ignore borken servers that return unrequested attrs */
3619 if (unlikely(res == NULL))
3620 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003621 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003622 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003623 if (unlikely(status != 0))
3624 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003625 p = xdr_inline_decode(xdr, 4);
3626 if (unlikely(!p))
3627 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003628 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003629 if (n <= 0)
3630 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003631 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003632 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003633 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003634
Trond Myklebust809b4262013-03-27 11:54:45 -04003635 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3636 break;
3637 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003638 p = xdr_inline_decode(xdr, 4);
3639 if (unlikely(!p))
3640 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003641 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003642
Chuck Lever02a29762012-03-01 17:00:31 -05003643 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003644 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3645 struct nfs4_string *server;
3646
3647 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003648 unsigned int i;
3649 dprintk("%s: using first %u of %u servers "
3650 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003651 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003652 NFS4_FS_LOCATION_MAXSERVERS,
3653 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003654 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003655 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003656 char *data;
3657 status = decode_opaque_inline(xdr, &len, &data);
3658 if (unlikely(status != 0))
3659 goto out_eio;
3660 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003661 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003662 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003663 server = &loc->servers[loc->nservers];
3664 status = decode_opaque_inline(xdr, &server->len, &server->data);
3665 if (unlikely(status != 0))
3666 goto out_eio;
3667 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003668 }
3669 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003670 if (unlikely(status != 0))
3671 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003672 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003673 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003674 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003675out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003676 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003677 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003678out_overflow:
3679 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003680out_eio:
3681 status = -EIO;
3682 goto out;
3683}
3684
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3686{
Al Viro8687b632006-10-19 23:28:48 -07003687 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 int status = 0;
3689
3690 *res = 0;
3691 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3692 return -EIO;
3693 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003694 p = xdr_inline_decode(xdr, 8);
3695 if (unlikely(!p))
3696 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003697 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3699 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003700 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003702out_overflow:
3703 print_overflow_msg(__func__, xdr);
3704 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705}
3706
3707static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3708{
Al Viro8687b632006-10-19 23:28:48 -07003709 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 int status = 0;
3711
3712 *maxlink = 1;
3713 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3714 return -EIO;
3715 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003716 p = xdr_inline_decode(xdr, 4);
3717 if (unlikely(!p))
3718 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003719 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3721 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003722 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003724out_overflow:
3725 print_overflow_msg(__func__, xdr);
3726 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727}
3728
3729static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3730{
Al Viro8687b632006-10-19 23:28:48 -07003731 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 int status = 0;
3733
3734 *maxname = 1024;
3735 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3736 return -EIO;
3737 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003738 p = xdr_inline_decode(xdr, 4);
3739 if (unlikely(!p))
3740 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003741 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3743 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003744 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003746out_overflow:
3747 print_overflow_msg(__func__, xdr);
3748 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749}
3750
3751static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3752{
Al Viro8687b632006-10-19 23:28:48 -07003753 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 int status = 0;
3755
3756 *res = 1024;
3757 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3758 return -EIO;
3759 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3760 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003761 p = xdr_inline_decode(xdr, 8);
3762 if (unlikely(!p))
3763 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003764 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 if (maxread > 0x7FFFFFFF)
3766 maxread = 0x7FFFFFFF;
3767 *res = (uint32_t)maxread;
3768 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3769 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003770 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003772out_overflow:
3773 print_overflow_msg(__func__, xdr);
3774 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775}
3776
3777static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3778{
Al Viro8687b632006-10-19 23:28:48 -07003779 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 int status = 0;
3781
3782 *res = 1024;
3783 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3784 return -EIO;
3785 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3786 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003787 p = xdr_inline_decode(xdr, 8);
3788 if (unlikely(!p))
3789 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003790 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791 if (maxwrite > 0x7FFFFFFF)
3792 maxwrite = 0x7FFFFFFF;
3793 *res = (uint32_t)maxwrite;
3794 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3795 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003796 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003798out_overflow:
3799 print_overflow_msg(__func__, xdr);
3800 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801}
3802
Trond Myklebustbca79472009-03-11 14:10:26 -04003803static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804{
Trond Myklebustbca79472009-03-11 14:10:26 -04003805 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003806 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003807 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808
3809 *mode = 0;
3810 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3811 return -EIO;
3812 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003813 p = xdr_inline_decode(xdr, 4);
3814 if (unlikely(!p))
3815 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003816 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003817 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003819 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003821 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003822 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003823out_overflow:
3824 print_overflow_msg(__func__, xdr);
3825 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826}
3827
3828static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3829{
Al Viro8687b632006-10-19 23:28:48 -07003830 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003831 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832
3833 *nlink = 1;
3834 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3835 return -EIO;
3836 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003837 p = xdr_inline_decode(xdr, 4);
3838 if (unlikely(!p))
3839 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003840 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003842 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003844 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003845 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003846out_overflow:
3847 print_overflow_msg(__func__, xdr);
3848 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849}
3850
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003851static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003852 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003853 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854{
Al Viro8687b632006-10-19 23:28:48 -07003855 uint32_t len;
3856 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003857 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858
Eric W. Biedermane5782072013-02-01 14:22:02 -08003859 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3861 return -EIO;
3862 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003863 p = xdr_inline_decode(xdr, 4);
3864 if (unlikely(!p))
3865 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003866 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003867 p = xdr_inline_decode(xdr, len);
3868 if (unlikely(!p))
3869 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003870 if (owner_name != NULL) {
3871 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3872 if (owner_name->data != NULL) {
3873 owner_name->len = len;
3874 ret = NFS_ATTR_FATTR_OWNER_NAME;
3875 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003876 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003877 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003878 ret = NFS_ATTR_FATTR_OWNER;
3879 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003881 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003883 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003884 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3886 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003887 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003888 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003889out_overflow:
3890 print_overflow_msg(__func__, xdr);
3891 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892}
3893
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003894static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003895 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003896 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897{
Al Viro8687b632006-10-19 23:28:48 -07003898 uint32_t len;
3899 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003900 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901
Eric W. Biedermane5782072013-02-01 14:22:02 -08003902 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3904 return -EIO;
3905 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003906 p = xdr_inline_decode(xdr, 4);
3907 if (unlikely(!p))
3908 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003909 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003910 p = xdr_inline_decode(xdr, len);
3911 if (unlikely(!p))
3912 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003913 if (group_name != NULL) {
3914 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3915 if (group_name->data != NULL) {
3916 group_name->len = len;
3917 ret = NFS_ATTR_FATTR_GROUP_NAME;
3918 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003919 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003920 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003921 ret = NFS_ATTR_FATTR_GROUP;
3922 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003924 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003926 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003927 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3929 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003930 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003931 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003932out_overflow:
3933 print_overflow_msg(__func__, xdr);
3934 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935}
3936
3937static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3938{
Al Viro8687b632006-10-19 23:28:48 -07003939 uint32_t major = 0, minor = 0;
3940 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003941 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942
3943 *rdev = MKDEV(0,0);
3944 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3945 return -EIO;
3946 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3947 dev_t tmp;
3948
Benny Halevyc0eae662009-08-14 17:20:14 +03003949 p = xdr_inline_decode(xdr, 8);
3950 if (unlikely(!p))
3951 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003952 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003953 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 tmp = MKDEV(major, minor);
3955 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3956 *rdev = tmp;
3957 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003958 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003960 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003961 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003962out_overflow:
3963 print_overflow_msg(__func__, xdr);
3964 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965}
3966
3967static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3968{
Al Viro8687b632006-10-19 23:28:48 -07003969 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 int status = 0;
3971
3972 *res = 0;
3973 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3974 return -EIO;
3975 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003976 p = xdr_inline_decode(xdr, 8);
3977 if (unlikely(!p))
3978 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003979 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3981 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003982 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003984out_overflow:
3985 print_overflow_msg(__func__, xdr);
3986 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987}
3988
3989static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3990{
Al Viro8687b632006-10-19 23:28:48 -07003991 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 int status = 0;
3993
3994 *res = 0;
3995 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3996 return -EIO;
3997 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003998 p = xdr_inline_decode(xdr, 8);
3999 if (unlikely(!p))
4000 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004001 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4003 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004004 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004006out_overflow:
4007 print_overflow_msg(__func__, xdr);
4008 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009}
4010
4011static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4012{
Al Viro8687b632006-10-19 23:28:48 -07004013 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 int status = 0;
4015
4016 *res = 0;
4017 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4018 return -EIO;
4019 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004020 p = xdr_inline_decode(xdr, 8);
4021 if (unlikely(!p))
4022 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004023 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4025 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004026 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004028out_overflow:
4029 print_overflow_msg(__func__, xdr);
4030 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031}
4032
4033static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4034{
Al Viro8687b632006-10-19 23:28:48 -07004035 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004036 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037
4038 *used = 0;
4039 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4040 return -EIO;
4041 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004042 p = xdr_inline_decode(xdr, 8);
4043 if (unlikely(!p))
4044 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004045 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004047 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004049 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004051 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004052out_overflow:
4053 print_overflow_msg(__func__, xdr);
4054 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055}
4056
4057static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4058{
Al Viro8687b632006-10-19 23:28:48 -07004059 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 uint64_t sec;
4061 uint32_t nsec;
4062
Benny Halevyc0eae662009-08-14 17:20:14 +03004063 p = xdr_inline_decode(xdr, 12);
4064 if (unlikely(!p))
4065 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004066 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004067 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 time->tv_sec = (time_t)sec;
4069 time->tv_nsec = (long)nsec;
4070 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004071out_overflow:
4072 print_overflow_msg(__func__, xdr);
4073 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074}
4075
4076static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4077{
4078 int status = 0;
4079
4080 time->tv_sec = 0;
4081 time->tv_nsec = 0;
4082 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4083 return -EIO;
4084 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4085 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004086 if (status == 0)
4087 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4089 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004090 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 return status;
4092}
4093
4094static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4095{
4096 int status = 0;
4097
4098 time->tv_sec = 0;
4099 time->tv_nsec = 0;
4100 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4101 return -EIO;
4102 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4103 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004104 if (status == 0)
4105 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4107 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004108 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 return status;
4110}
4111
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004112static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4113 struct timespec *time)
4114{
4115 int status = 0;
4116
4117 time->tv_sec = 0;
4118 time->tv_nsec = 0;
4119 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4120 return -EIO;
4121 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4122 status = decode_attr_time(xdr, time);
4123 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4124 }
4125 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4126 (long)time->tv_nsec);
4127 return status;
4128}
4129
David Quigleyaa9c2662013-05-22 12:50:44 -04004130static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4131 struct nfs4_label *label)
4132{
4133 uint32_t pi = 0;
4134 uint32_t lfs = 0;
4135 __u32 len;
4136 __be32 *p;
4137 int status = 0;
4138
4139 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4140 return -EIO;
4141 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4142 p = xdr_inline_decode(xdr, 4);
4143 if (unlikely(!p))
4144 goto out_overflow;
4145 lfs = be32_to_cpup(p++);
4146 p = xdr_inline_decode(xdr, 4);
4147 if (unlikely(!p))
4148 goto out_overflow;
4149 pi = be32_to_cpup(p++);
4150 p = xdr_inline_decode(xdr, 4);
4151 if (unlikely(!p))
4152 goto out_overflow;
4153 len = be32_to_cpup(p++);
4154 p = xdr_inline_decode(xdr, len);
4155 if (unlikely(!p))
4156 goto out_overflow;
4157 if (len < NFS4_MAXLABELLEN) {
4158 if (label) {
4159 memcpy(label->label, p, len);
4160 label->len = len;
4161 label->pi = pi;
4162 label->lfs = lfs;
4163 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4164 }
4165 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4166 } else
4167 printk(KERN_WARNING "%s: label too long (%u)!\n",
4168 __func__, len);
4169 }
4170 if (label && label->label)
4171 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4172 (char *)label->label, label->len, label->pi, label->lfs);
4173 return status;
4174
4175out_overflow:
4176 print_overflow_msg(__func__, xdr);
4177 return -EIO;
4178}
4179
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4181{
4182 int status = 0;
4183
4184 time->tv_sec = 0;
4185 time->tv_nsec = 0;
4186 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4187 return -EIO;
4188 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4189 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004190 if (status == 0)
4191 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4193 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004194 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 return status;
4196}
4197
Trond Myklebust256e48b2012-06-21 11:18:13 -04004198static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199{
4200 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004201 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202
4203 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004204 dprintk("%s: server returned incorrect attribute length: "
4205 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004206 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 attrwords << 2,
4208 (attrwords < nwords) ? '<' : '>',
4209 nwords << 2);
4210 return -EIO;
4211 }
4212 return 0;
4213}
4214
4215static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4216{
Al Viro8687b632006-10-19 23:28:48 -07004217 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218
Benny Halevyc0eae662009-08-14 17:20:14 +03004219 p = xdr_inline_decode(xdr, 20);
4220 if (unlikely(!p))
4221 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004222 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004223 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004224 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004226out_overflow:
4227 print_overflow_msg(__func__, xdr);
4228 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229}
4230
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004231static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232{
Al Viro8687b632006-10-19 23:28:48 -07004233 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 uint32_t supp, acc;
4235 int status;
4236
4237 status = decode_op_hdr(xdr, OP_ACCESS);
4238 if (status)
4239 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004240 p = xdr_inline_decode(xdr, 8);
4241 if (unlikely(!p))
4242 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004243 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004244 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004245 *supported = supp;
4246 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004248out_overflow:
4249 print_overflow_msg(__func__, xdr);
4250 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251}
4252
Benny Halevy07d30432009-08-14 17:19:52 +03004253static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254{
Al Viro8687b632006-10-19 23:28:48 -07004255 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004256
4257 p = xdr_inline_decode(xdr, len);
4258 if (likely(p)) {
4259 memcpy(buf, p, len);
4260 return 0;
4261 }
4262 print_overflow_msg(__func__, xdr);
4263 return -EIO;
4264}
4265
4266static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4267{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004268 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269}
4270
4271static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4272{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 int status;
4274
4275 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004276 if (status != -EIO)
4277 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004278 if (!status)
4279 status = decode_stateid(xdr, &res->stateid);
4280 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281}
4282
Benny Halevydb942bb2009-08-14 17:19:56 +03004283static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4284{
Chuck Levercd937102012-03-02 17:14:31 -05004285 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286}
4287
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004288static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4289{
4290 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4291}
4292
Fred Isaman0b7c0152012-04-20 14:47:39 -04004293static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295 int status;
4296
4297 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004298 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004299 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004300 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301}
4302
4303static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4304{
Al Viro8687b632006-10-19 23:28:48 -07004305 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 uint32_t bmlen;
4307 int status;
4308
4309 status = decode_op_hdr(xdr, OP_CREATE);
4310 if (status)
4311 return status;
4312 if ((status = decode_change_info(xdr, cinfo)))
4313 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004314 p = xdr_inline_decode(xdr, 4);
4315 if (unlikely(!p))
4316 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004317 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004318 p = xdr_inline_decode(xdr, bmlen << 2);
4319 if (likely(p))
4320 return 0;
4321out_overflow:
4322 print_overflow_msg(__func__, xdr);
4323 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324}
4325
4326static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4327{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004328 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004329 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 int status;
4331
4332 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4333 goto xdr_error;
4334 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4335 goto xdr_error;
4336 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4337 goto xdr_error;
4338 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4339 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004340 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4341 &res->fh_expire_type)) != 0)
4342 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4344 goto xdr_error;
4345 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4346 goto xdr_error;
4347 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4348 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004349 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4350 res->exclcreat_bitmask)) != 0)
4351 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 status = verify_attr_len(xdr, savep, attrlen);
4353xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004354 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 return status;
4356}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004357
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4359{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004360 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004361 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004362 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004363
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4365 goto xdr_error;
4366 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4367 goto xdr_error;
4368 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4369 goto xdr_error;
4370
4371 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4372 goto xdr_error;
4373 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4374 goto xdr_error;
4375 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4376 goto xdr_error;
4377 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4378 goto xdr_error;
4379 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4380 goto xdr_error;
4381 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4382 goto xdr_error;
4383
4384 status = verify_attr_len(xdr, savep, attrlen);
4385xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004386 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387 return status;
4388}
4389
4390static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4391{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004392 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004393 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004395
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4397 goto xdr_error;
4398 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4399 goto xdr_error;
4400 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4401 goto xdr_error;
4402
4403 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4404 goto xdr_error;
4405 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4406 goto xdr_error;
4407
4408 status = verify_attr_len(xdr, savep, attrlen);
4409xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004410 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 return status;
4412}
4413
Andy Adamson88034c32012-05-23 05:02:34 -04004414static int decode_threshold_hint(struct xdr_stream *xdr,
4415 uint32_t *bitmap,
4416 uint64_t *res,
4417 uint32_t hint_bit)
4418{
4419 __be32 *p;
4420
4421 *res = 0;
4422 if (likely(bitmap[0] & hint_bit)) {
4423 p = xdr_inline_decode(xdr, 8);
4424 if (unlikely(!p))
4425 goto out_overflow;
4426 xdr_decode_hyper(p, res);
4427 }
4428 return 0;
4429out_overflow:
4430 print_overflow_msg(__func__, xdr);
4431 return -EIO;
4432}
4433
4434static int decode_first_threshold_item4(struct xdr_stream *xdr,
4435 struct nfs4_threshold *res)
4436{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004437 __be32 *p;
4438 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004439 uint32_t bitmap[3] = {0,}, attrlen;
4440 int status;
4441
4442 /* layout type */
4443 p = xdr_inline_decode(xdr, 4);
4444 if (unlikely(!p)) {
4445 print_overflow_msg(__func__, xdr);
4446 return -EIO;
4447 }
4448 res->l_type = be32_to_cpup(p);
4449
4450 /* thi_hintset bitmap */
4451 status = decode_attr_bitmap(xdr, bitmap);
4452 if (status < 0)
4453 goto xdr_error;
4454
4455 /* thi_hintlist length */
4456 status = decode_attr_length(xdr, &attrlen, &savep);
4457 if (status < 0)
4458 goto xdr_error;
4459 /* thi_hintlist */
4460 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4461 if (status < 0)
4462 goto xdr_error;
4463 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4464 if (status < 0)
4465 goto xdr_error;
4466 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4467 THRESHOLD_RD_IO);
4468 if (status < 0)
4469 goto xdr_error;
4470 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4471 THRESHOLD_WR_IO);
4472 if (status < 0)
4473 goto xdr_error;
4474
4475 status = verify_attr_len(xdr, savep, attrlen);
4476 res->bm = bitmap[0];
4477
4478 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4479 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4480 res->wr_io_sz);
4481xdr_error:
4482 dprintk("%s ret=%d!\n", __func__, status);
4483 return status;
4484}
4485
4486/*
4487 * Thresholds on pNFS direct I/O vrs MDS I/O
4488 */
4489static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4490 uint32_t *bitmap,
4491 struct nfs4_threshold *res)
4492{
4493 __be32 *p;
4494 int status = 0;
4495 uint32_t num;
4496
4497 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4498 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004499 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004500 /* Did the server return an unrequested attribute? */
4501 if (unlikely(res == NULL))
4502 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004503 p = xdr_inline_decode(xdr, 4);
4504 if (unlikely(!p))
4505 goto out_overflow;
4506 num = be32_to_cpup(p);
4507 if (num == 0)
4508 return 0;
4509 if (num > 1)
4510 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4511 "drivers per filesystem not supported\n",
4512 __func__);
4513
4514 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004515 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004516 }
4517 return status;
4518out_overflow:
4519 print_overflow_msg(__func__, xdr);
4520 return -EIO;
4521}
4522
Bryan Schumakerae42c702010-10-21 16:33:17 -04004523static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4524 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004525 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004526 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527{
Trond Myklebustbca79472009-03-11 14:10:26 -04004528 int status;
4529 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004530 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004531 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004533 status = decode_attr_type(xdr, bitmap, &type);
4534 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004536 fattr->mode = 0;
4537 if (status != 0) {
4538 fattr->mode |= nfs_type2fmt[type];
4539 fattr->valid |= status;
4540 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004542 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4543 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004545 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004546
4547 status = decode_attr_size(xdr, bitmap, &fattr->size);
4548 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004550 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004551
4552 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4553 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004555 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004556
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004557 err = 0;
4558 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004559 if (status < 0)
4560 goto xdr_error;
4561
4562 status = decode_attr_filehandle(xdr, bitmap, fh);
4563 if (status < 0)
4564 goto xdr_error;
4565
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004566 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4567 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004569 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004570
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004571 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004572 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004573 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004574 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004575
4576 status = decode_attr_mode(xdr, bitmap, &fmode);
4577 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004578 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004579 if (status != 0) {
4580 fattr->mode |= fmode;
4581 fattr->valid |= status;
4582 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004583
4584 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4585 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
Trond Myklebust6926afd2012-01-07 13:22:46 -05004589 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004590 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
Trond Myklebust6926afd2012-01-07 13:22:46 -05004594 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004595 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_rdev(xdr, bitmap, &fattr->rdev);
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_space_used(xdr, bitmap, &fattr->du.nfs3.used);
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_access(xdr, bitmap, &fattr->atime);
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
4614 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4615 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004617 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004618
4619 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4620 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004622 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004623
Trond Myklebust28331a42011-04-27 13:47:52 -04004624 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004625 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004626 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004627 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004628
Andy Adamson88034c32012-05-23 05:02:34 -04004629 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4630 if (status < 0)
4631 goto xdr_error;
4632
David Quigleyaa9c2662013-05-22 12:50:44 -04004633 if (label) {
4634 status = decode_attr_security_label(xdr, bitmap, label);
4635 if (status < 0)
4636 goto xdr_error;
4637 fattr->valid |= status;
4638 }
4639
Bryan Schumakerae42c702010-10-21 16:33:17 -04004640xdr_error:
4641 dprintk("%s: xdr returned %d\n", __func__, -status);
4642 return status;
4643}
4644
4645static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004646 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004647 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004648{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004649 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004650 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004651 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004652 int status;
4653
4654 status = decode_op_hdr(xdr, OP_GETATTR);
4655 if (status < 0)
4656 goto xdr_error;
4657
4658 status = decode_attr_bitmap(xdr, bitmap);
4659 if (status < 0)
4660 goto xdr_error;
4661
4662 status = decode_attr_length(xdr, &attrlen, &savep);
4663 if (status < 0)
4664 goto xdr_error;
4665
David Quigleyaa9c2662013-05-22 12:50:44 -04004666 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4667 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004668 if (status < 0)
4669 goto xdr_error;
4670
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004671 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004673 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 return status;
4675}
4676
David Quigleyaa9c2662013-05-22 12:50:44 -04004677static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4678 struct nfs4_label *label, const struct nfs_server *server)
4679{
4680 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4681}
4682
Bryan Schumakerae42c702010-10-21 16:33:17 -04004683static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004684 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004685{
David Quigleyaa9c2662013-05-22 12:50:44 -04004686 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004687}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004688
Andy Adamson504913f2010-10-20 00:17:57 -04004689/*
4690 * Decode potentially multiple layout types. Currently we only support
4691 * one layout driver per file system.
4692 */
4693static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4694 uint32_t *layouttype)
4695{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004696 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004697 int num;
4698
4699 p = xdr_inline_decode(xdr, 4);
4700 if (unlikely(!p))
4701 goto out_overflow;
4702 num = be32_to_cpup(p);
4703
4704 /* pNFS is not supported by the underlying file system */
4705 if (num == 0) {
4706 *layouttype = 0;
4707 return 0;
4708 }
4709 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004710 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4711 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004712
4713 /* Decode and set first layout type, move xdr->p past unused types */
4714 p = xdr_inline_decode(xdr, num * 4);
4715 if (unlikely(!p))
4716 goto out_overflow;
4717 *layouttype = be32_to_cpup(p);
4718 return 0;
4719out_overflow:
4720 print_overflow_msg(__func__, xdr);
4721 return -EIO;
4722}
4723
4724/*
4725 * The type of file system exported.
4726 * Note we must ensure that layouttype is set in any non-error case.
4727 */
4728static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4729 uint32_t *layouttype)
4730{
4731 int status = 0;
4732
4733 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4734 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4735 return -EIO;
4736 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4737 status = decode_first_pnfs_layout_type(xdr, layouttype);
4738 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4739 } else
4740 *layouttype = 0;
4741 return status;
4742}
4743
Fred Isamandae100c2011-07-30 20:52:37 -04004744/*
4745 * The prefered block size for layout directed io
4746 */
4747static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4748 uint32_t *res)
4749{
4750 __be32 *p;
4751
4752 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4753 *res = 0;
4754 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4755 p = xdr_inline_decode(xdr, 4);
4756 if (unlikely(!p)) {
4757 print_overflow_msg(__func__, xdr);
4758 return -EIO;
4759 }
4760 *res = be32_to_cpup(p);
4761 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4762 }
4763 return 0;
4764}
4765
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4767{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004768 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004769 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 int status;
4771
4772 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4773 goto xdr_error;
4774 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4775 goto xdr_error;
4776 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4777 goto xdr_error;
4778
4779 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4780
4781 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4782 goto xdr_error;
4783 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4784 goto xdr_error;
4785 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4786 goto xdr_error;
4787 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4788 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4789 goto xdr_error;
4790 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004791 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4792 if (status != 0)
4793 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004794 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4795 if (status != 0)
4796 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004797 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4798 if (status)
4799 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800
4801 status = verify_attr_len(xdr, savep, attrlen);
4802xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004803 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804 return status;
4805}
4806
4807static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4808{
Al Viro8687b632006-10-19 23:28:48 -07004809 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810 uint32_t len;
4811 int status;
4812
Trond Myklebust99367812007-07-17 21:52:41 -04004813 /* Zero handle first to allow comparisons */
4814 memset(fh, 0, sizeof(*fh));
4815
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816 status = decode_op_hdr(xdr, OP_GETFH);
4817 if (status)
4818 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819
Benny Halevyc0eae662009-08-14 17:20:14 +03004820 p = xdr_inline_decode(xdr, 4);
4821 if (unlikely(!p))
4822 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004823 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004824 if (len > NFS4_FHSIZE)
4825 return -EIO;
4826 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004827 p = xdr_inline_decode(xdr, len);
4828 if (unlikely(!p))
4829 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004830 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004832out_overflow:
4833 print_overflow_msg(__func__, xdr);
4834 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835}
4836
4837static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4838{
4839 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004840
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 status = decode_op_hdr(xdr, OP_LINK);
4842 if (status)
4843 return status;
4844 return decode_change_info(xdr, cinfo);
4845}
4846
4847/*
4848 * We create the owner, so we know a proper owner.id length is 4.
4849 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004850static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004852 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004853 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004854 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004856 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004857 if (unlikely(!p))
4858 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004859 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004860 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004861 type = be32_to_cpup(p++); /* 4 byte read */
4862 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004863 fl->fl_start = (loff_t)offset;
4864 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4865 if (length == ~(uint64_t)0)
4866 fl->fl_end = OFFSET_MAX;
4867 fl->fl_type = F_WRLCK;
4868 if (type & 1)
4869 fl->fl_type = F_RDLCK;
4870 fl->fl_pid = 0;
4871 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004872 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4873 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4874 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004875 if (likely(p))
4876 return -NFS4ERR_DENIED;
4877out_overflow:
4878 print_overflow_msg(__func__, xdr);
4879 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880}
4881
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004882static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884 int status;
4885
4886 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004887 if (status == -EIO)
4888 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004890 status = decode_stateid(xdr, &res->stateid);
4891 if (unlikely(status))
4892 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004894 status = decode_lock_denied(xdr, NULL);
4895 if (res->open_seqid != NULL)
4896 nfs_increment_open_seqid(status, res->open_seqid);
4897 nfs_increment_lock_seqid(status, res->lock_seqid);
4898out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899 return status;
4900}
4901
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004902static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903{
4904 int status;
4905 status = decode_op_hdr(xdr, OP_LOCKT);
4906 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004907 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908 return status;
4909}
4910
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004911static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913 int status;
4914
4915 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004916 if (status != -EIO)
4917 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004918 if (status == 0)
4919 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920 return status;
4921}
4922
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004923static int decode_release_lockowner(struct xdr_stream *xdr)
4924{
4925 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4926}
4927
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928static int decode_lookup(struct xdr_stream *xdr)
4929{
4930 return decode_op_hdr(xdr, OP_LOOKUP);
4931}
4932
4933/* This is too sick! */
4934static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4935{
Andy Adamson05d564f2008-12-23 16:06:15 -05004936 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937 uint32_t limit_type, nblocks, blocksize;
4938
Benny Halevyc0eae662009-08-14 17:20:14 +03004939 p = xdr_inline_decode(xdr, 12);
4940 if (unlikely(!p))
4941 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004942 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004944 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004945 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004946 break;
4947 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004948 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004949 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004950 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951 }
4952 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004953out_overflow:
4954 print_overflow_msg(__func__, xdr);
4955 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004956}
4957
Trond Myklebust6ae37332015-01-30 14:21:14 -05004958static int decode_rw_delegation(struct xdr_stream *xdr,
4959 uint32_t delegation_type,
4960 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961{
Andy Adamson05d564f2008-12-23 16:06:15 -05004962 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004963 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964
Benny Halevy07d30432009-08-14 17:19:52 +03004965 status = decode_stateid(xdr, &res->delegation);
4966 if (unlikely(status))
4967 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004968 p = xdr_inline_decode(xdr, 4);
4969 if (unlikely(!p))
4970 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004971 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004972
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004974 case NFS4_OPEN_DELEGATE_READ:
4975 res->delegation_type = FMODE_READ;
4976 break;
4977 case NFS4_OPEN_DELEGATE_WRITE:
4978 res->delegation_type = FMODE_WRITE|FMODE_READ;
4979 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980 return -EIO;
4981 }
David Howells7539bba2006-08-22 20:06:09 -04004982 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004983out_overflow:
4984 print_overflow_msg(__func__, xdr);
4985 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986}
4987
Trond Myklebust6ae37332015-01-30 14:21:14 -05004988static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4989{
4990 __be32 *p;
4991 uint32_t why_no_delegation;
4992
4993 p = xdr_inline_decode(xdr, 4);
4994 if (unlikely(!p))
4995 goto out_overflow;
4996 why_no_delegation = be32_to_cpup(p);
4997 switch (why_no_delegation) {
4998 case WND4_CONTENTION:
4999 case WND4_RESOURCE:
5000 xdr_inline_decode(xdr, 4);
5001 /* Ignore for now */
5002 }
5003 return 0;
5004out_overflow:
5005 print_overflow_msg(__func__, xdr);
5006 return -EIO;
5007}
5008
5009static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5010{
5011 __be32 *p;
5012 uint32_t delegation_type;
5013
5014 p = xdr_inline_decode(xdr, 4);
5015 if (unlikely(!p))
5016 goto out_overflow;
5017 delegation_type = be32_to_cpup(p);
5018 res->delegation_type = 0;
5019 switch (delegation_type) {
5020 case NFS4_OPEN_DELEGATE_NONE:
5021 return 0;
5022 case NFS4_OPEN_DELEGATE_READ:
5023 case NFS4_OPEN_DELEGATE_WRITE:
5024 return decode_rw_delegation(xdr, delegation_type, res);
5025 case NFS4_OPEN_DELEGATE_NONE_EXT:
5026 return decode_no_delegation(xdr, res);
5027 }
5028 return -EIO;
5029out_overflow:
5030 print_overflow_msg(__func__, xdr);
5031 return -EIO;
5032}
5033
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5035{
Andy Adamson05d564f2008-12-23 16:06:15 -05005036 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005037 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005038 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039
Trond Myklebustc7848f62013-12-04 17:39:23 -05005040 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5041 return status;
5042 nfs_increment_open_seqid(status, res->seqid);
5043 if (status)
5044 return status;
5045 status = decode_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005046 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005047 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048
Andy Adamson05d564f2008-12-23 16:06:15 -05005049 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050
Benny Halevyc0eae662009-08-14 17:20:14 +03005051 p = xdr_inline_decode(xdr, 8);
5052 if (unlikely(!p))
5053 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005054 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005055 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005056 if (bmlen > 10)
5057 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058
Benny Halevyc0eae662009-08-14 17:20:14 +03005059 p = xdr_inline_decode(xdr, bmlen << 2);
5060 if (unlikely(!p))
5061 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005062 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5063 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005064 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005065 for (; i < NFS4_BITMAP_SIZE; i++)
5066 res->attrset[i] = 0;
5067
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068 return decode_delegation(xdr, res);
5069xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005070 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005072out_overflow:
5073 print_overflow_msg(__func__, xdr);
5074 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075}
5076
5077static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5078{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079 int status;
5080
Andy Adamson05d564f2008-12-23 16:06:15 -05005081 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005082 if (status != -EIO)
5083 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005084 if (!status)
5085 status = decode_stateid(xdr, &res->stateid);
5086 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087}
5088
5089static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5090{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 int status;
5092
5093 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005094 if (status != -EIO)
5095 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005096 if (!status)
5097 status = decode_stateid(xdr, &res->stateid);
5098 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099}
5100
5101static int decode_putfh(struct xdr_stream *xdr)
5102{
5103 return decode_op_hdr(xdr, OP_PUTFH);
5104}
5105
5106static int decode_putrootfh(struct xdr_stream *xdr)
5107{
5108 return decode_op_hdr(xdr, OP_PUTROOTFH);
5109}
5110
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005111static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5112 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113{
Al Viro8687b632006-10-19 23:28:48 -07005114 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005115 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116 int status;
5117
5118 status = decode_op_hdr(xdr, OP_READ);
5119 if (status)
5120 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005121 p = xdr_inline_decode(xdr, 8);
5122 if (unlikely(!p))
5123 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005124 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005125 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005126 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005128 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129 "count %u > recvd %u\n", count, recvd);
5130 count = recvd;
5131 eof = 0;
5132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133 res->eof = eof;
5134 res->count = count;
5135 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005136out_overflow:
5137 print_overflow_msg(__func__, xdr);
5138 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139}
5140
5141static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5142{
Chuck Leverbcecff72007-10-26 13:32:03 -04005143 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005144 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145
5146 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005147 if (!status)
5148 status = decode_verifier(xdr, readdir->verifier.data);
5149 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005150 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005151 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005152 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005153 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005154 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155}
5156
5157static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5158{
5159 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005160 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005161 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162 int status;
5163
5164 status = decode_op_hdr(xdr, OP_READLINK);
5165 if (status)
5166 return status;
5167
5168 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005169 p = xdr_inline_decode(xdr, 4);
5170 if (unlikely(!p))
5171 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005172 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005174 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175 return -ENAMETOOLONG;
5176 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005177 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005179 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005180 "count %u > recvd %u\n", len, recvd);
5181 return -EIO;
5182 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005183 /*
5184 * The XDR encode routine has set things up so that
5185 * the link text will be copied directly into the
5186 * buffer. We just have to do overflow-checking,
5187 * and and null-terminate the text (the VFS expects
5188 * null-termination).
5189 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005190 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005192out_overflow:
5193 print_overflow_msg(__func__, xdr);
5194 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195}
5196
5197static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5198{
5199 int status;
5200
5201 status = decode_op_hdr(xdr, OP_REMOVE);
5202 if (status)
5203 goto out;
5204 status = decode_change_info(xdr, cinfo);
5205out:
5206 return status;
5207}
5208
5209static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5210 struct nfs4_change_info *new_cinfo)
5211{
5212 int status;
5213
5214 status = decode_op_hdr(xdr, OP_RENAME);
5215 if (status)
5216 goto out;
5217 if ((status = decode_change_info(xdr, old_cinfo)))
5218 goto out;
5219 status = decode_change_info(xdr, new_cinfo);
5220out:
5221 return status;
5222}
5223
5224static int decode_renew(struct xdr_stream *xdr)
5225{
5226 return decode_op_hdr(xdr, OP_RENEW);
5227}
5228
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005229static int
5230decode_restorefh(struct xdr_stream *xdr)
5231{
5232 return decode_op_hdr(xdr, OP_RESTOREFH);
5233}
5234
J. Bruce Fields029d1052005-06-22 17:16:22 +00005235static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005236 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005237{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005238 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005239 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005240 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005241 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005242 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005243
Andy Adamsonbf118a32011-12-07 11:55:27 -05005244 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005245 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5246 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005247
Trond Myklebust519d3952012-08-14 17:30:10 -04005248 xdr_enter_page(xdr, xdr->buf->page_len);
5249
Trond Myklebustcff298c2012-08-14 17:14:17 -04005250 /* Calculate the offset of the page data */
5251 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005252
J. Bruce Fields029d1052005-06-22 17:16:22 +00005253 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5254 goto out;
5255 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5256 goto out;
5257
5258 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5259 return -EIO;
5260 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005261
Andy Adamsonbf118a32011-12-07 11:55:27 -05005262 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5263 * are stored with the acl data to handle the problem of
5264 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005265 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005266 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005267
5268 /* Check for receive buffer overflow */
5269 if (res->acl_len > (xdr->nwords << 2) ||
5270 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5271 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005272 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005273 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005274 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005275 } else
5276 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005277
5278out:
5279 return status;
5280}
5281
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282static int
5283decode_savefh(struct xdr_stream *xdr)
5284{
5285 return decode_op_hdr(xdr, OP_SAVEFH);
5286}
5287
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005288static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005289{
Al Viro8687b632006-10-19 23:28:48 -07005290 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005291 uint32_t bmlen;
5292 int status;
5293
Linus Torvalds1da177e2005-04-16 15:20:36 -07005294 status = decode_op_hdr(xdr, OP_SETATTR);
5295 if (status)
5296 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005297 p = xdr_inline_decode(xdr, 4);
5298 if (unlikely(!p))
5299 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005300 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005301 p = xdr_inline_decode(xdr, bmlen << 2);
5302 if (likely(p))
5303 return 0;
5304out_overflow:
5305 print_overflow_msg(__func__, xdr);
5306 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005307}
5308
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005309static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005310{
Al Viro8687b632006-10-19 23:28:48 -07005311 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312 uint32_t opnum;
5313 int32_t nfserr;
5314
Benny Halevyc0eae662009-08-14 17:20:14 +03005315 p = xdr_inline_decode(xdr, 8);
5316 if (unlikely(!p))
5317 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005318 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005320 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005321 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005322 return -EIO;
5323 }
Benny Halevycccddf42009-08-14 17:20:19 +03005324 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005326 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5327 if (unlikely(!p))
5328 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005329 p = xdr_decode_hyper(p, &res->clientid);
5330 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005331 } else if (nfserr == NFSERR_CLID_INUSE) {
5332 uint32_t len;
5333
5334 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005335 p = xdr_inline_decode(xdr, 4);
5336 if (unlikely(!p))
5337 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005338 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005339 p = xdr_inline_decode(xdr, len);
5340 if (unlikely(!p))
5341 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342
5343 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005344 p = xdr_inline_decode(xdr, 4);
5345 if (unlikely(!p))
5346 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005347 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005348 p = xdr_inline_decode(xdr, len);
5349 if (unlikely(!p))
5350 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351 return -NFSERR_CLID_INUSE;
5352 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005353 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005354
5355 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005356out_overflow:
5357 print_overflow_msg(__func__, xdr);
5358 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005359}
5360
5361static int decode_setclientid_confirm(struct xdr_stream *xdr)
5362{
5363 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5364}
5365
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005366static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005367{
Al Viro8687b632006-10-19 23:28:48 -07005368 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005369 int status;
5370
5371 status = decode_op_hdr(xdr, OP_WRITE);
5372 if (status)
5373 return status;
5374
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005375 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005376 if (unlikely(!p))
5377 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005378 res->count = be32_to_cpup(p++);
5379 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005380 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005381out_overflow:
5382 print_overflow_msg(__func__, xdr);
5383 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384}
5385
5386static int decode_delegreturn(struct xdr_stream *xdr)
5387{
5388 return decode_op_hdr(xdr, OP_DELEGRETURN);
5389}
5390
Chuck Leverfb15b262013-03-16 15:54:34 -04005391static int decode_secinfo_gss(struct xdr_stream *xdr,
5392 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005393{
Chuck Leverfb15b262013-03-16 15:54:34 -04005394 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005395 __be32 *p;
5396
5397 p = xdr_inline_decode(xdr, 4);
5398 if (unlikely(!p))
5399 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005400 oid_len = be32_to_cpup(p);
5401 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005402 goto out_err;
5403
Chuck Leverfb15b262013-03-16 15:54:34 -04005404 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005405 if (unlikely(!p))
5406 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005407 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5408 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005409
5410 p = xdr_inline_decode(xdr, 8);
5411 if (unlikely(!p))
5412 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005413 flavor->flavor_info.qop = be32_to_cpup(p++);
5414 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005415
5416 return 0;
5417
5418out_overflow:
5419 print_overflow_msg(__func__, xdr);
5420 return -EIO;
5421out_err:
5422 return -EINVAL;
5423}
5424
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005425static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005426{
Chuck Leverfb15b262013-03-16 15:54:34 -04005427 struct nfs4_secinfo4 *sec_flavor;
5428 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005429 int status;
5430 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005431
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005432 p = xdr_inline_decode(xdr, 4);
5433 if (unlikely(!p))
5434 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005435
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005436 res->flavors->num_flavors = 0;
5437 num_flavors = be32_to_cpup(p);
5438
5439 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005440 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005441 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005442 break;
5443
5444 p = xdr_inline_decode(xdr, 4);
5445 if (unlikely(!p))
5446 goto out_overflow;
5447 sec_flavor->flavor = be32_to_cpup(p);
5448
5449 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005450 status = decode_secinfo_gss(xdr, sec_flavor);
5451 if (status)
5452 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005453 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005454 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005455 }
5456
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005457 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005458out:
5459 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005460out_overflow:
5461 print_overflow_msg(__func__, xdr);
5462 return -EIO;
5463}
5464
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005465static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5466{
5467 int status = decode_op_hdr(xdr, OP_SECINFO);
5468 if (status)
5469 return status;
5470 return decode_secinfo_common(xdr, res);
5471}
5472
Benny Halevy99fe60d2009-04-01 09:22:29 -04005473#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005474static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5475{
5476 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5477 if (status)
5478 return status;
5479 return decode_secinfo_common(xdr, res);
5480}
5481
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005482static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5483{
5484 __be32 *p;
5485 uint32_t bitmap_words;
5486 unsigned int i;
5487
5488 p = xdr_inline_decode(xdr, 4);
5489 bitmap_words = be32_to_cpup(p++);
5490 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5491 return -EIO;
5492 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5493 for (i = 0; i < bitmap_words; i++)
5494 op_map->u.words[i] = be32_to_cpup(p++);
5495
5496 return 0;
5497}
5498
Benny Halevy99fe60d2009-04-01 09:22:29 -04005499static int decode_exchange_id(struct xdr_stream *xdr,
5500 struct nfs41_exchange_id_res *res)
5501{
5502 __be32 *p;
5503 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005504 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005505 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005506 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005507
5508 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5509 if (status)
5510 return status;
5511
Benny Halevyc0eae662009-08-14 17:20:14 +03005512 p = xdr_inline_decode(xdr, 8);
5513 if (unlikely(!p))
5514 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005515 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005516 p = xdr_inline_decode(xdr, 12);
5517 if (unlikely(!p))
5518 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005519 res->seqid = be32_to_cpup(p++);
5520 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005521
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005522 res->state_protect.how = be32_to_cpup(p);
5523 switch (res->state_protect.how) {
5524 case SP4_NONE:
5525 break;
5526 case SP4_MACH_CRED:
5527 status = decode_op_map(xdr, &res->state_protect.enforce);
5528 if (status)
5529 return status;
5530 status = decode_op_map(xdr, &res->state_protect.allow);
5531 if (status)
5532 return status;
5533 break;
5534 default:
5535 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005536 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005537 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005538
Chuck Leveracdeb692012-05-21 22:46:16 -04005539 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005540 p = xdr_inline_decode(xdr, 8);
5541 if (unlikely(!p))
5542 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005543 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005544
Chuck Leveracdeb692012-05-21 22:46:16 -04005545 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005546 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5547 if (unlikely(status))
5548 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005549 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5550 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005551 memcpy(res->server_owner->major_id, dummy_str, dummy);
5552 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005553
Chuck Leveracdeb692012-05-21 22:46:16 -04005554 /* server_scope4 */
5555 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5556 if (unlikely(status))
5557 return status;
5558 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5559 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005560 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5561 res->server_scope->server_scope_sz = dummy;
5562
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005563 /* Implementation Id */
5564 p = xdr_inline_decode(xdr, 4);
5565 if (unlikely(!p))
5566 goto out_overflow;
5567 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005568
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005569 if (impl_id_count) {
5570 /* nii_domain */
5571 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5572 if (unlikely(status))
5573 return status;
5574 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5575 return -EIO;
5576 memcpy(res->impl_id->domain, dummy_str, dummy);
5577
5578 /* nii_name */
5579 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5580 if (unlikely(status))
5581 return status;
5582 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5583 return -EIO;
5584 memcpy(res->impl_id->name, dummy_str, dummy);
5585
5586 /* nii_date */
5587 p = xdr_inline_decode(xdr, 12);
5588 if (unlikely(!p))
5589 goto out_overflow;
5590 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5591 res->impl_id->date.nseconds = be32_to_cpup(p);
5592
5593 /* if there's more than one entry, ignore the rest */
5594 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005595 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005596out_overflow:
5597 print_overflow_msg(__func__, xdr);
5598 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005599}
Andy Adamsonfc931582009-04-01 09:22:31 -04005600
5601static int decode_chan_attrs(struct xdr_stream *xdr,
5602 struct nfs4_channel_attrs *attrs)
5603{
5604 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005605 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005606
Benny Halevyc0eae662009-08-14 17:20:14 +03005607 p = xdr_inline_decode(xdr, 28);
5608 if (unlikely(!p))
5609 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005610 val = be32_to_cpup(p++); /* headerpadsz */
5611 if (val)
5612 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005613 attrs->max_rqst_sz = be32_to_cpup(p++);
5614 attrs->max_resp_sz = be32_to_cpup(p++);
5615 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5616 attrs->max_ops = be32_to_cpup(p++);
5617 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005618 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005619 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005620 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5621 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005622 return -EINVAL;
5623 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005624 if (nr_attrs == 1) {
5625 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5626 if (unlikely(!p))
5627 goto out_overflow;
5628 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005629 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005630out_overflow:
5631 print_overflow_msg(__func__, xdr);
5632 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005633}
5634
Benny Halevye78291e2009-08-14 17:20:00 +03005635static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5636{
5637 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005638}
5639
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005640static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5641 struct nfs41_bind_conn_to_session_res *res)
5642{
5643 __be32 *p;
5644 int status;
5645
5646 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5647 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005648 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005649 if (unlikely(status))
5650 return status;
5651
5652 /* dir flags, rdma mode bool */
5653 p = xdr_inline_decode(xdr, 8);
5654 if (unlikely(!p))
5655 goto out_overflow;
5656
5657 res->dir = be32_to_cpup(p++);
5658 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5659 return -EIO;
5660 if (be32_to_cpup(p) == 0)
5661 res->use_conn_in_rdma_mode = false;
5662 else
5663 res->use_conn_in_rdma_mode = true;
5664
5665 return 0;
5666out_overflow:
5667 print_overflow_msg(__func__, xdr);
5668 return -EIO;
5669}
5670
Andy Adamsonfc931582009-04-01 09:22:31 -04005671static int decode_create_session(struct xdr_stream *xdr,
5672 struct nfs41_create_session_res *res)
5673{
5674 __be32 *p;
5675 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005676
5677 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005678 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005679 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005680 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005681 return status;
5682
Andy Adamsonfc931582009-04-01 09:22:31 -04005683 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005684 p = xdr_inline_decode(xdr, 8);
5685 if (unlikely(!p))
5686 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005687 res->seqid = be32_to_cpup(p++);
5688 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005689
5690 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005691 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005692 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005693 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005694 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005695out_overflow:
5696 print_overflow_msg(__func__, xdr);
5697 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005698}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005699
5700static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5701{
5702 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5703}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005704
Trond Myklebust66245532012-05-25 17:18:09 -04005705static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5706{
5707 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5708}
5709
Ricardo Labiaga180197532009-12-05 16:08:40 -05005710static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5711{
5712 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5713}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005714#endif /* CONFIG_NFS_V4_1 */
5715
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005716static int decode_sequence(struct xdr_stream *xdr,
5717 struct nfs4_sequence_res *res,
5718 struct rpc_rqst *rqstp)
5719{
5720#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005721 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005722 struct nfs4_sessionid id;
5723 u32 dummy;
5724 int status;
5725 __be32 *p;
5726
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005727 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005728 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005729 if (!res->sr_slot->table->session)
5730 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005731
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005732 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005733 if (!status)
5734 status = decode_sessionid(xdr, &id);
5735 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005736 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005737
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005738 /*
5739 * If the server returns different values for sessionID, slotID or
5740 * sequence number, the server is looney tunes.
5741 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005742 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005743 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005744
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005745 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005746 NFS4_MAX_SESSIONID_LEN)) {
5747 dprintk("%s Invalid session id\n", __func__);
5748 goto out_err;
5749 }
Benny Halevye78291e2009-08-14 17:20:00 +03005750
Benny Halevyc0eae662009-08-14 17:20:14 +03005751 p = xdr_inline_decode(xdr, 20);
5752 if (unlikely(!p))
5753 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005754
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005755 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005756 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005757 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005758 dprintk("%s Invalid sequence number\n", __func__);
5759 goto out_err;
5760 }
5761 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005762 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005763 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005764 dprintk("%s Invalid slot id\n", __func__);
5765 goto out_err;
5766 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005767 /* highest slot id */
5768 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005769 /* target highest slot id */
5770 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005771 /* result flags */
5772 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005773 status = 0;
5774out_err:
5775 res->sr_status = status;
5776 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005777out_overflow:
5778 print_overflow_msg(__func__, xdr);
5779 status = -EIO;
5780 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005781#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005782 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005783#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005784}
5785
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005786#if defined(CONFIG_NFS_V4_1)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005787static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005788 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005789{
Trond Myklebust4e590802015-03-09 14:01:25 -04005790 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005791 __be32 *p;
5792 uint32_t len, type;
5793 int status;
5794
5795 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5796 if (status) {
5797 if (status == -ETOOSMALL) {
5798 p = xdr_inline_decode(xdr, 4);
5799 if (unlikely(!p))
5800 goto out_overflow;
5801 pdev->mincount = be32_to_cpup(p);
5802 dprintk("%s: Min count too small. mincnt = %u\n",
5803 __func__, pdev->mincount);
5804 }
5805 return status;
5806 }
5807
5808 p = xdr_inline_decode(xdr, 8);
5809 if (unlikely(!p))
5810 goto out_overflow;
5811 type = be32_to_cpup(p++);
5812 if (type != pdev->layout_type) {
5813 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5814 __func__, pdev->layout_type, type);
5815 return -EINVAL;
5816 }
5817 /*
5818 * Get the length of the opaque device_addr4. xdr_read_pages places
5819 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5820 * and places the remaining xdr data in xdr_buf->tail
5821 */
5822 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005823 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5824 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005825
5826 /* Parse notification bitmap, verifying that it is zero. */
5827 p = xdr_inline_decode(xdr, 4);
5828 if (unlikely(!p))
5829 goto out_overflow;
5830 len = be32_to_cpup(p);
5831 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005832 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005833
5834 p = xdr_inline_decode(xdr, 4 * len);
5835 if (unlikely(!p))
5836 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005837
Trond Myklebust4e590802015-03-09 14:01:25 -04005838 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005839 for (i = 1; i < len; i++) {
5840 if (be32_to_cpup(p++)) {
5841 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005842 __func__);
5843 return -EIO;
5844 }
5845 }
5846 }
5847 return 0;
5848out_overflow:
5849 print_overflow_msg(__func__, xdr);
5850 return -EIO;
5851}
5852
5853static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5854 struct nfs4_layoutget_res *res)
5855{
5856 __be32 *p;
5857 int status;
5858 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005859 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005860
5861 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5862 if (status)
5863 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005864 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005865 if (unlikely(!p))
5866 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005867 res->return_on_close = be32_to_cpup(p);
5868 decode_stateid(xdr, &res->stateid);
5869 p = xdr_inline_decode(xdr, 4);
5870 if (unlikely(!p))
5871 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005872 layout_count = be32_to_cpup(p);
5873 if (!layout_count) {
5874 dprintk("%s: server responded with empty layout array\n",
5875 __func__);
5876 return -EINVAL;
5877 }
5878
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005879 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005880 if (unlikely(!p))
5881 goto out_overflow;
5882 p = xdr_decode_hyper(p, &res->range.offset);
5883 p = xdr_decode_hyper(p, &res->range.length);
5884 res->range.iomode = be32_to_cpup(p++);
5885 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005886 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005887
5888 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5889 __func__,
5890 (unsigned long)res->range.offset,
5891 (unsigned long)res->range.length,
5892 res->range.iomode,
5893 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005894 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005895
Trond Myklebust64bd5772012-06-20 22:35:05 -04005896 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005897 if (res->layoutp->len > recvd) {
5898 dprintk("NFS: server cheating in layoutget reply: "
5899 "layout len %u > recvd %u\n",
5900 res->layoutp->len, recvd);
5901 return -EINVAL;
5902 }
5903
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005904 if (layout_count > 1) {
5905 /* We only handle a length one array at the moment. Any
5906 * further entries are just ignored. Note that this means
5907 * the client may see a response that is less than the
5908 * minimum it requested.
5909 */
5910 dprintk("%s: server responded with %d layouts, dropping tail\n",
5911 __func__, layout_count);
5912 }
5913
5914 return 0;
5915out_overflow:
5916 print_overflow_msg(__func__, xdr);
5917 return -EIO;
5918}
Andy Adamson863a3c62011-03-23 13:27:54 +00005919
Benny Halevycbe82602011-05-22 19:52:37 +03005920static int decode_layoutreturn(struct xdr_stream *xdr,
5921 struct nfs4_layoutreturn_res *res)
5922{
5923 __be32 *p;
5924 int status;
5925
5926 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5927 if (status)
5928 return status;
5929 p = xdr_inline_decode(xdr, 4);
5930 if (unlikely(!p))
5931 goto out_overflow;
5932 res->lrs_present = be32_to_cpup(p);
5933 if (res->lrs_present)
5934 status = decode_stateid(xdr, &res->stateid);
5935 return status;
5936out_overflow:
5937 print_overflow_msg(__func__, xdr);
5938 return -EIO;
5939}
5940
Andy Adamson863a3c62011-03-23 13:27:54 +00005941static int decode_layoutcommit(struct xdr_stream *xdr,
5942 struct rpc_rqst *req,
5943 struct nfs4_layoutcommit_res *res)
5944{
5945 __be32 *p;
5946 __u32 sizechanged;
5947 int status;
5948
5949 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005950 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005951 if (status)
5952 return status;
5953
5954 p = xdr_inline_decode(xdr, 4);
5955 if (unlikely(!p))
5956 goto out_overflow;
5957 sizechanged = be32_to_cpup(p);
5958
5959 if (sizechanged) {
5960 /* throw away new size */
5961 p = xdr_inline_decode(xdr, 8);
5962 if (unlikely(!p))
5963 goto out_overflow;
5964 }
5965 return 0;
5966out_overflow:
5967 print_overflow_msg(__func__, xdr);
5968 return -EIO;
5969}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005970
5971static int decode_test_stateid(struct xdr_stream *xdr,
5972 struct nfs41_test_stateid_res *res)
5973{
5974 __be32 *p;
5975 int status;
5976 int num_res;
5977
5978 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5979 if (status)
5980 return status;
5981
5982 p = xdr_inline_decode(xdr, 4);
5983 if (unlikely(!p))
5984 goto out_overflow;
5985 num_res = be32_to_cpup(p++);
5986 if (num_res != 1)
5987 goto out;
5988
5989 p = xdr_inline_decode(xdr, 4);
5990 if (unlikely(!p))
5991 goto out_overflow;
5992 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005993
5994 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005995out_overflow:
5996 print_overflow_msg(__func__, xdr);
5997out:
5998 return -EIO;
5999}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006000
6001static int decode_free_stateid(struct xdr_stream *xdr,
6002 struct nfs41_free_stateid_res *res)
6003{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006004 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006005 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006006}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006007#endif /* CONFIG_NFS_V4_1 */
6008
Linus Torvalds1da177e2005-04-16 15:20:36 -07006009/*
Benny Halevy49c25592008-12-23 16:06:16 -05006010 * END OF "GENERIC" DECODE ROUTINES.
6011 */
6012
6013/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014 * Decode OPEN_DOWNGRADE response
6015 */
Chuck Leverbf269552010-12-14 14:59:29 +00006016static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6017 struct xdr_stream *xdr,
6018 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019{
Andy Adamson05d564f2008-12-23 16:06:15 -05006020 struct compound_hdr hdr;
6021 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022
Chuck Leverbf269552010-12-14 14:59:29 +00006023 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006024 if (status)
6025 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006026 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006027 if (status)
6028 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006029 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006030 if (status)
6031 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006032 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006033 if (status != 0)
6034 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006035 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006036out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006037 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006038}
6039
6040/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006041 * Decode ACCESS response
6042 */
Chuck Leverbf269552010-12-14 14:59:29 +00006043static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6044 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006045{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046 struct compound_hdr hdr;
6047 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006048
Chuck Leverbf269552010-12-14 14:59:29 +00006049 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006050 if (status)
6051 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006052 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006053 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006055 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006056 if (status != 0)
6057 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006058 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006059 if (status != 0)
6060 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006061 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062out:
6063 return status;
6064}
6065
6066/*
6067 * Decode LOOKUP response
6068 */
Chuck Leverbf269552010-12-14 14:59:29 +00006069static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6070 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072 struct compound_hdr hdr;
6073 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006074
Chuck Leverbf269552010-12-14 14:59:29 +00006075 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006076 if (status)
6077 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006078 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006079 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006080 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006081 status = decode_putfh(xdr);
6082 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006084 status = decode_lookup(xdr);
6085 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006087 status = decode_getfh(xdr, res->fh);
6088 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006090 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006091out:
6092 return status;
6093}
6094
6095/*
6096 * Decode LOOKUP_ROOT response
6097 */
Chuck Leverbf269552010-12-14 14:59:29 +00006098static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6099 struct xdr_stream *xdr,
6100 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102 struct compound_hdr hdr;
6103 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006104
Chuck Leverbf269552010-12-14 14:59:29 +00006105 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006106 if (status)
6107 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006108 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006109 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006111 status = decode_putrootfh(xdr);
6112 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006114 status = decode_getfh(xdr, res->fh);
6115 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006116 status = decode_getfattr_label(xdr, res->fattr,
6117 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118out:
6119 return status;
6120}
6121
6122/*
6123 * Decode REMOVE response
6124 */
Chuck Leverbf269552010-12-14 14:59:29 +00006125static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6126 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128 struct compound_hdr hdr;
6129 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006130
Chuck Leverbf269552010-12-14 14:59:29 +00006131 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006132 if (status)
6133 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006134 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006135 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006136 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_putfh(xdr);
6138 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006139 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006140 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141out:
6142 return status;
6143}
6144
6145/*
6146 * Decode RENAME response
6147 */
Chuck Leverbf269552010-12-14 14:59:29 +00006148static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6149 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151 struct compound_hdr hdr;
6152 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006153
Chuck Leverbf269552010-12-14 14:59:29 +00006154 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006155 if (status)
6156 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006157 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006158 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006159 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006160 status = decode_putfh(xdr);
6161 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006163 status = decode_savefh(xdr);
6164 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006166 status = decode_putfh(xdr);
6167 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170out:
6171 return status;
6172}
6173
6174/*
6175 * Decode LINK response
6176 */
Chuck Leverbf269552010-12-14 14:59:29 +00006177static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6178 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180 struct compound_hdr hdr;
6181 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006182
Chuck Leverbf269552010-12-14 14:59:29 +00006183 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006184 if (status)
6185 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006186 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006187 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006189 status = decode_putfh(xdr);
6190 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006192 status = decode_savefh(xdr);
6193 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_putfh(xdr);
6196 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_link(xdr, &res->cinfo);
6199 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006200 goto out;
6201 /*
6202 * Note order: OP_LINK leaves the directory as the current
6203 * filehandle.
6204 */
Chuck Leverbf269552010-12-14 14:59:29 +00006205 status = decode_restorefh(xdr);
6206 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006207 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006208 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209out:
6210 return status;
6211}
6212
6213/*
6214 * Decode CREATE response
6215 */
Chuck Leverbf269552010-12-14 14:59:29 +00006216static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6217 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219 struct compound_hdr hdr;
6220 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006221
Chuck Leverbf269552010-12-14 14:59:29 +00006222 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006223 if (status)
6224 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006225 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006226 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006228 status = decode_putfh(xdr);
6229 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006231 status = decode_create(xdr, &res->dir_cinfo);
6232 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006234 status = decode_getfh(xdr, res->fh);
6235 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006237 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238out:
6239 return status;
6240}
6241
6242/*
6243 * Decode SYMLINK response
6244 */
Chuck Leverbf269552010-12-14 14:59:29 +00006245static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6246 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006247{
Chuck Leverbf269552010-12-14 14:59:29 +00006248 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006249}
6250
6251/*
6252 * Decode GETATTR response
6253 */
Chuck Leverbf269552010-12-14 14:59:29 +00006254static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6255 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006256{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257 struct compound_hdr hdr;
6258 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006259
Chuck Leverbf269552010-12-14 14:59:29 +00006260 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261 if (status)
6262 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006263 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006264 if (status)
6265 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006266 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267 if (status)
6268 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006269 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270out:
6271 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272}
6273
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006274/*
6275 * Encode an SETACL request
6276 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006277static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6278 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006279{
Andy Adamson05d564f2008-12-23 16:06:15 -05006280 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006281 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006282 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006283
Chuck Lever9f06c712010-12-14 14:59:18 +00006284 encode_compound_hdr(xdr, req, &hdr);
6285 encode_sequence(xdr, &args->seq_args, &hdr);
6286 encode_putfh(xdr, args->fh, &hdr);
6287 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006288 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006289}
Andy Adamson05d564f2008-12-23 16:06:15 -05006290
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006291/*
6292 * Decode SETACL response
6293 */
6294static int
Chuck Leverbf269552010-12-14 14:59:29 +00006295nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006296 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006297{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006298 struct compound_hdr hdr;
6299 int status;
6300
Chuck Leverbf269552010-12-14 14:59:29 +00006301 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006302 if (status)
6303 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006304 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006305 if (status)
6306 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006308 if (status)
6309 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006311out:
6312 return status;
6313}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006314
6315/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006316 * Decode GETACL response
6317 */
6318static int
Chuck Leverbf269552010-12-14 14:59:29 +00006319nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006320 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006321{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006322 struct compound_hdr hdr;
6323 int status;
6324
Trond Myklebust331818f2012-02-03 18:30:53 -05006325 if (res->acl_scratch != NULL) {
6326 void *p = page_address(res->acl_scratch);
6327 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6328 }
Chuck Leverbf269552010-12-14 14:59:29 +00006329 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006330 if (status)
6331 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006332 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006333 if (status)
6334 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006335 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006336 if (status)
6337 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006338 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006339
6340out:
6341 return status;
6342}
6343
6344/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 * Decode CLOSE response
6346 */
Chuck Leverbf269552010-12-14 14:59:29 +00006347static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6348 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349{
Andy Adamson05d564f2008-12-23 16:06:15 -05006350 struct compound_hdr hdr;
6351 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352
Chuck Leverbf269552010-12-14 14:59:29 +00006353 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006354 if (status)
6355 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006356 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006357 if (status)
6358 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006359 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006360 if (status)
6361 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006362 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006363 if (status != 0)
6364 goto out;
6365 /*
6366 * Note: Server may do delete on close for this file
6367 * in which case the getattr call will fail with
6368 * an ESTALE error. Shouldn't be a problem,
6369 * though, since fattr->valid will remain unset.
6370 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006371 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006373 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374}
6375
6376/*
6377 * Decode OPEN response
6378 */
Chuck Leverbf269552010-12-14 14:59:29 +00006379static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6380 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381{
Andy Adamson05d564f2008-12-23 16:06:15 -05006382 struct compound_hdr hdr;
6383 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006384
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006386 if (status)
6387 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006388 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006389 if (status)
6390 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006391 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006392 if (status)
6393 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006394 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006395 if (status)
6396 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006397 status = decode_getfh(xdr, &res->fh);
6398 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006399 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006400 if (res->access_request)
6401 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006402 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006403out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006404 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405}
6406
6407/*
6408 * Decode OPEN_CONFIRM response
6409 */
Chuck Leverbf269552010-12-14 14:59:29 +00006410static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6411 struct xdr_stream *xdr,
6412 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006413{
Andy Adamson05d564f2008-12-23 16:06:15 -05006414 struct compound_hdr hdr;
6415 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416
Chuck Leverbf269552010-12-14 14:59:29 +00006417 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006418 if (status)
6419 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006420 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006421 if (status)
6422 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006423 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006424out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006425 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426}
6427
6428/*
6429 * Decode OPEN response
6430 */
Chuck Leverbf269552010-12-14 14:59:29 +00006431static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6432 struct xdr_stream *xdr,
6433 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006434{
Andy Adamson05d564f2008-12-23 16:06:15 -05006435 struct compound_hdr hdr;
6436 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437
Chuck Leverbf269552010-12-14 14:59:29 +00006438 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006439 if (status)
6440 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006441 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006442 if (status)
6443 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006444 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006445 if (status)
6446 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006448 if (status)
6449 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006450 if (res->access_request)
6451 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006452 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006454 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006455}
6456
6457/*
6458 * Decode SETATTR response
6459 */
Chuck Leverbf269552010-12-14 14:59:29 +00006460static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6461 struct xdr_stream *xdr,
6462 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463{
Andy Adamson05d564f2008-12-23 16:06:15 -05006464 struct compound_hdr hdr;
6465 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466
Chuck Leverbf269552010-12-14 14:59:29 +00006467 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006468 if (status)
6469 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006470 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006471 if (status)
6472 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006473 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006474 if (status)
6475 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006476 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006477 if (status)
6478 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006479 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006481 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482}
6483
6484/*
6485 * Decode LOCK response
6486 */
Chuck Leverbf269552010-12-14 14:59:29 +00006487static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6488 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490 struct compound_hdr hdr;
6491 int status;
6492
Chuck Leverbf269552010-12-14 14:59:29 +00006493 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006494 if (status)
6495 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006496 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006497 if (status)
6498 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006499 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006500 if (status)
6501 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006502 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006503out:
6504 return status;
6505}
6506
6507/*
6508 * Decode LOCKT response
6509 */
Chuck Leverbf269552010-12-14 14:59:29 +00006510static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6511 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006512{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513 struct compound_hdr hdr;
6514 int status;
6515
Chuck Leverbf269552010-12-14 14:59:29 +00006516 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006517 if (status)
6518 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006519 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006520 if (status)
6521 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006522 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006523 if (status)
6524 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006525 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526out:
6527 return status;
6528}
6529
6530/*
6531 * Decode LOCKU response
6532 */
Chuck Leverbf269552010-12-14 14:59:29 +00006533static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6534 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 struct compound_hdr hdr;
6537 int status;
6538
Chuck Leverbf269552010-12-14 14:59:29 +00006539 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006540 if (status)
6541 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006542 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006543 if (status)
6544 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006545 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006546 if (status)
6547 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006548 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006549out:
6550 return status;
6551}
6552
Chuck Leverbf269552010-12-14 14:59:29 +00006553static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6554 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006555{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006556 struct compound_hdr hdr;
6557 int status;
6558
Chuck Leverbf269552010-12-14 14:59:29 +00006559 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006560 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006562 return status;
6563}
6564
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565/*
6566 * Decode READLINK response
6567 */
Chuck Leverbf269552010-12-14 14:59:29 +00006568static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6569 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006570 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006571{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572 struct compound_hdr hdr;
6573 int status;
6574
Chuck Leverbf269552010-12-14 14:59:29 +00006575 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006576 if (status)
6577 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006578 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006579 if (status)
6580 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006582 if (status)
6583 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006584 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585out:
6586 return status;
6587}
6588
6589/*
6590 * Decode READDIR response
6591 */
Chuck Leverbf269552010-12-14 14:59:29 +00006592static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6593 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006594{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595 struct compound_hdr hdr;
6596 int status;
6597
Chuck Leverbf269552010-12-14 14:59:29 +00006598 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599 if (status)
6600 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006601 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006602 if (status)
6603 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006604 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006605 if (status)
6606 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006607 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006608out:
6609 return status;
6610}
6611
6612/*
6613 * Decode Read response
6614 */
Chuck Leverbf269552010-12-14 14:59:29 +00006615static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006616 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006618 struct compound_hdr hdr;
6619 int status;
6620
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006622 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006623 if (status)
6624 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006625 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006626 if (status)
6627 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006628 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629 if (status)
6630 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006631 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006632 if (!status)
6633 status = res->count;
6634out:
6635 return status;
6636}
6637
6638/*
6639 * Decode WRITE response
6640 */
Chuck Leverbf269552010-12-14 14:59:29 +00006641static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006642 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006644 struct compound_hdr hdr;
6645 int status;
6646
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006648 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649 if (status)
6650 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006652 if (status)
6653 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006654 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655 if (status)
6656 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006657 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006658 if (status)
6659 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006660 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006661 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006662 if (!status)
6663 status = res->count;
6664out:
6665 return status;
6666}
6667
6668/*
6669 * Decode COMMIT response
6670 */
Chuck Leverbf269552010-12-14 14:59:29 +00006671static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006672 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006673{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674 struct compound_hdr hdr;
6675 int status;
6676
Chuck Leverbf269552010-12-14 14:59:29 +00006677 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006678 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006679 if (status)
6680 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006681 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006682 if (status)
6683 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006684 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006685 if (status)
6686 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006687 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006688out:
6689 return status;
6690}
6691
6692/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006693 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006694 */
Chuck Leverbf269552010-12-14 14:59:29 +00006695static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006696 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006697{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006698 struct compound_hdr hdr;
6699 int status;
6700
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006703 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006704 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006705 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006706 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006707 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006708 return status;
6709}
6710
6711/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006712 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006713 */
Chuck Leverbf269552010-12-14 14:59:29 +00006714static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006715 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006716{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006717 struct compound_hdr hdr;
6718 int status;
6719
Chuck Leverbf269552010-12-14 14:59:29 +00006720 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006721 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006722 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006723 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006724 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006725 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006726 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006727 return status;
6728}
6729
6730/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006731 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006732 */
Chuck Leverbf269552010-12-14 14:59:29 +00006733static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006734 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006735{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 struct compound_hdr hdr;
6737 int status;
6738
Chuck Leverbf269552010-12-14 14:59:29 +00006739 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006740 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006741 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006742 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006743 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006745 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006746 return status;
6747}
6748
6749/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006750 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006751 */
Chuck Leverbf269552010-12-14 14:59:29 +00006752static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6753 struct xdr_stream *xdr,
6754 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006755{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006756 struct compound_hdr hdr;
6757 int status;
6758
Chuck Leverbf269552010-12-14 14:59:29 +00006759 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006760 if (status)
6761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006762 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006763 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006764 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006765 status = decode_putfh(xdr);
6766 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006767 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006768 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769out:
6770 return status;
6771}
6772
6773/*
6774 * Decode RENEW response
6775 */
Chuck Leverbf269552010-12-14 14:59:29 +00006776static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6777 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006779 struct compound_hdr hdr;
6780 int status;
6781
Chuck Leverbf269552010-12-14 14:59:29 +00006782 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006783 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006784 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006785 return status;
6786}
6787
6788/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006789 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006790 */
Chuck Leverbf269552010-12-14 14:59:29 +00006791static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6792 struct xdr_stream *xdr,
6793 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006794{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006795 struct compound_hdr hdr;
6796 int status;
6797
Chuck Leverbf269552010-12-14 14:59:29 +00006798 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006799 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006800 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006801 return status;
6802}
6803
6804/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006805 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006806 */
Chuck Leverbf269552010-12-14 14:59:29 +00006807static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006808 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006809{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006810 struct compound_hdr hdr;
6811 int status;
6812
Chuck Leverbf269552010-12-14 14:59:29 +00006813 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006814 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006815 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006816 return status;
6817}
6818
6819/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006820 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006821 */
Chuck Leverbf269552010-12-14 14:59:29 +00006822static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6823 struct xdr_stream *xdr,
6824 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006825{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006826 struct compound_hdr hdr;
6827 int status;
6828
Chuck Leverbf269552010-12-14 14:59:29 +00006829 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006830 if (status)
6831 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006832 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006833 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006834 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006836 if (status != 0)
6837 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006838 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006839 if (status != 0)
6840 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006841 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006842out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006843 return status;
6844}
6845
Trond Myklebust683b57b2006-06-09 09:34:22 -04006846/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006847 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006848 */
Chuck Leverbf269552010-12-14 14:59:29 +00006849static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6850 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006851 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006852{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006853 struct compound_hdr hdr;
6854 int status;
6855
Chuck Leverbf269552010-12-14 14:59:29 +00006856 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006857 if (status)
6858 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006859 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006860 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006861 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006862 status = decode_putfh(xdr);
6863 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006864 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006865 if (res->migration) {
6866 xdr_enter_page(xdr, PAGE_SIZE);
6867 status = decode_getfattr_generic(xdr,
6868 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006869 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006870 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006871 if (status)
6872 goto out;
6873 if (res->renew)
6874 status = decode_renew(xdr);
6875 } else {
6876 status = decode_lookup(xdr);
6877 if (status)
6878 goto out;
6879 xdr_enter_page(xdr, PAGE_SIZE);
6880 status = decode_getfattr_generic(xdr,
6881 &res->fs_locations->fattr,
6882 NULL, res->fs_locations,
6883 NULL, res->fs_locations->server);
6884 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006885out:
6886 return status;
6887}
6888
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006889/*
6890 * Decode SECINFO response
6891 */
6892static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6893 struct xdr_stream *xdr,
6894 struct nfs4_secinfo_res *res)
6895{
6896 struct compound_hdr hdr;
6897 int status;
6898
6899 status = decode_compound_hdr(xdr, &hdr);
6900 if (status)
6901 goto out;
6902 status = decode_sequence(xdr, &res->seq_res, rqstp);
6903 if (status)
6904 goto out;
6905 status = decode_putfh(xdr);
6906 if (status)
6907 goto out;
6908 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006909out:
6910 return status;
6911}
6912
Chuck Lever44c99932013-10-17 14:13:30 -04006913/*
6914 * Decode FSID_PRESENT response
6915 */
6916static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6917 struct xdr_stream *xdr,
6918 struct nfs4_fsid_present_res *res)
6919{
6920 struct compound_hdr hdr;
6921 int status;
6922
6923 status = decode_compound_hdr(xdr, &hdr);
6924 if (status)
6925 goto out;
6926 status = decode_sequence(xdr, &res->seq_res, rqstp);
6927 if (status)
6928 goto out;
6929 status = decode_putfh(xdr);
6930 if (status)
6931 goto out;
6932 status = decode_getfh(xdr, res->fh);
6933 if (status)
6934 goto out;
6935 if (res->renew)
6936 status = decode_renew(xdr);
6937out:
6938 return status;
6939}
6940
Benny Halevy99fe60d2009-04-01 09:22:29 -04006941#if defined(CONFIG_NFS_V4_1)
6942/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006943 * Decode BIND_CONN_TO_SESSION response
6944 */
6945static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6946 struct xdr_stream *xdr,
6947 void *res)
6948{
6949 struct compound_hdr hdr;
6950 int status;
6951
6952 status = decode_compound_hdr(xdr, &hdr);
6953 if (!status)
6954 status = decode_bind_conn_to_session(xdr, res);
6955 return status;
6956}
6957
6958/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006959 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006960 */
Chuck Leverbf269552010-12-14 14:59:29 +00006961static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6962 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006963 void *res)
6964{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006965 struct compound_hdr hdr;
6966 int status;
6967
Chuck Leverbf269552010-12-14 14:59:29 +00006968 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006969 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006970 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006971 return status;
6972}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006973
6974/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006975 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006976 */
Chuck Leverbf269552010-12-14 14:59:29 +00006977static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6978 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006979 struct nfs41_create_session_res *res)
6980{
Andy Adamsonfc931582009-04-01 09:22:31 -04006981 struct compound_hdr hdr;
6982 int status;
6983
Chuck Leverbf269552010-12-14 14:59:29 +00006984 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006985 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006986 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006987 return status;
6988}
6989
6990/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006991 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006992 */
Chuck Leverbf269552010-12-14 14:59:29 +00006993static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6994 struct xdr_stream *xdr,
6995 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006996{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006997 struct compound_hdr hdr;
6998 int status;
6999
Chuck Leverbf269552010-12-14 14:59:29 +00007000 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007001 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007002 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007003 return status;
7004}
7005
7006/*
Trond Myklebust66245532012-05-25 17:18:09 -04007007 * Decode DESTROY_CLIENTID response
7008 */
7009static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7010 struct xdr_stream *xdr,
7011 void *res)
7012{
7013 struct compound_hdr hdr;
7014 int status;
7015
7016 status = decode_compound_hdr(xdr, &hdr);
7017 if (!status)
7018 status = decode_destroy_clientid(xdr, res);
7019 return status;
7020}
7021
7022/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007023 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007024 */
Chuck Leverbf269552010-12-14 14:59:29 +00007025static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7026 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007027 struct nfs4_sequence_res *res)
7028{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007029 struct compound_hdr hdr;
7030 int status;
7031
Chuck Leverbf269552010-12-14 14:59:29 +00007032 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007033 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007034 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007035 return status;
7036}
7037
7038/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007039 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007040 */
Chuck Leverbf269552010-12-14 14:59:29 +00007041static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7042 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007043 struct nfs4_get_lease_time_res *res)
7044{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007045 struct compound_hdr hdr;
7046 int status;
7047
Chuck Leverbf269552010-12-14 14:59:29 +00007048 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007049 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007050 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007051 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007052 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007053 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007054 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007055 return status;
7056}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007057
7058/*
7059 * Decode RECLAIM_COMPLETE response
7060 */
Chuck Leverbf269552010-12-14 14:59:29 +00007061static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7062 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007063 struct nfs41_reclaim_complete_res *res)
7064{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007065 struct compound_hdr hdr;
7066 int status;
7067
Chuck Leverbf269552010-12-14 14:59:29 +00007068 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007069 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007070 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007071 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307072 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007073 return status;
7074}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007075
7076/*
7077 * Decode GETDEVINFO response
7078 */
Chuck Leverbf269552010-12-14 14:59:29 +00007079static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7080 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007081 struct nfs4_getdeviceinfo_res *res)
7082{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007083 struct compound_hdr hdr;
7084 int status;
7085
Chuck Leverbf269552010-12-14 14:59:29 +00007086 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007087 if (status != 0)
7088 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007089 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007090 if (status != 0)
7091 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007092 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007093out:
7094 return status;
7095}
7096
7097/*
7098 * Decode LAYOUTGET response
7099 */
Chuck Leverbf269552010-12-14 14:59:29 +00007100static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7101 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007102 struct nfs4_layoutget_res *res)
7103{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007104 struct compound_hdr hdr;
7105 int status;
7106
Chuck Leverbf269552010-12-14 14:59:29 +00007107 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007108 if (status)
7109 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007110 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007111 if (status)
7112 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007113 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007114 if (status)
7115 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007116 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007117out:
7118 return status;
7119}
Andy Adamson863a3c62011-03-23 13:27:54 +00007120
7121/*
Benny Halevycbe82602011-05-22 19:52:37 +03007122 * Decode LAYOUTRETURN response
7123 */
7124static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7125 struct xdr_stream *xdr,
7126 struct nfs4_layoutreturn_res *res)
7127{
7128 struct compound_hdr hdr;
7129 int status;
7130
7131 status = decode_compound_hdr(xdr, &hdr);
7132 if (status)
7133 goto out;
7134 status = decode_sequence(xdr, &res->seq_res, rqstp);
7135 if (status)
7136 goto out;
7137 status = decode_putfh(xdr);
7138 if (status)
7139 goto out;
7140 status = decode_layoutreturn(xdr, res);
7141out:
7142 return status;
7143}
7144
7145/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007146 * Decode LAYOUTCOMMIT response
7147 */
7148static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7149 struct xdr_stream *xdr,
7150 struct nfs4_layoutcommit_res *res)
7151{
7152 struct compound_hdr hdr;
7153 int status;
7154
7155 status = decode_compound_hdr(xdr, &hdr);
7156 if (status)
7157 goto out;
7158 status = decode_sequence(xdr, &res->seq_res, rqstp);
7159 if (status)
7160 goto out;
7161 status = decode_putfh(xdr);
7162 if (status)
7163 goto out;
7164 status = decode_layoutcommit(xdr, rqstp, res);
7165 if (status)
7166 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007167 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007168out:
7169 return status;
7170}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007171
7172/*
7173 * Decode SECINFO_NO_NAME response
7174 */
7175static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7176 struct xdr_stream *xdr,
7177 struct nfs4_secinfo_res *res)
7178{
7179 struct compound_hdr hdr;
7180 int status;
7181
7182 status = decode_compound_hdr(xdr, &hdr);
7183 if (status)
7184 goto out;
7185 status = decode_sequence(xdr, &res->seq_res, rqstp);
7186 if (status)
7187 goto out;
7188 status = decode_putrootfh(xdr);
7189 if (status)
7190 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007191 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007192out:
7193 return status;
7194}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007195
7196/*
7197 * Decode TEST_STATEID response
7198 */
7199static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7200 struct xdr_stream *xdr,
7201 struct nfs41_test_stateid_res *res)
7202{
7203 struct compound_hdr hdr;
7204 int status;
7205
7206 status = decode_compound_hdr(xdr, &hdr);
7207 if (status)
7208 goto out;
7209 status = decode_sequence(xdr, &res->seq_res, rqstp);
7210 if (status)
7211 goto out;
7212 status = decode_test_stateid(xdr, res);
7213out:
7214 return status;
7215}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007216
7217/*
7218 * Decode FREE_STATEID response
7219 */
7220static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7221 struct xdr_stream *xdr,
7222 struct nfs41_free_stateid_res *res)
7223{
7224 struct compound_hdr hdr;
7225 int status;
7226
7227 status = decode_compound_hdr(xdr, &hdr);
7228 if (status)
7229 goto out;
7230 status = decode_sequence(xdr, &res->seq_res, rqstp);
7231 if (status)
7232 goto out;
7233 status = decode_free_stateid(xdr, res);
7234out:
7235 return status;
7236}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007237#endif /* CONFIG_NFS_V4_1 */
7238
Chuck Lever573c4e12010-12-14 14:58:11 +00007239/**
7240 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7241 * the local page cache.
7242 * @xdr: XDR stream where entry resides
7243 * @entry: buffer to fill in with entry data
7244 * @plus: boolean indicating whether this should be a readdirplus entry
7245 *
7246 * Returns zero if successful, otherwise a negative errno value is
7247 * returned.
7248 *
7249 * This function is not invoked during READDIR reply decoding, but
7250 * rather whenever an application invokes the getdents(2) system call
7251 * on a directory already in our cache.
7252 */
7253int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7254 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007255{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007256 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007257 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007258 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007259 __be32 *p = xdr_inline_decode(xdr, 4);
7260 if (unlikely(!p))
7261 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007262 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007263 p = xdr_inline_decode(xdr, 4);
7264 if (unlikely(!p))
7265 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007266 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007267 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007268 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007269 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007270 }
7271
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007272 p = xdr_inline_decode(xdr, 12);
7273 if (unlikely(!p))
7274 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007275 entry->prev_cookie = entry->cookie;
7276 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007277 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007278
Trond Myklebust9af8c222010-10-24 11:52:55 -04007279 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007280 if (unlikely(!p))
7281 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007282 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007283
7284 /*
7285 * In case the server doesn't return an inode number,
7286 * we fake one here. (We don't use inode number 0,
7287 * since glibc seems to choke on it...)
7288 */
7289 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007290 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007291
Trond Myklebust9af8c222010-10-24 11:52:55 -04007292 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007293 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007294
Trond Myklebust256e48b2012-06-21 11:18:13 -04007295 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007296 goto out_overflow;
7297
Chuck Lever573c4e12010-12-14 14:58:11 +00007298 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007299 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007300 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007301 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7302 entry->ino = entry->fattr->mounted_on_fileid;
7303 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007304 entry->ino = entry->fattr->fileid;
7305
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007306 entry->d_type = DT_UNKNOWN;
7307 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7308 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7309
Chuck Lever573c4e12010-12-14 14:58:11 +00007310 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007311
7312out_overflow:
7313 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007314 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007315}
7316
7317/*
7318 * We need to translate between nfs status return values and
7319 * the local errno values which may not be the same.
7320 */
7321static struct {
7322 int stat;
7323 int errno;
7324} nfs_errtbl[] = {
7325 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007326 { NFS4ERR_PERM, -EPERM },
7327 { NFS4ERR_NOENT, -ENOENT },
7328 { NFS4ERR_IO, -errno_NFSERR_IO},
7329 { NFS4ERR_NXIO, -ENXIO },
7330 { NFS4ERR_ACCESS, -EACCES },
7331 { NFS4ERR_EXIST, -EEXIST },
7332 { NFS4ERR_XDEV, -EXDEV },
7333 { NFS4ERR_NOTDIR, -ENOTDIR },
7334 { NFS4ERR_ISDIR, -EISDIR },
7335 { NFS4ERR_INVAL, -EINVAL },
7336 { NFS4ERR_FBIG, -EFBIG },
7337 { NFS4ERR_NOSPC, -ENOSPC },
7338 { NFS4ERR_ROFS, -EROFS },
7339 { NFS4ERR_MLINK, -EMLINK },
7340 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7341 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7342 { NFS4ERR_DQUOT, -EDQUOT },
7343 { NFS4ERR_STALE, -ESTALE },
7344 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007345 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7346 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7347 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007348 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007349 { NFS4ERR_BADTYPE, -EBADTYPE },
7350 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007351 { NFS4ERR_SYMLINK, -ELOOP },
7352 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7353 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007354 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007355};
7356
7357/*
7358 * Convert an NFS error code to a local one.
7359 * This one is used jointly by NFSv2 and NFSv3.
7360 */
7361static int
David Howells0a8ea432006-08-22 20:06:08 -04007362nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007363{
7364 int i;
7365 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7366 if (nfs_errtbl[i].stat == stat)
7367 return nfs_errtbl[i].errno;
7368 }
7369 if (stat <= 10000 || stat > 10100) {
7370 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007371 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007372 }
7373 /* If we cannot translate the error, the recovery routines should
7374 * handle it.
7375 * Note: remaining NFSv4 error codes have values > 10000, so should
7376 * not conflict with native Linux error codes.
7377 */
Benny Halevy856dff32008-03-31 17:39:06 +03007378 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007379}
7380
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007381#ifdef CONFIG_NFS_V4_2
7382#include "nfs42xdr.c"
7383#endif /* CONFIG_NFS_V4_2 */
7384
Linus Torvalds1da177e2005-04-16 15:20:36 -07007385#define PROC(proc, argtype, restype) \
7386[NFSPROC4_CLNT_##proc] = { \
7387 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007388 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007389 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007390 .p_arglen = NFS4_##argtype##_sz, \
7391 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007392 .p_statidx = NFSPROC4_CLNT_##proc, \
7393 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007394}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007395
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007396#define STUB(proc) \
7397[NFSPROC4_CLNT_##proc] = { \
7398 .p_name = #proc, \
7399}
7400
Linus Torvalds1da177e2005-04-16 15:20:36 -07007401struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007402 PROC(READ, enc_read, dec_read),
7403 PROC(WRITE, enc_write, dec_write),
7404 PROC(COMMIT, enc_commit, dec_commit),
7405 PROC(OPEN, enc_open, dec_open),
7406 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7407 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7408 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7409 PROC(CLOSE, enc_close, dec_close),
7410 PROC(SETATTR, enc_setattr, dec_setattr),
7411 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7412 PROC(RENEW, enc_renew, dec_renew),
7413 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7414 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7415 PROC(LOCK, enc_lock, dec_lock),
7416 PROC(LOCKT, enc_lockt, dec_lockt),
7417 PROC(LOCKU, enc_locku, dec_locku),
7418 PROC(ACCESS, enc_access, dec_access),
7419 PROC(GETATTR, enc_getattr, dec_getattr),
7420 PROC(LOOKUP, enc_lookup, dec_lookup),
7421 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7422 PROC(REMOVE, enc_remove, dec_remove),
7423 PROC(RENAME, enc_rename, dec_rename),
7424 PROC(LINK, enc_link, dec_link),
7425 PROC(SYMLINK, enc_symlink, dec_symlink),
7426 PROC(CREATE, enc_create, dec_create),
7427 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7428 PROC(STATFS, enc_statfs, dec_statfs),
7429 PROC(READLINK, enc_readlink, dec_readlink),
7430 PROC(READDIR, enc_readdir, dec_readdir),
7431 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7432 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7433 PROC(GETACL, enc_getacl, dec_getacl),
7434 PROC(SETACL, enc_setacl, dec_setacl),
7435 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7436 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007437 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007438 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007439#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007440 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7441 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7442 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7443 PROC(SEQUENCE, enc_sequence, dec_sequence),
7444 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7445 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7446 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7447 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007448 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007449 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007450 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007451 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007452 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007453 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007454 PROC(BIND_CONN_TO_SESSION,
7455 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007456 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007457#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007458#ifdef CONFIG_NFS_V4_2
7459 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007460 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007461 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007462 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007463#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007464};
7465
Trond Myklebusta613fa12012-01-20 13:53:56 -05007466const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007467 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007468 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007469 .procs = nfs4_procedures
7470};
7471
7472/*
7473 * Local variables:
7474 * c-basic-offset: 8
7475 * End:
7476 */