blob: 0b744895b9e19e80841abd899f6937585d1d209e [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 + \
533 encode_setclientid_confirm_maxsz + \
534 encode_putrootfh_maxsz + \
535 encode_fsinfo_maxsz)
536#define NFS4_dec_setclientid_confirm_sz \
537 (compound_decode_hdr_maxsz + \
538 decode_setclientid_confirm_maxsz + \
539 decode_putrootfh_maxsz + \
540 decode_fsinfo_maxsz)
541#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400544 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400548 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400552 encode_lockt_maxsz)
553#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400554 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400555 decode_putfh_maxsz + \
556 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400560 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400564 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400565#define NFS4_enc_release_lockowner_sz \
566 (compound_encode_hdr_maxsz + \
567 encode_lockowner_maxsz)
568#define NFS4_dec_release_lockowner_sz \
569 (compound_decode_hdr_maxsz + \
570 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400574 encode_access_maxsz + \
575 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400577 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400579 decode_access_maxsz + \
580 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 encode_putfh_maxsz + \
584 encode_getattr_maxsz)
585#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 decode_putfh_maxsz + \
588 decode_getattr_maxsz)
589#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
592 encode_lookup_maxsz + \
593 encode_getattr_maxsz + \
594 encode_getfh_maxsz)
595#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400598 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 decode_getattr_maxsz + \
600 decode_getfh_maxsz)
601#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400602 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 encode_putrootfh_maxsz + \
604 encode_getattr_maxsz + \
605 encode_getfh_maxsz)
606#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400607 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 decode_putrootfh_maxsz + \
609 decode_getattr_maxsz + \
610 decode_getfh_maxsz)
611#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400612 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400614 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400618 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400620 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 encode_putfh_maxsz + \
622 encode_savefh_maxsz + \
623 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400624 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 decode_putfh_maxsz + \
628 decode_savefh_maxsz + \
629 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400630 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400632 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 encode_putfh_maxsz + \
634 encode_savefh_maxsz + \
635 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400636 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400637 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400638 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400640 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 decode_putfh_maxsz + \
642 decode_savefh_maxsz + \
643 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400644 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400645 decode_restorefh_maxsz + \
646 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 encode_putfh_maxsz + \
650 encode_symlink_maxsz + \
651 encode_getattr_maxsz + \
652 encode_getfh_maxsz)
653#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 decode_putfh_maxsz + \
656 decode_symlink_maxsz + \
657 decode_getattr_maxsz + \
658 decode_getfh_maxsz)
659#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 encode_putfh_maxsz + \
662 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400663 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400664 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 decode_putfh_maxsz + \
668 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400669 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400670 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 encode_putfh_maxsz + \
674 encode_getattr_maxsz)
675#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 decode_putfh_maxsz + \
678 decode_getattr_maxsz)
679#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400686 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800689 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 encode_getattr_maxsz)
691#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800693 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 decode_getattr_maxsz)
695#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100698 encode_delegreturn_maxsz + \
699 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400701 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100702 decode_delegreturn_maxsz + \
703 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000704#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400705 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000706 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400707 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000708#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400709 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000710 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400711 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000712#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000714 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400715 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000716#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000718 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400719 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400720#define NFS4_enc_fs_locations_sz \
721 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400723 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400724 encode_lookup_maxsz + \
725 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400726#define NFS4_dec_fs_locations_sz \
727 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400729 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400730 decode_lookup_maxsz + \
731 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000732#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
733 encode_sequence_maxsz + \
734 encode_putfh_maxsz + \
735 encode_secinfo_maxsz)
736#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
737 decode_sequence_maxsz + \
738 decode_putfh_maxsz + \
739 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400740#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400741#define NFS4_enc_bind_conn_to_session_sz \
742 (compound_encode_hdr_maxsz + \
743 encode_bind_conn_to_session_maxsz)
744#define NFS4_dec_bind_conn_to_session_sz \
745 (compound_decode_hdr_maxsz + \
746 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400747#define NFS4_enc_exchange_id_sz \
748 (compound_encode_hdr_maxsz + \
749 encode_exchange_id_maxsz)
750#define NFS4_dec_exchange_id_sz \
751 (compound_decode_hdr_maxsz + \
752 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400753#define NFS4_enc_create_session_sz \
754 (compound_encode_hdr_maxsz + \
755 encode_create_session_maxsz)
756#define NFS4_dec_create_session_sz \
757 (compound_decode_hdr_maxsz + \
758 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400759#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
760 encode_destroy_session_maxsz)
761#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
762 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400763#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
764 encode_destroy_clientid_maxsz)
765#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
766 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400767#define NFS4_enc_sequence_sz \
768 (compound_decode_hdr_maxsz + \
769 encode_sequence_maxsz)
770#define NFS4_dec_sequence_sz \
771 (compound_decode_hdr_maxsz + \
772 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400773#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
774 encode_sequence_maxsz + \
775 encode_putrootfh_maxsz + \
776 encode_fsinfo_maxsz)
777#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
778 decode_sequence_maxsz + \
779 decode_putrootfh_maxsz + \
780 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500781#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
782 encode_sequence_maxsz + \
783 encode_reclaim_complete_maxsz)
784#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
785 decode_sequence_maxsz + \
786 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400787#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
788 encode_sequence_maxsz + \
789 encode_putfh_maxsz + \
790 encode_getdevicelist_maxsz)
791#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
792 decode_sequence_maxsz + \
793 decode_putfh_maxsz + \
794 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400795#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
796 encode_sequence_maxsz +\
797 encode_getdeviceinfo_maxsz)
798#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
799 decode_sequence_maxsz + \
800 decode_getdeviceinfo_maxsz)
801#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
802 encode_sequence_maxsz + \
803 encode_putfh_maxsz + \
804 encode_layoutget_maxsz)
805#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
806 decode_sequence_maxsz + \
807 decode_putfh_maxsz + \
808 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000809#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz +\
811 encode_putfh_maxsz + \
812 encode_layoutcommit_maxsz + \
813 encode_getattr_maxsz)
814#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_putfh_maxsz + \
817 decode_layoutcommit_maxsz + \
818 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300819#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz + \
821 encode_putfh_maxsz + \
822 encode_layoutreturn_maxsz)
823#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
824 decode_sequence_maxsz + \
825 decode_putfh_maxsz + \
826 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400827#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
828 encode_sequence_maxsz + \
829 encode_putrootfh_maxsz +\
830 encode_secinfo_no_name_maxsz)
831#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
832 decode_sequence_maxsz + \
833 decode_putrootfh_maxsz + \
834 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400835#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
836 encode_sequence_maxsz + \
837 encode_test_stateid_maxsz)
838#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
839 decode_sequence_maxsz + \
840 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400841#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
842 encode_sequence_maxsz + \
843 encode_free_stateid_maxsz)
844#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
845 decode_sequence_maxsz + \
846 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500847
848const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
849 compound_encode_hdr_maxsz +
850 encode_sequence_maxsz +
851 encode_putfh_maxsz +
852 encode_getattr_maxsz) *
853 XDR_UNIT);
854
855const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
856 compound_decode_hdr_maxsz +
857 decode_sequence_maxsz +
858 decode_putfh_maxsz) *
859 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400860#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
Trond Myklebustbca79472009-03-11 14:10:26 -0400862static const umode_t nfs_type2fmt[] = {
863 [NF4BAD] = 0,
864 [NF4REG] = S_IFREG,
865 [NF4DIR] = S_IFDIR,
866 [NF4BLK] = S_IFBLK,
867 [NF4CHR] = S_IFCHR,
868 [NF4LNK] = S_IFLNK,
869 [NF4SOCK] = S_IFSOCK,
870 [NF4FIFO] = S_IFIFO,
871 [NF4ATTRDIR] = 0,
872 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873};
874
875struct compound_hdr {
876 int32_t status;
877 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500878 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 uint32_t taglen;
880 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400881 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400882 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883};
884
Benny Halevy13c65ce2009-08-14 17:19:25 +0300885static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
886{
887 __be32 *p = xdr_reserve_space(xdr, nbytes);
888 BUG_ON(!p);
889 return p;
890}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Trond Myklebustcb17e552012-03-04 18:13:56 -0500892static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
893{
894 __be32 *p;
895
896 p = xdr_reserve_space(xdr, len);
897 xdr_encode_opaque_fixed(p, buf, len);
898}
899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
901{
Al Viro8687b632006-10-19 23:28:48 -0700902 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500904 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 xdr_encode_opaque(p, str, len);
906}
907
Trond Myklebust4ade9822012-03-04 18:13:57 -0500908static void encode_uint32(struct xdr_stream *xdr, u32 n)
909{
910 __be32 *p;
911
912 p = reserve_space(xdr, 4);
913 *p = cpu_to_be32(n);
914}
915
Trond Myklebustff2eb682012-03-05 11:40:12 -0500916static void encode_uint64(struct xdr_stream *xdr, u64 n)
917{
918 __be32 *p;
919
920 p = reserve_space(xdr, 8);
921 xdr_encode_hyper(p, n);
922}
923
Trond Myklebust4ade9822012-03-04 18:13:57 -0500924static void encode_nfs4_seqid(struct xdr_stream *xdr,
925 const struct nfs_seqid *seqid)
926{
927 encode_uint32(xdr, seqid->sequence->counter);
928}
929
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400930static void encode_compound_hdr(struct xdr_stream *xdr,
931 struct rpc_rqst *req,
932 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
Al Viro8687b632006-10-19 23:28:48 -0700934 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400935 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400936
937 /* initialize running count of expected bytes in reply.
938 * NOTE: the replied tag SHOULD be the same is the one sent,
939 * but this is not required as a MUST for the server to do so. */
940 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Trond Myklebust7fc38842012-10-15 11:51:21 -0400942 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500943 encode_string(xdr, hdr->taglen, hdr->tag);
944 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300945 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500946 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300947 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500948}
949
Trond Myklebustab19b482012-03-04 18:13:57 -0500950static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
951 uint32_t replen,
952 struct compound_hdr *hdr)
953{
954 encode_uint32(xdr, op);
955 hdr->nops++;
956 hdr->replen += replen;
957}
958
Andy Adamsond0179312008-12-23 16:06:17 -0500959static void encode_nops(struct compound_hdr *hdr)
960{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400961 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500962 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500965static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
966{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500967 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500968}
969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
971{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500972 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973}
974
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500975static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
977 char owner_name[IDMAP_NAMESZ];
978 char owner_group[IDMAP_NAMESZ];
979 int owner_namelen = 0;
980 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700981 __be32 *p;
982 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 int len;
984 uint32_t bmval0 = 0;
985 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
987 /*
988 * We reserve enough space to write the entire attribute buffer at once.
989 * In the worst-case, this would be
990 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
991 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000992 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 */
994 len = 16;
995
996 /* Sigh */
997 if (iap->ia_valid & ATTR_SIZE)
998 len += 8;
999 if (iap->ia_valid & ATTR_MODE)
1000 len += 4;
1001 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001002 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001004 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001005 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 /* XXX */
1007 strcpy(owner_name, "nobody");
1008 owner_namelen = sizeof("nobody") - 1;
1009 /* goto out; */
1010 }
1011 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1012 }
1013 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001014 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001016 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001017 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 strcpy(owner_group, "nobody");
1019 owner_grouplen = sizeof("nobody") - 1;
1020 /* goto out; */
1021 }
1022 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1023 }
1024 if (iap->ia_valid & ATTR_ATIME_SET)
1025 len += 16;
1026 else if (iap->ia_valid & ATTR_ATIME)
1027 len += 4;
1028 if (iap->ia_valid & ATTR_MTIME_SET)
1029 len += 16;
1030 else if (iap->ia_valid & ATTR_MTIME)
1031 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001032 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
1034 /*
1035 * We write the bitmap length now, but leave the bitmap and the attribute
1036 * buffer length to be backfilled at the end of this routine.
1037 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001038 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 q = p;
1040 p += 3;
1041
1042 if (iap->ia_valid & ATTR_SIZE) {
1043 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001044 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046 if (iap->ia_valid & ATTR_MODE) {
1047 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001048 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 }
1050 if (iap->ia_valid & ATTR_UID) {
1051 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001052 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
1054 if (iap->ia_valid & ATTR_GID) {
1055 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001056 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
1058 if (iap->ia_valid & ATTR_ATIME_SET) {
1059 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001060 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1061 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001062 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1063 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 }
1065 else if (iap->ia_valid & ATTR_ATIME) {
1066 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
1069 if (iap->ia_valid & ATTR_MTIME_SET) {
1070 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001071 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1072 *p++ = cpu_to_be32(0);
1073 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1074 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
1076 else if (iap->ia_valid & ATTR_MTIME) {
1077 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001078 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001080
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 /*
1082 * Now we backfill the bitmap and the attribute buffer length.
1083 */
1084 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001085 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 len, ((char *)p - (char *)q) + 4);
1087 BUG();
1088 }
1089 len = (char *)p - (char *)q - 12;
1090 *q++ = htonl(bmval0);
1091 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001092 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095}
1096
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001097static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001099 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1100 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101}
1102
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001103static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
Trond Myklebustab19b482012-03-04 18:13:57 -05001105 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001106 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001107 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108}
1109
Fred Isaman0b7c0152012-04-20 14:47:39 -04001110static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111{
Al Viro8687b632006-10-19 23:28:48 -07001112 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001113
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001114 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1115 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001116 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001117 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118}
1119
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001120static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
Al Viro8687b632006-10-19 23:28:48 -07001122 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001123
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001124 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1125 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
1127 switch (create->ftype) {
1128 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001129 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001130 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001131 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 break;
1133
1134 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001135 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001136 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001137 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 break;
1139
1140 default:
1141 break;
1142 }
1143
Benny Halevy811652b2009-08-14 17:19:34 +03001144 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001145 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146}
1147
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001148static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Andy Adamson05d564f2008-12-23 16:06:15 -05001150 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001152 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1153 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001154 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001155 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156}
1157
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001158static 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 -07001159{
Andy Adamson05d564f2008-12-23 16:06:15 -05001160 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001162 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1163 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001164 *p++ = cpu_to_be32(2);
1165 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001166 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167}
1168
Fred Isamandae100c2011-07-30 20:52:37 -04001169static void
1170encode_getattr_three(struct xdr_stream *xdr,
1171 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1172 struct compound_hdr *hdr)
1173{
1174 __be32 *p;
1175
Trond Myklebustab19b482012-03-04 18:13:57 -05001176 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001177 if (bm2) {
1178 p = reserve_space(xdr, 16);
1179 *p++ = cpu_to_be32(3);
1180 *p++ = cpu_to_be32(bm0);
1181 *p++ = cpu_to_be32(bm1);
1182 *p = cpu_to_be32(bm2);
1183 } else if (bm1) {
1184 p = reserve_space(xdr, 12);
1185 *p++ = cpu_to_be32(2);
1186 *p++ = cpu_to_be32(bm0);
1187 *p = cpu_to_be32(bm1);
1188 } else {
1189 p = reserve_space(xdr, 8);
1190 *p++ = cpu_to_be32(1);
1191 *p = cpu_to_be32(bm0);
1192 }
Fred Isamandae100c2011-07-30 20:52:37 -04001193}
1194
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001195static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001197 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1198 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199}
1200
Andy Adamson88034c32012-05-23 05:02:34 -04001201static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001202 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001203 struct compound_hdr *hdr)
1204{
1205 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001206 bitmask[0] & open_bitmap[0],
1207 bitmask[1] & open_bitmap[1],
1208 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001209 hdr);
1210}
1211
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001212static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
Fred Isamandae100c2011-07-30 20:52:37 -04001214 encode_getattr_three(xdr,
1215 bitmask[0] & nfs4_fsinfo_bitmap[0],
1216 bitmask[1] & nfs4_fsinfo_bitmap[1],
1217 bitmask[2] & nfs4_fsinfo_bitmap[2],
1218 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219}
1220
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001221static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001222{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001223 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1224 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001225}
1226
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001227static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228{
Trond Myklebustab19b482012-03-04 18:13:57 -05001229 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230}
1231
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001232static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
Trond Myklebustab19b482012-03-04 18:13:57 -05001234 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001235 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236}
1237
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001238static inline int nfs4_lock_type(struct file_lock *fl, int block)
1239{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001240 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001241 return block ? NFS4_READW_LT : NFS4_READ_LT;
1242 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1243}
1244
1245static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1246{
1247 if (fl->fl_end == OFFSET_MAX)
1248 return ~(uint64_t)0;
1249 return fl->fl_end - fl->fl_start + 1;
1250}
1251
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001252static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1253{
1254 __be32 *p;
1255
Trond Myklebustd035c362010-12-21 10:45:27 -05001256 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001257 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001258 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001259 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001260 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001261 xdr_encode_hyper(p, lowner->id);
1262}
1263
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264/*
1265 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1266 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1267 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001268static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269{
Al Viro8687b632006-10-19 23:28:48 -07001270 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001272 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1273 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001274 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1275 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001276 p = xdr_encode_hyper(p, args->fl->fl_start);
1277 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001278 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001279 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001280 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001281 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001282 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001283 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 }
1285 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001286 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001287 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289}
1290
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001291static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
Al Viro8687b632006-10-19 23:28:48 -07001293 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001295 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1296 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001297 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001298 p = xdr_encode_hyper(p, args->fl->fl_start);
1299 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001300 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301}
1302
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001303static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304{
Al Viro8687b632006-10-19 23:28:48 -07001305 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001307 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1308 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001309 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001310 encode_nfs4_stateid(xdr, args->stateid);
1311 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001312 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001313 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314}
1315
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001316static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1317{
Trond Myklebustab19b482012-03-04 18:13:57 -05001318 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001319 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001320}
1321
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001322static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323{
Trond Myklebustab19b482012-03-04 18:13:57 -05001324 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001325 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001328static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329{
Al Viro8687b632006-10-19 23:28:48 -07001330 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Benny Halevy13c65ce2009-08-14 17:19:25 +03001332 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001333 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001334 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001335 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001336 break;
1337 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001338 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001339 break;
1340 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001341 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001342 break;
1343 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001344 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 }
Benny Halevy34558512009-08-14 17:19:30 +03001346 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
1349static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1350{
Al Viro8687b632006-10-19 23:28:48 -07001351 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 /*
1353 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1354 * owner 4 = 32
1355 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001356 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001357 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001358 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001359 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001360 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001361 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001362 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001363 *p++ = cpu_to_be32(arg->id.uniquifier);
1364 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365}
1366
1367static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1368{
Al Viro8687b632006-10-19 23:28:48 -07001369 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001370 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Benny Halevy13c65ce2009-08-14 17:19:25 +03001372 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001374 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001375 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001376 encode_attrs(xdr, arg->u.attrs, arg->server);
1377 break;
1378 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001379 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001380 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001381 if (nfs4_has_persistent_session(clp)) {
1382 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1383 encode_attrs(xdr, arg->u.attrs, arg->server);
1384 } else {
1385 struct iattr dummy;
1386
1387 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1388 encode_nfs4_verifier(xdr, &arg->u.verifier);
1389 dummy.ia_valid = 0;
1390 encode_attrs(xdr, &dummy, arg->server);
1391 }
1392 } else {
1393 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1394 encode_nfs4_verifier(xdr, &arg->u.verifier);
1395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 }
1397}
1398
1399static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1400{
Al Viro8687b632006-10-19 23:28:48 -07001401 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Benny Halevy13c65ce2009-08-14 17:19:25 +03001403 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001405 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001406 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001407 break;
1408 default:
Benny Halevy34558512009-08-14 17:19:30 +03001409 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001410 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 }
1412}
1413
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001414static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415{
Al Viro8687b632006-10-19 23:28:48 -07001416 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
Benny Halevy13c65ce2009-08-14 17:19:25 +03001418 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001420 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001421 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001422 break;
1423 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001424 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001425 break;
1426 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001427 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001428 break;
1429 default:
1430 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 }
1432}
1433
1434static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1435{
Al Viro8687b632006-10-19 23:28:48 -07001436 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Benny Halevy13c65ce2009-08-14 17:19:25 +03001438 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001439 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 encode_string(xdr, name->len, name->name);
1441}
1442
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001443static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
Al Viro8687b632006-10-19 23:28:48 -07001445 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Benny Halevy13c65ce2009-08-14 17:19:25 +03001447 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001448 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 encode_delegation_type(xdr, type);
1450}
1451
1452static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1453{
Al Viro8687b632006-10-19 23:28:48 -07001454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001456 p = reserve_space(xdr, 4);
1457 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1458 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 encode_string(xdr, name->len, name->name);
1460}
1461
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001462static inline void encode_claim_fh(struct xdr_stream *xdr)
1463{
1464 __be32 *p;
1465
1466 p = reserve_space(xdr, 4);
1467 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1468}
1469
1470static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1471{
1472 __be32 *p;
1473
1474 p = reserve_space(xdr, 4);
1475 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1476 encode_nfs4_stateid(xdr, stateid);
1477}
1478
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001479static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480{
Trond Myklebustab19b482012-03-04 18:13:57 -05001481 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 encode_openhdr(xdr, arg);
1483 encode_opentype(xdr, arg);
1484 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001485 case NFS4_OPEN_CLAIM_NULL:
1486 encode_claim_null(xdr, arg->name);
1487 break;
1488 case NFS4_OPEN_CLAIM_PREVIOUS:
1489 encode_claim_previous(xdr, arg->u.delegation_type);
1490 break;
1491 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1492 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1493 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001494 case NFS4_OPEN_CLAIM_FH:
1495 encode_claim_fh(xdr);
1496 break;
1497 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1498 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1499 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001500 default:
1501 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503}
1504
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001505static 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 -07001506{
Trond Myklebustab19b482012-03-04 18:13:57 -05001507 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}
1511
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001512static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
Trond Myklebustab19b482012-03-04 18:13:57 -05001514 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001515 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001516 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001517 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518}
1519
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001520static void
Andy Adamsond0179312008-12-23 16:06:17 -05001521encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522{
Trond Myklebustab19b482012-03-04 18:13:57 -05001523 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001524 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
1526
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001527static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
Trond Myklebustab19b482012-03-04 18:13:57 -05001529 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001532static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533{
Al Viro8687b632006-10-19 23:28:48 -07001534 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
Trond Myklebustab19b482012-03-04 18:13:57 -05001536 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001537 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
Benny Halevy13c65ce2009-08-14 17:19:25 +03001539 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001540 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001541 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542}
1543
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001544static 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 -07001545{
Trond Myklebust28331a42011-04-27 13:47:52 -04001546 uint32_t attrs[2] = {
1547 FATTR4_WORD0_RDATTR_ERROR,
1548 FATTR4_WORD1_MOUNTED_ON_FILEID,
1549 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001550 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001551 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001553 if (readdir->plus) {
1554 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001555 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001556 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1557 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1558 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1559 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001560 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001561 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001562 /* Use mounted_on_fileid only if the server supports it */
1563 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1564 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001565
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001566 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001567 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001568 encode_nfs4_verifier(xdr, &readdir->verifier);
1569 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001570 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001571 *p++ = cpu_to_be32(readdir->count);
1572 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001573
Benny Halevye75bc1c2009-08-14 17:18:54 +03001574 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001575 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001576 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001577 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1578 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001579 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001580 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001581 attrs[0] & readdir->bitmask[0],
1582 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583}
1584
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001585static 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 -07001586{
Trond Myklebustab19b482012-03-04 18:13:57 -05001587 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588}
1589
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001590static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591{
Trond Myklebustab19b482012-03-04 18:13:57 -05001592 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001593 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594}
1595
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001596static 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 -07001597{
Trond Myklebustab19b482012-03-04 18:13:57 -05001598 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001599 encode_string(xdr, oldname->len, oldname->name);
1600 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601}
1602
Chuck Leverbb4dae52012-03-01 17:01:48 -05001603static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1604 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001606 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001607 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608}
1609
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001610static void
Andy Adamsond0179312008-12-23 16:06:17 -05001611encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001612{
Trond Myklebustab19b482012-03-04 18:13:57 -05001613 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001614}
1615
Chuck Lever9f06c712010-12-14 14:59:18 +00001616static void
Andy Adamsond0179312008-12-23 16:06:17 -05001617encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001618{
Al Viro8687b632006-10-19 23:28:48 -07001619 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001620
Trond Myklebustab19b482012-03-04 18:13:57 -05001621 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001622 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001623 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001624 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001625 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001626 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001627 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001628 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001629}
1630
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001631static void
Andy Adamsond0179312008-12-23 16:06:17 -05001632encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633{
Trond Myklebustab19b482012-03-04 18:13:57 -05001634 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635}
1636
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001637static 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 -07001638{
Trond Myklebustab19b482012-03-04 18:13:57 -05001639 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001640 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001641 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642}
1643
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001644static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645{
Al Viro8687b632006-10-19 23:28:48 -07001646 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
Trond Myklebust70019512012-03-04 20:49:32 -05001648 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001649 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
1651 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001652 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001653 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1655 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001656 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001657 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
1659
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001660static 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 -07001661{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001662 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1663 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001664 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001665 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666}
1667
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001668static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669{
Al Viro8687b632006-10-19 23:28:48 -07001670 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Trond Myklebustab19b482012-03-04 18:13:57 -05001672 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001673 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
Benny Halevy13c65ce2009-08-14 17:19:25 +03001675 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001676 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001677 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001678 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
1680 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681}
1682
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001683static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684{
Trond Myklebustab19b482012-03-04 18:13:57 -05001685 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001686 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001688
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001689static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1690{
Trond Myklebustab19b482012-03-04 18:13:57 -05001691 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001692 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001693}
1694
Benny Halevy99fe60d2009-04-01 09:22:29 -04001695#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001696/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001697static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1698 struct nfs4_session *session,
1699 struct compound_hdr *hdr)
1700{
1701 __be32 *p;
1702
1703 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1704 decode_bind_conn_to_session_maxsz, hdr);
1705 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1706 p = xdr_reserve_space(xdr, 8);
1707 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1708 *p = 0; /* use_conn_in_rdma_mode = False */
1709}
1710
Benny Halevy99fe60d2009-04-01 09:22:29 -04001711static void encode_exchange_id(struct xdr_stream *xdr,
1712 struct nfs41_exchange_id_args *args,
1713 struct compound_hdr *hdr)
1714{
1715 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001716 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001717 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001718
Trond Myklebust70019512012-03-04 20:49:32 -05001719 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001720 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001721
1722 encode_string(xdr, args->id_len, args->id);
1723
Benny Halevy13c65ce2009-08-14 17:19:25 +03001724 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001725 *p++ = cpu_to_be32(args->flags);
1726 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001727
1728 if (send_implementation_id &&
1729 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1730 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001731 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001732 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1733 utsname()->sysname, utsname()->release,
1734 utsname()->version, utsname()->machine);
1735
1736 if (len > 0) {
1737 *p = cpu_to_be32(1); /* implementation id array length=1 */
1738
1739 encode_string(xdr,
1740 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1741 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1742 encode_string(xdr, len, impl_name);
1743 /* just send zeros for nii_date - the date is in nii_name */
1744 p = reserve_space(xdr, 12);
1745 p = xdr_encode_hyper(p, 0);
1746 *p = cpu_to_be32(0);
1747 } else
1748 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001749}
Andy Adamsonfc931582009-04-01 09:22:31 -04001750
1751static void encode_create_session(struct xdr_stream *xdr,
1752 struct nfs41_create_session_args *args,
1753 struct compound_hdr *hdr)
1754{
1755 __be32 *p;
1756 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1757 uint32_t len;
1758 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001759 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001760 u32 max_resp_sz_cached;
1761
1762 /*
1763 * Assumes OPEN is the biggest non-idempotent compound.
1764 * 2 is the verifier.
1765 */
1766 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1767 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001768
Andy Adamsonfc931582009-04-01 09:22:31 -04001769 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1770 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001771
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001772 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1773 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001774 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001775 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1776 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001777
Andy Adamsonfc931582009-04-01 09:22:31 -04001778 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001779 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001780 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1781 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001782 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001783 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1784 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1785 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001786
1787 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001788 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001789 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1790 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1791 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1792 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1793 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1794 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001795
Benny Halevye75bc1c2009-08-14 17:18:54 +03001796 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001797 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001798 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001799
1800 /* authsys_parms rfc1831 */
Chuck Leverf0920752012-05-21 22:45:41 -04001801 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001802 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001803 *p++ = cpu_to_be32(0); /* UID */
1804 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001805 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001806}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001807
1808static void encode_destroy_session(struct xdr_stream *xdr,
1809 struct nfs4_session *session,
1810 struct compound_hdr *hdr)
1811{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001812 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1813 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001814}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001815
Trond Myklebust66245532012-05-25 17:18:09 -04001816static void encode_destroy_clientid(struct xdr_stream *xdr,
1817 uint64_t clientid,
1818 struct compound_hdr *hdr)
1819{
1820 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1821 encode_uint64(xdr, clientid);
1822}
1823
Ricardo Labiaga180197532009-12-05 16:08:40 -05001824static void encode_reclaim_complete(struct xdr_stream *xdr,
1825 struct nfs41_reclaim_complete_args *args,
1826 struct compound_hdr *hdr)
1827{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001828 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1829 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001830}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001831#endif /* CONFIG_NFS_V4_1 */
1832
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001833static void encode_sequence(struct xdr_stream *xdr,
1834 const struct nfs4_sequence_args *args,
1835 struct compound_hdr *hdr)
1836{
1837#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001838 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001839 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001840 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001841 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001842
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001843 if (slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001844 return;
1845
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001846 tp = slot->table;
1847 session = tp->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001848
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001849 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001850
1851 /*
1852 * Sessionid + seqid + slotid + max slotid + cache_this
1853 */
1854 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1855 "max_slotid=%d cache_this=%d\n",
1856 __func__,
1857 ((u32 *)session->sess_id.data)[0],
1858 ((u32 *)session->sess_id.data)[1],
1859 ((u32 *)session->sess_id.data)[2],
1860 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001861 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001862 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001863 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001864 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001865 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001866 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001867 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001868 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001869#endif /* CONFIG_NFS_V4_1 */
1870}
1871
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001872#ifdef CONFIG_NFS_V4_1
1873static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001874encode_getdevicelist(struct xdr_stream *xdr,
1875 const struct nfs4_getdevicelist_args *args,
1876 struct compound_hdr *hdr)
1877{
1878 __be32 *p;
1879 nfs4_verifier dummy = {
1880 .data = "dummmmmy",
1881 };
1882
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001883 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1884 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001885 *p++ = cpu_to_be32(args->layoutclass);
1886 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1887 xdr_encode_hyper(p, 0ULL); /* cookie */
1888 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001889}
1890
1891static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001892encode_getdeviceinfo(struct xdr_stream *xdr,
1893 const struct nfs4_getdeviceinfo_args *args,
1894 struct compound_hdr *hdr)
1895{
1896 __be32 *p;
1897
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001898 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1899 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001900 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1901 NFS4_DEVICEID4_SIZE);
1902 *p++ = cpu_to_be32(args->pdev->layout_type);
1903 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1904 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001905}
1906
1907static void
1908encode_layoutget(struct xdr_stream *xdr,
1909 const struct nfs4_layoutget_args *args,
1910 struct compound_hdr *hdr)
1911{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001912 __be32 *p;
1913
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001914 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1915 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001916 *p++ = cpu_to_be32(0); /* Signal layout available */
1917 *p++ = cpu_to_be32(args->type);
1918 *p++ = cpu_to_be32(args->range.iomode);
1919 p = xdr_encode_hyper(p, args->range.offset);
1920 p = xdr_encode_hyper(p, args->range.length);
1921 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001922 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001923 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001924
1925 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1926 __func__,
1927 args->type,
1928 args->range.iomode,
1929 (unsigned long)args->range.offset,
1930 (unsigned long)args->range.length,
1931 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001932}
Andy Adamson863a3c62011-03-23 13:27:54 +00001933
1934static int
1935encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001936 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001937 const struct nfs4_layoutcommit_args *args,
1938 struct compound_hdr *hdr)
1939{
1940 __be32 *p;
1941
1942 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1943 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1944
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001945 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1946 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001947 /* Only whole file layouts */
1948 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001949 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001950 *p = cpu_to_be32(0); /* reclaim */
1951 encode_nfs4_stateid(xdr, &args->stateid);
1952 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001953 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1954 p = xdr_encode_hyper(p, args->lastbytewritten);
1955 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1956 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001957
1958 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1959 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1960 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001961 else
1962 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001963
Andy Adamson863a3c62011-03-23 13:27:54 +00001964 return 0;
1965}
Benny Halevycbe82602011-05-22 19:52:37 +03001966
1967static void
1968encode_layoutreturn(struct xdr_stream *xdr,
1969 const struct nfs4_layoutreturn_args *args,
1970 struct compound_hdr *hdr)
1971{
1972 __be32 *p;
1973
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001974 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1975 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001976 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1977 *p++ = cpu_to_be32(args->layout_type);
1978 *p++ = cpu_to_be32(IOMODE_ANY);
1979 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001980 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001981 p = xdr_encode_hyper(p, 0);
1982 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1983 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001984 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001985 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001986 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1987 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1988 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001989 } else
1990 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001991}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001992
1993static int
1994encode_secinfo_no_name(struct xdr_stream *xdr,
1995 const struct nfs41_secinfo_no_name_args *args,
1996 struct compound_hdr *hdr)
1997{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001998 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1999 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002000 return 0;
2001}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002002
2003static void encode_test_stateid(struct xdr_stream *xdr,
2004 struct nfs41_test_stateid_args *args,
2005 struct compound_hdr *hdr)
2006{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002007 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2008 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002009 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002010}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002011
2012static void encode_free_stateid(struct xdr_stream *xdr,
2013 struct nfs41_free_stateid_args *args,
2014 struct compound_hdr *hdr)
2015{
Trond Myklebustab19b482012-03-04 18:13:57 -05002016 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002017 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002018}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002019#endif /* CONFIG_NFS_V4_1 */
2020
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021/*
2022 * END OF "GENERIC" ENCODE ROUTINES.
2023 */
2024
Benny Halevy66cc0422009-04-01 09:22:10 -04002025static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2026{
2027#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05002028
2029 if (args->sa_slot)
2030 return args->sa_slot->table->session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002031#endif /* CONFIG_NFS_V4_1 */
2032 return 0;
2033}
2034
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035/*
2036 * Encode an ACCESS request
2037 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002038static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2039 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002042 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
Chuck Lever9f06c712010-12-14 14:59:18 +00002045 encode_compound_hdr(xdr, req, &hdr);
2046 encode_sequence(xdr, &args->seq_args, &hdr);
2047 encode_putfh(xdr, args->fh, &hdr);
2048 encode_access(xdr, args->access, &hdr);
2049 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002050 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051}
2052
2053/*
2054 * Encode LOOKUP request
2055 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002056static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2057 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002060 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
Chuck Lever9f06c712010-12-14 14:59:18 +00002063 encode_compound_hdr(xdr, req, &hdr);
2064 encode_sequence(xdr, &args->seq_args, &hdr);
2065 encode_putfh(xdr, args->dir_fh, &hdr);
2066 encode_lookup(xdr, args->name, &hdr);
2067 encode_getfh(xdr, &hdr);
2068 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002069 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070}
2071
2072/*
2073 * Encode LOOKUP_ROOT request
2074 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002075static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2076 struct xdr_stream *xdr,
2077 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002080 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
Chuck Lever9f06c712010-12-14 14:59:18 +00002083 encode_compound_hdr(xdr, req, &hdr);
2084 encode_sequence(xdr, &args->seq_args, &hdr);
2085 encode_putrootfh(xdr, &hdr);
2086 encode_getfh(xdr, &hdr);
2087 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002088 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089}
2090
2091/*
2092 * Encode REMOVE request
2093 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002094static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2095 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002098 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Chuck Lever9f06c712010-12-14 14:59:18 +00002101 encode_compound_hdr(xdr, req, &hdr);
2102 encode_sequence(xdr, &args->seq_args, &hdr);
2103 encode_putfh(xdr, args->fh, &hdr);
2104 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002105 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
2108/*
2109 * Encode RENAME request
2110 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002111static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2112 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
Chuck Lever9f06c712010-12-14 14:59:18 +00002118 encode_compound_hdr(xdr, req, &hdr);
2119 encode_sequence(xdr, &args->seq_args, &hdr);
2120 encode_putfh(xdr, args->old_dir, &hdr);
2121 encode_savefh(xdr, &hdr);
2122 encode_putfh(xdr, args->new_dir, &hdr);
2123 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002124 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125}
2126
2127/*
2128 * Encode LINK request
2129 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002130static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2131 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002134 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
Chuck Lever9f06c712010-12-14 14:59:18 +00002137 encode_compound_hdr(xdr, req, &hdr);
2138 encode_sequence(xdr, &args->seq_args, &hdr);
2139 encode_putfh(xdr, args->fh, &hdr);
2140 encode_savefh(xdr, &hdr);
2141 encode_putfh(xdr, args->dir_fh, &hdr);
2142 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002143 encode_restorefh(xdr, &hdr);
2144 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002145 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146}
2147
2148/*
2149 * Encode CREATE request
2150 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002151static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2152 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002155 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
Chuck Lever9f06c712010-12-14 14:59:18 +00002158 encode_compound_hdr(xdr, req, &hdr);
2159 encode_sequence(xdr, &args->seq_args, &hdr);
2160 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002161 encode_create(xdr, args, &hdr);
2162 encode_getfh(xdr, &hdr);
2163 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002164 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165}
2166
2167/*
2168 * Encode SYMLINK request
2169 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002170static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2171 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
Chuck Lever9f06c712010-12-14 14:59:18 +00002173 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174}
2175
2176/*
2177 * Encode GETATTR request
2178 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002179static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2180 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002183 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
Chuck Lever9f06c712010-12-14 14:59:18 +00002186 encode_compound_hdr(xdr, req, &hdr);
2187 encode_sequence(xdr, &args->seq_args, &hdr);
2188 encode_putfh(xdr, args->fh, &hdr);
2189 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002190 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191}
2192
2193/*
2194 * Encode a CLOSE request
2195 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002196static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2197 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198{
Andy Adamson05d564f2008-12-23 16:06:15 -05002199 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002200 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002201 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
Chuck Lever9f06c712010-12-14 14:59:18 +00002203 encode_compound_hdr(xdr, req, &hdr);
2204 encode_sequence(xdr, &args->seq_args, &hdr);
2205 encode_putfh(xdr, args->fh, &hdr);
2206 encode_close(xdr, args, &hdr);
2207 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002208 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209}
2210
2211/*
2212 * Encode an OPEN request
2213 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002214static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2215 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002218 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
Chuck Lever9f06c712010-12-14 14:59:18 +00002221 encode_compound_hdr(xdr, req, &hdr);
2222 encode_sequence(xdr, &args->seq_args, &hdr);
2223 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002224 encode_open(xdr, args, &hdr);
2225 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002226 if (args->access)
2227 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002228 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002229 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230}
2231
2232/*
2233 * Encode an OPEN_CONFIRM request
2234 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002235static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2236 struct xdr_stream *xdr,
2237 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002240 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
Chuck Lever9f06c712010-12-14 14:59:18 +00002243 encode_compound_hdr(xdr, req, &hdr);
2244 encode_putfh(xdr, args->fh, &hdr);
2245 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002246 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247}
2248
2249/*
2250 * Encode an OPEN request with no attributes.
2251 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002252static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2253 struct xdr_stream *xdr,
2254 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002257 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
Chuck Lever9f06c712010-12-14 14:59:18 +00002260 encode_compound_hdr(xdr, req, &hdr);
2261 encode_sequence(xdr, &args->seq_args, &hdr);
2262 encode_putfh(xdr, args->fh, &hdr);
2263 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002264 if (args->access)
2265 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002266 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002267 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268}
2269
2270/*
2271 * Encode an OPEN_DOWNGRADE request
2272 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002273static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2274 struct xdr_stream *xdr,
2275 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002278 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
Chuck Lever9f06c712010-12-14 14:59:18 +00002281 encode_compound_hdr(xdr, req, &hdr);
2282 encode_sequence(xdr, &args->seq_args, &hdr);
2283 encode_putfh(xdr, args->fh, &hdr);
2284 encode_open_downgrade(xdr, args, &hdr);
2285 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002286 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287}
2288
2289/*
2290 * Encode a LOCK request
2291 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002292static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2293 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002296 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Chuck Lever9f06c712010-12-14 14:59:18 +00002299 encode_compound_hdr(xdr, req, &hdr);
2300 encode_sequence(xdr, &args->seq_args, &hdr);
2301 encode_putfh(xdr, args->fh, &hdr);
2302 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002303 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304}
2305
2306/*
2307 * Encode a LOCKT request
2308 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002309static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2310 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002313 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Chuck Lever9f06c712010-12-14 14:59:18 +00002316 encode_compound_hdr(xdr, req, &hdr);
2317 encode_sequence(xdr, &args->seq_args, &hdr);
2318 encode_putfh(xdr, args->fh, &hdr);
2319 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002320 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321}
2322
2323/*
2324 * Encode a LOCKU request
2325 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002326static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2327 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002330 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
Chuck Lever9f06c712010-12-14 14:59:18 +00002333 encode_compound_hdr(xdr, req, &hdr);
2334 encode_sequence(xdr, &args->seq_args, &hdr);
2335 encode_putfh(xdr, args->fh, &hdr);
2336 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002337 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338}
2339
Chuck Lever9f06c712010-12-14 14:59:18 +00002340static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2341 struct xdr_stream *xdr,
2342 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002343{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002344 struct compound_hdr hdr = {
2345 .minorversion = 0,
2346 };
2347
Chuck Lever9f06c712010-12-14 14:59:18 +00002348 encode_compound_hdr(xdr, req, &hdr);
2349 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002350 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002351}
2352
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353/*
2354 * Encode a READLINK request
2355 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002356static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2357 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002360 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Chuck Lever9f06c712010-12-14 14:59:18 +00002363 encode_compound_hdr(xdr, req, &hdr);
2364 encode_sequence(xdr, &args->seq_args, &hdr);
2365 encode_putfh(xdr, args->fh, &hdr);
2366 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002367
Benny Halevy28f56692009-04-01 09:22:09 -04002368 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002369 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002370 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371}
2372
2373/*
2374 * Encode a READDIR request
2375 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002376static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2377 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002380 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
Chuck Lever9f06c712010-12-14 14:59:18 +00002383 encode_compound_hdr(xdr, req, &hdr);
2384 encode_sequence(xdr, &args->seq_args, &hdr);
2385 encode_putfh(xdr, args->fh, &hdr);
2386 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002387
Benny Halevy28f56692009-04-01 09:22:09 -04002388 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002389 args->pgbase, args->count);
2390 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002391 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002392 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002393 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394}
2395
2396/*
2397 * Encode a READ request
2398 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002399static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2400 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002403 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
Chuck Lever9f06c712010-12-14 14:59:18 +00002406 encode_compound_hdr(xdr, req, &hdr);
2407 encode_sequence(xdr, &args->seq_args, &hdr);
2408 encode_putfh(xdr, args->fh, &hdr);
2409 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
Benny Halevy28f56692009-04-01 09:22:09 -04002411 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002413 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002414 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415}
2416
2417/*
2418 * Encode an SETATTR request
2419 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002420static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2421 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422{
Andy Adamson05d564f2008-12-23 16:06:15 -05002423 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002424 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002425 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426
Chuck Lever9f06c712010-12-14 14:59:18 +00002427 encode_compound_hdr(xdr, req, &hdr);
2428 encode_sequence(xdr, &args->seq_args, &hdr);
2429 encode_putfh(xdr, args->fh, &hdr);
2430 encode_setattr(xdr, args, args->server, &hdr);
2431 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002432 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433}
2434
2435/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002436 * Encode a GETACL request
2437 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002438static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2439 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002440{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002441 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002442 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002443 };
Benny Halevy28f56692009-04-01 09:22:09 -04002444 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002445
Chuck Lever9f06c712010-12-14 14:59:18 +00002446 encode_compound_hdr(xdr, req, &hdr);
2447 encode_sequence(xdr, &args->seq_args, &hdr);
2448 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002449 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002450 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002451
Benny Halevy28f56692009-04-01 09:22:09 -04002452 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002453 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002454
Andy Adamsond0179312008-12-23 16:06:17 -05002455 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002456}
2457
2458/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 * Encode a WRITE request
2460 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002461static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2462 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002465 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467
Chuck Lever9f06c712010-12-14 14:59:18 +00002468 encode_compound_hdr(xdr, req, &hdr);
2469 encode_sequence(xdr, &args->seq_args, &hdr);
2470 encode_putfh(xdr, args->fh, &hdr);
2471 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002472 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002473 if (args->bitmask)
2474 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002475 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476}
2477
2478/*
2479 * a COMMIT request
2480 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002481static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002482 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002485 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
Chuck Lever9f06c712010-12-14 14:59:18 +00002488 encode_compound_hdr(xdr, req, &hdr);
2489 encode_sequence(xdr, &args->seq_args, &hdr);
2490 encode_putfh(xdr, args->fh, &hdr);
2491 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002492 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493}
2494
2495/*
2496 * FSINFO request
2497 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002498static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2499 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002502 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504
Chuck Lever9f06c712010-12-14 14:59:18 +00002505 encode_compound_hdr(xdr, req, &hdr);
2506 encode_sequence(xdr, &args->seq_args, &hdr);
2507 encode_putfh(xdr, args->fh, &hdr);
2508 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002509 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510}
2511
2512/*
2513 * a PATHCONF request
2514 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002515static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2516 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002519 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
Chuck Lever9f06c712010-12-14 14:59:18 +00002522 encode_compound_hdr(xdr, req, &hdr);
2523 encode_sequence(xdr, &args->seq_args, &hdr);
2524 encode_putfh(xdr, args->fh, &hdr);
2525 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002526 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002527 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528}
2529
2530/*
2531 * a STATFS request
2532 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002533static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2534 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002537 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
Chuck Lever9f06c712010-12-14 14:59:18 +00002540 encode_compound_hdr(xdr, req, &hdr);
2541 encode_sequence(xdr, &args->seq_args, &hdr);
2542 encode_putfh(xdr, args->fh, &hdr);
2543 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002544 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002545 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546}
2547
2548/*
2549 * GETATTR_BITMAP request
2550 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002551static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2552 struct xdr_stream *xdr,
2553 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002556 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
Chuck Lever9f06c712010-12-14 14:59:18 +00002559 encode_compound_hdr(xdr, req, &hdr);
2560 encode_sequence(xdr, &args->seq_args, &hdr);
2561 encode_putfh(xdr, args->fhandle, &hdr);
2562 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002563 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002564 FATTR4_WORD0_LINK_SUPPORT|
2565 FATTR4_WORD0_SYMLINK_SUPPORT|
2566 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002567 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568}
2569
2570/*
2571 * a RENEW request
2572 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002573static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2574 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002577 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 };
2579
Chuck Lever9f06c712010-12-14 14:59:18 +00002580 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002581 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002582 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583}
2584
2585/*
2586 * a SETCLIENTID request
2587 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002588static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2589 struct xdr_stream *xdr,
2590 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002593 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 };
2595
Chuck Lever9f06c712010-12-14 14:59:18 +00002596 encode_compound_hdr(xdr, req, &hdr);
2597 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002598 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599}
2600
2601/*
2602 * a SETCLIENTID_CONFIRM request
2603 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002604static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2605 struct xdr_stream *xdr,
2606 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002609 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 };
Fred Isamandae100c2011-07-30 20:52:37 -04002611 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612
Chuck Lever9f06c712010-12-14 14:59:18 +00002613 encode_compound_hdr(xdr, req, &hdr);
2614 encode_setclientid_confirm(xdr, arg, &hdr);
2615 encode_putrootfh(xdr, &hdr);
2616 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002617 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618}
2619
2620/*
2621 * DELEGRETURN request
2622 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002623static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2624 struct xdr_stream *xdr,
2625 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002628 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
Chuck Lever9f06c712010-12-14 14:59:18 +00002631 encode_compound_hdr(xdr, req, &hdr);
2632 encode_sequence(xdr, &args->seq_args, &hdr);
2633 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002634 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002635 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002636 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637}
2638
2639/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002640 * Encode FS_LOCATIONS request
2641 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002642static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2643 struct xdr_stream *xdr,
2644 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002645{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002646 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002647 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002648 };
Benny Halevy28f56692009-04-01 09:22:09 -04002649 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002650
Chuck Lever9f06c712010-12-14 14:59:18 +00002651 encode_compound_hdr(xdr, req, &hdr);
2652 encode_sequence(xdr, &args->seq_args, &hdr);
2653 encode_putfh(xdr, args->dir_fh, &hdr);
2654 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002655 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002656 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002657
Benny Halevy28f56692009-04-01 09:22:09 -04002658 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002659 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002660 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002661}
2662
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002663/*
2664 * Encode SECINFO request
2665 */
2666static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2667 struct xdr_stream *xdr,
2668 struct nfs4_secinfo_arg *args)
2669{
2670 struct compound_hdr hdr = {
2671 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2672 };
2673
2674 encode_compound_hdr(xdr, req, &hdr);
2675 encode_sequence(xdr, &args->seq_args, &hdr);
2676 encode_putfh(xdr, args->dir_fh, &hdr);
2677 encode_secinfo(xdr, args->name, &hdr);
2678 encode_nops(&hdr);
2679}
2680
Benny Halevy99fe60d2009-04-01 09:22:29 -04002681#if defined(CONFIG_NFS_V4_1)
2682/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002683 * BIND_CONN_TO_SESSION request
2684 */
2685static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2686 struct xdr_stream *xdr,
2687 struct nfs_client *clp)
2688{
2689 struct compound_hdr hdr = {
2690 .minorversion = clp->cl_mvops->minor_version,
2691 };
2692
2693 encode_compound_hdr(xdr, req, &hdr);
2694 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2695 encode_nops(&hdr);
2696}
2697
2698/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002699 * EXCHANGE_ID request
2700 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002701static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2702 struct xdr_stream *xdr,
2703 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002704{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002705 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002706 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002707 };
2708
Chuck Lever9f06c712010-12-14 14:59:18 +00002709 encode_compound_hdr(xdr, req, &hdr);
2710 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002711 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002712}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002713
2714/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002715 * a CREATE_SESSION request
2716 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002717static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2718 struct xdr_stream *xdr,
2719 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002720{
Andy Adamsonfc931582009-04-01 09:22:31 -04002721 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002722 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002723 };
2724
Chuck Lever9f06c712010-12-14 14:59:18 +00002725 encode_compound_hdr(xdr, req, &hdr);
2726 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002727 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002728}
2729
2730/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002731 * a DESTROY_SESSION request
2732 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002733static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2734 struct xdr_stream *xdr,
2735 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002736{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002737 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002738 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002739 };
2740
Chuck Lever9f06c712010-12-14 14:59:18 +00002741 encode_compound_hdr(xdr, req, &hdr);
2742 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002743 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002744}
2745
2746/*
Trond Myklebust66245532012-05-25 17:18:09 -04002747 * a DESTROY_CLIENTID request
2748 */
2749static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2750 struct xdr_stream *xdr,
2751 struct nfs_client *clp)
2752{
2753 struct compound_hdr hdr = {
2754 .minorversion = clp->cl_mvops->minor_version,
2755 };
2756
2757 encode_compound_hdr(xdr, req, &hdr);
2758 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2759 encode_nops(&hdr);
2760}
2761
2762/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002763 * a SEQUENCE request
2764 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002765static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2766 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002767{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002768 struct compound_hdr hdr = {
2769 .minorversion = nfs4_xdr_minorversion(args),
2770 };
2771
Chuck Lever9f06c712010-12-14 14:59:18 +00002772 encode_compound_hdr(xdr, req, &hdr);
2773 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002774 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002775}
2776
2777/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002778 * a GET_LEASE_TIME request
2779 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002780static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2781 struct xdr_stream *xdr,
2782 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002783{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002784 struct compound_hdr hdr = {
2785 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2786 };
Fred Isamandae100c2011-07-30 20:52:37 -04002787 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002788
Chuck Lever9f06c712010-12-14 14:59:18 +00002789 encode_compound_hdr(xdr, req, &hdr);
2790 encode_sequence(xdr, &args->la_seq_args, &hdr);
2791 encode_putrootfh(xdr, &hdr);
2792 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002793 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002794}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002795
2796/*
2797 * a RECLAIM_COMPLETE request
2798 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002799static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2800 struct xdr_stream *xdr,
2801 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002802{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002803 struct compound_hdr hdr = {
2804 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2805 };
2806
Chuck Lever9f06c712010-12-14 14:59:18 +00002807 encode_compound_hdr(xdr, req, &hdr);
2808 encode_sequence(xdr, &args->seq_args, &hdr);
2809 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002810 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002811}
2812
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002813/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002814 * Encode GETDEVICELIST request
2815 */
2816static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2817 struct xdr_stream *xdr,
2818 struct nfs4_getdevicelist_args *args)
2819{
2820 struct compound_hdr hdr = {
2821 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2822 };
2823
2824 encode_compound_hdr(xdr, req, &hdr);
2825 encode_sequence(xdr, &args->seq_args, &hdr);
2826 encode_putfh(xdr, args->fh, &hdr);
2827 encode_getdevicelist(xdr, args, &hdr);
2828 encode_nops(&hdr);
2829}
2830
2831/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002832 * Encode GETDEVICEINFO request
2833 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002834static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2835 struct xdr_stream *xdr,
2836 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002837{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002838 struct compound_hdr hdr = {
2839 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2840 };
2841
Chuck Lever9f06c712010-12-14 14:59:18 +00002842 encode_compound_hdr(xdr, req, &hdr);
2843 encode_sequence(xdr, &args->seq_args, &hdr);
2844 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002845
2846 /* set up reply kvec. Subtract notification bitmap max size (2)
2847 * so that notification bitmap is put in xdr_buf tail */
2848 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2849 args->pdev->pages, args->pdev->pgbase,
2850 args->pdev->pglen);
2851
2852 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002853}
2854
2855/*
2856 * Encode LAYOUTGET request
2857 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002858static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2859 struct xdr_stream *xdr,
2860 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002861{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002862 struct compound_hdr hdr = {
2863 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2864 };
2865
Chuck Lever9f06c712010-12-14 14:59:18 +00002866 encode_compound_hdr(xdr, req, &hdr);
2867 encode_sequence(xdr, &args->seq_args, &hdr);
2868 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2869 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002870
2871 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2872 args->layout.pages, 0, args->layout.pglen);
2873
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002874 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002875}
Andy Adamson863a3c62011-03-23 13:27:54 +00002876
2877/*
2878 * Encode LAYOUTCOMMIT request
2879 */
Benny Halevycbe82602011-05-22 19:52:37 +03002880static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2881 struct xdr_stream *xdr,
2882 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002883{
Benny Halevyac7db722011-05-22 19:53:48 +03002884 struct nfs4_layoutcommit_data *data =
2885 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002886 struct compound_hdr hdr = {
2887 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2888 };
2889
2890 encode_compound_hdr(xdr, req, &hdr);
2891 encode_sequence(xdr, &args->seq_args, &hdr);
2892 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002893 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002894 encode_getfattr(xdr, args->bitmask, &hdr);
2895 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002896}
2897
2898/*
2899 * Encode LAYOUTRETURN request
2900 */
2901static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2902 struct xdr_stream *xdr,
2903 struct nfs4_layoutreturn_args *args)
2904{
2905 struct compound_hdr hdr = {
2906 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2907 };
2908
2909 encode_compound_hdr(xdr, req, &hdr);
2910 encode_sequence(xdr, &args->seq_args, &hdr);
2911 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2912 encode_layoutreturn(xdr, args, &hdr);
2913 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002914}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002915
2916/*
2917 * Encode SECINFO_NO_NAME request
2918 */
2919static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2920 struct xdr_stream *xdr,
2921 struct nfs41_secinfo_no_name_args *args)
2922{
2923 struct compound_hdr hdr = {
2924 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2925 };
2926
2927 encode_compound_hdr(xdr, req, &hdr);
2928 encode_sequence(xdr, &args->seq_args, &hdr);
2929 encode_putrootfh(xdr, &hdr);
2930 encode_secinfo_no_name(xdr, args, &hdr);
2931 encode_nops(&hdr);
2932 return 0;
2933}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002934
2935/*
2936 * Encode TEST_STATEID request
2937 */
2938static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2939 struct xdr_stream *xdr,
2940 struct nfs41_test_stateid_args *args)
2941{
2942 struct compound_hdr hdr = {
2943 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2944 };
2945
2946 encode_compound_hdr(xdr, req, &hdr);
2947 encode_sequence(xdr, &args->seq_args, &hdr);
2948 encode_test_stateid(xdr, args, &hdr);
2949 encode_nops(&hdr);
2950}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002951
2952/*
2953 * Encode FREE_STATEID request
2954 */
2955static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2956 struct xdr_stream *xdr,
2957 struct nfs41_free_stateid_args *args)
2958{
2959 struct compound_hdr hdr = {
2960 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2961 };
2962
2963 encode_compound_hdr(xdr, req, &hdr);
2964 encode_sequence(xdr, &args->seq_args, &hdr);
2965 encode_free_stateid(xdr, args, &hdr);
2966 encode_nops(&hdr);
2967}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002968#endif /* CONFIG_NFS_V4_1 */
2969
Benny Halevy686841b2009-08-14 17:19:48 +03002970static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2971{
2972 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2973 "Remaining buffer length is %tu words.\n",
2974 func, xdr->end - xdr->p);
2975}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976
Trond Myklebust683b57b2006-06-09 09:34:22 -04002977static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978{
Al Viro8687b632006-10-19 23:28:48 -07002979 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980
Benny Halevyc0eae662009-08-14 17:20:14 +03002981 p = xdr_inline_decode(xdr, 4);
2982 if (unlikely(!p))
2983 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002984 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002985 p = xdr_inline_decode(xdr, *len);
2986 if (unlikely(!p))
2987 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 *string = (char *)p;
2989 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002990out_overflow:
2991 print_overflow_msg(__func__, xdr);
2992 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993}
2994
2995static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2996{
Al Viro8687b632006-10-19 23:28:48 -07002997 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998
Benny Halevyc0eae662009-08-14 17:20:14 +03002999 p = xdr_inline_decode(xdr, 8);
3000 if (unlikely(!p))
3001 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003002 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003003 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003004
Benny Halevyc0eae662009-08-14 17:20:14 +03003005 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3006 if (unlikely(!p))
3007 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 hdr->tag = (char *)p;
3009 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003010 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003011 if (unlikely(hdr->nops < 1))
3012 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003014out_overflow:
3015 print_overflow_msg(__func__, xdr);
3016 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017}
3018
3019static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3020{
Al Viro8687b632006-10-19 23:28:48 -07003021 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 uint32_t opnum;
3023 int32_t nfserr;
3024
Benny Halevyc0eae662009-08-14 17:20:14 +03003025 p = xdr_inline_decode(xdr, 8);
3026 if (unlikely(!p))
3027 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003028 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003030 dprintk("nfs: Server returned operation"
3031 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 opnum, expected);
3033 return -EIO;
3034 }
Benny Halevycccddf42009-08-14 17:20:19 +03003035 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003037 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003039out_overflow:
3040 print_overflow_msg(__func__, xdr);
3041 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042}
3043
3044/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003045static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046{
Al Viro8687b632006-10-19 23:28:48 -07003047 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003048 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 char *str;
3050
Benny Halevyc0eae662009-08-14 17:20:14 +03003051 p = xdr_inline_decode(xdr, 12);
3052 if (likely(p))
3053 return decode_opaque_inline(xdr, &strlen, &str);
3054 print_overflow_msg(__func__, xdr);
3055 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056}
3057
3058static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3059{
Al Viro8687b632006-10-19 23:28:48 -07003060 uint32_t bmlen;
3061 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
Benny Halevyc0eae662009-08-14 17:20:14 +03003063 p = xdr_inline_decode(xdr, 4);
3064 if (unlikely(!p))
3065 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003066 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067
Fred Isamandae100c2011-07-30 20:52:37 -04003068 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003069 p = xdr_inline_decode(xdr, (bmlen << 2));
3070 if (unlikely(!p))
3071 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003073 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003074 if (bmlen > 1) {
3075 bitmap[1] = be32_to_cpup(p++);
3076 if (bmlen > 2)
3077 bitmap[2] = be32_to_cpup(p);
3078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 }
3080 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003081out_overflow:
3082 print_overflow_msg(__func__, xdr);
3083 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084}
3085
Trond Myklebust256e48b2012-06-21 11:18:13 -04003086static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087{
Al Viro8687b632006-10-19 23:28:48 -07003088 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089
Benny Halevyc0eae662009-08-14 17:20:14 +03003090 p = xdr_inline_decode(xdr, 4);
3091 if (unlikely(!p))
3092 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003093 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003094 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003096out_overflow:
3097 print_overflow_msg(__func__, xdr);
3098 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099}
3100
3101static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3102{
3103 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003104 int ret;
3105 ret = decode_attr_bitmap(xdr, bitmask);
3106 if (unlikely(ret < 0))
3107 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3109 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003110 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3111 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3112 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 return 0;
3114}
3115
3116static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3117{
Al Viro8687b632006-10-19 23:28:48 -07003118 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003119 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120
3121 *type = 0;
3122 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3123 return -EIO;
3124 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003125 p = xdr_inline_decode(xdr, 4);
3126 if (unlikely(!p))
3127 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003128 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003130 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 return -EIO;
3132 }
3133 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003134 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003136 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003137 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003138out_overflow:
3139 print_overflow_msg(__func__, xdr);
3140 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141}
3142
Chuck Lever264e6352012-03-01 17:02:05 -05003143static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3144 uint32_t *bitmap, uint32_t *type)
3145{
3146 __be32 *p;
3147
3148 *type = 0;
3149 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3150 return -EIO;
3151 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3152 p = xdr_inline_decode(xdr, 4);
3153 if (unlikely(!p))
3154 goto out_overflow;
3155 *type = be32_to_cpup(p);
3156 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3157 }
3158 dprintk("%s: expire type=0x%x\n", __func__, *type);
3159 return 0;
3160out_overflow:
3161 print_overflow_msg(__func__, xdr);
3162 return -EIO;
3163}
3164
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3166{
Al Viro8687b632006-10-19 23:28:48 -07003167 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003168 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
3170 *change = 0;
3171 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3172 return -EIO;
3173 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003174 p = xdr_inline_decode(xdr, 8);
3175 if (unlikely(!p))
3176 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003177 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003179 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003181 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003183 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003184out_overflow:
3185 print_overflow_msg(__func__, xdr);
3186 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187}
3188
3189static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3190{
Al Viro8687b632006-10-19 23:28:48 -07003191 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003192 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193
3194 *size = 0;
3195 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3196 return -EIO;
3197 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003198 p = xdr_inline_decode(xdr, 8);
3199 if (unlikely(!p))
3200 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003201 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003203 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003205 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003206 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003207out_overflow:
3208 print_overflow_msg(__func__, xdr);
3209 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210}
3211
3212static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3213{
Al Viro8687b632006-10-19 23:28:48 -07003214 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215
3216 *res = 0;
3217 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3218 return -EIO;
3219 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003220 p = xdr_inline_decode(xdr, 4);
3221 if (unlikely(!p))
3222 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003223 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3225 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003226 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003228out_overflow:
3229 print_overflow_msg(__func__, xdr);
3230 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231}
3232
3233static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3234{
Al Viro8687b632006-10-19 23:28:48 -07003235 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236
3237 *res = 0;
3238 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3239 return -EIO;
3240 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003241 p = xdr_inline_decode(xdr, 4);
3242 if (unlikely(!p))
3243 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003244 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3246 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003247 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003249out_overflow:
3250 print_overflow_msg(__func__, xdr);
3251 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252}
3253
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003254static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255{
Al Viro8687b632006-10-19 23:28:48 -07003256 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003257 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258
3259 fsid->major = 0;
3260 fsid->minor = 0;
3261 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3262 return -EIO;
3263 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003264 p = xdr_inline_decode(xdr, 16);
3265 if (unlikely(!p))
3266 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003267 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003268 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003270 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003272 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 (unsigned long long)fsid->major,
3274 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003275 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003276out_overflow:
3277 print_overflow_msg(__func__, xdr);
3278 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279}
3280
3281static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3282{
Al Viro8687b632006-10-19 23:28:48 -07003283 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284
3285 *res = 60;
3286 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3287 return -EIO;
3288 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003289 p = xdr_inline_decode(xdr, 4);
3290 if (unlikely(!p))
3291 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003292 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3294 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003295 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003297out_overflow:
3298 print_overflow_msg(__func__, xdr);
3299 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300}
3301
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003302static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003303{
3304 __be32 *p;
3305
3306 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3307 return -EIO;
3308 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3309 p = xdr_inline_decode(xdr, 4);
3310 if (unlikely(!p))
3311 goto out_overflow;
3312 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003313 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003314 }
3315 return 0;
3316out_overflow:
3317 print_overflow_msg(__func__, xdr);
3318 return -EIO;
3319}
3320
3321static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3322{
3323 __be32 *p;
3324 int len;
3325
Trond Myklebust7ad07352010-10-23 15:34:20 -04003326 if (fh != NULL)
3327 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003328
3329 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3330 return -EIO;
3331 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3332 p = xdr_inline_decode(xdr, 4);
3333 if (unlikely(!p))
3334 goto out_overflow;
3335 len = be32_to_cpup(p);
3336 if (len > NFS4_FHSIZE)
3337 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003338 p = xdr_inline_decode(xdr, len);
3339 if (unlikely(!p))
3340 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003341 if (fh != NULL) {
3342 memcpy(fh->data, p, len);
3343 fh->size = len;
3344 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003345 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3346 }
3347 return 0;
3348out_overflow:
3349 print_overflow_msg(__func__, xdr);
3350 return -EIO;
3351}
3352
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3354{
Al Viro8687b632006-10-19 23:28:48 -07003355 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356
3357 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3358 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3359 return -EIO;
3360 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003361 p = xdr_inline_decode(xdr, 4);
3362 if (unlikely(!p))
3363 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003364 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3366 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003367 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003369out_overflow:
3370 print_overflow_msg(__func__, xdr);
3371 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372}
3373
3374static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3375{
Al Viro8687b632006-10-19 23:28:48 -07003376 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003377 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
3379 *fileid = 0;
3380 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3381 return -EIO;
3382 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003383 p = xdr_inline_decode(xdr, 8);
3384 if (unlikely(!p))
3385 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003386 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003388 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003390 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003391 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003392out_overflow:
3393 print_overflow_msg(__func__, xdr);
3394 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395}
3396
Manoj Naik99baf622006-06-09 09:34:24 -04003397static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3398{
Al Viro8687b632006-10-19 23:28:48 -07003399 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003400 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003401
3402 *fileid = 0;
3403 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3404 return -EIO;
3405 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003406 p = xdr_inline_decode(xdr, 8);
3407 if (unlikely(!p))
3408 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003409 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003410 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003411 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003412 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003413 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003414 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003415out_overflow:
3416 print_overflow_msg(__func__, xdr);
3417 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003418}
3419
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3421{
Al Viro8687b632006-10-19 23:28:48 -07003422 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 int status = 0;
3424
3425 *res = 0;
3426 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3427 return -EIO;
3428 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003429 p = xdr_inline_decode(xdr, 8);
3430 if (unlikely(!p))
3431 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003432 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3434 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003435 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003437out_overflow:
3438 print_overflow_msg(__func__, xdr);
3439 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440}
3441
3442static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3443{
Al Viro8687b632006-10-19 23:28:48 -07003444 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 int status = 0;
3446
3447 *res = 0;
3448 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3449 return -EIO;
3450 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003451 p = xdr_inline_decode(xdr, 8);
3452 if (unlikely(!p))
3453 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003454 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3456 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003457 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003459out_overflow:
3460 print_overflow_msg(__func__, xdr);
3461 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462}
3463
3464static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3465{
Al Viro8687b632006-10-19 23:28:48 -07003466 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 int status = 0;
3468
3469 *res = 0;
3470 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3471 return -EIO;
3472 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003473 p = xdr_inline_decode(xdr, 8);
3474 if (unlikely(!p))
3475 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003476 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3478 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003479 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003481out_overflow:
3482 print_overflow_msg(__func__, xdr);
3483 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484}
3485
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003486static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3487{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003488 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003489 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003490 int status = 0;
3491
Benny Halevyc0eae662009-08-14 17:20:14 +03003492 p = xdr_inline_decode(xdr, 4);
3493 if (unlikely(!p))
3494 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003495 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003496 if (n == 0)
3497 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003498 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003499 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3500 dprintk("cannot parse %d components in path\n", n);
3501 goto out_eio;
3502 }
3503 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003504 struct nfs4_string *component = &path->components[path->ncomponents];
3505 status = decode_opaque_inline(xdr, &component->len, &component->data);
3506 if (unlikely(status != 0))
3507 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003508 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003509 pr_cont("%s%.*s ",
3510 (path->ncomponents != n ? "/ " : ""),
3511 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003512 }
3513out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003514 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003515root_path:
3516/* a root pathname is sent as a zero component4 */
3517 path->ncomponents = 1;
3518 path->components[0].len=0;
3519 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003520 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003521 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003522out_eio:
3523 dprintk(" status %d", status);
3524 status = -EIO;
3525 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003526out_overflow:
3527 print_overflow_msg(__func__, xdr);
3528 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003529}
3530
3531static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003532{
3533 int n;
Al Viro8687b632006-10-19 23:28:48 -07003534 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003535 int status = -EIO;
3536
3537 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3538 goto out;
3539 status = 0;
3540 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3541 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003542 status = -EIO;
3543 /* Ignore borken servers that return unrequested attrs */
3544 if (unlikely(res == NULL))
3545 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003546 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003547 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003548 if (unlikely(status != 0))
3549 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003550 p = xdr_inline_decode(xdr, 4);
3551 if (unlikely(!p))
3552 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003553 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003554 if (n <= 0)
3555 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003556 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003557 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003558 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003559
Trond Myklebust809b4262013-03-27 11:54:45 -04003560 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3561 break;
3562 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003563 p = xdr_inline_decode(xdr, 4);
3564 if (unlikely(!p))
3565 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003566 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003567
Chuck Lever02a29762012-03-01 17:00:31 -05003568 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003569 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3570 struct nfs4_string *server;
3571
3572 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003573 unsigned int i;
3574 dprintk("%s: using first %u of %u servers "
3575 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003576 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003577 NFS4_FS_LOCATION_MAXSERVERS,
3578 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003579 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003580 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003581 char *data;
3582 status = decode_opaque_inline(xdr, &len, &data);
3583 if (unlikely(status != 0))
3584 goto out_eio;
3585 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003586 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003587 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003588 server = &loc->servers[loc->nservers];
3589 status = decode_opaque_inline(xdr, &server->len, &server->data);
3590 if (unlikely(status != 0))
3591 goto out_eio;
3592 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003593 }
3594 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003595 if (unlikely(status != 0))
3596 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003597 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003598 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003599 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003600out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003601 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003602 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003603out_overflow:
3604 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003605out_eio:
3606 status = -EIO;
3607 goto out;
3608}
3609
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3611{
Al Viro8687b632006-10-19 23:28:48 -07003612 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 int status = 0;
3614
3615 *res = 0;
3616 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3617 return -EIO;
3618 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003619 p = xdr_inline_decode(xdr, 8);
3620 if (unlikely(!p))
3621 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003622 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3624 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003625 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003627out_overflow:
3628 print_overflow_msg(__func__, xdr);
3629 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630}
3631
3632static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3633{
Al Viro8687b632006-10-19 23:28:48 -07003634 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 int status = 0;
3636
3637 *maxlink = 1;
3638 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3639 return -EIO;
3640 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003641 p = xdr_inline_decode(xdr, 4);
3642 if (unlikely(!p))
3643 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003644 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3646 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003647 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003649out_overflow:
3650 print_overflow_msg(__func__, xdr);
3651 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652}
3653
3654static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3655{
Al Viro8687b632006-10-19 23:28:48 -07003656 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 int status = 0;
3658
3659 *maxname = 1024;
3660 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3661 return -EIO;
3662 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003663 p = xdr_inline_decode(xdr, 4);
3664 if (unlikely(!p))
3665 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003666 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3668 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003669 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003671out_overflow:
3672 print_overflow_msg(__func__, xdr);
3673 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674}
3675
3676static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3677{
Al Viro8687b632006-10-19 23:28:48 -07003678 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 int status = 0;
3680
3681 *res = 1024;
3682 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3683 return -EIO;
3684 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3685 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003686 p = xdr_inline_decode(xdr, 8);
3687 if (unlikely(!p))
3688 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003689 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 if (maxread > 0x7FFFFFFF)
3691 maxread = 0x7FFFFFFF;
3692 *res = (uint32_t)maxread;
3693 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3694 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003695 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003697out_overflow:
3698 print_overflow_msg(__func__, xdr);
3699 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700}
3701
3702static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3703{
Al Viro8687b632006-10-19 23:28:48 -07003704 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 int status = 0;
3706
3707 *res = 1024;
3708 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3709 return -EIO;
3710 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3711 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003712 p = xdr_inline_decode(xdr, 8);
3713 if (unlikely(!p))
3714 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003715 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 if (maxwrite > 0x7FFFFFFF)
3717 maxwrite = 0x7FFFFFFF;
3718 *res = (uint32_t)maxwrite;
3719 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3720 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003721 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003723out_overflow:
3724 print_overflow_msg(__func__, xdr);
3725 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726}
3727
Trond Myklebustbca79472009-03-11 14:10:26 -04003728static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729{
Trond Myklebustbca79472009-03-11 14:10:26 -04003730 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003731 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003732 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733
3734 *mode = 0;
3735 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3736 return -EIO;
3737 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003738 p = xdr_inline_decode(xdr, 4);
3739 if (unlikely(!p))
3740 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003741 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003742 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003744 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003746 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003747 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003748out_overflow:
3749 print_overflow_msg(__func__, xdr);
3750 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751}
3752
3753static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3754{
Al Viro8687b632006-10-19 23:28:48 -07003755 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003756 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757
3758 *nlink = 1;
3759 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3760 return -EIO;
3761 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003762 p = xdr_inline_decode(xdr, 4);
3763 if (unlikely(!p))
3764 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003765 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003767 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003769 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003770 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003771out_overflow:
3772 print_overflow_msg(__func__, xdr);
3773 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774}
3775
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003776static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003777 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003778 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779{
Al Viro8687b632006-10-19 23:28:48 -07003780 uint32_t len;
3781 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003782 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783
Eric W. Biedermane5782072013-02-01 14:22:02 -08003784 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3786 return -EIO;
3787 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003788 p = xdr_inline_decode(xdr, 4);
3789 if (unlikely(!p))
3790 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003791 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003792 p = xdr_inline_decode(xdr, len);
3793 if (unlikely(!p))
3794 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003795 if (owner_name != NULL) {
3796 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3797 if (owner_name->data != NULL) {
3798 owner_name->len = len;
3799 ret = NFS_ATTR_FATTR_OWNER_NAME;
3800 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003801 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003802 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003803 ret = NFS_ATTR_FATTR_OWNER;
3804 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003806 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003808 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003809 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3811 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003812 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003813 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003814out_overflow:
3815 print_overflow_msg(__func__, xdr);
3816 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817}
3818
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003819static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003820 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003821 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822{
Al Viro8687b632006-10-19 23:28:48 -07003823 uint32_t len;
3824 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003825 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826
Eric W. Biedermane5782072013-02-01 14:22:02 -08003827 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3829 return -EIO;
3830 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003831 p = xdr_inline_decode(xdr, 4);
3832 if (unlikely(!p))
3833 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003834 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003835 p = xdr_inline_decode(xdr, len);
3836 if (unlikely(!p))
3837 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003838 if (group_name != NULL) {
3839 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3840 if (group_name->data != NULL) {
3841 group_name->len = len;
3842 ret = NFS_ATTR_FATTR_GROUP_NAME;
3843 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003844 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003845 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003846 ret = NFS_ATTR_FATTR_GROUP;
3847 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003849 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003851 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003852 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3854 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003855 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003856 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003857out_overflow:
3858 print_overflow_msg(__func__, xdr);
3859 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860}
3861
3862static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3863{
Al Viro8687b632006-10-19 23:28:48 -07003864 uint32_t major = 0, minor = 0;
3865 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003866 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867
3868 *rdev = MKDEV(0,0);
3869 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3870 return -EIO;
3871 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3872 dev_t tmp;
3873
Benny Halevyc0eae662009-08-14 17:20:14 +03003874 p = xdr_inline_decode(xdr, 8);
3875 if (unlikely(!p))
3876 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003877 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003878 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 tmp = MKDEV(major, minor);
3880 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3881 *rdev = tmp;
3882 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003883 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003885 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003886 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003887out_overflow:
3888 print_overflow_msg(__func__, xdr);
3889 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890}
3891
3892static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3893{
Al Viro8687b632006-10-19 23:28:48 -07003894 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 int status = 0;
3896
3897 *res = 0;
3898 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3899 return -EIO;
3900 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003901 p = xdr_inline_decode(xdr, 8);
3902 if (unlikely(!p))
3903 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003904 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3906 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003907 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003909out_overflow:
3910 print_overflow_msg(__func__, xdr);
3911 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912}
3913
3914static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3915{
Al Viro8687b632006-10-19 23:28:48 -07003916 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917 int status = 0;
3918
3919 *res = 0;
3920 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3921 return -EIO;
3922 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003923 p = xdr_inline_decode(xdr, 8);
3924 if (unlikely(!p))
3925 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003926 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3928 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003929 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003931out_overflow:
3932 print_overflow_msg(__func__, xdr);
3933 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934}
3935
3936static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3937{
Al Viro8687b632006-10-19 23:28:48 -07003938 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 int status = 0;
3940
3941 *res = 0;
3942 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3943 return -EIO;
3944 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003945 p = xdr_inline_decode(xdr, 8);
3946 if (unlikely(!p))
3947 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003948 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3950 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003951 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003953out_overflow:
3954 print_overflow_msg(__func__, xdr);
3955 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956}
3957
3958static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3959{
Al Viro8687b632006-10-19 23:28:48 -07003960 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003961 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962
3963 *used = 0;
3964 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3965 return -EIO;
3966 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003967 p = xdr_inline_decode(xdr, 8);
3968 if (unlikely(!p))
3969 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003970 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003972 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003974 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003976 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003977out_overflow:
3978 print_overflow_msg(__func__, xdr);
3979 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980}
3981
3982static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3983{
Al Viro8687b632006-10-19 23:28:48 -07003984 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 uint64_t sec;
3986 uint32_t nsec;
3987
Benny Halevyc0eae662009-08-14 17:20:14 +03003988 p = xdr_inline_decode(xdr, 12);
3989 if (unlikely(!p))
3990 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003991 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003992 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 time->tv_sec = (time_t)sec;
3994 time->tv_nsec = (long)nsec;
3995 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003996out_overflow:
3997 print_overflow_msg(__func__, xdr);
3998 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999}
4000
4001static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4002{
4003 int status = 0;
4004
4005 time->tv_sec = 0;
4006 time->tv_nsec = 0;
4007 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4008 return -EIO;
4009 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4010 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004011 if (status == 0)
4012 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4014 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004015 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 return status;
4017}
4018
4019static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4020{
4021 int status = 0;
4022
4023 time->tv_sec = 0;
4024 time->tv_nsec = 0;
4025 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4026 return -EIO;
4027 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4028 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004029 if (status == 0)
4030 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4032 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004033 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 return status;
4035}
4036
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004037static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4038 struct timespec *time)
4039{
4040 int status = 0;
4041
4042 time->tv_sec = 0;
4043 time->tv_nsec = 0;
4044 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4045 return -EIO;
4046 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4047 status = decode_attr_time(xdr, time);
4048 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4049 }
4050 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4051 (long)time->tv_nsec);
4052 return status;
4053}
4054
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4056{
4057 int status = 0;
4058
4059 time->tv_sec = 0;
4060 time->tv_nsec = 0;
4061 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4062 return -EIO;
4063 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4064 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004065 if (status == 0)
4066 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4068 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004069 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 return status;
4071}
4072
Trond Myklebust256e48b2012-06-21 11:18:13 -04004073static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074{
4075 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004076 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077
4078 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004079 dprintk("%s: server returned incorrect attribute length: "
4080 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004081 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 attrwords << 2,
4083 (attrwords < nwords) ? '<' : '>',
4084 nwords << 2);
4085 return -EIO;
4086 }
4087 return 0;
4088}
4089
4090static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4091{
Al Viro8687b632006-10-19 23:28:48 -07004092 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093
Benny Halevyc0eae662009-08-14 17:20:14 +03004094 p = xdr_inline_decode(xdr, 20);
4095 if (unlikely(!p))
4096 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004097 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004098 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004099 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004101out_overflow:
4102 print_overflow_msg(__func__, xdr);
4103 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104}
4105
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004106static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107{
Al Viro8687b632006-10-19 23:28:48 -07004108 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 uint32_t supp, acc;
4110 int status;
4111
4112 status = decode_op_hdr(xdr, OP_ACCESS);
4113 if (status)
4114 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004115 p = xdr_inline_decode(xdr, 8);
4116 if (unlikely(!p))
4117 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004118 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004119 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004120 *supported = supp;
4121 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004123out_overflow:
4124 print_overflow_msg(__func__, xdr);
4125 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126}
4127
Benny Halevy07d30432009-08-14 17:19:52 +03004128static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129{
Al Viro8687b632006-10-19 23:28:48 -07004130 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004131
4132 p = xdr_inline_decode(xdr, len);
4133 if (likely(p)) {
4134 memcpy(buf, p, len);
4135 return 0;
4136 }
4137 print_overflow_msg(__func__, xdr);
4138 return -EIO;
4139}
4140
4141static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4142{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004143 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144}
4145
4146static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4147{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148 int status;
4149
4150 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004151 if (status != -EIO)
4152 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004153 if (!status)
4154 status = decode_stateid(xdr, &res->stateid);
4155 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156}
4157
Benny Halevydb942bb2009-08-14 17:19:56 +03004158static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4159{
Chuck Levercd937102012-03-02 17:14:31 -05004160 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161}
4162
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004163static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4164{
4165 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4166}
4167
Fred Isaman0b7c0152012-04-20 14:47:39 -04004168static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 int status;
4171
4172 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004173 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004174 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004175 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176}
4177
4178static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4179{
Al Viro8687b632006-10-19 23:28:48 -07004180 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181 uint32_t bmlen;
4182 int status;
4183
4184 status = decode_op_hdr(xdr, OP_CREATE);
4185 if (status)
4186 return status;
4187 if ((status = decode_change_info(xdr, cinfo)))
4188 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004189 p = xdr_inline_decode(xdr, 4);
4190 if (unlikely(!p))
4191 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004192 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004193 p = xdr_inline_decode(xdr, bmlen << 2);
4194 if (likely(p))
4195 return 0;
4196out_overflow:
4197 print_overflow_msg(__func__, xdr);
4198 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199}
4200
4201static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4202{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004203 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004204 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 int status;
4206
4207 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4208 goto xdr_error;
4209 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4210 goto xdr_error;
4211 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4212 goto xdr_error;
4213 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4214 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004215 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4216 &res->fh_expire_type)) != 0)
4217 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4219 goto xdr_error;
4220 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4221 goto xdr_error;
4222 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4223 goto xdr_error;
4224 status = verify_attr_len(xdr, savep, attrlen);
4225xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004226 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227 return status;
4228}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004229
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4231{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004232 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004233 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004235
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4237 goto xdr_error;
4238 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4239 goto xdr_error;
4240 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4241 goto xdr_error;
4242
4243 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4244 goto xdr_error;
4245 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4246 goto xdr_error;
4247 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4248 goto xdr_error;
4249 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4250 goto xdr_error;
4251 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4252 goto xdr_error;
4253 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4254 goto xdr_error;
4255
4256 status = verify_attr_len(xdr, savep, attrlen);
4257xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004258 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259 return status;
4260}
4261
4262static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4263{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004264 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004265 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004266 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004267
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4269 goto xdr_error;
4270 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4271 goto xdr_error;
4272 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4273 goto xdr_error;
4274
4275 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4276 goto xdr_error;
4277 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4278 goto xdr_error;
4279
4280 status = verify_attr_len(xdr, savep, attrlen);
4281xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004282 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 return status;
4284}
4285
Andy Adamson88034c32012-05-23 05:02:34 -04004286static int decode_threshold_hint(struct xdr_stream *xdr,
4287 uint32_t *bitmap,
4288 uint64_t *res,
4289 uint32_t hint_bit)
4290{
4291 __be32 *p;
4292
4293 *res = 0;
4294 if (likely(bitmap[0] & hint_bit)) {
4295 p = xdr_inline_decode(xdr, 8);
4296 if (unlikely(!p))
4297 goto out_overflow;
4298 xdr_decode_hyper(p, res);
4299 }
4300 return 0;
4301out_overflow:
4302 print_overflow_msg(__func__, xdr);
4303 return -EIO;
4304}
4305
4306static int decode_first_threshold_item4(struct xdr_stream *xdr,
4307 struct nfs4_threshold *res)
4308{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004309 __be32 *p;
4310 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004311 uint32_t bitmap[3] = {0,}, attrlen;
4312 int status;
4313
4314 /* layout type */
4315 p = xdr_inline_decode(xdr, 4);
4316 if (unlikely(!p)) {
4317 print_overflow_msg(__func__, xdr);
4318 return -EIO;
4319 }
4320 res->l_type = be32_to_cpup(p);
4321
4322 /* thi_hintset bitmap */
4323 status = decode_attr_bitmap(xdr, bitmap);
4324 if (status < 0)
4325 goto xdr_error;
4326
4327 /* thi_hintlist length */
4328 status = decode_attr_length(xdr, &attrlen, &savep);
4329 if (status < 0)
4330 goto xdr_error;
4331 /* thi_hintlist */
4332 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4333 if (status < 0)
4334 goto xdr_error;
4335 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4336 if (status < 0)
4337 goto xdr_error;
4338 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4339 THRESHOLD_RD_IO);
4340 if (status < 0)
4341 goto xdr_error;
4342 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4343 THRESHOLD_WR_IO);
4344 if (status < 0)
4345 goto xdr_error;
4346
4347 status = verify_attr_len(xdr, savep, attrlen);
4348 res->bm = bitmap[0];
4349
4350 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4351 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4352 res->wr_io_sz);
4353xdr_error:
4354 dprintk("%s ret=%d!\n", __func__, status);
4355 return status;
4356}
4357
4358/*
4359 * Thresholds on pNFS direct I/O vrs MDS I/O
4360 */
4361static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4362 uint32_t *bitmap,
4363 struct nfs4_threshold *res)
4364{
4365 __be32 *p;
4366 int status = 0;
4367 uint32_t num;
4368
4369 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4370 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004371 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004372 /* Did the server return an unrequested attribute? */
4373 if (unlikely(res == NULL))
4374 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004375 p = xdr_inline_decode(xdr, 4);
4376 if (unlikely(!p))
4377 goto out_overflow;
4378 num = be32_to_cpup(p);
4379 if (num == 0)
4380 return 0;
4381 if (num > 1)
4382 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4383 "drivers per filesystem not supported\n",
4384 __func__);
4385
4386 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004387 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004388 }
4389 return status;
4390out_overflow:
4391 print_overflow_msg(__func__, xdr);
4392 return -EIO;
4393}
4394
Bryan Schumakerae42c702010-10-21 16:33:17 -04004395static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4396 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004397 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004398 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399{
Trond Myklebustbca79472009-03-11 14:10:26 -04004400 int status;
4401 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004402 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004403 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004405 status = decode_attr_type(xdr, bitmap, &type);
4406 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004408 fattr->mode = 0;
4409 if (status != 0) {
4410 fattr->mode |= nfs_type2fmt[type];
4411 fattr->valid |= status;
4412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004414 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
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
4419 status = decode_attr_size(xdr, bitmap, &fattr->size);
4420 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004422 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004423
4424 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4425 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004427 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004428
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004429 err = 0;
4430 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004431 if (status < 0)
4432 goto xdr_error;
4433
4434 status = decode_attr_filehandle(xdr, bitmap, fh);
4435 if (status < 0)
4436 goto xdr_error;
4437
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004438 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4439 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004441 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004442
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004443 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004444 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004445 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004446 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004447
4448 status = decode_attr_mode(xdr, bitmap, &fmode);
4449 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004451 if (status != 0) {
4452 fattr->mode |= fmode;
4453 fattr->valid |= status;
4454 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004455
4456 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4457 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
Trond Myklebust6926afd2012-01-07 13:22:46 -05004461 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004462 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
Trond Myklebust6926afd2012-01-07 13:22:46 -05004466 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004467 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_rdev(xdr, bitmap, &fattr->rdev);
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_space_used(xdr, bitmap, &fattr->du.nfs3.used);
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_access(xdr, bitmap, &fattr->atime);
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
4486 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4487 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004489 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004490
4491 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4492 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004494 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004495
Trond Myklebust28331a42011-04-27 13:47:52 -04004496 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004497 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004498 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004499 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004500
Andy Adamson88034c32012-05-23 05:02:34 -04004501 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4502 if (status < 0)
4503 goto xdr_error;
4504
Bryan Schumakerae42c702010-10-21 16:33:17 -04004505xdr_error:
4506 dprintk("%s: xdr returned %d\n", __func__, -status);
4507 return status;
4508}
4509
4510static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004511 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4512 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004513{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004514 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004515 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004516 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004517 int status;
4518
4519 status = decode_op_hdr(xdr, OP_GETATTR);
4520 if (status < 0)
4521 goto xdr_error;
4522
4523 status = decode_attr_bitmap(xdr, bitmap);
4524 if (status < 0)
4525 goto xdr_error;
4526
4527 status = decode_attr_length(xdr, &attrlen, &savep);
4528 if (status < 0)
4529 goto xdr_error;
4530
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004531 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004532 if (status < 0)
4533 goto xdr_error;
4534
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004535 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004537 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 return status;
4539}
4540
Bryan Schumakerae42c702010-10-21 16:33:17 -04004541static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004542 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004543{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004544 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004545}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004546
Andy Adamson504913f2010-10-20 00:17:57 -04004547/*
4548 * Decode potentially multiple layout types. Currently we only support
4549 * one layout driver per file system.
4550 */
4551static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4552 uint32_t *layouttype)
4553{
4554 uint32_t *p;
4555 int num;
4556
4557 p = xdr_inline_decode(xdr, 4);
4558 if (unlikely(!p))
4559 goto out_overflow;
4560 num = be32_to_cpup(p);
4561
4562 /* pNFS is not supported by the underlying file system */
4563 if (num == 0) {
4564 *layouttype = 0;
4565 return 0;
4566 }
4567 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004568 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4569 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004570
4571 /* Decode and set first layout type, move xdr->p past unused types */
4572 p = xdr_inline_decode(xdr, num * 4);
4573 if (unlikely(!p))
4574 goto out_overflow;
4575 *layouttype = be32_to_cpup(p);
4576 return 0;
4577out_overflow:
4578 print_overflow_msg(__func__, xdr);
4579 return -EIO;
4580}
4581
4582/*
4583 * The type of file system exported.
4584 * Note we must ensure that layouttype is set in any non-error case.
4585 */
4586static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4587 uint32_t *layouttype)
4588{
4589 int status = 0;
4590
4591 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4592 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4593 return -EIO;
4594 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4595 status = decode_first_pnfs_layout_type(xdr, layouttype);
4596 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4597 } else
4598 *layouttype = 0;
4599 return status;
4600}
4601
Fred Isamandae100c2011-07-30 20:52:37 -04004602/*
4603 * The prefered block size for layout directed io
4604 */
4605static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4606 uint32_t *res)
4607{
4608 __be32 *p;
4609
4610 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4611 *res = 0;
4612 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4613 p = xdr_inline_decode(xdr, 4);
4614 if (unlikely(!p)) {
4615 print_overflow_msg(__func__, xdr);
4616 return -EIO;
4617 }
4618 *res = be32_to_cpup(p);
4619 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4620 }
4621 return 0;
4622}
4623
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4625{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004626 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004627 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 int status;
4629
4630 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4631 goto xdr_error;
4632 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4633 goto xdr_error;
4634 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4635 goto xdr_error;
4636
4637 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4638
4639 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4640 goto xdr_error;
4641 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4642 goto xdr_error;
4643 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4644 goto xdr_error;
4645 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4646 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4647 goto xdr_error;
4648 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004649 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4650 if (status != 0)
4651 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004652 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4653 if (status != 0)
4654 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004655 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4656 if (status)
4657 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658
4659 status = verify_attr_len(xdr, savep, attrlen);
4660xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004661 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 return status;
4663}
4664
4665static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4666{
Al Viro8687b632006-10-19 23:28:48 -07004667 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668 uint32_t len;
4669 int status;
4670
Trond Myklebust99367812007-07-17 21:52:41 -04004671 /* Zero handle first to allow comparisons */
4672 memset(fh, 0, sizeof(*fh));
4673
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 status = decode_op_hdr(xdr, OP_GETFH);
4675 if (status)
4676 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004677
Benny Halevyc0eae662009-08-14 17:20:14 +03004678 p = xdr_inline_decode(xdr, 4);
4679 if (unlikely(!p))
4680 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004681 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682 if (len > NFS4_FHSIZE)
4683 return -EIO;
4684 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004685 p = xdr_inline_decode(xdr, len);
4686 if (unlikely(!p))
4687 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004688 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004690out_overflow:
4691 print_overflow_msg(__func__, xdr);
4692 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693}
4694
4695static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4696{
4697 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004698
Linus Torvalds1da177e2005-04-16 15:20:36 -07004699 status = decode_op_hdr(xdr, OP_LINK);
4700 if (status)
4701 return status;
4702 return decode_change_info(xdr, cinfo);
4703}
4704
4705/*
4706 * We create the owner, so we know a proper owner.id length is 4.
4707 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004708static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004710 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004711 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004712 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004714 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004715 if (unlikely(!p))
4716 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004717 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004718 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004719 type = be32_to_cpup(p++); /* 4 byte read */
4720 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004721 fl->fl_start = (loff_t)offset;
4722 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4723 if (length == ~(uint64_t)0)
4724 fl->fl_end = OFFSET_MAX;
4725 fl->fl_type = F_WRLCK;
4726 if (type & 1)
4727 fl->fl_type = F_RDLCK;
4728 fl->fl_pid = 0;
4729 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004730 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4731 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4732 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004733 if (likely(p))
4734 return -NFS4ERR_DENIED;
4735out_overflow:
4736 print_overflow_msg(__func__, xdr);
4737 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004738}
4739
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004740static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742 int status;
4743
4744 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004745 if (status == -EIO)
4746 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004748 status = decode_stateid(xdr, &res->stateid);
4749 if (unlikely(status))
4750 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004752 status = decode_lock_denied(xdr, NULL);
4753 if (res->open_seqid != NULL)
4754 nfs_increment_open_seqid(status, res->open_seqid);
4755 nfs_increment_lock_seqid(status, res->lock_seqid);
4756out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757 return status;
4758}
4759
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004760static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004761{
4762 int status;
4763 status = decode_op_hdr(xdr, OP_LOCKT);
4764 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004765 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 return status;
4767}
4768
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004769static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771 int status;
4772
4773 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004774 if (status != -EIO)
4775 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004776 if (status == 0)
4777 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 return status;
4779}
4780
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004781static int decode_release_lockowner(struct xdr_stream *xdr)
4782{
4783 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4784}
4785
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786static int decode_lookup(struct xdr_stream *xdr)
4787{
4788 return decode_op_hdr(xdr, OP_LOOKUP);
4789}
4790
4791/* This is too sick! */
4792static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4793{
Andy Adamson05d564f2008-12-23 16:06:15 -05004794 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 uint32_t limit_type, nblocks, blocksize;
4796
Benny Halevyc0eae662009-08-14 17:20:14 +03004797 p = xdr_inline_decode(xdr, 12);
4798 if (unlikely(!p))
4799 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004800 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004802 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004803 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004804 break;
4805 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004806 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004807 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004808 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809 }
4810 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004811out_overflow:
4812 print_overflow_msg(__func__, xdr);
4813 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814}
4815
4816static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4817{
Andy Adamson05d564f2008-12-23 16:06:15 -05004818 __be32 *p;
4819 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004820 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821
Benny Halevyc0eae662009-08-14 17:20:14 +03004822 p = xdr_inline_decode(xdr, 4);
4823 if (unlikely(!p))
4824 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004825 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4827 res->delegation_type = 0;
4828 return 0;
4829 }
Benny Halevy07d30432009-08-14 17:19:52 +03004830 status = decode_stateid(xdr, &res->delegation);
4831 if (unlikely(status))
4832 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004833 p = xdr_inline_decode(xdr, 4);
4834 if (unlikely(!p))
4835 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004836 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004837
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004839 case NFS4_OPEN_DELEGATE_READ:
4840 res->delegation_type = FMODE_READ;
4841 break;
4842 case NFS4_OPEN_DELEGATE_WRITE:
4843 res->delegation_type = FMODE_WRITE|FMODE_READ;
4844 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845 return -EIO;
4846 }
David Howells7539bba2006-08-22 20:06:09 -04004847 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004848out_overflow:
4849 print_overflow_msg(__func__, xdr);
4850 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851}
4852
4853static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4854{
Andy Adamson05d564f2008-12-23 16:06:15 -05004855 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004856 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004857 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858
Andy Adamson05d564f2008-12-23 16:06:15 -05004859 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004860 if (status != -EIO)
4861 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004862 if (!status)
4863 status = decode_stateid(xdr, &res->stateid);
4864 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004865 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866
Andy Adamson05d564f2008-12-23 16:06:15 -05004867 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868
Benny Halevyc0eae662009-08-14 17:20:14 +03004869 p = xdr_inline_decode(xdr, 8);
4870 if (unlikely(!p))
4871 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004872 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004873 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004874 if (bmlen > 10)
4875 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876
Benny Halevyc0eae662009-08-14 17:20:14 +03004877 p = xdr_inline_decode(xdr, bmlen << 2);
4878 if (unlikely(!p))
4879 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004880 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4881 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004882 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004883 for (; i < NFS4_BITMAP_SIZE; i++)
4884 res->attrset[i] = 0;
4885
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886 return decode_delegation(xdr, res);
4887xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004888 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004889 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004890out_overflow:
4891 print_overflow_msg(__func__, xdr);
4892 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893}
4894
4895static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4896{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897 int status;
4898
Andy Adamson05d564f2008-12-23 16:06:15 -05004899 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004900 if (status != -EIO)
4901 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004902 if (!status)
4903 status = decode_stateid(xdr, &res->stateid);
4904 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905}
4906
4907static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4908{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004909 int status;
4910
4911 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004912 if (status != -EIO)
4913 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004914 if (!status)
4915 status = decode_stateid(xdr, &res->stateid);
4916 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917}
4918
4919static int decode_putfh(struct xdr_stream *xdr)
4920{
4921 return decode_op_hdr(xdr, OP_PUTFH);
4922}
4923
4924static int decode_putrootfh(struct xdr_stream *xdr)
4925{
4926 return decode_op_hdr(xdr, OP_PUTROOTFH);
4927}
4928
4929static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4930{
Al Viro8687b632006-10-19 23:28:48 -07004931 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04004932 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004933 int status;
4934
4935 status = decode_op_hdr(xdr, OP_READ);
4936 if (status)
4937 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004938 p = xdr_inline_decode(xdr, 8);
4939 if (unlikely(!p))
4940 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004941 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004942 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04004943 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004945 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004946 "count %u > recvd %u\n", count, recvd);
4947 count = recvd;
4948 eof = 0;
4949 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950 res->eof = eof;
4951 res->count = count;
4952 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004953out_overflow:
4954 print_overflow_msg(__func__, xdr);
4955 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004956}
4957
4958static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4959{
Chuck Leverbcecff72007-10-26 13:32:03 -04004960 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004961 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962
4963 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004964 if (!status)
4965 status = decode_verifier(xdr, readdir->verifier.data);
4966 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004968 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004969 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004970 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04004971 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972}
4973
4974static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4975{
4976 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04004977 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004978 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 int status;
4980
4981 status = decode_op_hdr(xdr, OP_READLINK);
4982 if (status)
4983 return status;
4984
4985 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004986 p = xdr_inline_decode(xdr, 4);
4987 if (unlikely(!p))
4988 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004989 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004991 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992 return -ENAMETOOLONG;
4993 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04004994 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004996 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997 "count %u > recvd %u\n", len, recvd);
4998 return -EIO;
4999 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000 /*
5001 * The XDR encode routine has set things up so that
5002 * the link text will be copied directly into the
5003 * buffer. We just have to do overflow-checking,
5004 * and and null-terminate the text (the VFS expects
5005 * null-termination).
5006 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005007 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005009out_overflow:
5010 print_overflow_msg(__func__, xdr);
5011 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012}
5013
5014static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5015{
5016 int status;
5017
5018 status = decode_op_hdr(xdr, OP_REMOVE);
5019 if (status)
5020 goto out;
5021 status = decode_change_info(xdr, cinfo);
5022out:
5023 return status;
5024}
5025
5026static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5027 struct nfs4_change_info *new_cinfo)
5028{
5029 int status;
5030
5031 status = decode_op_hdr(xdr, OP_RENAME);
5032 if (status)
5033 goto out;
5034 if ((status = decode_change_info(xdr, old_cinfo)))
5035 goto out;
5036 status = decode_change_info(xdr, new_cinfo);
5037out:
5038 return status;
5039}
5040
5041static int decode_renew(struct xdr_stream *xdr)
5042{
5043 return decode_op_hdr(xdr, OP_RENEW);
5044}
5045
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005046static int
5047decode_restorefh(struct xdr_stream *xdr)
5048{
5049 return decode_op_hdr(xdr, OP_RESTOREFH);
5050}
5051
J. Bruce Fields029d1052005-06-22 17:16:22 +00005052static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005053 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005054{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005055 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005056 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005057 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005058 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005059 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005060
Andy Adamsonbf118a32011-12-07 11:55:27 -05005061 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005062 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5063 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005064
Trond Myklebust519d3952012-08-14 17:30:10 -04005065 xdr_enter_page(xdr, xdr->buf->page_len);
5066
Trond Myklebustcff298c2012-08-14 17:14:17 -04005067 /* Calculate the offset of the page data */
5068 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005069
J. Bruce Fields029d1052005-06-22 17:16:22 +00005070 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5071 goto out;
5072 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5073 goto out;
5074
5075 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5076 return -EIO;
5077 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005078
Andy Adamsonbf118a32011-12-07 11:55:27 -05005079 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5080 * are stored with the acl data to handle the problem of
5081 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005082 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005083 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005084
5085 /* Check for receive buffer overflow */
5086 if (res->acl_len > (xdr->nwords << 2) ||
5087 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5088 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005089 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005090 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005091 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005092 } else
5093 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005094
5095out:
5096 return status;
5097}
5098
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099static int
5100decode_savefh(struct xdr_stream *xdr)
5101{
5102 return decode_op_hdr(xdr, OP_SAVEFH);
5103}
5104
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005105static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106{
Al Viro8687b632006-10-19 23:28:48 -07005107 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005108 uint32_t bmlen;
5109 int status;
5110
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111 status = decode_op_hdr(xdr, OP_SETATTR);
5112 if (status)
5113 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005114 p = xdr_inline_decode(xdr, 4);
5115 if (unlikely(!p))
5116 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005117 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005118 p = xdr_inline_decode(xdr, bmlen << 2);
5119 if (likely(p))
5120 return 0;
5121out_overflow:
5122 print_overflow_msg(__func__, xdr);
5123 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124}
5125
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005126static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127{
Al Viro8687b632006-10-19 23:28:48 -07005128 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129 uint32_t opnum;
5130 int32_t nfserr;
5131
Benny Halevyc0eae662009-08-14 17:20:14 +03005132 p = xdr_inline_decode(xdr, 8);
5133 if (unlikely(!p))
5134 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005135 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005137 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005138 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139 return -EIO;
5140 }
Benny Halevycccddf42009-08-14 17:20:19 +03005141 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005143 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5144 if (unlikely(!p))
5145 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005146 p = xdr_decode_hyper(p, &res->clientid);
5147 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148 } else if (nfserr == NFSERR_CLID_INUSE) {
5149 uint32_t len;
5150
5151 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005152 p = xdr_inline_decode(xdr, 4);
5153 if (unlikely(!p))
5154 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005155 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005156 p = xdr_inline_decode(xdr, len);
5157 if (unlikely(!p))
5158 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159
5160 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005161 p = xdr_inline_decode(xdr, 4);
5162 if (unlikely(!p))
5163 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005164 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005165 p = xdr_inline_decode(xdr, len);
5166 if (unlikely(!p))
5167 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168 return -NFSERR_CLID_INUSE;
5169 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005170 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171
5172 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005173out_overflow:
5174 print_overflow_msg(__func__, xdr);
5175 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005176}
5177
5178static int decode_setclientid_confirm(struct xdr_stream *xdr)
5179{
5180 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5181}
5182
5183static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5184{
Al Viro8687b632006-10-19 23:28:48 -07005185 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186 int status;
5187
5188 status = decode_op_hdr(xdr, OP_WRITE);
5189 if (status)
5190 return status;
5191
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005192 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005193 if (unlikely(!p))
5194 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005195 res->count = be32_to_cpup(p++);
5196 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005197 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005198out_overflow:
5199 print_overflow_msg(__func__, xdr);
5200 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005201}
5202
5203static int decode_delegreturn(struct xdr_stream *xdr)
5204{
5205 return decode_op_hdr(xdr, OP_DELEGRETURN);
5206}
5207
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005208static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5209{
5210 __be32 *p;
5211
5212 p = xdr_inline_decode(xdr, 4);
5213 if (unlikely(!p))
5214 goto out_overflow;
5215 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5216 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5217 goto out_err;
5218
5219 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5220 if (unlikely(!p))
5221 goto out_overflow;
5222 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5223
5224 p = xdr_inline_decode(xdr, 8);
5225 if (unlikely(!p))
5226 goto out_overflow;
5227 flavor->gss.qop4 = be32_to_cpup(p++);
5228 flavor->gss.service = be32_to_cpup(p);
5229
5230 return 0;
5231
5232out_overflow:
5233 print_overflow_msg(__func__, xdr);
5234 return -EIO;
5235out_err:
5236 return -EINVAL;
5237}
5238
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005239static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005240{
5241 struct nfs4_secinfo_flavor *sec_flavor;
5242 int status;
5243 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005244 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005245
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005246 p = xdr_inline_decode(xdr, 4);
5247 if (unlikely(!p))
5248 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005249
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005250 res->flavors->num_flavors = 0;
5251 num_flavors = be32_to_cpup(p);
5252
5253 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005254 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005255 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005256 break;
5257
5258 p = xdr_inline_decode(xdr, 4);
5259 if (unlikely(!p))
5260 goto out_overflow;
5261 sec_flavor->flavor = be32_to_cpup(p);
5262
5263 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005264 status = decode_secinfo_gss(xdr, sec_flavor);
5265 if (status)
5266 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005267 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005268 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005269 }
5270
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005271 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005272out:
5273 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005274out_overflow:
5275 print_overflow_msg(__func__, xdr);
5276 return -EIO;
5277}
5278
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005279static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5280{
5281 int status = decode_op_hdr(xdr, OP_SECINFO);
5282 if (status)
5283 return status;
5284 return decode_secinfo_common(xdr, res);
5285}
5286
Benny Halevy99fe60d2009-04-01 09:22:29 -04005287#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005288static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5289{
5290 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5291 if (status)
5292 return status;
5293 return decode_secinfo_common(xdr, res);
5294}
5295
Benny Halevy99fe60d2009-04-01 09:22:29 -04005296static int decode_exchange_id(struct xdr_stream *xdr,
5297 struct nfs41_exchange_id_res *res)
5298{
5299 __be32 *p;
5300 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005301 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005302 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005303 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005304
5305 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5306 if (status)
5307 return status;
5308
Benny Halevyc0eae662009-08-14 17:20:14 +03005309 p = xdr_inline_decode(xdr, 8);
5310 if (unlikely(!p))
5311 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005312 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005313 p = xdr_inline_decode(xdr, 12);
5314 if (unlikely(!p))
5315 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005316 res->seqid = be32_to_cpup(p++);
5317 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005318
5319 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005320 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005321 if (dummy != SP4_NONE)
5322 return -EIO;
5323
Chuck Leveracdeb692012-05-21 22:46:16 -04005324 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005325 p = xdr_inline_decode(xdr, 8);
5326 if (unlikely(!p))
5327 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005328 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005329
Chuck Leveracdeb692012-05-21 22:46:16 -04005330 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005331 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5332 if (unlikely(status))
5333 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005334 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5335 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005336 memcpy(res->server_owner->major_id, dummy_str, dummy);
5337 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005338
Chuck Leveracdeb692012-05-21 22:46:16 -04005339 /* server_scope4 */
5340 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5341 if (unlikely(status))
5342 return status;
5343 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5344 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005345 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5346 res->server_scope->server_scope_sz = dummy;
5347
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005348 /* Implementation Id */
5349 p = xdr_inline_decode(xdr, 4);
5350 if (unlikely(!p))
5351 goto out_overflow;
5352 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005353
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005354 if (impl_id_count) {
5355 /* nii_domain */
5356 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5357 if (unlikely(status))
5358 return status;
5359 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5360 return -EIO;
5361 memcpy(res->impl_id->domain, dummy_str, dummy);
5362
5363 /* nii_name */
5364 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5365 if (unlikely(status))
5366 return status;
5367 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5368 return -EIO;
5369 memcpy(res->impl_id->name, dummy_str, dummy);
5370
5371 /* nii_date */
5372 p = xdr_inline_decode(xdr, 12);
5373 if (unlikely(!p))
5374 goto out_overflow;
5375 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5376 res->impl_id->date.nseconds = be32_to_cpup(p);
5377
5378 /* if there's more than one entry, ignore the rest */
5379 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005380 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005381out_overflow:
5382 print_overflow_msg(__func__, xdr);
5383 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005384}
Andy Adamsonfc931582009-04-01 09:22:31 -04005385
5386static int decode_chan_attrs(struct xdr_stream *xdr,
5387 struct nfs4_channel_attrs *attrs)
5388{
5389 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005390 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005391
Benny Halevyc0eae662009-08-14 17:20:14 +03005392 p = xdr_inline_decode(xdr, 28);
5393 if (unlikely(!p))
5394 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005395 val = be32_to_cpup(p++); /* headerpadsz */
5396 if (val)
5397 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005398 attrs->max_rqst_sz = be32_to_cpup(p++);
5399 attrs->max_resp_sz = be32_to_cpup(p++);
5400 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5401 attrs->max_ops = be32_to_cpup(p++);
5402 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005403 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005404 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005405 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5406 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005407 return -EINVAL;
5408 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005409 if (nr_attrs == 1) {
5410 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5411 if (unlikely(!p))
5412 goto out_overflow;
5413 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005414 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005415out_overflow:
5416 print_overflow_msg(__func__, xdr);
5417 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005418}
5419
Benny Halevye78291e2009-08-14 17:20:00 +03005420static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5421{
5422 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005423}
5424
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005425static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5426 struct nfs41_bind_conn_to_session_res *res)
5427{
5428 __be32 *p;
5429 int status;
5430
5431 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5432 if (!status)
5433 status = decode_sessionid(xdr, &res->session->sess_id);
5434 if (unlikely(status))
5435 return status;
5436
5437 /* dir flags, rdma mode bool */
5438 p = xdr_inline_decode(xdr, 8);
5439 if (unlikely(!p))
5440 goto out_overflow;
5441
5442 res->dir = be32_to_cpup(p++);
5443 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5444 return -EIO;
5445 if (be32_to_cpup(p) == 0)
5446 res->use_conn_in_rdma_mode = false;
5447 else
5448 res->use_conn_in_rdma_mode = true;
5449
5450 return 0;
5451out_overflow:
5452 print_overflow_msg(__func__, xdr);
5453 return -EIO;
5454}
5455
Andy Adamsonfc931582009-04-01 09:22:31 -04005456static int decode_create_session(struct xdr_stream *xdr,
5457 struct nfs41_create_session_res *res)
5458{
5459 __be32 *p;
5460 int status;
5461 struct nfs_client *clp = res->client;
5462 struct nfs4_session *session = clp->cl_session;
5463
5464 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005465 if (!status)
5466 status = decode_sessionid(xdr, &session->sess_id);
5467 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005468 return status;
5469
Andy Adamsonfc931582009-04-01 09:22:31 -04005470 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005471 p = xdr_inline_decode(xdr, 8);
5472 if (unlikely(!p))
5473 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005474 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005475 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005476
5477 /* Channel attributes */
5478 status = decode_chan_attrs(xdr, &session->fc_attrs);
5479 if (!status)
5480 status = decode_chan_attrs(xdr, &session->bc_attrs);
5481 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005482out_overflow:
5483 print_overflow_msg(__func__, xdr);
5484 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005485}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005486
5487static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5488{
5489 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5490}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005491
Trond Myklebust66245532012-05-25 17:18:09 -04005492static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5493{
5494 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5495}
5496
Ricardo Labiaga180197532009-12-05 16:08:40 -05005497static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5498{
5499 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5500}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005501#endif /* CONFIG_NFS_V4_1 */
5502
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005503static int decode_sequence(struct xdr_stream *xdr,
5504 struct nfs4_sequence_res *res,
5505 struct rpc_rqst *rqstp)
5506{
5507#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005508 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005509 struct nfs4_sessionid id;
5510 u32 dummy;
5511 int status;
5512 __be32 *p;
5513
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005514 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005515 return 0;
5516
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005517 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005518 if (!status)
5519 status = decode_sessionid(xdr, &id);
5520 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005521 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005522
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005523 /*
5524 * If the server returns different values for sessionID, slotID or
5525 * sequence number, the server is looney tunes.
5526 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005527 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005528 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005529
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005530 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005531 NFS4_MAX_SESSIONID_LEN)) {
5532 dprintk("%s Invalid session id\n", __func__);
5533 goto out_err;
5534 }
Benny Halevye78291e2009-08-14 17:20:00 +03005535
Benny Halevyc0eae662009-08-14 17:20:14 +03005536 p = xdr_inline_decode(xdr, 20);
5537 if (unlikely(!p))
5538 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005539
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005540 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005541 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005542 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005543 dprintk("%s Invalid sequence number\n", __func__);
5544 goto out_err;
5545 }
5546 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005547 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005548 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005549 dprintk("%s Invalid slot id\n", __func__);
5550 goto out_err;
5551 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005552 /* highest slot id */
5553 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005554 /* target highest slot id */
5555 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005556 /* result flags */
5557 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005558 status = 0;
5559out_err:
5560 res->sr_status = status;
5561 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005562out_overflow:
5563 print_overflow_msg(__func__, xdr);
5564 status = -EIO;
5565 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005566#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005567 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005568#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005569}
5570
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005571#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005572/*
5573 * TODO: Need to handle case when EOF != true;
5574 */
5575static int decode_getdevicelist(struct xdr_stream *xdr,
5576 struct pnfs_devicelist *res)
5577{
5578 __be32 *p;
5579 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005580 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005581
5582 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5583 if (status)
5584 return status;
5585
5586 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5587 if (unlikely(!p))
5588 goto out_overflow;
5589
5590 /* TODO: Skip cookie for now */
5591 p += 2;
5592
5593 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005594 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005595
5596 res->num_devs = be32_to_cpup(p);
5597
5598 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5599
5600 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005601 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005602 __func__, res->num_devs);
5603 return -EIO;
5604 }
5605
5606 p = xdr_inline_decode(xdr,
5607 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5608 if (unlikely(!p))
5609 goto out_overflow;
5610 for (i = 0; i < res->num_devs; i++)
5611 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5612 NFS4_DEVICEID4_SIZE);
5613 res->eof = be32_to_cpup(p);
5614 return 0;
5615out_overflow:
5616 print_overflow_msg(__func__, xdr);
5617 return -EIO;
5618}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005619
5620static int decode_getdeviceinfo(struct xdr_stream *xdr,
5621 struct pnfs_device *pdev)
5622{
5623 __be32 *p;
5624 uint32_t len, type;
5625 int status;
5626
5627 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5628 if (status) {
5629 if (status == -ETOOSMALL) {
5630 p = xdr_inline_decode(xdr, 4);
5631 if (unlikely(!p))
5632 goto out_overflow;
5633 pdev->mincount = be32_to_cpup(p);
5634 dprintk("%s: Min count too small. mincnt = %u\n",
5635 __func__, pdev->mincount);
5636 }
5637 return status;
5638 }
5639
5640 p = xdr_inline_decode(xdr, 8);
5641 if (unlikely(!p))
5642 goto out_overflow;
5643 type = be32_to_cpup(p++);
5644 if (type != pdev->layout_type) {
5645 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5646 __func__, pdev->layout_type, type);
5647 return -EINVAL;
5648 }
5649 /*
5650 * Get the length of the opaque device_addr4. xdr_read_pages places
5651 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5652 * and places the remaining xdr data in xdr_buf->tail
5653 */
5654 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005655 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5656 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005657
5658 /* Parse notification bitmap, verifying that it is zero. */
5659 p = xdr_inline_decode(xdr, 4);
5660 if (unlikely(!p))
5661 goto out_overflow;
5662 len = be32_to_cpup(p);
5663 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005664 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005665
5666 p = xdr_inline_decode(xdr, 4 * len);
5667 if (unlikely(!p))
5668 goto out_overflow;
5669 for (i = 0; i < len; i++, p++) {
5670 if (be32_to_cpup(p)) {
5671 dprintk("%s: notifications not supported\n",
5672 __func__);
5673 return -EIO;
5674 }
5675 }
5676 }
5677 return 0;
5678out_overflow:
5679 print_overflow_msg(__func__, xdr);
5680 return -EIO;
5681}
5682
5683static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5684 struct nfs4_layoutget_res *res)
5685{
5686 __be32 *p;
5687 int status;
5688 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005689 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005690
5691 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5692 if (status)
5693 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005694 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005695 if (unlikely(!p))
5696 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005697 res->return_on_close = be32_to_cpup(p);
5698 decode_stateid(xdr, &res->stateid);
5699 p = xdr_inline_decode(xdr, 4);
5700 if (unlikely(!p))
5701 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005702 layout_count = be32_to_cpup(p);
5703 if (!layout_count) {
5704 dprintk("%s: server responded with empty layout array\n",
5705 __func__);
5706 return -EINVAL;
5707 }
5708
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005709 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005710 if (unlikely(!p))
5711 goto out_overflow;
5712 p = xdr_decode_hyper(p, &res->range.offset);
5713 p = xdr_decode_hyper(p, &res->range.length);
5714 res->range.iomode = be32_to_cpup(p++);
5715 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005716 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005717
5718 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5719 __func__,
5720 (unsigned long)res->range.offset,
5721 (unsigned long)res->range.length,
5722 res->range.iomode,
5723 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005724 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005725
Trond Myklebust64bd5772012-06-20 22:35:05 -04005726 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005727 if (res->layoutp->len > recvd) {
5728 dprintk("NFS: server cheating in layoutget reply: "
5729 "layout len %u > recvd %u\n",
5730 res->layoutp->len, recvd);
5731 return -EINVAL;
5732 }
5733
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005734 if (layout_count > 1) {
5735 /* We only handle a length one array at the moment. Any
5736 * further entries are just ignored. Note that this means
5737 * the client may see a response that is less than the
5738 * minimum it requested.
5739 */
5740 dprintk("%s: server responded with %d layouts, dropping tail\n",
5741 __func__, layout_count);
5742 }
5743
5744 return 0;
5745out_overflow:
5746 print_overflow_msg(__func__, xdr);
5747 return -EIO;
5748}
Andy Adamson863a3c62011-03-23 13:27:54 +00005749
Benny Halevycbe82602011-05-22 19:52:37 +03005750static int decode_layoutreturn(struct xdr_stream *xdr,
5751 struct nfs4_layoutreturn_res *res)
5752{
5753 __be32 *p;
5754 int status;
5755
5756 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5757 if (status)
5758 return status;
5759 p = xdr_inline_decode(xdr, 4);
5760 if (unlikely(!p))
5761 goto out_overflow;
5762 res->lrs_present = be32_to_cpup(p);
5763 if (res->lrs_present)
5764 status = decode_stateid(xdr, &res->stateid);
5765 return status;
5766out_overflow:
5767 print_overflow_msg(__func__, xdr);
5768 return -EIO;
5769}
5770
Andy Adamson863a3c62011-03-23 13:27:54 +00005771static int decode_layoutcommit(struct xdr_stream *xdr,
5772 struct rpc_rqst *req,
5773 struct nfs4_layoutcommit_res *res)
5774{
5775 __be32 *p;
5776 __u32 sizechanged;
5777 int status;
5778
5779 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005780 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005781 if (status)
5782 return status;
5783
5784 p = xdr_inline_decode(xdr, 4);
5785 if (unlikely(!p))
5786 goto out_overflow;
5787 sizechanged = be32_to_cpup(p);
5788
5789 if (sizechanged) {
5790 /* throw away new size */
5791 p = xdr_inline_decode(xdr, 8);
5792 if (unlikely(!p))
5793 goto out_overflow;
5794 }
5795 return 0;
5796out_overflow:
5797 print_overflow_msg(__func__, xdr);
5798 return -EIO;
5799}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005800
5801static int decode_test_stateid(struct xdr_stream *xdr,
5802 struct nfs41_test_stateid_res *res)
5803{
5804 __be32 *p;
5805 int status;
5806 int num_res;
5807
5808 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5809 if (status)
5810 return status;
5811
5812 p = xdr_inline_decode(xdr, 4);
5813 if (unlikely(!p))
5814 goto out_overflow;
5815 num_res = be32_to_cpup(p++);
5816 if (num_res != 1)
5817 goto out;
5818
5819 p = xdr_inline_decode(xdr, 4);
5820 if (unlikely(!p))
5821 goto out_overflow;
5822 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005823
5824 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005825out_overflow:
5826 print_overflow_msg(__func__, xdr);
5827out:
5828 return -EIO;
5829}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005830
5831static int decode_free_stateid(struct xdr_stream *xdr,
5832 struct nfs41_free_stateid_res *res)
5833{
5834 __be32 *p;
5835 int status;
5836
5837 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5838 if (status)
5839 return status;
5840
5841 p = xdr_inline_decode(xdr, 4);
5842 if (unlikely(!p))
5843 goto out_overflow;
5844 res->status = be32_to_cpup(p++);
5845 return res->status;
5846out_overflow:
5847 print_overflow_msg(__func__, xdr);
5848 return -EIO;
5849}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005850#endif /* CONFIG_NFS_V4_1 */
5851
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852/*
Benny Halevy49c25592008-12-23 16:06:16 -05005853 * END OF "GENERIC" DECODE ROUTINES.
5854 */
5855
5856/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857 * Decode OPEN_DOWNGRADE response
5858 */
Chuck Leverbf269552010-12-14 14:59:29 +00005859static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5860 struct xdr_stream *xdr,
5861 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862{
Andy Adamson05d564f2008-12-23 16:06:15 -05005863 struct compound_hdr hdr;
5864 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865
Chuck Leverbf269552010-12-14 14:59:29 +00005866 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005867 if (status)
5868 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005869 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005870 if (status)
5871 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005872 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005873 if (status)
5874 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005875 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005876 if (status != 0)
5877 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005878 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005880 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005881}
5882
5883/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005884 * Decode ACCESS response
5885 */
Chuck Leverbf269552010-12-14 14:59:29 +00005886static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5887 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005889 struct compound_hdr hdr;
5890 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005891
Chuck Leverbf269552010-12-14 14:59:29 +00005892 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005893 if (status)
5894 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005895 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005896 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005897 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005898 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005899 if (status != 0)
5900 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04005901 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04005902 if (status != 0)
5903 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005904 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905out:
5906 return status;
5907}
5908
5909/*
5910 * Decode LOOKUP response
5911 */
Chuck Leverbf269552010-12-14 14:59:29 +00005912static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5913 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005914{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005915 struct compound_hdr hdr;
5916 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005917
Chuck Leverbf269552010-12-14 14:59:29 +00005918 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005919 if (status)
5920 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005921 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005922 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005923 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005924 status = decode_putfh(xdr);
5925 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005927 status = decode_lookup(xdr);
5928 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005930 status = decode_getfh(xdr, res->fh);
5931 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005933 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005934out:
5935 return status;
5936}
5937
5938/*
5939 * Decode LOOKUP_ROOT response
5940 */
Chuck Leverbf269552010-12-14 14:59:29 +00005941static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5942 struct xdr_stream *xdr,
5943 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005944{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945 struct compound_hdr hdr;
5946 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005947
Chuck Leverbf269552010-12-14 14:59:29 +00005948 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005949 if (status)
5950 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005951 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005952 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005953 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005954 status = decode_putrootfh(xdr);
5955 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005957 status = decode_getfh(xdr, res->fh);
5958 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005959 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005960out:
5961 return status;
5962}
5963
5964/*
5965 * Decode REMOVE response
5966 */
Chuck Leverbf269552010-12-14 14:59:29 +00005967static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5968 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970 struct compound_hdr hdr;
5971 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005972
Chuck Leverbf269552010-12-14 14:59:29 +00005973 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005974 if (status)
5975 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005976 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005977 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005978 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005979 status = decode_putfh(xdr);
5980 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005981 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005982 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005983out:
5984 return status;
5985}
5986
5987/*
5988 * Decode RENAME response
5989 */
Chuck Leverbf269552010-12-14 14:59:29 +00005990static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5991 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005992{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005993 struct compound_hdr hdr;
5994 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005995
Chuck Leverbf269552010-12-14 14:59:29 +00005996 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005997 if (status)
5998 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005999 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006000 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006001 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006002 status = decode_putfh(xdr);
6003 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006004 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006005 status = decode_savefh(xdr);
6006 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006008 status = decode_putfh(xdr);
6009 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006011 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012out:
6013 return status;
6014}
6015
6016/*
6017 * Decode LINK response
6018 */
Chuck Leverbf269552010-12-14 14:59:29 +00006019static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6020 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022 struct compound_hdr hdr;
6023 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006024
Chuck Leverbf269552010-12-14 14:59:29 +00006025 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006026 if (status)
6027 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006028 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006029 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_putfh(xdr);
6032 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006034 status = decode_savefh(xdr);
6035 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006036 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006037 status = decode_putfh(xdr);
6038 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006040 status = decode_link(xdr, &res->cinfo);
6041 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006042 goto out;
6043 /*
6044 * Note order: OP_LINK leaves the directory as the current
6045 * filehandle.
6046 */
Chuck Leverbf269552010-12-14 14:59:29 +00006047 status = decode_restorefh(xdr);
6048 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006049 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006050 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006051out:
6052 return status;
6053}
6054
6055/*
6056 * Decode CREATE response
6057 */
Chuck Leverbf269552010-12-14 14:59:29 +00006058static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6059 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061 struct compound_hdr hdr;
6062 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006063
Chuck Leverbf269552010-12-14 14:59:29 +00006064 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006065 if (status)
6066 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006067 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006068 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006069 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006070 status = decode_putfh(xdr);
6071 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006073 status = decode_create(xdr, &res->dir_cinfo);
6074 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006075 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006076 status = decode_getfh(xdr, res->fh);
6077 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078 goto out;
Trond Myklebust7c317fc2012-04-27 13:48:18 -04006079 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006080out:
6081 return status;
6082}
6083
6084/*
6085 * Decode SYMLINK response
6086 */
Chuck Leverbf269552010-12-14 14:59:29 +00006087static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6088 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089{
Chuck Leverbf269552010-12-14 14:59:29 +00006090 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006091}
6092
6093/*
6094 * Decode GETATTR response
6095 */
Chuck Leverbf269552010-12-14 14:59:29 +00006096static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6097 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099 struct compound_hdr hdr;
6100 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006101
Chuck Leverbf269552010-12-14 14:59:29 +00006102 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103 if (status)
6104 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006105 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006106 if (status)
6107 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006108 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109 if (status)
6110 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006111 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006112out:
6113 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114}
6115
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006116/*
6117 * Encode an SETACL request
6118 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006119static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6120 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006121{
Andy Adamson05d564f2008-12-23 16:06:15 -05006122 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006123 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006124 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006125
Chuck Lever9f06c712010-12-14 14:59:18 +00006126 encode_compound_hdr(xdr, req, &hdr);
6127 encode_sequence(xdr, &args->seq_args, &hdr);
6128 encode_putfh(xdr, args->fh, &hdr);
6129 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006130 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006131}
Andy Adamson05d564f2008-12-23 16:06:15 -05006132
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006133/*
6134 * Decode SETACL response
6135 */
6136static int
Chuck Leverbf269552010-12-14 14:59:29 +00006137nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006138 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006139{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006140 struct compound_hdr hdr;
6141 int status;
6142
Chuck Leverbf269552010-12-14 14:59:29 +00006143 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006144 if (status)
6145 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006146 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006147 if (status)
6148 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006149 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006150 if (status)
6151 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006152 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006153out:
6154 return status;
6155}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156
6157/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006158 * Decode GETACL response
6159 */
6160static int
Chuck Leverbf269552010-12-14 14:59:29 +00006161nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006162 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006163{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006164 struct compound_hdr hdr;
6165 int status;
6166
Trond Myklebust331818f2012-02-03 18:30:53 -05006167 if (res->acl_scratch != NULL) {
6168 void *p = page_address(res->acl_scratch);
6169 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6170 }
Chuck Leverbf269552010-12-14 14:59:29 +00006171 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006172 if (status)
6173 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006174 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006175 if (status)
6176 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006178 if (status)
6179 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006180 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006181
6182out:
6183 return status;
6184}
6185
6186/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 * Decode CLOSE response
6188 */
Chuck Leverbf269552010-12-14 14:59:29 +00006189static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6190 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191{
Andy Adamson05d564f2008-12-23 16:06:15 -05006192 struct compound_hdr hdr;
6193 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006196 if (status)
6197 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006199 if (status)
6200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006202 if (status)
6203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006205 if (status != 0)
6206 goto out;
6207 /*
6208 * Note: Server may do delete on close for this file
6209 * in which case the getattr call will fail with
6210 * an ESTALE error. Shouldn't be a problem,
6211 * though, since fattr->valid will remain unset.
6212 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006213 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006215 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216}
6217
6218/*
6219 * Decode OPEN response
6220 */
Chuck Leverbf269552010-12-14 14:59:29 +00006221static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6222 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006223{
Andy Adamson05d564f2008-12-23 16:06:15 -05006224 struct compound_hdr hdr;
6225 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226
Chuck Leverbf269552010-12-14 14:59:29 +00006227 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006228 if (status)
6229 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006230 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006231 if (status)
6232 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006233 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006234 if (status)
6235 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006236 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006237 if (status)
6238 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006239 status = decode_getfh(xdr, &res->fh);
6240 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006242 if (res->access_request)
6243 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust90ff0c52012-04-27 13:48:18 -04006244 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006246 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006247}
6248
6249/*
6250 * Decode OPEN_CONFIRM response
6251 */
Chuck Leverbf269552010-12-14 14:59:29 +00006252static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6253 struct xdr_stream *xdr,
6254 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006255{
Andy Adamson05d564f2008-12-23 16:06:15 -05006256 struct compound_hdr hdr;
6257 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258
Chuck Leverbf269552010-12-14 14:59:29 +00006259 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006260 if (status)
6261 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006262 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006263 if (status)
6264 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006265 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006267 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006268}
6269
6270/*
6271 * Decode OPEN response
6272 */
Chuck Leverbf269552010-12-14 14:59:29 +00006273static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6274 struct xdr_stream *xdr,
6275 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276{
Andy Adamson05d564f2008-12-23 16:06:15 -05006277 struct compound_hdr hdr;
6278 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006279
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006281 if (status)
6282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006283 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006284 if (status)
6285 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006286 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006287 if (status)
6288 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006289 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006290 if (status)
6291 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006292 if (res->access_request)
6293 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006294 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006296 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297}
6298
6299/*
6300 * Decode SETATTR response
6301 */
Chuck Leverbf269552010-12-14 14:59:29 +00006302static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6303 struct xdr_stream *xdr,
6304 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305{
Andy Adamson05d564f2008-12-23 16:06:15 -05006306 struct compound_hdr hdr;
6307 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006308
Chuck Leverbf269552010-12-14 14:59:29 +00006309 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006310 if (status)
6311 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006312 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006313 if (status)
6314 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006315 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006316 if (status)
6317 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006318 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006319 if (status)
6320 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006321 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006323 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324}
6325
6326/*
6327 * Decode LOCK response
6328 */
Chuck Leverbf269552010-12-14 14:59:29 +00006329static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6330 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332 struct compound_hdr hdr;
6333 int status;
6334
Chuck Leverbf269552010-12-14 14:59:29 +00006335 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006336 if (status)
6337 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006338 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006339 if (status)
6340 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006341 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342 if (status)
6343 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006344 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345out:
6346 return status;
6347}
6348
6349/*
6350 * Decode LOCKT response
6351 */
Chuck Leverbf269552010-12-14 14:59:29 +00006352static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6353 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355 struct compound_hdr hdr;
6356 int status;
6357
Chuck Leverbf269552010-12-14 14:59:29 +00006358 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359 if (status)
6360 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006362 if (status)
6363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006365 if (status)
6366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368out:
6369 return status;
6370}
6371
6372/*
6373 * Decode LOCKU response
6374 */
Chuck Leverbf269552010-12-14 14:59:29 +00006375static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6376 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 struct compound_hdr hdr;
6379 int status;
6380
Chuck Leverbf269552010-12-14 14:59:29 +00006381 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006382 if (status)
6383 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006384 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006385 if (status)
6386 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006387 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388 if (status)
6389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006390 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391out:
6392 return status;
6393}
6394
Chuck Leverbf269552010-12-14 14:59:29 +00006395static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6396 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006397{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006398 struct compound_hdr hdr;
6399 int status;
6400
Chuck Leverbf269552010-12-14 14:59:29 +00006401 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006402 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006403 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006404 return status;
6405}
6406
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407/*
6408 * Decode READLINK response
6409 */
Chuck Leverbf269552010-12-14 14:59:29 +00006410static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6411 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006412 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006413{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414 struct compound_hdr hdr;
6415 int status;
6416
Chuck Leverbf269552010-12-14 14:59:29 +00006417 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006418 if (status)
6419 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006420 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006421 if (status)
6422 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006423 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006424 if (status)
6425 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006426 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427out:
6428 return status;
6429}
6430
6431/*
6432 * Decode READDIR response
6433 */
Chuck Leverbf269552010-12-14 14:59:29 +00006434static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6435 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437 struct compound_hdr hdr;
6438 int status;
6439
Chuck Leverbf269552010-12-14 14:59:29 +00006440 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006441 if (status)
6442 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006444 if (status)
6445 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006446 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006447 if (status)
6448 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006449 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450out:
6451 return status;
6452}
6453
6454/*
6455 * Decode Read response
6456 */
Chuck Leverbf269552010-12-14 14:59:29 +00006457static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6458 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460 struct compound_hdr hdr;
6461 int status;
6462
Chuck Leverbf269552010-12-14 14:59:29 +00006463 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464 if (status)
6465 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006466 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006467 if (status)
6468 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006469 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470 if (status)
6471 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006472 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006473 if (!status)
6474 status = res->count;
6475out:
6476 return status;
6477}
6478
6479/*
6480 * Decode WRITE response
6481 */
Chuck Leverbf269552010-12-14 14:59:29 +00006482static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6483 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485 struct compound_hdr hdr;
6486 int status;
6487
Chuck Leverbf269552010-12-14 14:59:29 +00006488 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006489 if (status)
6490 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006491 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006492 if (status)
6493 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006494 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006495 if (status)
6496 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006497 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006498 if (status)
6499 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006500 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006501 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502 if (!status)
6503 status = res->count;
6504out:
6505 return status;
6506}
6507
6508/*
6509 * Decode COMMIT response
6510 */
Chuck Leverbf269552010-12-14 14:59:29 +00006511static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006512 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006514 struct compound_hdr hdr;
6515 int status;
6516
Chuck Leverbf269552010-12-14 14:59:29 +00006517 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 if (status)
6519 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006520 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006521 if (status)
6522 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006523 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 if (status)
6525 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006527out:
6528 return status;
6529}
6530
6531/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006532 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533 */
Chuck Leverbf269552010-12-14 14:59:29 +00006534static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006535 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537 struct compound_hdr hdr;
6538 int status;
6539
Chuck Leverbf269552010-12-14 14:59:29 +00006540 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006541 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006542 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006543 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006544 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006546 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547 return status;
6548}
6549
6550/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006551 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552 */
Chuck Leverbf269552010-12-14 14:59:29 +00006553static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006554 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556 struct compound_hdr hdr;
6557 int status;
6558
Chuck Leverbf269552010-12-14 14:59:29 +00006559 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006560 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006562 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006563 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006564 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006565 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006566 return status;
6567}
6568
6569/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006570 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006571 */
Chuck Leverbf269552010-12-14 14:59:29 +00006572static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006573 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575 struct compound_hdr hdr;
6576 int status;
6577
Chuck Leverbf269552010-12-14 14:59:29 +00006578 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006581 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006582 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006584 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006585 return status;
6586}
6587
6588/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006589 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590 */
Chuck Leverbf269552010-12-14 14:59:29 +00006591static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6592 struct xdr_stream *xdr,
6593 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006594{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006595 struct compound_hdr hdr;
6596 int status;
6597
Chuck Leverbf269552010-12-14 14:59:29 +00006598 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006599 if (status)
6600 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006601 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006602 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006603 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006604 status = decode_putfh(xdr);
6605 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006607 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006608out:
6609 return status;
6610}
6611
6612/*
6613 * Decode RENEW response
6614 */
Chuck Leverbf269552010-12-14 14:59:29 +00006615static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6616 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006618 struct compound_hdr hdr;
6619 int status;
6620
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006623 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006624 return status;
6625}
6626
6627/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006628 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629 */
Chuck Leverbf269552010-12-14 14:59:29 +00006630static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6631 struct xdr_stream *xdr,
6632 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634 struct compound_hdr hdr;
6635 int status;
6636
Chuck Leverbf269552010-12-14 14:59:29 +00006637 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006638 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006639 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 return status;
6641}
6642
6643/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006644 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006645 */
Chuck Leverbf269552010-12-14 14:59:29 +00006646static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6647 struct xdr_stream *xdr,
6648 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006649{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650 struct compound_hdr hdr;
6651 int status;
6652
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006654 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006655 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006656 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006657 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006658 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006659 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660 return status;
6661}
6662
6663/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006664 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006665 */
Chuck Leverbf269552010-12-14 14:59:29 +00006666static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6667 struct xdr_stream *xdr,
6668 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006670 struct compound_hdr hdr;
6671 int status;
6672
Chuck Leverbf269552010-12-14 14:59:29 +00006673 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006674 if (status)
6675 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006676 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006677 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006678 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006679 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006680 if (status != 0)
6681 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006682 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006683 if (status != 0)
6684 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006685 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006686out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006687 return status;
6688}
6689
Trond Myklebust683b57b2006-06-09 09:34:22 -04006690/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006691 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006692 */
Chuck Leverbf269552010-12-14 14:59:29 +00006693static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6694 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006695 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006696{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006697 struct compound_hdr hdr;
6698 int status;
6699
Chuck Leverbf269552010-12-14 14:59:29 +00006700 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006701 if (status)
6702 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006703 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006704 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006705 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006706 status = decode_putfh(xdr);
6707 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006708 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006709 status = decode_lookup(xdr);
6710 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006711 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006712 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006713 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6714 NULL, res->fs_locations,
6715 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006716out:
6717 return status;
6718}
6719
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006720/*
6721 * Decode SECINFO response
6722 */
6723static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6724 struct xdr_stream *xdr,
6725 struct nfs4_secinfo_res *res)
6726{
6727 struct compound_hdr hdr;
6728 int status;
6729
6730 status = decode_compound_hdr(xdr, &hdr);
6731 if (status)
6732 goto out;
6733 status = decode_sequence(xdr, &res->seq_res, rqstp);
6734 if (status)
6735 goto out;
6736 status = decode_putfh(xdr);
6737 if (status)
6738 goto out;
6739 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006740out:
6741 return status;
6742}
6743
Benny Halevy99fe60d2009-04-01 09:22:29 -04006744#if defined(CONFIG_NFS_V4_1)
6745/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006746 * Decode BIND_CONN_TO_SESSION response
6747 */
6748static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6749 struct xdr_stream *xdr,
6750 void *res)
6751{
6752 struct compound_hdr hdr;
6753 int status;
6754
6755 status = decode_compound_hdr(xdr, &hdr);
6756 if (!status)
6757 status = decode_bind_conn_to_session(xdr, res);
6758 return status;
6759}
6760
6761/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006762 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006763 */
Chuck Leverbf269552010-12-14 14:59:29 +00006764static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6765 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006766 void *res)
6767{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006768 struct compound_hdr hdr;
6769 int status;
6770
Chuck Leverbf269552010-12-14 14:59:29 +00006771 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006772 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006773 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006774 return status;
6775}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006776
6777/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006778 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006779 */
Chuck Leverbf269552010-12-14 14:59:29 +00006780static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6781 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006782 struct nfs41_create_session_res *res)
6783{
Andy Adamsonfc931582009-04-01 09:22:31 -04006784 struct compound_hdr hdr;
6785 int status;
6786
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006788 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006789 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006790 return status;
6791}
6792
6793/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006794 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006795 */
Chuck Leverbf269552010-12-14 14:59:29 +00006796static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6797 struct xdr_stream *xdr,
6798 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006799{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006800 struct compound_hdr hdr;
6801 int status;
6802
Chuck Leverbf269552010-12-14 14:59:29 +00006803 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006804 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006805 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006806 return status;
6807}
6808
6809/*
Trond Myklebust66245532012-05-25 17:18:09 -04006810 * Decode DESTROY_CLIENTID response
6811 */
6812static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6813 struct xdr_stream *xdr,
6814 void *res)
6815{
6816 struct compound_hdr hdr;
6817 int status;
6818
6819 status = decode_compound_hdr(xdr, &hdr);
6820 if (!status)
6821 status = decode_destroy_clientid(xdr, res);
6822 return status;
6823}
6824
6825/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006826 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006827 */
Chuck Leverbf269552010-12-14 14:59:29 +00006828static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6829 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006830 struct nfs4_sequence_res *res)
6831{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006832 struct compound_hdr hdr;
6833 int status;
6834
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006836 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006837 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006838 return status;
6839}
6840
6841/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006842 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006843 */
Chuck Leverbf269552010-12-14 14:59:29 +00006844static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6845 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006846 struct nfs4_get_lease_time_res *res)
6847{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006848 struct compound_hdr hdr;
6849 int status;
6850
Chuck Leverbf269552010-12-14 14:59:29 +00006851 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006852 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006853 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006854 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006855 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006856 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006857 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006858 return status;
6859}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006860
6861/*
6862 * Decode RECLAIM_COMPLETE response
6863 */
Chuck Leverbf269552010-12-14 14:59:29 +00006864static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6865 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006866 struct nfs41_reclaim_complete_res *res)
6867{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006868 struct compound_hdr hdr;
6869 int status;
6870
Chuck Leverbf269552010-12-14 14:59:29 +00006871 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006872 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006873 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006874 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006875 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006876 return status;
6877}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006878
6879/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006880 * Decode GETDEVICELIST response
6881 */
6882static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6883 struct xdr_stream *xdr,
6884 struct nfs4_getdevicelist_res *res)
6885{
6886 struct compound_hdr hdr;
6887 int status;
6888
6889 dprintk("encoding getdevicelist!\n");
6890
6891 status = decode_compound_hdr(xdr, &hdr);
6892 if (status != 0)
6893 goto out;
6894 status = decode_sequence(xdr, &res->seq_res, rqstp);
6895 if (status != 0)
6896 goto out;
6897 status = decode_putfh(xdr);
6898 if (status != 0)
6899 goto out;
6900 status = decode_getdevicelist(xdr, res->devlist);
6901out:
6902 return status;
6903}
6904
6905/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006906 * Decode GETDEVINFO response
6907 */
Chuck Leverbf269552010-12-14 14:59:29 +00006908static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6909 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006910 struct nfs4_getdeviceinfo_res *res)
6911{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006912 struct compound_hdr hdr;
6913 int status;
6914
Chuck Leverbf269552010-12-14 14:59:29 +00006915 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006916 if (status != 0)
6917 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006918 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006919 if (status != 0)
6920 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006921 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006922out:
6923 return status;
6924}
6925
6926/*
6927 * Decode LAYOUTGET response
6928 */
Chuck Leverbf269552010-12-14 14:59:29 +00006929static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6930 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006931 struct nfs4_layoutget_res *res)
6932{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006933 struct compound_hdr hdr;
6934 int status;
6935
Chuck Leverbf269552010-12-14 14:59:29 +00006936 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006937 if (status)
6938 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006939 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006940 if (status)
6941 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006942 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006943 if (status)
6944 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006945 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006946out:
6947 return status;
6948}
Andy Adamson863a3c62011-03-23 13:27:54 +00006949
6950/*
Benny Halevycbe82602011-05-22 19:52:37 +03006951 * Decode LAYOUTRETURN response
6952 */
6953static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6954 struct xdr_stream *xdr,
6955 struct nfs4_layoutreturn_res *res)
6956{
6957 struct compound_hdr hdr;
6958 int status;
6959
6960 status = decode_compound_hdr(xdr, &hdr);
6961 if (status)
6962 goto out;
6963 status = decode_sequence(xdr, &res->seq_res, rqstp);
6964 if (status)
6965 goto out;
6966 status = decode_putfh(xdr);
6967 if (status)
6968 goto out;
6969 status = decode_layoutreturn(xdr, res);
6970out:
6971 return status;
6972}
6973
6974/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006975 * Decode LAYOUTCOMMIT response
6976 */
6977static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6978 struct xdr_stream *xdr,
6979 struct nfs4_layoutcommit_res *res)
6980{
6981 struct compound_hdr hdr;
6982 int status;
6983
6984 status = decode_compound_hdr(xdr, &hdr);
6985 if (status)
6986 goto out;
6987 status = decode_sequence(xdr, &res->seq_res, rqstp);
6988 if (status)
6989 goto out;
6990 status = decode_putfh(xdr);
6991 if (status)
6992 goto out;
6993 status = decode_layoutcommit(xdr, rqstp, res);
6994 if (status)
6995 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006996 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006997out:
6998 return status;
6999}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007000
7001/*
7002 * Decode SECINFO_NO_NAME response
7003 */
7004static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7005 struct xdr_stream *xdr,
7006 struct nfs4_secinfo_res *res)
7007{
7008 struct compound_hdr hdr;
7009 int status;
7010
7011 status = decode_compound_hdr(xdr, &hdr);
7012 if (status)
7013 goto out;
7014 status = decode_sequence(xdr, &res->seq_res, rqstp);
7015 if (status)
7016 goto out;
7017 status = decode_putrootfh(xdr);
7018 if (status)
7019 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007020 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007021out:
7022 return status;
7023}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007024
7025/*
7026 * Decode TEST_STATEID response
7027 */
7028static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7029 struct xdr_stream *xdr,
7030 struct nfs41_test_stateid_res *res)
7031{
7032 struct compound_hdr hdr;
7033 int status;
7034
7035 status = decode_compound_hdr(xdr, &hdr);
7036 if (status)
7037 goto out;
7038 status = decode_sequence(xdr, &res->seq_res, rqstp);
7039 if (status)
7040 goto out;
7041 status = decode_test_stateid(xdr, res);
7042out:
7043 return status;
7044}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007045
7046/*
7047 * Decode FREE_STATEID response
7048 */
7049static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7050 struct xdr_stream *xdr,
7051 struct nfs41_free_stateid_res *res)
7052{
7053 struct compound_hdr hdr;
7054 int status;
7055
7056 status = decode_compound_hdr(xdr, &hdr);
7057 if (status)
7058 goto out;
7059 status = decode_sequence(xdr, &res->seq_res, rqstp);
7060 if (status)
7061 goto out;
7062 status = decode_free_stateid(xdr, res);
7063out:
7064 return status;
7065}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007066#endif /* CONFIG_NFS_V4_1 */
7067
Chuck Lever573c4e12010-12-14 14:58:11 +00007068/**
7069 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7070 * the local page cache.
7071 * @xdr: XDR stream where entry resides
7072 * @entry: buffer to fill in with entry data
7073 * @plus: boolean indicating whether this should be a readdirplus entry
7074 *
7075 * Returns zero if successful, otherwise a negative errno value is
7076 * returned.
7077 *
7078 * This function is not invoked during READDIR reply decoding, but
7079 * rather whenever an application invokes the getdents(2) system call
7080 * on a directory already in our cache.
7081 */
7082int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7083 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007084{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007085 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007086 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007087 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007088 __be32 *p = xdr_inline_decode(xdr, 4);
7089 if (unlikely(!p))
7090 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007091 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007092 p = xdr_inline_decode(xdr, 4);
7093 if (unlikely(!p))
7094 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007095 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007096 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007097 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007098 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007099 }
7100
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007101 p = xdr_inline_decode(xdr, 12);
7102 if (unlikely(!p))
7103 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007104 entry->prev_cookie = entry->cookie;
7105 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007106 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007107
Trond Myklebust9af8c222010-10-24 11:52:55 -04007108 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007109 if (unlikely(!p))
7110 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007111 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007112
7113 /*
7114 * In case the server doesn't return an inode number,
7115 * we fake one here. (We don't use inode number 0,
7116 * since glibc seems to choke on it...)
7117 */
7118 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007119 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007120
Trond Myklebust9af8c222010-10-24 11:52:55 -04007121 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007122 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007123
Trond Myklebust256e48b2012-06-21 11:18:13 -04007124 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007125 goto out_overflow;
7126
Chuck Lever573c4e12010-12-14 14:58:11 +00007127 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007128 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007129 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007130 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7131 entry->ino = entry->fattr->mounted_on_fileid;
7132 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007133 entry->ino = entry->fattr->fileid;
7134
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007135 entry->d_type = DT_UNKNOWN;
7136 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7137 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7138
Chuck Lever573c4e12010-12-14 14:58:11 +00007139 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007140
7141out_overflow:
7142 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007143 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007144}
7145
7146/*
7147 * We need to translate between nfs status return values and
7148 * the local errno values which may not be the same.
7149 */
7150static struct {
7151 int stat;
7152 int errno;
7153} nfs_errtbl[] = {
7154 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007155 { NFS4ERR_PERM, -EPERM },
7156 { NFS4ERR_NOENT, -ENOENT },
7157 { NFS4ERR_IO, -errno_NFSERR_IO},
7158 { NFS4ERR_NXIO, -ENXIO },
7159 { NFS4ERR_ACCESS, -EACCES },
7160 { NFS4ERR_EXIST, -EEXIST },
7161 { NFS4ERR_XDEV, -EXDEV },
7162 { NFS4ERR_NOTDIR, -ENOTDIR },
7163 { NFS4ERR_ISDIR, -EISDIR },
7164 { NFS4ERR_INVAL, -EINVAL },
7165 { NFS4ERR_FBIG, -EFBIG },
7166 { NFS4ERR_NOSPC, -ENOSPC },
7167 { NFS4ERR_ROFS, -EROFS },
7168 { NFS4ERR_MLINK, -EMLINK },
7169 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7170 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7171 { NFS4ERR_DQUOT, -EDQUOT },
7172 { NFS4ERR_STALE, -ESTALE },
7173 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007174 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7175 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7176 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007177 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007178 { NFS4ERR_BADTYPE, -EBADTYPE },
7179 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007180 { NFS4ERR_SYMLINK, -ELOOP },
7181 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7182 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007183 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007184};
7185
7186/*
7187 * Convert an NFS error code to a local one.
7188 * This one is used jointly by NFSv2 and NFSv3.
7189 */
7190static int
David Howells0a8ea432006-08-22 20:06:08 -04007191nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007192{
7193 int i;
7194 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7195 if (nfs_errtbl[i].stat == stat)
7196 return nfs_errtbl[i].errno;
7197 }
7198 if (stat <= 10000 || stat > 10100) {
7199 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007200 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007201 }
7202 /* If we cannot translate the error, the recovery routines should
7203 * handle it.
7204 * Note: remaining NFSv4 error codes have values > 10000, so should
7205 * not conflict with native Linux error codes.
7206 */
Benny Halevy856dff32008-03-31 17:39:06 +03007207 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007208}
7209
Linus Torvalds1da177e2005-04-16 15:20:36 -07007210#define PROC(proc, argtype, restype) \
7211[NFSPROC4_CLNT_##proc] = { \
7212 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007213 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007214 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007215 .p_arglen = NFS4_##argtype##_sz, \
7216 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007217 .p_statidx = NFSPROC4_CLNT_##proc, \
7218 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007219}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007220
7221struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007222 PROC(READ, enc_read, dec_read),
7223 PROC(WRITE, enc_write, dec_write),
7224 PROC(COMMIT, enc_commit, dec_commit),
7225 PROC(OPEN, enc_open, dec_open),
7226 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7227 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7228 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7229 PROC(CLOSE, enc_close, dec_close),
7230 PROC(SETATTR, enc_setattr, dec_setattr),
7231 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7232 PROC(RENEW, enc_renew, dec_renew),
7233 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7234 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7235 PROC(LOCK, enc_lock, dec_lock),
7236 PROC(LOCKT, enc_lockt, dec_lockt),
7237 PROC(LOCKU, enc_locku, dec_locku),
7238 PROC(ACCESS, enc_access, dec_access),
7239 PROC(GETATTR, enc_getattr, dec_getattr),
7240 PROC(LOOKUP, enc_lookup, dec_lookup),
7241 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7242 PROC(REMOVE, enc_remove, dec_remove),
7243 PROC(RENAME, enc_rename, dec_rename),
7244 PROC(LINK, enc_link, dec_link),
7245 PROC(SYMLINK, enc_symlink, dec_symlink),
7246 PROC(CREATE, enc_create, dec_create),
7247 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7248 PROC(STATFS, enc_statfs, dec_statfs),
7249 PROC(READLINK, enc_readlink, dec_readlink),
7250 PROC(READDIR, enc_readdir, dec_readdir),
7251 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7252 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7253 PROC(GETACL, enc_getacl, dec_getacl),
7254 PROC(SETACL, enc_setacl, dec_setacl),
7255 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7256 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007257 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007258#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007259 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7260 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7261 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7262 PROC(SEQUENCE, enc_sequence, dec_sequence),
7263 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7264 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7265 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7266 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007267 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007268 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007269 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007270 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007271 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007272 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007273 PROC(BIND_CONN_TO_SESSION,
7274 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007275 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007276#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007277};
7278
Trond Myklebusta613fa12012-01-20 13:53:56 -05007279const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007280 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007281 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007282 .procs = nfs4_procedures
7283};
7284
7285/*
7286 * Local variables:
7287 * c-basic-offset: 8
7288 * End:
7289 */