blob: 727cfe080eae3ec1732d336dbb306b993ab20840 [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))
Andy Adamson88034c32012-05-23 05:02:34 -0400105/* We support only one layout type per file system */
106#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000107/* This is based on getfattr, which uses the most attributes: */
108#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400109 3 + 3 + 3 + nfs4_owner_maxsz + \
110 nfs4_group_maxsz + decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000111#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
112 nfs4_fattr_value_maxsz)
113#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400114#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
115 1 + 2 + 1 + \
116 nfs4_owner_maxsz + \
117 nfs4_group_maxsz + \
118 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#define encode_savefh_maxsz (op_encode_hdr_maxsz)
120#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400121#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
122#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200123#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400124/* The 5 accounts for the PNFS attributes, and assumes that at most three
125 * layout types will be returned.
126 */
127#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
128 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
130#define decode_renew_maxsz (op_decode_hdr_maxsz)
131#define encode_setclientid_maxsz \
132 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500133 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
134 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
135 1 /* sc_prog */ + \
136 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
137 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
138 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#define decode_setclientid_maxsz \
140 (op_decode_hdr_maxsz + \
141 2 + \
142 1024) /* large value for CLID_INUSE */
143#define encode_setclientid_confirm_maxsz \
144 (op_encode_hdr_maxsz + \
145 3 + (NFS4_VERIFIER_SIZE >> 2))
146#define decode_setclientid_confirm_maxsz \
147 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400148#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
149#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400150#define encode_share_access_maxsz \
151 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500152#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400153#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
154#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
155#define encode_open_maxsz (op_encode_hdr_maxsz + \
156 2 + encode_share_access_maxsz + 2 + \
157 open_owner_id_maxsz + \
158 encode_opentype_maxsz + \
159 encode_claim_null_maxsz)
160#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400161#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400162 decode_ace_maxsz)
163#define decode_change_info_maxsz (5)
164#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400165 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400166 decode_change_info_maxsz + 1 + \
167 nfs4_fattr_bitmap_maxsz + \
168 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400169#define encode_open_confirm_maxsz \
170 (op_encode_hdr_maxsz + \
171 encode_stateid_maxsz + 1)
172#define decode_open_confirm_maxsz \
173 (op_decode_hdr_maxsz + \
174 decode_stateid_maxsz)
175#define encode_open_downgrade_maxsz \
176 (op_encode_hdr_maxsz + \
177 encode_stateid_maxsz + 1 + \
178 encode_share_access_maxsz)
179#define decode_open_downgrade_maxsz \
180 (op_decode_hdr_maxsz + \
181 decode_stateid_maxsz)
182#define encode_close_maxsz (op_encode_hdr_maxsz + \
183 1 + encode_stateid_maxsz)
184#define decode_close_maxsz (op_decode_hdr_maxsz + \
185 decode_stateid_maxsz)
186#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + \
188 encode_attrs_maxsz)
189#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
190 nfs4_fattr_bitmap_maxsz)
191#define encode_read_maxsz (op_encode_hdr_maxsz + \
192 encode_stateid_maxsz + 3)
193#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
194#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
195 2 + encode_verifier_maxsz + 5)
196#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
197 decode_verifier_maxsz)
198#define encode_readlink_maxsz (op_encode_hdr_maxsz)
199#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
200#define encode_write_maxsz (op_encode_hdr_maxsz + \
201 encode_stateid_maxsz + 4)
202#define decode_write_maxsz (op_decode_hdr_maxsz + \
203 2 + decode_verifier_maxsz)
204#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
205#define decode_commit_maxsz (op_decode_hdr_maxsz + \
206 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#define encode_remove_maxsz (op_encode_hdr_maxsz + \
208 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400209#define decode_remove_maxsz (op_decode_hdr_maxsz + \
210 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211#define encode_rename_maxsz (op_encode_hdr_maxsz + \
212 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400213#define decode_rename_maxsz (op_decode_hdr_maxsz + \
214 decode_change_info_maxsz + \
215 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#define encode_link_maxsz (op_encode_hdr_maxsz + \
217 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400218#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400219#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400220#define encode_lock_maxsz (op_encode_hdr_maxsz + \
221 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400222 1 + encode_stateid_maxsz + 1 + \
223 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400224#define decode_lock_denied_maxsz \
225 (8 + decode_lockowner_maxsz)
226#define decode_lock_maxsz (op_decode_hdr_maxsz + \
227 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400228#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
229 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400230#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
231 decode_lock_denied_maxsz)
232#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
233 encode_stateid_maxsz + \
234 4)
235#define decode_locku_maxsz (op_decode_hdr_maxsz + \
236 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400237#define encode_release_lockowner_maxsz \
238 (op_encode_hdr_maxsz + \
239 encode_lockowner_maxsz)
240#define decode_release_lockowner_maxsz \
241 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400242#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
243#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
245 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400246 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000247 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
249#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400250 1 + 2 + nfs4_name_maxsz + \
251 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400252#define decode_create_maxsz (op_decode_hdr_maxsz + \
253 decode_change_info_maxsz + \
254 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400255#define encode_statfs_maxsz (encode_getattr_maxsz)
256#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
258#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400259#define encode_getacl_maxsz (encode_getattr_maxsz)
260#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
261 nfs4_fattr_bitmap_maxsz + 1)
262#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
263 encode_stateid_maxsz + 3)
264#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400265#define encode_fs_locations_maxsz \
266 (encode_getattr_maxsz)
267#define decode_fs_locations_maxsz \
268 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000269#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400270#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 -0400271
272#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400273#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500274#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
275 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400276
Benny Halevy99fe60d2009-04-01 09:22:29 -0400277#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
278 encode_verifier_maxsz + \
279 1 /* co_ownerid.len */ + \
280 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
281 1 /* flags */ + \
282 1 /* spa_how */ + \
283 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500284 1 /* implementation id array of size 1 */ + \
285 1 /* nii_domain */ + \
286 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
287 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500288 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500289 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400290#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
291 2 /* eir_clientid */ + \
292 1 /* eir_sequenceid */ + \
293 1 /* eir_flags */ + \
294 1 /* spr_how */ + \
295 0 /* SP4_NONE (for now) */ + \
296 2 /* eir_server_owner.so_minor_id */ + \
297 /* eir_server_owner.so_major_id<> */ \
298 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
299 /* eir_server_scope<> */ \
300 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
301 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500302 1 /* nii_domain */ + \
303 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
304 1 /* nii_name */ + \
305 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
306 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400307#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
308#define decode_channel_attrs_maxsz (6 + \
309 1 /* ca_rdma_ird.len */ + \
310 1 /* ca_rdma_ird */)
311#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
312 2 /* csa_clientid */ + \
313 1 /* csa_sequence */ + \
314 1 /* csa_flags */ + \
315 encode_channel_attrs_maxsz + \
316 encode_channel_attrs_maxsz + \
317 1 /* csa_cb_program */ + \
318 1 /* csa_sec_parms.len (1) */ + \
319 1 /* cb_secflavor (AUTH_SYS) */ + \
320 1 /* stamp */ + \
321 1 /* machinename.len */ + \
322 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
323 1 /* uid */ + \
324 1 /* gid */ + \
325 1 /* gids.len (0) */)
326#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
327 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
328 1 /* csr_sequence */ + \
329 1 /* csr_flags */ + \
330 decode_channel_attrs_maxsz + \
331 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400332#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
333 /* bctsa_sessid */ \
334 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
335 1 /* bctsa_dir */ + \
336 1 /* bctsa_use_conn_in_rdma_mode */)
337#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
338 /* bctsr_sessid */ \
339 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
340 1 /* bctsr_dir */ + \
341 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400342#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
343#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400344#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
345#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400346#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
347 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
348#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
349 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500350#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
351#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400352#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
353 encode_verifier_maxsz)
354#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
355 2 /* nfs_cookie4 gdlr_cookie */ + \
356 decode_verifier_maxsz \
357 /* verifier4 gdlr_verifier */ + \
358 1 /* gdlr_deviceid_list count */ + \
359 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
360 NFS4_DEVICEID4_SIZE) \
361 /* gdlr_deviceid_list */ + \
362 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400363#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
364 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
365#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
366 1 /* layout type */ + \
367 1 /* opaque devaddr4 length */ + \
368 /* devaddr4 payload is read into page */ \
369 1 /* notification bitmap length */ + \
370 1 /* notification bitmap */)
371#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
372 encode_stateid_maxsz)
373#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
374 decode_stateid_maxsz + \
375 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000376#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
377 2 /* offset */ + \
378 2 /* length */ + \
379 1 /* reclaim */ + \
380 encode_stateid_maxsz + \
381 1 /* new offset (true) */ + \
382 2 /* last byte written */ + \
383 1 /* nt_timechanged (false) */ + \
384 1 /* layoutupdate4 layout type */ + \
385 1 /* NULL filelayout layoutupdate4 payload */)
386#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300387#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
388 encode_stateid_maxsz + \
389 1 /* FIXME: opaque lrf_body always empty at the moment */)
390#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
391 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400392#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
393#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400394#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
395 XDR_QUADLEN(NFS4_STATEID_SIZE))
396#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400397#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
398 XDR_QUADLEN(NFS4_STATEID_SIZE))
399#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400#else /* CONFIG_NFS_V4_1 */
401#define encode_sequence_maxsz 0
402#define decode_sequence_maxsz 0
403#endif /* CONFIG_NFS_V4_1 */
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
406#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
407#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400410 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400416 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400418 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400420 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400422 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400424 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400426 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400430 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400434 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400435 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400439 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400440 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400444 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400448 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400450 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400451 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400452 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400453 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400454 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400455 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400457 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400458 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400459 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400460 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400461 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400462 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400463#define NFS4_enc_open_confirm_sz \
464 (compound_encode_hdr_maxsz + \
465 encode_putfh_maxsz + \
466 encode_open_confirm_maxsz)
467#define NFS4_dec_open_confirm_sz \
468 (compound_decode_hdr_maxsz + \
469 decode_putfh_maxsz + \
470 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400472 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400474 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400475 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400478 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400480 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400481 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400482 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#define NFS4_enc_open_downgrade_sz \
484 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 encode_putfh_maxsz + \
487 encode_open_downgrade_maxsz + \
488 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489#define NFS4_dec_open_downgrade_sz \
490 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400491 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400492 decode_putfh_maxsz + \
493 decode_open_downgrade_maxsz + \
494 decode_getattr_maxsz)
495#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400497 encode_putfh_maxsz + \
498 encode_close_maxsz + \
499 encode_getattr_maxsz)
500#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400501 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400502 decode_putfh_maxsz + \
503 decode_close_maxsz + \
504 decode_getattr_maxsz)
505#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400506 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400507 encode_putfh_maxsz + \
508 encode_setattr_maxsz + \
509 encode_getattr_maxsz)
510#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400511 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400512 decode_putfh_maxsz + \
513 decode_setattr_maxsz + \
514 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400516 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 encode_putfh_maxsz + \
518 encode_fsinfo_maxsz)
519#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 decode_putfh_maxsz + \
522 decode_fsinfo_maxsz)
523#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
524 encode_renew_maxsz)
525#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
526 decode_renew_maxsz)
527#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
528 encode_setclientid_maxsz)
529#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
530 decode_setclientid_maxsz)
531#define NFS4_enc_setclientid_confirm_sz \
532 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400533 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534#define NFS4_dec_setclientid_confirm_sz \
535 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400536 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400540 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400544 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400548 encode_lockt_maxsz)
549#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400551 decode_putfh_maxsz + \
552 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400554 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400556 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400560 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400561#define NFS4_enc_release_lockowner_sz \
562 (compound_encode_hdr_maxsz + \
563 encode_lockowner_maxsz)
564#define NFS4_dec_release_lockowner_sz \
565 (compound_decode_hdr_maxsz + \
566 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_enc_access_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 Myklebust76b32992007-08-10 17:45:11 -0400570 encode_access_maxsz + \
571 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400573 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400575 decode_access_maxsz + \
576 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400578 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 encode_putfh_maxsz + \
580 encode_getattr_maxsz)
581#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_putfh_maxsz + \
584 decode_getattr_maxsz)
585#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 encode_putfh_maxsz + \
588 encode_lookup_maxsz + \
589 encode_getattr_maxsz + \
590 encode_getfh_maxsz)
591#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400594 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 decode_getattr_maxsz + \
596 decode_getfh_maxsz)
597#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 encode_putrootfh_maxsz + \
600 encode_getattr_maxsz + \
601 encode_getfh_maxsz)
602#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400603 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 decode_putrootfh_maxsz + \
605 decode_getattr_maxsz + \
606 decode_getfh_maxsz)
607#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400608 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400610 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400612 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400614 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 encode_putfh_maxsz + \
618 encode_savefh_maxsz + \
619 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400620 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 decode_putfh_maxsz + \
624 decode_savefh_maxsz + \
625 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400626 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400628 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 encode_putfh_maxsz + \
630 encode_savefh_maxsz + \
631 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400632 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400633 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400634 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 decode_putfh_maxsz + \
638 decode_savefh_maxsz + \
639 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400640 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400641 decode_restorefh_maxsz + \
642 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643#define NFS4_enc_symlink_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_symlink_maxsz + \
647 encode_getattr_maxsz + \
648 encode_getfh_maxsz)
649#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_putfh_maxsz + \
652 decode_symlink_maxsz + \
653 decode_getattr_maxsz + \
654 decode_getfh_maxsz)
655#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400656 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 encode_putfh_maxsz + \
658 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400659 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400660 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400662 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 decode_putfh_maxsz + \
664 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400665 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400666 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 encode_putfh_maxsz + \
670 encode_getattr_maxsz)
671#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 decode_putfh_maxsz + \
674 decode_getattr_maxsz)
675#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400678 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800685 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 encode_getattr_maxsz)
687#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800689 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 decode_getattr_maxsz)
691#define NFS4_enc_delegreturn_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 Myklebustfa178f22006-01-03 09:55:38 +0100694 encode_delegreturn_maxsz + \
695 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400697 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100698 decode_delegreturn_maxsz + \
699 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000700#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000702 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400703 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000706 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000708#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000710 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400711 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000714 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400716#define NFS4_enc_fs_locations_sz \
717 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400718 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400719 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400720 encode_lookup_maxsz + \
721 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400722#define NFS4_dec_fs_locations_sz \
723 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400724 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400725 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400726 decode_lookup_maxsz + \
727 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000728#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
729 encode_sequence_maxsz + \
730 encode_putfh_maxsz + \
731 encode_secinfo_maxsz)
732#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
733 decode_sequence_maxsz + \
734 decode_putfh_maxsz + \
735 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400736#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400737#define NFS4_enc_bind_conn_to_session_sz \
738 (compound_encode_hdr_maxsz + \
739 encode_bind_conn_to_session_maxsz)
740#define NFS4_dec_bind_conn_to_session_sz \
741 (compound_decode_hdr_maxsz + \
742 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400743#define NFS4_enc_exchange_id_sz \
744 (compound_encode_hdr_maxsz + \
745 encode_exchange_id_maxsz)
746#define NFS4_dec_exchange_id_sz \
747 (compound_decode_hdr_maxsz + \
748 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400749#define NFS4_enc_create_session_sz \
750 (compound_encode_hdr_maxsz + \
751 encode_create_session_maxsz)
752#define NFS4_dec_create_session_sz \
753 (compound_decode_hdr_maxsz + \
754 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400755#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
756 encode_destroy_session_maxsz)
757#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
758 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400759#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
760 encode_destroy_clientid_maxsz)
761#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
762 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400763#define NFS4_enc_sequence_sz \
764 (compound_decode_hdr_maxsz + \
765 encode_sequence_maxsz)
766#define NFS4_dec_sequence_sz \
767 (compound_decode_hdr_maxsz + \
768 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400769#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
770 encode_sequence_maxsz + \
771 encode_putrootfh_maxsz + \
772 encode_fsinfo_maxsz)
773#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
774 decode_sequence_maxsz + \
775 decode_putrootfh_maxsz + \
776 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500777#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz + \
779 encode_reclaim_complete_maxsz)
780#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
781 decode_sequence_maxsz + \
782 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400783#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
784 encode_sequence_maxsz + \
785 encode_putfh_maxsz + \
786 encode_getdevicelist_maxsz)
787#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
788 decode_sequence_maxsz + \
789 decode_putfh_maxsz + \
790 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400791#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz +\
793 encode_getdeviceinfo_maxsz)
794#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
795 decode_sequence_maxsz + \
796 decode_getdeviceinfo_maxsz)
797#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_putfh_maxsz + \
800 encode_layoutget_maxsz)
801#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_putfh_maxsz + \
804 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000805#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz +\
807 encode_putfh_maxsz + \
808 encode_layoutcommit_maxsz + \
809 encode_getattr_maxsz)
810#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
811 decode_sequence_maxsz + \
812 decode_putfh_maxsz + \
813 decode_layoutcommit_maxsz + \
814 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300815#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
816 encode_sequence_maxsz + \
817 encode_putfh_maxsz + \
818 encode_layoutreturn_maxsz)
819#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
820 decode_sequence_maxsz + \
821 decode_putfh_maxsz + \
822 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400823#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
824 encode_sequence_maxsz + \
825 encode_putrootfh_maxsz +\
826 encode_secinfo_no_name_maxsz)
827#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
828 decode_sequence_maxsz + \
829 decode_putrootfh_maxsz + \
830 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400831#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
832 encode_sequence_maxsz + \
833 encode_test_stateid_maxsz)
834#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
835 decode_sequence_maxsz + \
836 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400837#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
838 encode_sequence_maxsz + \
839 encode_free_stateid_maxsz)
840#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
841 decode_sequence_maxsz + \
842 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500843
844const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
845 compound_encode_hdr_maxsz +
846 encode_sequence_maxsz +
847 encode_putfh_maxsz +
848 encode_getattr_maxsz) *
849 XDR_UNIT);
850
851const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
852 compound_decode_hdr_maxsz +
853 decode_sequence_maxsz +
854 decode_putfh_maxsz) *
855 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400856#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Trond Myklebustbca79472009-03-11 14:10:26 -0400858static const umode_t nfs_type2fmt[] = {
859 [NF4BAD] = 0,
860 [NF4REG] = S_IFREG,
861 [NF4DIR] = S_IFDIR,
862 [NF4BLK] = S_IFBLK,
863 [NF4CHR] = S_IFCHR,
864 [NF4LNK] = S_IFLNK,
865 [NF4SOCK] = S_IFSOCK,
866 [NF4FIFO] = S_IFIFO,
867 [NF4ATTRDIR] = 0,
868 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869};
870
871struct compound_hdr {
872 int32_t status;
873 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500874 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 uint32_t taglen;
876 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400877 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400878 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879};
880
Benny Halevy13c65ce2009-08-14 17:19:25 +0300881static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
882{
883 __be32 *p = xdr_reserve_space(xdr, nbytes);
884 BUG_ON(!p);
885 return p;
886}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Trond Myklebustcb17e552012-03-04 18:13:56 -0500888static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
889{
890 __be32 *p;
891
892 p = xdr_reserve_space(xdr, len);
893 xdr_encode_opaque_fixed(p, buf, len);
894}
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
897{
Al Viro8687b632006-10-19 23:28:48 -0700898 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500900 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 xdr_encode_opaque(p, str, len);
902}
903
Trond Myklebust4ade9822012-03-04 18:13:57 -0500904static void encode_uint32(struct xdr_stream *xdr, u32 n)
905{
906 __be32 *p;
907
908 p = reserve_space(xdr, 4);
909 *p = cpu_to_be32(n);
910}
911
Trond Myklebustff2eb682012-03-05 11:40:12 -0500912static void encode_uint64(struct xdr_stream *xdr, u64 n)
913{
914 __be32 *p;
915
916 p = reserve_space(xdr, 8);
917 xdr_encode_hyper(p, n);
918}
919
Trond Myklebust4ade9822012-03-04 18:13:57 -0500920static void encode_nfs4_seqid(struct xdr_stream *xdr,
921 const struct nfs_seqid *seqid)
922{
923 encode_uint32(xdr, seqid->sequence->counter);
924}
925
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400926static void encode_compound_hdr(struct xdr_stream *xdr,
927 struct rpc_rqst *req,
928 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929{
Al Viro8687b632006-10-19 23:28:48 -0700930 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400931 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400932
933 /* initialize running count of expected bytes in reply.
934 * NOTE: the replied tag SHOULD be the same is the one sent,
935 * but this is not required as a MUST for the server to do so. */
936 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Trond Myklebust7fc38842012-10-15 11:51:21 -0400938 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500939 encode_string(xdr, hdr->taglen, hdr->tag);
940 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300941 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500942 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300943 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500944}
945
Trond Myklebustab19b482012-03-04 18:13:57 -0500946static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
947 uint32_t replen,
948 struct compound_hdr *hdr)
949{
950 encode_uint32(xdr, op);
951 hdr->nops++;
952 hdr->replen += replen;
953}
954
Andy Adamsond0179312008-12-23 16:06:17 -0500955static void encode_nops(struct compound_hdr *hdr)
956{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400957 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500958 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959}
960
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500961static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
962{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500963 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500964}
965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
967{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500968 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500971static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972{
973 char owner_name[IDMAP_NAMESZ];
974 char owner_group[IDMAP_NAMESZ];
975 int owner_namelen = 0;
976 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700977 __be32 *p;
978 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 int len;
980 uint32_t bmval0 = 0;
981 uint32_t bmval1 = 0;
David Quigleya09df2c2013-05-22 12:50:41 -0400982 uint32_t bmval2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
984 /*
985 * We reserve enough space to write the entire attribute buffer at once.
986 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -0400987 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
988 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000989 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 */
David Quigleya09df2c2013-05-22 12:50:41 -0400991 len = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
993 /* Sigh */
994 if (iap->ia_valid & ATTR_SIZE)
995 len += 8;
996 if (iap->ia_valid & ATTR_MODE)
997 len += 4;
998 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800999 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001001 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001002 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 /* XXX */
1004 strcpy(owner_name, "nobody");
1005 owner_namelen = sizeof("nobody") - 1;
1006 /* goto out; */
1007 }
1008 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1009 }
1010 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001011 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001013 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001014 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 strcpy(owner_group, "nobody");
1016 owner_grouplen = sizeof("nobody") - 1;
1017 /* goto out; */
1018 }
1019 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1020 }
1021 if (iap->ia_valid & ATTR_ATIME_SET)
1022 len += 16;
1023 else if (iap->ia_valid & ATTR_ATIME)
1024 len += 4;
1025 if (iap->ia_valid & ATTR_MTIME_SET)
1026 len += 16;
1027 else if (iap->ia_valid & ATTR_MTIME)
1028 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001029 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
1031 /*
1032 * We write the bitmap length now, but leave the bitmap and the attribute
1033 * buffer length to be backfilled at the end of this routine.
1034 */
David Quigleya09df2c2013-05-22 12:50:41 -04001035 *p++ = cpu_to_be32(3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 q = p;
David Quigleya09df2c2013-05-22 12:50:41 -04001037 p += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 if (iap->ia_valid & ATTR_SIZE) {
1040 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001041 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 }
1043 if (iap->ia_valid & ATTR_MODE) {
1044 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001045 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 }
1047 if (iap->ia_valid & ATTR_UID) {
1048 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001049 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 }
1051 if (iap->ia_valid & ATTR_GID) {
1052 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001053 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 }
1055 if (iap->ia_valid & ATTR_ATIME_SET) {
1056 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001057 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Bryan Schumaker042ad0b2013-04-19 16:09:37 -04001058 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001059 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 }
1061 else if (iap->ia_valid & ATTR_ATIME) {
1062 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001063 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 }
1065 if (iap->ia_valid & ATTR_MTIME_SET) {
1066 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Bryan Schumaker042ad0b2013-04-19 16:09:37 -04001068 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001069 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 }
1071 else if (iap->ia_valid & ATTR_MTIME) {
1072 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001073 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001075
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 /*
1077 * Now we backfill the bitmap and the attribute buffer length.
1078 */
1079 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001080 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 len, ((char *)p - (char *)q) + 4);
1082 BUG();
1083 }
David Quigleya09df2c2013-05-22 12:50:41 -04001084 len = (char *)p - (char *)q - 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 *q++ = htonl(bmval0);
1086 *q++ = htonl(bmval1);
David Quigleya09df2c2013-05-22 12:50:41 -04001087 *q++ = htonl(bmval2);
Benny Halevy34558512009-08-14 17:19:30 +03001088 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091}
1092
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001093static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001095 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1096 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097}
1098
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001099static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100{
Trond Myklebustab19b482012-03-04 18:13:57 -05001101 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001102 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001103 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104}
1105
Fred Isaman0b7c0152012-04-20 14:47:39 -04001106static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107{
Al Viro8687b632006-10-19 23:28:48 -07001108 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001109
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001110 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1111 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001112 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001113 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114}
1115
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001116static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
Al Viro8687b632006-10-19 23:28:48 -07001118 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001119
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001120 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1121 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123 switch (create->ftype) {
1124 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001125 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001126 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001127 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 break;
1129
1130 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001131 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001132 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001133 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 break;
1135
1136 default:
1137 break;
1138 }
1139
Benny Halevy811652b2009-08-14 17:19:34 +03001140 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001144static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Andy Adamson05d564f2008-12-23 16:06:15 -05001146 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001148 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1149 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001150 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001151 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001154static 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 -07001155{
Andy Adamson05d564f2008-12-23 16:06:15 -05001156 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001158 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1159 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001160 *p++ = cpu_to_be32(2);
1161 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001162 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
Fred Isamandae100c2011-07-30 20:52:37 -04001165static void
1166encode_getattr_three(struct xdr_stream *xdr,
1167 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1168 struct compound_hdr *hdr)
1169{
1170 __be32 *p;
1171
Trond Myklebustab19b482012-03-04 18:13:57 -05001172 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001173 if (bm2) {
1174 p = reserve_space(xdr, 16);
1175 *p++ = cpu_to_be32(3);
1176 *p++ = cpu_to_be32(bm0);
1177 *p++ = cpu_to_be32(bm1);
1178 *p = cpu_to_be32(bm2);
1179 } else if (bm1) {
1180 p = reserve_space(xdr, 12);
1181 *p++ = cpu_to_be32(2);
1182 *p++ = cpu_to_be32(bm0);
1183 *p = cpu_to_be32(bm1);
1184 } else {
1185 p = reserve_space(xdr, 8);
1186 *p++ = cpu_to_be32(1);
1187 *p = cpu_to_be32(bm0);
1188 }
Fred Isamandae100c2011-07-30 20:52:37 -04001189}
1190
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001191static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192{
David Quigleya09df2c2013-05-22 12:50:41 -04001193 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1194 bitmask[1] & nfs4_fattr_bitmap[1],
1195 bitmask[2] & nfs4_fattr_bitmap[2],
1196 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197}
1198
Andy Adamson88034c32012-05-23 05:02:34 -04001199static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001200 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001201 struct compound_hdr *hdr)
1202{
1203 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001204 bitmask[0] & open_bitmap[0],
1205 bitmask[1] & open_bitmap[1],
1206 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001207 hdr);
1208}
1209
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001210static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211{
Fred Isamandae100c2011-07-30 20:52:37 -04001212 encode_getattr_three(xdr,
1213 bitmask[0] & nfs4_fsinfo_bitmap[0],
1214 bitmask[1] & nfs4_fsinfo_bitmap[1],
1215 bitmask[2] & nfs4_fsinfo_bitmap[2],
1216 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217}
1218
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001219static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001220{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001221 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1222 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001223}
1224
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001225static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
Trond Myklebustab19b482012-03-04 18:13:57 -05001227 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001230static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231{
Trond Myklebustab19b482012-03-04 18:13:57 -05001232 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001233 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234}
1235
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001236static inline int nfs4_lock_type(struct file_lock *fl, int block)
1237{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001238 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001239 return block ? NFS4_READW_LT : NFS4_READ_LT;
1240 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1241}
1242
1243static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1244{
1245 if (fl->fl_end == OFFSET_MAX)
1246 return ~(uint64_t)0;
1247 return fl->fl_end - fl->fl_start + 1;
1248}
1249
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001250static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1251{
1252 __be32 *p;
1253
Trond Myklebustd035c362010-12-21 10:45:27 -05001254 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001255 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001256 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001257 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001258 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001259 xdr_encode_hyper(p, lowner->id);
1260}
1261
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262/*
1263 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1264 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1265 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001266static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267{
Al Viro8687b632006-10-19 23:28:48 -07001268 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001270 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1271 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001272 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1273 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001274 p = xdr_encode_hyper(p, args->fl->fl_start);
1275 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001276 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001277 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001278 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001279 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001280 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001281 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 }
1283 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001284 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001285 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001289static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
Al Viro8687b632006-10-19 23:28:48 -07001291 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001293 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1294 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001295 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001296 p = xdr_encode_hyper(p, args->fl->fl_start);
1297 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001298 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299}
1300
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001301static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_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_LOCKU, decode_locku_maxsz, hdr);
1306 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001307 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001308 encode_nfs4_stateid(xdr, args->stateid);
1309 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001310 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001311 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312}
1313
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001314static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1315{
Trond Myklebustab19b482012-03-04 18:13:57 -05001316 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001317 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001318}
1319
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001320static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321{
Trond Myklebustab19b482012-03-04 18:13:57 -05001322 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001323 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324}
1325
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001326static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327{
Al Viro8687b632006-10-19 23:28:48 -07001328 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Benny Halevy13c65ce2009-08-14 17:19:25 +03001330 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001331 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001332 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001333 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001334 break;
1335 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001336 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001337 break;
1338 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001339 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001340 break;
1341 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001342 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 }
Benny Halevy34558512009-08-14 17:19:30 +03001344 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345}
1346
1347static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1348{
Al Viro8687b632006-10-19 23:28:48 -07001349 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 /*
1351 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1352 * owner 4 = 32
1353 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001354 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001355 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001356 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001357 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001358 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001359 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001360 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001361 *p++ = cpu_to_be32(arg->id.uniquifier);
1362 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363}
1364
1365static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1366{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001367 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001368 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Benny Halevy13c65ce2009-08-14 17:19:25 +03001370 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001371 switch(arg->createmode) {
1372 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001373 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001374 encode_attrs(xdr, arg->u.attrs, arg->server);
1375 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001376 case NFS4_CREATE_GUARDED:
1377 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1378 encode_attrs(xdr, arg->u.attrs, arg->server);
1379 break;
1380 case NFS4_CREATE_EXCLUSIVE:
1381 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1382 encode_nfs4_verifier(xdr, &arg->u.verifier);
1383 break;
1384 case NFS4_CREATE_EXCLUSIVE4_1:
1385 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1386 encode_nfs4_verifier(xdr, &arg->u.verifier);
1387 dummy.ia_valid = 0;
1388 encode_attrs(xdr, &dummy, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 }
1390}
1391
1392static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1393{
Al Viro8687b632006-10-19 23:28:48 -07001394 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Benny Halevy13c65ce2009-08-14 17:19:25 +03001396 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001398 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001399 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001400 break;
1401 default:
Benny Halevy34558512009-08-14 17:19:30 +03001402 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001403 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 }
1405}
1406
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001407static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408{
Al Viro8687b632006-10-19 23:28:48 -07001409 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Benny Halevy13c65ce2009-08-14 17:19:25 +03001411 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001413 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001414 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001415 break;
1416 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001417 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001418 break;
1419 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001420 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001421 break;
1422 default:
1423 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 }
1425}
1426
1427static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
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);
Benny Halevy34558512009-08-14 17:19:30 +03001432 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 encode_string(xdr, name->len, name->name);
1434}
1435
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001436static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437{
Al Viro8687b632006-10-19 23:28:48 -07001438 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Benny Halevy13c65ce2009-08-14 17:19:25 +03001440 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001441 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 encode_delegation_type(xdr, type);
1443}
1444
1445static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1446{
Al Viro8687b632006-10-19 23:28:48 -07001447 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001449 p = reserve_space(xdr, 4);
1450 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1451 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 encode_string(xdr, name->len, name->name);
1453}
1454
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001455static inline void encode_claim_fh(struct xdr_stream *xdr)
1456{
1457 __be32 *p;
1458
1459 p = reserve_space(xdr, 4);
1460 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1461}
1462
1463static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1464{
1465 __be32 *p;
1466
1467 p = reserve_space(xdr, 4);
1468 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1469 encode_nfs4_stateid(xdr, stateid);
1470}
1471
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001472static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473{
Trond Myklebustab19b482012-03-04 18:13:57 -05001474 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 encode_openhdr(xdr, arg);
1476 encode_opentype(xdr, arg);
1477 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001478 case NFS4_OPEN_CLAIM_NULL:
1479 encode_claim_null(xdr, arg->name);
1480 break;
1481 case NFS4_OPEN_CLAIM_PREVIOUS:
1482 encode_claim_previous(xdr, arg->u.delegation_type);
1483 break;
1484 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1485 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1486 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001487 case NFS4_OPEN_CLAIM_FH:
1488 encode_claim_fh(xdr);
1489 break;
1490 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1491 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1492 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001493 default:
1494 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496}
1497
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001498static 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 -07001499{
Trond Myklebustab19b482012-03-04 18:13:57 -05001500 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001501 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001502 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503}
1504
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001505static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506{
Trond Myklebustab19b482012-03-04 18:13:57 -05001507 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001508 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001509 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001510 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511}
1512
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001513static void
Andy Adamsond0179312008-12-23 16:06:17 -05001514encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515{
Trond Myklebustab19b482012-03-04 18:13:57 -05001516 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001517 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518}
1519
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001520static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
Trond Myklebustab19b482012-03-04 18:13:57 -05001522 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523}
1524
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001525static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
Al Viro8687b632006-10-19 23:28:48 -07001527 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Trond Myklebustab19b482012-03-04 18:13:57 -05001529 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001530 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Benny Halevy13c65ce2009-08-14 17:19:25 +03001532 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001533 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001534 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535}
1536
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001537static 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 -07001538{
Trond Myklebust28331a42011-04-27 13:47:52 -04001539 uint32_t attrs[2] = {
1540 FATTR4_WORD0_RDATTR_ERROR,
1541 FATTR4_WORD1_MOUNTED_ON_FILEID,
1542 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001543 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001544 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001546 if (readdir->plus) {
1547 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001548 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001549 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1550 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1551 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1552 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001553 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001554 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001555 /* Use mounted_on_fileid only if the server supports it */
1556 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1557 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001558
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001559 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001560 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001561 encode_nfs4_verifier(xdr, &readdir->verifier);
1562 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001563 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001564 *p++ = cpu_to_be32(readdir->count);
1565 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001566
Benny Halevye75bc1c2009-08-14 17:18:54 +03001567 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001568 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001569 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001570 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1571 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001572 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001573 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001574 attrs[0] & readdir->bitmask[0],
1575 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001578static 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 -07001579{
Trond Myklebustab19b482012-03-04 18:13:57 -05001580 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581}
1582
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001583static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584{
Trond Myklebustab19b482012-03-04 18:13:57 -05001585 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001586 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587}
1588
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001589static 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 -07001590{
Trond Myklebustab19b482012-03-04 18:13:57 -05001591 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001592 encode_string(xdr, oldname->len, oldname->name);
1593 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594}
1595
Chuck Leverbb4dae52012-03-01 17:01:48 -05001596static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1597 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001599 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001600 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601}
1602
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001603static void
Andy Adamsond0179312008-12-23 16:06:17 -05001604encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001605{
Trond Myklebustab19b482012-03-04 18:13:57 -05001606 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001607}
1608
Chuck Lever9f06c712010-12-14 14:59:18 +00001609static void
Andy Adamsond0179312008-12-23 16:06:17 -05001610encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001611{
Al Viro8687b632006-10-19 23:28:48 -07001612 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001613
Trond Myklebustab19b482012-03-04 18:13:57 -05001614 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001615 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001616 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001617 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001618 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001619 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001620 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001621 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001622}
1623
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001624static void
Andy Adamsond0179312008-12-23 16:06:17 -05001625encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626{
Trond Myklebustab19b482012-03-04 18:13:57 -05001627 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628}
1629
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001630static 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 -07001631{
Trond Myklebustab19b482012-03-04 18:13:57 -05001632 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001633 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001634 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635}
1636
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001637static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638{
Al Viro8687b632006-10-19 23:28:48 -07001639 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
Trond Myklebust70019512012-03-04 20:49:32 -05001641 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001642 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
1644 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001645 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001646 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1648 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001649 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001650 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651}
1652
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001653static 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 -07001654{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001655 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1656 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001657 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001658 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
1660
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001661static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662{
Al Viro8687b632006-10-19 23:28:48 -07001663 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
Trond Myklebustab19b482012-03-04 18:13:57 -05001665 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001666 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Benny Halevy13c65ce2009-08-14 17:19:25 +03001668 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001669 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001670 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001671 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
1673 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674}
1675
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001676static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677{
Trond Myklebustab19b482012-03-04 18:13:57 -05001678 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001679 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001681
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001682static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1683{
Trond Myklebustab19b482012-03-04 18:13:57 -05001684 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001685 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001686}
1687
Benny Halevy99fe60d2009-04-01 09:22:29 -04001688#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001689/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001690static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1691 struct nfs4_session *session,
1692 struct compound_hdr *hdr)
1693{
1694 __be32 *p;
1695
1696 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1697 decode_bind_conn_to_session_maxsz, hdr);
1698 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1699 p = xdr_reserve_space(xdr, 8);
1700 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1701 *p = 0; /* use_conn_in_rdma_mode = False */
1702}
1703
Benny Halevy99fe60d2009-04-01 09:22:29 -04001704static void encode_exchange_id(struct xdr_stream *xdr,
1705 struct nfs41_exchange_id_args *args,
1706 struct compound_hdr *hdr)
1707{
1708 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001709 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001710 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001711
Trond Myklebust70019512012-03-04 20:49:32 -05001712 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001713 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001714
1715 encode_string(xdr, args->id_len, args->id);
1716
Benny Halevy13c65ce2009-08-14 17:19:25 +03001717 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001718 *p++ = cpu_to_be32(args->flags);
1719 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001720
1721 if (send_implementation_id &&
1722 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1723 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001724 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001725 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1726 utsname()->sysname, utsname()->release,
1727 utsname()->version, utsname()->machine);
1728
1729 if (len > 0) {
1730 *p = cpu_to_be32(1); /* implementation id array length=1 */
1731
1732 encode_string(xdr,
1733 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1734 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1735 encode_string(xdr, len, impl_name);
1736 /* just send zeros for nii_date - the date is in nii_name */
1737 p = reserve_space(xdr, 12);
1738 p = xdr_encode_hyper(p, 0);
1739 *p = cpu_to_be32(0);
1740 } else
1741 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001742}
Andy Adamsonfc931582009-04-01 09:22:31 -04001743
1744static void encode_create_session(struct xdr_stream *xdr,
1745 struct nfs41_create_session_args *args,
1746 struct compound_hdr *hdr)
1747{
1748 __be32 *p;
1749 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1750 uint32_t len;
1751 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001752 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001753 u32 max_resp_sz_cached;
1754
1755 /*
1756 * Assumes OPEN is the biggest non-idempotent compound.
1757 * 2 is the verifier.
1758 */
1759 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1760 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001761
Andy Adamsonfc931582009-04-01 09:22:31 -04001762 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1763 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001764
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001765 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1766 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001767 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001768 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1769 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001770
Andy Adamsonfc931582009-04-01 09:22:31 -04001771 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001772 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001773 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1774 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001775 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001776 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1777 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1778 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001779
1780 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001781 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001782 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1783 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1784 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1785 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1786 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1787 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001788
Benny Halevye75bc1c2009-08-14 17:18:54 +03001789 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001790 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001791 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001792
1793 /* authsys_parms rfc1831 */
Chuck Leverf0920752012-05-21 22:45:41 -04001794 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001795 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001796 *p++ = cpu_to_be32(0); /* UID */
1797 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001798 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001799}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001800
1801static void encode_destroy_session(struct xdr_stream *xdr,
1802 struct nfs4_session *session,
1803 struct compound_hdr *hdr)
1804{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001805 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1806 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001807}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001808
Trond Myklebust66245532012-05-25 17:18:09 -04001809static void encode_destroy_clientid(struct xdr_stream *xdr,
1810 uint64_t clientid,
1811 struct compound_hdr *hdr)
1812{
1813 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1814 encode_uint64(xdr, clientid);
1815}
1816
Ricardo Labiaga180197532009-12-05 16:08:40 -05001817static void encode_reclaim_complete(struct xdr_stream *xdr,
1818 struct nfs41_reclaim_complete_args *args,
1819 struct compound_hdr *hdr)
1820{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001821 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1822 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001823}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001824#endif /* CONFIG_NFS_V4_1 */
1825
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001826static void encode_sequence(struct xdr_stream *xdr,
1827 const struct nfs4_sequence_args *args,
1828 struct compound_hdr *hdr)
1829{
1830#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001831 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001832 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001833 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001834 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001835
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001836 if (slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001837 return;
1838
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001839 tp = slot->table;
1840 session = tp->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001841
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001842 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001843
1844 /*
1845 * Sessionid + seqid + slotid + max slotid + cache_this
1846 */
1847 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1848 "max_slotid=%d cache_this=%d\n",
1849 __func__,
1850 ((u32 *)session->sess_id.data)[0],
1851 ((u32 *)session->sess_id.data)[1],
1852 ((u32 *)session->sess_id.data)[2],
1853 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001854 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001855 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001856 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001857 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001858 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001859 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001860 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001861 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001862#endif /* CONFIG_NFS_V4_1 */
1863}
1864
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001865#ifdef CONFIG_NFS_V4_1
1866static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001867encode_getdevicelist(struct xdr_stream *xdr,
1868 const struct nfs4_getdevicelist_args *args,
1869 struct compound_hdr *hdr)
1870{
1871 __be32 *p;
1872 nfs4_verifier dummy = {
1873 .data = "dummmmmy",
1874 };
1875
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001876 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1877 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001878 *p++ = cpu_to_be32(args->layoutclass);
1879 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1880 xdr_encode_hyper(p, 0ULL); /* cookie */
1881 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001882}
1883
1884static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001885encode_getdeviceinfo(struct xdr_stream *xdr,
1886 const struct nfs4_getdeviceinfo_args *args,
1887 struct compound_hdr *hdr)
1888{
1889 __be32 *p;
1890
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001891 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1892 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001893 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1894 NFS4_DEVICEID4_SIZE);
1895 *p++ = cpu_to_be32(args->pdev->layout_type);
1896 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1897 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001898}
1899
1900static void
1901encode_layoutget(struct xdr_stream *xdr,
1902 const struct nfs4_layoutget_args *args,
1903 struct compound_hdr *hdr)
1904{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001905 __be32 *p;
1906
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001907 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1908 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001909 *p++ = cpu_to_be32(0); /* Signal layout available */
1910 *p++ = cpu_to_be32(args->type);
1911 *p++ = cpu_to_be32(args->range.iomode);
1912 p = xdr_encode_hyper(p, args->range.offset);
1913 p = xdr_encode_hyper(p, args->range.length);
1914 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001915 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001916 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001917
1918 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1919 __func__,
1920 args->type,
1921 args->range.iomode,
1922 (unsigned long)args->range.offset,
1923 (unsigned long)args->range.length,
1924 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001925}
Andy Adamson863a3c62011-03-23 13:27:54 +00001926
1927static int
1928encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001929 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001930 const struct nfs4_layoutcommit_args *args,
1931 struct compound_hdr *hdr)
1932{
1933 __be32 *p;
1934
1935 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1936 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1937
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001938 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1939 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001940 /* Only whole file layouts */
1941 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001942 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001943 *p = cpu_to_be32(0); /* reclaim */
1944 encode_nfs4_stateid(xdr, &args->stateid);
1945 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001946 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1947 p = xdr_encode_hyper(p, args->lastbytewritten);
1948 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1949 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001950
1951 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1952 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1953 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001954 else
1955 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001956
Andy Adamson863a3c62011-03-23 13:27:54 +00001957 return 0;
1958}
Benny Halevycbe82602011-05-22 19:52:37 +03001959
1960static void
1961encode_layoutreturn(struct xdr_stream *xdr,
1962 const struct nfs4_layoutreturn_args *args,
1963 struct compound_hdr *hdr)
1964{
1965 __be32 *p;
1966
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001967 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1968 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001969 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1970 *p++ = cpu_to_be32(args->layout_type);
1971 *p++ = cpu_to_be32(IOMODE_ANY);
1972 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001973 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001974 p = xdr_encode_hyper(p, 0);
1975 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1976 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001977 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001978 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001979 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1980 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1981 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001982 } else
1983 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001984}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001985
1986static int
1987encode_secinfo_no_name(struct xdr_stream *xdr,
1988 const struct nfs41_secinfo_no_name_args *args,
1989 struct compound_hdr *hdr)
1990{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001991 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1992 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001993 return 0;
1994}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001995
1996static void encode_test_stateid(struct xdr_stream *xdr,
1997 struct nfs41_test_stateid_args *args,
1998 struct compound_hdr *hdr)
1999{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002000 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2001 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002002 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002003}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002004
2005static void encode_free_stateid(struct xdr_stream *xdr,
2006 struct nfs41_free_stateid_args *args,
2007 struct compound_hdr *hdr)
2008{
Trond Myklebustab19b482012-03-04 18:13:57 -05002009 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002010 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002011}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002012#endif /* CONFIG_NFS_V4_1 */
2013
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014/*
2015 * END OF "GENERIC" ENCODE ROUTINES.
2016 */
2017
Benny Halevy66cc0422009-04-01 09:22:10 -04002018static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2019{
2020#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05002021
2022 if (args->sa_slot)
2023 return args->sa_slot->table->session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002024#endif /* CONFIG_NFS_V4_1 */
2025 return 0;
2026}
2027
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028/*
2029 * Encode an ACCESS request
2030 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002031static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2032 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002035 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
Chuck Lever9f06c712010-12-14 14:59:18 +00002038 encode_compound_hdr(xdr, req, &hdr);
2039 encode_sequence(xdr, &args->seq_args, &hdr);
2040 encode_putfh(xdr, args->fh, &hdr);
2041 encode_access(xdr, args->access, &hdr);
2042 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002043 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044}
2045
2046/*
2047 * Encode LOOKUP request
2048 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002049static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2050 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002053 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
Chuck Lever9f06c712010-12-14 14:59:18 +00002056 encode_compound_hdr(xdr, req, &hdr);
2057 encode_sequence(xdr, &args->seq_args, &hdr);
2058 encode_putfh(xdr, args->dir_fh, &hdr);
2059 encode_lookup(xdr, args->name, &hdr);
2060 encode_getfh(xdr, &hdr);
2061 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002062 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063}
2064
2065/*
2066 * Encode LOOKUP_ROOT request
2067 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002068static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2069 struct xdr_stream *xdr,
2070 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002073 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
Chuck Lever9f06c712010-12-14 14:59:18 +00002076 encode_compound_hdr(xdr, req, &hdr);
2077 encode_sequence(xdr, &args->seq_args, &hdr);
2078 encode_putrootfh(xdr, &hdr);
2079 encode_getfh(xdr, &hdr);
2080 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002081 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082}
2083
2084/*
2085 * Encode REMOVE request
2086 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002087static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2088 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002091 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
Chuck Lever9f06c712010-12-14 14:59:18 +00002094 encode_compound_hdr(xdr, req, &hdr);
2095 encode_sequence(xdr, &args->seq_args, &hdr);
2096 encode_putfh(xdr, args->fh, &hdr);
2097 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002098 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099}
2100
2101/*
2102 * Encode RENAME request
2103 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002104static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2105 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002108 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110
Chuck Lever9f06c712010-12-14 14:59:18 +00002111 encode_compound_hdr(xdr, req, &hdr);
2112 encode_sequence(xdr, &args->seq_args, &hdr);
2113 encode_putfh(xdr, args->old_dir, &hdr);
2114 encode_savefh(xdr, &hdr);
2115 encode_putfh(xdr, args->new_dir, &hdr);
2116 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002117 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118}
2119
2120/*
2121 * Encode LINK request
2122 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002123static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2124 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002127 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
Chuck Lever9f06c712010-12-14 14:59:18 +00002130 encode_compound_hdr(xdr, req, &hdr);
2131 encode_sequence(xdr, &args->seq_args, &hdr);
2132 encode_putfh(xdr, args->fh, &hdr);
2133 encode_savefh(xdr, &hdr);
2134 encode_putfh(xdr, args->dir_fh, &hdr);
2135 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002136 encode_restorefh(xdr, &hdr);
2137 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002138 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139}
2140
2141/*
2142 * Encode CREATE request
2143 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002144static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2145 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002148 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
Chuck Lever9f06c712010-12-14 14:59:18 +00002151 encode_compound_hdr(xdr, req, &hdr);
2152 encode_sequence(xdr, &args->seq_args, &hdr);
2153 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002154 encode_create(xdr, args, &hdr);
2155 encode_getfh(xdr, &hdr);
2156 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002157 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158}
2159
2160/*
2161 * Encode SYMLINK request
2162 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002163static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2164 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165{
Chuck Lever9f06c712010-12-14 14:59:18 +00002166 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167}
2168
2169/*
2170 * Encode GETATTR request
2171 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002172static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2173 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002176 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Chuck Lever9f06c712010-12-14 14:59:18 +00002179 encode_compound_hdr(xdr, req, &hdr);
2180 encode_sequence(xdr, &args->seq_args, &hdr);
2181 encode_putfh(xdr, args->fh, &hdr);
2182 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002183 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184}
2185
2186/*
2187 * Encode a CLOSE request
2188 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002189static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2190 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191{
Andy Adamson05d564f2008-12-23 16:06:15 -05002192 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002193 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002194 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
Chuck Lever9f06c712010-12-14 14:59:18 +00002196 encode_compound_hdr(xdr, req, &hdr);
2197 encode_sequence(xdr, &args->seq_args, &hdr);
2198 encode_putfh(xdr, args->fh, &hdr);
2199 encode_close(xdr, args, &hdr);
2200 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002201 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202}
2203
2204/*
2205 * Encode an OPEN request
2206 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002207static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2208 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002211 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Chuck Lever9f06c712010-12-14 14:59:18 +00002214 encode_compound_hdr(xdr, req, &hdr);
2215 encode_sequence(xdr, &args->seq_args, &hdr);
2216 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002217 encode_open(xdr, args, &hdr);
2218 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002219 if (args->access)
2220 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002221 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002222 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223}
2224
2225/*
2226 * Encode an OPEN_CONFIRM request
2227 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002228static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2229 struct xdr_stream *xdr,
2230 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002233 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
Chuck Lever9f06c712010-12-14 14:59:18 +00002236 encode_compound_hdr(xdr, req, &hdr);
2237 encode_putfh(xdr, args->fh, &hdr);
2238 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002239 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240}
2241
2242/*
2243 * Encode an OPEN request with no attributes.
2244 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002245static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2246 struct xdr_stream *xdr,
2247 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002250 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
Chuck Lever9f06c712010-12-14 14:59:18 +00002253 encode_compound_hdr(xdr, req, &hdr);
2254 encode_sequence(xdr, &args->seq_args, &hdr);
2255 encode_putfh(xdr, args->fh, &hdr);
2256 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002257 if (args->access)
2258 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002259 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002260 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261}
2262
2263/*
2264 * Encode an OPEN_DOWNGRADE request
2265 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002266static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2267 struct xdr_stream *xdr,
2268 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002271 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273
Chuck Lever9f06c712010-12-14 14:59:18 +00002274 encode_compound_hdr(xdr, req, &hdr);
2275 encode_sequence(xdr, &args->seq_args, &hdr);
2276 encode_putfh(xdr, args->fh, &hdr);
2277 encode_open_downgrade(xdr, args, &hdr);
2278 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002279 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280}
2281
2282/*
2283 * Encode a LOCK request
2284 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002285static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2286 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002289 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
Chuck Lever9f06c712010-12-14 14:59:18 +00002292 encode_compound_hdr(xdr, req, &hdr);
2293 encode_sequence(xdr, &args->seq_args, &hdr);
2294 encode_putfh(xdr, args->fh, &hdr);
2295 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002296 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297}
2298
2299/*
2300 * Encode a LOCKT request
2301 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002302static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2303 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002306 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308
Chuck Lever9f06c712010-12-14 14:59:18 +00002309 encode_compound_hdr(xdr, req, &hdr);
2310 encode_sequence(xdr, &args->seq_args, &hdr);
2311 encode_putfh(xdr, args->fh, &hdr);
2312 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002313 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314}
2315
2316/*
2317 * Encode a LOCKU request
2318 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002319static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2320 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002323 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
Chuck Lever9f06c712010-12-14 14:59:18 +00002326 encode_compound_hdr(xdr, req, &hdr);
2327 encode_sequence(xdr, &args->seq_args, &hdr);
2328 encode_putfh(xdr, args->fh, &hdr);
2329 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002330 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331}
2332
Chuck Lever9f06c712010-12-14 14:59:18 +00002333static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2334 struct xdr_stream *xdr,
2335 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002336{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002337 struct compound_hdr hdr = {
2338 .minorversion = 0,
2339 };
2340
Chuck Lever9f06c712010-12-14 14:59:18 +00002341 encode_compound_hdr(xdr, req, &hdr);
2342 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002343 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002344}
2345
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346/*
2347 * Encode a READLINK request
2348 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002349static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2350 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002353 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Chuck Lever9f06c712010-12-14 14:59:18 +00002356 encode_compound_hdr(xdr, req, &hdr);
2357 encode_sequence(xdr, &args->seq_args, &hdr);
2358 encode_putfh(xdr, args->fh, &hdr);
2359 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002360
Benny Halevy28f56692009-04-01 09:22:09 -04002361 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002362 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002363 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364}
2365
2366/*
2367 * Encode a READDIR request
2368 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002369static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2370 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002373 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375
Chuck Lever9f06c712010-12-14 14:59:18 +00002376 encode_compound_hdr(xdr, req, &hdr);
2377 encode_sequence(xdr, &args->seq_args, &hdr);
2378 encode_putfh(xdr, args->fh, &hdr);
2379 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002380
Benny Halevy28f56692009-04-01 09:22:09 -04002381 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002382 args->pgbase, args->count);
2383 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002384 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002385 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002386 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387}
2388
2389/*
2390 * Encode a READ request
2391 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002392static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2393 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002396 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398
Chuck Lever9f06c712010-12-14 14:59:18 +00002399 encode_compound_hdr(xdr, req, &hdr);
2400 encode_sequence(xdr, &args->seq_args, &hdr);
2401 encode_putfh(xdr, args->fh, &hdr);
2402 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403
Benny Halevy28f56692009-04-01 09:22:09 -04002404 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002406 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002407 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408}
2409
2410/*
2411 * Encode an SETATTR request
2412 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002413static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2414 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415{
Andy Adamson05d564f2008-12-23 16:06:15 -05002416 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002417 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002418 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Chuck Lever9f06c712010-12-14 14:59:18 +00002420 encode_compound_hdr(xdr, req, &hdr);
2421 encode_sequence(xdr, &args->seq_args, &hdr);
2422 encode_putfh(xdr, args->fh, &hdr);
2423 encode_setattr(xdr, args, args->server, &hdr);
2424 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002425 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426}
2427
2428/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002429 * Encode a GETACL request
2430 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002431static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2432 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002433{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002434 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002435 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002436 };
Benny Halevy28f56692009-04-01 09:22:09 -04002437 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002438
Chuck Lever9f06c712010-12-14 14:59:18 +00002439 encode_compound_hdr(xdr, req, &hdr);
2440 encode_sequence(xdr, &args->seq_args, &hdr);
2441 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002442 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002443 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002444
Benny Halevy28f56692009-04-01 09:22:09 -04002445 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002446 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002447
Andy Adamsond0179312008-12-23 16:06:17 -05002448 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002449}
2450
2451/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 * Encode a WRITE request
2453 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002454static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2455 struct nfs_writeargs *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_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002465 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002466 if (args->bitmask)
2467 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002468 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469}
2470
2471/*
2472 * a COMMIT request
2473 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002474static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002475 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002478 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480
Chuck Lever9f06c712010-12-14 14:59:18 +00002481 encode_compound_hdr(xdr, req, &hdr);
2482 encode_sequence(xdr, &args->seq_args, &hdr);
2483 encode_putfh(xdr, args->fh, &hdr);
2484 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002485 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486}
2487
2488/*
2489 * FSINFO request
2490 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002491static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2492 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
Chuck Lever9f06c712010-12-14 14:59:18 +00002498 encode_compound_hdr(xdr, req, &hdr);
2499 encode_sequence(xdr, &args->seq_args, &hdr);
2500 encode_putfh(xdr, args->fh, &hdr);
2501 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002502 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503}
2504
2505/*
2506 * a PATHCONF request
2507 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002508static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2509 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002512 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514
Chuck Lever9f06c712010-12-14 14:59:18 +00002515 encode_compound_hdr(xdr, req, &hdr);
2516 encode_sequence(xdr, &args->seq_args, &hdr);
2517 encode_putfh(xdr, args->fh, &hdr);
2518 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002519 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002520 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521}
2522
2523/*
2524 * a STATFS request
2525 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002526static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2527 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002530 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Chuck Lever9f06c712010-12-14 14:59:18 +00002533 encode_compound_hdr(xdr, req, &hdr);
2534 encode_sequence(xdr, &args->seq_args, &hdr);
2535 encode_putfh(xdr, args->fh, &hdr);
2536 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002537 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002538 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539}
2540
2541/*
2542 * GETATTR_BITMAP request
2543 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002544static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2545 struct xdr_stream *xdr,
2546 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002549 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551
Chuck Lever9f06c712010-12-14 14:59:18 +00002552 encode_compound_hdr(xdr, req, &hdr);
2553 encode_sequence(xdr, &args->seq_args, &hdr);
2554 encode_putfh(xdr, args->fhandle, &hdr);
2555 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002556 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002557 FATTR4_WORD0_LINK_SUPPORT|
2558 FATTR4_WORD0_SYMLINK_SUPPORT|
2559 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002560 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561}
2562
2563/*
2564 * a RENEW request
2565 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002566static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2567 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002570 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 };
2572
Chuck Lever9f06c712010-12-14 14:59:18 +00002573 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002574 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002575 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576}
2577
2578/*
2579 * a SETCLIENTID request
2580 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002581static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2582 struct xdr_stream *xdr,
2583 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002586 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 };
2588
Chuck Lever9f06c712010-12-14 14:59:18 +00002589 encode_compound_hdr(xdr, req, &hdr);
2590 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002591 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592}
2593
2594/*
2595 * a SETCLIENTID_CONFIRM request
2596 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002597static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2598 struct xdr_stream *xdr,
2599 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002602 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
Chuck Lever9f06c712010-12-14 14:59:18 +00002605 encode_compound_hdr(xdr, req, &hdr);
2606 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002607 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608}
2609
2610/*
2611 * DELEGRETURN request
2612 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002613static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2614 struct xdr_stream *xdr,
2615 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002618 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620
Chuck Lever9f06c712010-12-14 14:59:18 +00002621 encode_compound_hdr(xdr, req, &hdr);
2622 encode_sequence(xdr, &args->seq_args, &hdr);
2623 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002624 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002625 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002626 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627}
2628
2629/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002630 * Encode FS_LOCATIONS request
2631 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002632static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2633 struct xdr_stream *xdr,
2634 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002635{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002636 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002637 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002638 };
Benny Halevy28f56692009-04-01 09:22:09 -04002639 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002640
Chuck Lever9f06c712010-12-14 14:59:18 +00002641 encode_compound_hdr(xdr, req, &hdr);
2642 encode_sequence(xdr, &args->seq_args, &hdr);
2643 encode_putfh(xdr, args->dir_fh, &hdr);
2644 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002645 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002646 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002647
Benny Halevy28f56692009-04-01 09:22:09 -04002648 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002649 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002650 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002651}
2652
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002653/*
2654 * Encode SECINFO request
2655 */
2656static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2657 struct xdr_stream *xdr,
2658 struct nfs4_secinfo_arg *args)
2659{
2660 struct compound_hdr hdr = {
2661 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2662 };
2663
2664 encode_compound_hdr(xdr, req, &hdr);
2665 encode_sequence(xdr, &args->seq_args, &hdr);
2666 encode_putfh(xdr, args->dir_fh, &hdr);
2667 encode_secinfo(xdr, args->name, &hdr);
2668 encode_nops(&hdr);
2669}
2670
Benny Halevy99fe60d2009-04-01 09:22:29 -04002671#if defined(CONFIG_NFS_V4_1)
2672/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002673 * BIND_CONN_TO_SESSION request
2674 */
2675static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2676 struct xdr_stream *xdr,
2677 struct nfs_client *clp)
2678{
2679 struct compound_hdr hdr = {
2680 .minorversion = clp->cl_mvops->minor_version,
2681 };
2682
2683 encode_compound_hdr(xdr, req, &hdr);
2684 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2685 encode_nops(&hdr);
2686}
2687
2688/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002689 * EXCHANGE_ID request
2690 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002691static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2692 struct xdr_stream *xdr,
2693 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002694{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002695 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002696 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002697 };
2698
Chuck Lever9f06c712010-12-14 14:59:18 +00002699 encode_compound_hdr(xdr, req, &hdr);
2700 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002701 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002702}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002703
2704/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002705 * a CREATE_SESSION request
2706 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002707static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2708 struct xdr_stream *xdr,
2709 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002710{
Andy Adamsonfc931582009-04-01 09:22:31 -04002711 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002712 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002713 };
2714
Chuck Lever9f06c712010-12-14 14:59:18 +00002715 encode_compound_hdr(xdr, req, &hdr);
2716 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002717 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002718}
2719
2720/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002721 * a DESTROY_SESSION request
2722 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002723static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2724 struct xdr_stream *xdr,
2725 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002726{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002727 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002728 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002729 };
2730
Chuck Lever9f06c712010-12-14 14:59:18 +00002731 encode_compound_hdr(xdr, req, &hdr);
2732 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002733 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002734}
2735
2736/*
Trond Myklebust66245532012-05-25 17:18:09 -04002737 * a DESTROY_CLIENTID request
2738 */
2739static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2740 struct xdr_stream *xdr,
2741 struct nfs_client *clp)
2742{
2743 struct compound_hdr hdr = {
2744 .minorversion = clp->cl_mvops->minor_version,
2745 };
2746
2747 encode_compound_hdr(xdr, req, &hdr);
2748 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2749 encode_nops(&hdr);
2750}
2751
2752/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002753 * a SEQUENCE request
2754 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002755static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2756 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002757{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002758 struct compound_hdr hdr = {
2759 .minorversion = nfs4_xdr_minorversion(args),
2760 };
2761
Chuck Lever9f06c712010-12-14 14:59:18 +00002762 encode_compound_hdr(xdr, req, &hdr);
2763 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002764 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002765}
2766
2767/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002768 * a GET_LEASE_TIME request
2769 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002770static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2771 struct xdr_stream *xdr,
2772 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002773{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002774 struct compound_hdr hdr = {
2775 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2776 };
Fred Isamandae100c2011-07-30 20:52:37 -04002777 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002778
Chuck Lever9f06c712010-12-14 14:59:18 +00002779 encode_compound_hdr(xdr, req, &hdr);
2780 encode_sequence(xdr, &args->la_seq_args, &hdr);
2781 encode_putrootfh(xdr, &hdr);
2782 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002783 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002784}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002785
2786/*
2787 * a RECLAIM_COMPLETE request
2788 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002789static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2790 struct xdr_stream *xdr,
2791 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002792{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002793 struct compound_hdr hdr = {
2794 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2795 };
2796
Chuck Lever9f06c712010-12-14 14:59:18 +00002797 encode_compound_hdr(xdr, req, &hdr);
2798 encode_sequence(xdr, &args->seq_args, &hdr);
2799 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002800 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002801}
2802
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002803/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002804 * Encode GETDEVICELIST request
2805 */
2806static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2807 struct xdr_stream *xdr,
2808 struct nfs4_getdevicelist_args *args)
2809{
2810 struct compound_hdr hdr = {
2811 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2812 };
2813
2814 encode_compound_hdr(xdr, req, &hdr);
2815 encode_sequence(xdr, &args->seq_args, &hdr);
2816 encode_putfh(xdr, args->fh, &hdr);
2817 encode_getdevicelist(xdr, args, &hdr);
2818 encode_nops(&hdr);
2819}
2820
2821/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002822 * Encode GETDEVICEINFO request
2823 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002824static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2825 struct xdr_stream *xdr,
2826 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002827{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002828 struct compound_hdr hdr = {
2829 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2830 };
2831
Chuck Lever9f06c712010-12-14 14:59:18 +00002832 encode_compound_hdr(xdr, req, &hdr);
2833 encode_sequence(xdr, &args->seq_args, &hdr);
2834 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002835
2836 /* set up reply kvec. Subtract notification bitmap max size (2)
2837 * so that notification bitmap is put in xdr_buf tail */
2838 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2839 args->pdev->pages, args->pdev->pgbase,
2840 args->pdev->pglen);
2841
2842 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002843}
2844
2845/*
2846 * Encode LAYOUTGET request
2847 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002848static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2849 struct xdr_stream *xdr,
2850 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002851{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002852 struct compound_hdr hdr = {
2853 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2854 };
2855
Chuck Lever9f06c712010-12-14 14:59:18 +00002856 encode_compound_hdr(xdr, req, &hdr);
2857 encode_sequence(xdr, &args->seq_args, &hdr);
2858 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2859 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002860
2861 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2862 args->layout.pages, 0, args->layout.pglen);
2863
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002864 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002865}
Andy Adamson863a3c62011-03-23 13:27:54 +00002866
2867/*
2868 * Encode LAYOUTCOMMIT request
2869 */
Benny Halevycbe82602011-05-22 19:52:37 +03002870static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2871 struct xdr_stream *xdr,
2872 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002873{
Benny Halevyac7db722011-05-22 19:53:48 +03002874 struct nfs4_layoutcommit_data *data =
2875 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002876 struct compound_hdr hdr = {
2877 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2878 };
2879
2880 encode_compound_hdr(xdr, req, &hdr);
2881 encode_sequence(xdr, &args->seq_args, &hdr);
2882 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002883 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002884 encode_getfattr(xdr, args->bitmask, &hdr);
2885 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002886}
2887
2888/*
2889 * Encode LAYOUTRETURN request
2890 */
2891static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2892 struct xdr_stream *xdr,
2893 struct nfs4_layoutreturn_args *args)
2894{
2895 struct compound_hdr hdr = {
2896 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2897 };
2898
2899 encode_compound_hdr(xdr, req, &hdr);
2900 encode_sequence(xdr, &args->seq_args, &hdr);
2901 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2902 encode_layoutreturn(xdr, args, &hdr);
2903 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002904}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002905
2906/*
2907 * Encode SECINFO_NO_NAME request
2908 */
2909static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2910 struct xdr_stream *xdr,
2911 struct nfs41_secinfo_no_name_args *args)
2912{
2913 struct compound_hdr hdr = {
2914 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2915 };
2916
2917 encode_compound_hdr(xdr, req, &hdr);
2918 encode_sequence(xdr, &args->seq_args, &hdr);
2919 encode_putrootfh(xdr, &hdr);
2920 encode_secinfo_no_name(xdr, args, &hdr);
2921 encode_nops(&hdr);
2922 return 0;
2923}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002924
2925/*
2926 * Encode TEST_STATEID request
2927 */
2928static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2929 struct xdr_stream *xdr,
2930 struct nfs41_test_stateid_args *args)
2931{
2932 struct compound_hdr hdr = {
2933 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2934 };
2935
2936 encode_compound_hdr(xdr, req, &hdr);
2937 encode_sequence(xdr, &args->seq_args, &hdr);
2938 encode_test_stateid(xdr, args, &hdr);
2939 encode_nops(&hdr);
2940}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002941
2942/*
2943 * Encode FREE_STATEID request
2944 */
2945static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2946 struct xdr_stream *xdr,
2947 struct nfs41_free_stateid_args *args)
2948{
2949 struct compound_hdr hdr = {
2950 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2951 };
2952
2953 encode_compound_hdr(xdr, req, &hdr);
2954 encode_sequence(xdr, &args->seq_args, &hdr);
2955 encode_free_stateid(xdr, args, &hdr);
2956 encode_nops(&hdr);
2957}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002958#endif /* CONFIG_NFS_V4_1 */
2959
Benny Halevy686841b2009-08-14 17:19:48 +03002960static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2961{
2962 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2963 "Remaining buffer length is %tu words.\n",
2964 func, xdr->end - xdr->p);
2965}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966
Trond Myklebust683b57b2006-06-09 09:34:22 -04002967static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968{
Al Viro8687b632006-10-19 23:28:48 -07002969 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970
Benny Halevyc0eae662009-08-14 17:20:14 +03002971 p = xdr_inline_decode(xdr, 4);
2972 if (unlikely(!p))
2973 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002974 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002975 p = xdr_inline_decode(xdr, *len);
2976 if (unlikely(!p))
2977 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 *string = (char *)p;
2979 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002980out_overflow:
2981 print_overflow_msg(__func__, xdr);
2982 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983}
2984
2985static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2986{
Al Viro8687b632006-10-19 23:28:48 -07002987 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
Benny Halevyc0eae662009-08-14 17:20:14 +03002989 p = xdr_inline_decode(xdr, 8);
2990 if (unlikely(!p))
2991 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002992 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002993 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002994
Benny Halevyc0eae662009-08-14 17:20:14 +03002995 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2996 if (unlikely(!p))
2997 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 hdr->tag = (char *)p;
2999 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003000 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003001 if (unlikely(hdr->nops < 1))
3002 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003004out_overflow:
3005 print_overflow_msg(__func__, xdr);
3006 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007}
3008
3009static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3010{
Al Viro8687b632006-10-19 23:28:48 -07003011 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 uint32_t opnum;
3013 int32_t nfserr;
3014
Benny Halevyc0eae662009-08-14 17:20:14 +03003015 p = xdr_inline_decode(xdr, 8);
3016 if (unlikely(!p))
3017 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003018 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003020 dprintk("nfs: Server returned operation"
3021 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 opnum, expected);
3023 return -EIO;
3024 }
Benny Halevycccddf42009-08-14 17:20:19 +03003025 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003027 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003029out_overflow:
3030 print_overflow_msg(__func__, xdr);
3031 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032}
3033
3034/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003035static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036{
Al Viro8687b632006-10-19 23:28:48 -07003037 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003038 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 char *str;
3040
Benny Halevyc0eae662009-08-14 17:20:14 +03003041 p = xdr_inline_decode(xdr, 12);
3042 if (likely(p))
3043 return decode_opaque_inline(xdr, &strlen, &str);
3044 print_overflow_msg(__func__, xdr);
3045 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046}
3047
3048static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3049{
Al Viro8687b632006-10-19 23:28:48 -07003050 uint32_t bmlen;
3051 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052
Benny Halevyc0eae662009-08-14 17:20:14 +03003053 p = xdr_inline_decode(xdr, 4);
3054 if (unlikely(!p))
3055 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003056 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
Fred Isamandae100c2011-07-30 20:52:37 -04003058 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003059 p = xdr_inline_decode(xdr, (bmlen << 2));
3060 if (unlikely(!p))
3061 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003063 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003064 if (bmlen > 1) {
3065 bitmap[1] = be32_to_cpup(p++);
3066 if (bmlen > 2)
3067 bitmap[2] = be32_to_cpup(p);
3068 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 }
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
Trond Myklebust256e48b2012-06-21 11:18:13 -04003076static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077{
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, 4);
3081 if (unlikely(!p))
3082 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003083 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003084 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003086out_overflow:
3087 print_overflow_msg(__func__, xdr);
3088 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089}
3090
3091static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3092{
3093 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003094 int ret;
3095 ret = decode_attr_bitmap(xdr, bitmask);
3096 if (unlikely(ret < 0))
3097 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3099 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003100 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3101 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3102 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 return 0;
3104}
3105
3106static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3107{
Al Viro8687b632006-10-19 23:28:48 -07003108 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003109 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
3111 *type = 0;
3112 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3113 return -EIO;
3114 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003115 p = xdr_inline_decode(xdr, 4);
3116 if (unlikely(!p))
3117 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003118 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003120 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 return -EIO;
3122 }
3123 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003124 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003126 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003127 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003128out_overflow:
3129 print_overflow_msg(__func__, xdr);
3130 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131}
3132
Chuck Lever264e6352012-03-01 17:02:05 -05003133static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3134 uint32_t *bitmap, uint32_t *type)
3135{
3136 __be32 *p;
3137
3138 *type = 0;
3139 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3140 return -EIO;
3141 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3142 p = xdr_inline_decode(xdr, 4);
3143 if (unlikely(!p))
3144 goto out_overflow;
3145 *type = be32_to_cpup(p);
3146 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3147 }
3148 dprintk("%s: expire type=0x%x\n", __func__, *type);
3149 return 0;
3150out_overflow:
3151 print_overflow_msg(__func__, xdr);
3152 return -EIO;
3153}
3154
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3156{
Al Viro8687b632006-10-19 23:28:48 -07003157 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003158 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159
3160 *change = 0;
3161 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3162 return -EIO;
3163 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003164 p = xdr_inline_decode(xdr, 8);
3165 if (unlikely(!p))
3166 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003167 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003169 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003171 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003173 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003174out_overflow:
3175 print_overflow_msg(__func__, xdr);
3176 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177}
3178
3179static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3180{
Al Viro8687b632006-10-19 23:28:48 -07003181 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003182 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183
3184 *size = 0;
3185 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3186 return -EIO;
3187 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003188 p = xdr_inline_decode(xdr, 8);
3189 if (unlikely(!p))
3190 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003191 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003193 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003195 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003196 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003197out_overflow:
3198 print_overflow_msg(__func__, xdr);
3199 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200}
3201
3202static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3203{
Al Viro8687b632006-10-19 23:28:48 -07003204 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205
3206 *res = 0;
3207 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3208 return -EIO;
3209 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003210 p = xdr_inline_decode(xdr, 4);
3211 if (unlikely(!p))
3212 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003213 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3215 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003216 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003218out_overflow:
3219 print_overflow_msg(__func__, xdr);
3220 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221}
3222
3223static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3224{
Al Viro8687b632006-10-19 23:28:48 -07003225 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226
3227 *res = 0;
3228 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3229 return -EIO;
3230 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003231 p = xdr_inline_decode(xdr, 4);
3232 if (unlikely(!p))
3233 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003234 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3236 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003237 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003239out_overflow:
3240 print_overflow_msg(__func__, xdr);
3241 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242}
3243
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003244static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245{
Al Viro8687b632006-10-19 23:28:48 -07003246 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003247 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248
3249 fsid->major = 0;
3250 fsid->minor = 0;
3251 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3252 return -EIO;
3253 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003254 p = xdr_inline_decode(xdr, 16);
3255 if (unlikely(!p))
3256 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003257 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003258 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003260 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003262 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 (unsigned long long)fsid->major,
3264 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003265 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003266out_overflow:
3267 print_overflow_msg(__func__, xdr);
3268 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269}
3270
3271static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3272{
Al Viro8687b632006-10-19 23:28:48 -07003273 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
3275 *res = 60;
3276 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3277 return -EIO;
3278 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003279 p = xdr_inline_decode(xdr, 4);
3280 if (unlikely(!p))
3281 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003282 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3284 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003285 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003287out_overflow:
3288 print_overflow_msg(__func__, xdr);
3289 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290}
3291
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003292static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003293{
3294 __be32 *p;
3295
3296 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3297 return -EIO;
3298 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3299 p = xdr_inline_decode(xdr, 4);
3300 if (unlikely(!p))
3301 goto out_overflow;
3302 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003303 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003304 }
3305 return 0;
3306out_overflow:
3307 print_overflow_msg(__func__, xdr);
3308 return -EIO;
3309}
3310
3311static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3312{
3313 __be32 *p;
3314 int len;
3315
Trond Myklebust7ad07352010-10-23 15:34:20 -04003316 if (fh != NULL)
3317 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003318
3319 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3320 return -EIO;
3321 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3322 p = xdr_inline_decode(xdr, 4);
3323 if (unlikely(!p))
3324 goto out_overflow;
3325 len = be32_to_cpup(p);
3326 if (len > NFS4_FHSIZE)
3327 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003328 p = xdr_inline_decode(xdr, len);
3329 if (unlikely(!p))
3330 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003331 if (fh != NULL) {
3332 memcpy(fh->data, p, len);
3333 fh->size = len;
3334 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003335 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3336 }
3337 return 0;
3338out_overflow:
3339 print_overflow_msg(__func__, xdr);
3340 return -EIO;
3341}
3342
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3344{
Al Viro8687b632006-10-19 23:28:48 -07003345 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346
3347 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3348 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3349 return -EIO;
3350 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003351 p = xdr_inline_decode(xdr, 4);
3352 if (unlikely(!p))
3353 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003354 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3356 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003357 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003359out_overflow:
3360 print_overflow_msg(__func__, xdr);
3361 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362}
3363
3364static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3365{
Al Viro8687b632006-10-19 23:28:48 -07003366 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003367 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368
3369 *fileid = 0;
3370 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3371 return -EIO;
3372 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003373 p = xdr_inline_decode(xdr, 8);
3374 if (unlikely(!p))
3375 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003376 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003378 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003380 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003381 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003382out_overflow:
3383 print_overflow_msg(__func__, xdr);
3384 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385}
3386
Manoj Naik99baf622006-06-09 09:34:24 -04003387static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3388{
Al Viro8687b632006-10-19 23:28:48 -07003389 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003390 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003391
3392 *fileid = 0;
3393 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3394 return -EIO;
3395 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003396 p = xdr_inline_decode(xdr, 8);
3397 if (unlikely(!p))
3398 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003399 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003400 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003401 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003402 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003403 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003404 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003405out_overflow:
3406 print_overflow_msg(__func__, xdr);
3407 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003408}
3409
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3411{
Al Viro8687b632006-10-19 23:28:48 -07003412 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 int status = 0;
3414
3415 *res = 0;
3416 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3417 return -EIO;
3418 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003419 p = xdr_inline_decode(xdr, 8);
3420 if (unlikely(!p))
3421 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003422 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3424 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003425 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003427out_overflow:
3428 print_overflow_msg(__func__, xdr);
3429 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430}
3431
3432static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3433{
Al Viro8687b632006-10-19 23:28:48 -07003434 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 int status = 0;
3436
3437 *res = 0;
3438 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3439 return -EIO;
3440 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003441 p = xdr_inline_decode(xdr, 8);
3442 if (unlikely(!p))
3443 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003444 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3446 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003447 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003449out_overflow:
3450 print_overflow_msg(__func__, xdr);
3451 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452}
3453
3454static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3455{
Al Viro8687b632006-10-19 23:28:48 -07003456 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 int status = 0;
3458
3459 *res = 0;
3460 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3461 return -EIO;
3462 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003463 p = xdr_inline_decode(xdr, 8);
3464 if (unlikely(!p))
3465 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003466 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3468 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003469 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003471out_overflow:
3472 print_overflow_msg(__func__, xdr);
3473 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474}
3475
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003476static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3477{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003478 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003479 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003480 int status = 0;
3481
Benny Halevyc0eae662009-08-14 17:20:14 +03003482 p = xdr_inline_decode(xdr, 4);
3483 if (unlikely(!p))
3484 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003485 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003486 if (n == 0)
3487 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003488 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003489 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3490 dprintk("cannot parse %d components in path\n", n);
3491 goto out_eio;
3492 }
3493 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003494 struct nfs4_string *component = &path->components[path->ncomponents];
3495 status = decode_opaque_inline(xdr, &component->len, &component->data);
3496 if (unlikely(status != 0))
3497 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003498 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003499 pr_cont("%s%.*s ",
3500 (path->ncomponents != n ? "/ " : ""),
3501 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003502 }
3503out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003504 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003505root_path:
3506/* a root pathname is sent as a zero component4 */
3507 path->ncomponents = 1;
3508 path->components[0].len=0;
3509 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003510 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003511 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003512out_eio:
3513 dprintk(" status %d", status);
3514 status = -EIO;
3515 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003516out_overflow:
3517 print_overflow_msg(__func__, xdr);
3518 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003519}
3520
3521static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003522{
3523 int n;
Al Viro8687b632006-10-19 23:28:48 -07003524 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003525 int status = -EIO;
3526
3527 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3528 goto out;
3529 status = 0;
3530 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3531 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003532 status = -EIO;
3533 /* Ignore borken servers that return unrequested attrs */
3534 if (unlikely(res == NULL))
3535 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003536 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003537 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003538 if (unlikely(status != 0))
3539 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003540 p = xdr_inline_decode(xdr, 4);
3541 if (unlikely(!p))
3542 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003543 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003544 if (n <= 0)
3545 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003546 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003547 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003548 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003549
Trond Myklebust809b4262013-03-27 11:54:45 -04003550 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3551 break;
3552 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003553 p = xdr_inline_decode(xdr, 4);
3554 if (unlikely(!p))
3555 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003556 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003557
Chuck Lever02a29762012-03-01 17:00:31 -05003558 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003559 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3560 struct nfs4_string *server;
3561
3562 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003563 unsigned int i;
3564 dprintk("%s: using first %u of %u servers "
3565 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003566 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003567 NFS4_FS_LOCATION_MAXSERVERS,
3568 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003569 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003570 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003571 char *data;
3572 status = decode_opaque_inline(xdr, &len, &data);
3573 if (unlikely(status != 0))
3574 goto out_eio;
3575 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003576 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003577 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003578 server = &loc->servers[loc->nservers];
3579 status = decode_opaque_inline(xdr, &server->len, &server->data);
3580 if (unlikely(status != 0))
3581 goto out_eio;
3582 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003583 }
3584 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003585 if (unlikely(status != 0))
3586 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003587 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003588 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003589 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003590out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003591 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003592 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003593out_overflow:
3594 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003595out_eio:
3596 status = -EIO;
3597 goto out;
3598}
3599
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3601{
Al Viro8687b632006-10-19 23:28:48 -07003602 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 int status = 0;
3604
3605 *res = 0;
3606 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3607 return -EIO;
3608 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003609 p = xdr_inline_decode(xdr, 8);
3610 if (unlikely(!p))
3611 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003612 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3614 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003615 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003617out_overflow:
3618 print_overflow_msg(__func__, xdr);
3619 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620}
3621
3622static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3623{
Al Viro8687b632006-10-19 23:28:48 -07003624 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 int status = 0;
3626
3627 *maxlink = 1;
3628 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3629 return -EIO;
3630 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003631 p = xdr_inline_decode(xdr, 4);
3632 if (unlikely(!p))
3633 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003634 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3636 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003637 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003639out_overflow:
3640 print_overflow_msg(__func__, xdr);
3641 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642}
3643
3644static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3645{
Al Viro8687b632006-10-19 23:28:48 -07003646 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 int status = 0;
3648
3649 *maxname = 1024;
3650 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3651 return -EIO;
3652 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003653 p = xdr_inline_decode(xdr, 4);
3654 if (unlikely(!p))
3655 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003656 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3658 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003659 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003661out_overflow:
3662 print_overflow_msg(__func__, xdr);
3663 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664}
3665
3666static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3667{
Al Viro8687b632006-10-19 23:28:48 -07003668 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 int status = 0;
3670
3671 *res = 1024;
3672 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3673 return -EIO;
3674 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3675 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003676 p = xdr_inline_decode(xdr, 8);
3677 if (unlikely(!p))
3678 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003679 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680 if (maxread > 0x7FFFFFFF)
3681 maxread = 0x7FFFFFFF;
3682 *res = (uint32_t)maxread;
3683 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3684 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003685 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003687out_overflow:
3688 print_overflow_msg(__func__, xdr);
3689 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690}
3691
3692static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3693{
Al Viro8687b632006-10-19 23:28:48 -07003694 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 int status = 0;
3696
3697 *res = 1024;
3698 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3699 return -EIO;
3700 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3701 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003702 p = xdr_inline_decode(xdr, 8);
3703 if (unlikely(!p))
3704 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003705 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706 if (maxwrite > 0x7FFFFFFF)
3707 maxwrite = 0x7FFFFFFF;
3708 *res = (uint32_t)maxwrite;
3709 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3710 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003711 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003713out_overflow:
3714 print_overflow_msg(__func__, xdr);
3715 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716}
3717
Trond Myklebustbca79472009-03-11 14:10:26 -04003718static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719{
Trond Myklebustbca79472009-03-11 14:10:26 -04003720 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003721 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003722 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723
3724 *mode = 0;
3725 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3726 return -EIO;
3727 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003728 p = xdr_inline_decode(xdr, 4);
3729 if (unlikely(!p))
3730 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003731 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003732 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003734 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003736 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003737 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003738out_overflow:
3739 print_overflow_msg(__func__, xdr);
3740 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741}
3742
3743static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3744{
Al Viro8687b632006-10-19 23:28:48 -07003745 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003746 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747
3748 *nlink = 1;
3749 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3750 return -EIO;
3751 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003752 p = xdr_inline_decode(xdr, 4);
3753 if (unlikely(!p))
3754 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003755 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003757 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003759 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003760 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003761out_overflow:
3762 print_overflow_msg(__func__, xdr);
3763 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764}
3765
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003766static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003767 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003768 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769{
Al Viro8687b632006-10-19 23:28:48 -07003770 uint32_t len;
3771 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003772 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773
Eric W. Biedermane5782072013-02-01 14:22:02 -08003774 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3776 return -EIO;
3777 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003778 p = xdr_inline_decode(xdr, 4);
3779 if (unlikely(!p))
3780 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003781 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003782 p = xdr_inline_decode(xdr, len);
3783 if (unlikely(!p))
3784 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003785 if (owner_name != NULL) {
3786 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3787 if (owner_name->data != NULL) {
3788 owner_name->len = len;
3789 ret = NFS_ATTR_FATTR_OWNER_NAME;
3790 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003791 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003792 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003793 ret = NFS_ATTR_FATTR_OWNER;
3794 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003796 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003798 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003799 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3801 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003802 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003803 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003804out_overflow:
3805 print_overflow_msg(__func__, xdr);
3806 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807}
3808
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003809static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003810 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003811 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812{
Al Viro8687b632006-10-19 23:28:48 -07003813 uint32_t len;
3814 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003815 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816
Eric W. Biedermane5782072013-02-01 14:22:02 -08003817 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3819 return -EIO;
3820 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003821 p = xdr_inline_decode(xdr, 4);
3822 if (unlikely(!p))
3823 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003824 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003825 p = xdr_inline_decode(xdr, len);
3826 if (unlikely(!p))
3827 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003828 if (group_name != NULL) {
3829 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3830 if (group_name->data != NULL) {
3831 group_name->len = len;
3832 ret = NFS_ATTR_FATTR_GROUP_NAME;
3833 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003834 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003835 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003836 ret = NFS_ATTR_FATTR_GROUP;
3837 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003839 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003841 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003842 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3844 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003845 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003846 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003847out_overflow:
3848 print_overflow_msg(__func__, xdr);
3849 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850}
3851
3852static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3853{
Al Viro8687b632006-10-19 23:28:48 -07003854 uint32_t major = 0, minor = 0;
3855 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003856 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857
3858 *rdev = MKDEV(0,0);
3859 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3860 return -EIO;
3861 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3862 dev_t tmp;
3863
Benny Halevyc0eae662009-08-14 17:20:14 +03003864 p = xdr_inline_decode(xdr, 8);
3865 if (unlikely(!p))
3866 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003867 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003868 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 tmp = MKDEV(major, minor);
3870 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3871 *rdev = tmp;
3872 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003873 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003875 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003876 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003877out_overflow:
3878 print_overflow_msg(__func__, xdr);
3879 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880}
3881
3882static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3883{
Al Viro8687b632006-10-19 23:28:48 -07003884 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 int status = 0;
3886
3887 *res = 0;
3888 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3889 return -EIO;
3890 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003891 p = xdr_inline_decode(xdr, 8);
3892 if (unlikely(!p))
3893 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003894 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3896 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003897 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003899out_overflow:
3900 print_overflow_msg(__func__, xdr);
3901 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902}
3903
3904static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3905{
Al Viro8687b632006-10-19 23:28:48 -07003906 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 int status = 0;
3908
3909 *res = 0;
3910 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3911 return -EIO;
3912 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003913 p = xdr_inline_decode(xdr, 8);
3914 if (unlikely(!p))
3915 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003916 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3918 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003919 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003921out_overflow:
3922 print_overflow_msg(__func__, xdr);
3923 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924}
3925
3926static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3927{
Al Viro8687b632006-10-19 23:28:48 -07003928 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 int status = 0;
3930
3931 *res = 0;
3932 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3933 return -EIO;
3934 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003935 p = xdr_inline_decode(xdr, 8);
3936 if (unlikely(!p))
3937 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003938 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3940 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003941 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003943out_overflow:
3944 print_overflow_msg(__func__, xdr);
3945 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946}
3947
3948static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3949{
Al Viro8687b632006-10-19 23:28:48 -07003950 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003951 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952
3953 *used = 0;
3954 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3955 return -EIO;
3956 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003957 p = xdr_inline_decode(xdr, 8);
3958 if (unlikely(!p))
3959 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003960 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003962 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003964 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003966 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003967out_overflow:
3968 print_overflow_msg(__func__, xdr);
3969 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970}
3971
3972static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3973{
Al Viro8687b632006-10-19 23:28:48 -07003974 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975 uint64_t sec;
3976 uint32_t nsec;
3977
Benny Halevyc0eae662009-08-14 17:20:14 +03003978 p = xdr_inline_decode(xdr, 12);
3979 if (unlikely(!p))
3980 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003981 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003982 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 time->tv_sec = (time_t)sec;
3984 time->tv_nsec = (long)nsec;
3985 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003986out_overflow:
3987 print_overflow_msg(__func__, xdr);
3988 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989}
3990
3991static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3992{
3993 int status = 0;
3994
3995 time->tv_sec = 0;
3996 time->tv_nsec = 0;
3997 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3998 return -EIO;
3999 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4000 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004001 if (status == 0)
4002 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4004 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004005 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 return status;
4007}
4008
4009static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4010{
4011 int status = 0;
4012
4013 time->tv_sec = 0;
4014 time->tv_nsec = 0;
4015 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4016 return -EIO;
4017 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4018 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004019 if (status == 0)
4020 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4022 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004023 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 return status;
4025}
4026
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004027static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4028 struct timespec *time)
4029{
4030 int status = 0;
4031
4032 time->tv_sec = 0;
4033 time->tv_nsec = 0;
4034 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4035 return -EIO;
4036 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4037 status = decode_attr_time(xdr, time);
4038 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4039 }
4040 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4041 (long)time->tv_nsec);
4042 return status;
4043}
4044
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4046{
4047 int status = 0;
4048
4049 time->tv_sec = 0;
4050 time->tv_nsec = 0;
4051 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4052 return -EIO;
4053 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4054 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004055 if (status == 0)
4056 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4058 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004059 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 return status;
4061}
4062
Trond Myklebust256e48b2012-06-21 11:18:13 -04004063static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064{
4065 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004066 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067
4068 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004069 dprintk("%s: server returned incorrect attribute length: "
4070 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004071 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 attrwords << 2,
4073 (attrwords < nwords) ? '<' : '>',
4074 nwords << 2);
4075 return -EIO;
4076 }
4077 return 0;
4078}
4079
4080static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4081{
Al Viro8687b632006-10-19 23:28:48 -07004082 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083
Benny Halevyc0eae662009-08-14 17:20:14 +03004084 p = xdr_inline_decode(xdr, 20);
4085 if (unlikely(!p))
4086 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004087 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004088 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004089 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 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
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004096static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097{
Al Viro8687b632006-10-19 23:28:48 -07004098 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 uint32_t supp, acc;
4100 int status;
4101
4102 status = decode_op_hdr(xdr, OP_ACCESS);
4103 if (status)
4104 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004105 p = xdr_inline_decode(xdr, 8);
4106 if (unlikely(!p))
4107 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004108 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004109 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004110 *supported = supp;
4111 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004113out_overflow:
4114 print_overflow_msg(__func__, xdr);
4115 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116}
4117
Benny Halevy07d30432009-08-14 17:19:52 +03004118static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119{
Al Viro8687b632006-10-19 23:28:48 -07004120 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004121
4122 p = xdr_inline_decode(xdr, len);
4123 if (likely(p)) {
4124 memcpy(buf, p, len);
4125 return 0;
4126 }
4127 print_overflow_msg(__func__, xdr);
4128 return -EIO;
4129}
4130
4131static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4132{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004133 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134}
4135
4136static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4137{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 int status;
4139
4140 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004141 if (status != -EIO)
4142 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004143 if (!status)
4144 status = decode_stateid(xdr, &res->stateid);
4145 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146}
4147
Benny Halevydb942bb2009-08-14 17:19:56 +03004148static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4149{
Chuck Levercd937102012-03-02 17:14:31 -05004150 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151}
4152
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004153static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4154{
4155 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4156}
4157
Fred Isaman0b7c0152012-04-20 14:47:39 -04004158static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 int status;
4161
4162 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004163 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004164 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004165 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166}
4167
4168static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4169{
Al Viro8687b632006-10-19 23:28:48 -07004170 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171 uint32_t bmlen;
4172 int status;
4173
4174 status = decode_op_hdr(xdr, OP_CREATE);
4175 if (status)
4176 return status;
4177 if ((status = decode_change_info(xdr, cinfo)))
4178 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004179 p = xdr_inline_decode(xdr, 4);
4180 if (unlikely(!p))
4181 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004182 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004183 p = xdr_inline_decode(xdr, bmlen << 2);
4184 if (likely(p))
4185 return 0;
4186out_overflow:
4187 print_overflow_msg(__func__, xdr);
4188 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189}
4190
4191static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4192{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004193 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004194 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 int status;
4196
4197 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4198 goto xdr_error;
4199 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4200 goto xdr_error;
4201 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4202 goto xdr_error;
4203 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4204 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004205 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4206 &res->fh_expire_type)) != 0)
4207 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4209 goto xdr_error;
4210 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4211 goto xdr_error;
4212 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4213 goto xdr_error;
4214 status = verify_attr_len(xdr, savep, attrlen);
4215xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004216 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 return status;
4218}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004219
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4221{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004222 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004223 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004225
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4227 goto xdr_error;
4228 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4229 goto xdr_error;
4230 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4231 goto xdr_error;
4232
4233 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4234 goto xdr_error;
4235 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4236 goto xdr_error;
4237 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4238 goto xdr_error;
4239 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4240 goto xdr_error;
4241 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4242 goto xdr_error;
4243 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4244 goto xdr_error;
4245
4246 status = verify_attr_len(xdr, savep, attrlen);
4247xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004248 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 return status;
4250}
4251
4252static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4253{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004254 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004255 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004257
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4259 goto xdr_error;
4260 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4261 goto xdr_error;
4262 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4263 goto xdr_error;
4264
4265 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4266 goto xdr_error;
4267 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4268 goto xdr_error;
4269
4270 status = verify_attr_len(xdr, savep, attrlen);
4271xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004272 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273 return status;
4274}
4275
Andy Adamson88034c32012-05-23 05:02:34 -04004276static int decode_threshold_hint(struct xdr_stream *xdr,
4277 uint32_t *bitmap,
4278 uint64_t *res,
4279 uint32_t hint_bit)
4280{
4281 __be32 *p;
4282
4283 *res = 0;
4284 if (likely(bitmap[0] & hint_bit)) {
4285 p = xdr_inline_decode(xdr, 8);
4286 if (unlikely(!p))
4287 goto out_overflow;
4288 xdr_decode_hyper(p, res);
4289 }
4290 return 0;
4291out_overflow:
4292 print_overflow_msg(__func__, xdr);
4293 return -EIO;
4294}
4295
4296static int decode_first_threshold_item4(struct xdr_stream *xdr,
4297 struct nfs4_threshold *res)
4298{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004299 __be32 *p;
4300 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004301 uint32_t bitmap[3] = {0,}, attrlen;
4302 int status;
4303
4304 /* layout type */
4305 p = xdr_inline_decode(xdr, 4);
4306 if (unlikely(!p)) {
4307 print_overflow_msg(__func__, xdr);
4308 return -EIO;
4309 }
4310 res->l_type = be32_to_cpup(p);
4311
4312 /* thi_hintset bitmap */
4313 status = decode_attr_bitmap(xdr, bitmap);
4314 if (status < 0)
4315 goto xdr_error;
4316
4317 /* thi_hintlist length */
4318 status = decode_attr_length(xdr, &attrlen, &savep);
4319 if (status < 0)
4320 goto xdr_error;
4321 /* thi_hintlist */
4322 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4323 if (status < 0)
4324 goto xdr_error;
4325 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4326 if (status < 0)
4327 goto xdr_error;
4328 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4329 THRESHOLD_RD_IO);
4330 if (status < 0)
4331 goto xdr_error;
4332 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4333 THRESHOLD_WR_IO);
4334 if (status < 0)
4335 goto xdr_error;
4336
4337 status = verify_attr_len(xdr, savep, attrlen);
4338 res->bm = bitmap[0];
4339
4340 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4341 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4342 res->wr_io_sz);
4343xdr_error:
4344 dprintk("%s ret=%d!\n", __func__, status);
4345 return status;
4346}
4347
4348/*
4349 * Thresholds on pNFS direct I/O vrs MDS I/O
4350 */
4351static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4352 uint32_t *bitmap,
4353 struct nfs4_threshold *res)
4354{
4355 __be32 *p;
4356 int status = 0;
4357 uint32_t num;
4358
4359 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4360 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004361 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004362 /* Did the server return an unrequested attribute? */
4363 if (unlikely(res == NULL))
4364 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004365 p = xdr_inline_decode(xdr, 4);
4366 if (unlikely(!p))
4367 goto out_overflow;
4368 num = be32_to_cpup(p);
4369 if (num == 0)
4370 return 0;
4371 if (num > 1)
4372 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4373 "drivers per filesystem not supported\n",
4374 __func__);
4375
4376 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004377 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004378 }
4379 return status;
4380out_overflow:
4381 print_overflow_msg(__func__, xdr);
4382 return -EIO;
4383}
4384
Bryan Schumakerae42c702010-10-21 16:33:17 -04004385static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4386 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004387 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004388 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389{
Trond Myklebustbca79472009-03-11 14:10:26 -04004390 int status;
4391 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004392 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004393 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004395 status = decode_attr_type(xdr, bitmap, &type);
4396 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004398 fattr->mode = 0;
4399 if (status != 0) {
4400 fattr->mode |= nfs_type2fmt[type];
4401 fattr->valid |= status;
4402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004404 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4405 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004407 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004408
4409 status = decode_attr_size(xdr, bitmap, &fattr->size);
4410 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004412 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004413
4414 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4415 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004417 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004418
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004419 err = 0;
4420 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004421 if (status < 0)
4422 goto xdr_error;
4423
4424 status = decode_attr_filehandle(xdr, bitmap, fh);
4425 if (status < 0)
4426 goto xdr_error;
4427
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004428 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4429 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004431 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004432
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004433 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004434 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004435 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004436 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004437
4438 status = decode_attr_mode(xdr, bitmap, &fmode);
4439 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004441 if (status != 0) {
4442 fattr->mode |= fmode;
4443 fattr->valid |= status;
4444 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004445
4446 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4447 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004449 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004450
Trond Myklebust6926afd2012-01-07 13:22:46 -05004451 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004452 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004454 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004455
Trond Myklebust6926afd2012-01-07 13:22:46 -05004456 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004457 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004459 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004460
4461 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4462 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004464 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004465
4466 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4467 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004469 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004470
4471 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4472 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004474 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004475
4476 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4477 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004479 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004480
4481 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4482 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004484 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004485
Trond Myklebust28331a42011-04-27 13:47:52 -04004486 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004487 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004488 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004489 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004490
Andy Adamson88034c32012-05-23 05:02:34 -04004491 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4492 if (status < 0)
4493 goto xdr_error;
4494
Bryan Schumakerae42c702010-10-21 16:33:17 -04004495xdr_error:
4496 dprintk("%s: xdr returned %d\n", __func__, -status);
4497 return status;
4498}
4499
4500static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004501 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4502 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004503{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004504 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004505 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004506 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004507 int status;
4508
4509 status = decode_op_hdr(xdr, OP_GETATTR);
4510 if (status < 0)
4511 goto xdr_error;
4512
4513 status = decode_attr_bitmap(xdr, bitmap);
4514 if (status < 0)
4515 goto xdr_error;
4516
4517 status = decode_attr_length(xdr, &attrlen, &savep);
4518 if (status < 0)
4519 goto xdr_error;
4520
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004521 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004522 if (status < 0)
4523 goto xdr_error;
4524
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004525 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004526xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004527 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 return status;
4529}
4530
Bryan Schumakerae42c702010-10-21 16:33:17 -04004531static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004532 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004533{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004534 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004535}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536
Andy Adamson504913f2010-10-20 00:17:57 -04004537/*
4538 * Decode potentially multiple layout types. Currently we only support
4539 * one layout driver per file system.
4540 */
4541static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4542 uint32_t *layouttype)
4543{
4544 uint32_t *p;
4545 int num;
4546
4547 p = xdr_inline_decode(xdr, 4);
4548 if (unlikely(!p))
4549 goto out_overflow;
4550 num = be32_to_cpup(p);
4551
4552 /* pNFS is not supported by the underlying file system */
4553 if (num == 0) {
4554 *layouttype = 0;
4555 return 0;
4556 }
4557 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004558 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4559 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004560
4561 /* Decode and set first layout type, move xdr->p past unused types */
4562 p = xdr_inline_decode(xdr, num * 4);
4563 if (unlikely(!p))
4564 goto out_overflow;
4565 *layouttype = be32_to_cpup(p);
4566 return 0;
4567out_overflow:
4568 print_overflow_msg(__func__, xdr);
4569 return -EIO;
4570}
4571
4572/*
4573 * The type of file system exported.
4574 * Note we must ensure that layouttype is set in any non-error case.
4575 */
4576static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4577 uint32_t *layouttype)
4578{
4579 int status = 0;
4580
4581 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4582 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4583 return -EIO;
4584 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4585 status = decode_first_pnfs_layout_type(xdr, layouttype);
4586 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4587 } else
4588 *layouttype = 0;
4589 return status;
4590}
4591
Fred Isamandae100c2011-07-30 20:52:37 -04004592/*
4593 * The prefered block size for layout directed io
4594 */
4595static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4596 uint32_t *res)
4597{
4598 __be32 *p;
4599
4600 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4601 *res = 0;
4602 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4603 p = xdr_inline_decode(xdr, 4);
4604 if (unlikely(!p)) {
4605 print_overflow_msg(__func__, xdr);
4606 return -EIO;
4607 }
4608 *res = be32_to_cpup(p);
4609 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4610 }
4611 return 0;
4612}
4613
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4615{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004616 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004617 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618 int status;
4619
4620 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4621 goto xdr_error;
4622 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4623 goto xdr_error;
4624 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4625 goto xdr_error;
4626
4627 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4628
4629 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4630 goto xdr_error;
4631 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4632 goto xdr_error;
4633 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4634 goto xdr_error;
4635 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4636 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4637 goto xdr_error;
4638 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004639 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4640 if (status != 0)
4641 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004642 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4643 if (status != 0)
4644 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004645 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4646 if (status)
4647 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648
4649 status = verify_attr_len(xdr, savep, attrlen);
4650xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004651 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652 return status;
4653}
4654
4655static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4656{
Al Viro8687b632006-10-19 23:28:48 -07004657 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658 uint32_t len;
4659 int status;
4660
Trond Myklebust99367812007-07-17 21:52:41 -04004661 /* Zero handle first to allow comparisons */
4662 memset(fh, 0, sizeof(*fh));
4663
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664 status = decode_op_hdr(xdr, OP_GETFH);
4665 if (status)
4666 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004667
Benny Halevyc0eae662009-08-14 17:20:14 +03004668 p = xdr_inline_decode(xdr, 4);
4669 if (unlikely(!p))
4670 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004671 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672 if (len > NFS4_FHSIZE)
4673 return -EIO;
4674 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004675 p = xdr_inline_decode(xdr, len);
4676 if (unlikely(!p))
4677 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004678 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004679 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004680out_overflow:
4681 print_overflow_msg(__func__, xdr);
4682 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683}
4684
4685static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4686{
4687 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004688
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689 status = decode_op_hdr(xdr, OP_LINK);
4690 if (status)
4691 return status;
4692 return decode_change_info(xdr, cinfo);
4693}
4694
4695/*
4696 * We create the owner, so we know a proper owner.id length is 4.
4697 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004698static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004699{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004700 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004701 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004702 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004704 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004705 if (unlikely(!p))
4706 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004707 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004708 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004709 type = be32_to_cpup(p++); /* 4 byte read */
4710 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004711 fl->fl_start = (loff_t)offset;
4712 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4713 if (length == ~(uint64_t)0)
4714 fl->fl_end = OFFSET_MAX;
4715 fl->fl_type = F_WRLCK;
4716 if (type & 1)
4717 fl->fl_type = F_RDLCK;
4718 fl->fl_pid = 0;
4719 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004720 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4721 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4722 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004723 if (likely(p))
4724 return -NFS4ERR_DENIED;
4725out_overflow:
4726 print_overflow_msg(__func__, xdr);
4727 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728}
4729
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004730static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732 int status;
4733
4734 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004735 if (status == -EIO)
4736 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004738 status = decode_stateid(xdr, &res->stateid);
4739 if (unlikely(status))
4740 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004742 status = decode_lock_denied(xdr, NULL);
4743 if (res->open_seqid != NULL)
4744 nfs_increment_open_seqid(status, res->open_seqid);
4745 nfs_increment_lock_seqid(status, res->lock_seqid);
4746out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747 return status;
4748}
4749
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004750static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751{
4752 int status;
4753 status = decode_op_hdr(xdr, OP_LOCKT);
4754 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004755 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756 return status;
4757}
4758
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004759static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004761 int status;
4762
4763 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004764 if (status != -EIO)
4765 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004766 if (status == 0)
4767 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768 return status;
4769}
4770
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004771static int decode_release_lockowner(struct xdr_stream *xdr)
4772{
4773 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4774}
4775
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776static int decode_lookup(struct xdr_stream *xdr)
4777{
4778 return decode_op_hdr(xdr, OP_LOOKUP);
4779}
4780
4781/* This is too sick! */
4782static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4783{
Andy Adamson05d564f2008-12-23 16:06:15 -05004784 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 uint32_t limit_type, nblocks, blocksize;
4786
Benny Halevyc0eae662009-08-14 17:20:14 +03004787 p = xdr_inline_decode(xdr, 12);
4788 if (unlikely(!p))
4789 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004790 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004791 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004792 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004793 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004794 break;
4795 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004796 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004797 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004798 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799 }
4800 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004801out_overflow:
4802 print_overflow_msg(__func__, xdr);
4803 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804}
4805
4806static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4807{
Andy Adamson05d564f2008-12-23 16:06:15 -05004808 __be32 *p;
4809 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004810 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811
Benny Halevyc0eae662009-08-14 17:20:14 +03004812 p = xdr_inline_decode(xdr, 4);
4813 if (unlikely(!p))
4814 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004815 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004816 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4817 res->delegation_type = 0;
4818 return 0;
4819 }
Benny Halevy07d30432009-08-14 17:19:52 +03004820 status = decode_stateid(xdr, &res->delegation);
4821 if (unlikely(status))
4822 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004823 p = xdr_inline_decode(xdr, 4);
4824 if (unlikely(!p))
4825 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004826 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004827
Linus Torvalds1da177e2005-04-16 15:20:36 -07004828 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004829 case NFS4_OPEN_DELEGATE_READ:
4830 res->delegation_type = FMODE_READ;
4831 break;
4832 case NFS4_OPEN_DELEGATE_WRITE:
4833 res->delegation_type = FMODE_WRITE|FMODE_READ;
4834 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835 return -EIO;
4836 }
David Howells7539bba2006-08-22 20:06:09 -04004837 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004838out_overflow:
4839 print_overflow_msg(__func__, xdr);
4840 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841}
4842
4843static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4844{
Andy Adamson05d564f2008-12-23 16:06:15 -05004845 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004846 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004847 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848
Andy Adamson05d564f2008-12-23 16:06:15 -05004849 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004850 if (status != -EIO)
4851 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004852 if (!status)
4853 status = decode_stateid(xdr, &res->stateid);
4854 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004855 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856
Andy Adamson05d564f2008-12-23 16:06:15 -05004857 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858
Benny Halevyc0eae662009-08-14 17:20:14 +03004859 p = xdr_inline_decode(xdr, 8);
4860 if (unlikely(!p))
4861 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004862 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004863 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004864 if (bmlen > 10)
4865 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866
Benny Halevyc0eae662009-08-14 17:20:14 +03004867 p = xdr_inline_decode(xdr, bmlen << 2);
4868 if (unlikely(!p))
4869 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004870 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4871 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004872 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004873 for (; i < NFS4_BITMAP_SIZE; i++)
4874 res->attrset[i] = 0;
4875
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876 return decode_delegation(xdr, res);
4877xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004878 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004880out_overflow:
4881 print_overflow_msg(__func__, xdr);
4882 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883}
4884
4885static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4886{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 int status;
4888
Andy Adamson05d564f2008-12-23 16:06:15 -05004889 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004890 if (status != -EIO)
4891 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004892 if (!status)
4893 status = decode_stateid(xdr, &res->stateid);
4894 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895}
4896
4897static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4898{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899 int status;
4900
4901 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004902 if (status != -EIO)
4903 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004904 if (!status)
4905 status = decode_stateid(xdr, &res->stateid);
4906 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907}
4908
4909static int decode_putfh(struct xdr_stream *xdr)
4910{
4911 return decode_op_hdr(xdr, OP_PUTFH);
4912}
4913
4914static int decode_putrootfh(struct xdr_stream *xdr)
4915{
4916 return decode_op_hdr(xdr, OP_PUTROOTFH);
4917}
4918
4919static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4920{
Al Viro8687b632006-10-19 23:28:48 -07004921 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04004922 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923 int status;
4924
4925 status = decode_op_hdr(xdr, OP_READ);
4926 if (status)
4927 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004928 p = xdr_inline_decode(xdr, 8);
4929 if (unlikely(!p))
4930 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004931 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004932 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04004933 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004934 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004935 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936 "count %u > recvd %u\n", count, recvd);
4937 count = recvd;
4938 eof = 0;
4939 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004940 res->eof = eof;
4941 res->count = count;
4942 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004943out_overflow:
4944 print_overflow_msg(__func__, xdr);
4945 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946}
4947
4948static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4949{
Chuck Leverbcecff72007-10-26 13:32:03 -04004950 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004951 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952
4953 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004954 if (!status)
4955 status = decode_verifier(xdr, readdir->verifier.data);
4956 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004958 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004959 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004960 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04004961 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962}
4963
4964static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4965{
4966 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04004967 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004968 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969 int status;
4970
4971 status = decode_op_hdr(xdr, OP_READLINK);
4972 if (status)
4973 return status;
4974
4975 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004976 p = xdr_inline_decode(xdr, 4);
4977 if (unlikely(!p))
4978 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004979 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004981 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 return -ENAMETOOLONG;
4983 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04004984 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004986 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 "count %u > recvd %u\n", len, recvd);
4988 return -EIO;
4989 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990 /*
4991 * The XDR encode routine has set things up so that
4992 * the link text will be copied directly into the
4993 * buffer. We just have to do overflow-checking,
4994 * and and null-terminate the text (the VFS expects
4995 * null-termination).
4996 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004997 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004999out_overflow:
5000 print_overflow_msg(__func__, xdr);
5001 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005002}
5003
5004static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5005{
5006 int status;
5007
5008 status = decode_op_hdr(xdr, OP_REMOVE);
5009 if (status)
5010 goto out;
5011 status = decode_change_info(xdr, cinfo);
5012out:
5013 return status;
5014}
5015
5016static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5017 struct nfs4_change_info *new_cinfo)
5018{
5019 int status;
5020
5021 status = decode_op_hdr(xdr, OP_RENAME);
5022 if (status)
5023 goto out;
5024 if ((status = decode_change_info(xdr, old_cinfo)))
5025 goto out;
5026 status = decode_change_info(xdr, new_cinfo);
5027out:
5028 return status;
5029}
5030
5031static int decode_renew(struct xdr_stream *xdr)
5032{
5033 return decode_op_hdr(xdr, OP_RENEW);
5034}
5035
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005036static int
5037decode_restorefh(struct xdr_stream *xdr)
5038{
5039 return decode_op_hdr(xdr, OP_RESTOREFH);
5040}
5041
J. Bruce Fields029d1052005-06-22 17:16:22 +00005042static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005043 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005044{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005045 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005046 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005047 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005048 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005049 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005050
Andy Adamsonbf118a32011-12-07 11:55:27 -05005051 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005052 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5053 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005054
Trond Myklebust519d3952012-08-14 17:30:10 -04005055 xdr_enter_page(xdr, xdr->buf->page_len);
5056
Trond Myklebustcff298c2012-08-14 17:14:17 -04005057 /* Calculate the offset of the page data */
5058 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005059
J. Bruce Fields029d1052005-06-22 17:16:22 +00005060 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5061 goto out;
5062 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5063 goto out;
5064
5065 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5066 return -EIO;
5067 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005068
Andy Adamsonbf118a32011-12-07 11:55:27 -05005069 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5070 * are stored with the acl data to handle the problem of
5071 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005072 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005073 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005074
5075 /* Check for receive buffer overflow */
5076 if (res->acl_len > (xdr->nwords << 2) ||
5077 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5078 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005079 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005080 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005081 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005082 } else
5083 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005084
5085out:
5086 return status;
5087}
5088
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089static int
5090decode_savefh(struct xdr_stream *xdr)
5091{
5092 return decode_op_hdr(xdr, OP_SAVEFH);
5093}
5094
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005095static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005096{
Al Viro8687b632006-10-19 23:28:48 -07005097 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098 uint32_t bmlen;
5099 int status;
5100
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101 status = decode_op_hdr(xdr, OP_SETATTR);
5102 if (status)
5103 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005104 p = xdr_inline_decode(xdr, 4);
5105 if (unlikely(!p))
5106 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005107 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005108 p = xdr_inline_decode(xdr, bmlen << 2);
5109 if (likely(p))
5110 return 0;
5111out_overflow:
5112 print_overflow_msg(__func__, xdr);
5113 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114}
5115
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005116static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005117{
Al Viro8687b632006-10-19 23:28:48 -07005118 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119 uint32_t opnum;
5120 int32_t nfserr;
5121
Benny Halevyc0eae662009-08-14 17:20:14 +03005122 p = xdr_inline_decode(xdr, 8);
5123 if (unlikely(!p))
5124 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005125 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005126 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005127 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005128 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129 return -EIO;
5130 }
Benny Halevycccddf42009-08-14 17:20:19 +03005131 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005133 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5134 if (unlikely(!p))
5135 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005136 p = xdr_decode_hyper(p, &res->clientid);
5137 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005138 } else if (nfserr == NFSERR_CLID_INUSE) {
5139 uint32_t len;
5140
5141 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005142 p = xdr_inline_decode(xdr, 4);
5143 if (unlikely(!p))
5144 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005145 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005146 p = xdr_inline_decode(xdr, len);
5147 if (unlikely(!p))
5148 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149
5150 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005151 p = xdr_inline_decode(xdr, 4);
5152 if (unlikely(!p))
5153 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005154 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005155 p = xdr_inline_decode(xdr, len);
5156 if (unlikely(!p))
5157 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158 return -NFSERR_CLID_INUSE;
5159 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005160 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161
5162 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005163out_overflow:
5164 print_overflow_msg(__func__, xdr);
5165 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166}
5167
5168static int decode_setclientid_confirm(struct xdr_stream *xdr)
5169{
5170 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5171}
5172
5173static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5174{
Al Viro8687b632006-10-19 23:28:48 -07005175 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005176 int status;
5177
5178 status = decode_op_hdr(xdr, OP_WRITE);
5179 if (status)
5180 return status;
5181
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005182 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005183 if (unlikely(!p))
5184 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005185 res->count = be32_to_cpup(p++);
5186 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005187 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005188out_overflow:
5189 print_overflow_msg(__func__, xdr);
5190 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191}
5192
5193static int decode_delegreturn(struct xdr_stream *xdr)
5194{
5195 return decode_op_hdr(xdr, OP_DELEGRETURN);
5196}
5197
Chuck Leverfb15b262013-03-16 15:54:34 -04005198static int decode_secinfo_gss(struct xdr_stream *xdr,
5199 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005200{
Chuck Leverfb15b262013-03-16 15:54:34 -04005201 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005202 __be32 *p;
5203
5204 p = xdr_inline_decode(xdr, 4);
5205 if (unlikely(!p))
5206 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005207 oid_len = be32_to_cpup(p);
5208 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005209 goto out_err;
5210
Chuck Leverfb15b262013-03-16 15:54:34 -04005211 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005212 if (unlikely(!p))
5213 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005214 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5215 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005216
5217 p = xdr_inline_decode(xdr, 8);
5218 if (unlikely(!p))
5219 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005220 flavor->flavor_info.qop = be32_to_cpup(p++);
5221 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005222
5223 return 0;
5224
5225out_overflow:
5226 print_overflow_msg(__func__, xdr);
5227 return -EIO;
5228out_err:
5229 return -EINVAL;
5230}
5231
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005232static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005233{
Chuck Leverfb15b262013-03-16 15:54:34 -04005234 struct nfs4_secinfo4 *sec_flavor;
5235 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005236 int status;
5237 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005238
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005239 p = xdr_inline_decode(xdr, 4);
5240 if (unlikely(!p))
5241 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005242
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005243 res->flavors->num_flavors = 0;
5244 num_flavors = be32_to_cpup(p);
5245
5246 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005247 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005248 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005249 break;
5250
5251 p = xdr_inline_decode(xdr, 4);
5252 if (unlikely(!p))
5253 goto out_overflow;
5254 sec_flavor->flavor = be32_to_cpup(p);
5255
5256 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005257 status = decode_secinfo_gss(xdr, sec_flavor);
5258 if (status)
5259 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005260 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005261 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005262 }
5263
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005264 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005265out:
5266 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005267out_overflow:
5268 print_overflow_msg(__func__, xdr);
5269 return -EIO;
5270}
5271
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005272static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5273{
5274 int status = decode_op_hdr(xdr, OP_SECINFO);
5275 if (status)
5276 return status;
5277 return decode_secinfo_common(xdr, res);
5278}
5279
Benny Halevy99fe60d2009-04-01 09:22:29 -04005280#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005281static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5282{
5283 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5284 if (status)
5285 return status;
5286 return decode_secinfo_common(xdr, res);
5287}
5288
Benny Halevy99fe60d2009-04-01 09:22:29 -04005289static int decode_exchange_id(struct xdr_stream *xdr,
5290 struct nfs41_exchange_id_res *res)
5291{
5292 __be32 *p;
5293 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005294 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005295 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005296 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005297
5298 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5299 if (status)
5300 return status;
5301
Benny Halevyc0eae662009-08-14 17:20:14 +03005302 p = xdr_inline_decode(xdr, 8);
5303 if (unlikely(!p))
5304 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005305 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005306 p = xdr_inline_decode(xdr, 12);
5307 if (unlikely(!p))
5308 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005309 res->seqid = be32_to_cpup(p++);
5310 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005311
5312 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005313 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005314 if (dummy != SP4_NONE)
5315 return -EIO;
5316
Chuck Leveracdeb692012-05-21 22:46:16 -04005317 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005318 p = xdr_inline_decode(xdr, 8);
5319 if (unlikely(!p))
5320 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005321 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005322
Chuck Leveracdeb692012-05-21 22:46:16 -04005323 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005324 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5325 if (unlikely(status))
5326 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005327 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5328 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005329 memcpy(res->server_owner->major_id, dummy_str, dummy);
5330 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005331
Chuck Leveracdeb692012-05-21 22:46:16 -04005332 /* server_scope4 */
5333 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5334 if (unlikely(status))
5335 return status;
5336 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5337 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005338 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5339 res->server_scope->server_scope_sz = dummy;
5340
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005341 /* Implementation Id */
5342 p = xdr_inline_decode(xdr, 4);
5343 if (unlikely(!p))
5344 goto out_overflow;
5345 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005346
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005347 if (impl_id_count) {
5348 /* nii_domain */
5349 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5350 if (unlikely(status))
5351 return status;
5352 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5353 return -EIO;
5354 memcpy(res->impl_id->domain, dummy_str, dummy);
5355
5356 /* nii_name */
5357 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5358 if (unlikely(status))
5359 return status;
5360 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5361 return -EIO;
5362 memcpy(res->impl_id->name, dummy_str, dummy);
5363
5364 /* nii_date */
5365 p = xdr_inline_decode(xdr, 12);
5366 if (unlikely(!p))
5367 goto out_overflow;
5368 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5369 res->impl_id->date.nseconds = be32_to_cpup(p);
5370
5371 /* if there's more than one entry, ignore the rest */
5372 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005373 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005374out_overflow:
5375 print_overflow_msg(__func__, xdr);
5376 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005377}
Andy Adamsonfc931582009-04-01 09:22:31 -04005378
5379static int decode_chan_attrs(struct xdr_stream *xdr,
5380 struct nfs4_channel_attrs *attrs)
5381{
5382 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005383 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005384
Benny Halevyc0eae662009-08-14 17:20:14 +03005385 p = xdr_inline_decode(xdr, 28);
5386 if (unlikely(!p))
5387 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005388 val = be32_to_cpup(p++); /* headerpadsz */
5389 if (val)
5390 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005391 attrs->max_rqst_sz = be32_to_cpup(p++);
5392 attrs->max_resp_sz = be32_to_cpup(p++);
5393 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5394 attrs->max_ops = be32_to_cpup(p++);
5395 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005396 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005397 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005398 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5399 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005400 return -EINVAL;
5401 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005402 if (nr_attrs == 1) {
5403 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5404 if (unlikely(!p))
5405 goto out_overflow;
5406 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005407 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005408out_overflow:
5409 print_overflow_msg(__func__, xdr);
5410 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005411}
5412
Benny Halevye78291e2009-08-14 17:20:00 +03005413static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5414{
5415 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005416}
5417
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005418static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5419 struct nfs41_bind_conn_to_session_res *res)
5420{
5421 __be32 *p;
5422 int status;
5423
5424 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5425 if (!status)
5426 status = decode_sessionid(xdr, &res->session->sess_id);
5427 if (unlikely(status))
5428 return status;
5429
5430 /* dir flags, rdma mode bool */
5431 p = xdr_inline_decode(xdr, 8);
5432 if (unlikely(!p))
5433 goto out_overflow;
5434
5435 res->dir = be32_to_cpup(p++);
5436 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5437 return -EIO;
5438 if (be32_to_cpup(p) == 0)
5439 res->use_conn_in_rdma_mode = false;
5440 else
5441 res->use_conn_in_rdma_mode = true;
5442
5443 return 0;
5444out_overflow:
5445 print_overflow_msg(__func__, xdr);
5446 return -EIO;
5447}
5448
Andy Adamsonfc931582009-04-01 09:22:31 -04005449static int decode_create_session(struct xdr_stream *xdr,
5450 struct nfs41_create_session_res *res)
5451{
5452 __be32 *p;
5453 int status;
5454 struct nfs_client *clp = res->client;
5455 struct nfs4_session *session = clp->cl_session;
5456
5457 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005458 if (!status)
5459 status = decode_sessionid(xdr, &session->sess_id);
5460 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005461 return status;
5462
Andy Adamsonfc931582009-04-01 09:22:31 -04005463 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005464 p = xdr_inline_decode(xdr, 8);
5465 if (unlikely(!p))
5466 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005467 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005468 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005469
5470 /* Channel attributes */
5471 status = decode_chan_attrs(xdr, &session->fc_attrs);
5472 if (!status)
5473 status = decode_chan_attrs(xdr, &session->bc_attrs);
5474 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005475out_overflow:
5476 print_overflow_msg(__func__, xdr);
5477 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005478}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005479
5480static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5481{
5482 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5483}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005484
Trond Myklebust66245532012-05-25 17:18:09 -04005485static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5486{
5487 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5488}
5489
Ricardo Labiaga180197532009-12-05 16:08:40 -05005490static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5491{
5492 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5493}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005494#endif /* CONFIG_NFS_V4_1 */
5495
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005496static int decode_sequence(struct xdr_stream *xdr,
5497 struct nfs4_sequence_res *res,
5498 struct rpc_rqst *rqstp)
5499{
5500#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005501 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005502 struct nfs4_sessionid id;
5503 u32 dummy;
5504 int status;
5505 __be32 *p;
5506
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005507 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005508 return 0;
5509
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005510 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005511 if (!status)
5512 status = decode_sessionid(xdr, &id);
5513 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005514 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005515
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005516 /*
5517 * If the server returns different values for sessionID, slotID or
5518 * sequence number, the server is looney tunes.
5519 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005520 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005521 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005522
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005523 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005524 NFS4_MAX_SESSIONID_LEN)) {
5525 dprintk("%s Invalid session id\n", __func__);
5526 goto out_err;
5527 }
Benny Halevye78291e2009-08-14 17:20:00 +03005528
Benny Halevyc0eae662009-08-14 17:20:14 +03005529 p = xdr_inline_decode(xdr, 20);
5530 if (unlikely(!p))
5531 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005532
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005533 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005534 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005535 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005536 dprintk("%s Invalid sequence number\n", __func__);
5537 goto out_err;
5538 }
5539 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005540 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005541 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005542 dprintk("%s Invalid slot id\n", __func__);
5543 goto out_err;
5544 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005545 /* highest slot id */
5546 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005547 /* target highest slot id */
5548 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005549 /* result flags */
5550 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005551 status = 0;
5552out_err:
5553 res->sr_status = status;
5554 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005555out_overflow:
5556 print_overflow_msg(__func__, xdr);
5557 status = -EIO;
5558 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005559#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005560 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005561#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005562}
5563
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005564#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005565/*
5566 * TODO: Need to handle case when EOF != true;
5567 */
5568static int decode_getdevicelist(struct xdr_stream *xdr,
5569 struct pnfs_devicelist *res)
5570{
5571 __be32 *p;
5572 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005573 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005574
5575 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5576 if (status)
5577 return status;
5578
5579 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5580 if (unlikely(!p))
5581 goto out_overflow;
5582
5583 /* TODO: Skip cookie for now */
5584 p += 2;
5585
5586 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005587 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005588
5589 res->num_devs = be32_to_cpup(p);
5590
5591 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5592
5593 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005594 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005595 __func__, res->num_devs);
5596 return -EIO;
5597 }
5598
5599 p = xdr_inline_decode(xdr,
5600 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5601 if (unlikely(!p))
5602 goto out_overflow;
5603 for (i = 0; i < res->num_devs; i++)
5604 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5605 NFS4_DEVICEID4_SIZE);
5606 res->eof = be32_to_cpup(p);
5607 return 0;
5608out_overflow:
5609 print_overflow_msg(__func__, xdr);
5610 return -EIO;
5611}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005612
5613static int decode_getdeviceinfo(struct xdr_stream *xdr,
5614 struct pnfs_device *pdev)
5615{
5616 __be32 *p;
5617 uint32_t len, type;
5618 int status;
5619
5620 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5621 if (status) {
5622 if (status == -ETOOSMALL) {
5623 p = xdr_inline_decode(xdr, 4);
5624 if (unlikely(!p))
5625 goto out_overflow;
5626 pdev->mincount = be32_to_cpup(p);
5627 dprintk("%s: Min count too small. mincnt = %u\n",
5628 __func__, pdev->mincount);
5629 }
5630 return status;
5631 }
5632
5633 p = xdr_inline_decode(xdr, 8);
5634 if (unlikely(!p))
5635 goto out_overflow;
5636 type = be32_to_cpup(p++);
5637 if (type != pdev->layout_type) {
5638 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5639 __func__, pdev->layout_type, type);
5640 return -EINVAL;
5641 }
5642 /*
5643 * Get the length of the opaque device_addr4. xdr_read_pages places
5644 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5645 * and places the remaining xdr data in xdr_buf->tail
5646 */
5647 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005648 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5649 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005650
5651 /* Parse notification bitmap, verifying that it is zero. */
5652 p = xdr_inline_decode(xdr, 4);
5653 if (unlikely(!p))
5654 goto out_overflow;
5655 len = be32_to_cpup(p);
5656 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005657 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005658
5659 p = xdr_inline_decode(xdr, 4 * len);
5660 if (unlikely(!p))
5661 goto out_overflow;
5662 for (i = 0; i < len; i++, p++) {
5663 if (be32_to_cpup(p)) {
5664 dprintk("%s: notifications not supported\n",
5665 __func__);
5666 return -EIO;
5667 }
5668 }
5669 }
5670 return 0;
5671out_overflow:
5672 print_overflow_msg(__func__, xdr);
5673 return -EIO;
5674}
5675
5676static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5677 struct nfs4_layoutget_res *res)
5678{
5679 __be32 *p;
5680 int status;
5681 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005682 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005683
5684 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5685 if (status)
5686 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005687 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005688 if (unlikely(!p))
5689 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005690 res->return_on_close = be32_to_cpup(p);
5691 decode_stateid(xdr, &res->stateid);
5692 p = xdr_inline_decode(xdr, 4);
5693 if (unlikely(!p))
5694 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005695 layout_count = be32_to_cpup(p);
5696 if (!layout_count) {
5697 dprintk("%s: server responded with empty layout array\n",
5698 __func__);
5699 return -EINVAL;
5700 }
5701
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005702 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005703 if (unlikely(!p))
5704 goto out_overflow;
5705 p = xdr_decode_hyper(p, &res->range.offset);
5706 p = xdr_decode_hyper(p, &res->range.length);
5707 res->range.iomode = be32_to_cpup(p++);
5708 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005709 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005710
5711 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5712 __func__,
5713 (unsigned long)res->range.offset,
5714 (unsigned long)res->range.length,
5715 res->range.iomode,
5716 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005717 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005718
Trond Myklebust64bd5772012-06-20 22:35:05 -04005719 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005720 if (res->layoutp->len > recvd) {
5721 dprintk("NFS: server cheating in layoutget reply: "
5722 "layout len %u > recvd %u\n",
5723 res->layoutp->len, recvd);
5724 return -EINVAL;
5725 }
5726
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005727 if (layout_count > 1) {
5728 /* We only handle a length one array at the moment. Any
5729 * further entries are just ignored. Note that this means
5730 * the client may see a response that is less than the
5731 * minimum it requested.
5732 */
5733 dprintk("%s: server responded with %d layouts, dropping tail\n",
5734 __func__, layout_count);
5735 }
5736
5737 return 0;
5738out_overflow:
5739 print_overflow_msg(__func__, xdr);
5740 return -EIO;
5741}
Andy Adamson863a3c62011-03-23 13:27:54 +00005742
Benny Halevycbe82602011-05-22 19:52:37 +03005743static int decode_layoutreturn(struct xdr_stream *xdr,
5744 struct nfs4_layoutreturn_res *res)
5745{
5746 __be32 *p;
5747 int status;
5748
5749 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5750 if (status)
5751 return status;
5752 p = xdr_inline_decode(xdr, 4);
5753 if (unlikely(!p))
5754 goto out_overflow;
5755 res->lrs_present = be32_to_cpup(p);
5756 if (res->lrs_present)
5757 status = decode_stateid(xdr, &res->stateid);
5758 return status;
5759out_overflow:
5760 print_overflow_msg(__func__, xdr);
5761 return -EIO;
5762}
5763
Andy Adamson863a3c62011-03-23 13:27:54 +00005764static int decode_layoutcommit(struct xdr_stream *xdr,
5765 struct rpc_rqst *req,
5766 struct nfs4_layoutcommit_res *res)
5767{
5768 __be32 *p;
5769 __u32 sizechanged;
5770 int status;
5771
5772 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005773 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005774 if (status)
5775 return status;
5776
5777 p = xdr_inline_decode(xdr, 4);
5778 if (unlikely(!p))
5779 goto out_overflow;
5780 sizechanged = be32_to_cpup(p);
5781
5782 if (sizechanged) {
5783 /* throw away new size */
5784 p = xdr_inline_decode(xdr, 8);
5785 if (unlikely(!p))
5786 goto out_overflow;
5787 }
5788 return 0;
5789out_overflow:
5790 print_overflow_msg(__func__, xdr);
5791 return -EIO;
5792}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005793
5794static int decode_test_stateid(struct xdr_stream *xdr,
5795 struct nfs41_test_stateid_res *res)
5796{
5797 __be32 *p;
5798 int status;
5799 int num_res;
5800
5801 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5802 if (status)
5803 return status;
5804
5805 p = xdr_inline_decode(xdr, 4);
5806 if (unlikely(!p))
5807 goto out_overflow;
5808 num_res = be32_to_cpup(p++);
5809 if (num_res != 1)
5810 goto out;
5811
5812 p = xdr_inline_decode(xdr, 4);
5813 if (unlikely(!p))
5814 goto out_overflow;
5815 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005816
5817 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005818out_overflow:
5819 print_overflow_msg(__func__, xdr);
5820out:
5821 return -EIO;
5822}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005823
5824static int decode_free_stateid(struct xdr_stream *xdr,
5825 struct nfs41_free_stateid_res *res)
5826{
5827 __be32 *p;
5828 int status;
5829
5830 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5831 if (status)
5832 return status;
5833
5834 p = xdr_inline_decode(xdr, 4);
5835 if (unlikely(!p))
5836 goto out_overflow;
5837 res->status = be32_to_cpup(p++);
5838 return res->status;
5839out_overflow:
5840 print_overflow_msg(__func__, xdr);
5841 return -EIO;
5842}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005843#endif /* CONFIG_NFS_V4_1 */
5844
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845/*
Benny Halevy49c25592008-12-23 16:06:16 -05005846 * END OF "GENERIC" DECODE ROUTINES.
5847 */
5848
5849/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 * Decode OPEN_DOWNGRADE response
5851 */
Chuck Leverbf269552010-12-14 14:59:29 +00005852static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5853 struct xdr_stream *xdr,
5854 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855{
Andy Adamson05d564f2008-12-23 16:06:15 -05005856 struct compound_hdr hdr;
5857 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005858
Chuck Leverbf269552010-12-14 14:59:29 +00005859 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005860 if (status)
5861 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005862 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005863 if (status)
5864 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005865 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005866 if (status)
5867 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005868 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005869 if (status != 0)
5870 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005871 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005872out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005873 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005874}
5875
5876/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 * Decode ACCESS response
5878 */
Chuck Leverbf269552010-12-14 14:59:29 +00005879static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5880 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005881{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005882 struct compound_hdr hdr;
5883 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005884
Chuck Leverbf269552010-12-14 14:59:29 +00005885 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005886 if (status)
5887 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005888 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005889 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005890 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005891 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005892 if (status != 0)
5893 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04005894 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04005895 if (status != 0)
5896 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005897 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005898out:
5899 return status;
5900}
5901
5902/*
5903 * Decode LOOKUP response
5904 */
Chuck Leverbf269552010-12-14 14:59:29 +00005905static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5906 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005907{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005908 struct compound_hdr hdr;
5909 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005910
Chuck Leverbf269552010-12-14 14:59:29 +00005911 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005912 if (status)
5913 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005914 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005915 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005916 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005917 status = decode_putfh(xdr);
5918 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005919 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005920 status = decode_lookup(xdr);
5921 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005922 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005923 status = decode_getfh(xdr, res->fh);
5924 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005925 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005926 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927out:
5928 return status;
5929}
5930
5931/*
5932 * Decode LOOKUP_ROOT response
5933 */
Chuck Leverbf269552010-12-14 14:59:29 +00005934static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5935 struct xdr_stream *xdr,
5936 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005938 struct compound_hdr hdr;
5939 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005940
Chuck Leverbf269552010-12-14 14:59:29 +00005941 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005942 if (status)
5943 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005944 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005945 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005946 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005947 status = decode_putrootfh(xdr);
5948 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005950 status = decode_getfh(xdr, res->fh);
5951 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005952 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005953out:
5954 return status;
5955}
5956
5957/*
5958 * Decode REMOVE response
5959 */
Chuck Leverbf269552010-12-14 14:59:29 +00005960static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5961 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963 struct compound_hdr hdr;
5964 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005965
Chuck Leverbf269552010-12-14 14:59:29 +00005966 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005967 if (status)
5968 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005970 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005971 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005972 status = decode_putfh(xdr);
5973 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005974 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005975 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976out:
5977 return status;
5978}
5979
5980/*
5981 * Decode RENAME response
5982 */
Chuck Leverbf269552010-12-14 14:59:29 +00005983static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5984 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005986 struct compound_hdr hdr;
5987 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005988
Chuck Leverbf269552010-12-14 14:59:29 +00005989 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005990 if (status)
5991 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005992 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005993 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005994 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005995 status = decode_putfh(xdr);
5996 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005998 status = decode_savefh(xdr);
5999 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006000 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006001 status = decode_putfh(xdr);
6002 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006004 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006005out:
6006 return status;
6007}
6008
6009/*
6010 * Decode LINK response
6011 */
Chuck Leverbf269552010-12-14 14:59:29 +00006012static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6013 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015 struct compound_hdr hdr;
6016 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006017
Chuck Leverbf269552010-12-14 14:59:29 +00006018 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006019 if (status)
6020 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006021 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006022 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006023 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006024 status = decode_putfh(xdr);
6025 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006026 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006027 status = decode_savefh(xdr);
6028 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006029 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006030 status = decode_putfh(xdr);
6031 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006032 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006033 status = decode_link(xdr, &res->cinfo);
6034 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006035 goto out;
6036 /*
6037 * Note order: OP_LINK leaves the directory as the current
6038 * filehandle.
6039 */
Chuck Leverbf269552010-12-14 14:59:29 +00006040 status = decode_restorefh(xdr);
6041 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006042 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006043 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044out:
6045 return status;
6046}
6047
6048/*
6049 * Decode CREATE response
6050 */
Chuck Leverbf269552010-12-14 14:59:29 +00006051static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6052 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054 struct compound_hdr hdr;
6055 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006056
Chuck Leverbf269552010-12-14 14:59:29 +00006057 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006058 if (status)
6059 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006060 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006061 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006063 status = decode_putfh(xdr);
6064 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006066 status = decode_create(xdr, &res->dir_cinfo);
6067 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006068 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006069 status = decode_getfh(xdr, res->fh);
6070 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071 goto out;
Trond Myklebust7c317fc2012-04-27 13:48:18 -04006072 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073out:
6074 return status;
6075}
6076
6077/*
6078 * Decode SYMLINK response
6079 */
Chuck Leverbf269552010-12-14 14:59:29 +00006080static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6081 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006082{
Chuck Leverbf269552010-12-14 14:59:29 +00006083 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006084}
6085
6086/*
6087 * Decode GETATTR response
6088 */
Chuck Leverbf269552010-12-14 14:59:29 +00006089static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6090 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006091{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092 struct compound_hdr hdr;
6093 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006094
Chuck Leverbf269552010-12-14 14:59:29 +00006095 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096 if (status)
6097 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006098 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006099 if (status)
6100 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006101 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102 if (status)
6103 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006104 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006105out:
6106 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107}
6108
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006109/*
6110 * Encode an SETACL request
6111 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006112static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6113 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006114{
Andy Adamson05d564f2008-12-23 16:06:15 -05006115 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006116 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006117 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006118
Chuck Lever9f06c712010-12-14 14:59:18 +00006119 encode_compound_hdr(xdr, req, &hdr);
6120 encode_sequence(xdr, &args->seq_args, &hdr);
6121 encode_putfh(xdr, args->fh, &hdr);
6122 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006123 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006124}
Andy Adamson05d564f2008-12-23 16:06:15 -05006125
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006126/*
6127 * Decode SETACL response
6128 */
6129static int
Chuck Leverbf269552010-12-14 14:59:29 +00006130nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006131 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006132{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006133 struct compound_hdr hdr;
6134 int status;
6135
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006137 if (status)
6138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006139 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006140 if (status)
6141 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006143 if (status)
6144 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006145 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006146out:
6147 return status;
6148}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006149
6150/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006151 * Decode GETACL response
6152 */
6153static int
Chuck Leverbf269552010-12-14 14:59:29 +00006154nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006155 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006156{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006157 struct compound_hdr hdr;
6158 int status;
6159
Trond Myklebust331818f2012-02-03 18:30:53 -05006160 if (res->acl_scratch != NULL) {
6161 void *p = page_address(res->acl_scratch);
6162 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6163 }
Chuck Leverbf269552010-12-14 14:59:29 +00006164 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006165 if (status)
6166 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006167 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006168 if (status)
6169 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006170 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006171 if (status)
6172 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006173 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006174
6175out:
6176 return status;
6177}
6178
6179/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180 * Decode CLOSE response
6181 */
Chuck Leverbf269552010-12-14 14:59:29 +00006182static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6183 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184{
Andy Adamson05d564f2008-12-23 16:06:15 -05006185 struct compound_hdr hdr;
6186 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187
Chuck Leverbf269552010-12-14 14:59:29 +00006188 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006189 if (status)
6190 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006191 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006192 if (status)
6193 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006194 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006195 if (status)
6196 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006197 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006198 if (status != 0)
6199 goto out;
6200 /*
6201 * Note: Server may do delete on close for this file
6202 * in which case the getattr call will fail with
6203 * an ESTALE error. Shouldn't be a problem,
6204 * though, since fattr->valid will remain unset.
6205 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006206 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006208 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209}
6210
6211/*
6212 * Decode OPEN response
6213 */
Chuck Leverbf269552010-12-14 14:59:29 +00006214static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6215 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216{
Andy Adamson05d564f2008-12-23 16:06:15 -05006217 struct compound_hdr hdr;
6218 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219
Chuck Leverbf269552010-12-14 14:59:29 +00006220 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006221 if (status)
6222 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006223 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006224 if (status)
6225 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006226 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006227 if (status)
6228 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006229 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006230 if (status)
6231 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006232 status = decode_getfh(xdr, &res->fh);
6233 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006234 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006235 if (res->access_request)
6236 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust90ff0c52012-04-27 13:48:18 -04006237 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006239 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240}
6241
6242/*
6243 * Decode OPEN_CONFIRM response
6244 */
Chuck Leverbf269552010-12-14 14:59:29 +00006245static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6246 struct xdr_stream *xdr,
6247 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248{
Andy Adamson05d564f2008-12-23 16:06:15 -05006249 struct compound_hdr hdr;
6250 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251
Chuck Leverbf269552010-12-14 14:59:29 +00006252 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006253 if (status)
6254 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006256 if (status)
6257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006259out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006260 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261}
6262
6263/*
6264 * Decode OPEN response
6265 */
Chuck Leverbf269552010-12-14 14:59:29 +00006266static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6267 struct xdr_stream *xdr,
6268 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269{
Andy Adamson05d564f2008-12-23 16:06:15 -05006270 struct compound_hdr hdr;
6271 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272
Chuck Leverbf269552010-12-14 14:59:29 +00006273 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006274 if (status)
6275 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006277 if (status)
6278 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006279 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006280 if (status)
6281 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006282 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006283 if (status)
6284 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006285 if (res->access_request)
6286 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006287 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006288out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006289 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290}
6291
6292/*
6293 * Decode SETATTR response
6294 */
Chuck Leverbf269552010-12-14 14:59:29 +00006295static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6296 struct xdr_stream *xdr,
6297 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298{
Andy Adamson05d564f2008-12-23 16:06:15 -05006299 struct compound_hdr hdr;
6300 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006301
Chuck Leverbf269552010-12-14 14:59:29 +00006302 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006303 if (status)
6304 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006305 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006306 if (status)
6307 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006308 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006309 if (status)
6310 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006311 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006312 if (status)
6313 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006314 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006315out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006316 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317}
6318
6319/*
6320 * Decode LOCK response
6321 */
Chuck Leverbf269552010-12-14 14:59:29 +00006322static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6323 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325 struct compound_hdr hdr;
6326 int status;
6327
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329 if (status)
6330 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006332 if (status)
6333 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006334 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335 if (status)
6336 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006337 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006338out:
6339 return status;
6340}
6341
6342/*
6343 * Decode LOCKT response
6344 */
Chuck Leverbf269552010-12-14 14:59:29 +00006345static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6346 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006347{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348 struct compound_hdr hdr;
6349 int status;
6350
Chuck Leverbf269552010-12-14 14:59:29 +00006351 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352 if (status)
6353 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006354 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006355 if (status)
6356 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006357 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 if (status)
6359 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006360 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361out:
6362 return status;
6363}
6364
6365/*
6366 * Decode LOCKU response
6367 */
Chuck Leverbf269552010-12-14 14:59:29 +00006368static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6369 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006370{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371 struct compound_hdr hdr;
6372 int status;
6373
Chuck Leverbf269552010-12-14 14:59:29 +00006374 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375 if (status)
6376 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006377 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006378 if (status)
6379 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006380 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 if (status)
6382 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006383 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006384out:
6385 return status;
6386}
6387
Chuck Leverbf269552010-12-14 14:59:29 +00006388static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6389 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006390{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006391 struct compound_hdr hdr;
6392 int status;
6393
Chuck Leverbf269552010-12-14 14:59:29 +00006394 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006395 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006396 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006397 return status;
6398}
6399
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400/*
6401 * Decode READLINK response
6402 */
Chuck Leverbf269552010-12-14 14:59:29 +00006403static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6404 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006405 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407 struct compound_hdr hdr;
6408 int status;
6409
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411 if (status)
6412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006414 if (status)
6415 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006417 if (status)
6418 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420out:
6421 return status;
6422}
6423
6424/*
6425 * Decode READDIR response
6426 */
Chuck Leverbf269552010-12-14 14:59:29 +00006427static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6428 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430 struct compound_hdr hdr;
6431 int status;
6432
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006434 if (status)
6435 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006436 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006437 if (status)
6438 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006439 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440 if (status)
6441 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006442 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443out:
6444 return status;
6445}
6446
6447/*
6448 * Decode Read response
6449 */
Chuck Leverbf269552010-12-14 14:59:29 +00006450static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6451 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006452{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453 struct compound_hdr hdr;
6454 int status;
6455
Chuck Leverbf269552010-12-14 14:59:29 +00006456 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457 if (status)
6458 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006459 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006460 if (status)
6461 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006462 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463 if (status)
6464 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006465 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466 if (!status)
6467 status = res->count;
6468out:
6469 return status;
6470}
6471
6472/*
6473 * Decode WRITE response
6474 */
Chuck Leverbf269552010-12-14 14:59:29 +00006475static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6476 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006478 struct compound_hdr hdr;
6479 int status;
6480
Chuck Leverbf269552010-12-14 14:59:29 +00006481 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482 if (status)
6483 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006484 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006485 if (status)
6486 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006487 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006488 if (status)
6489 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006490 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006491 if (status)
6492 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006493 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006494 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495 if (!status)
6496 status = res->count;
6497out:
6498 return status;
6499}
6500
6501/*
6502 * Decode COMMIT response
6503 */
Chuck Leverbf269552010-12-14 14:59:29 +00006504static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006505 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507 struct compound_hdr hdr;
6508 int status;
6509
Chuck Leverbf269552010-12-14 14:59:29 +00006510 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006511 if (status)
6512 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006513 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006514 if (status)
6515 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006516 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006517 if (status)
6518 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006519 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520out:
6521 return status;
6522}
6523
6524/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006525 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526 */
Chuck Leverbf269552010-12-14 14:59:29 +00006527static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006528 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006530 struct compound_hdr hdr;
6531 int status;
6532
Chuck Leverbf269552010-12-14 14:59:29 +00006533 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006534 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006536 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006537 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006538 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006539 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006540 return status;
6541}
6542
6543/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006544 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545 */
Chuck Leverbf269552010-12-14 14:59:29 +00006546static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006547 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006549 struct compound_hdr hdr;
6550 int status;
6551
Chuck Leverbf269552010-12-14 14:59:29 +00006552 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006553 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006554 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006555 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006556 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006557 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 return status;
6560}
6561
6562/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006563 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006564 */
Chuck Leverbf269552010-12-14 14:59:29 +00006565static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006566 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568 struct compound_hdr hdr;
6569 int status;
6570
Chuck Leverbf269552010-12-14 14:59:29 +00006571 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006573 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006574 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006575 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006576 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006577 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578 return status;
6579}
6580
6581/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006582 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583 */
Chuck Leverbf269552010-12-14 14:59:29 +00006584static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6585 struct xdr_stream *xdr,
6586 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006587{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006588 struct compound_hdr hdr;
6589 int status;
6590
Chuck Leverbf269552010-12-14 14:59:29 +00006591 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006592 if (status)
6593 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006594 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006595 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006596 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006597 status = decode_putfh(xdr);
6598 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006599 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006600 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006601out:
6602 return status;
6603}
6604
6605/*
6606 * Decode RENEW response
6607 */
Chuck Leverbf269552010-12-14 14:59:29 +00006608static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6609 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006610{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611 struct compound_hdr hdr;
6612 int status;
6613
Chuck Leverbf269552010-12-14 14:59:29 +00006614 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006616 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617 return status;
6618}
6619
6620/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006621 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622 */
Chuck Leverbf269552010-12-14 14:59:29 +00006623static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6624 struct xdr_stream *xdr,
6625 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006626{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006627 struct compound_hdr hdr;
6628 int status;
6629
Chuck Leverbf269552010-12-14 14:59:29 +00006630 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006632 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633 return status;
6634}
6635
6636/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006637 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638 */
Chuck Leverbf269552010-12-14 14:59:29 +00006639static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006640 struct xdr_stream *xdr)
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)
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006648 return status;
6649}
6650
6651/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006652 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006653 */
Chuck Leverbf269552010-12-14 14:59:29 +00006654static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6655 struct xdr_stream *xdr,
6656 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006657{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006658 struct compound_hdr hdr;
6659 int status;
6660
Chuck Leverbf269552010-12-14 14:59:29 +00006661 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006662 if (status)
6663 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006664 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006665 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006666 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006668 if (status != 0)
6669 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006670 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006671 if (status != 0)
6672 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006673 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006674out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675 return status;
6676}
6677
Trond Myklebust683b57b2006-06-09 09:34:22 -04006678/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006679 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006680 */
Chuck Leverbf269552010-12-14 14:59:29 +00006681static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6682 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006683 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006684{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006685 struct compound_hdr hdr;
6686 int status;
6687
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006689 if (status)
6690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006691 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006692 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006693 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006694 status = decode_putfh(xdr);
6695 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006696 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006697 status = decode_lookup(xdr);
6698 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006699 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006700 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006701 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6702 NULL, res->fs_locations,
6703 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006704out:
6705 return status;
6706}
6707
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006708/*
6709 * Decode SECINFO response
6710 */
6711static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6712 struct xdr_stream *xdr,
6713 struct nfs4_secinfo_res *res)
6714{
6715 struct compound_hdr hdr;
6716 int status;
6717
6718 status = decode_compound_hdr(xdr, &hdr);
6719 if (status)
6720 goto out;
6721 status = decode_sequence(xdr, &res->seq_res, rqstp);
6722 if (status)
6723 goto out;
6724 status = decode_putfh(xdr);
6725 if (status)
6726 goto out;
6727 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006728out:
6729 return status;
6730}
6731
Benny Halevy99fe60d2009-04-01 09:22:29 -04006732#if defined(CONFIG_NFS_V4_1)
6733/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006734 * Decode BIND_CONN_TO_SESSION response
6735 */
6736static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6737 struct xdr_stream *xdr,
6738 void *res)
6739{
6740 struct compound_hdr hdr;
6741 int status;
6742
6743 status = decode_compound_hdr(xdr, &hdr);
6744 if (!status)
6745 status = decode_bind_conn_to_session(xdr, res);
6746 return status;
6747}
6748
6749/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006750 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006751 */
Chuck Leverbf269552010-12-14 14:59:29 +00006752static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6753 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006754 void *res)
6755{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006756 struct compound_hdr hdr;
6757 int status;
6758
Chuck Leverbf269552010-12-14 14:59:29 +00006759 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006760 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006761 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006762 return status;
6763}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006764
6765/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006766 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006767 */
Chuck Leverbf269552010-12-14 14:59:29 +00006768static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6769 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006770 struct nfs41_create_session_res *res)
6771{
Andy Adamsonfc931582009-04-01 09:22:31 -04006772 struct compound_hdr hdr;
6773 int status;
6774
Chuck Leverbf269552010-12-14 14:59:29 +00006775 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006776 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006777 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006778 return status;
6779}
6780
6781/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006782 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006783 */
Chuck Leverbf269552010-12-14 14:59:29 +00006784static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6785 struct xdr_stream *xdr,
6786 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006787{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006788 struct compound_hdr hdr;
6789 int status;
6790
Chuck Leverbf269552010-12-14 14:59:29 +00006791 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006792 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006793 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006794 return status;
6795}
6796
6797/*
Trond Myklebust66245532012-05-25 17:18:09 -04006798 * Decode DESTROY_CLIENTID response
6799 */
6800static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6801 struct xdr_stream *xdr,
6802 void *res)
6803{
6804 struct compound_hdr hdr;
6805 int status;
6806
6807 status = decode_compound_hdr(xdr, &hdr);
6808 if (!status)
6809 status = decode_destroy_clientid(xdr, res);
6810 return status;
6811}
6812
6813/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006814 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006815 */
Chuck Leverbf269552010-12-14 14:59:29 +00006816static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6817 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006818 struct nfs4_sequence_res *res)
6819{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006820 struct compound_hdr hdr;
6821 int status;
6822
Chuck Leverbf269552010-12-14 14:59:29 +00006823 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006824 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006825 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006826 return status;
6827}
6828
6829/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006830 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006831 */
Chuck Leverbf269552010-12-14 14:59:29 +00006832static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6833 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006834 struct nfs4_get_lease_time_res *res)
6835{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006836 struct compound_hdr hdr;
6837 int status;
6838
Chuck Leverbf269552010-12-14 14:59:29 +00006839 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006840 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006841 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006842 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006843 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006844 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006845 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006846 return status;
6847}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006848
6849/*
6850 * Decode RECLAIM_COMPLETE response
6851 */
Chuck Leverbf269552010-12-14 14:59:29 +00006852static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6853 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006854 struct nfs41_reclaim_complete_res *res)
6855{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006856 struct compound_hdr hdr;
6857 int status;
6858
Chuck Leverbf269552010-12-14 14:59:29 +00006859 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006860 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006861 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006862 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006863 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006864 return status;
6865}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006866
6867/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006868 * Decode GETDEVICELIST response
6869 */
6870static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6871 struct xdr_stream *xdr,
6872 struct nfs4_getdevicelist_res *res)
6873{
6874 struct compound_hdr hdr;
6875 int status;
6876
6877 dprintk("encoding getdevicelist!\n");
6878
6879 status = decode_compound_hdr(xdr, &hdr);
6880 if (status != 0)
6881 goto out;
6882 status = decode_sequence(xdr, &res->seq_res, rqstp);
6883 if (status != 0)
6884 goto out;
6885 status = decode_putfh(xdr);
6886 if (status != 0)
6887 goto out;
6888 status = decode_getdevicelist(xdr, res->devlist);
6889out:
6890 return status;
6891}
6892
6893/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006894 * Decode GETDEVINFO response
6895 */
Chuck Leverbf269552010-12-14 14:59:29 +00006896static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6897 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006898 struct nfs4_getdeviceinfo_res *res)
6899{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006900 struct compound_hdr hdr;
6901 int status;
6902
Chuck Leverbf269552010-12-14 14:59:29 +00006903 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006904 if (status != 0)
6905 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006906 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006907 if (status != 0)
6908 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006909 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006910out:
6911 return status;
6912}
6913
6914/*
6915 * Decode LAYOUTGET response
6916 */
Chuck Leverbf269552010-12-14 14:59:29 +00006917static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6918 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006919 struct nfs4_layoutget_res *res)
6920{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006921 struct compound_hdr hdr;
6922 int status;
6923
Chuck Leverbf269552010-12-14 14:59:29 +00006924 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006925 if (status)
6926 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006927 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006928 if (status)
6929 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006930 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006931 if (status)
6932 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006933 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006934out:
6935 return status;
6936}
Andy Adamson863a3c62011-03-23 13:27:54 +00006937
6938/*
Benny Halevycbe82602011-05-22 19:52:37 +03006939 * Decode LAYOUTRETURN response
6940 */
6941static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6942 struct xdr_stream *xdr,
6943 struct nfs4_layoutreturn_res *res)
6944{
6945 struct compound_hdr hdr;
6946 int status;
6947
6948 status = decode_compound_hdr(xdr, &hdr);
6949 if (status)
6950 goto out;
6951 status = decode_sequence(xdr, &res->seq_res, rqstp);
6952 if (status)
6953 goto out;
6954 status = decode_putfh(xdr);
6955 if (status)
6956 goto out;
6957 status = decode_layoutreturn(xdr, res);
6958out:
6959 return status;
6960}
6961
6962/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006963 * Decode LAYOUTCOMMIT response
6964 */
6965static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6966 struct xdr_stream *xdr,
6967 struct nfs4_layoutcommit_res *res)
6968{
6969 struct compound_hdr hdr;
6970 int status;
6971
6972 status = decode_compound_hdr(xdr, &hdr);
6973 if (status)
6974 goto out;
6975 status = decode_sequence(xdr, &res->seq_res, rqstp);
6976 if (status)
6977 goto out;
6978 status = decode_putfh(xdr);
6979 if (status)
6980 goto out;
6981 status = decode_layoutcommit(xdr, rqstp, res);
6982 if (status)
6983 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006984 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006985out:
6986 return status;
6987}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006988
6989/*
6990 * Decode SECINFO_NO_NAME response
6991 */
6992static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6993 struct xdr_stream *xdr,
6994 struct nfs4_secinfo_res *res)
6995{
6996 struct compound_hdr hdr;
6997 int status;
6998
6999 status = decode_compound_hdr(xdr, &hdr);
7000 if (status)
7001 goto out;
7002 status = decode_sequence(xdr, &res->seq_res, rqstp);
7003 if (status)
7004 goto out;
7005 status = decode_putrootfh(xdr);
7006 if (status)
7007 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007008 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007009out:
7010 return status;
7011}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007012
7013/*
7014 * Decode TEST_STATEID response
7015 */
7016static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7017 struct xdr_stream *xdr,
7018 struct nfs41_test_stateid_res *res)
7019{
7020 struct compound_hdr hdr;
7021 int status;
7022
7023 status = decode_compound_hdr(xdr, &hdr);
7024 if (status)
7025 goto out;
7026 status = decode_sequence(xdr, &res->seq_res, rqstp);
7027 if (status)
7028 goto out;
7029 status = decode_test_stateid(xdr, res);
7030out:
7031 return status;
7032}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007033
7034/*
7035 * Decode FREE_STATEID response
7036 */
7037static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7038 struct xdr_stream *xdr,
7039 struct nfs41_free_stateid_res *res)
7040{
7041 struct compound_hdr hdr;
7042 int status;
7043
7044 status = decode_compound_hdr(xdr, &hdr);
7045 if (status)
7046 goto out;
7047 status = decode_sequence(xdr, &res->seq_res, rqstp);
7048 if (status)
7049 goto out;
7050 status = decode_free_stateid(xdr, res);
7051out:
7052 return status;
7053}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007054#endif /* CONFIG_NFS_V4_1 */
7055
Chuck Lever573c4e12010-12-14 14:58:11 +00007056/**
7057 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7058 * the local page cache.
7059 * @xdr: XDR stream where entry resides
7060 * @entry: buffer to fill in with entry data
7061 * @plus: boolean indicating whether this should be a readdirplus entry
7062 *
7063 * Returns zero if successful, otherwise a negative errno value is
7064 * returned.
7065 *
7066 * This function is not invoked during READDIR reply decoding, but
7067 * rather whenever an application invokes the getdents(2) system call
7068 * on a directory already in our cache.
7069 */
7070int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7071 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007072{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007073 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007074 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007075 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007076 __be32 *p = xdr_inline_decode(xdr, 4);
7077 if (unlikely(!p))
7078 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007079 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007080 p = xdr_inline_decode(xdr, 4);
7081 if (unlikely(!p))
7082 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007083 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007084 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007085 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007086 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007087 }
7088
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007089 p = xdr_inline_decode(xdr, 12);
7090 if (unlikely(!p))
7091 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007092 entry->prev_cookie = entry->cookie;
7093 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007094 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007095
Trond Myklebust9af8c222010-10-24 11:52:55 -04007096 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007097 if (unlikely(!p))
7098 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007099 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007100
7101 /*
7102 * In case the server doesn't return an inode number,
7103 * we fake one here. (We don't use inode number 0,
7104 * since glibc seems to choke on it...)
7105 */
7106 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007107 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007108
Trond Myklebust9af8c222010-10-24 11:52:55 -04007109 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007110 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007111
Trond Myklebust256e48b2012-06-21 11:18:13 -04007112 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007113 goto out_overflow;
7114
Chuck Lever573c4e12010-12-14 14:58:11 +00007115 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007116 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007117 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007118 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7119 entry->ino = entry->fattr->mounted_on_fileid;
7120 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007121 entry->ino = entry->fattr->fileid;
7122
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007123 entry->d_type = DT_UNKNOWN;
7124 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7125 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7126
Chuck Lever573c4e12010-12-14 14:58:11 +00007127 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007128
7129out_overflow:
7130 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007131 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007132}
7133
7134/*
7135 * We need to translate between nfs status return values and
7136 * the local errno values which may not be the same.
7137 */
7138static struct {
7139 int stat;
7140 int errno;
7141} nfs_errtbl[] = {
7142 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007143 { NFS4ERR_PERM, -EPERM },
7144 { NFS4ERR_NOENT, -ENOENT },
7145 { NFS4ERR_IO, -errno_NFSERR_IO},
7146 { NFS4ERR_NXIO, -ENXIO },
7147 { NFS4ERR_ACCESS, -EACCES },
7148 { NFS4ERR_EXIST, -EEXIST },
7149 { NFS4ERR_XDEV, -EXDEV },
7150 { NFS4ERR_NOTDIR, -ENOTDIR },
7151 { NFS4ERR_ISDIR, -EISDIR },
7152 { NFS4ERR_INVAL, -EINVAL },
7153 { NFS4ERR_FBIG, -EFBIG },
7154 { NFS4ERR_NOSPC, -ENOSPC },
7155 { NFS4ERR_ROFS, -EROFS },
7156 { NFS4ERR_MLINK, -EMLINK },
7157 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7158 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7159 { NFS4ERR_DQUOT, -EDQUOT },
7160 { NFS4ERR_STALE, -ESTALE },
7161 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007162 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7163 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7164 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007165 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007166 { NFS4ERR_BADTYPE, -EBADTYPE },
7167 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007168 { NFS4ERR_SYMLINK, -ELOOP },
7169 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7170 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007171 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007172};
7173
7174/*
7175 * Convert an NFS error code to a local one.
7176 * This one is used jointly by NFSv2 and NFSv3.
7177 */
7178static int
David Howells0a8ea432006-08-22 20:06:08 -04007179nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007180{
7181 int i;
7182 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7183 if (nfs_errtbl[i].stat == stat)
7184 return nfs_errtbl[i].errno;
7185 }
7186 if (stat <= 10000 || stat > 10100) {
7187 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007188 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007189 }
7190 /* If we cannot translate the error, the recovery routines should
7191 * handle it.
7192 * Note: remaining NFSv4 error codes have values > 10000, so should
7193 * not conflict with native Linux error codes.
7194 */
Benny Halevy856dff32008-03-31 17:39:06 +03007195 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007196}
7197
Linus Torvalds1da177e2005-04-16 15:20:36 -07007198#define PROC(proc, argtype, restype) \
7199[NFSPROC4_CLNT_##proc] = { \
7200 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007201 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007202 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007203 .p_arglen = NFS4_##argtype##_sz, \
7204 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007205 .p_statidx = NFSPROC4_CLNT_##proc, \
7206 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007207}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007208
7209struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007210 PROC(READ, enc_read, dec_read),
7211 PROC(WRITE, enc_write, dec_write),
7212 PROC(COMMIT, enc_commit, dec_commit),
7213 PROC(OPEN, enc_open, dec_open),
7214 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7215 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7216 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7217 PROC(CLOSE, enc_close, dec_close),
7218 PROC(SETATTR, enc_setattr, dec_setattr),
7219 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7220 PROC(RENEW, enc_renew, dec_renew),
7221 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7222 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7223 PROC(LOCK, enc_lock, dec_lock),
7224 PROC(LOCKT, enc_lockt, dec_lockt),
7225 PROC(LOCKU, enc_locku, dec_locku),
7226 PROC(ACCESS, enc_access, dec_access),
7227 PROC(GETATTR, enc_getattr, dec_getattr),
7228 PROC(LOOKUP, enc_lookup, dec_lookup),
7229 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7230 PROC(REMOVE, enc_remove, dec_remove),
7231 PROC(RENAME, enc_rename, dec_rename),
7232 PROC(LINK, enc_link, dec_link),
7233 PROC(SYMLINK, enc_symlink, dec_symlink),
7234 PROC(CREATE, enc_create, dec_create),
7235 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7236 PROC(STATFS, enc_statfs, dec_statfs),
7237 PROC(READLINK, enc_readlink, dec_readlink),
7238 PROC(READDIR, enc_readdir, dec_readdir),
7239 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7240 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7241 PROC(GETACL, enc_getacl, dec_getacl),
7242 PROC(SETACL, enc_setacl, dec_setacl),
7243 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7244 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007245 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007246#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007247 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7248 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7249 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7250 PROC(SEQUENCE, enc_sequence, dec_sequence),
7251 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7252 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7253 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7254 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007255 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007256 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007257 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007258 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007259 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007260 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007261 PROC(BIND_CONN_TO_SESSION,
7262 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007263 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007264#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007265};
7266
Trond Myklebusta613fa12012-01-20 13:53:56 -05007267const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007268 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007269 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007270 .procs = nfs4_procedures
7271};
7272
7273/*
7274 * Local variables:
7275 * c-basic-offset: 8
7276 * End:
7277 */