blob: 8c21d69a9dc114c8781dc8ae3171f17f67fb4a8d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
Chuck Leverf0920752012-05-21 22:45:41 -040056
Trond Myklebust4ce79712005-06-22 17:16:21 +000057#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050058#include "internal.h"
Trond Myklebust76e697b2012-11-26 14:20:49 -050059#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040060#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040061#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#define NFSDBG_FACILITY NFSDBG_XDR
64
65/* Mapping from NFS error code to "errno" error code. */
66#define errno_NFSERR_IO EIO
67
David Howells0a8ea432006-08-22 20:06:08 -040068static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
71#ifdef DEBUG
72#define NFS4_MAXTAGLEN 20
73#else
74#define NFS4_MAXTAGLEN 0
75#endif
76
Andy Adamson6c0195a2008-12-23 16:06:15 -050077/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040078 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040080#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050081#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85#define op_encode_hdr_maxsz (1)
86#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040087#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
92 (NFS4_FHSIZE >> 2))
93#define decode_putfh_maxsz (op_decode_hdr_maxsz)
94#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96#define encode_getfh_maxsz (op_encode_hdr_maxsz)
97#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040099#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000100#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400103#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400105#ifdef CONFIG_NFS_V4_SECURITY_LABEL
106/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
David Quigleyaa9c2662013-05-22 12:50:44 -0400108#else
109#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400110#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400111/* We support only one layout type per file system */
112#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000113/* This is based on getfattr, which uses the most attributes: */
114#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400115 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400116 nfs4_group_maxsz + nfs4_label_maxsz + \
117 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000118#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
119 nfs4_fattr_value_maxsz)
120#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400121#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
122 1 + 2 + 1 + \
123 nfs4_owner_maxsz + \
124 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400125 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400126 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define encode_savefh_maxsz (op_encode_hdr_maxsz)
128#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400129#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
130#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200131#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400132/* The 5 accounts for the PNFS attributes, and assumes that at most three
133 * layout types will be returned.
134 */
135#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
136 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
138#define decode_renew_maxsz (op_decode_hdr_maxsz)
139#define encode_setclientid_maxsz \
140 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500141 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
142 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
143 1 /* sc_prog */ + \
144 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
145 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
146 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#define decode_setclientid_maxsz \
148 (op_decode_hdr_maxsz + \
149 2 + \
150 1024) /* large value for CLID_INUSE */
151#define encode_setclientid_confirm_maxsz \
152 (op_encode_hdr_maxsz + \
153 3 + (NFS4_VERIFIER_SIZE >> 2))
154#define decode_setclientid_confirm_maxsz \
155 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400156#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
157#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400158#define encode_share_access_maxsz \
159 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500160#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400161#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
162#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
163#define encode_open_maxsz (op_encode_hdr_maxsz + \
164 2 + encode_share_access_maxsz + 2 + \
165 open_owner_id_maxsz + \
166 encode_opentype_maxsz + \
167 encode_claim_null_maxsz)
168#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400169#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400170 decode_ace_maxsz)
171#define decode_change_info_maxsz (5)
172#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400173 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400174 decode_change_info_maxsz + 1 + \
175 nfs4_fattr_bitmap_maxsz + \
176 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400177#define encode_open_confirm_maxsz \
178 (op_encode_hdr_maxsz + \
179 encode_stateid_maxsz + 1)
180#define decode_open_confirm_maxsz \
181 (op_decode_hdr_maxsz + \
182 decode_stateid_maxsz)
183#define encode_open_downgrade_maxsz \
184 (op_encode_hdr_maxsz + \
185 encode_stateid_maxsz + 1 + \
186 encode_share_access_maxsz)
187#define decode_open_downgrade_maxsz \
188 (op_decode_hdr_maxsz + \
189 decode_stateid_maxsz)
190#define encode_close_maxsz (op_encode_hdr_maxsz + \
191 1 + encode_stateid_maxsz)
192#define decode_close_maxsz (op_decode_hdr_maxsz + \
193 decode_stateid_maxsz)
194#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + \
196 encode_attrs_maxsz)
197#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
198 nfs4_fattr_bitmap_maxsz)
199#define encode_read_maxsz (op_encode_hdr_maxsz + \
200 encode_stateid_maxsz + 3)
201#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
202#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400203 2 + encode_verifier_maxsz + 5 + \
204 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400205#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400206 decode_verifier_maxsz + \
207 nfs4_label_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400208#define encode_readlink_maxsz (op_encode_hdr_maxsz)
209#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
210#define encode_write_maxsz (op_encode_hdr_maxsz + \
211 encode_stateid_maxsz + 4)
212#define decode_write_maxsz (op_decode_hdr_maxsz + \
213 2 + decode_verifier_maxsz)
214#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
215#define decode_commit_maxsz (op_decode_hdr_maxsz + \
216 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217#define encode_remove_maxsz (op_encode_hdr_maxsz + \
218 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400219#define decode_remove_maxsz (op_decode_hdr_maxsz + \
220 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#define encode_rename_maxsz (op_encode_hdr_maxsz + \
222 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400223#define decode_rename_maxsz (op_decode_hdr_maxsz + \
224 decode_change_info_maxsz + \
225 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#define encode_link_maxsz (op_encode_hdr_maxsz + \
227 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400228#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400229#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400230#define encode_lock_maxsz (op_encode_hdr_maxsz + \
231 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400232 1 + encode_stateid_maxsz + 1 + \
233 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400234#define decode_lock_denied_maxsz \
235 (8 + decode_lockowner_maxsz)
236#define decode_lock_maxsz (op_decode_hdr_maxsz + \
237 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400238#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
239 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400240#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
241 decode_lock_denied_maxsz)
242#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
243 encode_stateid_maxsz + \
244 4)
245#define decode_locku_maxsz (op_decode_hdr_maxsz + \
246 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400247#define encode_release_lockowner_maxsz \
248 (op_encode_hdr_maxsz + \
249 encode_lockowner_maxsz)
250#define decode_release_lockowner_maxsz \
251 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400252#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
253#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
255 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400256 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000257 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
259#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400260 1 + 2 + nfs4_name_maxsz + \
261 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400262#define decode_create_maxsz (op_decode_hdr_maxsz + \
263 decode_change_info_maxsz + \
264 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400265#define encode_statfs_maxsz (encode_getattr_maxsz)
266#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
268#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400269#define encode_getacl_maxsz (encode_getattr_maxsz)
270#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
271 nfs4_fattr_bitmap_maxsz + 1)
272#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
273 encode_stateid_maxsz + 3)
274#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400275#define encode_fs_locations_maxsz \
276 (encode_getattr_maxsz)
277#define decode_fs_locations_maxsz \
278 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000279#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400280#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 -0400281
282#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400283#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500284#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
285 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400286
Benny Halevy99fe60d2009-04-01 09:22:29 -0400287#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
288 encode_verifier_maxsz + \
289 1 /* co_ownerid.len */ + \
290 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
291 1 /* flags */ + \
292 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400293 /* max is SP4_MACH_CRED (for now) */ + \
294 1 + NFS4_OP_MAP_NUM_WORDS + \
295 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500296 1 /* implementation id array of size 1 */ + \
297 1 /* nii_domain */ + \
298 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
299 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500300 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500301 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400302#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
303 2 /* eir_clientid */ + \
304 1 /* eir_sequenceid */ + \
305 1 /* eir_flags */ + \
306 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400307 /* max is SP4_MACH_CRED (for now) */ + \
308 1 + NFS4_OP_MAP_NUM_WORDS + \
309 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400310 2 /* eir_server_owner.so_minor_id */ + \
311 /* eir_server_owner.so_major_id<> */ \
312 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
313 /* eir_server_scope<> */ \
314 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
315 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500316 1 /* nii_domain */ + \
317 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
318 1 /* nii_name */ + \
319 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
320 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400321#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
322#define decode_channel_attrs_maxsz (6 + \
323 1 /* ca_rdma_ird.len */ + \
324 1 /* ca_rdma_ird */)
325#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
326 2 /* csa_clientid */ + \
327 1 /* csa_sequence */ + \
328 1 /* csa_flags */ + \
329 encode_channel_attrs_maxsz + \
330 encode_channel_attrs_maxsz + \
331 1 /* csa_cb_program */ + \
332 1 /* csa_sec_parms.len (1) */ + \
333 1 /* cb_secflavor (AUTH_SYS) */ + \
334 1 /* stamp */ + \
335 1 /* machinename.len */ + \
336 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
337 1 /* uid */ + \
338 1 /* gid */ + \
339 1 /* gids.len (0) */)
340#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
341 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
342 1 /* csr_sequence */ + \
343 1 /* csr_flags */ + \
344 decode_channel_attrs_maxsz + \
345 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400346#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
347 /* bctsa_sessid */ \
348 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
349 1 /* bctsa_dir */ + \
350 1 /* bctsa_use_conn_in_rdma_mode */)
351#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
352 /* bctsr_sessid */ \
353 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
354 1 /* bctsr_dir */ + \
355 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400356#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
357#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400358#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
359#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400360#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
361 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
362#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
363 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500364#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
365#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400366#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
367 encode_verifier_maxsz)
368#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
369 2 /* nfs_cookie4 gdlr_cookie */ + \
370 decode_verifier_maxsz \
371 /* verifier4 gdlr_verifier */ + \
372 1 /* gdlr_deviceid_list count */ + \
373 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
374 NFS4_DEVICEID4_SIZE) \
375 /* gdlr_deviceid_list */ + \
376 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400377#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
378 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
379#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
380 1 /* layout type */ + \
381 1 /* opaque devaddr4 length */ + \
382 /* devaddr4 payload is read into page */ \
383 1 /* notification bitmap length */ + \
384 1 /* notification bitmap */)
385#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
386 encode_stateid_maxsz)
387#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
388 decode_stateid_maxsz + \
389 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000390#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
391 2 /* offset */ + \
392 2 /* length */ + \
393 1 /* reclaim */ + \
394 encode_stateid_maxsz + \
395 1 /* new offset (true) */ + \
396 2 /* last byte written */ + \
397 1 /* nt_timechanged (false) */ + \
398 1 /* layoutupdate4 layout type */ + \
399 1 /* NULL filelayout layoutupdate4 payload */)
400#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 Adamson7f11d8d2011-07-30 20:52:35 -0400813#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
814 encode_sequence_maxsz + \
815 encode_putfh_maxsz + \
816 encode_getdevicelist_maxsz)
817#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
818 decode_sequence_maxsz + \
819 decode_putfh_maxsz + \
820 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400821#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
822 encode_sequence_maxsz +\
823 encode_getdeviceinfo_maxsz)
824#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
825 decode_sequence_maxsz + \
826 decode_getdeviceinfo_maxsz)
827#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
828 encode_sequence_maxsz + \
829 encode_putfh_maxsz + \
830 encode_layoutget_maxsz)
831#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
832 decode_sequence_maxsz + \
833 decode_putfh_maxsz + \
834 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000835#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
836 encode_sequence_maxsz +\
837 encode_putfh_maxsz + \
838 encode_layoutcommit_maxsz + \
839 encode_getattr_maxsz)
840#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
841 decode_sequence_maxsz + \
842 decode_putfh_maxsz + \
843 decode_layoutcommit_maxsz + \
844 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300845#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
846 encode_sequence_maxsz + \
847 encode_putfh_maxsz + \
848 encode_layoutreturn_maxsz)
849#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
850 decode_sequence_maxsz + \
851 decode_putfh_maxsz + \
852 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400853#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
854 encode_sequence_maxsz + \
855 encode_putrootfh_maxsz +\
856 encode_secinfo_no_name_maxsz)
857#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
858 decode_sequence_maxsz + \
859 decode_putrootfh_maxsz + \
860 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400861#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
862 encode_sequence_maxsz + \
863 encode_test_stateid_maxsz)
864#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
865 decode_sequence_maxsz + \
866 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400867#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
868 encode_sequence_maxsz + \
869 encode_free_stateid_maxsz)
870#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
871 decode_sequence_maxsz + \
872 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500873
874const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
875 compound_encode_hdr_maxsz +
876 encode_sequence_maxsz +
877 encode_putfh_maxsz +
878 encode_getattr_maxsz) *
879 XDR_UNIT);
880
881const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
882 compound_decode_hdr_maxsz +
883 decode_sequence_maxsz +
884 decode_putfh_maxsz) *
885 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400886
887const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
888 compound_decode_hdr_maxsz +
889 decode_sequence_maxsz) *
890 XDR_UNIT);
891EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400892#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Trond Myklebustbca79472009-03-11 14:10:26 -0400894static const umode_t nfs_type2fmt[] = {
895 [NF4BAD] = 0,
896 [NF4REG] = S_IFREG,
897 [NF4DIR] = S_IFDIR,
898 [NF4BLK] = S_IFBLK,
899 [NF4CHR] = S_IFCHR,
900 [NF4LNK] = S_IFLNK,
901 [NF4SOCK] = S_IFSOCK,
902 [NF4FIFO] = S_IFIFO,
903 [NF4ATTRDIR] = 0,
904 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905};
906
907struct compound_hdr {
908 int32_t status;
909 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500910 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 uint32_t taglen;
912 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400913 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400914 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915};
916
Benny Halevy13c65ce2009-08-14 17:19:25 +0300917static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
918{
919 __be32 *p = xdr_reserve_space(xdr, nbytes);
920 BUG_ON(!p);
921 return p;
922}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Trond Myklebustcb17e552012-03-04 18:13:56 -0500924static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
925{
926 __be32 *p;
927
928 p = xdr_reserve_space(xdr, len);
929 xdr_encode_opaque_fixed(p, buf, len);
930}
931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
933{
Al Viro8687b632006-10-19 23:28:48 -0700934 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500936 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 xdr_encode_opaque(p, str, len);
938}
939
Trond Myklebust4ade9822012-03-04 18:13:57 -0500940static void encode_uint32(struct xdr_stream *xdr, u32 n)
941{
942 __be32 *p;
943
944 p = reserve_space(xdr, 4);
945 *p = cpu_to_be32(n);
946}
947
Trond Myklebustff2eb682012-03-05 11:40:12 -0500948static void encode_uint64(struct xdr_stream *xdr, u64 n)
949{
950 __be32 *p;
951
952 p = reserve_space(xdr, 8);
953 xdr_encode_hyper(p, n);
954}
955
Trond Myklebust4ade9822012-03-04 18:13:57 -0500956static void encode_nfs4_seqid(struct xdr_stream *xdr,
957 const struct nfs_seqid *seqid)
958{
959 encode_uint32(xdr, seqid->sequence->counter);
960}
961
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400962static void encode_compound_hdr(struct xdr_stream *xdr,
963 struct rpc_rqst *req,
964 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965{
Al Viro8687b632006-10-19 23:28:48 -0700966 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400967 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400968
969 /* initialize running count of expected bytes in reply.
970 * NOTE: the replied tag SHOULD be the same is the one sent,
971 * but this is not required as a MUST for the server to do so. */
972 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Trond Myklebust7fc38842012-10-15 11:51:21 -0400974 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500975 encode_string(xdr, hdr->taglen, hdr->tag);
976 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300977 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500978 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300979 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500980}
981
Trond Myklebustab19b482012-03-04 18:13:57 -0500982static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
983 uint32_t replen,
984 struct compound_hdr *hdr)
985{
986 encode_uint32(xdr, op);
987 hdr->nops++;
988 hdr->replen += replen;
989}
990
Andy Adamsond0179312008-12-23 16:06:17 -0500991static void encode_nops(struct compound_hdr *hdr)
992{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400993 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500994 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995}
996
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500997static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
998{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500999 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001000}
1001
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1003{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001004 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005}
1006
David Quigleyaa9c2662013-05-22 12:50:44 -04001007static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1008 const struct nfs4_label *label,
1009 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010{
1011 char owner_name[IDMAP_NAMESZ];
1012 char owner_group[IDMAP_NAMESZ];
1013 int owner_namelen = 0;
1014 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001015 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001016 unsigned i;
1017 uint32_t len = 0;
1018 uint32_t bmval_len;
1019 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
1021 /*
1022 * We reserve enough space to write the entire attribute buffer at once.
1023 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001024 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1025 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001026 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001028 if (iap->ia_valid & ATTR_SIZE) {
1029 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001031 }
1032 if (iap->ia_valid & ATTR_MODE) {
1033 bmval[1] |= FATTR4_WORD1_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 len += 4;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001035 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001037 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001039 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001040 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 /* XXX */
1042 strcpy(owner_name, "nobody");
1043 owner_namelen = sizeof("nobody") - 1;
1044 /* goto out; */
1045 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001046 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1048 }
1049 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001050 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001052 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001053 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 strcpy(owner_group, "nobody");
1055 owner_grouplen = sizeof("nobody") - 1;
1056 /* goto out; */
1057 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001058 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001062 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1063 len += 16;
1064 } else if (iap->ia_valid & ATTR_ATIME) {
1065 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1066 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 }
1068 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001069 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1070 len += 16;
1071 } else if (iap->ia_valid & ATTR_MTIME) {
1072 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1073 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001075 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001076 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1077 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1078 }
1079
1080 if (bmval[2] != 0)
1081 bmval_len = 3;
1082 else if (bmval[1] != 0)
1083 bmval_len = 2;
1084 else
1085 bmval_len = 1;
1086
1087 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1088
1089 *p++ = cpu_to_be32(bmval_len);
1090 for (i = 0; i < bmval_len; i++)
1091 *p++ = cpu_to_be32(bmval[i]);
1092 *p++ = cpu_to_be32(len);
1093
1094 if (bmval[0] & FATTR4_WORD0_SIZE)
1095 p = xdr_encode_hyper(p, iap->ia_size);
1096 if (bmval[1] & FATTR4_WORD1_MODE)
1097 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1098 if (bmval[1] & FATTR4_WORD1_OWNER)
1099 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1100 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1101 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1102 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1103 if (iap->ia_valid & ATTR_ATIME_SET) {
1104 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1105 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1106 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1107 } else
1108 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1109 }
1110 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1111 if (iap->ia_valid & ATTR_MTIME_SET) {
1112 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1113 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1114 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1115 } else
1116 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1117 }
1118 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001119 *p++ = cpu_to_be32(label->lfs);
1120 *p++ = cpu_to_be32(label->pi);
1121 *p++ = cpu_to_be32(label->len);
1122 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1123 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001124
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126}
1127
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001128static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001130 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1131 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001134static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
Trond Myklebustab19b482012-03-04 18:13:57 -05001136 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001137 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001138 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Fred Isaman0b7c0152012-04-20 14:47:39 -04001141static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Al Viro8687b632006-10-19 23:28:48 -07001143 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001144
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001145 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1146 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001147 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001148 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149}
1150
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001151static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152{
Al Viro8687b632006-10-19 23:28:48 -07001153 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001154
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001155 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1156 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
1158 switch (create->ftype) {
1159 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001160 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001161 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001162 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 break;
1164
1165 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001166 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001167 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001168 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 break;
1170
1171 default:
1172 break;
1173 }
1174
Benny Halevy811652b2009-08-14 17:19:34 +03001175 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001176 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177}
1178
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001179static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180{
Andy Adamson05d564f2008-12-23 16:06:15 -05001181 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001183 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1184 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001185 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001186 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001189static 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 -07001190{
Andy Adamson05d564f2008-12-23 16:06:15 -05001191 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001193 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1194 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001195 *p++ = cpu_to_be32(2);
1196 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001197 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198}
1199
Fred Isamandae100c2011-07-30 20:52:37 -04001200static void
1201encode_getattr_three(struct xdr_stream *xdr,
1202 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1203 struct compound_hdr *hdr)
1204{
1205 __be32 *p;
1206
Trond Myklebustab19b482012-03-04 18:13:57 -05001207 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001208 if (bm2) {
1209 p = reserve_space(xdr, 16);
1210 *p++ = cpu_to_be32(3);
1211 *p++ = cpu_to_be32(bm0);
1212 *p++ = cpu_to_be32(bm1);
1213 *p = cpu_to_be32(bm2);
1214 } else if (bm1) {
1215 p = reserve_space(xdr, 12);
1216 *p++ = cpu_to_be32(2);
1217 *p++ = cpu_to_be32(bm0);
1218 *p = cpu_to_be32(bm1);
1219 } else {
1220 p = reserve_space(xdr, 8);
1221 *p++ = cpu_to_be32(1);
1222 *p = cpu_to_be32(bm0);
1223 }
Fred Isamandae100c2011-07-30 20:52:37 -04001224}
1225
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001226static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227{
David Quigleya09df2c2013-05-22 12:50:41 -04001228 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1229 bitmask[1] & nfs4_fattr_bitmap[1],
1230 bitmask[2] & nfs4_fattr_bitmap[2],
1231 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232}
1233
Andy Adamson88034c32012-05-23 05:02:34 -04001234static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001235 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001236 struct compound_hdr *hdr)
1237{
1238 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001239 bitmask[0] & open_bitmap[0],
1240 bitmask[1] & open_bitmap[1],
1241 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001242 hdr);
1243}
1244
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001245static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246{
Fred Isamandae100c2011-07-30 20:52:37 -04001247 encode_getattr_three(xdr,
1248 bitmask[0] & nfs4_fsinfo_bitmap[0],
1249 bitmask[1] & nfs4_fsinfo_bitmap[1],
1250 bitmask[2] & nfs4_fsinfo_bitmap[2],
1251 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001254static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001255{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001256 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1257 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001258}
1259
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001260static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
Trond Myklebustab19b482012-03-04 18:13:57 -05001262 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263}
1264
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001265static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266{
Trond Myklebustab19b482012-03-04 18:13:57 -05001267 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001268 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269}
1270
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001271static inline int nfs4_lock_type(struct file_lock *fl, int block)
1272{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001273 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001274 return block ? NFS4_READW_LT : NFS4_READ_LT;
1275 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1276}
1277
1278static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1279{
1280 if (fl->fl_end == OFFSET_MAX)
1281 return ~(uint64_t)0;
1282 return fl->fl_end - fl->fl_start + 1;
1283}
1284
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001285static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1286{
1287 __be32 *p;
1288
Trond Myklebustd035c362010-12-21 10:45:27 -05001289 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001290 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001291 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001292 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001293 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001294 xdr_encode_hyper(p, lowner->id);
1295}
1296
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297/*
1298 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1299 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1300 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001301static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302{
Al Viro8687b632006-10-19 23:28:48 -07001303 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001305 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1306 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001307 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1308 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001309 p = xdr_encode_hyper(p, args->fl->fl_start);
1310 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001311 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001312 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001313 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001314 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001315 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001316 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 }
1318 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001319 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001320 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322}
1323
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001324static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325{
Al Viro8687b632006-10-19 23:28:48 -07001326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001328 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1329 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001330 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001331 p = xdr_encode_hyper(p, args->fl->fl_start);
1332 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001333 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334}
1335
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001336static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
Al Viro8687b632006-10-19 23:28:48 -07001338 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001340 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1341 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001342 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001343 encode_nfs4_stateid(xdr, args->stateid);
1344 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001345 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001346 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001349static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1350{
Trond Myklebustab19b482012-03-04 18:13:57 -05001351 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001352 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001353}
1354
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001355static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356{
Trond Myklebustab19b482012-03-04 18:13:57 -05001357 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001358 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359}
1360
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001361static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362{
Al Viro8687b632006-10-19 23:28:48 -07001363 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
Benny Halevy13c65ce2009-08-14 17:19:25 +03001365 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001366 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001367 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001368 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001369 break;
1370 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001371 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001372 break;
1373 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001374 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001375 break;
1376 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001377 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 }
Benny Halevy34558512009-08-14 17:19:30 +03001379 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380}
1381
1382static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1383{
Al Viro8687b632006-10-19 23:28:48 -07001384 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 /*
1386 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1387 * owner 4 = 32
1388 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001389 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001390 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001391 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001392 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001393 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001394 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001395 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001396 *p++ = cpu_to_be32(arg->id.uniquifier);
1397 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398}
1399
1400static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1401{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001402 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001403 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
Benny Halevy13c65ce2009-08-14 17:19:25 +03001405 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001406 switch(arg->createmode) {
1407 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001408 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001409 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001410 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001411 case NFS4_CREATE_GUARDED:
1412 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001413 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001414 break;
1415 case NFS4_CREATE_EXCLUSIVE:
1416 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1417 encode_nfs4_verifier(xdr, &arg->u.verifier);
1418 break;
1419 case NFS4_CREATE_EXCLUSIVE4_1:
1420 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1421 encode_nfs4_verifier(xdr, &arg->u.verifier);
1422 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001423 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 }
1425}
1426
1427static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1428{
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 (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001433 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001434 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001435 break;
1436 default:
Benny Halevy34558512009-08-14 17:19:30 +03001437 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 }
1440}
1441
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001442static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443{
Al Viro8687b632006-10-19 23:28:48 -07001444 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
Benny Halevy13c65ce2009-08-14 17:19:25 +03001446 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001448 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001449 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001450 break;
1451 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001452 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001453 break;
1454 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001455 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001456 break;
1457 default:
1458 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 }
1460}
1461
1462static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1463{
Al Viro8687b632006-10-19 23:28:48 -07001464 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
Benny Halevy13c65ce2009-08-14 17:19:25 +03001466 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001467 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 encode_string(xdr, name->len, name->name);
1469}
1470
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001471static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
Al Viro8687b632006-10-19 23:28:48 -07001473 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Benny Halevy13c65ce2009-08-14 17:19:25 +03001475 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001476 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 encode_delegation_type(xdr, type);
1478}
1479
1480static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1481{
Al Viro8687b632006-10-19 23:28:48 -07001482 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001484 p = reserve_space(xdr, 4);
1485 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1486 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 encode_string(xdr, name->len, name->name);
1488}
1489
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001490static inline void encode_claim_fh(struct xdr_stream *xdr)
1491{
1492 __be32 *p;
1493
1494 p = reserve_space(xdr, 4);
1495 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1496}
1497
1498static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1499{
1500 __be32 *p;
1501
1502 p = reserve_space(xdr, 4);
1503 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1504 encode_nfs4_stateid(xdr, stateid);
1505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Trond Myklebustab19b482012-03-04 18:13:57 -05001509 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 encode_openhdr(xdr, arg);
1511 encode_opentype(xdr, arg);
1512 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001513 case NFS4_OPEN_CLAIM_NULL:
1514 encode_claim_null(xdr, arg->name);
1515 break;
1516 case NFS4_OPEN_CLAIM_PREVIOUS:
1517 encode_claim_previous(xdr, arg->u.delegation_type);
1518 break;
1519 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1520 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1521 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001522 case NFS4_OPEN_CLAIM_FH:
1523 encode_claim_fh(xdr);
1524 break;
1525 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1526 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1527 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001528 default:
1529 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531}
1532
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001533static 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 -07001534{
Trond Myklebustab19b482012-03-04 18:13:57 -05001535 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001536 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001537 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538}
1539
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001540static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, 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_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001543 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001544 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001545 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001548static void
Andy Adamsond0179312008-12-23 16:06:17 -05001549encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550{
Trond Myklebustab19b482012-03-04 18:13:57 -05001551 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001552 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553}
1554
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001555static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556{
Trond Myklebustab19b482012-03-04 18:13:57 -05001557 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}
1559
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001560static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Al Viro8687b632006-10-19 23:28:48 -07001562 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
Trond Myklebustab19b482012-03-04 18:13:57 -05001564 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001565 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Benny Halevy13c65ce2009-08-14 17:19:25 +03001567 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001568 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001569 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570}
1571
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001572static 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 -07001573{
David Quigleyaa9c2662013-05-22 12:50:44 -04001574 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001575 FATTR4_WORD0_RDATTR_ERROR,
1576 FATTR4_WORD1_MOUNTED_ON_FILEID,
1577 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001578 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001579 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001580 uint32_t attrlen = 0;
1581 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001583 if (readdir->plus) {
1584 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001585 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001586 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1587 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1588 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1589 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001590 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001591 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001592 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001593 /* Use mounted_on_fileid only if the server supports it */
1594 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1595 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001596 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1597 attrs[i] &= readdir->bitmask[i];
1598 if (attrs[i] != 0)
1599 attrlen = i+1;
1600 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001601
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001602 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001603 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001604 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001605 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001606 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001607 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001608 *p++ = cpu_to_be32(attrlen);
1609 for (i = 0; i < attrlen; i++)
1610 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001611 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001612
1613 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001614 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001615 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001616 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001617 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001618 attrs[1] & readdir->bitmask[1],
1619 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
1621
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001622static 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 -07001623{
Trond Myklebustab19b482012-03-04 18:13:57 -05001624 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625}
1626
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001627static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628{
Trond Myklebustab19b482012-03-04 18:13:57 -05001629 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001630 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001633static 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 -07001634{
Trond Myklebustab19b482012-03-04 18:13:57 -05001635 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001636 encode_string(xdr, oldname->len, oldname->name);
1637 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638}
1639
Chuck Leverbb4dae52012-03-01 17:01:48 -05001640static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1641 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001643 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001644 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
1646
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001647static void
Andy Adamsond0179312008-12-23 16:06:17 -05001648encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001649{
Trond Myklebustab19b482012-03-04 18:13:57 -05001650 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001651}
1652
Chuck Lever9f06c712010-12-14 14:59:18 +00001653static void
Andy Adamsond0179312008-12-23 16:06:17 -05001654encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001655{
Al Viro8687b632006-10-19 23:28:48 -07001656 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001657
Trond Myklebustab19b482012-03-04 18:13:57 -05001658 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001659 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001660 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001661 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001662 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001663 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001664 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001665 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001666}
1667
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001668static void
Andy Adamsond0179312008-12-23 16:06:17 -05001669encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670{
Trond Myklebustab19b482012-03-04 18:13:57 -05001671 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672}
1673
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001674static 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 -07001675{
Trond Myklebustab19b482012-03-04 18:13:57 -05001676 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001677 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001678 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679}
1680
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001681static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
Al Viro8687b632006-10-19 23:28:48 -07001683 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Trond Myklebust70019512012-03-04 20:49:32 -05001685 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001686 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
1688 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001689 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001690 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1692 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001693 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001694 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695}
1696
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001697static 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 -07001698{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001699 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1700 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001701 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001702 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001705static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706{
Al Viro8687b632006-10-19 23:28:48 -07001707 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Trond Myklebustab19b482012-03-04 18:13:57 -05001709 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001710 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
Benny Halevy13c65ce2009-08-14 17:19:25 +03001712 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001713 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001714 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001715 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
1717 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718}
1719
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001720static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
Trond Myklebustab19b482012-03-04 18:13:57 -05001722 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001723 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001725
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001726static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1727{
Trond Myklebustab19b482012-03-04 18:13:57 -05001728 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001729 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001730}
1731
Benny Halevy99fe60d2009-04-01 09:22:29 -04001732#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001733/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001734static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1735 struct nfs4_session *session,
1736 struct compound_hdr *hdr)
1737{
1738 __be32 *p;
1739
1740 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1741 decode_bind_conn_to_session_maxsz, hdr);
1742 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1743 p = xdr_reserve_space(xdr, 8);
1744 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1745 *p = 0; /* use_conn_in_rdma_mode = False */
1746}
1747
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001748static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1749{
1750 unsigned int i;
1751 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1752 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1753 encode_uint32(xdr, op_map->u.words[i]);
1754}
1755
Benny Halevy99fe60d2009-04-01 09:22:29 -04001756static void encode_exchange_id(struct xdr_stream *xdr,
1757 struct nfs41_exchange_id_args *args,
1758 struct compound_hdr *hdr)
1759{
1760 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001761 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001762 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001763
Trond Myklebust70019512012-03-04 20:49:32 -05001764 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001765 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001766
1767 encode_string(xdr, args->id_len, args->id);
1768
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001769 encode_uint32(xdr, args->flags);
1770 encode_uint32(xdr, args->state_protect.how);
1771
1772 switch (args->state_protect.how) {
1773 case SP4_NONE:
1774 break;
1775 case SP4_MACH_CRED:
1776 encode_op_map(xdr, &args->state_protect.enforce);
1777 encode_op_map(xdr, &args->state_protect.allow);
1778 break;
1779 default:
1780 WARN_ON_ONCE(1);
1781 break;
1782 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001783
1784 if (send_implementation_id &&
1785 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1786 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001787 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001788 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1789 utsname()->sysname, utsname()->release,
1790 utsname()->version, utsname()->machine);
1791
1792 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001793 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001794
1795 encode_string(xdr,
1796 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1797 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1798 encode_string(xdr, len, impl_name);
1799 /* just send zeros for nii_date - the date is in nii_name */
1800 p = reserve_space(xdr, 12);
1801 p = xdr_encode_hyper(p, 0);
1802 *p = cpu_to_be32(0);
1803 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001804 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001805}
Andy Adamsonfc931582009-04-01 09:22:31 -04001806
1807static void encode_create_session(struct xdr_stream *xdr,
1808 struct nfs41_create_session_args *args,
1809 struct compound_hdr *hdr)
1810{
1811 __be32 *p;
1812 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1813 uint32_t len;
1814 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001815 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001816 u32 max_resp_sz_cached;
1817
1818 /*
1819 * Assumes OPEN is the biggest non-idempotent compound.
1820 * 2 is the verifier.
1821 */
1822 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1823 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001824
Andy Adamsonfc931582009-04-01 09:22:31 -04001825 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1826 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001827
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001828 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1829 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001830 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001831 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1832 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001833
Andy Adamsonfc931582009-04-01 09:22:31 -04001834 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001835 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001836 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1837 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001838 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001839 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1840 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1841 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001842
1843 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001844 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001845 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1846 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1847 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1848 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1849 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1850 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001851
Benny Halevye75bc1c2009-08-14 17:18:54 +03001852 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001853 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001854 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001855
1856 /* authsys_parms rfc1831 */
Trond Myklebust17f26b12013-08-21 15:48:42 -04001857 *p++ = cpu_to_be32(nn->boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001858 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001859 *p++ = cpu_to_be32(0); /* UID */
1860 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001861 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001862}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001863
1864static void encode_destroy_session(struct xdr_stream *xdr,
1865 struct nfs4_session *session,
1866 struct compound_hdr *hdr)
1867{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001868 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1869 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001870}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001871
Trond Myklebust66245532012-05-25 17:18:09 -04001872static void encode_destroy_clientid(struct xdr_stream *xdr,
1873 uint64_t clientid,
1874 struct compound_hdr *hdr)
1875{
1876 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1877 encode_uint64(xdr, clientid);
1878}
1879
Ricardo Labiaga180197532009-12-05 16:08:40 -05001880static void encode_reclaim_complete(struct xdr_stream *xdr,
1881 struct nfs41_reclaim_complete_args *args,
1882 struct compound_hdr *hdr)
1883{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001884 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1885 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001886}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001887#endif /* CONFIG_NFS_V4_1 */
1888
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001889static void encode_sequence(struct xdr_stream *xdr,
1890 const struct nfs4_sequence_args *args,
1891 struct compound_hdr *hdr)
1892{
1893#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001894 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001895 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001896 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001897 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001898
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001899 tp = slot->table;
1900 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001901 if (!session)
1902 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001903
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001904 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001905
1906 /*
1907 * Sessionid + seqid + slotid + max slotid + cache_this
1908 */
1909 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1910 "max_slotid=%d cache_this=%d\n",
1911 __func__,
1912 ((u32 *)session->sess_id.data)[0],
1913 ((u32 *)session->sess_id.data)[1],
1914 ((u32 *)session->sess_id.data)[2],
1915 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001916 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001917 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001918 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001919 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001920 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001921 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001922 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001923 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001924#endif /* CONFIG_NFS_V4_1 */
1925}
1926
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001927#ifdef CONFIG_NFS_V4_1
1928static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001929encode_getdevicelist(struct xdr_stream *xdr,
1930 const struct nfs4_getdevicelist_args *args,
1931 struct compound_hdr *hdr)
1932{
1933 __be32 *p;
1934 nfs4_verifier dummy = {
1935 .data = "dummmmmy",
1936 };
1937
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001938 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1939 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001940 *p++ = cpu_to_be32(args->layoutclass);
1941 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1942 xdr_encode_hyper(p, 0ULL); /* cookie */
1943 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001944}
1945
1946static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001947encode_getdeviceinfo(struct xdr_stream *xdr,
1948 const struct nfs4_getdeviceinfo_args *args,
1949 struct compound_hdr *hdr)
1950{
1951 __be32 *p;
1952
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001953 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1954 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001955 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1956 NFS4_DEVICEID4_SIZE);
1957 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001958 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001959 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001960}
1961
1962static void
1963encode_layoutget(struct xdr_stream *xdr,
1964 const struct nfs4_layoutget_args *args,
1965 struct compound_hdr *hdr)
1966{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001967 __be32 *p;
1968
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001969 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1970 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001971 *p++ = cpu_to_be32(0); /* Signal layout available */
1972 *p++ = cpu_to_be32(args->type);
1973 *p++ = cpu_to_be32(args->range.iomode);
1974 p = xdr_encode_hyper(p, args->range.offset);
1975 p = xdr_encode_hyper(p, args->range.length);
1976 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001977 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001978 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001979
1980 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1981 __func__,
1982 args->type,
1983 args->range.iomode,
1984 (unsigned long)args->range.offset,
1985 (unsigned long)args->range.length,
1986 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001987}
Andy Adamson863a3c62011-03-23 13:27:54 +00001988
1989static int
1990encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001991 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001992 const struct nfs4_layoutcommit_args *args,
1993 struct compound_hdr *hdr)
1994{
1995 __be32 *p;
1996
1997 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1998 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1999
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002000 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2001 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00002002 /* Only whole file layouts */
2003 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002004 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002005 *p = cpu_to_be32(0); /* reclaim */
2006 encode_nfs4_stateid(xdr, &args->stateid);
2007 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00002008 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2009 p = xdr_encode_hyper(p, args->lastbytewritten);
2010 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2011 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002012
2013 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2014 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2015 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002016 else
2017 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00002018
Andy Adamson863a3c62011-03-23 13:27:54 +00002019 return 0;
2020}
Benny Halevycbe82602011-05-22 19:52:37 +03002021
2022static void
2023encode_layoutreturn(struct xdr_stream *xdr,
2024 const struct nfs4_layoutreturn_args *args,
2025 struct compound_hdr *hdr)
2026{
2027 __be32 *p;
2028
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002029 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2030 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002031 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2032 *p++ = cpu_to_be32(args->layout_type);
2033 *p++ = cpu_to_be32(IOMODE_ANY);
2034 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002035 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002036 p = xdr_encode_hyper(p, 0);
2037 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2038 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002039 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002040 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002041 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2042 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2043 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002044 } else
2045 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002046}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002047
2048static int
2049encode_secinfo_no_name(struct xdr_stream *xdr,
2050 const struct nfs41_secinfo_no_name_args *args,
2051 struct compound_hdr *hdr)
2052{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002053 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2054 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002055 return 0;
2056}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002057
2058static void encode_test_stateid(struct xdr_stream *xdr,
2059 struct nfs41_test_stateid_args *args,
2060 struct compound_hdr *hdr)
2061{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002062 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2063 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002064 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002065}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002066
2067static void encode_free_stateid(struct xdr_stream *xdr,
2068 struct nfs41_free_stateid_args *args,
2069 struct compound_hdr *hdr)
2070{
Trond Myklebustab19b482012-03-04 18:13:57 -05002071 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002072 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002073}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002074#endif /* CONFIG_NFS_V4_1 */
2075
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076/*
2077 * END OF "GENERIC" ENCODE ROUTINES.
2078 */
2079
Benny Halevy66cc0422009-04-01 09:22:10 -04002080static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2081{
2082#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002083 struct nfs4_session *session = args->sa_slot->table->session;
2084 if (session)
2085 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002086#endif /* CONFIG_NFS_V4_1 */
2087 return 0;
2088}
2089
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090/*
2091 * Encode an ACCESS request
2092 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002093static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2094 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002097 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Chuck Lever9f06c712010-12-14 14:59:18 +00002100 encode_compound_hdr(xdr, req, &hdr);
2101 encode_sequence(xdr, &args->seq_args, &hdr);
2102 encode_putfh(xdr, args->fh, &hdr);
2103 encode_access(xdr, args->access, &hdr);
2104 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002105 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
2108/*
2109 * Encode LOOKUP request
2110 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002111static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2112 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
Chuck Lever9f06c712010-12-14 14:59:18 +00002118 encode_compound_hdr(xdr, req, &hdr);
2119 encode_sequence(xdr, &args->seq_args, &hdr);
2120 encode_putfh(xdr, args->dir_fh, &hdr);
2121 encode_lookup(xdr, args->name, &hdr);
2122 encode_getfh(xdr, &hdr);
2123 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002124 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125}
2126
2127/*
2128 * Encode LOOKUP_ROOT request
2129 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002130static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2131 struct xdr_stream *xdr,
2132 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002135 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
Chuck Lever9f06c712010-12-14 14:59:18 +00002138 encode_compound_hdr(xdr, req, &hdr);
2139 encode_sequence(xdr, &args->seq_args, &hdr);
2140 encode_putrootfh(xdr, &hdr);
2141 encode_getfh(xdr, &hdr);
2142 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002143 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144}
2145
2146/*
2147 * Encode REMOVE request
2148 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002149static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2150 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002153 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
Chuck Lever9f06c712010-12-14 14:59:18 +00002156 encode_compound_hdr(xdr, req, &hdr);
2157 encode_sequence(xdr, &args->seq_args, &hdr);
2158 encode_putfh(xdr, args->fh, &hdr);
2159 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002160 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161}
2162
2163/*
2164 * Encode RENAME request
2165 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002166static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2167 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002170 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
Chuck Lever9f06c712010-12-14 14:59:18 +00002173 encode_compound_hdr(xdr, req, &hdr);
2174 encode_sequence(xdr, &args->seq_args, &hdr);
2175 encode_putfh(xdr, args->old_dir, &hdr);
2176 encode_savefh(xdr, &hdr);
2177 encode_putfh(xdr, args->new_dir, &hdr);
2178 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002179 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180}
2181
2182/*
2183 * Encode LINK request
2184 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002185static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2186 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002189 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
Chuck Lever9f06c712010-12-14 14:59:18 +00002192 encode_compound_hdr(xdr, req, &hdr);
2193 encode_sequence(xdr, &args->seq_args, &hdr);
2194 encode_putfh(xdr, args->fh, &hdr);
2195 encode_savefh(xdr, &hdr);
2196 encode_putfh(xdr, args->dir_fh, &hdr);
2197 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002198 encode_restorefh(xdr, &hdr);
2199 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002200 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201}
2202
2203/*
2204 * Encode CREATE request
2205 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002206static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2207 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002210 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
Chuck Lever9f06c712010-12-14 14:59:18 +00002213 encode_compound_hdr(xdr, req, &hdr);
2214 encode_sequence(xdr, &args->seq_args, &hdr);
2215 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002216 encode_create(xdr, args, &hdr);
2217 encode_getfh(xdr, &hdr);
2218 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002219 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220}
2221
2222/*
2223 * Encode SYMLINK request
2224 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002225static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2226 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227{
Chuck Lever9f06c712010-12-14 14:59:18 +00002228 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229}
2230
2231/*
2232 * Encode GETATTR request
2233 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002234static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2235 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002238 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
Chuck Lever9f06c712010-12-14 14:59:18 +00002241 encode_compound_hdr(xdr, req, &hdr);
2242 encode_sequence(xdr, &args->seq_args, &hdr);
2243 encode_putfh(xdr, args->fh, &hdr);
2244 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002245 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246}
2247
2248/*
2249 * Encode a CLOSE request
2250 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002251static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2252 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253{
Andy Adamson05d564f2008-12-23 16:06:15 -05002254 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002255 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002256 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
Chuck Lever9f06c712010-12-14 14:59:18 +00002258 encode_compound_hdr(xdr, req, &hdr);
2259 encode_sequence(xdr, &args->seq_args, &hdr);
2260 encode_putfh(xdr, args->fh, &hdr);
2261 encode_close(xdr, args, &hdr);
2262 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002263 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264}
2265
2266/*
2267 * Encode an OPEN request
2268 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002269static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2270 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002273 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
Chuck Lever9f06c712010-12-14 14:59:18 +00002276 encode_compound_hdr(xdr, req, &hdr);
2277 encode_sequence(xdr, &args->seq_args, &hdr);
2278 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002279 encode_open(xdr, args, &hdr);
2280 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002281 if (args->access)
2282 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002283 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002284 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285}
2286
2287/*
2288 * Encode an OPEN_CONFIRM request
2289 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002290static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2291 struct xdr_stream *xdr,
2292 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002295 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297
Chuck Lever9f06c712010-12-14 14:59:18 +00002298 encode_compound_hdr(xdr, req, &hdr);
2299 encode_putfh(xdr, args->fh, &hdr);
2300 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002301 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302}
2303
2304/*
2305 * Encode an OPEN request with no attributes.
2306 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002307static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2308 struct xdr_stream *xdr,
2309 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002312 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
Chuck Lever9f06c712010-12-14 14:59:18 +00002315 encode_compound_hdr(xdr, req, &hdr);
2316 encode_sequence(xdr, &args->seq_args, &hdr);
2317 encode_putfh(xdr, args->fh, &hdr);
2318 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002319 if (args->access)
2320 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002321 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002322 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323}
2324
2325/*
2326 * Encode an OPEN_DOWNGRADE request
2327 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002328static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2329 struct xdr_stream *xdr,
2330 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002333 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
Chuck Lever9f06c712010-12-14 14:59:18 +00002336 encode_compound_hdr(xdr, req, &hdr);
2337 encode_sequence(xdr, &args->seq_args, &hdr);
2338 encode_putfh(xdr, args->fh, &hdr);
2339 encode_open_downgrade(xdr, args, &hdr);
2340 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002341 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342}
2343
2344/*
2345 * Encode a LOCK request
2346 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002347static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2348 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002351 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353
Chuck Lever9f06c712010-12-14 14:59:18 +00002354 encode_compound_hdr(xdr, req, &hdr);
2355 encode_sequence(xdr, &args->seq_args, &hdr);
2356 encode_putfh(xdr, args->fh, &hdr);
2357 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002358 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359}
2360
2361/*
2362 * Encode a LOCKT request
2363 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002364static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2365 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002368 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370
Chuck Lever9f06c712010-12-14 14:59:18 +00002371 encode_compound_hdr(xdr, req, &hdr);
2372 encode_sequence(xdr, &args->seq_args, &hdr);
2373 encode_putfh(xdr, args->fh, &hdr);
2374 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002375 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376}
2377
2378/*
2379 * Encode a LOCKU request
2380 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002381static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2382 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002385 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
Chuck Lever9f06c712010-12-14 14:59:18 +00002388 encode_compound_hdr(xdr, req, &hdr);
2389 encode_sequence(xdr, &args->seq_args, &hdr);
2390 encode_putfh(xdr, args->fh, &hdr);
2391 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002392 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393}
2394
Chuck Lever9f06c712010-12-14 14:59:18 +00002395static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2396 struct xdr_stream *xdr,
2397 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002398{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002399 struct compound_hdr hdr = {
2400 .minorversion = 0,
2401 };
2402
Chuck Lever9f06c712010-12-14 14:59:18 +00002403 encode_compound_hdr(xdr, req, &hdr);
2404 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002405 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002406}
2407
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408/*
2409 * Encode a READLINK request
2410 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002411static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2412 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002415 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Chuck Lever9f06c712010-12-14 14:59:18 +00002418 encode_compound_hdr(xdr, req, &hdr);
2419 encode_sequence(xdr, &args->seq_args, &hdr);
2420 encode_putfh(xdr, args->fh, &hdr);
2421 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002422
Benny Halevy28f56692009-04-01 09:22:09 -04002423 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002424 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002425 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426}
2427
2428/*
2429 * Encode a READDIR request
2430 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002431static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2432 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002435 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437
Chuck Lever9f06c712010-12-14 14:59:18 +00002438 encode_compound_hdr(xdr, req, &hdr);
2439 encode_sequence(xdr, &args->seq_args, &hdr);
2440 encode_putfh(xdr, args->fh, &hdr);
2441 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002442
Benny Halevy28f56692009-04-01 09:22:09 -04002443 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002444 args->pgbase, args->count);
2445 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002446 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002447 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002448 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449}
2450
2451/*
2452 * Encode a READ request
2453 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002454static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2455 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002458 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460
Chuck Lever9f06c712010-12-14 14:59:18 +00002461 encode_compound_hdr(xdr, req, &hdr);
2462 encode_sequence(xdr, &args->seq_args, &hdr);
2463 encode_putfh(xdr, args->fh, &hdr);
2464 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465
Benny Halevy28f56692009-04-01 09:22:09 -04002466 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002468 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002469 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470}
2471
2472/*
2473 * Encode an SETATTR request
2474 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002475static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2476 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477{
Andy Adamson05d564f2008-12-23 16:06:15 -05002478 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002479 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002480 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481
Chuck Lever9f06c712010-12-14 14:59:18 +00002482 encode_compound_hdr(xdr, req, &hdr);
2483 encode_sequence(xdr, &args->seq_args, &hdr);
2484 encode_putfh(xdr, args->fh, &hdr);
2485 encode_setattr(xdr, args, args->server, &hdr);
2486 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002487 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488}
2489
2490/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002491 * Encode a GETACL request
2492 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002493static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2494 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002495{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002496 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002497 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002498 };
Benny Halevy28f56692009-04-01 09:22:09 -04002499 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002500
Chuck Lever9f06c712010-12-14 14:59:18 +00002501 encode_compound_hdr(xdr, req, &hdr);
2502 encode_sequence(xdr, &args->seq_args, &hdr);
2503 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002504 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002505 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002506
Benny Halevy28f56692009-04-01 09:22:09 -04002507 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002508 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002509
Andy Adamsond0179312008-12-23 16:06:17 -05002510 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002511}
2512
2513/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 * Encode a WRITE request
2515 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002516static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2517 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002520 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522
Chuck Lever9f06c712010-12-14 14:59:18 +00002523 encode_compound_hdr(xdr, req, &hdr);
2524 encode_sequence(xdr, &args->seq_args, &hdr);
2525 encode_putfh(xdr, args->fh, &hdr);
2526 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002527 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002528 if (args->bitmask)
2529 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002530 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531}
2532
2533/*
2534 * a COMMIT request
2535 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002536static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002537 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002540 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542
Chuck Lever9f06c712010-12-14 14:59:18 +00002543 encode_compound_hdr(xdr, req, &hdr);
2544 encode_sequence(xdr, &args->seq_args, &hdr);
2545 encode_putfh(xdr, args->fh, &hdr);
2546 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002547 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548}
2549
2550/*
2551 * FSINFO request
2552 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002553static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2554 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002557 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
Chuck Lever9f06c712010-12-14 14:59:18 +00002560 encode_compound_hdr(xdr, req, &hdr);
2561 encode_sequence(xdr, &args->seq_args, &hdr);
2562 encode_putfh(xdr, args->fh, &hdr);
2563 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002564 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565}
2566
2567/*
2568 * a PATHCONF request
2569 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002570static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2571 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002574 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576
Chuck Lever9f06c712010-12-14 14:59:18 +00002577 encode_compound_hdr(xdr, req, &hdr);
2578 encode_sequence(xdr, &args->seq_args, &hdr);
2579 encode_putfh(xdr, args->fh, &hdr);
2580 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002581 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002582 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583}
2584
2585/*
2586 * a STATFS request
2587 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002588static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2589 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002592 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594
Chuck Lever9f06c712010-12-14 14:59:18 +00002595 encode_compound_hdr(xdr, req, &hdr);
2596 encode_sequence(xdr, &args->seq_args, &hdr);
2597 encode_putfh(xdr, args->fh, &hdr);
2598 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002599 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002600 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601}
2602
2603/*
2604 * GETATTR_BITMAP request
2605 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002606static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2607 struct xdr_stream *xdr,
2608 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002611 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613
Chuck Lever9f06c712010-12-14 14:59:18 +00002614 encode_compound_hdr(xdr, req, &hdr);
2615 encode_sequence(xdr, &args->seq_args, &hdr);
2616 encode_putfh(xdr, args->fhandle, &hdr);
2617 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002618 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002619 FATTR4_WORD0_LINK_SUPPORT|
2620 FATTR4_WORD0_SYMLINK_SUPPORT|
2621 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002622 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623}
2624
2625/*
2626 * a RENEW request
2627 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002628static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2629 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002632 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 };
2634
Chuck Lever9f06c712010-12-14 14:59:18 +00002635 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002636 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002637 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638}
2639
2640/*
2641 * a SETCLIENTID request
2642 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002643static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2644 struct xdr_stream *xdr,
2645 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002648 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 };
2650
Chuck Lever9f06c712010-12-14 14:59:18 +00002651 encode_compound_hdr(xdr, req, &hdr);
2652 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002653 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654}
2655
2656/*
2657 * a SETCLIENTID_CONFIRM request
2658 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002659static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2660 struct xdr_stream *xdr,
2661 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002664 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
Chuck Lever9f06c712010-12-14 14:59:18 +00002667 encode_compound_hdr(xdr, req, &hdr);
2668 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002669 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670}
2671
2672/*
2673 * DELEGRETURN request
2674 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002675static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2676 struct xdr_stream *xdr,
2677 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002680 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
Chuck Lever9f06c712010-12-14 14:59:18 +00002683 encode_compound_hdr(xdr, req, &hdr);
2684 encode_sequence(xdr, &args->seq_args, &hdr);
2685 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002686 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002687 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002688 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689}
2690
2691/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002692 * Encode FS_LOCATIONS request
2693 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002694static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2695 struct xdr_stream *xdr,
2696 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002697{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002698 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002699 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002700 };
Benny Halevy28f56692009-04-01 09:22:09 -04002701 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002702
Chuck Lever9f06c712010-12-14 14:59:18 +00002703 encode_compound_hdr(xdr, req, &hdr);
2704 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002705 if (args->migration) {
2706 encode_putfh(xdr, args->fh, &hdr);
2707 replen = hdr.replen;
2708 encode_fs_locations(xdr, args->bitmask, &hdr);
2709 if (args->renew)
2710 encode_renew(xdr, args->clientid, &hdr);
2711 } else {
2712 encode_putfh(xdr, args->dir_fh, &hdr);
2713 encode_lookup(xdr, args->name, &hdr);
2714 replen = hdr.replen;
2715 encode_fs_locations(xdr, args->bitmask, &hdr);
2716 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002717
Chuck Leverb03d7352013-10-17 14:12:50 -04002718 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002719 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002720 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002721 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002722}
2723
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002724/*
2725 * Encode SECINFO request
2726 */
2727static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2728 struct xdr_stream *xdr,
2729 struct nfs4_secinfo_arg *args)
2730{
2731 struct compound_hdr hdr = {
2732 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2733 };
2734
2735 encode_compound_hdr(xdr, req, &hdr);
2736 encode_sequence(xdr, &args->seq_args, &hdr);
2737 encode_putfh(xdr, args->dir_fh, &hdr);
2738 encode_secinfo(xdr, args->name, &hdr);
2739 encode_nops(&hdr);
2740}
2741
Chuck Lever44c99932013-10-17 14:13:30 -04002742/*
2743 * Encode FSID_PRESENT request
2744 */
2745static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2746 struct xdr_stream *xdr,
2747 struct nfs4_fsid_present_arg *args)
2748{
2749 struct compound_hdr hdr = {
2750 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2751 };
2752
2753 encode_compound_hdr(xdr, req, &hdr);
2754 encode_sequence(xdr, &args->seq_args, &hdr);
2755 encode_putfh(xdr, args->fh, &hdr);
2756 encode_getfh(xdr, &hdr);
2757 if (args->renew)
2758 encode_renew(xdr, args->clientid, &hdr);
2759 encode_nops(&hdr);
2760}
2761
Benny Halevy99fe60d2009-04-01 09:22:29 -04002762#if defined(CONFIG_NFS_V4_1)
2763/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002764 * BIND_CONN_TO_SESSION request
2765 */
2766static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2767 struct xdr_stream *xdr,
2768 struct nfs_client *clp)
2769{
2770 struct compound_hdr hdr = {
2771 .minorversion = clp->cl_mvops->minor_version,
2772 };
2773
2774 encode_compound_hdr(xdr, req, &hdr);
2775 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2776 encode_nops(&hdr);
2777}
2778
2779/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002780 * EXCHANGE_ID request
2781 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002782static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2783 struct xdr_stream *xdr,
2784 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002785{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002786 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002787 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002788 };
2789
Chuck Lever9f06c712010-12-14 14:59:18 +00002790 encode_compound_hdr(xdr, req, &hdr);
2791 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002792 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002793}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002794
2795/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002796 * a CREATE_SESSION request
2797 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002798static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2799 struct xdr_stream *xdr,
2800 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002801{
Andy Adamsonfc931582009-04-01 09:22:31 -04002802 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002803 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002804 };
2805
Chuck Lever9f06c712010-12-14 14:59:18 +00002806 encode_compound_hdr(xdr, req, &hdr);
2807 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002808 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002809}
2810
2811/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002812 * a DESTROY_SESSION request
2813 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002814static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2815 struct xdr_stream *xdr,
2816 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002817{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002818 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002819 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002820 };
2821
Chuck Lever9f06c712010-12-14 14:59:18 +00002822 encode_compound_hdr(xdr, req, &hdr);
2823 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002824 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002825}
2826
2827/*
Trond Myklebust66245532012-05-25 17:18:09 -04002828 * a DESTROY_CLIENTID request
2829 */
2830static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2831 struct xdr_stream *xdr,
2832 struct nfs_client *clp)
2833{
2834 struct compound_hdr hdr = {
2835 .minorversion = clp->cl_mvops->minor_version,
2836 };
2837
2838 encode_compound_hdr(xdr, req, &hdr);
2839 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2840 encode_nops(&hdr);
2841}
2842
2843/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002844 * a SEQUENCE request
2845 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002846static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2847 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002848{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002849 struct compound_hdr hdr = {
2850 .minorversion = nfs4_xdr_minorversion(args),
2851 };
2852
Chuck Lever9f06c712010-12-14 14:59:18 +00002853 encode_compound_hdr(xdr, req, &hdr);
2854 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002855 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002856}
2857
2858/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002859 * a GET_LEASE_TIME request
2860 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002861static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2862 struct xdr_stream *xdr,
2863 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002864{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002865 struct compound_hdr hdr = {
2866 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2867 };
Fred Isamandae100c2011-07-30 20:52:37 -04002868 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002869
Chuck Lever9f06c712010-12-14 14:59:18 +00002870 encode_compound_hdr(xdr, req, &hdr);
2871 encode_sequence(xdr, &args->la_seq_args, &hdr);
2872 encode_putrootfh(xdr, &hdr);
2873 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002874 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002875}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002876
2877/*
2878 * a RECLAIM_COMPLETE request
2879 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002880static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2881 struct xdr_stream *xdr,
2882 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002883{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002884 struct compound_hdr hdr = {
2885 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2886 };
2887
Chuck Lever9f06c712010-12-14 14:59:18 +00002888 encode_compound_hdr(xdr, req, &hdr);
2889 encode_sequence(xdr, &args->seq_args, &hdr);
2890 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002891 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002892}
2893
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002894/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002895 * Encode GETDEVICELIST request
2896 */
2897static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2898 struct xdr_stream *xdr,
2899 struct nfs4_getdevicelist_args *args)
2900{
2901 struct compound_hdr hdr = {
2902 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2903 };
2904
2905 encode_compound_hdr(xdr, req, &hdr);
2906 encode_sequence(xdr, &args->seq_args, &hdr);
2907 encode_putfh(xdr, args->fh, &hdr);
2908 encode_getdevicelist(xdr, args, &hdr);
2909 encode_nops(&hdr);
2910}
2911
2912/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002913 * Encode GETDEVICEINFO request
2914 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002915static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2916 struct xdr_stream *xdr,
2917 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002918{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002919 struct compound_hdr hdr = {
2920 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2921 };
2922
Chuck Lever9f06c712010-12-14 14:59:18 +00002923 encode_compound_hdr(xdr, req, &hdr);
2924 encode_sequence(xdr, &args->seq_args, &hdr);
2925 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002926
2927 /* set up reply kvec. Subtract notification bitmap max size (2)
2928 * so that notification bitmap is put in xdr_buf tail */
2929 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2930 args->pdev->pages, args->pdev->pgbase,
2931 args->pdev->pglen);
2932
2933 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002934}
2935
2936/*
2937 * Encode LAYOUTGET request
2938 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002939static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2940 struct xdr_stream *xdr,
2941 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002942{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002943 struct compound_hdr hdr = {
2944 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2945 };
2946
Chuck Lever9f06c712010-12-14 14:59:18 +00002947 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_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002951
2952 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2953 args->layout.pages, 0, args->layout.pglen);
2954
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002955 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002956}
Andy Adamson863a3c62011-03-23 13:27:54 +00002957
2958/*
2959 * Encode LAYOUTCOMMIT request
2960 */
Benny Halevycbe82602011-05-22 19:52:37 +03002961static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2962 struct xdr_stream *xdr,
2963 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002964{
Benny Halevyac7db722011-05-22 19:53:48 +03002965 struct nfs4_layoutcommit_data *data =
2966 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002967 struct compound_hdr hdr = {
2968 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2969 };
2970
2971 encode_compound_hdr(xdr, req, &hdr);
2972 encode_sequence(xdr, &args->seq_args, &hdr);
2973 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002974 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002975 encode_getfattr(xdr, args->bitmask, &hdr);
2976 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002977}
2978
2979/*
2980 * Encode LAYOUTRETURN request
2981 */
2982static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2983 struct xdr_stream *xdr,
2984 struct nfs4_layoutreturn_args *args)
2985{
2986 struct compound_hdr hdr = {
2987 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2988 };
2989
2990 encode_compound_hdr(xdr, req, &hdr);
2991 encode_sequence(xdr, &args->seq_args, &hdr);
2992 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2993 encode_layoutreturn(xdr, args, &hdr);
2994 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002995}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002996
2997/*
2998 * Encode SECINFO_NO_NAME request
2999 */
3000static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3001 struct xdr_stream *xdr,
3002 struct nfs41_secinfo_no_name_args *args)
3003{
3004 struct compound_hdr hdr = {
3005 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3006 };
3007
3008 encode_compound_hdr(xdr, req, &hdr);
3009 encode_sequence(xdr, &args->seq_args, &hdr);
3010 encode_putrootfh(xdr, &hdr);
3011 encode_secinfo_no_name(xdr, args, &hdr);
3012 encode_nops(&hdr);
3013 return 0;
3014}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003015
3016/*
3017 * Encode TEST_STATEID request
3018 */
3019static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3020 struct xdr_stream *xdr,
3021 struct nfs41_test_stateid_args *args)
3022{
3023 struct compound_hdr hdr = {
3024 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3025 };
3026
3027 encode_compound_hdr(xdr, req, &hdr);
3028 encode_sequence(xdr, &args->seq_args, &hdr);
3029 encode_test_stateid(xdr, args, &hdr);
3030 encode_nops(&hdr);
3031}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003032
3033/*
3034 * Encode FREE_STATEID request
3035 */
3036static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3037 struct xdr_stream *xdr,
3038 struct nfs41_free_stateid_args *args)
3039{
3040 struct compound_hdr hdr = {
3041 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3042 };
3043
3044 encode_compound_hdr(xdr, req, &hdr);
3045 encode_sequence(xdr, &args->seq_args, &hdr);
3046 encode_free_stateid(xdr, args, &hdr);
3047 encode_nops(&hdr);
3048}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003049#endif /* CONFIG_NFS_V4_1 */
3050
Benny Halevy686841b2009-08-14 17:19:48 +03003051static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3052{
3053 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3054 "Remaining buffer length is %tu words.\n",
3055 func, xdr->end - xdr->p);
3056}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
Trond Myklebust683b57b2006-06-09 09:34:22 -04003058static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
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
Benny Halevyc0eae662009-08-14 17:20:14 +03003062 p = xdr_inline_decode(xdr, 4);
3063 if (unlikely(!p))
3064 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003065 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003066 p = xdr_inline_decode(xdr, *len);
3067 if (unlikely(!p))
3068 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 *string = (char *)p;
3070 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003071out_overflow:
3072 print_overflow_msg(__func__, xdr);
3073 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074}
3075
3076static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3077{
Al Viro8687b632006-10-19 23:28:48 -07003078 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079
Benny Halevyc0eae662009-08-14 17:20:14 +03003080 p = xdr_inline_decode(xdr, 8);
3081 if (unlikely(!p))
3082 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003083 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003084 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003085
Benny Halevyc0eae662009-08-14 17:20:14 +03003086 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3087 if (unlikely(!p))
3088 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 hdr->tag = (char *)p;
3090 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003091 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003092 if (unlikely(hdr->nops < 1))
3093 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003095out_overflow:
3096 print_overflow_msg(__func__, xdr);
3097 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098}
3099
Trond Myklebustc7848f62013-12-04 17:39:23 -05003100static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3101 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102{
Al Viro8687b632006-10-19 23:28:48 -07003103 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 uint32_t opnum;
3105 int32_t nfserr;
3106
Benny Halevyc0eae662009-08-14 17:20:14 +03003107 p = xdr_inline_decode(xdr, 8);
3108 if (unlikely(!p))
3109 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003110 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003111 if (unlikely(opnum != expected))
3112 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003113 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003114 if (nfserr == NFS_OK)
3115 *nfs_retval = 0;
3116 else
3117 *nfs_retval = nfs4_stat_to_errno(nfserr);
3118 return true;
3119out_bad_operation:
3120 dprintk("nfs: Server returned operation"
3121 " %d but we issued a request for %d\n",
3122 opnum, expected);
3123 *nfs_retval = -EREMOTEIO;
3124 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003125out_overflow:
3126 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003127 *nfs_retval = -EIO;
3128 return false;
3129}
3130
3131static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3132{
3133 int retval;
3134
3135 __decode_op_hdr(xdr, expected, &retval);
3136 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137}
3138
3139/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003140static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141{
Al Viro8687b632006-10-19 23:28:48 -07003142 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003143 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 char *str;
3145
Benny Halevyc0eae662009-08-14 17:20:14 +03003146 p = xdr_inline_decode(xdr, 12);
3147 if (likely(p))
3148 return decode_opaque_inline(xdr, &strlen, &str);
3149 print_overflow_msg(__func__, xdr);
3150 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151}
3152
3153static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3154{
Al Viro8687b632006-10-19 23:28:48 -07003155 uint32_t bmlen;
3156 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157
Benny Halevyc0eae662009-08-14 17:20:14 +03003158 p = xdr_inline_decode(xdr, 4);
3159 if (unlikely(!p))
3160 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003161 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162
Fred Isamandae100c2011-07-30 20:52:37 -04003163 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003164 p = xdr_inline_decode(xdr, (bmlen << 2));
3165 if (unlikely(!p))
3166 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003168 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003169 if (bmlen > 1) {
3170 bitmap[1] = be32_to_cpup(p++);
3171 if (bmlen > 2)
3172 bitmap[2] = be32_to_cpup(p);
3173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 }
3175 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003176out_overflow:
3177 print_overflow_msg(__func__, xdr);
3178 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179}
3180
Trond Myklebust256e48b2012-06-21 11:18:13 -04003181static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182{
Al Viro8687b632006-10-19 23:28:48 -07003183 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184
Benny Halevyc0eae662009-08-14 17:20:14 +03003185 p = xdr_inline_decode(xdr, 4);
3186 if (unlikely(!p))
3187 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003188 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003189 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003191out_overflow:
3192 print_overflow_msg(__func__, xdr);
3193 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194}
3195
3196static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3197{
3198 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003199 int ret;
3200 ret = decode_attr_bitmap(xdr, bitmask);
3201 if (unlikely(ret < 0))
3202 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3204 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003205 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3206 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3207 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 return 0;
3209}
3210
3211static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3212{
Al Viro8687b632006-10-19 23:28:48 -07003213 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003214 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215
3216 *type = 0;
3217 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3218 return -EIO;
3219 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003220 p = xdr_inline_decode(xdr, 4);
3221 if (unlikely(!p))
3222 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003223 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003225 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 return -EIO;
3227 }
3228 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003229 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003231 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003232 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003233out_overflow:
3234 print_overflow_msg(__func__, xdr);
3235 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236}
3237
Chuck Lever264e6352012-03-01 17:02:05 -05003238static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3239 uint32_t *bitmap, uint32_t *type)
3240{
3241 __be32 *p;
3242
3243 *type = 0;
3244 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3245 return -EIO;
3246 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3247 p = xdr_inline_decode(xdr, 4);
3248 if (unlikely(!p))
3249 goto out_overflow;
3250 *type = be32_to_cpup(p);
3251 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3252 }
3253 dprintk("%s: expire type=0x%x\n", __func__, *type);
3254 return 0;
3255out_overflow:
3256 print_overflow_msg(__func__, xdr);
3257 return -EIO;
3258}
3259
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3261{
Al Viro8687b632006-10-19 23:28:48 -07003262 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003263 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264
3265 *change = 0;
3266 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3267 return -EIO;
3268 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003269 p = xdr_inline_decode(xdr, 8);
3270 if (unlikely(!p))
3271 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003272 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003274 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003276 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003278 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003279out_overflow:
3280 print_overflow_msg(__func__, xdr);
3281 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282}
3283
3284static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3285{
Al Viro8687b632006-10-19 23:28:48 -07003286 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003287 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288
3289 *size = 0;
3290 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3291 return -EIO;
3292 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003293 p = xdr_inline_decode(xdr, 8);
3294 if (unlikely(!p))
3295 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003296 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003298 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003300 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003301 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003302out_overflow:
3303 print_overflow_msg(__func__, xdr);
3304 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305}
3306
3307static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3308{
Al Viro8687b632006-10-19 23:28:48 -07003309 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310
3311 *res = 0;
3312 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3313 return -EIO;
3314 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003315 p = xdr_inline_decode(xdr, 4);
3316 if (unlikely(!p))
3317 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003318 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3320 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003321 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003323out_overflow:
3324 print_overflow_msg(__func__, xdr);
3325 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326}
3327
3328static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3329{
Al Viro8687b632006-10-19 23:28:48 -07003330 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331
3332 *res = 0;
3333 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3334 return -EIO;
3335 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003336 p = xdr_inline_decode(xdr, 4);
3337 if (unlikely(!p))
3338 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003339 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3341 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003342 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003344out_overflow:
3345 print_overflow_msg(__func__, xdr);
3346 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347}
3348
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003349static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350{
Al Viro8687b632006-10-19 23:28:48 -07003351 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003352 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353
3354 fsid->major = 0;
3355 fsid->minor = 0;
3356 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3357 return -EIO;
3358 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003359 p = xdr_inline_decode(xdr, 16);
3360 if (unlikely(!p))
3361 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003362 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003363 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003365 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003367 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 (unsigned long long)fsid->major,
3369 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003370 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003371out_overflow:
3372 print_overflow_msg(__func__, xdr);
3373 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374}
3375
3376static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3377{
Al Viro8687b632006-10-19 23:28:48 -07003378 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379
3380 *res = 60;
3381 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3382 return -EIO;
3383 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003384 p = xdr_inline_decode(xdr, 4);
3385 if (unlikely(!p))
3386 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003387 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3389 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003390 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003392out_overflow:
3393 print_overflow_msg(__func__, xdr);
3394 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395}
3396
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003397static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003398{
3399 __be32 *p;
3400
3401 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3402 return -EIO;
3403 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3404 p = xdr_inline_decode(xdr, 4);
3405 if (unlikely(!p))
3406 goto out_overflow;
3407 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003408 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003409 }
3410 return 0;
3411out_overflow:
3412 print_overflow_msg(__func__, xdr);
3413 return -EIO;
3414}
3415
3416static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3417{
3418 __be32 *p;
3419 int len;
3420
Trond Myklebust7ad07352010-10-23 15:34:20 -04003421 if (fh != NULL)
3422 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003423
3424 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3425 return -EIO;
3426 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3427 p = xdr_inline_decode(xdr, 4);
3428 if (unlikely(!p))
3429 goto out_overflow;
3430 len = be32_to_cpup(p);
3431 if (len > NFS4_FHSIZE)
3432 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003433 p = xdr_inline_decode(xdr, len);
3434 if (unlikely(!p))
3435 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003436 if (fh != NULL) {
3437 memcpy(fh->data, p, len);
3438 fh->size = len;
3439 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003440 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3441 }
3442 return 0;
3443out_overflow:
3444 print_overflow_msg(__func__, xdr);
3445 return -EIO;
3446}
3447
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3449{
Al Viro8687b632006-10-19 23:28:48 -07003450 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451
3452 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3453 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3454 return -EIO;
3455 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003456 p = xdr_inline_decode(xdr, 4);
3457 if (unlikely(!p))
3458 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003459 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3461 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003462 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003464out_overflow:
3465 print_overflow_msg(__func__, xdr);
3466 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467}
3468
3469static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3470{
Al Viro8687b632006-10-19 23:28:48 -07003471 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003472 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473
3474 *fileid = 0;
3475 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3476 return -EIO;
3477 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003478 p = xdr_inline_decode(xdr, 8);
3479 if (unlikely(!p))
3480 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003481 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003483 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003485 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003486 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003487out_overflow:
3488 print_overflow_msg(__func__, xdr);
3489 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490}
3491
Manoj Naik99baf622006-06-09 09:34:24 -04003492static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3493{
Al Viro8687b632006-10-19 23:28:48 -07003494 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003495 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003496
3497 *fileid = 0;
3498 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3499 return -EIO;
3500 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003501 p = xdr_inline_decode(xdr, 8);
3502 if (unlikely(!p))
3503 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003504 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003505 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003506 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003507 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003508 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003509 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003510out_overflow:
3511 print_overflow_msg(__func__, xdr);
3512 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003513}
3514
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3516{
Al Viro8687b632006-10-19 23:28:48 -07003517 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 int status = 0;
3519
3520 *res = 0;
3521 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3522 return -EIO;
3523 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003524 p = xdr_inline_decode(xdr, 8);
3525 if (unlikely(!p))
3526 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003527 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3529 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003530 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003532out_overflow:
3533 print_overflow_msg(__func__, xdr);
3534 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535}
3536
3537static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3538{
Al Viro8687b632006-10-19 23:28:48 -07003539 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 int status = 0;
3541
3542 *res = 0;
3543 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3544 return -EIO;
3545 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003546 p = xdr_inline_decode(xdr, 8);
3547 if (unlikely(!p))
3548 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003549 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3551 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003552 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003554out_overflow:
3555 print_overflow_msg(__func__, xdr);
3556 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557}
3558
3559static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3560{
Al Viro8687b632006-10-19 23:28:48 -07003561 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 int status = 0;
3563
3564 *res = 0;
3565 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3566 return -EIO;
3567 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003568 p = xdr_inline_decode(xdr, 8);
3569 if (unlikely(!p))
3570 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003571 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3573 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003574 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003576out_overflow:
3577 print_overflow_msg(__func__, xdr);
3578 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579}
3580
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003581static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3582{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003583 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003584 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003585 int status = 0;
3586
Benny Halevyc0eae662009-08-14 17:20:14 +03003587 p = xdr_inline_decode(xdr, 4);
3588 if (unlikely(!p))
3589 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003590 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003591 if (n == 0)
3592 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003593 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003594 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3595 dprintk("cannot parse %d components in path\n", n);
3596 goto out_eio;
3597 }
3598 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003599 struct nfs4_string *component = &path->components[path->ncomponents];
3600 status = decode_opaque_inline(xdr, &component->len, &component->data);
3601 if (unlikely(status != 0))
3602 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003603 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003604 pr_cont("%s%.*s ",
3605 (path->ncomponents != n ? "/ " : ""),
3606 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003607 }
3608out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003609 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003610root_path:
3611/* a root pathname is sent as a zero component4 */
3612 path->ncomponents = 1;
3613 path->components[0].len=0;
3614 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003615 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003616 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003617out_eio:
3618 dprintk(" status %d", status);
3619 status = -EIO;
3620 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003621out_overflow:
3622 print_overflow_msg(__func__, xdr);
3623 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003624}
3625
3626static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003627{
3628 int n;
Al Viro8687b632006-10-19 23:28:48 -07003629 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003630 int status = -EIO;
3631
3632 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3633 goto out;
3634 status = 0;
3635 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3636 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003637 status = -EIO;
3638 /* Ignore borken servers that return unrequested attrs */
3639 if (unlikely(res == NULL))
3640 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003641 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003642 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003643 if (unlikely(status != 0))
3644 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003645 p = xdr_inline_decode(xdr, 4);
3646 if (unlikely(!p))
3647 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003648 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003649 if (n <= 0)
3650 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003651 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003652 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003653 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003654
Trond Myklebust809b4262013-03-27 11:54:45 -04003655 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3656 break;
3657 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003658 p = xdr_inline_decode(xdr, 4);
3659 if (unlikely(!p))
3660 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003661 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003662
Chuck Lever02a29762012-03-01 17:00:31 -05003663 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003664 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3665 struct nfs4_string *server;
3666
3667 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003668 unsigned int i;
3669 dprintk("%s: using first %u of %u servers "
3670 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003671 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003672 NFS4_FS_LOCATION_MAXSERVERS,
3673 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003674 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003675 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003676 char *data;
3677 status = decode_opaque_inline(xdr, &len, &data);
3678 if (unlikely(status != 0))
3679 goto out_eio;
3680 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003681 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003682 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003683 server = &loc->servers[loc->nservers];
3684 status = decode_opaque_inline(xdr, &server->len, &server->data);
3685 if (unlikely(status != 0))
3686 goto out_eio;
3687 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003688 }
3689 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003690 if (unlikely(status != 0))
3691 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003692 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003693 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003694 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003695out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003696 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003697 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003698out_overflow:
3699 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003700out_eio:
3701 status = -EIO;
3702 goto out;
3703}
3704
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3706{
Al Viro8687b632006-10-19 23:28:48 -07003707 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 int status = 0;
3709
3710 *res = 0;
3711 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3712 return -EIO;
3713 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003714 p = xdr_inline_decode(xdr, 8);
3715 if (unlikely(!p))
3716 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003717 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3719 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003720 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003722out_overflow:
3723 print_overflow_msg(__func__, xdr);
3724 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725}
3726
3727static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3728{
Al Viro8687b632006-10-19 23:28:48 -07003729 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 int status = 0;
3731
3732 *maxlink = 1;
3733 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3734 return -EIO;
3735 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003736 p = xdr_inline_decode(xdr, 4);
3737 if (unlikely(!p))
3738 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003739 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3741 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003742 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003744out_overflow:
3745 print_overflow_msg(__func__, xdr);
3746 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747}
3748
3749static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3750{
Al Viro8687b632006-10-19 23:28:48 -07003751 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 int status = 0;
3753
3754 *maxname = 1024;
3755 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3756 return -EIO;
3757 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003758 p = xdr_inline_decode(xdr, 4);
3759 if (unlikely(!p))
3760 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003761 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3763 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003764 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003766out_overflow:
3767 print_overflow_msg(__func__, xdr);
3768 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769}
3770
3771static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3772{
Al Viro8687b632006-10-19 23:28:48 -07003773 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 int status = 0;
3775
3776 *res = 1024;
3777 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3778 return -EIO;
3779 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3780 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003781 p = xdr_inline_decode(xdr, 8);
3782 if (unlikely(!p))
3783 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003784 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 if (maxread > 0x7FFFFFFF)
3786 maxread = 0x7FFFFFFF;
3787 *res = (uint32_t)maxread;
3788 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3789 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003790 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003792out_overflow:
3793 print_overflow_msg(__func__, xdr);
3794 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795}
3796
3797static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3798{
Al Viro8687b632006-10-19 23:28:48 -07003799 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 int status = 0;
3801
3802 *res = 1024;
3803 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3804 return -EIO;
3805 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3806 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003807 p = xdr_inline_decode(xdr, 8);
3808 if (unlikely(!p))
3809 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003810 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811 if (maxwrite > 0x7FFFFFFF)
3812 maxwrite = 0x7FFFFFFF;
3813 *res = (uint32_t)maxwrite;
3814 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3815 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003816 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003818out_overflow:
3819 print_overflow_msg(__func__, xdr);
3820 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821}
3822
Trond Myklebustbca79472009-03-11 14:10:26 -04003823static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824{
Trond Myklebustbca79472009-03-11 14:10:26 -04003825 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003826 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003827 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828
3829 *mode = 0;
3830 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3831 return -EIO;
3832 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003833 p = xdr_inline_decode(xdr, 4);
3834 if (unlikely(!p))
3835 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003836 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003837 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003839 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003841 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003842 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003843out_overflow:
3844 print_overflow_msg(__func__, xdr);
3845 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846}
3847
3848static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3849{
Al Viro8687b632006-10-19 23:28:48 -07003850 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003851 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852
3853 *nlink = 1;
3854 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3855 return -EIO;
3856 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003857 p = xdr_inline_decode(xdr, 4);
3858 if (unlikely(!p))
3859 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003860 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003862 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003864 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
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_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003872 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003873 struct nfs4_string *owner_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 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3881 return -EIO;
3882 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
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 (owner_name != NULL) {
3891 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3892 if (owner_name->data != NULL) {
3893 owner_name->len = len;
3894 ret = NFS_ATTR_FATTR_OWNER_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_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003898 ret = NFS_ATTR_FATTR_OWNER;
3899 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900 dprintk("%s: nfs_map_name_to_uid 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;
3906 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003907 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
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
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003914static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003915 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003916 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917{
Al Viro8687b632006-10-19 23:28:48 -07003918 uint32_t len;
3919 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003920 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921
Eric W. Biedermane5782072013-02-01 14:22:02 -08003922 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3924 return -EIO;
3925 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003926 p = xdr_inline_decode(xdr, 4);
3927 if (unlikely(!p))
3928 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003929 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003930 p = xdr_inline_decode(xdr, len);
3931 if (unlikely(!p))
3932 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003933 if (group_name != NULL) {
3934 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3935 if (group_name->data != NULL) {
3936 group_name->len = len;
3937 ret = NFS_ATTR_FATTR_GROUP_NAME;
3938 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003939 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003940 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003941 ret = NFS_ATTR_FATTR_GROUP;
3942 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003944 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003946 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003947 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3949 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003950 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003951 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003952out_overflow:
3953 print_overflow_msg(__func__, xdr);
3954 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955}
3956
3957static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3958{
Al Viro8687b632006-10-19 23:28:48 -07003959 uint32_t major = 0, minor = 0;
3960 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003961 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962
3963 *rdev = MKDEV(0,0);
3964 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3965 return -EIO;
3966 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3967 dev_t tmp;
3968
Benny Halevyc0eae662009-08-14 17:20:14 +03003969 p = xdr_inline_decode(xdr, 8);
3970 if (unlikely(!p))
3971 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003972 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003973 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 tmp = MKDEV(major, minor);
3975 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3976 *rdev = tmp;
3977 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003978 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003980 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003981 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003982out_overflow:
3983 print_overflow_msg(__func__, xdr);
3984 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985}
3986
3987static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3988{
Al Viro8687b632006-10-19 23:28:48 -07003989 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 int status = 0;
3991
3992 *res = 0;
3993 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3994 return -EIO;
3995 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003996 p = xdr_inline_decode(xdr, 8);
3997 if (unlikely(!p))
3998 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003999 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4001 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004002 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004004out_overflow:
4005 print_overflow_msg(__func__, xdr);
4006 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007}
4008
4009static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4010{
Al Viro8687b632006-10-19 23:28:48 -07004011 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 int status = 0;
4013
4014 *res = 0;
4015 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4016 return -EIO;
4017 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004018 p = xdr_inline_decode(xdr, 8);
4019 if (unlikely(!p))
4020 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004021 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4023 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004024 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004026out_overflow:
4027 print_overflow_msg(__func__, xdr);
4028 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029}
4030
4031static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4032{
Al Viro8687b632006-10-19 23:28:48 -07004033 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 int status = 0;
4035
4036 *res = 0;
4037 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4038 return -EIO;
4039 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004040 p = xdr_inline_decode(xdr, 8);
4041 if (unlikely(!p))
4042 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004043 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4045 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004046 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 return status;
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_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4054{
Al Viro8687b632006-10-19 23:28:48 -07004055 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004056 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057
4058 *used = 0;
4059 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4060 return -EIO;
4061 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004062 p = xdr_inline_decode(xdr, 8);
4063 if (unlikely(!p))
4064 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004065 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004067 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004069 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004071 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004072out_overflow:
4073 print_overflow_msg(__func__, xdr);
4074 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075}
4076
4077static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4078{
Al Viro8687b632006-10-19 23:28:48 -07004079 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 uint64_t sec;
4081 uint32_t nsec;
4082
Benny Halevyc0eae662009-08-14 17:20:14 +03004083 p = xdr_inline_decode(xdr, 12);
4084 if (unlikely(!p))
4085 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004086 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004087 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088 time->tv_sec = (time_t)sec;
4089 time->tv_nsec = (long)nsec;
4090 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004091out_overflow:
4092 print_overflow_msg(__func__, xdr);
4093 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094}
4095
4096static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4097{
4098 int status = 0;
4099
4100 time->tv_sec = 0;
4101 time->tv_nsec = 0;
4102 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4103 return -EIO;
4104 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4105 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004106 if (status == 0)
4107 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4109 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004110 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 return status;
4112}
4113
4114static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4115{
4116 int status = 0;
4117
4118 time->tv_sec = 0;
4119 time->tv_nsec = 0;
4120 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4121 return -EIO;
4122 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4123 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004124 if (status == 0)
4125 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4127 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004128 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 return status;
4130}
4131
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004132static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4133 struct timespec *time)
4134{
4135 int status = 0;
4136
4137 time->tv_sec = 0;
4138 time->tv_nsec = 0;
4139 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4140 return -EIO;
4141 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4142 status = decode_attr_time(xdr, time);
4143 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4144 }
4145 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4146 (long)time->tv_nsec);
4147 return status;
4148}
4149
David Quigleyaa9c2662013-05-22 12:50:44 -04004150static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4151 struct nfs4_label *label)
4152{
4153 uint32_t pi = 0;
4154 uint32_t lfs = 0;
4155 __u32 len;
4156 __be32 *p;
4157 int status = 0;
4158
4159 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4160 return -EIO;
4161 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4162 p = xdr_inline_decode(xdr, 4);
4163 if (unlikely(!p))
4164 goto out_overflow;
4165 lfs = be32_to_cpup(p++);
4166 p = xdr_inline_decode(xdr, 4);
4167 if (unlikely(!p))
4168 goto out_overflow;
4169 pi = be32_to_cpup(p++);
4170 p = xdr_inline_decode(xdr, 4);
4171 if (unlikely(!p))
4172 goto out_overflow;
4173 len = be32_to_cpup(p++);
4174 p = xdr_inline_decode(xdr, len);
4175 if (unlikely(!p))
4176 goto out_overflow;
4177 if (len < NFS4_MAXLABELLEN) {
4178 if (label) {
4179 memcpy(label->label, p, len);
4180 label->len = len;
4181 label->pi = pi;
4182 label->lfs = lfs;
4183 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4184 }
4185 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4186 } else
4187 printk(KERN_WARNING "%s: label too long (%u)!\n",
4188 __func__, len);
4189 }
4190 if (label && label->label)
4191 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4192 (char *)label->label, label->len, label->pi, label->lfs);
4193 return status;
4194
4195out_overflow:
4196 print_overflow_msg(__func__, xdr);
4197 return -EIO;
4198}
4199
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4201{
4202 int status = 0;
4203
4204 time->tv_sec = 0;
4205 time->tv_nsec = 0;
4206 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4207 return -EIO;
4208 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4209 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004210 if (status == 0)
4211 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4213 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004214 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215 return status;
4216}
4217
Trond Myklebust256e48b2012-06-21 11:18:13 -04004218static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219{
4220 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004221 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222
4223 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004224 dprintk("%s: server returned incorrect attribute length: "
4225 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004226 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227 attrwords << 2,
4228 (attrwords < nwords) ? '<' : '>',
4229 nwords << 2);
4230 return -EIO;
4231 }
4232 return 0;
4233}
4234
4235static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4236{
Al Viro8687b632006-10-19 23:28:48 -07004237 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238
Benny Halevyc0eae662009-08-14 17:20:14 +03004239 p = xdr_inline_decode(xdr, 20);
4240 if (unlikely(!p))
4241 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004242 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004243 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004244 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004246out_overflow:
4247 print_overflow_msg(__func__, xdr);
4248 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249}
4250
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004251static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252{
Al Viro8687b632006-10-19 23:28:48 -07004253 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 uint32_t supp, acc;
4255 int status;
4256
4257 status = decode_op_hdr(xdr, OP_ACCESS);
4258 if (status)
4259 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004260 p = xdr_inline_decode(xdr, 8);
4261 if (unlikely(!p))
4262 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004263 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004264 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004265 *supported = supp;
4266 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004268out_overflow:
4269 print_overflow_msg(__func__, xdr);
4270 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271}
4272
Benny Halevy07d30432009-08-14 17:19:52 +03004273static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274{
Al Viro8687b632006-10-19 23:28:48 -07004275 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004276
4277 p = xdr_inline_decode(xdr, len);
4278 if (likely(p)) {
4279 memcpy(buf, p, len);
4280 return 0;
4281 }
4282 print_overflow_msg(__func__, xdr);
4283 return -EIO;
4284}
4285
4286static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4287{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004288 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289}
4290
4291static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4292{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 int status;
4294
4295 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004296 if (status != -EIO)
4297 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004298 if (!status)
4299 status = decode_stateid(xdr, &res->stateid);
4300 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301}
4302
Benny Halevydb942bb2009-08-14 17:19:56 +03004303static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4304{
Chuck Levercd937102012-03-02 17:14:31 -05004305 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306}
4307
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004308static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4309{
4310 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4311}
4312
Fred Isaman0b7c0152012-04-20 14:47:39 -04004313static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 int status;
4316
4317 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004318 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004319 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004320 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321}
4322
4323static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4324{
Al Viro8687b632006-10-19 23:28:48 -07004325 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 uint32_t bmlen;
4327 int status;
4328
4329 status = decode_op_hdr(xdr, OP_CREATE);
4330 if (status)
4331 return status;
4332 if ((status = decode_change_info(xdr, cinfo)))
4333 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004334 p = xdr_inline_decode(xdr, 4);
4335 if (unlikely(!p))
4336 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004337 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004338 p = xdr_inline_decode(xdr, bmlen << 2);
4339 if (likely(p))
4340 return 0;
4341out_overflow:
4342 print_overflow_msg(__func__, xdr);
4343 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344}
4345
4346static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4347{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004348 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004349 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 int status;
4351
4352 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4353 goto xdr_error;
4354 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4355 goto xdr_error;
4356 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4357 goto xdr_error;
4358 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4359 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004360 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4361 &res->fh_expire_type)) != 0)
4362 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4364 goto xdr_error;
4365 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4366 goto xdr_error;
4367 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4368 goto xdr_error;
4369 status = verify_attr_len(xdr, savep, attrlen);
4370xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004371 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372 return status;
4373}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004374
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4376{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004377 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004378 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004379 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004380
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4382 goto xdr_error;
4383 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4384 goto xdr_error;
4385 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4386 goto xdr_error;
4387
4388 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4389 goto xdr_error;
4390 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4391 goto xdr_error;
4392 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4393 goto xdr_error;
4394 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4395 goto xdr_error;
4396 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4397 goto xdr_error;
4398 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4399 goto xdr_error;
4400
4401 status = verify_attr_len(xdr, savep, attrlen);
4402xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004403 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 return status;
4405}
4406
4407static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4408{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004409 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004410 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004412
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4414 goto xdr_error;
4415 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4416 goto xdr_error;
4417 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4418 goto xdr_error;
4419
4420 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4421 goto xdr_error;
4422 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4423 goto xdr_error;
4424
4425 status = verify_attr_len(xdr, savep, attrlen);
4426xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004427 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428 return status;
4429}
4430
Andy Adamson88034c32012-05-23 05:02:34 -04004431static int decode_threshold_hint(struct xdr_stream *xdr,
4432 uint32_t *bitmap,
4433 uint64_t *res,
4434 uint32_t hint_bit)
4435{
4436 __be32 *p;
4437
4438 *res = 0;
4439 if (likely(bitmap[0] & hint_bit)) {
4440 p = xdr_inline_decode(xdr, 8);
4441 if (unlikely(!p))
4442 goto out_overflow;
4443 xdr_decode_hyper(p, res);
4444 }
4445 return 0;
4446out_overflow:
4447 print_overflow_msg(__func__, xdr);
4448 return -EIO;
4449}
4450
4451static int decode_first_threshold_item4(struct xdr_stream *xdr,
4452 struct nfs4_threshold *res)
4453{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004454 __be32 *p;
4455 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004456 uint32_t bitmap[3] = {0,}, attrlen;
4457 int status;
4458
4459 /* layout type */
4460 p = xdr_inline_decode(xdr, 4);
4461 if (unlikely(!p)) {
4462 print_overflow_msg(__func__, xdr);
4463 return -EIO;
4464 }
4465 res->l_type = be32_to_cpup(p);
4466
4467 /* thi_hintset bitmap */
4468 status = decode_attr_bitmap(xdr, bitmap);
4469 if (status < 0)
4470 goto xdr_error;
4471
4472 /* thi_hintlist length */
4473 status = decode_attr_length(xdr, &attrlen, &savep);
4474 if (status < 0)
4475 goto xdr_error;
4476 /* thi_hintlist */
4477 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4478 if (status < 0)
4479 goto xdr_error;
4480 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4481 if (status < 0)
4482 goto xdr_error;
4483 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4484 THRESHOLD_RD_IO);
4485 if (status < 0)
4486 goto xdr_error;
4487 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4488 THRESHOLD_WR_IO);
4489 if (status < 0)
4490 goto xdr_error;
4491
4492 status = verify_attr_len(xdr, savep, attrlen);
4493 res->bm = bitmap[0];
4494
4495 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4496 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4497 res->wr_io_sz);
4498xdr_error:
4499 dprintk("%s ret=%d!\n", __func__, status);
4500 return status;
4501}
4502
4503/*
4504 * Thresholds on pNFS direct I/O vrs MDS I/O
4505 */
4506static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4507 uint32_t *bitmap,
4508 struct nfs4_threshold *res)
4509{
4510 __be32 *p;
4511 int status = 0;
4512 uint32_t num;
4513
4514 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4515 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004516 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004517 /* Did the server return an unrequested attribute? */
4518 if (unlikely(res == NULL))
4519 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004520 p = xdr_inline_decode(xdr, 4);
4521 if (unlikely(!p))
4522 goto out_overflow;
4523 num = be32_to_cpup(p);
4524 if (num == 0)
4525 return 0;
4526 if (num > 1)
4527 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4528 "drivers per filesystem not supported\n",
4529 __func__);
4530
4531 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004532 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004533 }
4534 return status;
4535out_overflow:
4536 print_overflow_msg(__func__, xdr);
4537 return -EIO;
4538}
4539
Bryan Schumakerae42c702010-10-21 16:33:17 -04004540static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4541 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004542 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004543 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544{
Trond Myklebustbca79472009-03-11 14:10:26 -04004545 int status;
4546 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004547 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004548 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004550 status = decode_attr_type(xdr, bitmap, &type);
4551 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004553 fattr->mode = 0;
4554 if (status != 0) {
4555 fattr->mode |= nfs_type2fmt[type];
4556 fattr->valid |= status;
4557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004559 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4560 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004562 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004563
4564 status = decode_attr_size(xdr, bitmap, &fattr->size);
4565 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004567 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004568
4569 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4570 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004572 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004573
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004574 err = 0;
4575 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004576 if (status < 0)
4577 goto xdr_error;
4578
4579 status = decode_attr_filehandle(xdr, bitmap, fh);
4580 if (status < 0)
4581 goto xdr_error;
4582
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004583 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
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
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004588 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004589 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004590 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_mode(xdr, bitmap, &fmode);
4594 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004596 if (status != 0) {
4597 fattr->mode |= fmode;
4598 fattr->valid |= status;
4599 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004600
4601 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4602 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004604 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004605
Trond Myklebust6926afd2012-01-07 13:22:46 -05004606 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004607 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004609 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004610
Trond Myklebust6926afd2012-01-07 13:22:46 -05004611 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004612 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004614 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004615
4616 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4617 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004619 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004620
4621 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4622 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004624 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004625
4626 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4627 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004629 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004630
4631 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4632 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004634 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004635
4636 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4637 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004639 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004640
Trond Myklebust28331a42011-04-27 13:47:52 -04004641 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004642 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004643 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004644 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004645
Andy Adamson88034c32012-05-23 05:02:34 -04004646 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4647 if (status < 0)
4648 goto xdr_error;
4649
David Quigleyaa9c2662013-05-22 12:50:44 -04004650 if (label) {
4651 status = decode_attr_security_label(xdr, bitmap, label);
4652 if (status < 0)
4653 goto xdr_error;
4654 fattr->valid |= status;
4655 }
4656
Bryan Schumakerae42c702010-10-21 16:33:17 -04004657xdr_error:
4658 dprintk("%s: xdr returned %d\n", __func__, -status);
4659 return status;
4660}
4661
4662static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004663 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004664 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004665{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004666 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004667 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004668 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004669 int status;
4670
4671 status = decode_op_hdr(xdr, OP_GETATTR);
4672 if (status < 0)
4673 goto xdr_error;
4674
4675 status = decode_attr_bitmap(xdr, bitmap);
4676 if (status < 0)
4677 goto xdr_error;
4678
4679 status = decode_attr_length(xdr, &attrlen, &savep);
4680 if (status < 0)
4681 goto xdr_error;
4682
David Quigleyaa9c2662013-05-22 12:50:44 -04004683 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4684 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004685 if (status < 0)
4686 goto xdr_error;
4687
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004688 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004690 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691 return status;
4692}
4693
David Quigleyaa9c2662013-05-22 12:50:44 -04004694static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4695 struct nfs4_label *label, const struct nfs_server *server)
4696{
4697 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4698}
4699
Bryan Schumakerae42c702010-10-21 16:33:17 -04004700static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004701 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004702{
David Quigleyaa9c2662013-05-22 12:50:44 -04004703 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004704}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705
Andy Adamson504913f2010-10-20 00:17:57 -04004706/*
4707 * Decode potentially multiple layout types. Currently we only support
4708 * one layout driver per file system.
4709 */
4710static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4711 uint32_t *layouttype)
4712{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004713 __be32 *p;
Andy Adamson504913f2010-10-20 00:17:57 -04004714 int num;
4715
4716 p = xdr_inline_decode(xdr, 4);
4717 if (unlikely(!p))
4718 goto out_overflow;
4719 num = be32_to_cpup(p);
4720
4721 /* pNFS is not supported by the underlying file system */
4722 if (num == 0) {
4723 *layouttype = 0;
4724 return 0;
4725 }
4726 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004727 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4728 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004729
4730 /* Decode and set first layout type, move xdr->p past unused types */
4731 p = xdr_inline_decode(xdr, num * 4);
4732 if (unlikely(!p))
4733 goto out_overflow;
4734 *layouttype = be32_to_cpup(p);
4735 return 0;
4736out_overflow:
4737 print_overflow_msg(__func__, xdr);
4738 return -EIO;
4739}
4740
4741/*
4742 * The type of file system exported.
4743 * Note we must ensure that layouttype is set in any non-error case.
4744 */
4745static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4746 uint32_t *layouttype)
4747{
4748 int status = 0;
4749
4750 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4751 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4752 return -EIO;
4753 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4754 status = decode_first_pnfs_layout_type(xdr, layouttype);
4755 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4756 } else
4757 *layouttype = 0;
4758 return status;
4759}
4760
Fred Isamandae100c2011-07-30 20:52:37 -04004761/*
4762 * The prefered block size for layout directed io
4763 */
4764static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4765 uint32_t *res)
4766{
4767 __be32 *p;
4768
4769 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4770 *res = 0;
4771 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4772 p = xdr_inline_decode(xdr, 4);
4773 if (unlikely(!p)) {
4774 print_overflow_msg(__func__, xdr);
4775 return -EIO;
4776 }
4777 *res = be32_to_cpup(p);
4778 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4779 }
4780 return 0;
4781}
4782
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4784{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004785 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004786 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 int status;
4788
4789 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4790 goto xdr_error;
4791 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4792 goto xdr_error;
4793 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4794 goto xdr_error;
4795
4796 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4797
4798 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4799 goto xdr_error;
4800 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4801 goto xdr_error;
4802 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4803 goto xdr_error;
4804 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4805 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4806 goto xdr_error;
4807 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004808 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4809 if (status != 0)
4810 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004811 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4812 if (status != 0)
4813 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004814 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4815 if (status)
4816 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817
4818 status = verify_attr_len(xdr, savep, attrlen);
4819xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004820 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821 return status;
4822}
4823
4824static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4825{
Al Viro8687b632006-10-19 23:28:48 -07004826 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827 uint32_t len;
4828 int status;
4829
Trond Myklebust99367812007-07-17 21:52:41 -04004830 /* Zero handle first to allow comparisons */
4831 memset(fh, 0, sizeof(*fh));
4832
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833 status = decode_op_hdr(xdr, OP_GETFH);
4834 if (status)
4835 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836
Benny Halevyc0eae662009-08-14 17:20:14 +03004837 p = xdr_inline_decode(xdr, 4);
4838 if (unlikely(!p))
4839 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004840 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 if (len > NFS4_FHSIZE)
4842 return -EIO;
4843 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004844 p = xdr_inline_decode(xdr, len);
4845 if (unlikely(!p))
4846 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004847 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004849out_overflow:
4850 print_overflow_msg(__func__, xdr);
4851 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852}
4853
4854static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4855{
4856 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004857
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858 status = decode_op_hdr(xdr, OP_LINK);
4859 if (status)
4860 return status;
4861 return decode_change_info(xdr, cinfo);
4862}
4863
4864/*
4865 * We create the owner, so we know a proper owner.id length is 4.
4866 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004867static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004869 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004870 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004871 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004873 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004874 if (unlikely(!p))
4875 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004876 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004877 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004878 type = be32_to_cpup(p++); /* 4 byte read */
4879 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004880 fl->fl_start = (loff_t)offset;
4881 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4882 if (length == ~(uint64_t)0)
4883 fl->fl_end = OFFSET_MAX;
4884 fl->fl_type = F_WRLCK;
4885 if (type & 1)
4886 fl->fl_type = F_RDLCK;
4887 fl->fl_pid = 0;
4888 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004889 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4890 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4891 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004892 if (likely(p))
4893 return -NFS4ERR_DENIED;
4894out_overflow:
4895 print_overflow_msg(__func__, xdr);
4896 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897}
4898
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004899static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 int status;
4902
4903 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004904 if (status == -EIO)
4905 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004907 status = decode_stateid(xdr, &res->stateid);
4908 if (unlikely(status))
4909 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004911 status = decode_lock_denied(xdr, NULL);
4912 if (res->open_seqid != NULL)
4913 nfs_increment_open_seqid(status, res->open_seqid);
4914 nfs_increment_lock_seqid(status, res->lock_seqid);
4915out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916 return status;
4917}
4918
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004919static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920{
4921 int status;
4922 status = decode_op_hdr(xdr, OP_LOCKT);
4923 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004924 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925 return status;
4926}
4927
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004928static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004929{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004930 int status;
4931
4932 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004933 if (status != -EIO)
4934 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004935 if (status == 0)
4936 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937 return status;
4938}
4939
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004940static int decode_release_lockowner(struct xdr_stream *xdr)
4941{
4942 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4943}
4944
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945static int decode_lookup(struct xdr_stream *xdr)
4946{
4947 return decode_op_hdr(xdr, OP_LOOKUP);
4948}
4949
4950/* This is too sick! */
4951static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4952{
Andy Adamson05d564f2008-12-23 16:06:15 -05004953 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 uint32_t limit_type, nblocks, blocksize;
4955
Benny Halevyc0eae662009-08-14 17:20:14 +03004956 p = xdr_inline_decode(xdr, 12);
4957 if (unlikely(!p))
4958 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004959 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004961 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004962 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004963 break;
4964 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004965 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004966 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004967 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968 }
4969 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004970out_overflow:
4971 print_overflow_msg(__func__, xdr);
4972 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973}
4974
4975static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4976{
Andy Adamson05d564f2008-12-23 16:06:15 -05004977 __be32 *p;
4978 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004979 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980
Benny Halevyc0eae662009-08-14 17:20:14 +03004981 p = xdr_inline_decode(xdr, 4);
4982 if (unlikely(!p))
4983 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004984 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4986 res->delegation_type = 0;
4987 return 0;
4988 }
Benny Halevy07d30432009-08-14 17:19:52 +03004989 status = decode_stateid(xdr, &res->delegation);
4990 if (unlikely(status))
4991 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004992 p = xdr_inline_decode(xdr, 4);
4993 if (unlikely(!p))
4994 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004995 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004996
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004998 case NFS4_OPEN_DELEGATE_READ:
4999 res->delegation_type = FMODE_READ;
5000 break;
5001 case NFS4_OPEN_DELEGATE_WRITE:
5002 res->delegation_type = FMODE_WRITE|FMODE_READ;
5003 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004 return -EIO;
5005 }
David Howells7539bba2006-08-22 20:06:09 -04005006 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03005007out_overflow:
5008 print_overflow_msg(__func__, xdr);
5009 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010}
5011
5012static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5013{
Andy Adamson05d564f2008-12-23 16:06:15 -05005014 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005015 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005016 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005017
Trond Myklebustc7848f62013-12-04 17:39:23 -05005018 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5019 return status;
5020 nfs_increment_open_seqid(status, res->seqid);
5021 if (status)
5022 return status;
5023 status = decode_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005024 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005025 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026
Andy Adamson05d564f2008-12-23 16:06:15 -05005027 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028
Benny Halevyc0eae662009-08-14 17:20:14 +03005029 p = xdr_inline_decode(xdr, 8);
5030 if (unlikely(!p))
5031 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005032 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005033 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005034 if (bmlen > 10)
5035 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036
Benny Halevyc0eae662009-08-14 17:20:14 +03005037 p = xdr_inline_decode(xdr, bmlen << 2);
5038 if (unlikely(!p))
5039 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005040 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5041 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005042 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005043 for (; i < NFS4_BITMAP_SIZE; i++)
5044 res->attrset[i] = 0;
5045
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 return decode_delegation(xdr, res);
5047xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005048 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005050out_overflow:
5051 print_overflow_msg(__func__, xdr);
5052 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053}
5054
5055static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5056{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057 int status;
5058
Andy Adamson05d564f2008-12-23 16:06:15 -05005059 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005060 if (status != -EIO)
5061 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005062 if (!status)
5063 status = decode_stateid(xdr, &res->stateid);
5064 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065}
5066
5067static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5068{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 int status;
5070
5071 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005072 if (status != -EIO)
5073 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005074 if (!status)
5075 status = decode_stateid(xdr, &res->stateid);
5076 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077}
5078
5079static int decode_putfh(struct xdr_stream *xdr)
5080{
5081 return decode_op_hdr(xdr, OP_PUTFH);
5082}
5083
5084static int decode_putrootfh(struct xdr_stream *xdr)
5085{
5086 return decode_op_hdr(xdr, OP_PUTROOTFH);
5087}
5088
5089static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
5090{
Al Viro8687b632006-10-19 23:28:48 -07005091 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005092 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093 int status;
5094
5095 status = decode_op_hdr(xdr, OP_READ);
5096 if (status)
5097 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005098 p = xdr_inline_decode(xdr, 8);
5099 if (unlikely(!p))
5100 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005101 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005102 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005103 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005105 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106 "count %u > recvd %u\n", count, recvd);
5107 count = recvd;
5108 eof = 0;
5109 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005110 res->eof = eof;
5111 res->count = count;
5112 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005113out_overflow:
5114 print_overflow_msg(__func__, xdr);
5115 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116}
5117
5118static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5119{
Chuck Leverbcecff72007-10-26 13:32:03 -04005120 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005121 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122
5123 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005124 if (!status)
5125 status = decode_verifier(xdr, readdir->verifier.data);
5126 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005128 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005129 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005130 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005131 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132}
5133
5134static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5135{
5136 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005137 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005138 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139 int status;
5140
5141 status = decode_op_hdr(xdr, OP_READLINK);
5142 if (status)
5143 return status;
5144
5145 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005146 p = xdr_inline_decode(xdr, 4);
5147 if (unlikely(!p))
5148 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005149 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005150 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005151 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152 return -ENAMETOOLONG;
5153 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005154 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005156 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 "count %u > recvd %u\n", len, recvd);
5158 return -EIO;
5159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160 /*
5161 * The XDR encode routine has set things up so that
5162 * the link text will be copied directly into the
5163 * buffer. We just have to do overflow-checking,
5164 * and and null-terminate the text (the VFS expects
5165 * null-termination).
5166 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005167 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005169out_overflow:
5170 print_overflow_msg(__func__, xdr);
5171 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172}
5173
5174static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5175{
5176 int status;
5177
5178 status = decode_op_hdr(xdr, OP_REMOVE);
5179 if (status)
5180 goto out;
5181 status = decode_change_info(xdr, cinfo);
5182out:
5183 return status;
5184}
5185
5186static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5187 struct nfs4_change_info *new_cinfo)
5188{
5189 int status;
5190
5191 status = decode_op_hdr(xdr, OP_RENAME);
5192 if (status)
5193 goto out;
5194 if ((status = decode_change_info(xdr, old_cinfo)))
5195 goto out;
5196 status = decode_change_info(xdr, new_cinfo);
5197out:
5198 return status;
5199}
5200
5201static int decode_renew(struct xdr_stream *xdr)
5202{
5203 return decode_op_hdr(xdr, OP_RENEW);
5204}
5205
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005206static int
5207decode_restorefh(struct xdr_stream *xdr)
5208{
5209 return decode_op_hdr(xdr, OP_RESTOREFH);
5210}
5211
J. Bruce Fields029d1052005-06-22 17:16:22 +00005212static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005213 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005214{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005215 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005216 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005217 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005218 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005219 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005220
Andy Adamsonbf118a32011-12-07 11:55:27 -05005221 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005222 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5223 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005224
Trond Myklebust519d3952012-08-14 17:30:10 -04005225 xdr_enter_page(xdr, xdr->buf->page_len);
5226
Trond Myklebustcff298c2012-08-14 17:14:17 -04005227 /* Calculate the offset of the page data */
5228 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005229
J. Bruce Fields029d1052005-06-22 17:16:22 +00005230 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5231 goto out;
5232 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5233 goto out;
5234
5235 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5236 return -EIO;
5237 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005238
Andy Adamsonbf118a32011-12-07 11:55:27 -05005239 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5240 * are stored with the acl data to handle the problem of
5241 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005242 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005243 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005244
5245 /* Check for receive buffer overflow */
5246 if (res->acl_len > (xdr->nwords << 2) ||
5247 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5248 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005249 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005250 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005251 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005252 } else
5253 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005254
5255out:
5256 return status;
5257}
5258
Linus Torvalds1da177e2005-04-16 15:20:36 -07005259static int
5260decode_savefh(struct xdr_stream *xdr)
5261{
5262 return decode_op_hdr(xdr, OP_SAVEFH);
5263}
5264
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005265static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266{
Al Viro8687b632006-10-19 23:28:48 -07005267 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005268 uint32_t bmlen;
5269 int status;
5270
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 status = decode_op_hdr(xdr, OP_SETATTR);
5272 if (status)
5273 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005274 p = xdr_inline_decode(xdr, 4);
5275 if (unlikely(!p))
5276 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005277 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005278 p = xdr_inline_decode(xdr, bmlen << 2);
5279 if (likely(p))
5280 return 0;
5281out_overflow:
5282 print_overflow_msg(__func__, xdr);
5283 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284}
5285
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005286static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287{
Al Viro8687b632006-10-19 23:28:48 -07005288 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005289 uint32_t opnum;
5290 int32_t nfserr;
5291
Benny Halevyc0eae662009-08-14 17:20:14 +03005292 p = xdr_inline_decode(xdr, 8);
5293 if (unlikely(!p))
5294 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005295 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005297 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005298 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299 return -EIO;
5300 }
Benny Halevycccddf42009-08-14 17:20:19 +03005301 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005303 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5304 if (unlikely(!p))
5305 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005306 p = xdr_decode_hyper(p, &res->clientid);
5307 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308 } else if (nfserr == NFSERR_CLID_INUSE) {
5309 uint32_t len;
5310
5311 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005312 p = xdr_inline_decode(xdr, 4);
5313 if (unlikely(!p))
5314 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005315 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005316 p = xdr_inline_decode(xdr, len);
5317 if (unlikely(!p))
5318 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319
5320 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005321 p = xdr_inline_decode(xdr, 4);
5322 if (unlikely(!p))
5323 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005324 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005325 p = xdr_inline_decode(xdr, len);
5326 if (unlikely(!p))
5327 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005328 return -NFSERR_CLID_INUSE;
5329 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005330 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005331
5332 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005333out_overflow:
5334 print_overflow_msg(__func__, xdr);
5335 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336}
5337
5338static int decode_setclientid_confirm(struct xdr_stream *xdr)
5339{
5340 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5341}
5342
5343static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5344{
Al Viro8687b632006-10-19 23:28:48 -07005345 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005346 int status;
5347
5348 status = decode_op_hdr(xdr, OP_WRITE);
5349 if (status)
5350 return status;
5351
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005352 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005353 if (unlikely(!p))
5354 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005355 res->count = be32_to_cpup(p++);
5356 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005357 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005358out_overflow:
5359 print_overflow_msg(__func__, xdr);
5360 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361}
5362
5363static int decode_delegreturn(struct xdr_stream *xdr)
5364{
5365 return decode_op_hdr(xdr, OP_DELEGRETURN);
5366}
5367
Chuck Leverfb15b262013-03-16 15:54:34 -04005368static int decode_secinfo_gss(struct xdr_stream *xdr,
5369 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005370{
Chuck Leverfb15b262013-03-16 15:54:34 -04005371 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005372 __be32 *p;
5373
5374 p = xdr_inline_decode(xdr, 4);
5375 if (unlikely(!p))
5376 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005377 oid_len = be32_to_cpup(p);
5378 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005379 goto out_err;
5380
Chuck Leverfb15b262013-03-16 15:54:34 -04005381 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005382 if (unlikely(!p))
5383 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005384 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5385 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005386
5387 p = xdr_inline_decode(xdr, 8);
5388 if (unlikely(!p))
5389 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005390 flavor->flavor_info.qop = be32_to_cpup(p++);
5391 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005392
5393 return 0;
5394
5395out_overflow:
5396 print_overflow_msg(__func__, xdr);
5397 return -EIO;
5398out_err:
5399 return -EINVAL;
5400}
5401
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005402static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005403{
Chuck Leverfb15b262013-03-16 15:54:34 -04005404 struct nfs4_secinfo4 *sec_flavor;
5405 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005406 int status;
5407 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005408
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005409 p = xdr_inline_decode(xdr, 4);
5410 if (unlikely(!p))
5411 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005412
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005413 res->flavors->num_flavors = 0;
5414 num_flavors = be32_to_cpup(p);
5415
5416 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005417 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005418 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005419 break;
5420
5421 p = xdr_inline_decode(xdr, 4);
5422 if (unlikely(!p))
5423 goto out_overflow;
5424 sec_flavor->flavor = be32_to_cpup(p);
5425
5426 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005427 status = decode_secinfo_gss(xdr, sec_flavor);
5428 if (status)
5429 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005430 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005431 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005432 }
5433
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005434 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005435out:
5436 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005437out_overflow:
5438 print_overflow_msg(__func__, xdr);
5439 return -EIO;
5440}
5441
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005442static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5443{
5444 int status = decode_op_hdr(xdr, OP_SECINFO);
5445 if (status)
5446 return status;
5447 return decode_secinfo_common(xdr, res);
5448}
5449
Benny Halevy99fe60d2009-04-01 09:22:29 -04005450#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005451static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5452{
5453 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5454 if (status)
5455 return status;
5456 return decode_secinfo_common(xdr, res);
5457}
5458
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005459static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5460{
5461 __be32 *p;
5462 uint32_t bitmap_words;
5463 unsigned int i;
5464
5465 p = xdr_inline_decode(xdr, 4);
5466 bitmap_words = be32_to_cpup(p++);
5467 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5468 return -EIO;
5469 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5470 for (i = 0; i < bitmap_words; i++)
5471 op_map->u.words[i] = be32_to_cpup(p++);
5472
5473 return 0;
5474}
5475
Benny Halevy99fe60d2009-04-01 09:22:29 -04005476static int decode_exchange_id(struct xdr_stream *xdr,
5477 struct nfs41_exchange_id_res *res)
5478{
5479 __be32 *p;
5480 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005481 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005482 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005483 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005484
5485 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5486 if (status)
5487 return status;
5488
Benny Halevyc0eae662009-08-14 17:20:14 +03005489 p = xdr_inline_decode(xdr, 8);
5490 if (unlikely(!p))
5491 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005492 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005493 p = xdr_inline_decode(xdr, 12);
5494 if (unlikely(!p))
5495 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005496 res->seqid = be32_to_cpup(p++);
5497 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005498
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005499 res->state_protect.how = be32_to_cpup(p);
5500 switch (res->state_protect.how) {
5501 case SP4_NONE:
5502 break;
5503 case SP4_MACH_CRED:
5504 status = decode_op_map(xdr, &res->state_protect.enforce);
5505 if (status)
5506 return status;
5507 status = decode_op_map(xdr, &res->state_protect.allow);
5508 if (status)
5509 return status;
5510 break;
5511 default:
5512 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005513 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005514 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005515
Chuck Leveracdeb692012-05-21 22:46:16 -04005516 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005517 p = xdr_inline_decode(xdr, 8);
5518 if (unlikely(!p))
5519 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005520 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005521
Chuck Leveracdeb692012-05-21 22:46:16 -04005522 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005523 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5524 if (unlikely(status))
5525 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005526 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5527 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005528 memcpy(res->server_owner->major_id, dummy_str, dummy);
5529 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005530
Chuck Leveracdeb692012-05-21 22:46:16 -04005531 /* server_scope4 */
5532 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5533 if (unlikely(status))
5534 return status;
5535 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5536 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005537 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5538 res->server_scope->server_scope_sz = dummy;
5539
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005540 /* Implementation Id */
5541 p = xdr_inline_decode(xdr, 4);
5542 if (unlikely(!p))
5543 goto out_overflow;
5544 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005545
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005546 if (impl_id_count) {
5547 /* nii_domain */
5548 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5549 if (unlikely(status))
5550 return status;
5551 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5552 return -EIO;
5553 memcpy(res->impl_id->domain, dummy_str, dummy);
5554
5555 /* nii_name */
5556 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5557 if (unlikely(status))
5558 return status;
5559 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5560 return -EIO;
5561 memcpy(res->impl_id->name, dummy_str, dummy);
5562
5563 /* nii_date */
5564 p = xdr_inline_decode(xdr, 12);
5565 if (unlikely(!p))
5566 goto out_overflow;
5567 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5568 res->impl_id->date.nseconds = be32_to_cpup(p);
5569
5570 /* if there's more than one entry, ignore the rest */
5571 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005572 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005573out_overflow:
5574 print_overflow_msg(__func__, xdr);
5575 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005576}
Andy Adamsonfc931582009-04-01 09:22:31 -04005577
5578static int decode_chan_attrs(struct xdr_stream *xdr,
5579 struct nfs4_channel_attrs *attrs)
5580{
5581 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005582 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005583
Benny Halevyc0eae662009-08-14 17:20:14 +03005584 p = xdr_inline_decode(xdr, 28);
5585 if (unlikely(!p))
5586 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005587 val = be32_to_cpup(p++); /* headerpadsz */
5588 if (val)
5589 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005590 attrs->max_rqst_sz = be32_to_cpup(p++);
5591 attrs->max_resp_sz = be32_to_cpup(p++);
5592 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5593 attrs->max_ops = be32_to_cpup(p++);
5594 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005595 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005596 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005597 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5598 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005599 return -EINVAL;
5600 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005601 if (nr_attrs == 1) {
5602 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5603 if (unlikely(!p))
5604 goto out_overflow;
5605 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005606 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005607out_overflow:
5608 print_overflow_msg(__func__, xdr);
5609 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005610}
5611
Benny Halevye78291e2009-08-14 17:20:00 +03005612static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5613{
5614 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005615}
5616
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005617static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5618 struct nfs41_bind_conn_to_session_res *res)
5619{
5620 __be32 *p;
5621 int status;
5622
5623 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5624 if (!status)
5625 status = decode_sessionid(xdr, &res->session->sess_id);
5626 if (unlikely(status))
5627 return status;
5628
5629 /* dir flags, rdma mode bool */
5630 p = xdr_inline_decode(xdr, 8);
5631 if (unlikely(!p))
5632 goto out_overflow;
5633
5634 res->dir = be32_to_cpup(p++);
5635 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5636 return -EIO;
5637 if (be32_to_cpup(p) == 0)
5638 res->use_conn_in_rdma_mode = false;
5639 else
5640 res->use_conn_in_rdma_mode = true;
5641
5642 return 0;
5643out_overflow:
5644 print_overflow_msg(__func__, xdr);
5645 return -EIO;
5646}
5647
Andy Adamsonfc931582009-04-01 09:22:31 -04005648static int decode_create_session(struct xdr_stream *xdr,
5649 struct nfs41_create_session_res *res)
5650{
5651 __be32 *p;
5652 int status;
5653 struct nfs_client *clp = res->client;
5654 struct nfs4_session *session = clp->cl_session;
5655
5656 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005657 if (!status)
5658 status = decode_sessionid(xdr, &session->sess_id);
5659 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005660 return status;
5661
Andy Adamsonfc931582009-04-01 09:22:31 -04005662 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005663 p = xdr_inline_decode(xdr, 8);
5664 if (unlikely(!p))
5665 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005666 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005667 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005668
5669 /* Channel attributes */
5670 status = decode_chan_attrs(xdr, &session->fc_attrs);
5671 if (!status)
5672 status = decode_chan_attrs(xdr, &session->bc_attrs);
5673 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005674out_overflow:
5675 print_overflow_msg(__func__, xdr);
5676 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005677}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005678
5679static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5680{
5681 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5682}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005683
Trond Myklebust66245532012-05-25 17:18:09 -04005684static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5685{
5686 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5687}
5688
Ricardo Labiaga180197532009-12-05 16:08:40 -05005689static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5690{
5691 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5692}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005693#endif /* CONFIG_NFS_V4_1 */
5694
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005695static int decode_sequence(struct xdr_stream *xdr,
5696 struct nfs4_sequence_res *res,
5697 struct rpc_rqst *rqstp)
5698{
5699#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005700 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005701 struct nfs4_sessionid id;
5702 u32 dummy;
5703 int status;
5704 __be32 *p;
5705
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005706 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005707 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005708 if (!res->sr_slot->table->session)
5709 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005710
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005711 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005712 if (!status)
5713 status = decode_sessionid(xdr, &id);
5714 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005715 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005716
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005717 /*
5718 * If the server returns different values for sessionID, slotID or
5719 * sequence number, the server is looney tunes.
5720 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005721 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005722 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005723
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005724 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005725 NFS4_MAX_SESSIONID_LEN)) {
5726 dprintk("%s Invalid session id\n", __func__);
5727 goto out_err;
5728 }
Benny Halevye78291e2009-08-14 17:20:00 +03005729
Benny Halevyc0eae662009-08-14 17:20:14 +03005730 p = xdr_inline_decode(xdr, 20);
5731 if (unlikely(!p))
5732 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005733
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005734 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005735 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005736 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005737 dprintk("%s Invalid sequence number\n", __func__);
5738 goto out_err;
5739 }
5740 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005741 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005742 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005743 dprintk("%s Invalid slot id\n", __func__);
5744 goto out_err;
5745 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005746 /* highest slot id */
5747 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005748 /* target highest slot id */
5749 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005750 /* result flags */
5751 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005752 status = 0;
5753out_err:
5754 res->sr_status = status;
5755 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005756out_overflow:
5757 print_overflow_msg(__func__, xdr);
5758 status = -EIO;
5759 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005760#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005761 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005762#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005763}
5764
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005765#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005766/*
5767 * TODO: Need to handle case when EOF != true;
5768 */
5769static int decode_getdevicelist(struct xdr_stream *xdr,
5770 struct pnfs_devicelist *res)
5771{
5772 __be32 *p;
5773 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005774 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005775
5776 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5777 if (status)
5778 return status;
5779
5780 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5781 if (unlikely(!p))
5782 goto out_overflow;
5783
5784 /* TODO: Skip cookie for now */
5785 p += 2;
5786
5787 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005788 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005789
5790 res->num_devs = be32_to_cpup(p);
5791
5792 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5793
5794 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005795 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005796 __func__, res->num_devs);
5797 return -EIO;
5798 }
5799
5800 p = xdr_inline_decode(xdr,
5801 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5802 if (unlikely(!p))
5803 goto out_overflow;
5804 for (i = 0; i < res->num_devs; i++)
5805 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5806 NFS4_DEVICEID4_SIZE);
5807 res->eof = be32_to_cpup(p);
5808 return 0;
5809out_overflow:
5810 print_overflow_msg(__func__, xdr);
5811 return -EIO;
5812}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005813
5814static int decode_getdeviceinfo(struct xdr_stream *xdr,
5815 struct pnfs_device *pdev)
5816{
5817 __be32 *p;
5818 uint32_t len, type;
5819 int status;
5820
5821 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5822 if (status) {
5823 if (status == -ETOOSMALL) {
5824 p = xdr_inline_decode(xdr, 4);
5825 if (unlikely(!p))
5826 goto out_overflow;
5827 pdev->mincount = be32_to_cpup(p);
5828 dprintk("%s: Min count too small. mincnt = %u\n",
5829 __func__, pdev->mincount);
5830 }
5831 return status;
5832 }
5833
5834 p = xdr_inline_decode(xdr, 8);
5835 if (unlikely(!p))
5836 goto out_overflow;
5837 type = be32_to_cpup(p++);
5838 if (type != pdev->layout_type) {
5839 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5840 __func__, pdev->layout_type, type);
5841 return -EINVAL;
5842 }
5843 /*
5844 * Get the length of the opaque device_addr4. xdr_read_pages places
5845 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5846 * and places the remaining xdr data in xdr_buf->tail
5847 */
5848 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005849 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5850 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005851
5852 /* Parse notification bitmap, verifying that it is zero. */
5853 p = xdr_inline_decode(xdr, 4);
5854 if (unlikely(!p))
5855 goto out_overflow;
5856 len = be32_to_cpup(p);
5857 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005858 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005859
5860 p = xdr_inline_decode(xdr, 4 * len);
5861 if (unlikely(!p))
5862 goto out_overflow;
5863 for (i = 0; i < len; i++, p++) {
5864 if (be32_to_cpup(p)) {
5865 dprintk("%s: notifications not supported\n",
5866 __func__);
5867 return -EIO;
5868 }
5869 }
5870 }
5871 return 0;
5872out_overflow:
5873 print_overflow_msg(__func__, xdr);
5874 return -EIO;
5875}
5876
5877static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5878 struct nfs4_layoutget_res *res)
5879{
5880 __be32 *p;
5881 int status;
5882 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005883 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005884
5885 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5886 if (status)
5887 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005888 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005889 if (unlikely(!p))
5890 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005891 res->return_on_close = be32_to_cpup(p);
5892 decode_stateid(xdr, &res->stateid);
5893 p = xdr_inline_decode(xdr, 4);
5894 if (unlikely(!p))
5895 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005896 layout_count = be32_to_cpup(p);
5897 if (!layout_count) {
5898 dprintk("%s: server responded with empty layout array\n",
5899 __func__);
5900 return -EINVAL;
5901 }
5902
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005903 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005904 if (unlikely(!p))
5905 goto out_overflow;
5906 p = xdr_decode_hyper(p, &res->range.offset);
5907 p = xdr_decode_hyper(p, &res->range.length);
5908 res->range.iomode = be32_to_cpup(p++);
5909 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005910 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005911
5912 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5913 __func__,
5914 (unsigned long)res->range.offset,
5915 (unsigned long)res->range.length,
5916 res->range.iomode,
5917 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005918 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005919
Trond Myklebust64bd5772012-06-20 22:35:05 -04005920 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005921 if (res->layoutp->len > recvd) {
5922 dprintk("NFS: server cheating in layoutget reply: "
5923 "layout len %u > recvd %u\n",
5924 res->layoutp->len, recvd);
5925 return -EINVAL;
5926 }
5927
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005928 if (layout_count > 1) {
5929 /* We only handle a length one array at the moment. Any
5930 * further entries are just ignored. Note that this means
5931 * the client may see a response that is less than the
5932 * minimum it requested.
5933 */
5934 dprintk("%s: server responded with %d layouts, dropping tail\n",
5935 __func__, layout_count);
5936 }
5937
5938 return 0;
5939out_overflow:
5940 print_overflow_msg(__func__, xdr);
5941 return -EIO;
5942}
Andy Adamson863a3c62011-03-23 13:27:54 +00005943
Benny Halevycbe82602011-05-22 19:52:37 +03005944static int decode_layoutreturn(struct xdr_stream *xdr,
5945 struct nfs4_layoutreturn_res *res)
5946{
5947 __be32 *p;
5948 int status;
5949
5950 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5951 if (status)
5952 return status;
5953 p = xdr_inline_decode(xdr, 4);
5954 if (unlikely(!p))
5955 goto out_overflow;
5956 res->lrs_present = be32_to_cpup(p);
5957 if (res->lrs_present)
5958 status = decode_stateid(xdr, &res->stateid);
5959 return status;
5960out_overflow:
5961 print_overflow_msg(__func__, xdr);
5962 return -EIO;
5963}
5964
Andy Adamson863a3c62011-03-23 13:27:54 +00005965static int decode_layoutcommit(struct xdr_stream *xdr,
5966 struct rpc_rqst *req,
5967 struct nfs4_layoutcommit_res *res)
5968{
5969 __be32 *p;
5970 __u32 sizechanged;
5971 int status;
5972
5973 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005974 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005975 if (status)
5976 return status;
5977
5978 p = xdr_inline_decode(xdr, 4);
5979 if (unlikely(!p))
5980 goto out_overflow;
5981 sizechanged = be32_to_cpup(p);
5982
5983 if (sizechanged) {
5984 /* throw away new size */
5985 p = xdr_inline_decode(xdr, 8);
5986 if (unlikely(!p))
5987 goto out_overflow;
5988 }
5989 return 0;
5990out_overflow:
5991 print_overflow_msg(__func__, xdr);
5992 return -EIO;
5993}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005994
5995static int decode_test_stateid(struct xdr_stream *xdr,
5996 struct nfs41_test_stateid_res *res)
5997{
5998 __be32 *p;
5999 int status;
6000 int num_res;
6001
6002 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6003 if (status)
6004 return status;
6005
6006 p = xdr_inline_decode(xdr, 4);
6007 if (unlikely(!p))
6008 goto out_overflow;
6009 num_res = be32_to_cpup(p++);
6010 if (num_res != 1)
6011 goto out;
6012
6013 p = xdr_inline_decode(xdr, 4);
6014 if (unlikely(!p))
6015 goto out_overflow;
6016 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006017
6018 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006019out_overflow:
6020 print_overflow_msg(__func__, xdr);
6021out:
6022 return -EIO;
6023}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006024
6025static int decode_free_stateid(struct xdr_stream *xdr,
6026 struct nfs41_free_stateid_res *res)
6027{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006028 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006029 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006030}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006031#endif /* CONFIG_NFS_V4_1 */
6032
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033/*
Benny Halevy49c25592008-12-23 16:06:16 -05006034 * END OF "GENERIC" DECODE ROUTINES.
6035 */
6036
6037/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006038 * Decode OPEN_DOWNGRADE response
6039 */
Chuck Leverbf269552010-12-14 14:59:29 +00006040static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6041 struct xdr_stream *xdr,
6042 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043{
Andy Adamson05d564f2008-12-23 16:06:15 -05006044 struct compound_hdr hdr;
6045 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046
Chuck Leverbf269552010-12-14 14:59:29 +00006047 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006048 if (status)
6049 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006050 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006051 if (status)
6052 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006053 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006054 if (status)
6055 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006056 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006057 if (status != 0)
6058 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006059 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006061 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062}
6063
6064/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065 * Decode ACCESS response
6066 */
Chuck Leverbf269552010-12-14 14:59:29 +00006067static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6068 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006069{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 struct compound_hdr hdr;
6071 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006072
Chuck Leverbf269552010-12-14 14:59:29 +00006073 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006074 if (status)
6075 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006076 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006077 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006079 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006080 if (status != 0)
6081 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006082 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006083 if (status != 0)
6084 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006085 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086out:
6087 return status;
6088}
6089
6090/*
6091 * Decode LOOKUP response
6092 */
Chuck Leverbf269552010-12-14 14:59:29 +00006093static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6094 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096 struct compound_hdr hdr;
6097 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006098
Chuck Leverbf269552010-12-14 14:59:29 +00006099 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006100 if (status)
6101 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006102 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006103 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006105 status = decode_putfh(xdr);
6106 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006108 status = decode_lookup(xdr);
6109 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006111 status = decode_getfh(xdr, res->fh);
6112 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006114 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006115out:
6116 return status;
6117}
6118
6119/*
6120 * Decode LOOKUP_ROOT response
6121 */
Chuck Leverbf269552010-12-14 14:59:29 +00006122static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6123 struct xdr_stream *xdr,
6124 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126 struct compound_hdr hdr;
6127 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006128
Chuck Leverbf269552010-12-14 14:59:29 +00006129 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006130 if (status)
6131 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006132 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006133 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006134 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006135 status = decode_putrootfh(xdr);
6136 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006138 status = decode_getfh(xdr, res->fh);
6139 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006140 status = decode_getfattr_label(xdr, res->fattr,
6141 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006142out:
6143 return status;
6144}
6145
6146/*
6147 * Decode REMOVE response
6148 */
Chuck Leverbf269552010-12-14 14:59:29 +00006149static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6150 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 struct compound_hdr hdr;
6153 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006154
Chuck Leverbf269552010-12-14 14:59:29 +00006155 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006156 if (status)
6157 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006158 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006159 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006161 status = decode_putfh(xdr);
6162 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006163 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006164 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006165out:
6166 return status;
6167}
6168
6169/*
6170 * Decode RENAME response
6171 */
Chuck Leverbf269552010-12-14 14:59:29 +00006172static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6173 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175 struct compound_hdr hdr;
6176 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006177
Chuck Leverbf269552010-12-14 14:59:29 +00006178 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006179 if (status)
6180 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006181 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006182 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006184 status = decode_putfh(xdr);
6185 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006187 status = decode_savefh(xdr);
6188 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006190 status = decode_putfh(xdr);
6191 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006193 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194out:
6195 return status;
6196}
6197
6198/*
6199 * Decode LINK response
6200 */
Chuck Leverbf269552010-12-14 14:59:29 +00006201static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6202 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204 struct compound_hdr hdr;
6205 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006206
Chuck Leverbf269552010-12-14 14:59:29 +00006207 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006208 if (status)
6209 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006210 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006211 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006213 status = decode_putfh(xdr);
6214 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006216 status = decode_savefh(xdr);
6217 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006219 status = decode_putfh(xdr);
6220 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006222 status = decode_link(xdr, &res->cinfo);
6223 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006224 goto out;
6225 /*
6226 * Note order: OP_LINK leaves the directory as the current
6227 * filehandle.
6228 */
Chuck Leverbf269552010-12-14 14:59:29 +00006229 status = decode_restorefh(xdr);
6230 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006231 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006232 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233out:
6234 return status;
6235}
6236
6237/*
6238 * Decode CREATE response
6239 */
Chuck Leverbf269552010-12-14 14:59:29 +00006240static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6241 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 struct compound_hdr hdr;
6244 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006245
Chuck Leverbf269552010-12-14 14:59:29 +00006246 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006247 if (status)
6248 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006250 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006252 status = decode_putfh(xdr);
6253 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006254 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_create(xdr, &res->dir_cinfo);
6256 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_getfh(xdr, res->fh);
6259 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006261 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262out:
6263 return status;
6264}
6265
6266/*
6267 * Decode SYMLINK response
6268 */
Chuck Leverbf269552010-12-14 14:59:29 +00006269static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6270 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271{
Chuck Leverbf269552010-12-14 14:59:29 +00006272 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273}
6274
6275/*
6276 * Decode GETATTR response
6277 */
Chuck Leverbf269552010-12-14 14:59:29 +00006278static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6279 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281 struct compound_hdr hdr;
6282 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006283
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285 if (status)
6286 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006287 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006288 if (status)
6289 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006290 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006291 if (status)
6292 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006293 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294out:
6295 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296}
6297
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006298/*
6299 * Encode an SETACL request
6300 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006301static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6302 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006303{
Andy Adamson05d564f2008-12-23 16:06:15 -05006304 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006305 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006306 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006307
Chuck Lever9f06c712010-12-14 14:59:18 +00006308 encode_compound_hdr(xdr, req, &hdr);
6309 encode_sequence(xdr, &args->seq_args, &hdr);
6310 encode_putfh(xdr, args->fh, &hdr);
6311 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006312 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006313}
Andy Adamson05d564f2008-12-23 16:06:15 -05006314
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006315/*
6316 * Decode SETACL response
6317 */
6318static int
Chuck Leverbf269552010-12-14 14:59:29 +00006319nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006320 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006321{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006322 struct compound_hdr hdr;
6323 int status;
6324
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006326 if (status)
6327 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006329 if (status)
6330 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006332 if (status)
6333 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006334 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006335out:
6336 return status;
6337}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006338
6339/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006340 * Decode GETACL response
6341 */
6342static int
Chuck Leverbf269552010-12-14 14:59:29 +00006343nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006344 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006345{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006346 struct compound_hdr hdr;
6347 int status;
6348
Trond Myklebust331818f2012-02-03 18:30:53 -05006349 if (res->acl_scratch != NULL) {
6350 void *p = page_address(res->acl_scratch);
6351 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6352 }
Chuck Leverbf269552010-12-14 14:59:29 +00006353 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006354 if (status)
6355 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006356 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006357 if (status)
6358 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006359 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006360 if (status)
6361 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006362 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006363
6364out:
6365 return status;
6366}
6367
6368/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369 * Decode CLOSE response
6370 */
Chuck Leverbf269552010-12-14 14:59:29 +00006371static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6372 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373{
Andy Adamson05d564f2008-12-23 16:06:15 -05006374 struct compound_hdr hdr;
6375 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006376
Chuck Leverbf269552010-12-14 14:59:29 +00006377 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006378 if (status)
6379 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006380 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006381 if (status)
6382 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006383 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006384 if (status)
6385 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006386 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006387 if (status != 0)
6388 goto out;
6389 /*
6390 * Note: Server may do delete on close for this file
6391 * in which case the getattr call will fail with
6392 * an ESTALE error. Shouldn't be a problem,
6393 * though, since fattr->valid will remain unset.
6394 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006395 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006397 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398}
6399
6400/*
6401 * Decode OPEN response
6402 */
Chuck Leverbf269552010-12-14 14:59:29 +00006403static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6404 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405{
Andy Adamson05d564f2008-12-23 16:06:15 -05006406 struct compound_hdr hdr;
6407 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408
Chuck Leverbf269552010-12-14 14:59:29 +00006409 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006410 if (status)
6411 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006412 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006413 if (status)
6414 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006415 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006416 if (status)
6417 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006418 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006419 if (status)
6420 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006421 status = decode_getfh(xdr, &res->fh);
6422 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006423 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);
David Quigleyaa9c2662013-05-22 12:50:44 -04006426 decode_getfattr_label(xdr, res->f_attr, res->f_label, 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 OPEN_CONFIRM response
6433 */
Chuck Leverbf269552010-12-14 14:59:29 +00006434static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6435 struct xdr_stream *xdr,
6436 struct nfs_open_confirmres *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_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006445 if (status)
6446 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006447 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006449 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450}
6451
6452/*
6453 * Decode OPEN response
6454 */
Chuck Leverbf269552010-12-14 14:59:29 +00006455static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6456 struct xdr_stream *xdr,
6457 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458{
Andy Adamson05d564f2008-12-23 16:06:15 -05006459 struct compound_hdr hdr;
6460 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461
Chuck Leverbf269552010-12-14 14:59:29 +00006462 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006463 if (status)
6464 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006465 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006466 if (status)
6467 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006468 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006469 if (status)
6470 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006472 if (status)
6473 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006474 if (res->access_request)
6475 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006476 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006478 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479}
6480
6481/*
6482 * Decode SETATTR response
6483 */
Chuck Leverbf269552010-12-14 14:59:29 +00006484static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6485 struct xdr_stream *xdr,
6486 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487{
Andy Adamson05d564f2008-12-23 16:06:15 -05006488 struct compound_hdr hdr;
6489 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490
Chuck Leverbf269552010-12-14 14:59:29 +00006491 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006492 if (status)
6493 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006494 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006495 if (status)
6496 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006497 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006498 if (status)
6499 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006500 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006501 if (status)
6502 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006503 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006504out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006505 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506}
6507
6508/*
6509 * Decode LOCK response
6510 */
Chuck Leverbf269552010-12-14 14:59:29 +00006511static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6512 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006514 struct compound_hdr hdr;
6515 int status;
6516
Chuck Leverbf269552010-12-14 14:59:29 +00006517 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 if (status)
6519 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006520 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006521 if (status)
6522 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006523 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 if (status)
6525 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527out:
6528 return status;
6529}
6530
6531/*
6532 * Decode LOCKT response
6533 */
Chuck Leverbf269552010-12-14 14:59:29 +00006534static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6535 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537 struct compound_hdr hdr;
6538 int status;
6539
Chuck Leverbf269552010-12-14 14:59:29 +00006540 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541 if (status)
6542 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006543 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006544 if (status)
6545 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006546 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547 if (status)
6548 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006549 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006550out:
6551 return status;
6552}
6553
6554/*
6555 * Decode LOCKU response
6556 */
Chuck Leverbf269552010-12-14 14:59:29 +00006557static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6558 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006560 struct compound_hdr hdr;
6561 int status;
6562
Chuck Leverbf269552010-12-14 14:59:29 +00006563 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006564 if (status)
6565 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006566 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006567 if (status)
6568 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006569 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006570 if (status)
6571 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006572 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006573out:
6574 return status;
6575}
6576
Chuck Leverbf269552010-12-14 14:59:29 +00006577static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6578 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006579{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006580 struct compound_hdr hdr;
6581 int status;
6582
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006584 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006585 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006586 return status;
6587}
6588
Linus Torvalds1da177e2005-04-16 15:20:36 -07006589/*
6590 * Decode READLINK response
6591 */
Chuck Leverbf269552010-12-14 14:59:29 +00006592static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6593 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006594 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006596 struct compound_hdr hdr;
6597 int status;
6598
Chuck Leverbf269552010-12-14 14:59:29 +00006599 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006600 if (status)
6601 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006602 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006603 if (status)
6604 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006605 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 if (status)
6607 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006608 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006609out:
6610 return status;
6611}
6612
6613/*
6614 * Decode READDIR response
6615 */
Chuck Leverbf269552010-12-14 14:59:29 +00006616static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6617 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006618{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619 struct compound_hdr hdr;
6620 int status;
6621
Chuck Leverbf269552010-12-14 14:59:29 +00006622 status = decode_compound_hdr(xdr, &hdr);
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_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006632out:
6633 return status;
6634}
6635
6636/*
6637 * Decode Read response
6638 */
Chuck Leverbf269552010-12-14 14:59:29 +00006639static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6640 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006641{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642 struct compound_hdr hdr;
6643 int status;
6644
Chuck Leverbf269552010-12-14 14:59:29 +00006645 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006646 if (status)
6647 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006648 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006649 if (status)
6650 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006652 if (status)
6653 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006654 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655 if (!status)
6656 status = res->count;
6657out:
6658 return status;
6659}
6660
6661/*
6662 * Decode WRITE response
6663 */
Chuck Leverbf269552010-12-14 14:59:29 +00006664static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6665 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006667 struct compound_hdr hdr;
6668 int status;
6669
Chuck Leverbf269552010-12-14 14:59:29 +00006670 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006671 if (status)
6672 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006673 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006674 if (status)
6675 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006676 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677 if (status)
6678 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006679 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006680 if (status)
6681 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006682 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006683 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006684 if (!status)
6685 status = res->count;
6686out:
6687 return status;
6688}
6689
6690/*
6691 * Decode COMMIT response
6692 */
Chuck Leverbf269552010-12-14 14:59:29 +00006693static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006694 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006695{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006696 struct compound_hdr hdr;
6697 int status;
6698
Chuck Leverbf269552010-12-14 14:59:29 +00006699 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006700 if (status)
6701 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006702 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006703 if (status)
6704 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006705 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006706 if (status)
6707 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006708 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006709out:
6710 return status;
6711}
6712
6713/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006714 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006715 */
Chuck Leverbf269552010-12-14 14:59:29 +00006716static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006717 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006718{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006719 struct compound_hdr hdr;
6720 int status;
6721
Chuck Leverbf269552010-12-14 14:59:29 +00006722 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006724 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006725 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006726 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006727 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006729 return status;
6730}
6731
6732/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006733 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006734 */
Chuck Leverbf269552010-12-14 14:59:29 +00006735static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006736 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006737{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006738 struct compound_hdr hdr;
6739 int status;
6740
Chuck Leverbf269552010-12-14 14:59:29 +00006741 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006743 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006744 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006745 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006746 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006747 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006748 return status;
6749}
6750
6751/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006752 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753 */
Chuck Leverbf269552010-12-14 14:59:29 +00006754static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006755 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006756{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 struct compound_hdr hdr;
6758 int status;
6759
Chuck Leverbf269552010-12-14 14:59:29 +00006760 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006761 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006762 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006763 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006764 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006765 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006766 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006767 return status;
6768}
6769
6770/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006771 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006772 */
Chuck Leverbf269552010-12-14 14:59:29 +00006773static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6774 struct xdr_stream *xdr,
6775 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006776{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006777 struct compound_hdr hdr;
6778 int status;
6779
Chuck Leverbf269552010-12-14 14:59:29 +00006780 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006781 if (status)
6782 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006783 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006784 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006785 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006786 status = decode_putfh(xdr);
6787 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006788 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006789 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006790out:
6791 return status;
6792}
6793
6794/*
6795 * Decode RENEW response
6796 */
Chuck Leverbf269552010-12-14 14:59:29 +00006797static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6798 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006799{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006800 struct compound_hdr hdr;
6801 int status;
6802
Chuck Leverbf269552010-12-14 14:59:29 +00006803 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006804 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006805 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006806 return status;
6807}
6808
6809/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006810 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006811 */
Chuck Leverbf269552010-12-14 14:59:29 +00006812static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6813 struct xdr_stream *xdr,
6814 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006815{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006816 struct compound_hdr hdr;
6817 int status;
6818
Chuck Leverbf269552010-12-14 14:59:29 +00006819 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006820 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006821 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006822 return status;
6823}
6824
6825/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006826 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006827 */
Chuck Leverbf269552010-12-14 14:59:29 +00006828static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006829 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006830{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006831 struct compound_hdr hdr;
6832 int status;
6833
Chuck Leverbf269552010-12-14 14:59:29 +00006834 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006835 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006836 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006837 return status;
6838}
6839
6840/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006841 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006842 */
Chuck Leverbf269552010-12-14 14:59:29 +00006843static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6844 struct xdr_stream *xdr,
6845 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006846{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006847 struct compound_hdr hdr;
6848 int status;
6849
Chuck Leverbf269552010-12-14 14:59:29 +00006850 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006851 if (status)
6852 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006853 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006854 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006855 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006856 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006857 if (status != 0)
6858 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006859 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006860 if (status != 0)
6861 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006862 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006863out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006864 return status;
6865}
6866
Trond Myklebust683b57b2006-06-09 09:34:22 -04006867/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006868 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006869 */
Chuck Leverbf269552010-12-14 14:59:29 +00006870static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6871 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006872 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006873{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006874 struct compound_hdr hdr;
6875 int status;
6876
Chuck Leverbf269552010-12-14 14:59:29 +00006877 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006878 if (status)
6879 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006880 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006881 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006882 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006883 status = decode_putfh(xdr);
6884 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006885 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006886 if (res->migration) {
6887 xdr_enter_page(xdr, PAGE_SIZE);
6888 status = decode_getfattr_generic(xdr,
6889 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006890 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006891 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006892 if (status)
6893 goto out;
6894 if (res->renew)
6895 status = decode_renew(xdr);
6896 } else {
6897 status = decode_lookup(xdr);
6898 if (status)
6899 goto out;
6900 xdr_enter_page(xdr, PAGE_SIZE);
6901 status = decode_getfattr_generic(xdr,
6902 &res->fs_locations->fattr,
6903 NULL, res->fs_locations,
6904 NULL, res->fs_locations->server);
6905 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006906out:
6907 return status;
6908}
6909
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006910/*
6911 * Decode SECINFO response
6912 */
6913static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6914 struct xdr_stream *xdr,
6915 struct nfs4_secinfo_res *res)
6916{
6917 struct compound_hdr hdr;
6918 int status;
6919
6920 status = decode_compound_hdr(xdr, &hdr);
6921 if (status)
6922 goto out;
6923 status = decode_sequence(xdr, &res->seq_res, rqstp);
6924 if (status)
6925 goto out;
6926 status = decode_putfh(xdr);
6927 if (status)
6928 goto out;
6929 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006930out:
6931 return status;
6932}
6933
Chuck Lever44c99932013-10-17 14:13:30 -04006934/*
6935 * Decode FSID_PRESENT response
6936 */
6937static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
6938 struct xdr_stream *xdr,
6939 struct nfs4_fsid_present_res *res)
6940{
6941 struct compound_hdr hdr;
6942 int status;
6943
6944 status = decode_compound_hdr(xdr, &hdr);
6945 if (status)
6946 goto out;
6947 status = decode_sequence(xdr, &res->seq_res, rqstp);
6948 if (status)
6949 goto out;
6950 status = decode_putfh(xdr);
6951 if (status)
6952 goto out;
6953 status = decode_getfh(xdr, res->fh);
6954 if (status)
6955 goto out;
6956 if (res->renew)
6957 status = decode_renew(xdr);
6958out:
6959 return status;
6960}
6961
Benny Halevy99fe60d2009-04-01 09:22:29 -04006962#if defined(CONFIG_NFS_V4_1)
6963/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006964 * Decode BIND_CONN_TO_SESSION response
6965 */
6966static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6967 struct xdr_stream *xdr,
6968 void *res)
6969{
6970 struct compound_hdr hdr;
6971 int status;
6972
6973 status = decode_compound_hdr(xdr, &hdr);
6974 if (!status)
6975 status = decode_bind_conn_to_session(xdr, res);
6976 return status;
6977}
6978
6979/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006980 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006981 */
Chuck Leverbf269552010-12-14 14:59:29 +00006982static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6983 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006984 void *res)
6985{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006986 struct compound_hdr hdr;
6987 int status;
6988
Chuck Leverbf269552010-12-14 14:59:29 +00006989 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006990 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006991 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006992 return status;
6993}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006994
6995/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006996 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006997 */
Chuck Leverbf269552010-12-14 14:59:29 +00006998static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6999 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04007000 struct nfs41_create_session_res *res)
7001{
Andy Adamsonfc931582009-04-01 09:22:31 -04007002 struct compound_hdr hdr;
7003 int status;
7004
Chuck Leverbf269552010-12-14 14:59:29 +00007005 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007006 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007007 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007008 return status;
7009}
7010
7011/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007012 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007013 */
Chuck Leverbf269552010-12-14 14:59:29 +00007014static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7015 struct xdr_stream *xdr,
7016 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007017{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007018 struct compound_hdr hdr;
7019 int status;
7020
Chuck Leverbf269552010-12-14 14:59:29 +00007021 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007022 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007023 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007024 return status;
7025}
7026
7027/*
Trond Myklebust66245532012-05-25 17:18:09 -04007028 * Decode DESTROY_CLIENTID response
7029 */
7030static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7031 struct xdr_stream *xdr,
7032 void *res)
7033{
7034 struct compound_hdr hdr;
7035 int status;
7036
7037 status = decode_compound_hdr(xdr, &hdr);
7038 if (!status)
7039 status = decode_destroy_clientid(xdr, res);
7040 return status;
7041}
7042
7043/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007044 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007045 */
Chuck Leverbf269552010-12-14 14:59:29 +00007046static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7047 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007048 struct nfs4_sequence_res *res)
7049{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007050 struct compound_hdr hdr;
7051 int status;
7052
Chuck Leverbf269552010-12-14 14:59:29 +00007053 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007054 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007055 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007056 return status;
7057}
7058
7059/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007060 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007061 */
Chuck Leverbf269552010-12-14 14:59:29 +00007062static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7063 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007064 struct nfs4_get_lease_time_res *res)
7065{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007066 struct compound_hdr hdr;
7067 int status;
7068
Chuck Leverbf269552010-12-14 14:59:29 +00007069 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007070 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007071 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007072 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007073 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007074 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007075 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007076 return status;
7077}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007078
7079/*
7080 * Decode RECLAIM_COMPLETE response
7081 */
Chuck Leverbf269552010-12-14 14:59:29 +00007082static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7083 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007084 struct nfs41_reclaim_complete_res *res)
7085{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007086 struct compound_hdr hdr;
7087 int status;
7088
Chuck Leverbf269552010-12-14 14:59:29 +00007089 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007090 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007091 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007092 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007093 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007094 return status;
7095}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007096
7097/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007098 * Decode GETDEVICELIST response
7099 */
7100static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
7101 struct xdr_stream *xdr,
7102 struct nfs4_getdevicelist_res *res)
7103{
7104 struct compound_hdr hdr;
7105 int status;
7106
7107 dprintk("encoding getdevicelist!\n");
7108
7109 status = decode_compound_hdr(xdr, &hdr);
7110 if (status != 0)
7111 goto out;
7112 status = decode_sequence(xdr, &res->seq_res, rqstp);
7113 if (status != 0)
7114 goto out;
7115 status = decode_putfh(xdr);
7116 if (status != 0)
7117 goto out;
7118 status = decode_getdevicelist(xdr, res->devlist);
7119out:
7120 return status;
7121}
7122
7123/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007124 * Decode GETDEVINFO response
7125 */
Chuck Leverbf269552010-12-14 14:59:29 +00007126static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7127 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007128 struct nfs4_getdeviceinfo_res *res)
7129{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007130 struct compound_hdr hdr;
7131 int status;
7132
Chuck Leverbf269552010-12-14 14:59:29 +00007133 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007134 if (status != 0)
7135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007136 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007137 if (status != 0)
7138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007139 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007140out:
7141 return status;
7142}
7143
7144/*
7145 * Decode LAYOUTGET response
7146 */
Chuck Leverbf269552010-12-14 14:59:29 +00007147static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7148 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007149 struct nfs4_layoutget_res *res)
7150{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007151 struct compound_hdr hdr;
7152 int status;
7153
Chuck Leverbf269552010-12-14 14:59:29 +00007154 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007155 if (status)
7156 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007157 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007158 if (status)
7159 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007160 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007161 if (status)
7162 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007163 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007164out:
7165 return status;
7166}
Andy Adamson863a3c62011-03-23 13:27:54 +00007167
7168/*
Benny Halevycbe82602011-05-22 19:52:37 +03007169 * Decode LAYOUTRETURN response
7170 */
7171static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7172 struct xdr_stream *xdr,
7173 struct nfs4_layoutreturn_res *res)
7174{
7175 struct compound_hdr hdr;
7176 int status;
7177
7178 status = decode_compound_hdr(xdr, &hdr);
7179 if (status)
7180 goto out;
7181 status = decode_sequence(xdr, &res->seq_res, rqstp);
7182 if (status)
7183 goto out;
7184 status = decode_putfh(xdr);
7185 if (status)
7186 goto out;
7187 status = decode_layoutreturn(xdr, res);
7188out:
7189 return status;
7190}
7191
7192/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007193 * Decode LAYOUTCOMMIT response
7194 */
7195static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7196 struct xdr_stream *xdr,
7197 struct nfs4_layoutcommit_res *res)
7198{
7199 struct compound_hdr hdr;
7200 int status;
7201
7202 status = decode_compound_hdr(xdr, &hdr);
7203 if (status)
7204 goto out;
7205 status = decode_sequence(xdr, &res->seq_res, rqstp);
7206 if (status)
7207 goto out;
7208 status = decode_putfh(xdr);
7209 if (status)
7210 goto out;
7211 status = decode_layoutcommit(xdr, rqstp, res);
7212 if (status)
7213 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007214 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007215out:
7216 return status;
7217}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007218
7219/*
7220 * Decode SECINFO_NO_NAME response
7221 */
7222static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7223 struct xdr_stream *xdr,
7224 struct nfs4_secinfo_res *res)
7225{
7226 struct compound_hdr hdr;
7227 int status;
7228
7229 status = decode_compound_hdr(xdr, &hdr);
7230 if (status)
7231 goto out;
7232 status = decode_sequence(xdr, &res->seq_res, rqstp);
7233 if (status)
7234 goto out;
7235 status = decode_putrootfh(xdr);
7236 if (status)
7237 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007238 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007239out:
7240 return status;
7241}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007242
7243/*
7244 * Decode TEST_STATEID response
7245 */
7246static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7247 struct xdr_stream *xdr,
7248 struct nfs41_test_stateid_res *res)
7249{
7250 struct compound_hdr hdr;
7251 int status;
7252
7253 status = decode_compound_hdr(xdr, &hdr);
7254 if (status)
7255 goto out;
7256 status = decode_sequence(xdr, &res->seq_res, rqstp);
7257 if (status)
7258 goto out;
7259 status = decode_test_stateid(xdr, res);
7260out:
7261 return status;
7262}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007263
7264/*
7265 * Decode FREE_STATEID response
7266 */
7267static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7268 struct xdr_stream *xdr,
7269 struct nfs41_free_stateid_res *res)
7270{
7271 struct compound_hdr hdr;
7272 int status;
7273
7274 status = decode_compound_hdr(xdr, &hdr);
7275 if (status)
7276 goto out;
7277 status = decode_sequence(xdr, &res->seq_res, rqstp);
7278 if (status)
7279 goto out;
7280 status = decode_free_stateid(xdr, res);
7281out:
7282 return status;
7283}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007284#endif /* CONFIG_NFS_V4_1 */
7285
Chuck Lever573c4e12010-12-14 14:58:11 +00007286/**
7287 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7288 * the local page cache.
7289 * @xdr: XDR stream where entry resides
7290 * @entry: buffer to fill in with entry data
7291 * @plus: boolean indicating whether this should be a readdirplus entry
7292 *
7293 * Returns zero if successful, otherwise a negative errno value is
7294 * returned.
7295 *
7296 * This function is not invoked during READDIR reply decoding, but
7297 * rather whenever an application invokes the getdents(2) system call
7298 * on a directory already in our cache.
7299 */
7300int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7301 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007302{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007303 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007304 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007305 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007306 __be32 *p = xdr_inline_decode(xdr, 4);
7307 if (unlikely(!p))
7308 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007309 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007310 p = xdr_inline_decode(xdr, 4);
7311 if (unlikely(!p))
7312 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007313 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007314 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007315 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007316 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007317 }
7318
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007319 p = xdr_inline_decode(xdr, 12);
7320 if (unlikely(!p))
7321 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007322 entry->prev_cookie = entry->cookie;
7323 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007324 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007325
Trond Myklebust9af8c222010-10-24 11:52:55 -04007326 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007327 if (unlikely(!p))
7328 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007329 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007330
7331 /*
7332 * In case the server doesn't return an inode number,
7333 * we fake one here. (We don't use inode number 0,
7334 * since glibc seems to choke on it...)
7335 */
7336 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007337 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007338
Trond Myklebust9af8c222010-10-24 11:52:55 -04007339 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007340 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007341
Trond Myklebust256e48b2012-06-21 11:18:13 -04007342 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007343 goto out_overflow;
7344
Chuck Lever573c4e12010-12-14 14:58:11 +00007345 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007346 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007347 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007348 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7349 entry->ino = entry->fattr->mounted_on_fileid;
7350 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007351 entry->ino = entry->fattr->fileid;
7352
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007353 entry->d_type = DT_UNKNOWN;
7354 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7355 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7356
Chuck Lever573c4e12010-12-14 14:58:11 +00007357 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007358
7359out_overflow:
7360 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007361 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007362}
7363
7364/*
7365 * We need to translate between nfs status return values and
7366 * the local errno values which may not be the same.
7367 */
7368static struct {
7369 int stat;
7370 int errno;
7371} nfs_errtbl[] = {
7372 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007373 { NFS4ERR_PERM, -EPERM },
7374 { NFS4ERR_NOENT, -ENOENT },
7375 { NFS4ERR_IO, -errno_NFSERR_IO},
7376 { NFS4ERR_NXIO, -ENXIO },
7377 { NFS4ERR_ACCESS, -EACCES },
7378 { NFS4ERR_EXIST, -EEXIST },
7379 { NFS4ERR_XDEV, -EXDEV },
7380 { NFS4ERR_NOTDIR, -ENOTDIR },
7381 { NFS4ERR_ISDIR, -EISDIR },
7382 { NFS4ERR_INVAL, -EINVAL },
7383 { NFS4ERR_FBIG, -EFBIG },
7384 { NFS4ERR_NOSPC, -ENOSPC },
7385 { NFS4ERR_ROFS, -EROFS },
7386 { NFS4ERR_MLINK, -EMLINK },
7387 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7388 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7389 { NFS4ERR_DQUOT, -EDQUOT },
7390 { NFS4ERR_STALE, -ESTALE },
7391 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007392 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7393 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7394 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007395 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007396 { NFS4ERR_BADTYPE, -EBADTYPE },
7397 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007398 { NFS4ERR_SYMLINK, -ELOOP },
7399 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7400 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007401 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007402};
7403
7404/*
7405 * Convert an NFS error code to a local one.
7406 * This one is used jointly by NFSv2 and NFSv3.
7407 */
7408static int
David Howells0a8ea432006-08-22 20:06:08 -04007409nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007410{
7411 int i;
7412 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7413 if (nfs_errtbl[i].stat == stat)
7414 return nfs_errtbl[i].errno;
7415 }
7416 if (stat <= 10000 || stat > 10100) {
7417 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007418 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007419 }
7420 /* If we cannot translate the error, the recovery routines should
7421 * handle it.
7422 * Note: remaining NFSv4 error codes have values > 10000, so should
7423 * not conflict with native Linux error codes.
7424 */
Benny Halevy856dff32008-03-31 17:39:06 +03007425 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007426}
7427
Linus Torvalds1da177e2005-04-16 15:20:36 -07007428#define PROC(proc, argtype, restype) \
7429[NFSPROC4_CLNT_##proc] = { \
7430 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007431 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007432 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007433 .p_arglen = NFS4_##argtype##_sz, \
7434 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007435 .p_statidx = NFSPROC4_CLNT_##proc, \
7436 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007437}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007438
7439struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007440 PROC(READ, enc_read, dec_read),
7441 PROC(WRITE, enc_write, dec_write),
7442 PROC(COMMIT, enc_commit, dec_commit),
7443 PROC(OPEN, enc_open, dec_open),
7444 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7445 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7446 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7447 PROC(CLOSE, enc_close, dec_close),
7448 PROC(SETATTR, enc_setattr, dec_setattr),
7449 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7450 PROC(RENEW, enc_renew, dec_renew),
7451 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7452 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7453 PROC(LOCK, enc_lock, dec_lock),
7454 PROC(LOCKT, enc_lockt, dec_lockt),
7455 PROC(LOCKU, enc_locku, dec_locku),
7456 PROC(ACCESS, enc_access, dec_access),
7457 PROC(GETATTR, enc_getattr, dec_getattr),
7458 PROC(LOOKUP, enc_lookup, dec_lookup),
7459 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7460 PROC(REMOVE, enc_remove, dec_remove),
7461 PROC(RENAME, enc_rename, dec_rename),
7462 PROC(LINK, enc_link, dec_link),
7463 PROC(SYMLINK, enc_symlink, dec_symlink),
7464 PROC(CREATE, enc_create, dec_create),
7465 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7466 PROC(STATFS, enc_statfs, dec_statfs),
7467 PROC(READLINK, enc_readlink, dec_readlink),
7468 PROC(READDIR, enc_readdir, dec_readdir),
7469 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7470 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7471 PROC(GETACL, enc_getacl, dec_getacl),
7472 PROC(SETACL, enc_setacl, dec_setacl),
7473 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7474 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007475 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007476 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007477#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007478 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7479 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7480 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7481 PROC(SEQUENCE, enc_sequence, dec_sequence),
7482 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7483 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7484 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7485 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007486 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007487 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007488 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007489 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007490 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007491 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007492 PROC(BIND_CONN_TO_SESSION,
7493 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007494 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007495#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007496};
7497
Trond Myklebusta613fa12012-01-20 13:53:56 -05007498const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007499 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007500 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007501 .procs = nfs4_procedures
7502};
7503
7504/*
7505 * Local variables:
7506 * c-basic-offset: 8
7507 * End:
7508 */