blob: c42459e45f622c8b13a1dcf7c77d00bdf99d2da6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
Chuck Leverf0920752012-05-21 22:45:41 -040055
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Anna Schumaker40c64c22015-04-15 13:00:05 -040058#include "nfs4idmap.h"
Trond Myklebust76e697b2012-11-26 14:20:49 -050059#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040060#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040061#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#define NFSDBG_FACILITY NFSDBG_XDR
64
65/* Mapping from NFS error code to "errno" error code. */
66#define errno_NFSERR_IO EIO
67
David Howells0a8ea432006-08-22 20:06:08 -040068static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
71#ifdef DEBUG
72#define NFS4_MAXTAGLEN 20
73#else
74#define NFS4_MAXTAGLEN 0
75#endif
76
Andy Adamson6c0195a2008-12-23 16:06:15 -050077/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040078 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040080#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050081#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85#define op_encode_hdr_maxsz (1)
86#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040087#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
92 (NFS4_FHSIZE >> 2))
93#define decode_putfh_maxsz (op_decode_hdr_maxsz)
94#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96#define encode_getfh_maxsz (op_encode_hdr_maxsz)
97#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040099#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000100#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400103#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400105#ifdef CONFIG_NFS_V4_SECURITY_LABEL
106/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
David Quigleyaa9c2662013-05-22 12:50:44 -0400108#else
109#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400110#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400111/* We support only one layout type per file system */
112#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000113/* This is based on getfattr, which uses the most attributes: */
114#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400115 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400116 nfs4_group_maxsz + nfs4_label_maxsz + \
117 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000118#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
119 nfs4_fattr_value_maxsz)
120#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400121#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
122 1 + 2 + 1 + \
123 nfs4_owner_maxsz + \
124 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400125 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400126 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define encode_savefh_maxsz (op_encode_hdr_maxsz)
128#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400129#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
130#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200131#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400132/* The 5 accounts for the PNFS attributes, and assumes that at most three
133 * layout types will be returned.
134 */
135#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
136 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
138#define decode_renew_maxsz (op_decode_hdr_maxsz)
139#define encode_setclientid_maxsz \
140 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500141 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400142 /* client name */ \
143 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500144 1 /* sc_prog */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500145 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
146 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500147 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define decode_setclientid_maxsz \
149 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500150 2 /* clientid */ + \
151 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
152 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
153 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#define encode_setclientid_confirm_maxsz \
155 (op_encode_hdr_maxsz + \
156 3 + (NFS4_VERIFIER_SIZE >> 2))
157#define decode_setclientid_confirm_maxsz \
158 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400159#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
160#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400161#define encode_share_access_maxsz \
162 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500163#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400164#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
165#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
166#define encode_open_maxsz (op_encode_hdr_maxsz + \
167 2 + encode_share_access_maxsz + 2 + \
168 open_owner_id_maxsz + \
169 encode_opentype_maxsz + \
170 encode_claim_null_maxsz)
171#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400172#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400173 decode_ace_maxsz)
174#define decode_change_info_maxsz (5)
175#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400176 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400177 decode_change_info_maxsz + 1 + \
178 nfs4_fattr_bitmap_maxsz + \
179 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400180#define encode_open_confirm_maxsz \
181 (op_encode_hdr_maxsz + \
182 encode_stateid_maxsz + 1)
183#define decode_open_confirm_maxsz \
184 (op_decode_hdr_maxsz + \
185 decode_stateid_maxsz)
186#define encode_open_downgrade_maxsz \
187 (op_encode_hdr_maxsz + \
188 encode_stateid_maxsz + 1 + \
189 encode_share_access_maxsz)
190#define decode_open_downgrade_maxsz \
191 (op_decode_hdr_maxsz + \
192 decode_stateid_maxsz)
193#define encode_close_maxsz (op_encode_hdr_maxsz + \
194 1 + encode_stateid_maxsz)
195#define decode_close_maxsz (op_decode_hdr_maxsz + \
196 decode_stateid_maxsz)
197#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
198 encode_stateid_maxsz + \
199 encode_attrs_maxsz)
200#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
201 nfs4_fattr_bitmap_maxsz)
202#define encode_read_maxsz (op_encode_hdr_maxsz + \
203 encode_stateid_maxsz + 3)
204#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
205#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400206 2 + encode_verifier_maxsz + 5 + \
207 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400208#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400209 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400210#define encode_readlink_maxsz (op_encode_hdr_maxsz)
211#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
212#define encode_write_maxsz (op_encode_hdr_maxsz + \
213 encode_stateid_maxsz + 4)
214#define decode_write_maxsz (op_decode_hdr_maxsz + \
215 2 + decode_verifier_maxsz)
216#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
217#define decode_commit_maxsz (op_decode_hdr_maxsz + \
218 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219#define encode_remove_maxsz (op_encode_hdr_maxsz + \
220 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400221#define decode_remove_maxsz (op_decode_hdr_maxsz + \
222 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#define encode_rename_maxsz (op_encode_hdr_maxsz + \
224 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400225#define decode_rename_maxsz (op_decode_hdr_maxsz + \
226 decode_change_info_maxsz + \
227 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228#define encode_link_maxsz (op_encode_hdr_maxsz + \
229 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400230#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400231#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400232#define encode_lock_maxsz (op_encode_hdr_maxsz + \
233 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400234 1 + encode_stateid_maxsz + 1 + \
235 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400236#define decode_lock_denied_maxsz \
237 (8 + decode_lockowner_maxsz)
238#define decode_lock_maxsz (op_decode_hdr_maxsz + \
239 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400240#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
241 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400242#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
243 decode_lock_denied_maxsz)
244#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
245 encode_stateid_maxsz + \
246 4)
247#define decode_locku_maxsz (op_decode_hdr_maxsz + \
248 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400249#define encode_release_lockowner_maxsz \
250 (op_encode_hdr_maxsz + \
251 encode_lockowner_maxsz)
252#define decode_release_lockowner_maxsz \
253 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400254#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
255#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
257 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400258 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000259 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
261#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400262 1 + 2 + nfs4_name_maxsz + \
263 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400264#define decode_create_maxsz (op_decode_hdr_maxsz + \
265 decode_change_info_maxsz + \
266 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400267#define encode_statfs_maxsz (encode_getattr_maxsz)
268#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
270#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400271#define encode_getacl_maxsz (encode_getattr_maxsz)
272#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
273 nfs4_fattr_bitmap_maxsz + 1)
274#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
275 encode_stateid_maxsz + 3)
276#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400277#define encode_fs_locations_maxsz \
278 (encode_getattr_maxsz)
279#define decode_fs_locations_maxsz \
280 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000281#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400282#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400283
284#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400285#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500286#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
287 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400288
Benny Halevy99fe60d2009-04-01 09:22:29 -0400289#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
290 encode_verifier_maxsz + \
291 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400292 /* eia_clientowner */ \
293 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400294 1 /* flags */ + \
295 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400296 /* max is SP4_MACH_CRED (for now) */ + \
297 1 + NFS4_OP_MAP_NUM_WORDS + \
298 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500299 1 /* implementation id array of size 1 */ + \
300 1 /* nii_domain */ + \
301 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
302 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500303 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500304 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400305#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
306 2 /* eir_clientid */ + \
307 1 /* eir_sequenceid */ + \
308 1 /* eir_flags */ + \
309 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400310 /* max is SP4_MACH_CRED (for now) */ + \
311 1 + NFS4_OP_MAP_NUM_WORDS + \
312 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400313 2 /* eir_server_owner.so_minor_id */ + \
314 /* eir_server_owner.so_major_id<> */ \
315 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
316 /* eir_server_scope<> */ \
317 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
318 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500319 1 /* nii_domain */ + \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
321 1 /* nii_name */ + \
322 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
323 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400324#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
325#define decode_channel_attrs_maxsz (6 + \
326 1 /* ca_rdma_ird.len */ + \
327 1 /* ca_rdma_ird */)
328#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
329 2 /* csa_clientid */ + \
330 1 /* csa_sequence */ + \
331 1 /* csa_flags */ + \
332 encode_channel_attrs_maxsz + \
333 encode_channel_attrs_maxsz + \
334 1 /* csa_cb_program */ + \
335 1 /* csa_sec_parms.len (1) */ + \
336 1 /* cb_secflavor (AUTH_SYS) */ + \
337 1 /* stamp */ + \
338 1 /* machinename.len */ + \
339 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
340 1 /* uid */ + \
341 1 /* gid */ + \
342 1 /* gids.len (0) */)
343#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
344 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
345 1 /* csr_sequence */ + \
346 1 /* csr_flags */ + \
347 decode_channel_attrs_maxsz + \
348 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400349#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
350 /* bctsa_sessid */ \
351 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
352 1 /* bctsa_dir */ + \
353 1 /* bctsa_use_conn_in_rdma_mode */)
354#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
355 /* bctsr_sessid */ \
356 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
357 1 /* bctsr_dir */ + \
358 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400359#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
360#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400361#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
362#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400363#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
364 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
365#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
366 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500367#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
368#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700369#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
370 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
371 1 /* layout type */ + \
372 1 /* maxcount */ + \
373 1 /* bitmap size */ + \
374 1 /* notification bitmap length */ + \
375 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400376#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
377 1 /* layout type */ + \
378 1 /* opaque devaddr4 length */ + \
379 /* devaddr4 payload is read into page */ \
380 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700381 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400382#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
383 encode_stateid_maxsz)
384#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
385 decode_stateid_maxsz + \
386 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000387#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
388 2 /* offset */ + \
389 2 /* length */ + \
390 1 /* reclaim */ + \
391 encode_stateid_maxsz + \
392 1 /* new offset (true) */ + \
393 2 /* last byte written */ + \
394 1 /* nt_timechanged (false) */ + \
395 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500396 1 /* layoutupdate4 opaqueue len */)
397 /* the actual content of layoutupdate4 should
398 be allocated by drivers and spliced in
399 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000400#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300401#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
402 encode_stateid_maxsz + \
403 1 /* FIXME: opaque lrf_body always empty at the moment */)
404#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
405 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400406#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
407#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400408#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
409 XDR_QUADLEN(NFS4_STATEID_SIZE))
410#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400411#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
412 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400413#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400414#else /* CONFIG_NFS_V4_1 */
415#define encode_sequence_maxsz 0
416#define decode_sequence_maxsz 0
417#endif /* CONFIG_NFS_V4_1 */
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
420#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
421#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400432 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400444 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400448 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400449 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400453 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400454 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400458 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400462 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400466 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400467 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400468 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400469 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400474 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400475 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400477#define NFS4_enc_open_confirm_sz \
478 (compound_encode_hdr_maxsz + \
479 encode_putfh_maxsz + \
480 encode_open_confirm_maxsz)
481#define NFS4_dec_open_confirm_sz \
482 (compound_decode_hdr_maxsz + \
483 decode_putfh_maxsz + \
484 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400486 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400488 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400489 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400490 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400495 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400496 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497#define NFS4_enc_open_downgrade_sz \
498 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400499 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400500 encode_putfh_maxsz + \
501 encode_open_downgrade_maxsz + \
502 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#define NFS4_dec_open_downgrade_sz \
504 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400505 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400506 decode_putfh_maxsz + \
507 decode_open_downgrade_maxsz + \
508 decode_getattr_maxsz)
509#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400510 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400511 encode_putfh_maxsz + \
512 encode_close_maxsz + \
513 encode_getattr_maxsz)
514#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400515 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400516 decode_putfh_maxsz + \
517 decode_close_maxsz + \
518 decode_getattr_maxsz)
519#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400521 encode_putfh_maxsz + \
522 encode_setattr_maxsz + \
523 encode_getattr_maxsz)
524#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400525 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400526 decode_putfh_maxsz + \
527 decode_setattr_maxsz + \
528 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 encode_putfh_maxsz + \
532 encode_fsinfo_maxsz)
533#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 decode_putfh_maxsz + \
536 decode_fsinfo_maxsz)
537#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
538 encode_renew_maxsz)
539#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
540 decode_renew_maxsz)
541#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
542 encode_setclientid_maxsz)
543#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
544 decode_setclientid_maxsz)
545#define NFS4_enc_setclientid_confirm_sz \
546 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400547 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#define NFS4_dec_setclientid_confirm_sz \
549 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400550 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400552 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400554 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400558 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400562 encode_lockt_maxsz)
563#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400565 decode_putfh_maxsz + \
566 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400570 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400574 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400575#define NFS4_enc_release_lockowner_sz \
576 (compound_encode_hdr_maxsz + \
577 encode_lockowner_maxsz)
578#define NFS4_dec_release_lockowner_sz \
579 (compound_decode_hdr_maxsz + \
580 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400584 encode_access_maxsz + \
585 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400587 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400589 decode_access_maxsz + \
590 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400594 encode_getattr_maxsz + \
595 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400597 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400599 decode_getattr_maxsz + \
600 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400602 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 encode_putfh_maxsz + \
604 encode_lookup_maxsz + \
605 encode_getattr_maxsz + \
606 encode_getfh_maxsz)
607#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400608 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400610 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 decode_getattr_maxsz + \
612 decode_getfh_maxsz)
613#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400614 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 encode_putrootfh_maxsz + \
616 encode_getattr_maxsz + \
617 encode_getfh_maxsz)
618#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400619 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 decode_putrootfh_maxsz + \
621 decode_getattr_maxsz + \
622 decode_getfh_maxsz)
623#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400624 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400626 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400628 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400630 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400632 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 encode_putfh_maxsz + \
634 encode_savefh_maxsz + \
635 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400636 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 decode_putfh_maxsz + \
640 decode_savefh_maxsz + \
641 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400642 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400644 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 encode_putfh_maxsz + \
646 encode_savefh_maxsz + \
647 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400648 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400649 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400650 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400652 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 decode_putfh_maxsz + \
654 decode_savefh_maxsz + \
655 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400656 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400657 decode_restorefh_maxsz + \
658 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 encode_putfh_maxsz + \
662 encode_symlink_maxsz + \
663 encode_getattr_maxsz + \
664 encode_getfh_maxsz)
665#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 decode_putfh_maxsz + \
668 decode_symlink_maxsz + \
669 decode_getattr_maxsz + \
670 decode_getfh_maxsz)
671#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
674 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400675 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400676 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400678 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 decode_putfh_maxsz + \
680 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400681 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400682 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 encode_putfh_maxsz + \
686 encode_getattr_maxsz)
687#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 decode_putfh_maxsz + \
690 decode_getattr_maxsz)
691#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400694 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400698 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400700 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800701 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 encode_getattr_maxsz)
703#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400704 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800705 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 decode_getattr_maxsz)
707#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400708 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100710 encode_delegreturn_maxsz + \
711 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100714 decode_delegreturn_maxsz + \
715 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000716#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000718 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000720#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400721 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000722 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400723 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000724#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400725 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000726 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400727 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000728#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400729 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000730 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400731 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400732#define NFS4_enc_fs_locations_sz \
733 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400734 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400735 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400736 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400737 encode_fs_locations_maxsz + \
738 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400739#define NFS4_dec_fs_locations_sz \
740 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400741 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400742 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400743 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400744 decode_fs_locations_maxsz + \
745 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000746#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
747 encode_sequence_maxsz + \
748 encode_putfh_maxsz + \
749 encode_secinfo_maxsz)
750#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
751 decode_sequence_maxsz + \
752 decode_putfh_maxsz + \
753 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400754#define NFS4_enc_fsid_present_sz \
755 (compound_encode_hdr_maxsz + \
756 encode_sequence_maxsz + \
757 encode_putfh_maxsz + \
758 encode_getfh_maxsz + \
759 encode_renew_maxsz)
760#define NFS4_dec_fsid_present_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz + \
763 decode_putfh_maxsz + \
764 decode_getfh_maxsz + \
765 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400766#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400767#define NFS4_enc_bind_conn_to_session_sz \
768 (compound_encode_hdr_maxsz + \
769 encode_bind_conn_to_session_maxsz)
770#define NFS4_dec_bind_conn_to_session_sz \
771 (compound_decode_hdr_maxsz + \
772 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400773#define NFS4_enc_exchange_id_sz \
774 (compound_encode_hdr_maxsz + \
775 encode_exchange_id_maxsz)
776#define NFS4_dec_exchange_id_sz \
777 (compound_decode_hdr_maxsz + \
778 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400779#define NFS4_enc_create_session_sz \
780 (compound_encode_hdr_maxsz + \
781 encode_create_session_maxsz)
782#define NFS4_dec_create_session_sz \
783 (compound_decode_hdr_maxsz + \
784 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400785#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
786 encode_destroy_session_maxsz)
787#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
788 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400789#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
790 encode_destroy_clientid_maxsz)
791#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
792 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400793#define NFS4_enc_sequence_sz \
794 (compound_decode_hdr_maxsz + \
795 encode_sequence_maxsz)
796#define NFS4_dec_sequence_sz \
797 (compound_decode_hdr_maxsz + \
798 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400799#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
800 encode_sequence_maxsz + \
801 encode_putrootfh_maxsz + \
802 encode_fsinfo_maxsz)
803#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
804 decode_sequence_maxsz + \
805 decode_putrootfh_maxsz + \
806 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500807#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
808 encode_sequence_maxsz + \
809 encode_reclaim_complete_maxsz)
810#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
811 decode_sequence_maxsz + \
812 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400813#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
814 encode_sequence_maxsz +\
815 encode_getdeviceinfo_maxsz)
816#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
817 decode_sequence_maxsz + \
818 decode_getdeviceinfo_maxsz)
819#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz + \
821 encode_putfh_maxsz + \
822 encode_layoutget_maxsz)
823#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
824 decode_sequence_maxsz + \
825 decode_putfh_maxsz + \
826 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000827#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
828 encode_sequence_maxsz +\
829 encode_putfh_maxsz + \
830 encode_layoutcommit_maxsz + \
831 encode_getattr_maxsz)
832#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
833 decode_sequence_maxsz + \
834 decode_putfh_maxsz + \
835 decode_layoutcommit_maxsz + \
836 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300837#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
838 encode_sequence_maxsz + \
839 encode_putfh_maxsz + \
840 encode_layoutreturn_maxsz)
841#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
842 decode_sequence_maxsz + \
843 decode_putfh_maxsz + \
844 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400845#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
846 encode_sequence_maxsz + \
847 encode_putrootfh_maxsz +\
848 encode_secinfo_no_name_maxsz)
849#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
850 decode_sequence_maxsz + \
851 decode_putrootfh_maxsz + \
852 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400853#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
854 encode_sequence_maxsz + \
855 encode_test_stateid_maxsz)
856#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
857 decode_sequence_maxsz + \
858 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400859#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
860 encode_sequence_maxsz + \
861 encode_free_stateid_maxsz)
862#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
863 decode_sequence_maxsz + \
864 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500865
866const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
867 compound_encode_hdr_maxsz +
868 encode_sequence_maxsz +
869 encode_putfh_maxsz +
870 encode_getattr_maxsz) *
871 XDR_UNIT);
872
873const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
874 compound_decode_hdr_maxsz +
875 decode_sequence_maxsz +
876 decode_putfh_maxsz) *
877 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400878
879const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
880 compound_decode_hdr_maxsz +
881 decode_sequence_maxsz) *
882 XDR_UNIT);
883EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400884#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Trond Myklebustbca79472009-03-11 14:10:26 -0400886static const umode_t nfs_type2fmt[] = {
887 [NF4BAD] = 0,
888 [NF4REG] = S_IFREG,
889 [NF4DIR] = S_IFDIR,
890 [NF4BLK] = S_IFBLK,
891 [NF4CHR] = S_IFCHR,
892 [NF4LNK] = S_IFLNK,
893 [NF4SOCK] = S_IFSOCK,
894 [NF4FIFO] = S_IFIFO,
895 [NF4ATTRDIR] = 0,
896 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897};
898
899struct compound_hdr {
900 int32_t status;
901 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500902 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 uint32_t taglen;
904 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400905 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400906 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907};
908
Benny Halevy13c65ce2009-08-14 17:19:25 +0300909static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
910{
911 __be32 *p = xdr_reserve_space(xdr, nbytes);
912 BUG_ON(!p);
913 return p;
914}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Trond Myklebustcb17e552012-03-04 18:13:56 -0500916static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
917{
918 __be32 *p;
919
920 p = xdr_reserve_space(xdr, len);
921 xdr_encode_opaque_fixed(p, buf, len);
922}
923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
925{
Al Viro8687b632006-10-19 23:28:48 -0700926 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500928 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 xdr_encode_opaque(p, str, len);
930}
931
Trond Myklebust4ade9822012-03-04 18:13:57 -0500932static void encode_uint32(struct xdr_stream *xdr, u32 n)
933{
934 __be32 *p;
935
936 p = reserve_space(xdr, 4);
937 *p = cpu_to_be32(n);
938}
939
Trond Myklebustff2eb682012-03-05 11:40:12 -0500940static void encode_uint64(struct xdr_stream *xdr, u64 n)
941{
942 __be32 *p;
943
944 p = reserve_space(xdr, 8);
945 xdr_encode_hyper(p, n);
946}
947
Trond Myklebust4ade9822012-03-04 18:13:57 -0500948static void encode_nfs4_seqid(struct xdr_stream *xdr,
949 const struct nfs_seqid *seqid)
950{
Trond Myklebusta6796412015-01-23 19:04:44 -0500951 if (seqid != NULL)
952 encode_uint32(xdr, seqid->sequence->counter);
953 else
954 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500955}
956
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400957static void encode_compound_hdr(struct xdr_stream *xdr,
958 struct rpc_rqst *req,
959 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
Al Viro8687b632006-10-19 23:28:48 -0700961 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400962 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400963
964 /* initialize running count of expected bytes in reply.
965 * NOTE: the replied tag SHOULD be the same is the one sent,
966 * but this is not required as a MUST for the server to do so. */
967 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Trond Myklebust7fc38842012-10-15 11:51:21 -0400969 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500970 encode_string(xdr, hdr->taglen, hdr->tag);
971 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300972 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500973 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300974 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500975}
976
Trond Myklebustab19b482012-03-04 18:13:57 -0500977static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
978 uint32_t replen,
979 struct compound_hdr *hdr)
980{
981 encode_uint32(xdr, op);
982 hdr->nops++;
983 hdr->replen += replen;
984}
985
Andy Adamsond0179312008-12-23 16:06:17 -0500986static void encode_nops(struct compound_hdr *hdr)
987{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400988 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500989 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990}
991
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500992static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
993{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500994 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500995}
996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
998{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500999 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000}
1001
David Quigleyaa9c2662013-05-22 12:50:44 -04001002static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1003 const struct nfs4_label *label,
1004 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005{
1006 char owner_name[IDMAP_NAMESZ];
1007 char owner_group[IDMAP_NAMESZ];
1008 int owner_namelen = 0;
1009 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001010 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001011 unsigned i;
1012 uint32_t len = 0;
1013 uint32_t bmval_len;
1014 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 /*
1017 * We reserve enough space to write the entire attribute buffer at once.
1018 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001019 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1020 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001021 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001023 if (iap->ia_valid & ATTR_SIZE) {
1024 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001026 }
1027 if (iap->ia_valid & ATTR_MODE) {
1028 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001032 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001034 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001035 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 /* XXX */
1037 strcpy(owner_name, "nobody");
1038 owner_namelen = sizeof("nobody") - 1;
1039 /* goto out; */
1040 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001041 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1043 }
1044 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001045 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001047 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001048 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 strcpy(owner_group, "nobody");
1050 owner_grouplen = sizeof("nobody") - 1;
1051 /* goto out; */
1052 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001053 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1055 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001057 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1058 len += 16;
1059 } else if (iap->ia_valid & ATTR_ATIME) {
1060 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1061 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
1063 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001064 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1065 len += 16;
1066 } else if (iap->ia_valid & ATTR_MTIME) {
1067 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1068 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001070 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001071 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1072 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1073 }
1074
1075 if (bmval[2] != 0)
1076 bmval_len = 3;
1077 else if (bmval[1] != 0)
1078 bmval_len = 2;
1079 else
1080 bmval_len = 1;
1081
1082 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1083
1084 *p++ = cpu_to_be32(bmval_len);
1085 for (i = 0; i < bmval_len; i++)
1086 *p++ = cpu_to_be32(bmval[i]);
1087 *p++ = cpu_to_be32(len);
1088
1089 if (bmval[0] & FATTR4_WORD0_SIZE)
1090 p = xdr_encode_hyper(p, iap->ia_size);
1091 if (bmval[1] & FATTR4_WORD1_MODE)
1092 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1093 if (bmval[1] & FATTR4_WORD1_OWNER)
1094 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1095 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1096 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1097 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1098 if (iap->ia_valid & ATTR_ATIME_SET) {
1099 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1100 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1101 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1102 } else
1103 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1104 }
1105 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1106 if (iap->ia_valid & ATTR_MTIME_SET) {
1107 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1108 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1109 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1110 } else
1111 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1112 }
1113 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001114 *p++ = cpu_to_be32(label->lfs);
1115 *p++ = cpu_to_be32(label->pi);
1116 *p++ = cpu_to_be32(label->len);
1117 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1118 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121}
1122
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001123static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001125 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1126 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001129static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
Trond Myklebustab19b482012-03-04 18:13:57 -05001131 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001132 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001133 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134}
1135
Fred Isaman0b7c0152012-04-20 14:47:39 -04001136static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137{
Al Viro8687b632006-10-19 23:28:48 -07001138 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001139
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001140 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1141 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001142 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001143 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001146static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147{
Al Viro8687b632006-10-19 23:28:48 -07001148 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001149
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001150 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1151 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
1153 switch (create->ftype) {
1154 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001155 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001156 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001157 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1158 create->u.symlink.len);
1159 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 break;
1161
1162 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001163 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001164 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001165 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 break;
1167
1168 default:
1169 break;
1170 }
1171
Benny Halevy811652b2009-08-14 17:19:34 +03001172 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001173 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174}
1175
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001176static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177{
Andy Adamson05d564f2008-12-23 16:06:15 -05001178 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001180 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1181 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001182 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001183 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184}
1185
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001186static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187{
Andy Adamson05d564f2008-12-23 16:06:15 -05001188 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001190 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1191 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001192 *p++ = cpu_to_be32(2);
1193 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001194 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195}
1196
Fred Isamandae100c2011-07-30 20:52:37 -04001197static void
1198encode_getattr_three(struct xdr_stream *xdr,
1199 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1200 struct compound_hdr *hdr)
1201{
1202 __be32 *p;
1203
Trond Myklebustab19b482012-03-04 18:13:57 -05001204 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001205 if (bm2) {
1206 p = reserve_space(xdr, 16);
1207 *p++ = cpu_to_be32(3);
1208 *p++ = cpu_to_be32(bm0);
1209 *p++ = cpu_to_be32(bm1);
1210 *p = cpu_to_be32(bm2);
1211 } else if (bm1) {
1212 p = reserve_space(xdr, 12);
1213 *p++ = cpu_to_be32(2);
1214 *p++ = cpu_to_be32(bm0);
1215 *p = cpu_to_be32(bm1);
1216 } else {
1217 p = reserve_space(xdr, 8);
1218 *p++ = cpu_to_be32(1);
1219 *p = cpu_to_be32(bm0);
1220 }
Fred Isamandae100c2011-07-30 20:52:37 -04001221}
1222
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001223static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
David Quigleya09df2c2013-05-22 12:50:41 -04001225 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1226 bitmask[1] & nfs4_fattr_bitmap[1],
1227 bitmask[2] & nfs4_fattr_bitmap[2],
1228 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229}
1230
Andy Adamson88034c32012-05-23 05:02:34 -04001231static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001232 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001233 struct compound_hdr *hdr)
1234{
1235 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001236 bitmask[0] & open_bitmap[0],
1237 bitmask[1] & open_bitmap[1],
1238 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001239 hdr);
1240}
1241
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001242static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
Fred Isamandae100c2011-07-30 20:52:37 -04001244 encode_getattr_three(xdr,
1245 bitmask[0] & nfs4_fsinfo_bitmap[0],
1246 bitmask[1] & nfs4_fsinfo_bitmap[1],
1247 bitmask[2] & nfs4_fsinfo_bitmap[2],
1248 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249}
1250
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001251static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001252{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001253 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1254 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001255}
1256
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001257static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
Trond Myklebustab19b482012-03-04 18:13:57 -05001259 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260}
1261
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001262static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
Trond Myklebustab19b482012-03-04 18:13:57 -05001264 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001265 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266}
1267
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001268static inline int nfs4_lock_type(struct file_lock *fl, int block)
1269{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001270 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001271 return block ? NFS4_READW_LT : NFS4_READ_LT;
1272 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1273}
1274
1275static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1276{
1277 if (fl->fl_end == OFFSET_MAX)
1278 return ~(uint64_t)0;
1279 return fl->fl_end - fl->fl_start + 1;
1280}
1281
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001282static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1283{
1284 __be32 *p;
1285
Trond Myklebustd035c362010-12-21 10:45:27 -05001286 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001287 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001288 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001289 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001290 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001291 xdr_encode_hyper(p, lowner->id);
1292}
1293
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294/*
1295 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1296 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1297 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001298static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
Al Viro8687b632006-10-19 23:28:48 -07001300 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001302 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1303 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001304 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1305 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001306 p = xdr_encode_hyper(p, args->fl->fl_start);
1307 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001308 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001309 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001310 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001311 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001312 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001313 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 }
1315 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001316 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001317 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319}
1320
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001321static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322{
Al Viro8687b632006-10-19 23:28:48 -07001323 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001325 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1326 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001327 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001328 p = xdr_encode_hyper(p, args->fl->fl_start);
1329 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001330 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001333static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334{
Al Viro8687b632006-10-19 23:28:48 -07001335 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001337 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1338 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001339 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001340 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001341 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001342 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001343 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344}
1345
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001346static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1347{
Trond Myklebustab19b482012-03-04 18:13:57 -05001348 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001349 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001350}
1351
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001352static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353{
Trond Myklebustab19b482012-03-04 18:13:57 -05001354 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001355 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356}
1357
Trond Myklebust6ae37332015-01-30 14:21:14 -05001358static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359{
Al Viro8687b632006-10-19 23:28:48 -07001360 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Benny Halevy13c65ce2009-08-14 17:19:25 +03001362 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001363 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001364 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365}
1366
1367static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1368{
Al Viro8687b632006-10-19 23:28:48 -07001369 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 /*
1371 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1372 * owner 4 = 32
1373 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001374 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001375 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001376 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001377 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001378 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001379 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001380 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001381 *p++ = cpu_to_be32(arg->id.uniquifier);
1382 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383}
1384
1385static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1386{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001387 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001388 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Benny Halevy13c65ce2009-08-14 17:19:25 +03001390 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001391 switch(arg->createmode) {
1392 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001393 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001394 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001395 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001396 case NFS4_CREATE_GUARDED:
1397 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001398 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001399 break;
1400 case NFS4_CREATE_EXCLUSIVE:
1401 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1402 encode_nfs4_verifier(xdr, &arg->u.verifier);
1403 break;
1404 case NFS4_CREATE_EXCLUSIVE4_1:
1405 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1406 encode_nfs4_verifier(xdr, &arg->u.verifier);
1407 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001408 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 }
1410}
1411
1412static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1413{
Al Viro8687b632006-10-19 23:28:48 -07001414 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
Benny Halevy13c65ce2009-08-14 17:19:25 +03001416 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001418 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001419 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001420 break;
1421 default:
Benny Halevy34558512009-08-14 17:19:30 +03001422 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001423 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 }
1425}
1426
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001427static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428{
Al Viro8687b632006-10-19 23:28:48 -07001429 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Benny Halevy13c65ce2009-08-14 17:19:25 +03001431 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001433 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001434 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001435 break;
1436 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001437 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 break;
1439 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001440 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001441 break;
1442 default:
1443 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 }
1445}
1446
1447static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1448{
Al Viro8687b632006-10-19 23:28:48 -07001449 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Benny Halevy13c65ce2009-08-14 17:19:25 +03001451 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001452 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 encode_string(xdr, name->len, name->name);
1454}
1455
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001456static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457{
Al Viro8687b632006-10-19 23:28:48 -07001458 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Benny Halevy13c65ce2009-08-14 17:19:25 +03001460 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001461 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 encode_delegation_type(xdr, type);
1463}
1464
1465static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1466{
Al Viro8687b632006-10-19 23:28:48 -07001467 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001469 p = reserve_space(xdr, 4);
1470 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1471 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 encode_string(xdr, name->len, name->name);
1473}
1474
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001475static inline void encode_claim_fh(struct xdr_stream *xdr)
1476{
1477 __be32 *p;
1478
1479 p = reserve_space(xdr, 4);
1480 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1481}
1482
1483static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1484{
1485 __be32 *p;
1486
1487 p = reserve_space(xdr, 4);
1488 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1489 encode_nfs4_stateid(xdr, stateid);
1490}
1491
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001492static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493{
Trond Myklebustab19b482012-03-04 18:13:57 -05001494 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 encode_openhdr(xdr, arg);
1496 encode_opentype(xdr, arg);
1497 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001498 case NFS4_OPEN_CLAIM_NULL:
1499 encode_claim_null(xdr, arg->name);
1500 break;
1501 case NFS4_OPEN_CLAIM_PREVIOUS:
1502 encode_claim_previous(xdr, arg->u.delegation_type);
1503 break;
1504 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1505 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1506 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001507 case NFS4_OPEN_CLAIM_FH:
1508 encode_claim_fh(xdr);
1509 break;
1510 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1511 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1512 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001513 default:
1514 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516}
1517
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001518static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519{
Trond Myklebustab19b482012-03-04 18:13:57 -05001520 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001521 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001522 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523}
1524
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001525static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
Trond Myklebustab19b482012-03-04 18:13:57 -05001527 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001528 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001529 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001530 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531}
1532
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001533static void
Andy Adamsond0179312008-12-23 16:06:17 -05001534encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535{
Trond Myklebustab19b482012-03-04 18:13:57 -05001536 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001537 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538}
1539
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001540static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
Trond Myklebustab19b482012-03-04 18:13:57 -05001542 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001545static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1546 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547{
Al Viro8687b632006-10-19 23:28:48 -07001548 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Trond Myklebustab19b482012-03-04 18:13:57 -05001550 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001551 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Benny Halevy13c65ce2009-08-14 17:19:25 +03001553 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001554 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001555 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556}
1557
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001558static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559{
David Quigleyaa9c2662013-05-22 12:50:44 -04001560 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001561 FATTR4_WORD0_RDATTR_ERROR,
1562 FATTR4_WORD1_MOUNTED_ON_FILEID,
1563 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001564 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001565 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001566 uint32_t attrlen = 0;
1567 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001569 if (readdir->plus) {
1570 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001571 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001572 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1573 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1574 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1575 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001576 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001577 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001578 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001579 /* Use mounted_on_fileid only if the server supports it */
1580 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1581 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001582 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1583 attrs[i] &= readdir->bitmask[i];
1584 if (attrs[i] != 0)
1585 attrlen = i+1;
1586 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001587
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001588 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001589 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001590 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001591 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001592 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001593 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001594 *p++ = cpu_to_be32(attrlen);
1595 for (i = 0; i < attrlen; i++)
1596 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001597 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001598
1599 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001600 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001601 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001602 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001603 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001604 attrs[1] & readdir->bitmask[1],
1605 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606}
1607
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001608static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609{
Trond Myklebustab19b482012-03-04 18:13:57 -05001610 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611}
1612
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001613static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614{
Trond Myklebustab19b482012-03-04 18:13:57 -05001615 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001616 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617}
1618
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001619static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620{
Trond Myklebustab19b482012-03-04 18:13:57 -05001621 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001622 encode_string(xdr, oldname->len, oldname->name);
1623 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624}
1625
Chuck Leverbb4dae52012-03-01 17:01:48 -05001626static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1627 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001629 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001630 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001633static void
Andy Adamsond0179312008-12-23 16:06:17 -05001634encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001635{
Trond Myklebustab19b482012-03-04 18:13:57 -05001636 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001637}
1638
Chuck Lever9f06c712010-12-14 14:59:18 +00001639static void
Andy Adamsond0179312008-12-23 16:06:17 -05001640encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001641{
Al Viro8687b632006-10-19 23:28:48 -07001642 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001643
Trond Myklebustab19b482012-03-04 18:13:57 -05001644 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001645 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001646 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001647 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001648 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001649 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001650 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001651 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001652}
1653
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001654static void
Andy Adamsond0179312008-12-23 16:06:17 -05001655encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
Trond Myklebustab19b482012-03-04 18:13:57 -05001657 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
1659
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001660static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
Trond Myklebustab19b482012-03-04 18:13:57 -05001662 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001663 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001664 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
1666
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001667static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668{
Al Viro8687b632006-10-19 23:28:48 -07001669 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
Trond Myklebust70019512012-03-04 20:49:32 -05001671 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001672 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Jeff Layton3a6bb732015-06-09 19:43:57 -04001674 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1675 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001676 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001677 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1679 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001680 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001681 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682}
1683
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001684static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001686 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1687 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001688 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001689 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690}
1691
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001692static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1693 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
Al Viro8687b632006-10-19 23:28:48 -07001695 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
Trond Myklebustab19b482012-03-04 18:13:57 -05001697 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001698 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
Benny Halevy13c65ce2009-08-14 17:19:25 +03001700 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001701 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001702 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001703 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
1705 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706}
1707
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001708static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709{
Trond Myklebustab19b482012-03-04 18:13:57 -05001710 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001711 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001713
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001714static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1715{
Trond Myklebustab19b482012-03-04 18:13:57 -05001716 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001717 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001718}
1719
Benny Halevy99fe60d2009-04-01 09:22:29 -04001720#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001721/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001722static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08001723 struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001724 struct compound_hdr *hdr)
1725{
1726 __be32 *p;
1727
1728 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1729 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001730 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001731 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001732 *p++ = cpu_to_be32(args->dir);
1733 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001734}
1735
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001736static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1737{
1738 unsigned int i;
1739 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1740 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1741 encode_uint32(xdr, op_map->u.words[i]);
1742}
1743
Benny Halevy99fe60d2009-04-01 09:22:29 -04001744static void encode_exchange_id(struct xdr_stream *xdr,
1745 struct nfs41_exchange_id_args *args,
1746 struct compound_hdr *hdr)
1747{
1748 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001749 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001750 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001751
Trond Myklebust70019512012-03-04 20:49:32 -05001752 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001753 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001754
Jeff Layton3a6bb732015-06-09 19:43:57 -04001755 encode_string(xdr, strlen(args->client->cl_owner_id),
1756 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001757
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001758 encode_uint32(xdr, args->flags);
1759 encode_uint32(xdr, args->state_protect.how);
1760
1761 switch (args->state_protect.how) {
1762 case SP4_NONE:
1763 break;
1764 case SP4_MACH_CRED:
1765 encode_op_map(xdr, &args->state_protect.enforce);
1766 encode_op_map(xdr, &args->state_protect.allow);
1767 break;
1768 default:
1769 WARN_ON_ONCE(1);
1770 break;
1771 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001772
1773 if (send_implementation_id &&
1774 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1775 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001776 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001777 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1778 utsname()->sysname, utsname()->release,
1779 utsname()->version, utsname()->machine);
1780
1781 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001782 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001783
1784 encode_string(xdr,
1785 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1786 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1787 encode_string(xdr, len, impl_name);
1788 /* just send zeros for nii_date - the date is in nii_name */
1789 p = reserve_space(xdr, 12);
1790 p = xdr_encode_hyper(p, 0);
1791 *p = cpu_to_be32(0);
1792 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001793 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001794}
Andy Adamsonfc931582009-04-01 09:22:31 -04001795
1796static void encode_create_session(struct xdr_stream *xdr,
1797 struct nfs41_create_session_args *args,
1798 struct compound_hdr *hdr)
1799{
1800 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001801 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001802 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001803 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001804 u32 max_resp_sz_cached;
1805
1806 /*
1807 * Assumes OPEN is the biggest non-idempotent compound.
1808 * 2 is the verifier.
1809 */
1810 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1811 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001812
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001813 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001814 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001815 p = xdr_encode_hyper(p, args->clientid);
1816 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001817 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001818
Andy Adamsonfc931582009-04-01 09:22:31 -04001819 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001820 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001821 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1822 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001823 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001824 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1825 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1826 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001827
1828 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001829 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001830 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1831 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1832 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1833 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1834 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1835 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001836
Benny Halevye75bc1c2009-08-14 17:18:54 +03001837 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001838 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001839 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001840
1841 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001842 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001843 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001844 *p++ = cpu_to_be32(0); /* UID */
1845 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001846 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001847}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001848
1849static void encode_destroy_session(struct xdr_stream *xdr,
1850 struct nfs4_session *session,
1851 struct compound_hdr *hdr)
1852{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001853 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1854 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001855}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001856
Trond Myklebust66245532012-05-25 17:18:09 -04001857static void encode_destroy_clientid(struct xdr_stream *xdr,
1858 uint64_t clientid,
1859 struct compound_hdr *hdr)
1860{
1861 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1862 encode_uint64(xdr, clientid);
1863}
1864
Ricardo Labiaga180197532009-12-05 16:08:40 -05001865static void encode_reclaim_complete(struct xdr_stream *xdr,
1866 struct nfs41_reclaim_complete_args *args,
1867 struct compound_hdr *hdr)
1868{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001869 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1870 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001871}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001872#endif /* CONFIG_NFS_V4_1 */
1873
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001874static void encode_sequence(struct xdr_stream *xdr,
1875 const struct nfs4_sequence_args *args,
1876 struct compound_hdr *hdr)
1877{
1878#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001879 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001880 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001881 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001882 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001883
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001884 tp = slot->table;
1885 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001886 if (!session)
1887 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001888
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001889 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001890
1891 /*
1892 * Sessionid + seqid + slotid + max slotid + cache_this
1893 */
1894 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1895 "max_slotid=%d cache_this=%d\n",
1896 __func__,
1897 ((u32 *)session->sess_id.data)[0],
1898 ((u32 *)session->sess_id.data)[1],
1899 ((u32 *)session->sess_id.data)[2],
1900 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001901 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001902 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001903 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001904 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001905 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001906 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001907 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001908 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001909#endif /* CONFIG_NFS_V4_1 */
1910}
1911
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001912#ifdef CONFIG_NFS_V4_1
1913static void
1914encode_getdeviceinfo(struct xdr_stream *xdr,
1915 const struct nfs4_getdeviceinfo_args *args,
1916 struct compound_hdr *hdr)
1917{
1918 __be32 *p;
1919
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001920 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001921 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001922 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1923 NFS4_DEVICEID4_SIZE);
1924 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001925 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001926
1927 p = reserve_space(xdr, 4 + 4);
1928 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001929 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001930}
1931
1932static void
1933encode_layoutget(struct xdr_stream *xdr,
1934 const struct nfs4_layoutget_args *args,
1935 struct compound_hdr *hdr)
1936{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001937 __be32 *p;
1938
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001939 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1940 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001941 *p++ = cpu_to_be32(0); /* Signal layout available */
1942 *p++ = cpu_to_be32(args->type);
1943 *p++ = cpu_to_be32(args->range.iomode);
1944 p = xdr_encode_hyper(p, args->range.offset);
1945 p = xdr_encode_hyper(p, args->range.length);
1946 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001947 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001948 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001949
1950 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1951 __func__,
1952 args->type,
1953 args->range.iomode,
1954 (unsigned long)args->range.offset,
1955 (unsigned long)args->range.length,
1956 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001957}
Andy Adamson863a3c62011-03-23 13:27:54 +00001958
1959static int
1960encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001961 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001962 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001963 struct compound_hdr *hdr)
1964{
1965 __be32 *p;
1966
1967 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1968 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1969
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001970 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1971 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001972 /* Only whole file layouts */
1973 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001974 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001975 *p = cpu_to_be32(0); /* reclaim */
1976 encode_nfs4_stateid(xdr, &args->stateid);
1977 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001978 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1979 p = xdr_encode_hyper(p, args->lastbytewritten);
1980 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1981 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001982
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001983 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) {
Benny Halevyac7db722011-05-22 19:53:48 +03001984 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1985 NFS_I(inode)->layout, xdr, args);
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001986 } else {
1987 encode_uint32(xdr, args->layoutupdate_len);
1988 if (args->layoutupdate_pages) {
1989 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
1990 args->layoutupdate_len);
1991 }
1992 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001993
Andy Adamson863a3c62011-03-23 13:27:54 +00001994 return 0;
1995}
Benny Halevycbe82602011-05-22 19:52:37 +03001996
1997static void
1998encode_layoutreturn(struct xdr_stream *xdr,
1999 const struct nfs4_layoutreturn_args *args,
2000 struct compound_hdr *hdr)
2001{
2002 __be32 *p;
2003
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002004 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2005 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002006 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2007 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002008 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002009 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002010 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002011 p = xdr_encode_hyper(p, args->range.offset);
2012 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002013 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002014 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002015 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002016 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2017 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2018 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002019 } else
2020 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002021}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002022
2023static int
2024encode_secinfo_no_name(struct xdr_stream *xdr,
2025 const struct nfs41_secinfo_no_name_args *args,
2026 struct compound_hdr *hdr)
2027{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002028 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2029 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002030 return 0;
2031}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002032
2033static void encode_test_stateid(struct xdr_stream *xdr,
2034 struct nfs41_test_stateid_args *args,
2035 struct compound_hdr *hdr)
2036{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002037 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2038 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002039 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002040}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002041
2042static void encode_free_stateid(struct xdr_stream *xdr,
2043 struct nfs41_free_stateid_args *args,
2044 struct compound_hdr *hdr)
2045{
Trond Myklebustab19b482012-03-04 18:13:57 -05002046 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002047 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002048}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002049#endif /* CONFIG_NFS_V4_1 */
2050
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051/*
2052 * END OF "GENERIC" ENCODE ROUTINES.
2053 */
2054
Benny Halevy66cc0422009-04-01 09:22:10 -04002055static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2056{
2057#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002058 struct nfs4_session *session = args->sa_slot->table->session;
2059 if (session)
2060 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002061#endif /* CONFIG_NFS_V4_1 */
2062 return 0;
2063}
2064
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065/*
2066 * Encode an ACCESS request
2067 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002068static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2069 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002072 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Chuck Lever9f06c712010-12-14 14:59:18 +00002075 encode_compound_hdr(xdr, req, &hdr);
2076 encode_sequence(xdr, &args->seq_args, &hdr);
2077 encode_putfh(xdr, args->fh, &hdr);
2078 encode_access(xdr, args->access, &hdr);
2079 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002080 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081}
2082
2083/*
2084 * Encode LOOKUP request
2085 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002086static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2087 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002090 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
Chuck Lever9f06c712010-12-14 14:59:18 +00002093 encode_compound_hdr(xdr, req, &hdr);
2094 encode_sequence(xdr, &args->seq_args, &hdr);
2095 encode_putfh(xdr, args->dir_fh, &hdr);
2096 encode_lookup(xdr, args->name, &hdr);
2097 encode_getfh(xdr, &hdr);
2098 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002099 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100}
2101
2102/*
2103 * Encode LOOKUP_ROOT request
2104 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002105static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2106 struct xdr_stream *xdr,
2107 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002110 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
Chuck Lever9f06c712010-12-14 14:59:18 +00002113 encode_compound_hdr(xdr, req, &hdr);
2114 encode_sequence(xdr, &args->seq_args, &hdr);
2115 encode_putrootfh(xdr, &hdr);
2116 encode_getfh(xdr, &hdr);
2117 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002118 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119}
2120
2121/*
2122 * Encode REMOVE request
2123 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002124static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2125 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002128 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
Chuck Lever9f06c712010-12-14 14:59:18 +00002131 encode_compound_hdr(xdr, req, &hdr);
2132 encode_sequence(xdr, &args->seq_args, &hdr);
2133 encode_putfh(xdr, args->fh, &hdr);
2134 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002135 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136}
2137
2138/*
2139 * Encode RENAME request
2140 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002141static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2142 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002145 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
Chuck Lever9f06c712010-12-14 14:59:18 +00002148 encode_compound_hdr(xdr, req, &hdr);
2149 encode_sequence(xdr, &args->seq_args, &hdr);
2150 encode_putfh(xdr, args->old_dir, &hdr);
2151 encode_savefh(xdr, &hdr);
2152 encode_putfh(xdr, args->new_dir, &hdr);
2153 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002154 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155}
2156
2157/*
2158 * Encode LINK request
2159 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002160static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2161 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002164 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
Chuck Lever9f06c712010-12-14 14:59:18 +00002167 encode_compound_hdr(xdr, req, &hdr);
2168 encode_sequence(xdr, &args->seq_args, &hdr);
2169 encode_putfh(xdr, args->fh, &hdr);
2170 encode_savefh(xdr, &hdr);
2171 encode_putfh(xdr, args->dir_fh, &hdr);
2172 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002173 encode_restorefh(xdr, &hdr);
2174 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002175 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176}
2177
2178/*
2179 * Encode CREATE request
2180 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002181static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2182 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002185 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
Chuck Lever9f06c712010-12-14 14:59:18 +00002188 encode_compound_hdr(xdr, req, &hdr);
2189 encode_sequence(xdr, &args->seq_args, &hdr);
2190 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002191 encode_create(xdr, args, &hdr);
2192 encode_getfh(xdr, &hdr);
2193 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002194 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195}
2196
2197/*
2198 * Encode SYMLINK request
2199 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002200static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2201 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202{
Chuck Lever9f06c712010-12-14 14:59:18 +00002203 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204}
2205
2206/*
2207 * Encode GETATTR request
2208 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002209static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2210 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002213 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
Chuck Lever9f06c712010-12-14 14:59:18 +00002216 encode_compound_hdr(xdr, req, &hdr);
2217 encode_sequence(xdr, &args->seq_args, &hdr);
2218 encode_putfh(xdr, args->fh, &hdr);
2219 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002220 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221}
2222
2223/*
2224 * Encode a CLOSE request
2225 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002226static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2227 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228{
Andy Adamson05d564f2008-12-23 16:06:15 -05002229 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002230 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002231 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
Chuck Lever9f06c712010-12-14 14:59:18 +00002233 encode_compound_hdr(xdr, req, &hdr);
2234 encode_sequence(xdr, &args->seq_args, &hdr);
2235 encode_putfh(xdr, args->fh, &hdr);
2236 encode_close(xdr, args, &hdr);
2237 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002238 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239}
2240
2241/*
2242 * Encode an OPEN request
2243 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002244static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2245 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002248 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
Chuck Lever9f06c712010-12-14 14:59:18 +00002251 encode_compound_hdr(xdr, req, &hdr);
2252 encode_sequence(xdr, &args->seq_args, &hdr);
2253 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002254 encode_open(xdr, args, &hdr);
2255 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002256 if (args->access)
2257 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002258 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002259 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260}
2261
2262/*
2263 * Encode an OPEN_CONFIRM request
2264 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002265static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2266 struct xdr_stream *xdr,
2267 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002270 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
Chuck Lever9f06c712010-12-14 14:59:18 +00002273 encode_compound_hdr(xdr, req, &hdr);
2274 encode_putfh(xdr, args->fh, &hdr);
2275 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002276 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277}
2278
2279/*
2280 * Encode an OPEN request with no attributes.
2281 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002282static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2283 struct xdr_stream *xdr,
2284 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002287 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Chuck Lever9f06c712010-12-14 14:59:18 +00002290 encode_compound_hdr(xdr, req, &hdr);
2291 encode_sequence(xdr, &args->seq_args, &hdr);
2292 encode_putfh(xdr, args->fh, &hdr);
2293 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002294 if (args->access)
2295 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002296 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002297 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298}
2299
2300/*
2301 * Encode an OPEN_DOWNGRADE request
2302 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002303static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2304 struct xdr_stream *xdr,
2305 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002308 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Chuck Lever9f06c712010-12-14 14:59:18 +00002311 encode_compound_hdr(xdr, req, &hdr);
2312 encode_sequence(xdr, &args->seq_args, &hdr);
2313 encode_putfh(xdr, args->fh, &hdr);
2314 encode_open_downgrade(xdr, args, &hdr);
2315 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002316 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317}
2318
2319/*
2320 * Encode a LOCK request
2321 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002322static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2323 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002326 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
Chuck Lever9f06c712010-12-14 14:59:18 +00002329 encode_compound_hdr(xdr, req, &hdr);
2330 encode_sequence(xdr, &args->seq_args, &hdr);
2331 encode_putfh(xdr, args->fh, &hdr);
2332 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002333 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334}
2335
2336/*
2337 * Encode a LOCKT request
2338 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002339static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2340 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002343 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
Chuck Lever9f06c712010-12-14 14:59:18 +00002346 encode_compound_hdr(xdr, req, &hdr);
2347 encode_sequence(xdr, &args->seq_args, &hdr);
2348 encode_putfh(xdr, args->fh, &hdr);
2349 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002350 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351}
2352
2353/*
2354 * Encode a LOCKU request
2355 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002356static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2357 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002360 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Chuck Lever9f06c712010-12-14 14:59:18 +00002363 encode_compound_hdr(xdr, req, &hdr);
2364 encode_sequence(xdr, &args->seq_args, &hdr);
2365 encode_putfh(xdr, args->fh, &hdr);
2366 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002367 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368}
2369
Chuck Lever9f06c712010-12-14 14:59:18 +00002370static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2371 struct xdr_stream *xdr,
2372 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002373{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002374 struct compound_hdr hdr = {
2375 .minorversion = 0,
2376 };
2377
Chuck Lever9f06c712010-12-14 14:59:18 +00002378 encode_compound_hdr(xdr, req, &hdr);
2379 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002380 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002381}
2382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383/*
2384 * Encode a READLINK request
2385 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002386static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2387 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002390 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
Chuck Lever9f06c712010-12-14 14:59:18 +00002393 encode_compound_hdr(xdr, req, &hdr);
2394 encode_sequence(xdr, &args->seq_args, &hdr);
2395 encode_putfh(xdr, args->fh, &hdr);
2396 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002397
Benny Halevy28f56692009-04-01 09:22:09 -04002398 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002399 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002400 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401}
2402
2403/*
2404 * Encode a READDIR request
2405 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002406static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2407 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002410 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412
Chuck Lever9f06c712010-12-14 14:59:18 +00002413 encode_compound_hdr(xdr, req, &hdr);
2414 encode_sequence(xdr, &args->seq_args, &hdr);
2415 encode_putfh(xdr, args->fh, &hdr);
2416 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002417
Benny Halevy28f56692009-04-01 09:22:09 -04002418 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002419 args->pgbase, args->count);
2420 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002421 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002422 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002423 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424}
2425
2426/*
2427 * Encode a READ request
2428 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002429static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002430 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002433 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
Chuck Lever9f06c712010-12-14 14:59:18 +00002436 encode_compound_hdr(xdr, req, &hdr);
2437 encode_sequence(xdr, &args->seq_args, &hdr);
2438 encode_putfh(xdr, args->fh, &hdr);
2439 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
Benny Halevy28f56692009-04-01 09:22:09 -04002441 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002443 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002444 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445}
2446
2447/*
2448 * Encode an SETATTR request
2449 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002450static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2451 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452{
Andy Adamson05d564f2008-12-23 16:06:15 -05002453 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002454 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002455 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Chuck Lever9f06c712010-12-14 14:59:18 +00002457 encode_compound_hdr(xdr, req, &hdr);
2458 encode_sequence(xdr, &args->seq_args, &hdr);
2459 encode_putfh(xdr, args->fh, &hdr);
2460 encode_setattr(xdr, args, args->server, &hdr);
2461 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002462 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463}
2464
2465/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002466 * Encode a GETACL request
2467 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002468static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2469 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002470{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002471 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002472 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002473 };
Benny Halevy28f56692009-04-01 09:22:09 -04002474 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002475
Chuck Lever9f06c712010-12-14 14:59:18 +00002476 encode_compound_hdr(xdr, req, &hdr);
2477 encode_sequence(xdr, &args->seq_args, &hdr);
2478 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002479 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002480 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002481
Benny Halevy28f56692009-04-01 09:22:09 -04002482 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002483 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002484
Andy Adamsond0179312008-12-23 16:06:17 -05002485 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002486}
2487
2488/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 * Encode a WRITE request
2490 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002491static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002492 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
Chuck Lever9f06c712010-12-14 14:59:18 +00002498 encode_compound_hdr(xdr, req, &hdr);
2499 encode_sequence(xdr, &args->seq_args, &hdr);
2500 encode_putfh(xdr, args->fh, &hdr);
2501 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002502 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002503 if (args->bitmask)
2504 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002505 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506}
2507
2508/*
2509 * a COMMIT request
2510 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002511static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002512 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002515 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
Chuck Lever9f06c712010-12-14 14:59:18 +00002518 encode_compound_hdr(xdr, req, &hdr);
2519 encode_sequence(xdr, &args->seq_args, &hdr);
2520 encode_putfh(xdr, args->fh, &hdr);
2521 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002522 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523}
2524
2525/*
2526 * FSINFO request
2527 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002528static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2529 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002532 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
Chuck Lever9f06c712010-12-14 14:59:18 +00002535 encode_compound_hdr(xdr, req, &hdr);
2536 encode_sequence(xdr, &args->seq_args, &hdr);
2537 encode_putfh(xdr, args->fh, &hdr);
2538 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002539 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540}
2541
2542/*
2543 * a PATHCONF request
2544 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002545static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2546 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002549 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551
Chuck Lever9f06c712010-12-14 14:59:18 +00002552 encode_compound_hdr(xdr, req, &hdr);
2553 encode_sequence(xdr, &args->seq_args, &hdr);
2554 encode_putfh(xdr, args->fh, &hdr);
2555 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002556 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002557 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558}
2559
2560/*
2561 * a STATFS request
2562 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002563static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2564 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002567 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
Chuck Lever9f06c712010-12-14 14:59:18 +00002570 encode_compound_hdr(xdr, req, &hdr);
2571 encode_sequence(xdr, &args->seq_args, &hdr);
2572 encode_putfh(xdr, args->fh, &hdr);
2573 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002574 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002575 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576}
2577
2578/*
2579 * GETATTR_BITMAP request
2580 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002581static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2582 struct xdr_stream *xdr,
2583 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002586 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588
Chuck Lever9f06c712010-12-14 14:59:18 +00002589 encode_compound_hdr(xdr, req, &hdr);
2590 encode_sequence(xdr, &args->seq_args, &hdr);
2591 encode_putfh(xdr, args->fhandle, &hdr);
2592 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002593 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002594 FATTR4_WORD0_LINK_SUPPORT|
2595 FATTR4_WORD0_SYMLINK_SUPPORT|
2596 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002597 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598}
2599
2600/*
2601 * a RENEW request
2602 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002603static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2604 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002607 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 };
2609
Chuck Lever9f06c712010-12-14 14:59:18 +00002610 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002611 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002612 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613}
2614
2615/*
2616 * a SETCLIENTID request
2617 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002618static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2619 struct xdr_stream *xdr,
2620 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002623 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 };
2625
Chuck Lever9f06c712010-12-14 14:59:18 +00002626 encode_compound_hdr(xdr, req, &hdr);
2627 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002628 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629}
2630
2631/*
2632 * a SETCLIENTID_CONFIRM request
2633 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002634static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2635 struct xdr_stream *xdr,
2636 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002639 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641
Chuck Lever9f06c712010-12-14 14:59:18 +00002642 encode_compound_hdr(xdr, req, &hdr);
2643 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002644 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645}
2646
2647/*
2648 * DELEGRETURN request
2649 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002650static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2651 struct xdr_stream *xdr,
2652 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002655 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
Chuck Lever9f06c712010-12-14 14:59:18 +00002658 encode_compound_hdr(xdr, req, &hdr);
2659 encode_sequence(xdr, &args->seq_args, &hdr);
2660 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002661 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002662 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002663 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664}
2665
2666/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002667 * Encode FS_LOCATIONS request
2668 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002669static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2670 struct xdr_stream *xdr,
2671 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002672{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002673 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002674 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002675 };
Benny Halevy28f56692009-04-01 09:22:09 -04002676 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002677
Chuck Lever9f06c712010-12-14 14:59:18 +00002678 encode_compound_hdr(xdr, req, &hdr);
2679 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002680 if (args->migration) {
2681 encode_putfh(xdr, args->fh, &hdr);
2682 replen = hdr.replen;
2683 encode_fs_locations(xdr, args->bitmask, &hdr);
2684 if (args->renew)
2685 encode_renew(xdr, args->clientid, &hdr);
2686 } else {
2687 encode_putfh(xdr, args->dir_fh, &hdr);
2688 encode_lookup(xdr, args->name, &hdr);
2689 replen = hdr.replen;
2690 encode_fs_locations(xdr, args->bitmask, &hdr);
2691 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002692
Chuck Leverb03d7352013-10-17 14:12:50 -04002693 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002694 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002695 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002696 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002697}
2698
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002699/*
2700 * Encode SECINFO request
2701 */
2702static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2703 struct xdr_stream *xdr,
2704 struct nfs4_secinfo_arg *args)
2705{
2706 struct compound_hdr hdr = {
2707 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2708 };
2709
2710 encode_compound_hdr(xdr, req, &hdr);
2711 encode_sequence(xdr, &args->seq_args, &hdr);
2712 encode_putfh(xdr, args->dir_fh, &hdr);
2713 encode_secinfo(xdr, args->name, &hdr);
2714 encode_nops(&hdr);
2715}
2716
Chuck Lever44c99932013-10-17 14:13:30 -04002717/*
2718 * Encode FSID_PRESENT request
2719 */
2720static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2721 struct xdr_stream *xdr,
2722 struct nfs4_fsid_present_arg *args)
2723{
2724 struct compound_hdr hdr = {
2725 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2726 };
2727
2728 encode_compound_hdr(xdr, req, &hdr);
2729 encode_sequence(xdr, &args->seq_args, &hdr);
2730 encode_putfh(xdr, args->fh, &hdr);
2731 encode_getfh(xdr, &hdr);
2732 if (args->renew)
2733 encode_renew(xdr, args->clientid, &hdr);
2734 encode_nops(&hdr);
2735}
2736
Benny Halevy99fe60d2009-04-01 09:22:29 -04002737#if defined(CONFIG_NFS_V4_1)
2738/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002739 * BIND_CONN_TO_SESSION request
2740 */
2741static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2742 struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08002743 struct nfs41_bind_conn_to_session_args *args)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002744{
2745 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002746 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002747 };
2748
2749 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002750 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002751 encode_nops(&hdr);
2752}
2753
2754/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002755 * EXCHANGE_ID request
2756 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002757static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2758 struct xdr_stream *xdr,
2759 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002760{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002761 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002762 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002763 };
2764
Chuck Lever9f06c712010-12-14 14:59:18 +00002765 encode_compound_hdr(xdr, req, &hdr);
2766 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002767 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002768}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002769
2770/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002771 * a CREATE_SESSION request
2772 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002773static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2774 struct xdr_stream *xdr,
2775 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002776{
Andy Adamsonfc931582009-04-01 09:22:31 -04002777 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002778 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002779 };
2780
Chuck Lever9f06c712010-12-14 14:59:18 +00002781 encode_compound_hdr(xdr, req, &hdr);
2782 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002783 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002784}
2785
2786/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002787 * a DESTROY_SESSION request
2788 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002789static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2790 struct xdr_stream *xdr,
2791 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002792{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002793 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002794 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002795 };
2796
Chuck Lever9f06c712010-12-14 14:59:18 +00002797 encode_compound_hdr(xdr, req, &hdr);
2798 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002799 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002800}
2801
2802/*
Trond Myklebust66245532012-05-25 17:18:09 -04002803 * a DESTROY_CLIENTID request
2804 */
2805static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2806 struct xdr_stream *xdr,
2807 struct nfs_client *clp)
2808{
2809 struct compound_hdr hdr = {
2810 .minorversion = clp->cl_mvops->minor_version,
2811 };
2812
2813 encode_compound_hdr(xdr, req, &hdr);
2814 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2815 encode_nops(&hdr);
2816}
2817
2818/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002819 * a SEQUENCE request
2820 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002821static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2822 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002823{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002824 struct compound_hdr hdr = {
2825 .minorversion = nfs4_xdr_minorversion(args),
2826 };
2827
Chuck Lever9f06c712010-12-14 14:59:18 +00002828 encode_compound_hdr(xdr, req, &hdr);
2829 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002830 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002831}
2832
2833/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002834 * a GET_LEASE_TIME request
2835 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002836static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2837 struct xdr_stream *xdr,
2838 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002839{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002840 struct compound_hdr hdr = {
2841 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2842 };
Fred Isamandae100c2011-07-30 20:52:37 -04002843 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002844
Chuck Lever9f06c712010-12-14 14:59:18 +00002845 encode_compound_hdr(xdr, req, &hdr);
2846 encode_sequence(xdr, &args->la_seq_args, &hdr);
2847 encode_putrootfh(xdr, &hdr);
2848 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002849 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002850}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002851
2852/*
2853 * a RECLAIM_COMPLETE request
2854 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002855static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2856 struct xdr_stream *xdr,
2857 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002858{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002859 struct compound_hdr hdr = {
2860 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2861 };
2862
Chuck Lever9f06c712010-12-14 14:59:18 +00002863 encode_compound_hdr(xdr, req, &hdr);
2864 encode_sequence(xdr, &args->seq_args, &hdr);
2865 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002866 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002867}
2868
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002869/*
2870 * Encode GETDEVICEINFO request
2871 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002872static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2873 struct xdr_stream *xdr,
2874 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002875{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002876 struct compound_hdr hdr = {
2877 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2878 };
2879
Chuck Lever9f06c712010-12-14 14:59:18 +00002880 encode_compound_hdr(xdr, req, &hdr);
2881 encode_sequence(xdr, &args->seq_args, &hdr);
2882 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002883
2884 /* set up reply kvec. Subtract notification bitmap max size (2)
2885 * so that notification bitmap is put in xdr_buf tail */
2886 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2887 args->pdev->pages, args->pdev->pgbase,
2888 args->pdev->pglen);
2889
2890 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002891}
2892
2893/*
2894 * Encode LAYOUTGET request
2895 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002896static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2897 struct xdr_stream *xdr,
2898 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002899{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002900 struct compound_hdr hdr = {
2901 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2902 };
2903
Chuck Lever9f06c712010-12-14 14:59:18 +00002904 encode_compound_hdr(xdr, req, &hdr);
2905 encode_sequence(xdr, &args->seq_args, &hdr);
2906 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2907 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002908
2909 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2910 args->layout.pages, 0, args->layout.pglen);
2911
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002912 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002913}
Andy Adamson863a3c62011-03-23 13:27:54 +00002914
2915/*
2916 * Encode LAYOUTCOMMIT request
2917 */
Benny Halevycbe82602011-05-22 19:52:37 +03002918static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2919 struct xdr_stream *xdr,
2920 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002921{
Benny Halevyac7db722011-05-22 19:53:48 +03002922 struct nfs4_layoutcommit_data *data =
2923 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002924 struct compound_hdr hdr = {
2925 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2926 };
2927
2928 encode_compound_hdr(xdr, req, &hdr);
2929 encode_sequence(xdr, &args->seq_args, &hdr);
2930 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002931 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002932 encode_getfattr(xdr, args->bitmask, &hdr);
2933 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002934}
2935
2936/*
2937 * Encode LAYOUTRETURN request
2938 */
2939static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2940 struct xdr_stream *xdr,
2941 struct nfs4_layoutreturn_args *args)
2942{
2943 struct compound_hdr hdr = {
2944 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2945 };
2946
2947 encode_compound_hdr(xdr, req, &hdr);
2948 encode_sequence(xdr, &args->seq_args, &hdr);
2949 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2950 encode_layoutreturn(xdr, args, &hdr);
2951 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002952}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002953
2954/*
2955 * Encode SECINFO_NO_NAME request
2956 */
2957static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2958 struct xdr_stream *xdr,
2959 struct nfs41_secinfo_no_name_args *args)
2960{
2961 struct compound_hdr hdr = {
2962 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2963 };
2964
2965 encode_compound_hdr(xdr, req, &hdr);
2966 encode_sequence(xdr, &args->seq_args, &hdr);
2967 encode_putrootfh(xdr, &hdr);
2968 encode_secinfo_no_name(xdr, args, &hdr);
2969 encode_nops(&hdr);
2970 return 0;
2971}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002972
2973/*
2974 * Encode TEST_STATEID request
2975 */
2976static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2977 struct xdr_stream *xdr,
2978 struct nfs41_test_stateid_args *args)
2979{
2980 struct compound_hdr hdr = {
2981 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2982 };
2983
2984 encode_compound_hdr(xdr, req, &hdr);
2985 encode_sequence(xdr, &args->seq_args, &hdr);
2986 encode_test_stateid(xdr, args, &hdr);
2987 encode_nops(&hdr);
2988}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002989
2990/*
2991 * Encode FREE_STATEID request
2992 */
2993static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2994 struct xdr_stream *xdr,
2995 struct nfs41_free_stateid_args *args)
2996{
2997 struct compound_hdr hdr = {
2998 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2999 };
3000
3001 encode_compound_hdr(xdr, req, &hdr);
3002 encode_sequence(xdr, &args->seq_args, &hdr);
3003 encode_free_stateid(xdr, args, &hdr);
3004 encode_nops(&hdr);
3005}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003006#endif /* CONFIG_NFS_V4_1 */
3007
Benny Halevy686841b2009-08-14 17:19:48 +03003008static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3009{
3010 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3011 "Remaining buffer length is %tu words.\n",
3012 func, xdr->end - xdr->p);
3013}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014
Trond Myklebust683b57b2006-06-09 09:34:22 -04003015static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016{
Al Viro8687b632006-10-19 23:28:48 -07003017 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018
Benny Halevyc0eae662009-08-14 17:20:14 +03003019 p = xdr_inline_decode(xdr, 4);
3020 if (unlikely(!p))
3021 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003022 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003023 p = xdr_inline_decode(xdr, *len);
3024 if (unlikely(!p))
3025 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 *string = (char *)p;
3027 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003028out_overflow:
3029 print_overflow_msg(__func__, xdr);
3030 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031}
3032
3033static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3034{
Al Viro8687b632006-10-19 23:28:48 -07003035 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036
Benny Halevyc0eae662009-08-14 17:20:14 +03003037 p = xdr_inline_decode(xdr, 8);
3038 if (unlikely(!p))
3039 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003040 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003041 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003042
Benny Halevyc0eae662009-08-14 17:20:14 +03003043 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3044 if (unlikely(!p))
3045 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 hdr->tag = (char *)p;
3047 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003048 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003049 if (unlikely(hdr->nops < 1))
3050 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003052out_overflow:
3053 print_overflow_msg(__func__, xdr);
3054 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055}
3056
Trond Myklebustc7848f62013-12-04 17:39:23 -05003057static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3058 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059{
Al Viro8687b632006-10-19 23:28:48 -07003060 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 uint32_t opnum;
3062 int32_t nfserr;
3063
Benny Halevyc0eae662009-08-14 17:20:14 +03003064 p = xdr_inline_decode(xdr, 8);
3065 if (unlikely(!p))
3066 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003067 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003068 if (unlikely(opnum != expected))
3069 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003070 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003071 if (nfserr == NFS_OK)
3072 *nfs_retval = 0;
3073 else
3074 *nfs_retval = nfs4_stat_to_errno(nfserr);
3075 return true;
3076out_bad_operation:
3077 dprintk("nfs: Server returned operation"
3078 " %d but we issued a request for %d\n",
3079 opnum, expected);
3080 *nfs_retval = -EREMOTEIO;
3081 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003082out_overflow:
3083 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003084 *nfs_retval = -EIO;
3085 return false;
3086}
3087
3088static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3089{
3090 int retval;
3091
3092 __decode_op_hdr(xdr, expected, &retval);
3093 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094}
3095
3096/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003097static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098{
Al Viro8687b632006-10-19 23:28:48 -07003099 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003100 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 char *str;
3102
Benny Halevyc0eae662009-08-14 17:20:14 +03003103 p = xdr_inline_decode(xdr, 12);
3104 if (likely(p))
3105 return decode_opaque_inline(xdr, &strlen, &str);
3106 print_overflow_msg(__func__, xdr);
3107 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108}
3109
3110static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3111{
Al Viro8687b632006-10-19 23:28:48 -07003112 uint32_t bmlen;
3113 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114
Benny Halevyc0eae662009-08-14 17:20:14 +03003115 p = xdr_inline_decode(xdr, 4);
3116 if (unlikely(!p))
3117 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003118 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119
Fred Isamandae100c2011-07-30 20:52:37 -04003120 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003121 p = xdr_inline_decode(xdr, (bmlen << 2));
3122 if (unlikely(!p))
3123 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003125 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003126 if (bmlen > 1) {
3127 bitmap[1] = be32_to_cpup(p++);
3128 if (bmlen > 2)
3129 bitmap[2] = be32_to_cpup(p);
3130 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 }
3132 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003133out_overflow:
3134 print_overflow_msg(__func__, xdr);
3135 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136}
3137
Trond Myklebust256e48b2012-06-21 11:18:13 -04003138static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139{
Al Viro8687b632006-10-19 23:28:48 -07003140 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141
Benny Halevyc0eae662009-08-14 17:20:14 +03003142 p = xdr_inline_decode(xdr, 4);
3143 if (unlikely(!p))
3144 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003145 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003146 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003148out_overflow:
3149 print_overflow_msg(__func__, xdr);
3150 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151}
3152
3153static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3154{
3155 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003156 int ret;
3157 ret = decode_attr_bitmap(xdr, bitmask);
3158 if (unlikely(ret < 0))
3159 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3161 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003162 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3163 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3164 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 return 0;
3166}
3167
3168static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3169{
Al Viro8687b632006-10-19 23:28:48 -07003170 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003171 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172
3173 *type = 0;
3174 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3175 return -EIO;
3176 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003177 p = xdr_inline_decode(xdr, 4);
3178 if (unlikely(!p))
3179 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003180 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003182 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 return -EIO;
3184 }
3185 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003186 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003188 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003189 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003190out_overflow:
3191 print_overflow_msg(__func__, xdr);
3192 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193}
3194
Chuck Lever264e6352012-03-01 17:02:05 -05003195static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3196 uint32_t *bitmap, uint32_t *type)
3197{
3198 __be32 *p;
3199
3200 *type = 0;
3201 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3202 return -EIO;
3203 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3204 p = xdr_inline_decode(xdr, 4);
3205 if (unlikely(!p))
3206 goto out_overflow;
3207 *type = be32_to_cpup(p);
3208 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3209 }
3210 dprintk("%s: expire type=0x%x\n", __func__, *type);
3211 return 0;
3212out_overflow:
3213 print_overflow_msg(__func__, xdr);
3214 return -EIO;
3215}
3216
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3218{
Al Viro8687b632006-10-19 23:28:48 -07003219 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003220 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221
3222 *change = 0;
3223 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3224 return -EIO;
3225 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003226 p = xdr_inline_decode(xdr, 8);
3227 if (unlikely(!p))
3228 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003229 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003231 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003233 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003235 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003236out_overflow:
3237 print_overflow_msg(__func__, xdr);
3238 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239}
3240
3241static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3242{
Al Viro8687b632006-10-19 23:28:48 -07003243 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003244 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245
3246 *size = 0;
3247 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3248 return -EIO;
3249 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003250 p = xdr_inline_decode(xdr, 8);
3251 if (unlikely(!p))
3252 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003253 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003255 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003257 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003258 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003259out_overflow:
3260 print_overflow_msg(__func__, xdr);
3261 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262}
3263
3264static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3265{
Al Viro8687b632006-10-19 23:28:48 -07003266 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267
3268 *res = 0;
3269 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3270 return -EIO;
3271 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003272 p = xdr_inline_decode(xdr, 4);
3273 if (unlikely(!p))
3274 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003275 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3277 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003278 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003280out_overflow:
3281 print_overflow_msg(__func__, xdr);
3282 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283}
3284
3285static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3286{
Al Viro8687b632006-10-19 23:28:48 -07003287 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288
3289 *res = 0;
3290 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3291 return -EIO;
3292 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003293 p = xdr_inline_decode(xdr, 4);
3294 if (unlikely(!p))
3295 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003296 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3298 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003299 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003301out_overflow:
3302 print_overflow_msg(__func__, xdr);
3303 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304}
3305
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003306static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307{
Al Viro8687b632006-10-19 23:28:48 -07003308 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003309 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310
3311 fsid->major = 0;
3312 fsid->minor = 0;
3313 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3314 return -EIO;
3315 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003316 p = xdr_inline_decode(xdr, 16);
3317 if (unlikely(!p))
3318 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003319 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003320 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003322 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003324 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 (unsigned long long)fsid->major,
3326 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003327 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003328out_overflow:
3329 print_overflow_msg(__func__, xdr);
3330 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331}
3332
3333static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3334{
Al Viro8687b632006-10-19 23:28:48 -07003335 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336
3337 *res = 60;
3338 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3339 return -EIO;
3340 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003341 p = xdr_inline_decode(xdr, 4);
3342 if (unlikely(!p))
3343 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003344 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3346 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003347 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003349out_overflow:
3350 print_overflow_msg(__func__, xdr);
3351 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352}
3353
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003354static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003355{
3356 __be32 *p;
3357
3358 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3359 return -EIO;
3360 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3361 p = xdr_inline_decode(xdr, 4);
3362 if (unlikely(!p))
3363 goto out_overflow;
3364 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003365 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003366 }
3367 return 0;
3368out_overflow:
3369 print_overflow_msg(__func__, xdr);
3370 return -EIO;
3371}
3372
3373static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3374{
3375 __be32 *p;
3376 int len;
3377
Trond Myklebust7ad07352010-10-23 15:34:20 -04003378 if (fh != NULL)
3379 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003380
3381 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3382 return -EIO;
3383 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3384 p = xdr_inline_decode(xdr, 4);
3385 if (unlikely(!p))
3386 goto out_overflow;
3387 len = be32_to_cpup(p);
3388 if (len > NFS4_FHSIZE)
3389 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003390 p = xdr_inline_decode(xdr, len);
3391 if (unlikely(!p))
3392 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003393 if (fh != NULL) {
3394 memcpy(fh->data, p, len);
3395 fh->size = len;
3396 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003397 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3398 }
3399 return 0;
3400out_overflow:
3401 print_overflow_msg(__func__, xdr);
3402 return -EIO;
3403}
3404
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3406{
Al Viro8687b632006-10-19 23:28:48 -07003407 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003409 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3411 return -EIO;
3412 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003413 p = xdr_inline_decode(xdr, 4);
3414 if (unlikely(!p))
3415 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003416 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3418 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003419 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003421out_overflow:
3422 print_overflow_msg(__func__, xdr);
3423 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424}
3425
3426static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3427{
Al Viro8687b632006-10-19 23:28:48 -07003428 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003429 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430
3431 *fileid = 0;
3432 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3433 return -EIO;
3434 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003435 p = xdr_inline_decode(xdr, 8);
3436 if (unlikely(!p))
3437 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003438 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003440 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003442 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003443 return ret;
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
Manoj Naik99baf622006-06-09 09:34:24 -04003449static int decode_attr_mounted_on_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;
Manoj Naik99baf622006-06-09 09:34:24 -04003453
3454 *fileid = 0;
3455 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3456 return -EIO;
3457 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_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);
Manoj Naik99baf622006-06-09 09:34:24 -04003462 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003463 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003464 }
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;
Manoj Naik99baf622006-06-09 09:34:24 -04003470}
3471
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3473{
Al Viro8687b632006-10-19 23:28:48 -07003474 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 int status = 0;
3476
3477 *res = 0;
3478 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3479 return -EIO;
3480 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
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, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3486 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003487 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003489out_overflow:
3490 print_overflow_msg(__func__, xdr);
3491 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492}
3493
3494static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3495{
Al Viro8687b632006-10-19 23:28:48 -07003496 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 int status = 0;
3498
3499 *res = 0;
3500 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3501 return -EIO;
3502 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003503 p = xdr_inline_decode(xdr, 8);
3504 if (unlikely(!p))
3505 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003506 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3508 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003509 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003511out_overflow:
3512 print_overflow_msg(__func__, xdr);
3513 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514}
3515
3516static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3517{
Al Viro8687b632006-10-19 23:28:48 -07003518 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 int status = 0;
3520
3521 *res = 0;
3522 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3523 return -EIO;
3524 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003525 p = xdr_inline_decode(xdr, 8);
3526 if (unlikely(!p))
3527 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003528 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3530 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003531 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003533out_overflow:
3534 print_overflow_msg(__func__, xdr);
3535 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536}
3537
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003538static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3539{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003540 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003541 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003542 int status = 0;
3543
Benny Halevyc0eae662009-08-14 17:20:14 +03003544 p = xdr_inline_decode(xdr, 4);
3545 if (unlikely(!p))
3546 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003547 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003548 if (n == 0)
3549 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003550 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003551 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3552 dprintk("cannot parse %d components in path\n", n);
3553 goto out_eio;
3554 }
3555 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003556 struct nfs4_string *component = &path->components[path->ncomponents];
3557 status = decode_opaque_inline(xdr, &component->len, &component->data);
3558 if (unlikely(status != 0))
3559 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003560 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003561 pr_cont("%s%.*s ",
3562 (path->ncomponents != n ? "/ " : ""),
3563 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003564 }
3565out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003566 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003567root_path:
3568/* a root pathname is sent as a zero component4 */
3569 path->ncomponents = 1;
3570 path->components[0].len=0;
3571 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003572 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003573 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003574out_eio:
3575 dprintk(" status %d", status);
3576 status = -EIO;
3577 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003578out_overflow:
3579 print_overflow_msg(__func__, xdr);
3580 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003581}
3582
3583static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003584{
3585 int n;
Al Viro8687b632006-10-19 23:28:48 -07003586 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003587 int status = -EIO;
3588
3589 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3590 goto out;
3591 status = 0;
3592 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3593 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003594 status = -EIO;
3595 /* Ignore borken servers that return unrequested attrs */
3596 if (unlikely(res == NULL))
3597 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003598 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003599 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003600 if (unlikely(status != 0))
3601 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003602 p = xdr_inline_decode(xdr, 4);
3603 if (unlikely(!p))
3604 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003605 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003606 if (n <= 0)
3607 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003608 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003609 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003610 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003611
Trond Myklebust809b4262013-03-27 11:54:45 -04003612 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3613 break;
3614 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003615 p = xdr_inline_decode(xdr, 4);
3616 if (unlikely(!p))
3617 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003618 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003619
Chuck Lever02a29762012-03-01 17:00:31 -05003620 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003621 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3622 struct nfs4_string *server;
3623
3624 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003625 unsigned int i;
3626 dprintk("%s: using first %u of %u servers "
3627 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003628 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003629 NFS4_FS_LOCATION_MAXSERVERS,
3630 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003631 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003632 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003633 char *data;
3634 status = decode_opaque_inline(xdr, &len, &data);
3635 if (unlikely(status != 0))
3636 goto out_eio;
3637 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003638 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003639 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003640 server = &loc->servers[loc->nservers];
3641 status = decode_opaque_inline(xdr, &server->len, &server->data);
3642 if (unlikely(status != 0))
3643 goto out_eio;
3644 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003645 }
3646 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003647 if (unlikely(status != 0))
3648 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003649 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003650 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003651 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003652out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003653 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003654 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003655out_overflow:
3656 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003657out_eio:
3658 status = -EIO;
3659 goto out;
3660}
3661
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3663{
Al Viro8687b632006-10-19 23:28:48 -07003664 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665 int status = 0;
3666
3667 *res = 0;
3668 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3669 return -EIO;
3670 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003671 p = xdr_inline_decode(xdr, 8);
3672 if (unlikely(!p))
3673 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003674 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3676 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003677 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003679out_overflow:
3680 print_overflow_msg(__func__, xdr);
3681 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682}
3683
3684static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3685{
Al Viro8687b632006-10-19 23:28:48 -07003686 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 int status = 0;
3688
3689 *maxlink = 1;
3690 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3691 return -EIO;
3692 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003693 p = xdr_inline_decode(xdr, 4);
3694 if (unlikely(!p))
3695 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003696 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3698 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003699 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003701out_overflow:
3702 print_overflow_msg(__func__, xdr);
3703 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704}
3705
3706static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3707{
Al Viro8687b632006-10-19 23:28:48 -07003708 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 int status = 0;
3710
3711 *maxname = 1024;
3712 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3713 return -EIO;
3714 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003715 p = xdr_inline_decode(xdr, 4);
3716 if (unlikely(!p))
3717 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003718 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3720 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003721 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003723out_overflow:
3724 print_overflow_msg(__func__, xdr);
3725 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726}
3727
3728static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3729{
Al Viro8687b632006-10-19 23:28:48 -07003730 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 int status = 0;
3732
3733 *res = 1024;
3734 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3735 return -EIO;
3736 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3737 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003738 p = xdr_inline_decode(xdr, 8);
3739 if (unlikely(!p))
3740 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003741 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 if (maxread > 0x7FFFFFFF)
3743 maxread = 0x7FFFFFFF;
3744 *res = (uint32_t)maxread;
3745 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3746 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003747 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003749out_overflow:
3750 print_overflow_msg(__func__, xdr);
3751 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752}
3753
3754static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3755{
Al Viro8687b632006-10-19 23:28:48 -07003756 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757 int status = 0;
3758
3759 *res = 1024;
3760 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3761 return -EIO;
3762 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3763 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003764 p = xdr_inline_decode(xdr, 8);
3765 if (unlikely(!p))
3766 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003767 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 if (maxwrite > 0x7FFFFFFF)
3769 maxwrite = 0x7FFFFFFF;
3770 *res = (uint32_t)maxwrite;
3771 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3772 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003773 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003775out_overflow:
3776 print_overflow_msg(__func__, xdr);
3777 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778}
3779
Trond Myklebustbca79472009-03-11 14:10:26 -04003780static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781{
Trond Myklebustbca79472009-03-11 14:10:26 -04003782 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003783 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003784 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
3786 *mode = 0;
3787 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3788 return -EIO;
3789 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003790 p = xdr_inline_decode(xdr, 4);
3791 if (unlikely(!p))
3792 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003793 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003794 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003796 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003798 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003799 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003800out_overflow:
3801 print_overflow_msg(__func__, xdr);
3802 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803}
3804
3805static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3806{
Al Viro8687b632006-10-19 23:28:48 -07003807 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003808 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809
3810 *nlink = 1;
3811 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3812 return -EIO;
3813 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003814 p = xdr_inline_decode(xdr, 4);
3815 if (unlikely(!p))
3816 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003817 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003819 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003821 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
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
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003828static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003829 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003830 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831{
Al Viro8687b632006-10-19 23:28:48 -07003832 uint32_t len;
3833 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003834 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835
Eric W. Biedermane5782072013-02-01 14:22:02 -08003836 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3838 return -EIO;
3839 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003840 p = xdr_inline_decode(xdr, 4);
3841 if (unlikely(!p))
3842 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003843 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003844 p = xdr_inline_decode(xdr, len);
3845 if (unlikely(!p))
3846 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003847 if (owner_name != NULL) {
3848 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3849 if (owner_name->data != NULL) {
3850 owner_name->len = len;
3851 ret = NFS_ATTR_FATTR_OWNER_NAME;
3852 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003853 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003854 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003855 ret = NFS_ATTR_FATTR_OWNER;
3856 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003858 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003860 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003861 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3863 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003864 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003865 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003866out_overflow:
3867 print_overflow_msg(__func__, xdr);
3868 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869}
3870
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003871static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003872 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003873 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874{
Al Viro8687b632006-10-19 23:28:48 -07003875 uint32_t len;
3876 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003877 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878
Eric W. Biedermane5782072013-02-01 14:22:02 -08003879 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3881 return -EIO;
3882 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003883 p = xdr_inline_decode(xdr, 4);
3884 if (unlikely(!p))
3885 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003886 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003887 p = xdr_inline_decode(xdr, len);
3888 if (unlikely(!p))
3889 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003890 if (group_name != NULL) {
3891 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3892 if (group_name->data != NULL) {
3893 group_name->len = len;
3894 ret = NFS_ATTR_FATTR_GROUP_NAME;
3895 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003896 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003897 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003898 ret = NFS_ATTR_FATTR_GROUP;
3899 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003901 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003903 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003904 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3906 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003907 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003908 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003909out_overflow:
3910 print_overflow_msg(__func__, xdr);
3911 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912}
3913
3914static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3915{
Al Viro8687b632006-10-19 23:28:48 -07003916 uint32_t major = 0, minor = 0;
3917 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003918 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919
3920 *rdev = MKDEV(0,0);
3921 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3922 return -EIO;
3923 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3924 dev_t tmp;
3925
Benny Halevyc0eae662009-08-14 17:20:14 +03003926 p = xdr_inline_decode(xdr, 8);
3927 if (unlikely(!p))
3928 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003929 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003930 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 tmp = MKDEV(major, minor);
3932 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3933 *rdev = tmp;
3934 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003935 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003937 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003938 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003939out_overflow:
3940 print_overflow_msg(__func__, xdr);
3941 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942}
3943
3944static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3945{
Al Viro8687b632006-10-19 23:28:48 -07003946 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 int status = 0;
3948
3949 *res = 0;
3950 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3951 return -EIO;
3952 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003953 p = xdr_inline_decode(xdr, 8);
3954 if (unlikely(!p))
3955 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003956 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3958 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003959 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003961out_overflow:
3962 print_overflow_msg(__func__, xdr);
3963 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964}
3965
3966static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3967{
Al Viro8687b632006-10-19 23:28:48 -07003968 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 int status = 0;
3970
3971 *res = 0;
3972 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3973 return -EIO;
3974 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003975 p = xdr_inline_decode(xdr, 8);
3976 if (unlikely(!p))
3977 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003978 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3980 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003981 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003983out_overflow:
3984 print_overflow_msg(__func__, xdr);
3985 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986}
3987
3988static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3989{
Al Viro8687b632006-10-19 23:28:48 -07003990 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 int status = 0;
3992
3993 *res = 0;
3994 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3995 return -EIO;
3996 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003997 p = xdr_inline_decode(xdr, 8);
3998 if (unlikely(!p))
3999 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004000 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4002 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004003 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004005out_overflow:
4006 print_overflow_msg(__func__, xdr);
4007 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008}
4009
4010static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4011{
Al Viro8687b632006-10-19 23:28:48 -07004012 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004013 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014
4015 *used = 0;
4016 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4017 return -EIO;
4018 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004019 p = xdr_inline_decode(xdr, 8);
4020 if (unlikely(!p))
4021 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004022 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004024 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004026 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004028 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004029out_overflow:
4030 print_overflow_msg(__func__, xdr);
4031 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032}
4033
4034static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4035{
Al Viro8687b632006-10-19 23:28:48 -07004036 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 uint64_t sec;
4038 uint32_t nsec;
4039
Benny Halevyc0eae662009-08-14 17:20:14 +03004040 p = xdr_inline_decode(xdr, 12);
4041 if (unlikely(!p))
4042 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004043 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004044 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045 time->tv_sec = (time_t)sec;
4046 time->tv_nsec = (long)nsec;
4047 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004048out_overflow:
4049 print_overflow_msg(__func__, xdr);
4050 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051}
4052
4053static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4054{
4055 int status = 0;
4056
4057 time->tv_sec = 0;
4058 time->tv_nsec = 0;
4059 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4060 return -EIO;
4061 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4062 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004063 if (status == 0)
4064 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4066 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004067 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 return status;
4069}
4070
4071static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4072{
4073 int status = 0;
4074
4075 time->tv_sec = 0;
4076 time->tv_nsec = 0;
4077 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4078 return -EIO;
4079 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4080 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004081 if (status == 0)
4082 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4084 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004085 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 return status;
4087}
4088
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004089static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4090 struct timespec *time)
4091{
4092 int status = 0;
4093
4094 time->tv_sec = 0;
4095 time->tv_nsec = 0;
4096 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4097 return -EIO;
4098 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4099 status = decode_attr_time(xdr, time);
4100 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4101 }
4102 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4103 (long)time->tv_nsec);
4104 return status;
4105}
4106
David Quigleyaa9c2662013-05-22 12:50:44 -04004107static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4108 struct nfs4_label *label)
4109{
4110 uint32_t pi = 0;
4111 uint32_t lfs = 0;
4112 __u32 len;
4113 __be32 *p;
4114 int status = 0;
4115
4116 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4117 return -EIO;
4118 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4119 p = xdr_inline_decode(xdr, 4);
4120 if (unlikely(!p))
4121 goto out_overflow;
4122 lfs = be32_to_cpup(p++);
4123 p = xdr_inline_decode(xdr, 4);
4124 if (unlikely(!p))
4125 goto out_overflow;
4126 pi = be32_to_cpup(p++);
4127 p = xdr_inline_decode(xdr, 4);
4128 if (unlikely(!p))
4129 goto out_overflow;
4130 len = be32_to_cpup(p++);
4131 p = xdr_inline_decode(xdr, len);
4132 if (unlikely(!p))
4133 goto out_overflow;
4134 if (len < NFS4_MAXLABELLEN) {
4135 if (label) {
4136 memcpy(label->label, p, len);
4137 label->len = len;
4138 label->pi = pi;
4139 label->lfs = lfs;
4140 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4141 }
4142 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4143 } else
4144 printk(KERN_WARNING "%s: label too long (%u)!\n",
4145 __func__, len);
4146 }
4147 if (label && label->label)
4148 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4149 (char *)label->label, label->len, label->pi, label->lfs);
4150 return status;
4151
4152out_overflow:
4153 print_overflow_msg(__func__, xdr);
4154 return -EIO;
4155}
4156
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4158{
4159 int status = 0;
4160
4161 time->tv_sec = 0;
4162 time->tv_nsec = 0;
4163 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4164 return -EIO;
4165 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4166 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004167 if (status == 0)
4168 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4170 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004171 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 return status;
4173}
4174
Trond Myklebust256e48b2012-06-21 11:18:13 -04004175static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176{
4177 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004178 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179
4180 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004181 dprintk("%s: server returned incorrect attribute length: "
4182 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004183 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 attrwords << 2,
4185 (attrwords < nwords) ? '<' : '>',
4186 nwords << 2);
4187 return -EIO;
4188 }
4189 return 0;
4190}
4191
4192static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4193{
Al Viro8687b632006-10-19 23:28:48 -07004194 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195
Benny Halevyc0eae662009-08-14 17:20:14 +03004196 p = xdr_inline_decode(xdr, 20);
4197 if (unlikely(!p))
4198 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004199 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004200 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004201 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004203out_overflow:
4204 print_overflow_msg(__func__, xdr);
4205 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206}
4207
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004208static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209{
Al Viro8687b632006-10-19 23:28:48 -07004210 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 uint32_t supp, acc;
4212 int status;
4213
4214 status = decode_op_hdr(xdr, OP_ACCESS);
4215 if (status)
4216 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004217 p = xdr_inline_decode(xdr, 8);
4218 if (unlikely(!p))
4219 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004220 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004221 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004222 *supported = supp;
4223 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004225out_overflow:
4226 print_overflow_msg(__func__, xdr);
4227 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228}
4229
Benny Halevy07d30432009-08-14 17:19:52 +03004230static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231{
Al Viro8687b632006-10-19 23:28:48 -07004232 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004233
4234 p = xdr_inline_decode(xdr, len);
4235 if (likely(p)) {
4236 memcpy(buf, p, len);
4237 return 0;
4238 }
4239 print_overflow_msg(__func__, xdr);
4240 return -EIO;
4241}
4242
4243static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4244{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004245 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246}
4247
4248static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4249{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 int status;
4251
4252 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004253 if (status != -EIO)
4254 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004255 if (!status)
4256 status = decode_stateid(xdr, &res->stateid);
4257 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258}
4259
Benny Halevydb942bb2009-08-14 17:19:56 +03004260static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4261{
Chuck Levercd937102012-03-02 17:14:31 -05004262 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263}
4264
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004265static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4266{
4267 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4268}
4269
Fred Isaman0b7c0152012-04-20 14:47:39 -04004270static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 int status;
4273
4274 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004275 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004276 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004277 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278}
4279
4280static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4281{
Al Viro8687b632006-10-19 23:28:48 -07004282 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 uint32_t bmlen;
4284 int status;
4285
4286 status = decode_op_hdr(xdr, OP_CREATE);
4287 if (status)
4288 return status;
4289 if ((status = decode_change_info(xdr, cinfo)))
4290 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004291 p = xdr_inline_decode(xdr, 4);
4292 if (unlikely(!p))
4293 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004294 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004295 p = xdr_inline_decode(xdr, bmlen << 2);
4296 if (likely(p))
4297 return 0;
4298out_overflow:
4299 print_overflow_msg(__func__, xdr);
4300 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301}
4302
4303static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4304{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004305 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004306 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 int status;
4308
4309 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4310 goto xdr_error;
4311 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4312 goto xdr_error;
4313 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4314 goto xdr_error;
4315 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4316 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004317 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4318 &res->fh_expire_type)) != 0)
4319 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4321 goto xdr_error;
4322 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4323 goto xdr_error;
4324 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4325 goto xdr_error;
4326 status = verify_attr_len(xdr, savep, attrlen);
4327xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004328 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329 return status;
4330}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004331
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4333{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004334 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004335 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004337
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4339 goto xdr_error;
4340 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4341 goto xdr_error;
4342 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4343 goto xdr_error;
4344
4345 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4346 goto xdr_error;
4347 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4348 goto xdr_error;
4349 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4350 goto xdr_error;
4351 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4352 goto xdr_error;
4353 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4354 goto xdr_error;
4355 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4356 goto xdr_error;
4357
4358 status = verify_attr_len(xdr, savep, attrlen);
4359xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004360 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361 return status;
4362}
4363
4364static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4365{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004366 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004367 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004369
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4371 goto xdr_error;
4372 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4373 goto xdr_error;
4374 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4375 goto xdr_error;
4376
4377 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4378 goto xdr_error;
4379 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4380 goto xdr_error;
4381
4382 status = verify_attr_len(xdr, savep, attrlen);
4383xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004384 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385 return status;
4386}
4387
Andy Adamson88034c32012-05-23 05:02:34 -04004388static int decode_threshold_hint(struct xdr_stream *xdr,
4389 uint32_t *bitmap,
4390 uint64_t *res,
4391 uint32_t hint_bit)
4392{
4393 __be32 *p;
4394
4395 *res = 0;
4396 if (likely(bitmap[0] & hint_bit)) {
4397 p = xdr_inline_decode(xdr, 8);
4398 if (unlikely(!p))
4399 goto out_overflow;
4400 xdr_decode_hyper(p, res);
4401 }
4402 return 0;
4403out_overflow:
4404 print_overflow_msg(__func__, xdr);
4405 return -EIO;
4406}
4407
4408static int decode_first_threshold_item4(struct xdr_stream *xdr,
4409 struct nfs4_threshold *res)
4410{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004411 __be32 *p;
4412 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004413 uint32_t bitmap[3] = {0,}, attrlen;
4414 int status;
4415
4416 /* layout type */
4417 p = xdr_inline_decode(xdr, 4);
4418 if (unlikely(!p)) {
4419 print_overflow_msg(__func__, xdr);
4420 return -EIO;
4421 }
4422 res->l_type = be32_to_cpup(p);
4423
4424 /* thi_hintset bitmap */
4425 status = decode_attr_bitmap(xdr, bitmap);
4426 if (status < 0)
4427 goto xdr_error;
4428
4429 /* thi_hintlist length */
4430 status = decode_attr_length(xdr, &attrlen, &savep);
4431 if (status < 0)
4432 goto xdr_error;
4433 /* thi_hintlist */
4434 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4435 if (status < 0)
4436 goto xdr_error;
4437 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4438 if (status < 0)
4439 goto xdr_error;
4440 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4441 THRESHOLD_RD_IO);
4442 if (status < 0)
4443 goto xdr_error;
4444 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4445 THRESHOLD_WR_IO);
4446 if (status < 0)
4447 goto xdr_error;
4448
4449 status = verify_attr_len(xdr, savep, attrlen);
4450 res->bm = bitmap[0];
4451
4452 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4453 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4454 res->wr_io_sz);
4455xdr_error:
4456 dprintk("%s ret=%d!\n", __func__, status);
4457 return status;
4458}
4459
4460/*
4461 * Thresholds on pNFS direct I/O vrs MDS I/O
4462 */
4463static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4464 uint32_t *bitmap,
4465 struct nfs4_threshold *res)
4466{
4467 __be32 *p;
4468 int status = 0;
4469 uint32_t num;
4470
4471 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4472 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004473 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004474 /* Did the server return an unrequested attribute? */
4475 if (unlikely(res == NULL))
4476 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004477 p = xdr_inline_decode(xdr, 4);
4478 if (unlikely(!p))
4479 goto out_overflow;
4480 num = be32_to_cpup(p);
4481 if (num == 0)
4482 return 0;
4483 if (num > 1)
4484 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4485 "drivers per filesystem not supported\n",
4486 __func__);
4487
4488 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004489 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004490 }
4491 return status;
4492out_overflow:
4493 print_overflow_msg(__func__, xdr);
4494 return -EIO;
4495}
4496
Bryan Schumakerae42c702010-10-21 16:33:17 -04004497static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4498 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004499 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004500 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004501{
Trond Myklebustbca79472009-03-11 14:10:26 -04004502 int status;
4503 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004504 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004505 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004507 status = decode_attr_type(xdr, bitmap, &type);
4508 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004510 fattr->mode = 0;
4511 if (status != 0) {
4512 fattr->mode |= nfs_type2fmt[type];
4513 fattr->valid |= status;
4514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004516 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4517 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004519 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004520
4521 status = decode_attr_size(xdr, bitmap, &fattr->size);
4522 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004524 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004525
4526 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4527 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004529 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004530
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004531 err = 0;
4532 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004533 if (status < 0)
4534 goto xdr_error;
4535
4536 status = decode_attr_filehandle(xdr, bitmap, fh);
4537 if (status < 0)
4538 goto xdr_error;
4539
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004540 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4541 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004542 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004543 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004544
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004545 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004546 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004547 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004548 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004549
4550 status = decode_attr_mode(xdr, bitmap, &fmode);
4551 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004553 if (status != 0) {
4554 fattr->mode |= fmode;
4555 fattr->valid |= status;
4556 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004557
4558 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4559 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004561 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004562
Trond Myklebust6926afd2012-01-07 13:22:46 -05004563 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004564 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004565 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004566 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004567
Trond Myklebust6926afd2012-01-07 13:22:46 -05004568 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004569 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004571 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004572
4573 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4574 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004576 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004577
4578 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4579 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004581 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004582
4583 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4584 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004586 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004587
4588 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4589 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004591 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004592
4593 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4594 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004596 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004597
Trond Myklebust28331a42011-04-27 13:47:52 -04004598 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004599 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004600 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004601 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004602
Andy Adamson88034c32012-05-23 05:02:34 -04004603 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4604 if (status < 0)
4605 goto xdr_error;
4606
David Quigleyaa9c2662013-05-22 12:50:44 -04004607 if (label) {
4608 status = decode_attr_security_label(xdr, bitmap, label);
4609 if (status < 0)
4610 goto xdr_error;
4611 fattr->valid |= status;
4612 }
4613
Bryan Schumakerae42c702010-10-21 16:33:17 -04004614xdr_error:
4615 dprintk("%s: xdr returned %d\n", __func__, -status);
4616 return status;
4617}
4618
4619static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004620 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004621 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004622{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004623 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004624 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004625 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004626 int status;
4627
4628 status = decode_op_hdr(xdr, OP_GETATTR);
4629 if (status < 0)
4630 goto xdr_error;
4631
4632 status = decode_attr_bitmap(xdr, bitmap);
4633 if (status < 0)
4634 goto xdr_error;
4635
4636 status = decode_attr_length(xdr, &attrlen, &savep);
4637 if (status < 0)
4638 goto xdr_error;
4639
David Quigleyaa9c2662013-05-22 12:50:44 -04004640 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4641 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004642 if (status < 0)
4643 goto xdr_error;
4644
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004645 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004647 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648 return status;
4649}
4650
David Quigleyaa9c2662013-05-22 12:50:44 -04004651static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4652 struct nfs4_label *label, const struct nfs_server *server)
4653{
4654 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4655}
4656
Bryan Schumakerae42c702010-10-21 16:33:17 -04004657static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004658 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004659{
David Quigleyaa9c2662013-05-22 12:50:44 -04004660 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004661}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662
Andy Adamson504913f2010-10-20 00:17:57 -04004663/*
4664 * Decode potentially multiple layout types. Currently we only support
4665 * one layout driver per file system.
4666 */
4667static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4668 uint32_t *layouttype)
4669{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004670 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004671 int num;
4672
4673 p = xdr_inline_decode(xdr, 4);
4674 if (unlikely(!p))
4675 goto out_overflow;
4676 num = be32_to_cpup(p);
4677
4678 /* pNFS is not supported by the underlying file system */
4679 if (num == 0) {
4680 *layouttype = 0;
4681 return 0;
4682 }
4683 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004684 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4685 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004686
4687 /* Decode and set first layout type, move xdr->p past unused types */
4688 p = xdr_inline_decode(xdr, num * 4);
4689 if (unlikely(!p))
4690 goto out_overflow;
4691 *layouttype = be32_to_cpup(p);
4692 return 0;
4693out_overflow:
4694 print_overflow_msg(__func__, xdr);
4695 return -EIO;
4696}
4697
4698/*
4699 * The type of file system exported.
4700 * Note we must ensure that layouttype is set in any non-error case.
4701 */
4702static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4703 uint32_t *layouttype)
4704{
4705 int status = 0;
4706
4707 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4708 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4709 return -EIO;
4710 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4711 status = decode_first_pnfs_layout_type(xdr, layouttype);
4712 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4713 } else
4714 *layouttype = 0;
4715 return status;
4716}
4717
Fred Isamandae100c2011-07-30 20:52:37 -04004718/*
4719 * The prefered block size for layout directed io
4720 */
4721static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4722 uint32_t *res)
4723{
4724 __be32 *p;
4725
4726 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4727 *res = 0;
4728 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4729 p = xdr_inline_decode(xdr, 4);
4730 if (unlikely(!p)) {
4731 print_overflow_msg(__func__, xdr);
4732 return -EIO;
4733 }
4734 *res = be32_to_cpup(p);
4735 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4736 }
4737 return 0;
4738}
4739
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4741{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004742 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004743 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 int status;
4745
4746 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4747 goto xdr_error;
4748 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4749 goto xdr_error;
4750 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4751 goto xdr_error;
4752
4753 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4754
4755 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4756 goto xdr_error;
4757 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4758 goto xdr_error;
4759 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4760 goto xdr_error;
4761 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4762 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4763 goto xdr_error;
4764 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004765 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4766 if (status != 0)
4767 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004768 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4769 if (status != 0)
4770 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004771 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4772 if (status)
4773 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774
4775 status = verify_attr_len(xdr, savep, attrlen);
4776xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004777 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 return status;
4779}
4780
4781static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4782{
Al Viro8687b632006-10-19 23:28:48 -07004783 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784 uint32_t len;
4785 int status;
4786
Trond Myklebust99367812007-07-17 21:52:41 -04004787 /* Zero handle first to allow comparisons */
4788 memset(fh, 0, sizeof(*fh));
4789
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790 status = decode_op_hdr(xdr, OP_GETFH);
4791 if (status)
4792 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793
Benny Halevyc0eae662009-08-14 17:20:14 +03004794 p = xdr_inline_decode(xdr, 4);
4795 if (unlikely(!p))
4796 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004797 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 if (len > NFS4_FHSIZE)
4799 return -EIO;
4800 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004801 p = xdr_inline_decode(xdr, len);
4802 if (unlikely(!p))
4803 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004804 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004805 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004806out_overflow:
4807 print_overflow_msg(__func__, xdr);
4808 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809}
4810
4811static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4812{
4813 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004814
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815 status = decode_op_hdr(xdr, OP_LINK);
4816 if (status)
4817 return status;
4818 return decode_change_info(xdr, cinfo);
4819}
4820
4821/*
4822 * We create the owner, so we know a proper owner.id length is 4.
4823 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004824static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004826 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004827 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004828 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004830 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004831 if (unlikely(!p))
4832 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004833 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004834 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004835 type = be32_to_cpup(p++); /* 4 byte read */
4836 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004837 fl->fl_start = (loff_t)offset;
4838 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4839 if (length == ~(uint64_t)0)
4840 fl->fl_end = OFFSET_MAX;
4841 fl->fl_type = F_WRLCK;
4842 if (type & 1)
4843 fl->fl_type = F_RDLCK;
4844 fl->fl_pid = 0;
4845 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004846 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4847 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4848 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004849 if (likely(p))
4850 return -NFS4ERR_DENIED;
4851out_overflow:
4852 print_overflow_msg(__func__, xdr);
4853 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854}
4855
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004856static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858 int status;
4859
4860 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004861 if (status == -EIO)
4862 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004863 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004864 status = decode_stateid(xdr, &res->stateid);
4865 if (unlikely(status))
4866 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004868 status = decode_lock_denied(xdr, NULL);
4869 if (res->open_seqid != NULL)
4870 nfs_increment_open_seqid(status, res->open_seqid);
4871 nfs_increment_lock_seqid(status, res->lock_seqid);
4872out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873 return status;
4874}
4875
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004876static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877{
4878 int status;
4879 status = decode_op_hdr(xdr, OP_LOCKT);
4880 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004881 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882 return status;
4883}
4884
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004885static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 int status;
4888
4889 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004890 if (status != -EIO)
4891 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004892 if (status == 0)
4893 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894 return status;
4895}
4896
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004897static int decode_release_lockowner(struct xdr_stream *xdr)
4898{
4899 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4900}
4901
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902static int decode_lookup(struct xdr_stream *xdr)
4903{
4904 return decode_op_hdr(xdr, OP_LOOKUP);
4905}
4906
4907/* This is too sick! */
4908static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4909{
Andy Adamson05d564f2008-12-23 16:06:15 -05004910 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911 uint32_t limit_type, nblocks, blocksize;
4912
Benny Halevyc0eae662009-08-14 17:20:14 +03004913 p = xdr_inline_decode(xdr, 12);
4914 if (unlikely(!p))
4915 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004916 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004918 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004919 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004920 break;
4921 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004922 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004923 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004924 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925 }
4926 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004927out_overflow:
4928 print_overflow_msg(__func__, xdr);
4929 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930}
4931
Trond Myklebust6ae37332015-01-30 14:21:14 -05004932static int decode_rw_delegation(struct xdr_stream *xdr,
4933 uint32_t delegation_type,
4934 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935{
Andy Adamson05d564f2008-12-23 16:06:15 -05004936 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004937 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938
Benny Halevy07d30432009-08-14 17:19:52 +03004939 status = decode_stateid(xdr, &res->delegation);
4940 if (unlikely(status))
4941 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004942 p = xdr_inline_decode(xdr, 4);
4943 if (unlikely(!p))
4944 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004945 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004946
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004948 case NFS4_OPEN_DELEGATE_READ:
4949 res->delegation_type = FMODE_READ;
4950 break;
4951 case NFS4_OPEN_DELEGATE_WRITE:
4952 res->delegation_type = FMODE_WRITE|FMODE_READ;
4953 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 return -EIO;
4955 }
David Howells7539bba2006-08-22 20:06:09 -04004956 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004957out_overflow:
4958 print_overflow_msg(__func__, xdr);
4959 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960}
4961
Trond Myklebust6ae37332015-01-30 14:21:14 -05004962static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4963{
4964 __be32 *p;
4965 uint32_t why_no_delegation;
4966
4967 p = xdr_inline_decode(xdr, 4);
4968 if (unlikely(!p))
4969 goto out_overflow;
4970 why_no_delegation = be32_to_cpup(p);
4971 switch (why_no_delegation) {
4972 case WND4_CONTENTION:
4973 case WND4_RESOURCE:
4974 xdr_inline_decode(xdr, 4);
4975 /* Ignore for now */
4976 }
4977 return 0;
4978out_overflow:
4979 print_overflow_msg(__func__, xdr);
4980 return -EIO;
4981}
4982
4983static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4984{
4985 __be32 *p;
4986 uint32_t delegation_type;
4987
4988 p = xdr_inline_decode(xdr, 4);
4989 if (unlikely(!p))
4990 goto out_overflow;
4991 delegation_type = be32_to_cpup(p);
4992 res->delegation_type = 0;
4993 switch (delegation_type) {
4994 case NFS4_OPEN_DELEGATE_NONE:
4995 return 0;
4996 case NFS4_OPEN_DELEGATE_READ:
4997 case NFS4_OPEN_DELEGATE_WRITE:
4998 return decode_rw_delegation(xdr, delegation_type, res);
4999 case NFS4_OPEN_DELEGATE_NONE_EXT:
5000 return decode_no_delegation(xdr, res);
5001 }
5002 return -EIO;
5003out_overflow:
5004 print_overflow_msg(__func__, xdr);
5005 return -EIO;
5006}
5007
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5009{
Andy Adamson05d564f2008-12-23 16:06:15 -05005010 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005011 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005012 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013
Trond Myklebustc7848f62013-12-04 17:39:23 -05005014 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5015 return status;
5016 nfs_increment_open_seqid(status, res->seqid);
5017 if (status)
5018 return status;
5019 status = decode_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005020 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005021 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022
Andy Adamson05d564f2008-12-23 16:06:15 -05005023 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024
Benny Halevyc0eae662009-08-14 17:20:14 +03005025 p = xdr_inline_decode(xdr, 8);
5026 if (unlikely(!p))
5027 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005028 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005029 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005030 if (bmlen > 10)
5031 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032
Benny Halevyc0eae662009-08-14 17:20:14 +03005033 p = xdr_inline_decode(xdr, bmlen << 2);
5034 if (unlikely(!p))
5035 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005036 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5037 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005038 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005039 for (; i < NFS4_BITMAP_SIZE; i++)
5040 res->attrset[i] = 0;
5041
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042 return decode_delegation(xdr, res);
5043xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005044 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005046out_overflow:
5047 print_overflow_msg(__func__, xdr);
5048 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049}
5050
5051static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5052{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053 int status;
5054
Andy Adamson05d564f2008-12-23 16:06:15 -05005055 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005056 if (status != -EIO)
5057 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005058 if (!status)
5059 status = decode_stateid(xdr, &res->stateid);
5060 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061}
5062
5063static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5064{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065 int status;
5066
5067 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005068 if (status != -EIO)
5069 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005070 if (!status)
5071 status = decode_stateid(xdr, &res->stateid);
5072 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073}
5074
5075static int decode_putfh(struct xdr_stream *xdr)
5076{
5077 return decode_op_hdr(xdr, OP_PUTFH);
5078}
5079
5080static int decode_putrootfh(struct xdr_stream *xdr)
5081{
5082 return decode_op_hdr(xdr, OP_PUTROOTFH);
5083}
5084
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005085static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5086 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087{
Al Viro8687b632006-10-19 23:28:48 -07005088 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005089 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090 int status;
5091
5092 status = decode_op_hdr(xdr, OP_READ);
5093 if (status)
5094 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005095 p = xdr_inline_decode(xdr, 8);
5096 if (unlikely(!p))
5097 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005098 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005099 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005100 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005102 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103 "count %u > recvd %u\n", count, recvd);
5104 count = recvd;
5105 eof = 0;
5106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107 res->eof = eof;
5108 res->count = count;
5109 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005110out_overflow:
5111 print_overflow_msg(__func__, xdr);
5112 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113}
5114
5115static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5116{
Chuck Leverbcecff72007-10-26 13:32:03 -04005117 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005118 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119
5120 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005121 if (!status)
5122 status = decode_verifier(xdr, readdir->verifier.data);
5123 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005125 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005126 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005127 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005128 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129}
5130
5131static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5132{
5133 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005134 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005135 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 int status;
5137
5138 status = decode_op_hdr(xdr, OP_READLINK);
5139 if (status)
5140 return status;
5141
5142 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005143 p = xdr_inline_decode(xdr, 4);
5144 if (unlikely(!p))
5145 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005146 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005148 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149 return -ENAMETOOLONG;
5150 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005151 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005153 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005154 "count %u > recvd %u\n", len, recvd);
5155 return -EIO;
5156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 /*
5158 * The XDR encode routine has set things up so that
5159 * the link text will be copied directly into the
5160 * buffer. We just have to do overflow-checking,
5161 * and and null-terminate the text (the VFS expects
5162 * null-termination).
5163 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005164 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005166out_overflow:
5167 print_overflow_msg(__func__, xdr);
5168 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169}
5170
5171static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5172{
5173 int status;
5174
5175 status = decode_op_hdr(xdr, OP_REMOVE);
5176 if (status)
5177 goto out;
5178 status = decode_change_info(xdr, cinfo);
5179out:
5180 return status;
5181}
5182
5183static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5184 struct nfs4_change_info *new_cinfo)
5185{
5186 int status;
5187
5188 status = decode_op_hdr(xdr, OP_RENAME);
5189 if (status)
5190 goto out;
5191 if ((status = decode_change_info(xdr, old_cinfo)))
5192 goto out;
5193 status = decode_change_info(xdr, new_cinfo);
5194out:
5195 return status;
5196}
5197
5198static int decode_renew(struct xdr_stream *xdr)
5199{
5200 return decode_op_hdr(xdr, OP_RENEW);
5201}
5202
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005203static int
5204decode_restorefh(struct xdr_stream *xdr)
5205{
5206 return decode_op_hdr(xdr, OP_RESTOREFH);
5207}
5208
J. Bruce Fields029d1052005-06-22 17:16:22 +00005209static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005210 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005211{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005212 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005213 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005214 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005215 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005216 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005217
Andy Adamsonbf118a32011-12-07 11:55:27 -05005218 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005219 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5220 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005221
Trond Myklebust519d3952012-08-14 17:30:10 -04005222 xdr_enter_page(xdr, xdr->buf->page_len);
5223
Trond Myklebustcff298c2012-08-14 17:14:17 -04005224 /* Calculate the offset of the page data */
5225 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005226
J. Bruce Fields029d1052005-06-22 17:16:22 +00005227 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5228 goto out;
5229 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5230 goto out;
5231
5232 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5233 return -EIO;
5234 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005235
Andy Adamsonbf118a32011-12-07 11:55:27 -05005236 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5237 * are stored with the acl data to handle the problem of
5238 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005239 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005240 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005241
5242 /* Check for receive buffer overflow */
5243 if (res->acl_len > (xdr->nwords << 2) ||
5244 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5245 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005246 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005247 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005248 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005249 } else
5250 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005251
5252out:
5253 return status;
5254}
5255
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256static int
5257decode_savefh(struct xdr_stream *xdr)
5258{
5259 return decode_op_hdr(xdr, OP_SAVEFH);
5260}
5261
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005262static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263{
Al Viro8687b632006-10-19 23:28:48 -07005264 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265 uint32_t bmlen;
5266 int status;
5267
Linus Torvalds1da177e2005-04-16 15:20:36 -07005268 status = decode_op_hdr(xdr, OP_SETATTR);
5269 if (status)
5270 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005271 p = xdr_inline_decode(xdr, 4);
5272 if (unlikely(!p))
5273 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005274 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005275 p = xdr_inline_decode(xdr, bmlen << 2);
5276 if (likely(p))
5277 return 0;
5278out_overflow:
5279 print_overflow_msg(__func__, xdr);
5280 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005281}
5282
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005283static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284{
Al Viro8687b632006-10-19 23:28:48 -07005285 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286 uint32_t opnum;
5287 int32_t nfserr;
5288
Benny Halevyc0eae662009-08-14 17:20:14 +03005289 p = xdr_inline_decode(xdr, 8);
5290 if (unlikely(!p))
5291 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005292 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005294 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005295 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296 return -EIO;
5297 }
Benny Halevycccddf42009-08-14 17:20:19 +03005298 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005300 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5301 if (unlikely(!p))
5302 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005303 p = xdr_decode_hyper(p, &res->clientid);
5304 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005305 } else if (nfserr == NFSERR_CLID_INUSE) {
5306 uint32_t len;
5307
5308 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005309 p = xdr_inline_decode(xdr, 4);
5310 if (unlikely(!p))
5311 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005312 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005313 p = xdr_inline_decode(xdr, len);
5314 if (unlikely(!p))
5315 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316
5317 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005318 p = xdr_inline_decode(xdr, 4);
5319 if (unlikely(!p))
5320 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005321 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005322 p = xdr_inline_decode(xdr, len);
5323 if (unlikely(!p))
5324 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325 return -NFSERR_CLID_INUSE;
5326 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005327 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005328
5329 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005330out_overflow:
5331 print_overflow_msg(__func__, xdr);
5332 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333}
5334
5335static int decode_setclientid_confirm(struct xdr_stream *xdr)
5336{
5337 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5338}
5339
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005340static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005341{
Al Viro8687b632006-10-19 23:28:48 -07005342 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343 int status;
5344
5345 status = decode_op_hdr(xdr, OP_WRITE);
5346 if (status)
5347 return status;
5348
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005349 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005350 if (unlikely(!p))
5351 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005352 res->count = be32_to_cpup(p++);
5353 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005354 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005355out_overflow:
5356 print_overflow_msg(__func__, xdr);
5357 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358}
5359
5360static int decode_delegreturn(struct xdr_stream *xdr)
5361{
5362 return decode_op_hdr(xdr, OP_DELEGRETURN);
5363}
5364
Chuck Leverfb15b262013-03-16 15:54:34 -04005365static int decode_secinfo_gss(struct xdr_stream *xdr,
5366 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005367{
Chuck Leverfb15b262013-03-16 15:54:34 -04005368 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005369 __be32 *p;
5370
5371 p = xdr_inline_decode(xdr, 4);
5372 if (unlikely(!p))
5373 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005374 oid_len = be32_to_cpup(p);
5375 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005376 goto out_err;
5377
Chuck Leverfb15b262013-03-16 15:54:34 -04005378 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005379 if (unlikely(!p))
5380 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005381 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5382 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005383
5384 p = xdr_inline_decode(xdr, 8);
5385 if (unlikely(!p))
5386 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005387 flavor->flavor_info.qop = be32_to_cpup(p++);
5388 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005389
5390 return 0;
5391
5392out_overflow:
5393 print_overflow_msg(__func__, xdr);
5394 return -EIO;
5395out_err:
5396 return -EINVAL;
5397}
5398
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005399static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005400{
Chuck Leverfb15b262013-03-16 15:54:34 -04005401 struct nfs4_secinfo4 *sec_flavor;
5402 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005403 int status;
5404 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005405
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005406 p = xdr_inline_decode(xdr, 4);
5407 if (unlikely(!p))
5408 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005409
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005410 res->flavors->num_flavors = 0;
5411 num_flavors = be32_to_cpup(p);
5412
5413 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005414 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005415 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005416 break;
5417
5418 p = xdr_inline_decode(xdr, 4);
5419 if (unlikely(!p))
5420 goto out_overflow;
5421 sec_flavor->flavor = be32_to_cpup(p);
5422
5423 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005424 status = decode_secinfo_gss(xdr, sec_flavor);
5425 if (status)
5426 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005427 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005428 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005429 }
5430
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005431 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005432out:
5433 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005434out_overflow:
5435 print_overflow_msg(__func__, xdr);
5436 return -EIO;
5437}
5438
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005439static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5440{
5441 int status = decode_op_hdr(xdr, OP_SECINFO);
5442 if (status)
5443 return status;
5444 return decode_secinfo_common(xdr, res);
5445}
5446
Benny Halevy99fe60d2009-04-01 09:22:29 -04005447#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005448static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5449{
5450 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5451 if (status)
5452 return status;
5453 return decode_secinfo_common(xdr, res);
5454}
5455
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005456static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5457{
5458 __be32 *p;
5459 uint32_t bitmap_words;
5460 unsigned int i;
5461
5462 p = xdr_inline_decode(xdr, 4);
5463 bitmap_words = be32_to_cpup(p++);
5464 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5465 return -EIO;
5466 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5467 for (i = 0; i < bitmap_words; i++)
5468 op_map->u.words[i] = be32_to_cpup(p++);
5469
5470 return 0;
5471}
5472
Benny Halevy99fe60d2009-04-01 09:22:29 -04005473static int decode_exchange_id(struct xdr_stream *xdr,
5474 struct nfs41_exchange_id_res *res)
5475{
5476 __be32 *p;
5477 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005478 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005479 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005480 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005481
5482 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5483 if (status)
5484 return status;
5485
Benny Halevyc0eae662009-08-14 17:20:14 +03005486 p = xdr_inline_decode(xdr, 8);
5487 if (unlikely(!p))
5488 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005489 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005490 p = xdr_inline_decode(xdr, 12);
5491 if (unlikely(!p))
5492 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005493 res->seqid = be32_to_cpup(p++);
5494 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005495
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005496 res->state_protect.how = be32_to_cpup(p);
5497 switch (res->state_protect.how) {
5498 case SP4_NONE:
5499 break;
5500 case SP4_MACH_CRED:
5501 status = decode_op_map(xdr, &res->state_protect.enforce);
5502 if (status)
5503 return status;
5504 status = decode_op_map(xdr, &res->state_protect.allow);
5505 if (status)
5506 return status;
5507 break;
5508 default:
5509 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005510 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005511 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005512
Chuck Leveracdeb692012-05-21 22:46:16 -04005513 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005514 p = xdr_inline_decode(xdr, 8);
5515 if (unlikely(!p))
5516 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005517 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005518
Chuck Leveracdeb692012-05-21 22:46:16 -04005519 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005520 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5521 if (unlikely(status))
5522 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005523 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5524 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005525 memcpy(res->server_owner->major_id, dummy_str, dummy);
5526 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005527
Chuck Leveracdeb692012-05-21 22:46:16 -04005528 /* server_scope4 */
5529 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5530 if (unlikely(status))
5531 return status;
5532 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5533 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005534 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5535 res->server_scope->server_scope_sz = dummy;
5536
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005537 /* Implementation Id */
5538 p = xdr_inline_decode(xdr, 4);
5539 if (unlikely(!p))
5540 goto out_overflow;
5541 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005542
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005543 if (impl_id_count) {
5544 /* nii_domain */
5545 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5546 if (unlikely(status))
5547 return status;
5548 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5549 return -EIO;
5550 memcpy(res->impl_id->domain, dummy_str, dummy);
5551
5552 /* nii_name */
5553 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5554 if (unlikely(status))
5555 return status;
5556 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5557 return -EIO;
5558 memcpy(res->impl_id->name, dummy_str, dummy);
5559
5560 /* nii_date */
5561 p = xdr_inline_decode(xdr, 12);
5562 if (unlikely(!p))
5563 goto out_overflow;
5564 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5565 res->impl_id->date.nseconds = be32_to_cpup(p);
5566
5567 /* if there's more than one entry, ignore the rest */
5568 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005569 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005570out_overflow:
5571 print_overflow_msg(__func__, xdr);
5572 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005573}
Andy Adamsonfc931582009-04-01 09:22:31 -04005574
5575static int decode_chan_attrs(struct xdr_stream *xdr,
5576 struct nfs4_channel_attrs *attrs)
5577{
5578 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005579 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005580
Benny Halevyc0eae662009-08-14 17:20:14 +03005581 p = xdr_inline_decode(xdr, 28);
5582 if (unlikely(!p))
5583 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005584 val = be32_to_cpup(p++); /* headerpadsz */
5585 if (val)
5586 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005587 attrs->max_rqst_sz = be32_to_cpup(p++);
5588 attrs->max_resp_sz = be32_to_cpup(p++);
5589 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5590 attrs->max_ops = be32_to_cpup(p++);
5591 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005592 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005593 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005594 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5595 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005596 return -EINVAL;
5597 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005598 if (nr_attrs == 1) {
5599 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5600 if (unlikely(!p))
5601 goto out_overflow;
5602 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005603 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005604out_overflow:
5605 print_overflow_msg(__func__, xdr);
5606 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005607}
5608
Benny Halevye78291e2009-08-14 17:20:00 +03005609static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5610{
5611 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005612}
5613
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005614static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5615 struct nfs41_bind_conn_to_session_res *res)
5616{
5617 __be32 *p;
5618 int status;
5619
5620 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5621 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005622 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005623 if (unlikely(status))
5624 return status;
5625
5626 /* dir flags, rdma mode bool */
5627 p = xdr_inline_decode(xdr, 8);
5628 if (unlikely(!p))
5629 goto out_overflow;
5630
5631 res->dir = be32_to_cpup(p++);
5632 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5633 return -EIO;
5634 if (be32_to_cpup(p) == 0)
5635 res->use_conn_in_rdma_mode = false;
5636 else
5637 res->use_conn_in_rdma_mode = true;
5638
5639 return 0;
5640out_overflow:
5641 print_overflow_msg(__func__, xdr);
5642 return -EIO;
5643}
5644
Andy Adamsonfc931582009-04-01 09:22:31 -04005645static int decode_create_session(struct xdr_stream *xdr,
5646 struct nfs41_create_session_res *res)
5647{
5648 __be32 *p;
5649 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005650
5651 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005652 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005653 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005654 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005655 return status;
5656
Andy Adamsonfc931582009-04-01 09:22:31 -04005657 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005658 p = xdr_inline_decode(xdr, 8);
5659 if (unlikely(!p))
5660 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005661 res->seqid = be32_to_cpup(p++);
5662 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005663
5664 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005665 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005666 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005667 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005668 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005669out_overflow:
5670 print_overflow_msg(__func__, xdr);
5671 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005672}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005673
5674static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5675{
5676 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5677}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005678
Trond Myklebust66245532012-05-25 17:18:09 -04005679static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5680{
5681 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5682}
5683
Ricardo Labiaga180197532009-12-05 16:08:40 -05005684static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5685{
5686 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5687}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005688#endif /* CONFIG_NFS_V4_1 */
5689
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005690static int decode_sequence(struct xdr_stream *xdr,
5691 struct nfs4_sequence_res *res,
5692 struct rpc_rqst *rqstp)
5693{
5694#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005695 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005696 struct nfs4_sessionid id;
5697 u32 dummy;
5698 int status;
5699 __be32 *p;
5700
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005701 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005702 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005703 if (!res->sr_slot->table->session)
5704 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005705
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005706 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005707 if (!status)
5708 status = decode_sessionid(xdr, &id);
5709 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005710 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005711
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005712 /*
5713 * If the server returns different values for sessionID, slotID or
5714 * sequence number, the server is looney tunes.
5715 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005716 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005717 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005718
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005719 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005720 NFS4_MAX_SESSIONID_LEN)) {
5721 dprintk("%s Invalid session id\n", __func__);
5722 goto out_err;
5723 }
Benny Halevye78291e2009-08-14 17:20:00 +03005724
Benny Halevyc0eae662009-08-14 17:20:14 +03005725 p = xdr_inline_decode(xdr, 20);
5726 if (unlikely(!p))
5727 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005728
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005729 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005730 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005731 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005732 dprintk("%s Invalid sequence number\n", __func__);
5733 goto out_err;
5734 }
5735 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005736 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005737 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005738 dprintk("%s Invalid slot id\n", __func__);
5739 goto out_err;
5740 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005741 /* highest slot id */
5742 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005743 /* target highest slot id */
5744 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005745 /* result flags */
5746 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005747 status = 0;
5748out_err:
5749 res->sr_status = status;
5750 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005751out_overflow:
5752 print_overflow_msg(__func__, xdr);
5753 status = -EIO;
5754 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005755#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005756 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005757#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005758}
5759
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005760#if defined(CONFIG_NFS_V4_1)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005761static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005762 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005763{
Trond Myklebust4e590802015-03-09 14:01:25 -04005764 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005765 __be32 *p;
5766 uint32_t len, type;
5767 int status;
5768
5769 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5770 if (status) {
5771 if (status == -ETOOSMALL) {
5772 p = xdr_inline_decode(xdr, 4);
5773 if (unlikely(!p))
5774 goto out_overflow;
5775 pdev->mincount = be32_to_cpup(p);
5776 dprintk("%s: Min count too small. mincnt = %u\n",
5777 __func__, pdev->mincount);
5778 }
5779 return status;
5780 }
5781
5782 p = xdr_inline_decode(xdr, 8);
5783 if (unlikely(!p))
5784 goto out_overflow;
5785 type = be32_to_cpup(p++);
5786 if (type != pdev->layout_type) {
5787 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5788 __func__, pdev->layout_type, type);
5789 return -EINVAL;
5790 }
5791 /*
5792 * Get the length of the opaque device_addr4. xdr_read_pages places
5793 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5794 * and places the remaining xdr data in xdr_buf->tail
5795 */
5796 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005797 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5798 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005799
5800 /* Parse notification bitmap, verifying that it is zero. */
5801 p = xdr_inline_decode(xdr, 4);
5802 if (unlikely(!p))
5803 goto out_overflow;
5804 len = be32_to_cpup(p);
5805 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005806 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005807
5808 p = xdr_inline_decode(xdr, 4 * len);
5809 if (unlikely(!p))
5810 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005811
Trond Myklebust4e590802015-03-09 14:01:25 -04005812 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005813 for (i = 1; i < len; i++) {
5814 if (be32_to_cpup(p++)) {
5815 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005816 __func__);
5817 return -EIO;
5818 }
5819 }
5820 }
5821 return 0;
5822out_overflow:
5823 print_overflow_msg(__func__, xdr);
5824 return -EIO;
5825}
5826
5827static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5828 struct nfs4_layoutget_res *res)
5829{
5830 __be32 *p;
5831 int status;
5832 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005833 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005834
5835 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5836 if (status)
5837 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005838 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005839 if (unlikely(!p))
5840 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005841 res->return_on_close = be32_to_cpup(p);
5842 decode_stateid(xdr, &res->stateid);
5843 p = xdr_inline_decode(xdr, 4);
5844 if (unlikely(!p))
5845 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005846 layout_count = be32_to_cpup(p);
5847 if (!layout_count) {
5848 dprintk("%s: server responded with empty layout array\n",
5849 __func__);
5850 return -EINVAL;
5851 }
5852
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005853 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005854 if (unlikely(!p))
5855 goto out_overflow;
5856 p = xdr_decode_hyper(p, &res->range.offset);
5857 p = xdr_decode_hyper(p, &res->range.length);
5858 res->range.iomode = be32_to_cpup(p++);
5859 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005860 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005861
5862 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5863 __func__,
5864 (unsigned long)res->range.offset,
5865 (unsigned long)res->range.length,
5866 res->range.iomode,
5867 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005868 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005869
Trond Myklebust64bd5772012-06-20 22:35:05 -04005870 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005871 if (res->layoutp->len > recvd) {
5872 dprintk("NFS: server cheating in layoutget reply: "
5873 "layout len %u > recvd %u\n",
5874 res->layoutp->len, recvd);
5875 return -EINVAL;
5876 }
5877
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005878 if (layout_count > 1) {
5879 /* We only handle a length one array at the moment. Any
5880 * further entries are just ignored. Note that this means
5881 * the client may see a response that is less than the
5882 * minimum it requested.
5883 */
5884 dprintk("%s: server responded with %d layouts, dropping tail\n",
5885 __func__, layout_count);
5886 }
5887
5888 return 0;
5889out_overflow:
5890 print_overflow_msg(__func__, xdr);
5891 return -EIO;
5892}
Andy Adamson863a3c62011-03-23 13:27:54 +00005893
Benny Halevycbe82602011-05-22 19:52:37 +03005894static int decode_layoutreturn(struct xdr_stream *xdr,
5895 struct nfs4_layoutreturn_res *res)
5896{
5897 __be32 *p;
5898 int status;
5899
5900 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5901 if (status)
5902 return status;
5903 p = xdr_inline_decode(xdr, 4);
5904 if (unlikely(!p))
5905 goto out_overflow;
5906 res->lrs_present = be32_to_cpup(p);
5907 if (res->lrs_present)
5908 status = decode_stateid(xdr, &res->stateid);
5909 return status;
5910out_overflow:
5911 print_overflow_msg(__func__, xdr);
5912 return -EIO;
5913}
5914
Andy Adamson863a3c62011-03-23 13:27:54 +00005915static int decode_layoutcommit(struct xdr_stream *xdr,
5916 struct rpc_rqst *req,
5917 struct nfs4_layoutcommit_res *res)
5918{
5919 __be32 *p;
5920 __u32 sizechanged;
5921 int status;
5922
5923 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005924 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005925 if (status)
5926 return status;
5927
5928 p = xdr_inline_decode(xdr, 4);
5929 if (unlikely(!p))
5930 goto out_overflow;
5931 sizechanged = be32_to_cpup(p);
5932
5933 if (sizechanged) {
5934 /* throw away new size */
5935 p = xdr_inline_decode(xdr, 8);
5936 if (unlikely(!p))
5937 goto out_overflow;
5938 }
5939 return 0;
5940out_overflow:
5941 print_overflow_msg(__func__, xdr);
5942 return -EIO;
5943}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005944
5945static int decode_test_stateid(struct xdr_stream *xdr,
5946 struct nfs41_test_stateid_res *res)
5947{
5948 __be32 *p;
5949 int status;
5950 int num_res;
5951
5952 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5953 if (status)
5954 return status;
5955
5956 p = xdr_inline_decode(xdr, 4);
5957 if (unlikely(!p))
5958 goto out_overflow;
5959 num_res = be32_to_cpup(p++);
5960 if (num_res != 1)
5961 goto out;
5962
5963 p = xdr_inline_decode(xdr, 4);
5964 if (unlikely(!p))
5965 goto out_overflow;
5966 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005967
5968 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005969out_overflow:
5970 print_overflow_msg(__func__, xdr);
5971out:
5972 return -EIO;
5973}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005974
5975static int decode_free_stateid(struct xdr_stream *xdr,
5976 struct nfs41_free_stateid_res *res)
5977{
Andy Adamson9f79fb42013-09-10 12:56:29 -04005978 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005979 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005980}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005981#endif /* CONFIG_NFS_V4_1 */
5982
Linus Torvalds1da177e2005-04-16 15:20:36 -07005983/*
Benny Halevy49c25592008-12-23 16:06:16 -05005984 * END OF "GENERIC" DECODE ROUTINES.
5985 */
5986
5987/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005988 * Decode OPEN_DOWNGRADE response
5989 */
Chuck Leverbf269552010-12-14 14:59:29 +00005990static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5991 struct xdr_stream *xdr,
5992 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005993{
Andy Adamson05d564f2008-12-23 16:06:15 -05005994 struct compound_hdr hdr;
5995 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005996
Chuck Leverbf269552010-12-14 14:59:29 +00005997 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005998 if (status)
5999 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006000 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006001 if (status)
6002 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006003 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006004 if (status)
6005 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006006 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006007 if (status != 0)
6008 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006009 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006011 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012}
6013
6014/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015 * Decode ACCESS response
6016 */
Chuck Leverbf269552010-12-14 14:59:29 +00006017static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6018 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020 struct compound_hdr hdr;
6021 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006022
Chuck Leverbf269552010-12-14 14:59:29 +00006023 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006024 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)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006028 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006029 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006030 if (status != 0)
6031 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006032 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -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:
6037 return status;
6038}
6039
6040/*
6041 * Decode LOOKUP response
6042 */
Chuck Leverbf269552010-12-14 14:59:29 +00006043static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6044 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006045{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046 struct compound_hdr hdr;
6047 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006048
Chuck Leverbf269552010-12-14 14:59:29 +00006049 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006050 if (status)
6051 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006052 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006053 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006055 status = decode_putfh(xdr);
6056 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006057 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006058 status = decode_lookup(xdr);
6059 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006061 status = decode_getfh(xdr, res->fh);
6062 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006063 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006064 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065out:
6066 return status;
6067}
6068
6069/*
6070 * Decode LOOKUP_ROOT response
6071 */
Chuck Leverbf269552010-12-14 14:59:29 +00006072static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6073 struct xdr_stream *xdr,
6074 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006075{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006076 struct compound_hdr hdr;
6077 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006078
Chuck Leverbf269552010-12-14 14:59:29 +00006079 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006080 if (status)
6081 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006082 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006083 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006084 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006085 status = decode_putrootfh(xdr);
6086 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006087 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_getfh(xdr, res->fh);
6089 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006090 status = decode_getfattr_label(xdr, res->fattr,
6091 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092out:
6093 return status;
6094}
6095
6096/*
6097 * Decode REMOVE response
6098 */
Chuck Leverbf269552010-12-14 14:59:29 +00006099static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6100 struct nfs_removeres *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_putfh(xdr);
6112 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006113 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006114 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006115out:
6116 return status;
6117}
6118
6119/*
6120 * Decode RENAME response
6121 */
Chuck Leverbf269552010-12-14 14:59:29 +00006122static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6123 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006124{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125 struct compound_hdr hdr;
6126 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006127
Chuck Leverbf269552010-12-14 14:59:29 +00006128 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006129 if (status)
6130 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006131 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006132 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006134 status = decode_putfh(xdr);
6135 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006136 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_savefh(xdr);
6138 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006140 status = decode_putfh(xdr);
6141 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006142 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006143 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006144out:
6145 return status;
6146}
6147
6148/*
6149 * Decode LINK response
6150 */
Chuck Leverbf269552010-12-14 14:59:29 +00006151static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6152 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006153{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006154 struct compound_hdr hdr;
6155 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006156
Chuck Leverbf269552010-12-14 14:59:29 +00006157 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006158 if (status)
6159 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006160 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006161 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006163 status = decode_putfh(xdr);
6164 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006166 status = decode_savefh(xdr);
6167 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_putfh(xdr);
6170 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006172 status = decode_link(xdr, &res->cinfo);
6173 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006174 goto out;
6175 /*
6176 * Note order: OP_LINK leaves the directory as the current
6177 * filehandle.
6178 */
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_restorefh(xdr);
6180 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006181 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006182 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183out:
6184 return status;
6185}
6186
6187/*
6188 * Decode CREATE response
6189 */
Chuck Leverbf269552010-12-14 14:59:29 +00006190static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6191 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193 struct compound_hdr hdr;
6194 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006195
Chuck Leverbf269552010-12-14 14:59:29 +00006196 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006197 if (status)
6198 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006199 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006200 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006202 status = decode_putfh(xdr);
6203 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006205 status = decode_create(xdr, &res->dir_cinfo);
6206 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006208 status = decode_getfh(xdr, res->fh);
6209 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006211 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212out:
6213 return status;
6214}
6215
6216/*
6217 * Decode SYMLINK response
6218 */
Chuck Leverbf269552010-12-14 14:59:29 +00006219static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6220 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221{
Chuck Leverbf269552010-12-14 14:59:29 +00006222 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006223}
6224
6225/*
6226 * Decode GETATTR response
6227 */
Chuck Leverbf269552010-12-14 14:59:29 +00006228static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6229 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006231 struct compound_hdr hdr;
6232 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006233
Chuck Leverbf269552010-12-14 14:59:29 +00006234 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235 if (status)
6236 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006237 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006238 if (status)
6239 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006240 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241 if (status)
6242 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006243 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006244out:
6245 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246}
6247
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006248/*
6249 * Encode an SETACL request
6250 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006251static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6252 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006253{
Andy Adamson05d564f2008-12-23 16:06:15 -05006254 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006255 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006256 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006257
Chuck Lever9f06c712010-12-14 14:59:18 +00006258 encode_compound_hdr(xdr, req, &hdr);
6259 encode_sequence(xdr, &args->seq_args, &hdr);
6260 encode_putfh(xdr, args->fh, &hdr);
6261 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006262 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006263}
Andy Adamson05d564f2008-12-23 16:06:15 -05006264
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006265/*
6266 * Decode SETACL response
6267 */
6268static int
Chuck Leverbf269552010-12-14 14:59:29 +00006269nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006270 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006271{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006272 struct compound_hdr hdr;
6273 int status;
6274
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006276 if (status)
6277 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006278 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006279 if (status)
6280 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006281 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006282 if (status)
6283 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006285out:
6286 return status;
6287}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006288
6289/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006290 * Decode GETACL response
6291 */
6292static int
Chuck Leverbf269552010-12-14 14:59:29 +00006293nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006294 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006295{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006296 struct compound_hdr hdr;
6297 int status;
6298
Trond Myklebust331818f2012-02-03 18:30:53 -05006299 if (res->acl_scratch != NULL) {
6300 void *p = page_address(res->acl_scratch);
6301 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6302 }
Chuck Leverbf269552010-12-14 14:59:29 +00006303 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006304 if (status)
6305 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006306 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006307 if (status)
6308 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006309 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006310 if (status)
6311 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006312 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006313
6314out:
6315 return status;
6316}
6317
6318/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319 * Decode CLOSE response
6320 */
Chuck Leverbf269552010-12-14 14:59:29 +00006321static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6322 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323{
Andy Adamson05d564f2008-12-23 16:06:15 -05006324 struct compound_hdr hdr;
6325 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006326
Chuck Leverbf269552010-12-14 14:59:29 +00006327 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006328 if (status)
6329 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006330 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006331 if (status)
6332 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006333 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006334 if (status)
6335 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006336 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006337 if (status != 0)
6338 goto out;
6339 /*
6340 * Note: Server may do delete on close for this file
6341 * in which case the getattr call will fail with
6342 * an ESTALE error. Shouldn't be a problem,
6343 * though, since fattr->valid will remain unset.
6344 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006345 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006346out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006347 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348}
6349
6350/*
6351 * Decode OPEN response
6352 */
Chuck Leverbf269552010-12-14 14:59:29 +00006353static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6354 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355{
Andy Adamson05d564f2008-12-23 16:06:15 -05006356 struct compound_hdr hdr;
6357 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358
Chuck Leverbf269552010-12-14 14:59:29 +00006359 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006360 if (status)
6361 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006362 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006363 if (status)
6364 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006365 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006366 if (status)
6367 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006369 if (status)
6370 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006371 status = decode_getfh(xdr, &res->fh);
6372 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006374 if (res->access_request)
6375 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006376 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006378 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006379}
6380
6381/*
6382 * Decode OPEN_CONFIRM response
6383 */
Chuck Leverbf269552010-12-14 14:59:29 +00006384static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6385 struct xdr_stream *xdr,
6386 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387{
Andy Adamson05d564f2008-12-23 16:06:15 -05006388 struct compound_hdr hdr;
6389 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006390
Chuck Leverbf269552010-12-14 14:59:29 +00006391 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006392 if (status)
6393 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006394 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006395 if (status)
6396 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006397 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006399 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400}
6401
6402/*
6403 * Decode OPEN response
6404 */
Chuck Leverbf269552010-12-14 14:59:29 +00006405static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6406 struct xdr_stream *xdr,
6407 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408{
Andy Adamson05d564f2008-12-23 16:06:15 -05006409 struct compound_hdr hdr;
6410 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411
Chuck Leverbf269552010-12-14 14:59:29 +00006412 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006413 if (status)
6414 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006415 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006416 if (status)
6417 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006418 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006419 if (status)
6420 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006421 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006422 if (status)
6423 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006424 if (res->access_request)
6425 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006426 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006428 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429}
6430
6431/*
6432 * Decode SETATTR response
6433 */
Chuck Leverbf269552010-12-14 14:59:29 +00006434static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6435 struct xdr_stream *xdr,
6436 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437{
Andy Adamson05d564f2008-12-23 16:06:15 -05006438 struct compound_hdr hdr;
6439 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440
Chuck Leverbf269552010-12-14 14:59:29 +00006441 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006442 if (status)
6443 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006444 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006445 if (status)
6446 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006448 if (status)
6449 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006450 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006451 if (status)
6452 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006453 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006455 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456}
6457
6458/*
6459 * Decode LOCK response
6460 */
Chuck Leverbf269552010-12-14 14:59:29 +00006461static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6462 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464 struct compound_hdr hdr;
6465 int status;
6466
Chuck Leverbf269552010-12-14 14:59:29 +00006467 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006474 if (status)
6475 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006476 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477out:
6478 return status;
6479}
6480
6481/*
6482 * Decode LOCKT response
6483 */
Chuck Leverbf269552010-12-14 14:59:29 +00006484static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6485 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487 struct compound_hdr hdr;
6488 int status;
6489
Chuck Leverbf269552010-12-14 14:59:29 +00006490 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 if (status)
6492 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006493 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006494 if (status)
6495 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006496 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497 if (status)
6498 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006499 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006500out:
6501 return status;
6502}
6503
6504/*
6505 * Decode LOCKU response
6506 */
Chuck Leverbf269552010-12-14 14:59:29 +00006507static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6508 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006509{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510 struct compound_hdr hdr;
6511 int status;
6512
Chuck Leverbf269552010-12-14 14:59:29 +00006513 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006514 if (status)
6515 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006516 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006517 if (status)
6518 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006519 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520 if (status)
6521 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006522 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006523out:
6524 return status;
6525}
6526
Chuck Leverbf269552010-12-14 14:59:29 +00006527static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6528 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006529{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006530 struct compound_hdr hdr;
6531 int status;
6532
Chuck Leverbf269552010-12-14 14:59:29 +00006533 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006534 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006536 return status;
6537}
6538
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539/*
6540 * Decode READLINK response
6541 */
Chuck Leverbf269552010-12-14 14:59:29 +00006542static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6543 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006544 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006546 struct compound_hdr hdr;
6547 int status;
6548
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550 if (status)
6551 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006552 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006553 if (status)
6554 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556 if (status)
6557 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559out:
6560 return status;
6561}
6562
6563/*
6564 * Decode READDIR response
6565 */
Chuck Leverbf269552010-12-14 14:59:29 +00006566static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6567 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569 struct compound_hdr hdr;
6570 int status;
6571
Chuck Leverbf269552010-12-14 14:59:29 +00006572 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573 if (status)
6574 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006575 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006576 if (status)
6577 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006578 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579 if (status)
6580 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006581 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006582out:
6583 return status;
6584}
6585
6586/*
6587 * Decode Read response
6588 */
Chuck Leverbf269552010-12-14 14:59:29 +00006589static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006590 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006591{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006592 struct compound_hdr hdr;
6593 int status;
6594
Chuck Leverbf269552010-12-14 14:59:29 +00006595 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006596 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597 if (status)
6598 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006599 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006600 if (status)
6601 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006602 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006603 if (status)
6604 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006605 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 if (!status)
6607 status = res->count;
6608out:
6609 return status;
6610}
6611
6612/*
6613 * Decode WRITE response
6614 */
Chuck Leverbf269552010-12-14 14:59:29 +00006615static int nfs4_xdr_dec_write(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_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006632 if (status)
6633 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006634 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006635 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636 if (!status)
6637 status = res->count;
6638out:
6639 return status;
6640}
6641
6642/*
6643 * Decode COMMIT response
6644 */
Chuck Leverbf269552010-12-14 14:59:29 +00006645static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006646 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006648 struct compound_hdr hdr;
6649 int status;
6650
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006652 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 if (status)
6654 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006655 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006656 if (status)
6657 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006658 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659 if (status)
6660 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006661 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006662out:
6663 return status;
6664}
6665
6666/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006667 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006668 */
Chuck Leverbf269552010-12-14 14:59:29 +00006669static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006670 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006671{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672 struct compound_hdr hdr;
6673 int status;
6674
Chuck Leverbf269552010-12-14 14:59:29 +00006675 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006676 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006677 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006678 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006679 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006681 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006682 return status;
6683}
6684
6685/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006686 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006687 */
Chuck Leverbf269552010-12-14 14:59:29 +00006688static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006689 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006690{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006691 struct compound_hdr hdr;
6692 int status;
6693
Chuck Leverbf269552010-12-14 14:59:29 +00006694 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006695 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006696 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006697 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006698 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006700 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006701 return status;
6702}
6703
6704/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006705 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006706 */
Chuck Leverbf269552010-12-14 14:59:29 +00006707static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006708 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006709{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006710 struct compound_hdr hdr;
6711 int status;
6712
Chuck Leverbf269552010-12-14 14:59:29 +00006713 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006714 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006715 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006716 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006717 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006718 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006719 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006720 return status;
6721}
6722
6723/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006724 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006725 */
Chuck Leverbf269552010-12-14 14:59:29 +00006726static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6727 struct xdr_stream *xdr,
6728 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006729{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006730 struct compound_hdr hdr;
6731 int status;
6732
Chuck Leverbf269552010-12-14 14:59:29 +00006733 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006734 if (status)
6735 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006736 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006737 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006738 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006739 status = decode_putfh(xdr);
6740 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006741 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006742 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006743out:
6744 return status;
6745}
6746
6747/*
6748 * Decode RENEW response
6749 */
Chuck Leverbf269552010-12-14 14:59:29 +00006750static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6751 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006752{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753 struct compound_hdr hdr;
6754 int status;
6755
Chuck Leverbf269552010-12-14 14:59:29 +00006756 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006758 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759 return status;
6760}
6761
6762/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006763 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006764 */
Chuck Leverbf269552010-12-14 14:59:29 +00006765static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6766 struct xdr_stream *xdr,
6767 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006769 struct compound_hdr hdr;
6770 int status;
6771
Chuck Leverbf269552010-12-14 14:59:29 +00006772 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006773 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006774 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006775 return status;
6776}
6777
6778/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006779 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006780 */
Chuck Leverbf269552010-12-14 14:59:29 +00006781static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006782 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006783{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006784 struct compound_hdr hdr;
6785 int status;
6786
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006788 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006789 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006790 return status;
6791}
6792
6793/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006794 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006795 */
Chuck Leverbf269552010-12-14 14:59:29 +00006796static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6797 struct xdr_stream *xdr,
6798 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006799{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006800 struct compound_hdr hdr;
6801 int status;
6802
Chuck Leverbf269552010-12-14 14:59:29 +00006803 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006804 if (status)
6805 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006806 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006807 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006808 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006809 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006810 if (status != 0)
6811 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006812 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006813 if (status != 0)
6814 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006815 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006816out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006817 return status;
6818}
6819
Trond Myklebust683b57b2006-06-09 09:34:22 -04006820/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006821 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006822 */
Chuck Leverbf269552010-12-14 14:59:29 +00006823static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6824 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006825 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006826{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006827 struct compound_hdr hdr;
6828 int status;
6829
Chuck Leverbf269552010-12-14 14:59:29 +00006830 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006831 if (status)
6832 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006833 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006834 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006835 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006836 status = decode_putfh(xdr);
6837 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006838 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006839 if (res->migration) {
6840 xdr_enter_page(xdr, PAGE_SIZE);
6841 status = decode_getfattr_generic(xdr,
6842 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006843 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006844 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006845 if (status)
6846 goto out;
6847 if (res->renew)
6848 status = decode_renew(xdr);
6849 } else {
6850 status = decode_lookup(xdr);
6851 if (status)
6852 goto out;
6853 xdr_enter_page(xdr, PAGE_SIZE);
6854 status = decode_getfattr_generic(xdr,
6855 &res->fs_locations->fattr,
6856 NULL, res->fs_locations,
6857 NULL, res->fs_locations->server);
6858 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006859out:
6860 return status;
6861}
6862
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006863/*
6864 * Decode SECINFO response
6865 */
6866static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6867 struct xdr_stream *xdr,
6868 struct nfs4_secinfo_res *res)
6869{
6870 struct compound_hdr hdr;
6871 int status;
6872
6873 status = decode_compound_hdr(xdr, &hdr);
6874 if (status)
6875 goto out;
6876 status = decode_sequence(xdr, &res->seq_res, rqstp);
6877 if (status)
6878 goto out;
6879 status = decode_putfh(xdr);
6880 if (status)
6881 goto out;
6882 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006883out:
6884 return status;
6885}
6886
Chuck Lever44c99932013-10-17 14:13:30 -04006887/*
6888 * Decode FSID_PRESENT response
6889 */
6890static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6891 struct xdr_stream *xdr,
6892 struct nfs4_fsid_present_res *res)
6893{
6894 struct compound_hdr hdr;
6895 int status;
6896
6897 status = decode_compound_hdr(xdr, &hdr);
6898 if (status)
6899 goto out;
6900 status = decode_sequence(xdr, &res->seq_res, rqstp);
6901 if (status)
6902 goto out;
6903 status = decode_putfh(xdr);
6904 if (status)
6905 goto out;
6906 status = decode_getfh(xdr, res->fh);
6907 if (status)
6908 goto out;
6909 if (res->renew)
6910 status = decode_renew(xdr);
6911out:
6912 return status;
6913}
6914
Benny Halevy99fe60d2009-04-01 09:22:29 -04006915#if defined(CONFIG_NFS_V4_1)
6916/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006917 * Decode BIND_CONN_TO_SESSION response
6918 */
6919static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6920 struct xdr_stream *xdr,
6921 void *res)
6922{
6923 struct compound_hdr hdr;
6924 int status;
6925
6926 status = decode_compound_hdr(xdr, &hdr);
6927 if (!status)
6928 status = decode_bind_conn_to_session(xdr, res);
6929 return status;
6930}
6931
6932/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006933 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006934 */
Chuck Leverbf269552010-12-14 14:59:29 +00006935static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6936 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006937 void *res)
6938{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006939 struct compound_hdr hdr;
6940 int status;
6941
Chuck Leverbf269552010-12-14 14:59:29 +00006942 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006943 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006944 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006945 return status;
6946}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006947
6948/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006949 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006950 */
Chuck Leverbf269552010-12-14 14:59:29 +00006951static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6952 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006953 struct nfs41_create_session_res *res)
6954{
Andy Adamsonfc931582009-04-01 09:22:31 -04006955 struct compound_hdr hdr;
6956 int status;
6957
Chuck Leverbf269552010-12-14 14:59:29 +00006958 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006959 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006960 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006961 return status;
6962}
6963
6964/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006965 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006966 */
Chuck Leverbf269552010-12-14 14:59:29 +00006967static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6968 struct xdr_stream *xdr,
6969 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006970{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006971 struct compound_hdr hdr;
6972 int status;
6973
Chuck Leverbf269552010-12-14 14:59:29 +00006974 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006975 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006976 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006977 return status;
6978}
6979
6980/*
Trond Myklebust66245532012-05-25 17:18:09 -04006981 * Decode DESTROY_CLIENTID response
6982 */
6983static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6984 struct xdr_stream *xdr,
6985 void *res)
6986{
6987 struct compound_hdr hdr;
6988 int status;
6989
6990 status = decode_compound_hdr(xdr, &hdr);
6991 if (!status)
6992 status = decode_destroy_clientid(xdr, res);
6993 return status;
6994}
6995
6996/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006997 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006998 */
Chuck Leverbf269552010-12-14 14:59:29 +00006999static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7000 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007001 struct nfs4_sequence_res *res)
7002{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007003 struct compound_hdr hdr;
7004 int status;
7005
Chuck Leverbf269552010-12-14 14:59:29 +00007006 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007007 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007008 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007009 return status;
7010}
7011
7012/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007013 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007014 */
Chuck Leverbf269552010-12-14 14:59:29 +00007015static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7016 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007017 struct nfs4_get_lease_time_res *res)
7018{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007019 struct compound_hdr hdr;
7020 int status;
7021
Chuck Leverbf269552010-12-14 14:59:29 +00007022 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007023 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007024 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007025 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007026 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007027 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007028 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007029 return status;
7030}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007031
7032/*
7033 * Decode RECLAIM_COMPLETE response
7034 */
Chuck Leverbf269552010-12-14 14:59:29 +00007035static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7036 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007037 struct nfs41_reclaim_complete_res *res)
7038{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007039 struct compound_hdr hdr;
7040 int status;
7041
Chuck Leverbf269552010-12-14 14:59:29 +00007042 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007043 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007044 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007045 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307046 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007047 return status;
7048}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007049
7050/*
7051 * Decode GETDEVINFO response
7052 */
Chuck Leverbf269552010-12-14 14:59:29 +00007053static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7054 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007055 struct nfs4_getdeviceinfo_res *res)
7056{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007057 struct compound_hdr hdr;
7058 int status;
7059
Chuck Leverbf269552010-12-14 14:59:29 +00007060 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007061 if (status != 0)
7062 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007063 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007064 if (status != 0)
7065 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007066 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007067out:
7068 return status;
7069}
7070
7071/*
7072 * Decode LAYOUTGET response
7073 */
Chuck Leverbf269552010-12-14 14:59:29 +00007074static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7075 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007076 struct nfs4_layoutget_res *res)
7077{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007078 struct compound_hdr hdr;
7079 int status;
7080
Chuck Leverbf269552010-12-14 14:59:29 +00007081 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007082 if (status)
7083 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007084 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007085 if (status)
7086 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007087 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007088 if (status)
7089 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007090 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007091out:
7092 return status;
7093}
Andy Adamson863a3c62011-03-23 13:27:54 +00007094
7095/*
Benny Halevycbe82602011-05-22 19:52:37 +03007096 * Decode LAYOUTRETURN response
7097 */
7098static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7099 struct xdr_stream *xdr,
7100 struct nfs4_layoutreturn_res *res)
7101{
7102 struct compound_hdr hdr;
7103 int status;
7104
7105 status = decode_compound_hdr(xdr, &hdr);
7106 if (status)
7107 goto out;
7108 status = decode_sequence(xdr, &res->seq_res, rqstp);
7109 if (status)
7110 goto out;
7111 status = decode_putfh(xdr);
7112 if (status)
7113 goto out;
7114 status = decode_layoutreturn(xdr, res);
7115out:
7116 return status;
7117}
7118
7119/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007120 * Decode LAYOUTCOMMIT response
7121 */
7122static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7123 struct xdr_stream *xdr,
7124 struct nfs4_layoutcommit_res *res)
7125{
7126 struct compound_hdr hdr;
7127 int status;
7128
7129 status = decode_compound_hdr(xdr, &hdr);
7130 if (status)
7131 goto out;
7132 status = decode_sequence(xdr, &res->seq_res, rqstp);
7133 if (status)
7134 goto out;
7135 status = decode_putfh(xdr);
7136 if (status)
7137 goto out;
7138 status = decode_layoutcommit(xdr, rqstp, res);
7139 if (status)
7140 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007141 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007142out:
7143 return status;
7144}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007145
7146/*
7147 * Decode SECINFO_NO_NAME response
7148 */
7149static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7150 struct xdr_stream *xdr,
7151 struct nfs4_secinfo_res *res)
7152{
7153 struct compound_hdr hdr;
7154 int status;
7155
7156 status = decode_compound_hdr(xdr, &hdr);
7157 if (status)
7158 goto out;
7159 status = decode_sequence(xdr, &res->seq_res, rqstp);
7160 if (status)
7161 goto out;
7162 status = decode_putrootfh(xdr);
7163 if (status)
7164 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007165 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007166out:
7167 return status;
7168}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007169
7170/*
7171 * Decode TEST_STATEID response
7172 */
7173static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7174 struct xdr_stream *xdr,
7175 struct nfs41_test_stateid_res *res)
7176{
7177 struct compound_hdr hdr;
7178 int status;
7179
7180 status = decode_compound_hdr(xdr, &hdr);
7181 if (status)
7182 goto out;
7183 status = decode_sequence(xdr, &res->seq_res, rqstp);
7184 if (status)
7185 goto out;
7186 status = decode_test_stateid(xdr, res);
7187out:
7188 return status;
7189}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007190
7191/*
7192 * Decode FREE_STATEID response
7193 */
7194static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7195 struct xdr_stream *xdr,
7196 struct nfs41_free_stateid_res *res)
7197{
7198 struct compound_hdr hdr;
7199 int status;
7200
7201 status = decode_compound_hdr(xdr, &hdr);
7202 if (status)
7203 goto out;
7204 status = decode_sequence(xdr, &res->seq_res, rqstp);
7205 if (status)
7206 goto out;
7207 status = decode_free_stateid(xdr, res);
7208out:
7209 return status;
7210}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007211#endif /* CONFIG_NFS_V4_1 */
7212
Chuck Lever573c4e12010-12-14 14:58:11 +00007213/**
7214 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7215 * the local page cache.
7216 * @xdr: XDR stream where entry resides
7217 * @entry: buffer to fill in with entry data
7218 * @plus: boolean indicating whether this should be a readdirplus entry
7219 *
7220 * Returns zero if successful, otherwise a negative errno value is
7221 * returned.
7222 *
7223 * This function is not invoked during READDIR reply decoding, but
7224 * rather whenever an application invokes the getdents(2) system call
7225 * on a directory already in our cache.
7226 */
7227int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7228 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007229{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007230 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007231 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007232 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007233 __be32 *p = xdr_inline_decode(xdr, 4);
7234 if (unlikely(!p))
7235 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007236 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007237 p = xdr_inline_decode(xdr, 4);
7238 if (unlikely(!p))
7239 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007240 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007241 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007242 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007243 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007244 }
7245
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007246 p = xdr_inline_decode(xdr, 12);
7247 if (unlikely(!p))
7248 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007249 entry->prev_cookie = entry->cookie;
7250 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007251 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007252
Trond Myklebust9af8c222010-10-24 11:52:55 -04007253 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007254 if (unlikely(!p))
7255 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007256 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007257
7258 /*
7259 * In case the server doesn't return an inode number,
7260 * we fake one here. (We don't use inode number 0,
7261 * since glibc seems to choke on it...)
7262 */
7263 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007264 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007265
Trond Myklebust9af8c222010-10-24 11:52:55 -04007266 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007267 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007268
Trond Myklebust256e48b2012-06-21 11:18:13 -04007269 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007270 goto out_overflow;
7271
Chuck Lever573c4e12010-12-14 14:58:11 +00007272 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007273 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007274 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007275 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7276 entry->ino = entry->fattr->mounted_on_fileid;
7277 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007278 entry->ino = entry->fattr->fileid;
7279
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007280 entry->d_type = DT_UNKNOWN;
7281 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7282 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7283
Chuck Lever573c4e12010-12-14 14:58:11 +00007284 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007285
7286out_overflow:
7287 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007288 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007289}
7290
7291/*
7292 * We need to translate between nfs status return values and
7293 * the local errno values which may not be the same.
7294 */
7295static struct {
7296 int stat;
7297 int errno;
7298} nfs_errtbl[] = {
7299 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007300 { NFS4ERR_PERM, -EPERM },
7301 { NFS4ERR_NOENT, -ENOENT },
7302 { NFS4ERR_IO, -errno_NFSERR_IO},
7303 { NFS4ERR_NXIO, -ENXIO },
7304 { NFS4ERR_ACCESS, -EACCES },
7305 { NFS4ERR_EXIST, -EEXIST },
7306 { NFS4ERR_XDEV, -EXDEV },
7307 { NFS4ERR_NOTDIR, -ENOTDIR },
7308 { NFS4ERR_ISDIR, -EISDIR },
7309 { NFS4ERR_INVAL, -EINVAL },
7310 { NFS4ERR_FBIG, -EFBIG },
7311 { NFS4ERR_NOSPC, -ENOSPC },
7312 { NFS4ERR_ROFS, -EROFS },
7313 { NFS4ERR_MLINK, -EMLINK },
7314 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7315 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7316 { NFS4ERR_DQUOT, -EDQUOT },
7317 { NFS4ERR_STALE, -ESTALE },
7318 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007319 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7320 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7321 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007322 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007323 { NFS4ERR_BADTYPE, -EBADTYPE },
7324 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007325 { NFS4ERR_SYMLINK, -ELOOP },
7326 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7327 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007328 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007329};
7330
7331/*
7332 * Convert an NFS error code to a local one.
7333 * This one is used jointly by NFSv2 and NFSv3.
7334 */
7335static int
David Howells0a8ea432006-08-22 20:06:08 -04007336nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007337{
7338 int i;
7339 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7340 if (nfs_errtbl[i].stat == stat)
7341 return nfs_errtbl[i].errno;
7342 }
7343 if (stat <= 10000 || stat > 10100) {
7344 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007345 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007346 }
7347 /* If we cannot translate the error, the recovery routines should
7348 * handle it.
7349 * Note: remaining NFSv4 error codes have values > 10000, so should
7350 * not conflict with native Linux error codes.
7351 */
Benny Halevy856dff32008-03-31 17:39:06 +03007352 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007353}
7354
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007355#ifdef CONFIG_NFS_V4_2
7356#include "nfs42xdr.c"
7357#endif /* CONFIG_NFS_V4_2 */
7358
Linus Torvalds1da177e2005-04-16 15:20:36 -07007359#define PROC(proc, argtype, restype) \
7360[NFSPROC4_CLNT_##proc] = { \
7361 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007362 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007363 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007364 .p_arglen = NFS4_##argtype##_sz, \
7365 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007366 .p_statidx = NFSPROC4_CLNT_##proc, \
7367 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007368}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007369
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007370#define STUB(proc) \
7371[NFSPROC4_CLNT_##proc] = { \
7372 .p_name = #proc, \
7373}
7374
Linus Torvalds1da177e2005-04-16 15:20:36 -07007375struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007376 PROC(READ, enc_read, dec_read),
7377 PROC(WRITE, enc_write, dec_write),
7378 PROC(COMMIT, enc_commit, dec_commit),
7379 PROC(OPEN, enc_open, dec_open),
7380 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7381 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7382 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7383 PROC(CLOSE, enc_close, dec_close),
7384 PROC(SETATTR, enc_setattr, dec_setattr),
7385 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7386 PROC(RENEW, enc_renew, dec_renew),
7387 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7388 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7389 PROC(LOCK, enc_lock, dec_lock),
7390 PROC(LOCKT, enc_lockt, dec_lockt),
7391 PROC(LOCKU, enc_locku, dec_locku),
7392 PROC(ACCESS, enc_access, dec_access),
7393 PROC(GETATTR, enc_getattr, dec_getattr),
7394 PROC(LOOKUP, enc_lookup, dec_lookup),
7395 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7396 PROC(REMOVE, enc_remove, dec_remove),
7397 PROC(RENAME, enc_rename, dec_rename),
7398 PROC(LINK, enc_link, dec_link),
7399 PROC(SYMLINK, enc_symlink, dec_symlink),
7400 PROC(CREATE, enc_create, dec_create),
7401 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7402 PROC(STATFS, enc_statfs, dec_statfs),
7403 PROC(READLINK, enc_readlink, dec_readlink),
7404 PROC(READDIR, enc_readdir, dec_readdir),
7405 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7406 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7407 PROC(GETACL, enc_getacl, dec_getacl),
7408 PROC(SETACL, enc_setacl, dec_setacl),
7409 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7410 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007411 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007412 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007413#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007414 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7415 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7416 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7417 PROC(SEQUENCE, enc_sequence, dec_sequence),
7418 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7419 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7420 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7421 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007422 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007423 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007424 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007425 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007426 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007427 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007428 PROC(BIND_CONN_TO_SESSION,
7429 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007430 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007431#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007432#ifdef CONFIG_NFS_V4_2
7433 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007434 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007435 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007436 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007437#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007438};
7439
Trond Myklebusta613fa12012-01-20 13:53:56 -05007440const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007441 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007442 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007443 .procs = nfs4_procedures
7444};
7445
7446/*
7447 * Local variables:
7448 * c-basic-offset: 8
7449 * End:
7450 */