blob: 0abfb8466e796cb8c0894ae6fbc38180865904f4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
55#include <linux/nfs_idmap.h>
Chuck Leverf0920752012-05-21 22:45:41 -040056
Trond Myklebust4ce79712005-06-22 17:16:21 +000057#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050058#include "internal.h"
Trond Myklebust76e697b2012-11-26 14:20:49 -050059#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040060#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040061#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#define NFSDBG_FACILITY NFSDBG_XDR
64
65/* Mapping from NFS error code to "errno" error code. */
66#define errno_NFSERR_IO EIO
67
David Howells0a8ea432006-08-22 20:06:08 -040068static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
71#ifdef DEBUG
72#define NFS4_MAXTAGLEN 20
73#else
74#define NFS4_MAXTAGLEN 0
75#endif
76
Andy Adamson6c0195a2008-12-23 16:06:15 -050077/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040078 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040080#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050081#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85#define op_encode_hdr_maxsz (1)
86#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040087#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
90#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
92 (NFS4_FHSIZE >> 2))
93#define decode_putfh_maxsz (op_decode_hdr_maxsz)
94#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
95#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
96#define encode_getfh_maxsz (op_encode_hdr_maxsz)
97#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
98 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040099#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000100#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
102#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400103#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
104#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400105#ifdef CONFIG_NFS_V4_SECURITY_LABEL
106/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
107#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
108#define encode_readdir_space 24
109#define encode_readdir_bitmask_sz 3
110#else
111#define nfs4_label_maxsz 0
112#define encode_readdir_space 20
113#define encode_readdir_bitmask_sz 2
114#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400115/* We support only one layout type per file system */
116#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000117/* This is based on getfattr, which uses the most attributes: */
118#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400119 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400120 nfs4_group_maxsz + nfs4_label_maxsz + \
121 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000122#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
123 nfs4_fattr_value_maxsz)
124#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400125#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
126 1 + 2 + 1 + \
127 nfs4_owner_maxsz + \
128 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400129 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400130 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#define encode_savefh_maxsz (op_encode_hdr_maxsz)
132#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400133#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
134#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200135#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400136/* The 5 accounts for the PNFS attributes, and assumes that at most three
137 * layout types will be returned.
138 */
139#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
140 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
142#define decode_renew_maxsz (op_decode_hdr_maxsz)
143#define encode_setclientid_maxsz \
144 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500145 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
146 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
147 1 /* sc_prog */ + \
148 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
149 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
150 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#define decode_setclientid_maxsz \
152 (op_decode_hdr_maxsz + \
153 2 + \
154 1024) /* large value for CLID_INUSE */
155#define encode_setclientid_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 3 + (NFS4_VERIFIER_SIZE >> 2))
158#define decode_setclientid_confirm_maxsz \
159 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400160#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
161#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400162#define encode_share_access_maxsz \
163 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500164#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400165#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
166#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
167#define encode_open_maxsz (op_encode_hdr_maxsz + \
168 2 + encode_share_access_maxsz + 2 + \
169 open_owner_id_maxsz + \
170 encode_opentype_maxsz + \
171 encode_claim_null_maxsz)
172#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400173#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400174 decode_ace_maxsz)
175#define decode_change_info_maxsz (5)
176#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400177 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400178 decode_change_info_maxsz + 1 + \
179 nfs4_fattr_bitmap_maxsz + \
180 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400181#define encode_open_confirm_maxsz \
182 (op_encode_hdr_maxsz + \
183 encode_stateid_maxsz + 1)
184#define decode_open_confirm_maxsz \
185 (op_decode_hdr_maxsz + \
186 decode_stateid_maxsz)
187#define encode_open_downgrade_maxsz \
188 (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 1 + \
190 encode_share_access_maxsz)
191#define decode_open_downgrade_maxsz \
192 (op_decode_hdr_maxsz + \
193 decode_stateid_maxsz)
194#define encode_close_maxsz (op_encode_hdr_maxsz + \
195 1 + encode_stateid_maxsz)
196#define decode_close_maxsz (op_decode_hdr_maxsz + \
197 decode_stateid_maxsz)
198#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
199 encode_stateid_maxsz + \
200 encode_attrs_maxsz)
201#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
202 nfs4_fattr_bitmap_maxsz)
203#define encode_read_maxsz (op_encode_hdr_maxsz + \
204 encode_stateid_maxsz + 3)
205#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
206#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400207 2 + encode_verifier_maxsz + 5 + \
208 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400209#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400210 decode_verifier_maxsz + \
211 nfs4_label_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400212#define encode_readlink_maxsz (op_encode_hdr_maxsz)
213#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
214#define encode_write_maxsz (op_encode_hdr_maxsz + \
215 encode_stateid_maxsz + 4)
216#define decode_write_maxsz (op_decode_hdr_maxsz + \
217 2 + decode_verifier_maxsz)
218#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
219#define decode_commit_maxsz (op_decode_hdr_maxsz + \
220 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#define encode_remove_maxsz (op_encode_hdr_maxsz + \
222 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400223#define decode_remove_maxsz (op_decode_hdr_maxsz + \
224 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#define encode_rename_maxsz (op_encode_hdr_maxsz + \
226 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400227#define decode_rename_maxsz (op_decode_hdr_maxsz + \
228 decode_change_info_maxsz + \
229 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230#define encode_link_maxsz (op_encode_hdr_maxsz + \
231 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400232#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400233#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400234#define encode_lock_maxsz (op_encode_hdr_maxsz + \
235 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400236 1 + encode_stateid_maxsz + 1 + \
237 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400238#define decode_lock_denied_maxsz \
239 (8 + decode_lockowner_maxsz)
240#define decode_lock_maxsz (op_decode_hdr_maxsz + \
241 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400242#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
243 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400244#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
245 decode_lock_denied_maxsz)
246#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
247 encode_stateid_maxsz + \
248 4)
249#define decode_locku_maxsz (op_decode_hdr_maxsz + \
250 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400251#define encode_release_lockowner_maxsz \
252 (op_encode_hdr_maxsz + \
253 encode_lockowner_maxsz)
254#define decode_release_lockowner_maxsz \
255 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400256#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
257#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
259 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400260 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000261 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
263#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400264 1 + 2 + nfs4_name_maxsz + \
265 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400266#define decode_create_maxsz (op_decode_hdr_maxsz + \
267 decode_change_info_maxsz + \
268 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400269#define encode_statfs_maxsz (encode_getattr_maxsz)
270#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
272#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400273#define encode_getacl_maxsz (encode_getattr_maxsz)
274#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
275 nfs4_fattr_bitmap_maxsz + 1)
276#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
277 encode_stateid_maxsz + 3)
278#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400279#define encode_fs_locations_maxsz \
280 (encode_getattr_maxsz)
281#define decode_fs_locations_maxsz \
282 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000283#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400284#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 -0400285
286#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400287#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500288#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
289 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400290
Benny Halevy99fe60d2009-04-01 09:22:29 -0400291#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
292 encode_verifier_maxsz + \
293 1 /* co_ownerid.len */ + \
294 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
295 1 /* flags */ + \
296 1 /* spa_how */ + \
297 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500298 1 /* implementation id array of size 1 */ + \
299 1 /* nii_domain */ + \
300 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
301 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500302 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500303 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400304#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
305 2 /* eir_clientid */ + \
306 1 /* eir_sequenceid */ + \
307 1 /* eir_flags */ + \
308 1 /* spr_how */ + \
309 0 /* SP4_NONE (for now) */ + \
310 2 /* eir_server_owner.so_minor_id */ + \
311 /* eir_server_owner.so_major_id<> */ \
312 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
313 /* eir_server_scope<> */ \
314 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
315 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500316 1 /* nii_domain */ + \
317 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
318 1 /* nii_name */ + \
319 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
320 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400321#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
322#define decode_channel_attrs_maxsz (6 + \
323 1 /* ca_rdma_ird.len */ + \
324 1 /* ca_rdma_ird */)
325#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
326 2 /* csa_clientid */ + \
327 1 /* csa_sequence */ + \
328 1 /* csa_flags */ + \
329 encode_channel_attrs_maxsz + \
330 encode_channel_attrs_maxsz + \
331 1 /* csa_cb_program */ + \
332 1 /* csa_sec_parms.len (1) */ + \
333 1 /* cb_secflavor (AUTH_SYS) */ + \
334 1 /* stamp */ + \
335 1 /* machinename.len */ + \
336 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
337 1 /* uid */ + \
338 1 /* gid */ + \
339 1 /* gids.len (0) */)
340#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
341 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
342 1 /* csr_sequence */ + \
343 1 /* csr_flags */ + \
344 decode_channel_attrs_maxsz + \
345 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400346#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
347 /* bctsa_sessid */ \
348 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
349 1 /* bctsa_dir */ + \
350 1 /* bctsa_use_conn_in_rdma_mode */)
351#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
352 /* bctsr_sessid */ \
353 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
354 1 /* bctsr_dir */ + \
355 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400356#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
357#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400358#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
359#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400360#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
361 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
362#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
363 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga18019752009-12-05 16:08:40 -0500364#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
365#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400366#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
367 encode_verifier_maxsz)
368#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
369 2 /* nfs_cookie4 gdlr_cookie */ + \
370 decode_verifier_maxsz \
371 /* verifier4 gdlr_verifier */ + \
372 1 /* gdlr_deviceid_list count */ + \
373 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
374 NFS4_DEVICEID4_SIZE) \
375 /* gdlr_deviceid_list */ + \
376 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400377#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
378 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
379#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
380 1 /* layout type */ + \
381 1 /* opaque devaddr4 length */ + \
382 /* devaddr4 payload is read into page */ \
383 1 /* notification bitmap length */ + \
384 1 /* notification bitmap */)
385#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
386 encode_stateid_maxsz)
387#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
388 decode_stateid_maxsz + \
389 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000390#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
391 2 /* offset */ + \
392 2 /* length */ + \
393 1 /* reclaim */ + \
394 encode_stateid_maxsz + \
395 1 /* new offset (true) */ + \
396 2 /* last byte written */ + \
397 1 /* nt_timechanged (false) */ + \
398 1 /* layoutupdate4 layout type */ + \
399 1 /* NULL filelayout layoutupdate4 payload */)
400#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300401#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
402 encode_stateid_maxsz + \
403 1 /* FIXME: opaque lrf_body always empty at the moment */)
404#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
405 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400406#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
407#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400408#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
409 XDR_QUADLEN(NFS4_STATEID_SIZE))
410#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400411#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
412 XDR_QUADLEN(NFS4_STATEID_SIZE))
413#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400414#else /* CONFIG_NFS_V4_1 */
415#define encode_sequence_maxsz 0
416#define decode_sequence_maxsz 0
417#endif /* CONFIG_NFS_V4_1 */
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
420#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
421#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400424 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400432 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400444 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400448 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400449 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400453 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400454 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400458 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400462 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400465 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400466 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400467 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400468 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400469 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400474 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400475 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400477#define NFS4_enc_open_confirm_sz \
478 (compound_encode_hdr_maxsz + \
479 encode_putfh_maxsz + \
480 encode_open_confirm_maxsz)
481#define NFS4_dec_open_confirm_sz \
482 (compound_decode_hdr_maxsz + \
483 decode_putfh_maxsz + \
484 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400486 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400488 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400489 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400490 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400495 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400496 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497#define NFS4_enc_open_downgrade_sz \
498 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400499 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400500 encode_putfh_maxsz + \
501 encode_open_downgrade_maxsz + \
502 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#define NFS4_dec_open_downgrade_sz \
504 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400505 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400506 decode_putfh_maxsz + \
507 decode_open_downgrade_maxsz + \
508 decode_getattr_maxsz)
509#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400510 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400511 encode_putfh_maxsz + \
512 encode_close_maxsz + \
513 encode_getattr_maxsz)
514#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400515 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400516 decode_putfh_maxsz + \
517 decode_close_maxsz + \
518 decode_getattr_maxsz)
519#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400521 encode_putfh_maxsz + \
522 encode_setattr_maxsz + \
523 encode_getattr_maxsz)
524#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400525 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400526 decode_putfh_maxsz + \
527 decode_setattr_maxsz + \
528 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 encode_putfh_maxsz + \
532 encode_fsinfo_maxsz)
533#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 decode_putfh_maxsz + \
536 decode_fsinfo_maxsz)
537#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
538 encode_renew_maxsz)
539#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
540 decode_renew_maxsz)
541#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
542 encode_setclientid_maxsz)
543#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
544 decode_setclientid_maxsz)
545#define NFS4_enc_setclientid_confirm_sz \
546 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400547 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#define NFS4_dec_setclientid_confirm_sz \
549 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400550 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400552 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400554 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400558 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400562 encode_lockt_maxsz)
563#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400565 decode_putfh_maxsz + \
566 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400570 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400574 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400575#define NFS4_enc_release_lockowner_sz \
576 (compound_encode_hdr_maxsz + \
577 encode_lockowner_maxsz)
578#define NFS4_dec_release_lockowner_sz \
579 (compound_decode_hdr_maxsz + \
580 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400584 encode_access_maxsz + \
585 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400587 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400589 decode_access_maxsz + \
590 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 encode_putfh_maxsz + \
594 encode_getattr_maxsz)
595#define NFS4_dec_getattr_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 + \
598 decode_getattr_maxsz)
599#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 encode_putfh_maxsz + \
602 encode_lookup_maxsz + \
603 encode_getattr_maxsz + \
604 encode_getfh_maxsz)
605#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400608 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 decode_getattr_maxsz + \
610 decode_getfh_maxsz)
611#define NFS4_enc_lookup_root_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_putrootfh_maxsz + \
614 encode_getattr_maxsz + \
615 encode_getfh_maxsz)
616#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400617 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 decode_putrootfh_maxsz + \
619 decode_getattr_maxsz + \
620 decode_getfh_maxsz)
621#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400624 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#define NFS4_dec_remove_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 + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400628 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 encode_putfh_maxsz + \
632 encode_savefh_maxsz + \
633 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400634 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 decode_putfh_maxsz + \
638 decode_savefh_maxsz + \
639 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400640 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 encode_putfh_maxsz + \
644 encode_savefh_maxsz + \
645 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400646 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400647 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400648 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_putfh_maxsz + \
652 decode_savefh_maxsz + \
653 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400654 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400655 decode_restorefh_maxsz + \
656 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400658 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 encode_putfh_maxsz + \
660 encode_symlink_maxsz + \
661 encode_getattr_maxsz + \
662 encode_getfh_maxsz)
663#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 decode_putfh_maxsz + \
666 decode_symlink_maxsz + \
667 decode_getattr_maxsz + \
668 decode_getfh_maxsz)
669#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400670 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 encode_putfh_maxsz + \
672 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400673 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400674 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#define NFS4_dec_create_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_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400679 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400680 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400682 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 encode_putfh_maxsz + \
684 encode_getattr_maxsz)
685#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400686 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 decode_putfh_maxsz + \
688 decode_getattr_maxsz)
689#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400692 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400696 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800699 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 encode_getattr_maxsz)
701#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800703 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 decode_getattr_maxsz)
705#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100708 encode_delegreturn_maxsz + \
709 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400711 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100712 decode_delegreturn_maxsz + \
713 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000714#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400715 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000716 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400717 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000718#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400719 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000720 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400721 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000722#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400723 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000724 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400725 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000726#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400727 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000728 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400729 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400730#define NFS4_enc_fs_locations_sz \
731 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400732 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400733 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400734 encode_lookup_maxsz + \
735 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400736#define NFS4_dec_fs_locations_sz \
737 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400738 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400739 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400740 decode_lookup_maxsz + \
741 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000742#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
743 encode_sequence_maxsz + \
744 encode_putfh_maxsz + \
745 encode_secinfo_maxsz)
746#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
747 decode_sequence_maxsz + \
748 decode_putfh_maxsz + \
749 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400750#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400751#define NFS4_enc_bind_conn_to_session_sz \
752 (compound_encode_hdr_maxsz + \
753 encode_bind_conn_to_session_maxsz)
754#define NFS4_dec_bind_conn_to_session_sz \
755 (compound_decode_hdr_maxsz + \
756 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400757#define NFS4_enc_exchange_id_sz \
758 (compound_encode_hdr_maxsz + \
759 encode_exchange_id_maxsz)
760#define NFS4_dec_exchange_id_sz \
761 (compound_decode_hdr_maxsz + \
762 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400763#define NFS4_enc_create_session_sz \
764 (compound_encode_hdr_maxsz + \
765 encode_create_session_maxsz)
766#define NFS4_dec_create_session_sz \
767 (compound_decode_hdr_maxsz + \
768 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400769#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
770 encode_destroy_session_maxsz)
771#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
772 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400773#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
774 encode_destroy_clientid_maxsz)
775#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
776 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400777#define NFS4_enc_sequence_sz \
778 (compound_decode_hdr_maxsz + \
779 encode_sequence_maxsz)
780#define NFS4_dec_sequence_sz \
781 (compound_decode_hdr_maxsz + \
782 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400783#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
784 encode_sequence_maxsz + \
785 encode_putrootfh_maxsz + \
786 encode_fsinfo_maxsz)
787#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
788 decode_sequence_maxsz + \
789 decode_putrootfh_maxsz + \
790 decode_fsinfo_maxsz)
Ricardo Labiaga18019752009-12-05 16:08:40 -0500791#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
792 encode_sequence_maxsz + \
793 encode_reclaim_complete_maxsz)
794#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
795 decode_sequence_maxsz + \
796 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400797#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
798 encode_sequence_maxsz + \
799 encode_putfh_maxsz + \
800 encode_getdevicelist_maxsz)
801#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
802 decode_sequence_maxsz + \
803 decode_putfh_maxsz + \
804 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400805#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
806 encode_sequence_maxsz +\
807 encode_getdeviceinfo_maxsz)
808#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
809 decode_sequence_maxsz + \
810 decode_getdeviceinfo_maxsz)
811#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
812 encode_sequence_maxsz + \
813 encode_putfh_maxsz + \
814 encode_layoutget_maxsz)
815#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
816 decode_sequence_maxsz + \
817 decode_putfh_maxsz + \
818 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000819#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
820 encode_sequence_maxsz +\
821 encode_putfh_maxsz + \
822 encode_layoutcommit_maxsz + \
823 encode_getattr_maxsz)
824#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
825 decode_sequence_maxsz + \
826 decode_putfh_maxsz + \
827 decode_layoutcommit_maxsz + \
828 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300829#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
830 encode_sequence_maxsz + \
831 encode_putfh_maxsz + \
832 encode_layoutreturn_maxsz)
833#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
834 decode_sequence_maxsz + \
835 decode_putfh_maxsz + \
836 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400837#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
838 encode_sequence_maxsz + \
839 encode_putrootfh_maxsz +\
840 encode_secinfo_no_name_maxsz)
841#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
842 decode_sequence_maxsz + \
843 decode_putrootfh_maxsz + \
844 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400845#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
846 encode_sequence_maxsz + \
847 encode_test_stateid_maxsz)
848#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
849 decode_sequence_maxsz + \
850 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400851#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
852 encode_sequence_maxsz + \
853 encode_free_stateid_maxsz)
854#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
855 decode_sequence_maxsz + \
856 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500857
858const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
859 compound_encode_hdr_maxsz +
860 encode_sequence_maxsz +
861 encode_putfh_maxsz +
862 encode_getattr_maxsz) *
863 XDR_UNIT);
864
865const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
866 compound_decode_hdr_maxsz +
867 decode_sequence_maxsz +
868 decode_putfh_maxsz) *
869 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400870
871const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
872 compound_decode_hdr_maxsz +
873 decode_sequence_maxsz) *
874 XDR_UNIT);
875EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400876#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Trond Myklebustbca79472009-03-11 14:10:26 -0400878static const umode_t nfs_type2fmt[] = {
879 [NF4BAD] = 0,
880 [NF4REG] = S_IFREG,
881 [NF4DIR] = S_IFDIR,
882 [NF4BLK] = S_IFBLK,
883 [NF4CHR] = S_IFCHR,
884 [NF4LNK] = S_IFLNK,
885 [NF4SOCK] = S_IFSOCK,
886 [NF4FIFO] = S_IFIFO,
887 [NF4ATTRDIR] = 0,
888 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889};
890
891struct compound_hdr {
892 int32_t status;
893 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500894 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 uint32_t taglen;
896 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400897 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400898 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899};
900
Benny Halevy13c65ce2009-08-14 17:19:25 +0300901static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
902{
903 __be32 *p = xdr_reserve_space(xdr, nbytes);
904 BUG_ON(!p);
905 return p;
906}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Trond Myklebustcb17e552012-03-04 18:13:56 -0500908static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
909{
910 __be32 *p;
911
912 p = xdr_reserve_space(xdr, len);
913 xdr_encode_opaque_fixed(p, buf, len);
914}
915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
917{
Al Viro8687b632006-10-19 23:28:48 -0700918 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500920 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 xdr_encode_opaque(p, str, len);
922}
923
Trond Myklebust4ade9822012-03-04 18:13:57 -0500924static void encode_uint32(struct xdr_stream *xdr, u32 n)
925{
926 __be32 *p;
927
928 p = reserve_space(xdr, 4);
929 *p = cpu_to_be32(n);
930}
931
Trond Myklebustff2eb682012-03-05 11:40:12 -0500932static void encode_uint64(struct xdr_stream *xdr, u64 n)
933{
934 __be32 *p;
935
936 p = reserve_space(xdr, 8);
937 xdr_encode_hyper(p, n);
938}
939
Trond Myklebust4ade9822012-03-04 18:13:57 -0500940static void encode_nfs4_seqid(struct xdr_stream *xdr,
941 const struct nfs_seqid *seqid)
942{
943 encode_uint32(xdr, seqid->sequence->counter);
944}
945
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400946static void encode_compound_hdr(struct xdr_stream *xdr,
947 struct rpc_rqst *req,
948 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949{
Al Viro8687b632006-10-19 23:28:48 -0700950 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400951 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400952
953 /* initialize running count of expected bytes in reply.
954 * NOTE: the replied tag SHOULD be the same is the one sent,
955 * but this is not required as a MUST for the server to do so. */
956 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Trond Myklebust7fc38842012-10-15 11:51:21 -0400958 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500959 encode_string(xdr, hdr->taglen, hdr->tag);
960 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300961 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500962 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300963 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500964}
965
Trond Myklebustab19b482012-03-04 18:13:57 -0500966static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
967 uint32_t replen,
968 struct compound_hdr *hdr)
969{
970 encode_uint32(xdr, op);
971 hdr->nops++;
972 hdr->replen += replen;
973}
974
Andy Adamsond0179312008-12-23 16:06:17 -0500975static void encode_nops(struct compound_hdr *hdr)
976{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400977 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500978 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979}
980
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500981static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
982{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500983 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500984}
985
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
987{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500988 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
David Quigleyaa9c2662013-05-22 12:50:44 -0400991static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
992 const struct nfs4_label *label,
993 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994{
995 char owner_name[IDMAP_NAMESZ];
996 char owner_group[IDMAP_NAMESZ];
997 int owner_namelen = 0;
998 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700999 __be32 *p;
1000 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 int len;
1002 uint32_t bmval0 = 0;
1003 uint32_t bmval1 = 0;
David Quigleya09df2c2013-05-22 12:50:41 -04001004 uint32_t bmval2 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
1006 /*
1007 * We reserve enough space to write the entire attribute buffer at once.
1008 * In the worst-case, this would be
David Quigleya09df2c2013-05-22 12:50:41 -04001009 * 16(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
1010 * = 40 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001011 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 */
David Quigleya09df2c2013-05-22 12:50:41 -04001013 len = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 /* Sigh */
1016 if (iap->ia_valid & ATTR_SIZE)
1017 len += 8;
1018 if (iap->ia_valid & ATTR_MODE)
1019 len += 4;
1020 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001021 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001023 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001024 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 /* XXX */
1026 strcpy(owner_name, "nobody");
1027 owner_namelen = sizeof("nobody") - 1;
1028 /* goto out; */
1029 }
1030 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1031 }
1032 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001033 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001035 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001036 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 strcpy(owner_group, "nobody");
1038 owner_grouplen = sizeof("nobody") - 1;
1039 /* goto out; */
1040 }
1041 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1042 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001043 if (label)
1044 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 if (iap->ia_valid & ATTR_ATIME_SET)
1046 len += 16;
1047 else if (iap->ia_valid & ATTR_ATIME)
1048 len += 4;
1049 if (iap->ia_valid & ATTR_MTIME_SET)
1050 len += 16;
1051 else if (iap->ia_valid & ATTR_MTIME)
1052 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001053 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
1055 /*
1056 * We write the bitmap length now, but leave the bitmap and the attribute
1057 * buffer length to be backfilled at the end of this routine.
1058 */
David Quigleya09df2c2013-05-22 12:50:41 -04001059 *p++ = cpu_to_be32(3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 q = p;
David Quigleya09df2c2013-05-22 12:50:41 -04001061 p += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063 if (iap->ia_valid & ATTR_SIZE) {
1064 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001065 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 }
1067 if (iap->ia_valid & ATTR_MODE) {
1068 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001069 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 }
1071 if (iap->ia_valid & ATTR_UID) {
1072 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001073 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 }
1075 if (iap->ia_valid & ATTR_GID) {
1076 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001077 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 }
1079 if (iap->ia_valid & ATTR_ATIME_SET) {
1080 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001081 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Bryan Schumaker042ad0b2013-04-19 16:09:37 -04001082 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001083 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 }
1085 else if (iap->ia_valid & ATTR_ATIME) {
1086 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001087 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 }
1089 if (iap->ia_valid & ATTR_MTIME_SET) {
1090 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001091 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Bryan Schumaker042ad0b2013-04-19 16:09:37 -04001092 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001093 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 }
1095 else if (iap->ia_valid & ATTR_MTIME) {
1096 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001097 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 }
David Quigleyaa9c2662013-05-22 12:50:44 -04001099 if (label) {
1100 bmval2 |= FATTR4_WORD2_SECURITY_LABEL;
1101 *p++ = cpu_to_be32(label->lfs);
1102 *p++ = cpu_to_be32(label->pi);
1103 *p++ = cpu_to_be32(label->len);
1104 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1105 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 /*
1108 * Now we backfill the bitmap and the attribute buffer length.
1109 */
1110 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001111 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 len, ((char *)p - (char *)q) + 4);
1113 BUG();
1114 }
David Quigleya09df2c2013-05-22 12:50:41 -04001115 len = (char *)p - (char *)q - 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 *q++ = htonl(bmval0);
1117 *q++ = htonl(bmval1);
David Quigleya09df2c2013-05-22 12:50:41 -04001118 *q++ = htonl(bmval2);
Benny Halevy34558512009-08-14 17:19:30 +03001119 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001124static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001126 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1127 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001130static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131{
Trond Myklebustab19b482012-03-04 18:13:57 -05001132 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001133 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001134 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135}
1136
Fred Isaman0b7c0152012-04-20 14:47:39 -04001137static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138{
Al Viro8687b632006-10-19 23:28:48 -07001139 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001140
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001141 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1142 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001143 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001144 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145}
1146
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001147static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
Al Viro8687b632006-10-19 23:28:48 -07001149 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001150
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001151 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1152 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
1154 switch (create->ftype) {
1155 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001156 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001157 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001158 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 break;
1160
1161 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001162 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001163 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001164 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 break;
1166
1167 default:
1168 break;
1169 }
1170
Benny Halevy811652b2009-08-14 17:19:34 +03001171 encode_string(xdr, create->name->len, create->name->name);
David Quigleyaa9c2662013-05-22 12:50:44 -04001172 encode_attrs(xdr, create->attrs, create->label, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001175static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
Andy Adamson05d564f2008-12-23 16:06:15 -05001177 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001179 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1180 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001181 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001182 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183}
1184
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001185static 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 -07001186{
Andy Adamson05d564f2008-12-23 16:06:15 -05001187 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001189 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1190 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001191 *p++ = cpu_to_be32(2);
1192 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001193 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194}
1195
Fred Isamandae100c2011-07-30 20:52:37 -04001196static void
1197encode_getattr_three(struct xdr_stream *xdr,
1198 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1199 struct compound_hdr *hdr)
1200{
1201 __be32 *p;
1202
Trond Myklebustab19b482012-03-04 18:13:57 -05001203 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001204 if (bm2) {
1205 p = reserve_space(xdr, 16);
1206 *p++ = cpu_to_be32(3);
1207 *p++ = cpu_to_be32(bm0);
1208 *p++ = cpu_to_be32(bm1);
1209 *p = cpu_to_be32(bm2);
1210 } else if (bm1) {
1211 p = reserve_space(xdr, 12);
1212 *p++ = cpu_to_be32(2);
1213 *p++ = cpu_to_be32(bm0);
1214 *p = cpu_to_be32(bm1);
1215 } else {
1216 p = reserve_space(xdr, 8);
1217 *p++ = cpu_to_be32(1);
1218 *p = cpu_to_be32(bm0);
1219 }
Fred Isamandae100c2011-07-30 20:52:37 -04001220}
1221
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001222static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223{
David Quigleya09df2c2013-05-22 12:50:41 -04001224 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1225 bitmask[1] & nfs4_fattr_bitmap[1],
1226 bitmask[2] & nfs4_fattr_bitmap[2],
1227 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
Andy Adamson88034c32012-05-23 05:02:34 -04001230static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001231 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001232 struct compound_hdr *hdr)
1233{
1234 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001235 bitmask[0] & open_bitmap[0],
1236 bitmask[1] & open_bitmap[1],
1237 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001238 hdr);
1239}
1240
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001241static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242{
Fred Isamandae100c2011-07-30 20:52:37 -04001243 encode_getattr_three(xdr,
1244 bitmask[0] & nfs4_fsinfo_bitmap[0],
1245 bitmask[1] & nfs4_fsinfo_bitmap[1],
1246 bitmask[2] & nfs4_fsinfo_bitmap[2],
1247 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248}
1249
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001250static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001251{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001252 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1253 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001254}
1255
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001256static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
Trond Myklebustab19b482012-03-04 18:13:57 -05001258 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259}
1260
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001261static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262{
Trond Myklebustab19b482012-03-04 18:13:57 -05001263 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001264 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001267static inline int nfs4_lock_type(struct file_lock *fl, int block)
1268{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001269 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001270 return block ? NFS4_READW_LT : NFS4_READ_LT;
1271 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1272}
1273
1274static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1275{
1276 if (fl->fl_end == OFFSET_MAX)
1277 return ~(uint64_t)0;
1278 return fl->fl_end - fl->fl_start + 1;
1279}
1280
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001281static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1282{
1283 __be32 *p;
1284
Trond Myklebustd035c362010-12-21 10:45:27 -05001285 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001286 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001287 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001288 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001289 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001290 xdr_encode_hyper(p, lowner->id);
1291}
1292
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293/*
1294 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1295 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1296 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001297static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298{
Al Viro8687b632006-10-19 23:28:48 -07001299 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001301 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1302 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001303 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1304 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001305 p = xdr_encode_hyper(p, args->fl->fl_start);
1306 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001307 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001308 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001309 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001310 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001311 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001312 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 }
1314 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001315 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001316 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
1319
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001320static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321{
Al Viro8687b632006-10-19 23:28:48 -07001322 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001324 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1325 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001326 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001327 p = xdr_encode_hyper(p, args->fl->fl_start);
1328 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001329 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330}
1331
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001332static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333{
Al Viro8687b632006-10-19 23:28:48 -07001334 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001336 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1337 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001338 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001339 encode_nfs4_stateid(xdr, args->stateid);
1340 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001341 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001342 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343}
1344
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001345static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1346{
Trond Myklebustab19b482012-03-04 18:13:57 -05001347 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001348 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001349}
1350
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001351static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352{
Trond Myklebustab19b482012-03-04 18:13:57 -05001353 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001354 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355}
1356
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001357static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358{
Al Viro8687b632006-10-19 23:28:48 -07001359 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
Benny Halevy13c65ce2009-08-14 17:19:25 +03001361 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001362 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001363 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001364 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001365 break;
1366 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001367 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001368 break;
1369 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001370 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001371 break;
1372 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001373 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 }
Benny Halevy34558512009-08-14 17:19:30 +03001375 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376}
1377
1378static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1379{
Al Viro8687b632006-10-19 23:28:48 -07001380 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 /*
1382 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1383 * owner 4 = 32
1384 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001385 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001386 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001387 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001388 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001389 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001390 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001391 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001392 *p++ = cpu_to_be32(arg->id.uniquifier);
1393 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394}
1395
1396static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1397{
Trond Myklebust549b19c2013-04-16 18:42:34 -04001398 struct iattr dummy;
Al Viro8687b632006-10-19 23:28:48 -07001399 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
Benny Halevy13c65ce2009-08-14 17:19:25 +03001401 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001402 switch(arg->createmode) {
1403 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001404 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001405 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Andy Adamson05d564f2008-12-23 16:06:15 -05001406 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001407 case NFS4_CREATE_GUARDED:
1408 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
David Quigleyaa9c2662013-05-22 12:50:44 -04001409 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001410 break;
1411 case NFS4_CREATE_EXCLUSIVE:
1412 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1413 encode_nfs4_verifier(xdr, &arg->u.verifier);
1414 break;
1415 case NFS4_CREATE_EXCLUSIVE4_1:
1416 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1417 encode_nfs4_verifier(xdr, &arg->u.verifier);
1418 dummy.ia_valid = 0;
David Quigleyaa9c2662013-05-22 12:50:44 -04001419 encode_attrs(xdr, &dummy, arg->label, arg->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 }
1421}
1422
1423static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1424{
Al Viro8687b632006-10-19 23:28:48 -07001425 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Benny Halevy13c65ce2009-08-14 17:19:25 +03001427 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001429 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001430 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001431 break;
1432 default:
Benny Halevy34558512009-08-14 17:19:30 +03001433 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001434 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 }
1436}
1437
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001438static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
Al Viro8687b632006-10-19 23:28:48 -07001440 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Benny Halevy13c65ce2009-08-14 17:19:25 +03001442 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001444 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001445 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001446 break;
1447 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001448 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001449 break;
1450 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001451 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001452 break;
1453 default:
1454 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 }
1456}
1457
1458static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1459{
Al Viro8687b632006-10-19 23:28:48 -07001460 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Benny Halevy13c65ce2009-08-14 17:19:25 +03001462 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001463 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 encode_string(xdr, name->len, name->name);
1465}
1466
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001467static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
Al Viro8687b632006-10-19 23:28:48 -07001469 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
Benny Halevy13c65ce2009-08-14 17:19:25 +03001471 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001472 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 encode_delegation_type(xdr, type);
1474}
1475
1476static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1477{
Al Viro8687b632006-10-19 23:28:48 -07001478 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001480 p = reserve_space(xdr, 4);
1481 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1482 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 encode_string(xdr, name->len, name->name);
1484}
1485
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001486static inline void encode_claim_fh(struct xdr_stream *xdr)
1487{
1488 __be32 *p;
1489
1490 p = reserve_space(xdr, 4);
1491 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1492}
1493
1494static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1495{
1496 __be32 *p;
1497
1498 p = reserve_space(xdr, 4);
1499 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1500 encode_nfs4_stateid(xdr, stateid);
1501}
1502
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001503static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504{
Trond Myklebustab19b482012-03-04 18:13:57 -05001505 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 encode_openhdr(xdr, arg);
1507 encode_opentype(xdr, arg);
1508 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001509 case NFS4_OPEN_CLAIM_NULL:
1510 encode_claim_null(xdr, arg->name);
1511 break;
1512 case NFS4_OPEN_CLAIM_PREVIOUS:
1513 encode_claim_previous(xdr, arg->u.delegation_type);
1514 break;
1515 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1516 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1517 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001518 case NFS4_OPEN_CLAIM_FH:
1519 encode_claim_fh(xdr);
1520 break;
1521 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1522 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1523 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001524 default:
1525 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527}
1528
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001529static 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 -07001530{
Trond Myklebustab19b482012-03-04 18:13:57 -05001531 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001532 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001533 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534}
1535
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001536static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537{
Trond Myklebustab19b482012-03-04 18:13:57 -05001538 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001539 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001540 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001541 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542}
1543
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001544static void
Andy Adamsond0179312008-12-23 16:06:17 -05001545encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546{
Trond Myklebustab19b482012-03-04 18:13:57 -05001547 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001548 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549}
1550
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001551static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552{
Trond Myklebustab19b482012-03-04 18:13:57 -05001553 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001556static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Al Viro8687b632006-10-19 23:28:48 -07001558 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Trond Myklebustab19b482012-03-04 18:13:57 -05001560 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001561 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Benny Halevy13c65ce2009-08-14 17:19:25 +03001563 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001564 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001565 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566}
1567
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001568static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569{
David Quigleyaa9c2662013-05-22 12:50:44 -04001570 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001571 FATTR4_WORD0_RDATTR_ERROR,
1572 FATTR4_WORD1_MOUNTED_ON_FILEID,
1573 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001574 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001575 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001577 if (readdir->plus) {
1578 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001579 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001580 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1581 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1582 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1583 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001584 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001585 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001586 /* Use mounted_on_fileid only if the server supports it */
1587 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1588 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001589
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001590 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001591 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001592 encode_nfs4_verifier(xdr, &readdir->verifier);
David Quigleyaa9c2662013-05-22 12:50:44 -04001593 p = reserve_space(xdr, encode_readdir_space);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001594 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001595 *p++ = cpu_to_be32(readdir->count);
David Quigleyaa9c2662013-05-22 12:50:44 -04001596 *p++ = cpu_to_be32(encode_readdir_bitmask_sz);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001597 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
David Quigleyaa9c2662013-05-22 12:50:44 -04001598 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1599 if (encode_readdir_bitmask_sz > 2) {
1600 if (hdr->minorversion > 1)
1601 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
1602 p++, *p++ = cpu_to_be32(attrs[2] & readdir->bitmask[2]);
1603 }
Chuck Levercd937102012-03-02 17:14:31 -05001604 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001605
1606 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001607 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001608 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001609 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001610 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001611 attrs[1] & readdir->bitmask[1],
1612 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613}
1614
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001615static 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 -07001616{
Trond Myklebustab19b482012-03-04 18:13:57 -05001617 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618}
1619
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001620static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621{
Trond Myklebustab19b482012-03-04 18:13:57 -05001622 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001623 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624}
1625
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001626static 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 -07001627{
Trond Myklebustab19b482012-03-04 18:13:57 -05001628 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001629 encode_string(xdr, oldname->len, oldname->name);
1630 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
Chuck Leverbb4dae52012-03-01 17:01:48 -05001633static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1634 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001636 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001637 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638}
1639
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001640static void
Andy Adamsond0179312008-12-23 16:06:17 -05001641encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001642{
Trond Myklebustab19b482012-03-04 18:13:57 -05001643 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001644}
1645
Chuck Lever9f06c712010-12-14 14:59:18 +00001646static void
Andy Adamsond0179312008-12-23 16:06:17 -05001647encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001648{
Al Viro8687b632006-10-19 23:28:48 -07001649 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001650
Trond Myklebustab19b482012-03-04 18:13:57 -05001651 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001652 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001653 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001654 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001655 *p = cpu_to_be32(FATTR4_WORD0_ACL);
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(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001658 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001659}
1660
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001661static void
Andy Adamsond0179312008-12-23 16:06:17 -05001662encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663{
Trond Myklebustab19b482012-03-04 18:13:57 -05001664 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
1666
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001667static 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 -07001668{
Trond Myklebustab19b482012-03-04 18:13:57 -05001669 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001670 encode_nfs4_stateid(xdr, &arg->stateid);
David Quigleyaa9c2662013-05-22 12:50:44 -04001671 encode_attrs(xdr, arg->iap, arg->label, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672}
1673
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001674static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
Al Viro8687b632006-10-19 23:28:48 -07001676 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
Trond Myklebust70019512012-03-04 20:49:32 -05001678 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001679 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
1681 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001682 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001683 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1685 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001686 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001687 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688}
1689
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001690static 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 -07001691{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001692 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1693 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001694 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001695 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696}
1697
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001698static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699{
Al Viro8687b632006-10-19 23:28:48 -07001700 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Trond Myklebustab19b482012-03-04 18:13:57 -05001702 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001703 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
Benny Halevy13c65ce2009-08-14 17:19:25 +03001705 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001706 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001707 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001708 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
1710 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711}
1712
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001713static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714{
Trond Myklebustab19b482012-03-04 18:13:57 -05001715 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001716 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001718
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001719static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1720{
Trond Myklebustab19b482012-03-04 18:13:57 -05001721 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001722 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001723}
1724
Benny Halevy99fe60d2009-04-01 09:22:29 -04001725#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001726/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001727static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1728 struct nfs4_session *session,
1729 struct compound_hdr *hdr)
1730{
1731 __be32 *p;
1732
1733 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1734 decode_bind_conn_to_session_maxsz, hdr);
1735 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1736 p = xdr_reserve_space(xdr, 8);
1737 *p++ = cpu_to_be32(NFS4_CDFC4_BACK_OR_BOTH);
1738 *p = 0; /* use_conn_in_rdma_mode = False */
1739}
1740
Benny Halevy99fe60d2009-04-01 09:22:29 -04001741static void encode_exchange_id(struct xdr_stream *xdr,
1742 struct nfs41_exchange_id_args *args,
1743 struct compound_hdr *hdr)
1744{
1745 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001746 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001747 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001748
Trond Myklebust70019512012-03-04 20:49:32 -05001749 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001750 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001751
1752 encode_string(xdr, args->id_len, args->id);
1753
Benny Halevy13c65ce2009-08-14 17:19:25 +03001754 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001755 *p++ = cpu_to_be32(args->flags);
1756 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001757
1758 if (send_implementation_id &&
1759 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1760 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001761 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001762 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1763 utsname()->sysname, utsname()->release,
1764 utsname()->version, utsname()->machine);
1765
1766 if (len > 0) {
1767 *p = cpu_to_be32(1); /* implementation id array length=1 */
1768
1769 encode_string(xdr,
1770 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1771 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1772 encode_string(xdr, len, impl_name);
1773 /* just send zeros for nii_date - the date is in nii_name */
1774 p = reserve_space(xdr, 12);
1775 p = xdr_encode_hyper(p, 0);
1776 *p = cpu_to_be32(0);
1777 } else
1778 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001779}
Andy Adamsonfc931582009-04-01 09:22:31 -04001780
1781static void encode_create_session(struct xdr_stream *xdr,
1782 struct nfs41_create_session_args *args,
1783 struct compound_hdr *hdr)
1784{
1785 __be32 *p;
1786 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1787 uint32_t len;
1788 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001789 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001790 u32 max_resp_sz_cached;
1791
1792 /*
1793 * Assumes OPEN is the biggest non-idempotent compound.
1794 * 2 is the verifier.
1795 */
1796 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1797 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001798
Andy Adamsonfc931582009-04-01 09:22:31 -04001799 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1800 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001801
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001802 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1803 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001804 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001805 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1806 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001807
Andy Adamsonfc931582009-04-01 09:22:31 -04001808 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001809 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001810 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1811 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001812 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001813 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1814 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1815 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001816
1817 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001818 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001819 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1820 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1821 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1822 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1823 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1824 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001825
Benny Halevye75bc1c2009-08-14 17:18:54 +03001826 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001827 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001828 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001829
1830 /* authsys_parms rfc1831 */
Chuck Leverf0920752012-05-21 22:45:41 -04001831 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001832 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001833 *p++ = cpu_to_be32(0); /* UID */
1834 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001835 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001836}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001837
1838static void encode_destroy_session(struct xdr_stream *xdr,
1839 struct nfs4_session *session,
1840 struct compound_hdr *hdr)
1841{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001842 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1843 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001844}
Ricardo Labiaga18019752009-12-05 16:08:40 -05001845
Trond Myklebust66245532012-05-25 17:18:09 -04001846static void encode_destroy_clientid(struct xdr_stream *xdr,
1847 uint64_t clientid,
1848 struct compound_hdr *hdr)
1849{
1850 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1851 encode_uint64(xdr, clientid);
1852}
1853
Ricardo Labiaga18019752009-12-05 16:08:40 -05001854static void encode_reclaim_complete(struct xdr_stream *xdr,
1855 struct nfs41_reclaim_complete_args *args,
1856 struct compound_hdr *hdr)
1857{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001858 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1859 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga18019752009-12-05 16:08:40 -05001860}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001861#endif /* CONFIG_NFS_V4_1 */
1862
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001863static void encode_sequence(struct xdr_stream *xdr,
1864 const struct nfs4_sequence_args *args,
1865 struct compound_hdr *hdr)
1866{
1867#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001868 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001869 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001870 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001871 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001872
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001873 if (slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001874 return;
1875
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001876 tp = slot->table;
1877 session = tp->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001878
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001879 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001880
1881 /*
1882 * Sessionid + seqid + slotid + max slotid + cache_this
1883 */
1884 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1885 "max_slotid=%d cache_this=%d\n",
1886 __func__,
1887 ((u32 *)session->sess_id.data)[0],
1888 ((u32 *)session->sess_id.data)[1],
1889 ((u32 *)session->sess_id.data)[2],
1890 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001891 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001892 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001893 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001894 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001895 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001896 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001897 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001898 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001899#endif /* CONFIG_NFS_V4_1 */
1900}
1901
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001902#ifdef CONFIG_NFS_V4_1
1903static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001904encode_getdevicelist(struct xdr_stream *xdr,
1905 const struct nfs4_getdevicelist_args *args,
1906 struct compound_hdr *hdr)
1907{
1908 __be32 *p;
1909 nfs4_verifier dummy = {
1910 .data = "dummmmmy",
1911 };
1912
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001913 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1914 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001915 *p++ = cpu_to_be32(args->layoutclass);
1916 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1917 xdr_encode_hyper(p, 0ULL); /* cookie */
1918 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001919}
1920
1921static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001922encode_getdeviceinfo(struct xdr_stream *xdr,
1923 const struct nfs4_getdeviceinfo_args *args,
1924 struct compound_hdr *hdr)
1925{
1926 __be32 *p;
1927
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001928 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1929 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001930 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1931 NFS4_DEVICEID4_SIZE);
1932 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001933 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001934 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001935}
1936
1937static void
1938encode_layoutget(struct xdr_stream *xdr,
1939 const struct nfs4_layoutget_args *args,
1940 struct compound_hdr *hdr)
1941{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001942 __be32 *p;
1943
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001944 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1945 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001946 *p++ = cpu_to_be32(0); /* Signal layout available */
1947 *p++ = cpu_to_be32(args->type);
1948 *p++ = cpu_to_be32(args->range.iomode);
1949 p = xdr_encode_hyper(p, args->range.offset);
1950 p = xdr_encode_hyper(p, args->range.length);
1951 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001952 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001953 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001954
1955 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1956 __func__,
1957 args->type,
1958 args->range.iomode,
1959 (unsigned long)args->range.offset,
1960 (unsigned long)args->range.length,
1961 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001962}
Andy Adamson863a3c62011-03-23 13:27:54 +00001963
1964static int
1965encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001966 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001967 const struct nfs4_layoutcommit_args *args,
1968 struct compound_hdr *hdr)
1969{
1970 __be32 *p;
1971
1972 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1973 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1974
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001975 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1976 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001977 /* Only whole file layouts */
1978 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001979 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001980 *p = cpu_to_be32(0); /* reclaim */
1981 encode_nfs4_stateid(xdr, &args->stateid);
1982 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001983 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1984 p = xdr_encode_hyper(p, args->lastbytewritten);
1985 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1986 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001987
1988 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1989 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1990 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001991 else
1992 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001993
Andy Adamson863a3c62011-03-23 13:27:54 +00001994 return 0;
1995}
Benny Halevycbe82602011-05-22 19:52:37 +03001996
1997static void
1998encode_layoutreturn(struct xdr_stream *xdr,
1999 const struct nfs4_layoutreturn_args *args,
2000 struct compound_hdr *hdr)
2001{
2002 __be32 *p;
2003
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002004 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2005 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002006 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2007 *p++ = cpu_to_be32(args->layout_type);
2008 *p++ = cpu_to_be32(IOMODE_ANY);
2009 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002010 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002011 p = xdr_encode_hyper(p, 0);
2012 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2013 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002014 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002015 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002016 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2017 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2018 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002019 } else
2020 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002021}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002022
2023static int
2024encode_secinfo_no_name(struct xdr_stream *xdr,
2025 const struct nfs41_secinfo_no_name_args *args,
2026 struct compound_hdr *hdr)
2027{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002028 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2029 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002030 return 0;
2031}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002032
2033static void encode_test_stateid(struct xdr_stream *xdr,
2034 struct nfs41_test_stateid_args *args,
2035 struct compound_hdr *hdr)
2036{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002037 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2038 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002039 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002040}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002041
2042static void encode_free_stateid(struct xdr_stream *xdr,
2043 struct nfs41_free_stateid_args *args,
2044 struct compound_hdr *hdr)
2045{
Trond Myklebustab19b482012-03-04 18:13:57 -05002046 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002047 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002048}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002049#endif /* CONFIG_NFS_V4_1 */
2050
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051/*
2052 * END OF "GENERIC" ENCODE ROUTINES.
2053 */
2054
Benny Halevy66cc0422009-04-01 09:22:10 -04002055static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2056{
2057#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05002058
2059 if (args->sa_slot)
2060 return args->sa_slot->table->session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002061#endif /* CONFIG_NFS_V4_1 */
2062 return 0;
2063}
2064
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065/*
2066 * Encode an ACCESS request
2067 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002068static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2069 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002072 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Chuck Lever9f06c712010-12-14 14:59:18 +00002075 encode_compound_hdr(xdr, req, &hdr);
2076 encode_sequence(xdr, &args->seq_args, &hdr);
2077 encode_putfh(xdr, args->fh, &hdr);
2078 encode_access(xdr, args->access, &hdr);
2079 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002080 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081}
2082
2083/*
2084 * Encode LOOKUP request
2085 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002086static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2087 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002090 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
Chuck Lever9f06c712010-12-14 14:59:18 +00002093 encode_compound_hdr(xdr, req, &hdr);
2094 encode_sequence(xdr, &args->seq_args, &hdr);
2095 encode_putfh(xdr, args->dir_fh, &hdr);
2096 encode_lookup(xdr, args->name, &hdr);
2097 encode_getfh(xdr, &hdr);
2098 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002099 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100}
2101
2102/*
2103 * Encode LOOKUP_ROOT request
2104 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002105static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2106 struct xdr_stream *xdr,
2107 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002110 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
Chuck Lever9f06c712010-12-14 14:59:18 +00002113 encode_compound_hdr(xdr, req, &hdr);
2114 encode_sequence(xdr, &args->seq_args, &hdr);
2115 encode_putrootfh(xdr, &hdr);
2116 encode_getfh(xdr, &hdr);
2117 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002118 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119}
2120
2121/*
2122 * Encode REMOVE request
2123 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002124static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2125 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002128 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
Chuck Lever9f06c712010-12-14 14:59:18 +00002131 encode_compound_hdr(xdr, req, &hdr);
2132 encode_sequence(xdr, &args->seq_args, &hdr);
2133 encode_putfh(xdr, args->fh, &hdr);
2134 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002135 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136}
2137
2138/*
2139 * Encode RENAME request
2140 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002141static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2142 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002145 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
Chuck Lever9f06c712010-12-14 14:59:18 +00002148 encode_compound_hdr(xdr, req, &hdr);
2149 encode_sequence(xdr, &args->seq_args, &hdr);
2150 encode_putfh(xdr, args->old_dir, &hdr);
2151 encode_savefh(xdr, &hdr);
2152 encode_putfh(xdr, args->new_dir, &hdr);
2153 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002154 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155}
2156
2157/*
2158 * Encode LINK request
2159 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002160static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2161 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002164 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
Chuck Lever9f06c712010-12-14 14:59:18 +00002167 encode_compound_hdr(xdr, req, &hdr);
2168 encode_sequence(xdr, &args->seq_args, &hdr);
2169 encode_putfh(xdr, args->fh, &hdr);
2170 encode_savefh(xdr, &hdr);
2171 encode_putfh(xdr, args->dir_fh, &hdr);
2172 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002173 encode_restorefh(xdr, &hdr);
2174 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002175 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176}
2177
2178/*
2179 * Encode CREATE request
2180 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002181static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2182 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002185 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
Chuck Lever9f06c712010-12-14 14:59:18 +00002188 encode_compound_hdr(xdr, req, &hdr);
2189 encode_sequence(xdr, &args->seq_args, &hdr);
2190 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002191 encode_create(xdr, args, &hdr);
2192 encode_getfh(xdr, &hdr);
2193 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002194 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195}
2196
2197/*
2198 * Encode SYMLINK request
2199 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002200static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2201 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202{
Chuck Lever9f06c712010-12-14 14:59:18 +00002203 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204}
2205
2206/*
2207 * Encode GETATTR request
2208 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002209static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2210 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002213 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
Chuck Lever9f06c712010-12-14 14:59:18 +00002216 encode_compound_hdr(xdr, req, &hdr);
2217 encode_sequence(xdr, &args->seq_args, &hdr);
2218 encode_putfh(xdr, args->fh, &hdr);
2219 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002220 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221}
2222
2223/*
2224 * Encode a CLOSE request
2225 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002226static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2227 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228{
Andy Adamson05d564f2008-12-23 16:06:15 -05002229 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002230 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002231 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
Chuck Lever9f06c712010-12-14 14:59:18 +00002233 encode_compound_hdr(xdr, req, &hdr);
2234 encode_sequence(xdr, &args->seq_args, &hdr);
2235 encode_putfh(xdr, args->fh, &hdr);
2236 encode_close(xdr, args, &hdr);
2237 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002238 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239}
2240
2241/*
2242 * Encode an OPEN request
2243 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002244static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2245 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002248 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
Chuck Lever9f06c712010-12-14 14:59:18 +00002251 encode_compound_hdr(xdr, req, &hdr);
2252 encode_sequence(xdr, &args->seq_args, &hdr);
2253 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002254 encode_open(xdr, args, &hdr);
2255 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002256 if (args->access)
2257 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002258 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002259 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260}
2261
2262/*
2263 * Encode an OPEN_CONFIRM request
2264 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002265static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2266 struct xdr_stream *xdr,
2267 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002270 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
Chuck Lever9f06c712010-12-14 14:59:18 +00002273 encode_compound_hdr(xdr, req, &hdr);
2274 encode_putfh(xdr, args->fh, &hdr);
2275 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002276 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277}
2278
2279/*
2280 * Encode an OPEN request with no attributes.
2281 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002282static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2283 struct xdr_stream *xdr,
2284 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002287 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Chuck Lever9f06c712010-12-14 14:59:18 +00002290 encode_compound_hdr(xdr, req, &hdr);
2291 encode_sequence(xdr, &args->seq_args, &hdr);
2292 encode_putfh(xdr, args->fh, &hdr);
2293 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002294 if (args->access)
2295 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002296 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002297 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298}
2299
2300/*
2301 * Encode an OPEN_DOWNGRADE request
2302 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002303static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2304 struct xdr_stream *xdr,
2305 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002308 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Chuck Lever9f06c712010-12-14 14:59:18 +00002311 encode_compound_hdr(xdr, req, &hdr);
2312 encode_sequence(xdr, &args->seq_args, &hdr);
2313 encode_putfh(xdr, args->fh, &hdr);
2314 encode_open_downgrade(xdr, args, &hdr);
2315 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002316 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317}
2318
2319/*
2320 * Encode a LOCK request
2321 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002322static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2323 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002326 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
Chuck Lever9f06c712010-12-14 14:59:18 +00002329 encode_compound_hdr(xdr, req, &hdr);
2330 encode_sequence(xdr, &args->seq_args, &hdr);
2331 encode_putfh(xdr, args->fh, &hdr);
2332 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002333 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334}
2335
2336/*
2337 * Encode a LOCKT request
2338 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002339static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2340 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002343 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
Chuck Lever9f06c712010-12-14 14:59:18 +00002346 encode_compound_hdr(xdr, req, &hdr);
2347 encode_sequence(xdr, &args->seq_args, &hdr);
2348 encode_putfh(xdr, args->fh, &hdr);
2349 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002350 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351}
2352
2353/*
2354 * Encode a LOCKU request
2355 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002356static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2357 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002360 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Chuck Lever9f06c712010-12-14 14:59:18 +00002363 encode_compound_hdr(xdr, req, &hdr);
2364 encode_sequence(xdr, &args->seq_args, &hdr);
2365 encode_putfh(xdr, args->fh, &hdr);
2366 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002367 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368}
2369
Chuck Lever9f06c712010-12-14 14:59:18 +00002370static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2371 struct xdr_stream *xdr,
2372 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002373{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002374 struct compound_hdr hdr = {
2375 .minorversion = 0,
2376 };
2377
Chuck Lever9f06c712010-12-14 14:59:18 +00002378 encode_compound_hdr(xdr, req, &hdr);
2379 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002380 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002381}
2382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383/*
2384 * Encode a READLINK request
2385 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002386static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2387 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002390 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
Chuck Lever9f06c712010-12-14 14:59:18 +00002393 encode_compound_hdr(xdr, req, &hdr);
2394 encode_sequence(xdr, &args->seq_args, &hdr);
2395 encode_putfh(xdr, args->fh, &hdr);
2396 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002397
Benny Halevy28f56692009-04-01 09:22:09 -04002398 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002399 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002400 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401}
2402
2403/*
2404 * Encode a READDIR request
2405 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002406static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2407 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002410 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412
Chuck Lever9f06c712010-12-14 14:59:18 +00002413 encode_compound_hdr(xdr, req, &hdr);
2414 encode_sequence(xdr, &args->seq_args, &hdr);
2415 encode_putfh(xdr, args->fh, &hdr);
2416 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002417
Benny Halevy28f56692009-04-01 09:22:09 -04002418 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002419 args->pgbase, args->count);
2420 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002421 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002422 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002423 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424}
2425
2426/*
2427 * Encode a READ request
2428 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002429static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2430 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002433 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
Chuck Lever9f06c712010-12-14 14:59:18 +00002436 encode_compound_hdr(xdr, req, &hdr);
2437 encode_sequence(xdr, &args->seq_args, &hdr);
2438 encode_putfh(xdr, args->fh, &hdr);
2439 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
Benny Halevy28f56692009-04-01 09:22:09 -04002441 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002443 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002444 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445}
2446
2447/*
2448 * Encode an SETATTR request
2449 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002450static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2451 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452{
Andy Adamson05d564f2008-12-23 16:06:15 -05002453 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002454 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002455 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Chuck Lever9f06c712010-12-14 14:59:18 +00002457 encode_compound_hdr(xdr, req, &hdr);
2458 encode_sequence(xdr, &args->seq_args, &hdr);
2459 encode_putfh(xdr, args->fh, &hdr);
2460 encode_setattr(xdr, args, args->server, &hdr);
2461 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002462 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463}
2464
2465/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002466 * Encode a GETACL request
2467 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002468static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2469 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002470{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002471 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002472 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002473 };
Benny Halevy28f56692009-04-01 09:22:09 -04002474 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002475
Chuck Lever9f06c712010-12-14 14:59:18 +00002476 encode_compound_hdr(xdr, req, &hdr);
2477 encode_sequence(xdr, &args->seq_args, &hdr);
2478 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002479 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002480 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002481
Benny Halevy28f56692009-04-01 09:22:09 -04002482 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002483 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002484
Andy Adamsond0179312008-12-23 16:06:17 -05002485 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002486}
2487
2488/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 * Encode a WRITE request
2490 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002491static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2492 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
Chuck Lever9f06c712010-12-14 14:59:18 +00002498 encode_compound_hdr(xdr, req, &hdr);
2499 encode_sequence(xdr, &args->seq_args, &hdr);
2500 encode_putfh(xdr, args->fh, &hdr);
2501 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002502 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002503 if (args->bitmask)
2504 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002505 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506}
2507
2508/*
2509 * a COMMIT request
2510 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002511static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002512 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002515 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
Chuck Lever9f06c712010-12-14 14:59:18 +00002518 encode_compound_hdr(xdr, req, &hdr);
2519 encode_sequence(xdr, &args->seq_args, &hdr);
2520 encode_putfh(xdr, args->fh, &hdr);
2521 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002522 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523}
2524
2525/*
2526 * FSINFO request
2527 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002528static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2529 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002532 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
Chuck Lever9f06c712010-12-14 14:59:18 +00002535 encode_compound_hdr(xdr, req, &hdr);
2536 encode_sequence(xdr, &args->seq_args, &hdr);
2537 encode_putfh(xdr, args->fh, &hdr);
2538 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002539 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540}
2541
2542/*
2543 * a PATHCONF request
2544 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002545static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2546 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002549 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551
Chuck Lever9f06c712010-12-14 14:59:18 +00002552 encode_compound_hdr(xdr, req, &hdr);
2553 encode_sequence(xdr, &args->seq_args, &hdr);
2554 encode_putfh(xdr, args->fh, &hdr);
2555 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002556 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002557 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558}
2559
2560/*
2561 * a STATFS request
2562 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002563static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2564 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002567 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
Chuck Lever9f06c712010-12-14 14:59:18 +00002570 encode_compound_hdr(xdr, req, &hdr);
2571 encode_sequence(xdr, &args->seq_args, &hdr);
2572 encode_putfh(xdr, args->fh, &hdr);
2573 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002574 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002575 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576}
2577
2578/*
2579 * GETATTR_BITMAP request
2580 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002581static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2582 struct xdr_stream *xdr,
2583 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002586 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588
Chuck Lever9f06c712010-12-14 14:59:18 +00002589 encode_compound_hdr(xdr, req, &hdr);
2590 encode_sequence(xdr, &args->seq_args, &hdr);
2591 encode_putfh(xdr, args->fhandle, &hdr);
2592 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002593 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002594 FATTR4_WORD0_LINK_SUPPORT|
2595 FATTR4_WORD0_SYMLINK_SUPPORT|
2596 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002597 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598}
2599
2600/*
2601 * a RENEW request
2602 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002603static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2604 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002607 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 };
2609
Chuck Lever9f06c712010-12-14 14:59:18 +00002610 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002611 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002612 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613}
2614
2615/*
2616 * a SETCLIENTID request
2617 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002618static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2619 struct xdr_stream *xdr,
2620 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002623 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 };
2625
Chuck Lever9f06c712010-12-14 14:59:18 +00002626 encode_compound_hdr(xdr, req, &hdr);
2627 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002628 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629}
2630
2631/*
2632 * a SETCLIENTID_CONFIRM request
2633 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002634static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2635 struct xdr_stream *xdr,
2636 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002639 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641
Chuck Lever9f06c712010-12-14 14:59:18 +00002642 encode_compound_hdr(xdr, req, &hdr);
2643 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002644 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645}
2646
2647/*
2648 * DELEGRETURN request
2649 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002650static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2651 struct xdr_stream *xdr,
2652 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002655 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
Chuck Lever9f06c712010-12-14 14:59:18 +00002658 encode_compound_hdr(xdr, req, &hdr);
2659 encode_sequence(xdr, &args->seq_args, &hdr);
2660 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002661 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002662 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002663 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664}
2665
2666/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002667 * Encode FS_LOCATIONS request
2668 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002669static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2670 struct xdr_stream *xdr,
2671 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002672{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002673 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002674 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002675 };
Benny Halevy28f56692009-04-01 09:22:09 -04002676 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002677
Chuck Lever9f06c712010-12-14 14:59:18 +00002678 encode_compound_hdr(xdr, req, &hdr);
2679 encode_sequence(xdr, &args->seq_args, &hdr);
2680 encode_putfh(xdr, args->dir_fh, &hdr);
2681 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002682 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002683 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002684
Benny Halevy28f56692009-04-01 09:22:09 -04002685 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002686 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002687 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002688}
2689
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002690/*
2691 * Encode SECINFO request
2692 */
2693static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2694 struct xdr_stream *xdr,
2695 struct nfs4_secinfo_arg *args)
2696{
2697 struct compound_hdr hdr = {
2698 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2699 };
2700
2701 encode_compound_hdr(xdr, req, &hdr);
2702 encode_sequence(xdr, &args->seq_args, &hdr);
2703 encode_putfh(xdr, args->dir_fh, &hdr);
2704 encode_secinfo(xdr, args->name, &hdr);
2705 encode_nops(&hdr);
2706}
2707
Benny Halevy99fe60d2009-04-01 09:22:29 -04002708#if defined(CONFIG_NFS_V4_1)
2709/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002710 * BIND_CONN_TO_SESSION request
2711 */
2712static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2713 struct xdr_stream *xdr,
2714 struct nfs_client *clp)
2715{
2716 struct compound_hdr hdr = {
2717 .minorversion = clp->cl_mvops->minor_version,
2718 };
2719
2720 encode_compound_hdr(xdr, req, &hdr);
2721 encode_bind_conn_to_session(xdr, clp->cl_session, &hdr);
2722 encode_nops(&hdr);
2723}
2724
2725/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002726 * EXCHANGE_ID request
2727 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002728static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2729 struct xdr_stream *xdr,
2730 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002731{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002732 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002733 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002734 };
2735
Chuck Lever9f06c712010-12-14 14:59:18 +00002736 encode_compound_hdr(xdr, req, &hdr);
2737 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002738 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002739}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002740
2741/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002742 * a CREATE_SESSION request
2743 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002744static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2745 struct xdr_stream *xdr,
2746 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002747{
Andy Adamsonfc931582009-04-01 09:22:31 -04002748 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002749 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002750 };
2751
Chuck Lever9f06c712010-12-14 14:59:18 +00002752 encode_compound_hdr(xdr, req, &hdr);
2753 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002754 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002755}
2756
2757/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002758 * a DESTROY_SESSION request
2759 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002760static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2761 struct xdr_stream *xdr,
2762 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002763{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002764 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002765 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002766 };
2767
Chuck Lever9f06c712010-12-14 14:59:18 +00002768 encode_compound_hdr(xdr, req, &hdr);
2769 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002770 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002771}
2772
2773/*
Trond Myklebust66245532012-05-25 17:18:09 -04002774 * a DESTROY_CLIENTID request
2775 */
2776static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2777 struct xdr_stream *xdr,
2778 struct nfs_client *clp)
2779{
2780 struct compound_hdr hdr = {
2781 .minorversion = clp->cl_mvops->minor_version,
2782 };
2783
2784 encode_compound_hdr(xdr, req, &hdr);
2785 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2786 encode_nops(&hdr);
2787}
2788
2789/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002790 * a SEQUENCE request
2791 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002792static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2793 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002794{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002795 struct compound_hdr hdr = {
2796 .minorversion = nfs4_xdr_minorversion(args),
2797 };
2798
Chuck Lever9f06c712010-12-14 14:59:18 +00002799 encode_compound_hdr(xdr, req, &hdr);
2800 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002801 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002802}
2803
2804/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002805 * a GET_LEASE_TIME request
2806 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002807static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2808 struct xdr_stream *xdr,
2809 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002810{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002811 struct compound_hdr hdr = {
2812 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2813 };
Fred Isamandae100c2011-07-30 20:52:37 -04002814 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002815
Chuck Lever9f06c712010-12-14 14:59:18 +00002816 encode_compound_hdr(xdr, req, &hdr);
2817 encode_sequence(xdr, &args->la_seq_args, &hdr);
2818 encode_putrootfh(xdr, &hdr);
2819 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002820 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002821}
Ricardo Labiaga18019752009-12-05 16:08:40 -05002822
2823/*
2824 * a RECLAIM_COMPLETE request
2825 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002826static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2827 struct xdr_stream *xdr,
2828 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga18019752009-12-05 16:08:40 -05002829{
Ricardo Labiaga18019752009-12-05 16:08:40 -05002830 struct compound_hdr hdr = {
2831 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2832 };
2833
Chuck Lever9f06c712010-12-14 14:59:18 +00002834 encode_compound_hdr(xdr, req, &hdr);
2835 encode_sequence(xdr, &args->seq_args, &hdr);
2836 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002837 encode_nops(&hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002838}
2839
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002840/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002841 * Encode GETDEVICELIST request
2842 */
2843static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2844 struct xdr_stream *xdr,
2845 struct nfs4_getdevicelist_args *args)
2846{
2847 struct compound_hdr hdr = {
2848 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2849 };
2850
2851 encode_compound_hdr(xdr, req, &hdr);
2852 encode_sequence(xdr, &args->seq_args, &hdr);
2853 encode_putfh(xdr, args->fh, &hdr);
2854 encode_getdevicelist(xdr, args, &hdr);
2855 encode_nops(&hdr);
2856}
2857
2858/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002859 * Encode GETDEVICEINFO request
2860 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002861static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2862 struct xdr_stream *xdr,
2863 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002864{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002865 struct compound_hdr hdr = {
2866 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2867 };
2868
Chuck Lever9f06c712010-12-14 14:59:18 +00002869 encode_compound_hdr(xdr, req, &hdr);
2870 encode_sequence(xdr, &args->seq_args, &hdr);
2871 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002872
2873 /* set up reply kvec. Subtract notification bitmap max size (2)
2874 * so that notification bitmap is put in xdr_buf tail */
2875 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2876 args->pdev->pages, args->pdev->pgbase,
2877 args->pdev->pglen);
2878
2879 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002880}
2881
2882/*
2883 * Encode LAYOUTGET request
2884 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002885static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2886 struct xdr_stream *xdr,
2887 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002888{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002889 struct compound_hdr hdr = {
2890 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2891 };
2892
Chuck Lever9f06c712010-12-14 14:59:18 +00002893 encode_compound_hdr(xdr, req, &hdr);
2894 encode_sequence(xdr, &args->seq_args, &hdr);
2895 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2896 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002897
2898 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2899 args->layout.pages, 0, args->layout.pglen);
2900
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002901 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002902}
Andy Adamson863a3c62011-03-23 13:27:54 +00002903
2904/*
2905 * Encode LAYOUTCOMMIT request
2906 */
Benny Halevycbe82602011-05-22 19:52:37 +03002907static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2908 struct xdr_stream *xdr,
2909 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002910{
Benny Halevyac7db722011-05-22 19:53:48 +03002911 struct nfs4_layoutcommit_data *data =
2912 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002913 struct compound_hdr hdr = {
2914 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2915 };
2916
2917 encode_compound_hdr(xdr, req, &hdr);
2918 encode_sequence(xdr, &args->seq_args, &hdr);
2919 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002920 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002921 encode_getfattr(xdr, args->bitmask, &hdr);
2922 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002923}
2924
2925/*
2926 * Encode LAYOUTRETURN request
2927 */
2928static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2929 struct xdr_stream *xdr,
2930 struct nfs4_layoutreturn_args *args)
2931{
2932 struct compound_hdr hdr = {
2933 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2934 };
2935
2936 encode_compound_hdr(xdr, req, &hdr);
2937 encode_sequence(xdr, &args->seq_args, &hdr);
2938 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2939 encode_layoutreturn(xdr, args, &hdr);
2940 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002941}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002942
2943/*
2944 * Encode SECINFO_NO_NAME request
2945 */
2946static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2947 struct xdr_stream *xdr,
2948 struct nfs41_secinfo_no_name_args *args)
2949{
2950 struct compound_hdr hdr = {
2951 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2952 };
2953
2954 encode_compound_hdr(xdr, req, &hdr);
2955 encode_sequence(xdr, &args->seq_args, &hdr);
2956 encode_putrootfh(xdr, &hdr);
2957 encode_secinfo_no_name(xdr, args, &hdr);
2958 encode_nops(&hdr);
2959 return 0;
2960}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002961
2962/*
2963 * Encode TEST_STATEID request
2964 */
2965static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2966 struct xdr_stream *xdr,
2967 struct nfs41_test_stateid_args *args)
2968{
2969 struct compound_hdr hdr = {
2970 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2971 };
2972
2973 encode_compound_hdr(xdr, req, &hdr);
2974 encode_sequence(xdr, &args->seq_args, &hdr);
2975 encode_test_stateid(xdr, args, &hdr);
2976 encode_nops(&hdr);
2977}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002978
2979/*
2980 * Encode FREE_STATEID request
2981 */
2982static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2983 struct xdr_stream *xdr,
2984 struct nfs41_free_stateid_args *args)
2985{
2986 struct compound_hdr hdr = {
2987 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2988 };
2989
2990 encode_compound_hdr(xdr, req, &hdr);
2991 encode_sequence(xdr, &args->seq_args, &hdr);
2992 encode_free_stateid(xdr, args, &hdr);
2993 encode_nops(&hdr);
2994}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002995#endif /* CONFIG_NFS_V4_1 */
2996
Benny Halevy686841b2009-08-14 17:19:48 +03002997static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2998{
2999 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3000 "Remaining buffer length is %tu words.\n",
3001 func, xdr->end - xdr->p);
3002}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003
Trond Myklebust683b57b2006-06-09 09:34:22 -04003004static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005{
Al Viro8687b632006-10-19 23:28:48 -07003006 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007
Benny Halevyc0eae662009-08-14 17:20:14 +03003008 p = xdr_inline_decode(xdr, 4);
3009 if (unlikely(!p))
3010 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003011 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003012 p = xdr_inline_decode(xdr, *len);
3013 if (unlikely(!p))
3014 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 *string = (char *)p;
3016 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003017out_overflow:
3018 print_overflow_msg(__func__, xdr);
3019 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020}
3021
3022static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3023{
Al Viro8687b632006-10-19 23:28:48 -07003024 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025
Benny Halevyc0eae662009-08-14 17:20:14 +03003026 p = xdr_inline_decode(xdr, 8);
3027 if (unlikely(!p))
3028 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003029 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003030 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003031
Benny Halevyc0eae662009-08-14 17:20:14 +03003032 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3033 if (unlikely(!p))
3034 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 hdr->tag = (char *)p;
3036 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003037 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003038 if (unlikely(hdr->nops < 1))
3039 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003041out_overflow:
3042 print_overflow_msg(__func__, xdr);
3043 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044}
3045
3046static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3047{
Al Viro8687b632006-10-19 23:28:48 -07003048 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 uint32_t opnum;
3050 int32_t nfserr;
3051
Benny Halevyc0eae662009-08-14 17:20:14 +03003052 p = xdr_inline_decode(xdr, 8);
3053 if (unlikely(!p))
3054 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003055 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003057 dprintk("nfs: Server returned operation"
3058 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 opnum, expected);
3060 return -EIO;
3061 }
Benny Halevycccddf42009-08-14 17:20:19 +03003062 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003064 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003066out_overflow:
3067 print_overflow_msg(__func__, xdr);
3068 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069}
3070
3071/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003072static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073{
Al Viro8687b632006-10-19 23:28:48 -07003074 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003075 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 char *str;
3077
Benny Halevyc0eae662009-08-14 17:20:14 +03003078 p = xdr_inline_decode(xdr, 12);
3079 if (likely(p))
3080 return decode_opaque_inline(xdr, &strlen, &str);
3081 print_overflow_msg(__func__, xdr);
3082 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083}
3084
3085static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3086{
Al Viro8687b632006-10-19 23:28:48 -07003087 uint32_t bmlen;
3088 __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 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094
Fred Isamandae100c2011-07-30 20:52:37 -04003095 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003096 p = xdr_inline_decode(xdr, (bmlen << 2));
3097 if (unlikely(!p))
3098 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003100 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003101 if (bmlen > 1) {
3102 bitmap[1] = be32_to_cpup(p++);
3103 if (bmlen > 2)
3104 bitmap[2] = be32_to_cpup(p);
3105 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 }
3107 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003108out_overflow:
3109 print_overflow_msg(__func__, xdr);
3110 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111}
3112
Trond Myklebust256e48b2012-06-21 11:18:13 -04003113static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114{
Al Viro8687b632006-10-19 23:28:48 -07003115 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116
Benny Halevyc0eae662009-08-14 17:20:14 +03003117 p = xdr_inline_decode(xdr, 4);
3118 if (unlikely(!p))
3119 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003120 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003121 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003123out_overflow:
3124 print_overflow_msg(__func__, xdr);
3125 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126}
3127
3128static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3129{
3130 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003131 int ret;
3132 ret = decode_attr_bitmap(xdr, bitmask);
3133 if (unlikely(ret < 0))
3134 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3136 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003137 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3138 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3139 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140 return 0;
3141}
3142
3143static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3144{
Al Viro8687b632006-10-19 23:28:48 -07003145 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003146 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147
3148 *type = 0;
3149 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3150 return -EIO;
3151 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003152 p = xdr_inline_decode(xdr, 4);
3153 if (unlikely(!p))
3154 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003155 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003157 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 return -EIO;
3159 }
3160 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003161 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003163 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003164 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003165out_overflow:
3166 print_overflow_msg(__func__, xdr);
3167 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168}
3169
Chuck Lever264e6352012-03-01 17:02:05 -05003170static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3171 uint32_t *bitmap, uint32_t *type)
3172{
3173 __be32 *p;
3174
3175 *type = 0;
3176 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3177 return -EIO;
3178 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3179 p = xdr_inline_decode(xdr, 4);
3180 if (unlikely(!p))
3181 goto out_overflow;
3182 *type = be32_to_cpup(p);
3183 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3184 }
3185 dprintk("%s: expire type=0x%x\n", __func__, *type);
3186 return 0;
3187out_overflow:
3188 print_overflow_msg(__func__, xdr);
3189 return -EIO;
3190}
3191
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3193{
Al Viro8687b632006-10-19 23:28:48 -07003194 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003195 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196
3197 *change = 0;
3198 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3199 return -EIO;
3200 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003201 p = xdr_inline_decode(xdr, 8);
3202 if (unlikely(!p))
3203 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003204 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003206 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003208 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003210 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003211out_overflow:
3212 print_overflow_msg(__func__, xdr);
3213 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214}
3215
3216static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3217{
Al Viro8687b632006-10-19 23:28:48 -07003218 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003219 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220
3221 *size = 0;
3222 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3223 return -EIO;
3224 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003225 p = xdr_inline_decode(xdr, 8);
3226 if (unlikely(!p))
3227 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003228 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003230 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003232 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003233 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003234out_overflow:
3235 print_overflow_msg(__func__, xdr);
3236 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237}
3238
3239static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3240{
Al Viro8687b632006-10-19 23:28:48 -07003241 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242
3243 *res = 0;
3244 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3245 return -EIO;
3246 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003247 p = xdr_inline_decode(xdr, 4);
3248 if (unlikely(!p))
3249 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003250 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3252 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003253 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003255out_overflow:
3256 print_overflow_msg(__func__, xdr);
3257 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258}
3259
3260static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3261{
Al Viro8687b632006-10-19 23:28:48 -07003262 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263
3264 *res = 0;
3265 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3266 return -EIO;
3267 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003268 p = xdr_inline_decode(xdr, 4);
3269 if (unlikely(!p))
3270 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003271 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3273 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003274 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 return 0;
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
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003281static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282{
Al Viro8687b632006-10-19 23:28:48 -07003283 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003284 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
3286 fsid->major = 0;
3287 fsid->minor = 0;
3288 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3289 return -EIO;
3290 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003291 p = xdr_inline_decode(xdr, 16);
3292 if (unlikely(!p))
3293 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003294 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003295 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003297 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003299 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 (unsigned long long)fsid->major,
3301 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003302 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003303out_overflow:
3304 print_overflow_msg(__func__, xdr);
3305 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306}
3307
3308static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3309{
Al Viro8687b632006-10-19 23:28:48 -07003310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311
3312 *res = 60;
3313 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3314 return -EIO;
3315 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003316 p = xdr_inline_decode(xdr, 4);
3317 if (unlikely(!p))
3318 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003319 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3321 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003322 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003324out_overflow:
3325 print_overflow_msg(__func__, xdr);
3326 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327}
3328
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003329static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003330{
3331 __be32 *p;
3332
3333 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3334 return -EIO;
3335 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3336 p = xdr_inline_decode(xdr, 4);
3337 if (unlikely(!p))
3338 goto out_overflow;
3339 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003340 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003341 }
3342 return 0;
3343out_overflow:
3344 print_overflow_msg(__func__, xdr);
3345 return -EIO;
3346}
3347
3348static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3349{
3350 __be32 *p;
3351 int len;
3352
Trond Myklebust7ad07352010-10-23 15:34:20 -04003353 if (fh != NULL)
3354 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003355
3356 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3357 return -EIO;
3358 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3359 p = xdr_inline_decode(xdr, 4);
3360 if (unlikely(!p))
3361 goto out_overflow;
3362 len = be32_to_cpup(p);
3363 if (len > NFS4_FHSIZE)
3364 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003365 p = xdr_inline_decode(xdr, len);
3366 if (unlikely(!p))
3367 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003368 if (fh != NULL) {
3369 memcpy(fh->data, p, len);
3370 fh->size = len;
3371 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003372 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3373 }
3374 return 0;
3375out_overflow:
3376 print_overflow_msg(__func__, xdr);
3377 return -EIO;
3378}
3379
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3381{
Al Viro8687b632006-10-19 23:28:48 -07003382 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383
3384 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3385 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3386 return -EIO;
3387 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003388 p = xdr_inline_decode(xdr, 4);
3389 if (unlikely(!p))
3390 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003391 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3393 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003394 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003396out_overflow:
3397 print_overflow_msg(__func__, xdr);
3398 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399}
3400
3401static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3402{
Al Viro8687b632006-10-19 23:28:48 -07003403 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003404 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405
3406 *fileid = 0;
3407 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3408 return -EIO;
3409 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003410 p = xdr_inline_decode(xdr, 8);
3411 if (unlikely(!p))
3412 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003413 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003415 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003417 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003418 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003419out_overflow:
3420 print_overflow_msg(__func__, xdr);
3421 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422}
3423
Manoj Naik99baf622006-06-09 09:34:24 -04003424static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3425{
Al Viro8687b632006-10-19 23:28:48 -07003426 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003427 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003428
3429 *fileid = 0;
3430 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3431 return -EIO;
3432 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003433 p = xdr_inline_decode(xdr, 8);
3434 if (unlikely(!p))
3435 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003436 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003437 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003438 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003439 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003440 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003441 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003442out_overflow:
3443 print_overflow_msg(__func__, xdr);
3444 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003445}
3446
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3448{
Al Viro8687b632006-10-19 23:28:48 -07003449 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 int status = 0;
3451
3452 *res = 0;
3453 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3454 return -EIO;
3455 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003456 p = xdr_inline_decode(xdr, 8);
3457 if (unlikely(!p))
3458 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003459 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3461 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003462 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003464out_overflow:
3465 print_overflow_msg(__func__, xdr);
3466 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467}
3468
3469static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3470{
Al Viro8687b632006-10-19 23:28:48 -07003471 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 int status = 0;
3473
3474 *res = 0;
3475 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3476 return -EIO;
3477 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003478 p = xdr_inline_decode(xdr, 8);
3479 if (unlikely(!p))
3480 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003481 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3483 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003484 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003486out_overflow:
3487 print_overflow_msg(__func__, xdr);
3488 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489}
3490
3491static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3492{
Al Viro8687b632006-10-19 23:28:48 -07003493 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 int status = 0;
3495
3496 *res = 0;
3497 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3498 return -EIO;
3499 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003500 p = xdr_inline_decode(xdr, 8);
3501 if (unlikely(!p))
3502 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003503 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3505 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003506 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003508out_overflow:
3509 print_overflow_msg(__func__, xdr);
3510 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511}
3512
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003513static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3514{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003515 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003516 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003517 int status = 0;
3518
Benny Halevyc0eae662009-08-14 17:20:14 +03003519 p = xdr_inline_decode(xdr, 4);
3520 if (unlikely(!p))
3521 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003522 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003523 if (n == 0)
3524 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003525 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003526 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3527 dprintk("cannot parse %d components in path\n", n);
3528 goto out_eio;
3529 }
3530 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003531 struct nfs4_string *component = &path->components[path->ncomponents];
3532 status = decode_opaque_inline(xdr, &component->len, &component->data);
3533 if (unlikely(status != 0))
3534 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003535 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003536 pr_cont("%s%.*s ",
3537 (path->ncomponents != n ? "/ " : ""),
3538 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003539 }
3540out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003541 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003542root_path:
3543/* a root pathname is sent as a zero component4 */
3544 path->ncomponents = 1;
3545 path->components[0].len=0;
3546 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003547 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003548 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003549out_eio:
3550 dprintk(" status %d", status);
3551 status = -EIO;
3552 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003553out_overflow:
3554 print_overflow_msg(__func__, xdr);
3555 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003556}
3557
3558static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003559{
3560 int n;
Al Viro8687b632006-10-19 23:28:48 -07003561 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003562 int status = -EIO;
3563
3564 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3565 goto out;
3566 status = 0;
3567 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3568 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003569 status = -EIO;
3570 /* Ignore borken servers that return unrequested attrs */
3571 if (unlikely(res == NULL))
3572 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003573 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003574 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003575 if (unlikely(status != 0))
3576 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003577 p = xdr_inline_decode(xdr, 4);
3578 if (unlikely(!p))
3579 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003580 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003581 if (n <= 0)
3582 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003583 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003584 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003585 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003586
Trond Myklebust809b4262013-03-27 11:54:45 -04003587 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3588 break;
3589 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003590 p = xdr_inline_decode(xdr, 4);
3591 if (unlikely(!p))
3592 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003593 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003594
Chuck Lever02a29762012-03-01 17:00:31 -05003595 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003596 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3597 struct nfs4_string *server;
3598
3599 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003600 unsigned int i;
3601 dprintk("%s: using first %u of %u servers "
3602 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003603 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003604 NFS4_FS_LOCATION_MAXSERVERS,
3605 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003606 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003607 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003608 char *data;
3609 status = decode_opaque_inline(xdr, &len, &data);
3610 if (unlikely(status != 0))
3611 goto out_eio;
3612 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003613 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003614 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003615 server = &loc->servers[loc->nservers];
3616 status = decode_opaque_inline(xdr, &server->len, &server->data);
3617 if (unlikely(status != 0))
3618 goto out_eio;
3619 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003620 }
3621 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003622 if (unlikely(status != 0))
3623 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003624 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003625 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003626 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003627out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003628 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003629 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003630out_overflow:
3631 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003632out_eio:
3633 status = -EIO;
3634 goto out;
3635}
3636
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3638{
Al Viro8687b632006-10-19 23:28:48 -07003639 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 int status = 0;
3641
3642 *res = 0;
3643 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3644 return -EIO;
3645 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003646 p = xdr_inline_decode(xdr, 8);
3647 if (unlikely(!p))
3648 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003649 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3651 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003652 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003654out_overflow:
3655 print_overflow_msg(__func__, xdr);
3656 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657}
3658
3659static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3660{
Al Viro8687b632006-10-19 23:28:48 -07003661 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 int status = 0;
3663
3664 *maxlink = 1;
3665 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3666 return -EIO;
3667 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003668 p = xdr_inline_decode(xdr, 4);
3669 if (unlikely(!p))
3670 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003671 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3673 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003674 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003676out_overflow:
3677 print_overflow_msg(__func__, xdr);
3678 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679}
3680
3681static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3682{
Al Viro8687b632006-10-19 23:28:48 -07003683 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 int status = 0;
3685
3686 *maxname = 1024;
3687 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3688 return -EIO;
3689 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003690 p = xdr_inline_decode(xdr, 4);
3691 if (unlikely(!p))
3692 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003693 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3695 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003696 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003698out_overflow:
3699 print_overflow_msg(__func__, xdr);
3700 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701}
3702
3703static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3704{
Al Viro8687b632006-10-19 23:28:48 -07003705 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706 int status = 0;
3707
3708 *res = 1024;
3709 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3710 return -EIO;
3711 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3712 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003713 p = xdr_inline_decode(xdr, 8);
3714 if (unlikely(!p))
3715 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003716 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 if (maxread > 0x7FFFFFFF)
3718 maxread = 0x7FFFFFFF;
3719 *res = (uint32_t)maxread;
3720 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3721 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003722 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003724out_overflow:
3725 print_overflow_msg(__func__, xdr);
3726 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727}
3728
3729static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3730{
Al Viro8687b632006-10-19 23:28:48 -07003731 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 int status = 0;
3733
3734 *res = 1024;
3735 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3736 return -EIO;
3737 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3738 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003739 p = xdr_inline_decode(xdr, 8);
3740 if (unlikely(!p))
3741 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003742 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 if (maxwrite > 0x7FFFFFFF)
3744 maxwrite = 0x7FFFFFFF;
3745 *res = (uint32_t)maxwrite;
3746 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3747 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003748 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003750out_overflow:
3751 print_overflow_msg(__func__, xdr);
3752 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753}
3754
Trond Myklebustbca79472009-03-11 14:10:26 -04003755static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756{
Trond Myklebustbca79472009-03-11 14:10:26 -04003757 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003758 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003759 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760
3761 *mode = 0;
3762 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3763 return -EIO;
3764 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003765 p = xdr_inline_decode(xdr, 4);
3766 if (unlikely(!p))
3767 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003768 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003769 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003771 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003773 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003774 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003775out_overflow:
3776 print_overflow_msg(__func__, xdr);
3777 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778}
3779
3780static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3781{
Al Viro8687b632006-10-19 23:28:48 -07003782 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003783 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784
3785 *nlink = 1;
3786 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3787 return -EIO;
3788 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003789 p = xdr_inline_decode(xdr, 4);
3790 if (unlikely(!p))
3791 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003792 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003794 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003796 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003797 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003798out_overflow:
3799 print_overflow_msg(__func__, xdr);
3800 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801}
3802
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003803static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003804 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003805 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806{
Al Viro8687b632006-10-19 23:28:48 -07003807 uint32_t len;
3808 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003809 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810
Eric W. Biedermane5782072013-02-01 14:22:02 -08003811 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3813 return -EIO;
3814 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003815 p = xdr_inline_decode(xdr, 4);
3816 if (unlikely(!p))
3817 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003818 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003819 p = xdr_inline_decode(xdr, len);
3820 if (unlikely(!p))
3821 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003822 if (owner_name != NULL) {
3823 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3824 if (owner_name->data != NULL) {
3825 owner_name->len = len;
3826 ret = NFS_ATTR_FATTR_OWNER_NAME;
3827 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003828 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003829 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003830 ret = NFS_ATTR_FATTR_OWNER;
3831 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003833 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003835 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003836 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3838 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003839 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003840 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003841out_overflow:
3842 print_overflow_msg(__func__, xdr);
3843 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844}
3845
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003846static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003847 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003848 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849{
Al Viro8687b632006-10-19 23:28:48 -07003850 uint32_t len;
3851 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003852 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853
Eric W. Biedermane5782072013-02-01 14:22:02 -08003854 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3856 return -EIO;
3857 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003858 p = xdr_inline_decode(xdr, 4);
3859 if (unlikely(!p))
3860 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003861 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003862 p = xdr_inline_decode(xdr, len);
3863 if (unlikely(!p))
3864 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003865 if (group_name != NULL) {
3866 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3867 if (group_name->data != NULL) {
3868 group_name->len = len;
3869 ret = NFS_ATTR_FATTR_GROUP_NAME;
3870 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003871 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003872 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003873 ret = NFS_ATTR_FATTR_GROUP;
3874 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003876 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003878 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003879 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3881 }
Eric W. Biedermane5782072013-02-01 14:22:02 -08003882 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
Trond Myklebust409924e2009-03-11 14:10:27 -04003883 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003884out_overflow:
3885 print_overflow_msg(__func__, xdr);
3886 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887}
3888
3889static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3890{
Al Viro8687b632006-10-19 23:28:48 -07003891 uint32_t major = 0, minor = 0;
3892 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003893 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894
3895 *rdev = MKDEV(0,0);
3896 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3897 return -EIO;
3898 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3899 dev_t tmp;
3900
Benny Halevyc0eae662009-08-14 17:20:14 +03003901 p = xdr_inline_decode(xdr, 8);
3902 if (unlikely(!p))
3903 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003904 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003905 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 tmp = MKDEV(major, minor);
3907 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3908 *rdev = tmp;
3909 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003910 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003912 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003913 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003914out_overflow:
3915 print_overflow_msg(__func__, xdr);
3916 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917}
3918
3919static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3920{
Al Viro8687b632006-10-19 23:28:48 -07003921 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 int status = 0;
3923
3924 *res = 0;
3925 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3926 return -EIO;
3927 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003928 p = xdr_inline_decode(xdr, 8);
3929 if (unlikely(!p))
3930 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003931 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3933 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003934 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003936out_overflow:
3937 print_overflow_msg(__func__, xdr);
3938 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939}
3940
3941static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3942{
Al Viro8687b632006-10-19 23:28:48 -07003943 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 int status = 0;
3945
3946 *res = 0;
3947 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3948 return -EIO;
3949 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003950 p = xdr_inline_decode(xdr, 8);
3951 if (unlikely(!p))
3952 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003953 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3955 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003956 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003958out_overflow:
3959 print_overflow_msg(__func__, xdr);
3960 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961}
3962
3963static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3964{
Al Viro8687b632006-10-19 23:28:48 -07003965 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 int status = 0;
3967
3968 *res = 0;
3969 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3970 return -EIO;
3971 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003972 p = xdr_inline_decode(xdr, 8);
3973 if (unlikely(!p))
3974 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003975 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3977 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003978 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003980out_overflow:
3981 print_overflow_msg(__func__, xdr);
3982 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983}
3984
3985static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3986{
Al Viro8687b632006-10-19 23:28:48 -07003987 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003988 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989
3990 *used = 0;
3991 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3992 return -EIO;
3993 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003994 p = xdr_inline_decode(xdr, 8);
3995 if (unlikely(!p))
3996 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003997 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003999 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004001 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004003 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004004out_overflow:
4005 print_overflow_msg(__func__, xdr);
4006 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007}
4008
4009static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4010{
Al Viro8687b632006-10-19 23:28:48 -07004011 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 uint64_t sec;
4013 uint32_t nsec;
4014
Benny Halevyc0eae662009-08-14 17:20:14 +03004015 p = xdr_inline_decode(xdr, 12);
4016 if (unlikely(!p))
4017 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004018 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004019 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 time->tv_sec = (time_t)sec;
4021 time->tv_nsec = (long)nsec;
4022 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004023out_overflow:
4024 print_overflow_msg(__func__, xdr);
4025 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026}
4027
4028static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4029{
4030 int status = 0;
4031
4032 time->tv_sec = 0;
4033 time->tv_nsec = 0;
4034 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4035 return -EIO;
4036 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4037 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004038 if (status == 0)
4039 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4041 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004042 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 return status;
4044}
4045
4046static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4047{
4048 int status = 0;
4049
4050 time->tv_sec = 0;
4051 time->tv_nsec = 0;
4052 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4053 return -EIO;
4054 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4055 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004056 if (status == 0)
4057 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4059 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004060 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 return status;
4062}
4063
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004064static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4065 struct timespec *time)
4066{
4067 int status = 0;
4068
4069 time->tv_sec = 0;
4070 time->tv_nsec = 0;
4071 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4072 return -EIO;
4073 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4074 status = decode_attr_time(xdr, time);
4075 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4076 }
4077 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4078 (long)time->tv_nsec);
4079 return status;
4080}
4081
David Quigleyaa9c2662013-05-22 12:50:44 -04004082static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4083 struct nfs4_label *label)
4084{
4085 uint32_t pi = 0;
4086 uint32_t lfs = 0;
4087 __u32 len;
4088 __be32 *p;
4089 int status = 0;
4090
4091 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4092 return -EIO;
4093 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4094 p = xdr_inline_decode(xdr, 4);
4095 if (unlikely(!p))
4096 goto out_overflow;
4097 lfs = be32_to_cpup(p++);
4098 p = xdr_inline_decode(xdr, 4);
4099 if (unlikely(!p))
4100 goto out_overflow;
4101 pi = be32_to_cpup(p++);
4102 p = xdr_inline_decode(xdr, 4);
4103 if (unlikely(!p))
4104 goto out_overflow;
4105 len = be32_to_cpup(p++);
4106 p = xdr_inline_decode(xdr, len);
4107 if (unlikely(!p))
4108 goto out_overflow;
4109 if (len < NFS4_MAXLABELLEN) {
4110 if (label) {
4111 memcpy(label->label, p, len);
4112 label->len = len;
4113 label->pi = pi;
4114 label->lfs = lfs;
4115 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4116 }
4117 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4118 } else
4119 printk(KERN_WARNING "%s: label too long (%u)!\n",
4120 __func__, len);
4121 }
4122 if (label && label->label)
4123 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4124 (char *)label->label, label->len, label->pi, label->lfs);
4125 return status;
4126
4127out_overflow:
4128 print_overflow_msg(__func__, xdr);
4129 return -EIO;
4130}
4131
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4133{
4134 int status = 0;
4135
4136 time->tv_sec = 0;
4137 time->tv_nsec = 0;
4138 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4139 return -EIO;
4140 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4141 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004142 if (status == 0)
4143 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4145 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004146 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 return status;
4148}
4149
Trond Myklebust256e48b2012-06-21 11:18:13 -04004150static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151{
4152 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004153 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154
4155 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004156 dprintk("%s: server returned incorrect attribute length: "
4157 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004158 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 attrwords << 2,
4160 (attrwords < nwords) ? '<' : '>',
4161 nwords << 2);
4162 return -EIO;
4163 }
4164 return 0;
4165}
4166
4167static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4168{
Al Viro8687b632006-10-19 23:28:48 -07004169 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170
Benny Halevyc0eae662009-08-14 17:20:14 +03004171 p = xdr_inline_decode(xdr, 20);
4172 if (unlikely(!p))
4173 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004174 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004175 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004176 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004178out_overflow:
4179 print_overflow_msg(__func__, xdr);
4180 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181}
4182
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004183static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184{
Al Viro8687b632006-10-19 23:28:48 -07004185 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 uint32_t supp, acc;
4187 int status;
4188
4189 status = decode_op_hdr(xdr, OP_ACCESS);
4190 if (status)
4191 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004192 p = xdr_inline_decode(xdr, 8);
4193 if (unlikely(!p))
4194 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004195 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004196 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004197 *supported = supp;
4198 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004200out_overflow:
4201 print_overflow_msg(__func__, xdr);
4202 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203}
4204
Benny Halevy07d30432009-08-14 17:19:52 +03004205static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206{
Al Viro8687b632006-10-19 23:28:48 -07004207 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004208
4209 p = xdr_inline_decode(xdr, len);
4210 if (likely(p)) {
4211 memcpy(buf, p, len);
4212 return 0;
4213 }
4214 print_overflow_msg(__func__, xdr);
4215 return -EIO;
4216}
4217
4218static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4219{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004220 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221}
4222
4223static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4224{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225 int status;
4226
4227 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004228 if (status != -EIO)
4229 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004230 if (!status)
4231 status = decode_stateid(xdr, &res->stateid);
4232 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233}
4234
Benny Halevydb942bb2009-08-14 17:19:56 +03004235static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4236{
Chuck Levercd937102012-03-02 17:14:31 -05004237 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238}
4239
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004240static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4241{
4242 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4243}
4244
Fred Isaman0b7c0152012-04-20 14:47:39 -04004245static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 int status;
4248
4249 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004250 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004251 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004252 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253}
4254
4255static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4256{
Al Viro8687b632006-10-19 23:28:48 -07004257 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 uint32_t bmlen;
4259 int status;
4260
4261 status = decode_op_hdr(xdr, OP_CREATE);
4262 if (status)
4263 return status;
4264 if ((status = decode_change_info(xdr, cinfo)))
4265 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004266 p = xdr_inline_decode(xdr, 4);
4267 if (unlikely(!p))
4268 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004269 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004270 p = xdr_inline_decode(xdr, bmlen << 2);
4271 if (likely(p))
4272 return 0;
4273out_overflow:
4274 print_overflow_msg(__func__, xdr);
4275 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276}
4277
4278static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4279{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004280 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004281 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 int status;
4283
4284 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4285 goto xdr_error;
4286 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4287 goto xdr_error;
4288 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4289 goto xdr_error;
4290 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4291 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004292 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4293 &res->fh_expire_type)) != 0)
4294 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4296 goto xdr_error;
4297 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4298 goto xdr_error;
4299 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4300 goto xdr_error;
4301 status = verify_attr_len(xdr, savep, attrlen);
4302xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004303 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304 return status;
4305}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004306
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4308{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004309 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004310 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004312
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4314 goto xdr_error;
4315 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4316 goto xdr_error;
4317 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4318 goto xdr_error;
4319
4320 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4321 goto xdr_error;
4322 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4323 goto xdr_error;
4324 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4325 goto xdr_error;
4326 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4327 goto xdr_error;
4328 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4329 goto xdr_error;
4330 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4331 goto xdr_error;
4332
4333 status = verify_attr_len(xdr, savep, attrlen);
4334xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004335 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 return status;
4337}
4338
4339static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4340{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004341 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004342 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004344
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4346 goto xdr_error;
4347 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4348 goto xdr_error;
4349 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4350 goto xdr_error;
4351
4352 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4353 goto xdr_error;
4354 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4355 goto xdr_error;
4356
4357 status = verify_attr_len(xdr, savep, attrlen);
4358xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004359 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 return status;
4361}
4362
Andy Adamson88034c32012-05-23 05:02:34 -04004363static int decode_threshold_hint(struct xdr_stream *xdr,
4364 uint32_t *bitmap,
4365 uint64_t *res,
4366 uint32_t hint_bit)
4367{
4368 __be32 *p;
4369
4370 *res = 0;
4371 if (likely(bitmap[0] & hint_bit)) {
4372 p = xdr_inline_decode(xdr, 8);
4373 if (unlikely(!p))
4374 goto out_overflow;
4375 xdr_decode_hyper(p, res);
4376 }
4377 return 0;
4378out_overflow:
4379 print_overflow_msg(__func__, xdr);
4380 return -EIO;
4381}
4382
4383static int decode_first_threshold_item4(struct xdr_stream *xdr,
4384 struct nfs4_threshold *res)
4385{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004386 __be32 *p;
4387 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004388 uint32_t bitmap[3] = {0,}, attrlen;
4389 int status;
4390
4391 /* layout type */
4392 p = xdr_inline_decode(xdr, 4);
4393 if (unlikely(!p)) {
4394 print_overflow_msg(__func__, xdr);
4395 return -EIO;
4396 }
4397 res->l_type = be32_to_cpup(p);
4398
4399 /* thi_hintset bitmap */
4400 status = decode_attr_bitmap(xdr, bitmap);
4401 if (status < 0)
4402 goto xdr_error;
4403
4404 /* thi_hintlist length */
4405 status = decode_attr_length(xdr, &attrlen, &savep);
4406 if (status < 0)
4407 goto xdr_error;
4408 /* thi_hintlist */
4409 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4410 if (status < 0)
4411 goto xdr_error;
4412 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4413 if (status < 0)
4414 goto xdr_error;
4415 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4416 THRESHOLD_RD_IO);
4417 if (status < 0)
4418 goto xdr_error;
4419 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4420 THRESHOLD_WR_IO);
4421 if (status < 0)
4422 goto xdr_error;
4423
4424 status = verify_attr_len(xdr, savep, attrlen);
4425 res->bm = bitmap[0];
4426
4427 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4428 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4429 res->wr_io_sz);
4430xdr_error:
4431 dprintk("%s ret=%d!\n", __func__, status);
4432 return status;
4433}
4434
4435/*
4436 * Thresholds on pNFS direct I/O vrs MDS I/O
4437 */
4438static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4439 uint32_t *bitmap,
4440 struct nfs4_threshold *res)
4441{
4442 __be32 *p;
4443 int status = 0;
4444 uint32_t num;
4445
4446 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4447 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004448 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004449 /* Did the server return an unrequested attribute? */
4450 if (unlikely(res == NULL))
4451 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004452 p = xdr_inline_decode(xdr, 4);
4453 if (unlikely(!p))
4454 goto out_overflow;
4455 num = be32_to_cpup(p);
4456 if (num == 0)
4457 return 0;
4458 if (num > 1)
4459 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4460 "drivers per filesystem not supported\n",
4461 __func__);
4462
4463 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004464 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004465 }
4466 return status;
4467out_overflow:
4468 print_overflow_msg(__func__, xdr);
4469 return -EIO;
4470}
4471
Bryan Schumakerae42c702010-10-21 16:33:17 -04004472static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4473 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004474 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004475 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476{
Trond Myklebustbca79472009-03-11 14:10:26 -04004477 int status;
4478 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004479 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004480 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004482 status = decode_attr_type(xdr, bitmap, &type);
4483 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004485 fattr->mode = 0;
4486 if (status != 0) {
4487 fattr->mode |= nfs_type2fmt[type];
4488 fattr->valid |= status;
4489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004491 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
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
4496 status = decode_attr_size(xdr, bitmap, &fattr->size);
4497 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004498 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004499 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004500
4501 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4502 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004504 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004505
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004506 err = 0;
4507 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004508 if (status < 0)
4509 goto xdr_error;
4510
4511 status = decode_attr_filehandle(xdr, bitmap, fh);
4512 if (status < 0)
4513 goto xdr_error;
4514
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004515 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4516 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004518 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004519
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004520 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004521 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004522 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004523 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004524
4525 status = decode_attr_mode(xdr, bitmap, &fmode);
4526 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004528 if (status != 0) {
4529 fattr->mode |= fmode;
4530 fattr->valid |= status;
4531 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004532
4533 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4534 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004536 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004537
Trond Myklebust6926afd2012-01-07 13:22:46 -05004538 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004539 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004540 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004541 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004542
Trond Myklebust6926afd2012-01-07 13:22:46 -05004543 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004544 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004546 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004547
4548 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4549 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004550 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004551 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004552
4553 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4554 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004555 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004556 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004557
4558 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4559 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004561 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004562
4563 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4564 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004565 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004566 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004567
4568 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4569 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004571 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004572
Trond Myklebust28331a42011-04-27 13:47:52 -04004573 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004574 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004575 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004576 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004577
Andy Adamson88034c32012-05-23 05:02:34 -04004578 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4579 if (status < 0)
4580 goto xdr_error;
4581
David Quigleyaa9c2662013-05-22 12:50:44 -04004582 if (label) {
4583 status = decode_attr_security_label(xdr, bitmap, label);
4584 if (status < 0)
4585 goto xdr_error;
4586 fattr->valid |= status;
4587 }
4588
Bryan Schumakerae42c702010-10-21 16:33:17 -04004589xdr_error:
4590 dprintk("%s: xdr returned %d\n", __func__, -status);
4591 return status;
4592}
4593
4594static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004595 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004596 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004597{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004598 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004599 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004600 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004601 int status;
4602
4603 status = decode_op_hdr(xdr, OP_GETATTR);
4604 if (status < 0)
4605 goto xdr_error;
4606
4607 status = decode_attr_bitmap(xdr, bitmap);
4608 if (status < 0)
4609 goto xdr_error;
4610
4611 status = decode_attr_length(xdr, &attrlen, &savep);
4612 if (status < 0)
4613 goto xdr_error;
4614
David Quigleyaa9c2662013-05-22 12:50:44 -04004615 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4616 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004617 if (status < 0)
4618 goto xdr_error;
4619
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004620 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004622 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623 return status;
4624}
4625
David Quigleyaa9c2662013-05-22 12:50:44 -04004626static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4627 struct nfs4_label *label, const struct nfs_server *server)
4628{
4629 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4630}
4631
Bryan Schumakerae42c702010-10-21 16:33:17 -04004632static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004633 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004634{
David Quigleyaa9c2662013-05-22 12:50:44 -04004635 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004636}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637
Andy Adamson504913f2010-10-20 00:17:57 -04004638/*
4639 * Decode potentially multiple layout types. Currently we only support
4640 * one layout driver per file system.
4641 */
4642static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4643 uint32_t *layouttype)
4644{
4645 uint32_t *p;
4646 int num;
4647
4648 p = xdr_inline_decode(xdr, 4);
4649 if (unlikely(!p))
4650 goto out_overflow;
4651 num = be32_to_cpup(p);
4652
4653 /* pNFS is not supported by the underlying file system */
4654 if (num == 0) {
4655 *layouttype = 0;
4656 return 0;
4657 }
4658 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004659 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4660 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004661
4662 /* Decode and set first layout type, move xdr->p past unused types */
4663 p = xdr_inline_decode(xdr, num * 4);
4664 if (unlikely(!p))
4665 goto out_overflow;
4666 *layouttype = be32_to_cpup(p);
4667 return 0;
4668out_overflow:
4669 print_overflow_msg(__func__, xdr);
4670 return -EIO;
4671}
4672
4673/*
4674 * The type of file system exported.
4675 * Note we must ensure that layouttype is set in any non-error case.
4676 */
4677static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4678 uint32_t *layouttype)
4679{
4680 int status = 0;
4681
4682 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4683 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4684 return -EIO;
4685 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4686 status = decode_first_pnfs_layout_type(xdr, layouttype);
4687 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4688 } else
4689 *layouttype = 0;
4690 return status;
4691}
4692
Fred Isamandae100c2011-07-30 20:52:37 -04004693/*
4694 * The prefered block size for layout directed io
4695 */
4696static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4697 uint32_t *res)
4698{
4699 __be32 *p;
4700
4701 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4702 *res = 0;
4703 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4704 p = xdr_inline_decode(xdr, 4);
4705 if (unlikely(!p)) {
4706 print_overflow_msg(__func__, xdr);
4707 return -EIO;
4708 }
4709 *res = be32_to_cpup(p);
4710 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4711 }
4712 return 0;
4713}
4714
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4716{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004717 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004718 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719 int status;
4720
4721 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4722 goto xdr_error;
4723 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4724 goto xdr_error;
4725 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4726 goto xdr_error;
4727
4728 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4729
4730 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4731 goto xdr_error;
4732 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4733 goto xdr_error;
4734 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4735 goto xdr_error;
4736 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4737 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4738 goto xdr_error;
4739 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004740 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4741 if (status != 0)
4742 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004743 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4744 if (status != 0)
4745 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004746 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4747 if (status)
4748 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749
4750 status = verify_attr_len(xdr, savep, attrlen);
4751xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004752 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753 return status;
4754}
4755
4756static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4757{
Al Viro8687b632006-10-19 23:28:48 -07004758 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759 uint32_t len;
4760 int status;
4761
Trond Myklebust99367812007-07-17 21:52:41 -04004762 /* Zero handle first to allow comparisons */
4763 memset(fh, 0, sizeof(*fh));
4764
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765 status = decode_op_hdr(xdr, OP_GETFH);
4766 if (status)
4767 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768
Benny Halevyc0eae662009-08-14 17:20:14 +03004769 p = xdr_inline_decode(xdr, 4);
4770 if (unlikely(!p))
4771 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004772 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773 if (len > NFS4_FHSIZE)
4774 return -EIO;
4775 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004776 p = xdr_inline_decode(xdr, len);
4777 if (unlikely(!p))
4778 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004779 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004781out_overflow:
4782 print_overflow_msg(__func__, xdr);
4783 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004784}
4785
4786static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4787{
4788 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004789
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790 status = decode_op_hdr(xdr, OP_LINK);
4791 if (status)
4792 return status;
4793 return decode_change_info(xdr, cinfo);
4794}
4795
4796/*
4797 * We create the owner, so we know a proper owner.id length is 4.
4798 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004799static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004801 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004802 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004803 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004805 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004806 if (unlikely(!p))
4807 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004808 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004809 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004810 type = be32_to_cpup(p++); /* 4 byte read */
4811 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004812 fl->fl_start = (loff_t)offset;
4813 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4814 if (length == ~(uint64_t)0)
4815 fl->fl_end = OFFSET_MAX;
4816 fl->fl_type = F_WRLCK;
4817 if (type & 1)
4818 fl->fl_type = F_RDLCK;
4819 fl->fl_pid = 0;
4820 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004821 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4822 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4823 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004824 if (likely(p))
4825 return -NFS4ERR_DENIED;
4826out_overflow:
4827 print_overflow_msg(__func__, xdr);
4828 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829}
4830
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004831static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833 int status;
4834
4835 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004836 if (status == -EIO)
4837 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004839 status = decode_stateid(xdr, &res->stateid);
4840 if (unlikely(status))
4841 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004843 status = decode_lock_denied(xdr, NULL);
4844 if (res->open_seqid != NULL)
4845 nfs_increment_open_seqid(status, res->open_seqid);
4846 nfs_increment_lock_seqid(status, res->lock_seqid);
4847out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 return status;
4849}
4850
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004851static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004852{
4853 int status;
4854 status = decode_op_hdr(xdr, OP_LOCKT);
4855 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004856 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857 return status;
4858}
4859
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004860static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862 int status;
4863
4864 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004865 if (status != -EIO)
4866 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004867 if (status == 0)
4868 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869 return status;
4870}
4871
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004872static int decode_release_lockowner(struct xdr_stream *xdr)
4873{
4874 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4875}
4876
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877static int decode_lookup(struct xdr_stream *xdr)
4878{
4879 return decode_op_hdr(xdr, OP_LOOKUP);
4880}
4881
4882/* This is too sick! */
4883static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4884{
Andy Adamson05d564f2008-12-23 16:06:15 -05004885 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886 uint32_t limit_type, nblocks, blocksize;
4887
Benny Halevyc0eae662009-08-14 17:20:14 +03004888 p = xdr_inline_decode(xdr, 12);
4889 if (unlikely(!p))
4890 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004891 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004892 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004893 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004894 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004895 break;
4896 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004897 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004898 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004899 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 }
4901 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004902out_overflow:
4903 print_overflow_msg(__func__, xdr);
4904 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905}
4906
4907static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4908{
Andy Adamson05d564f2008-12-23 16:06:15 -05004909 __be32 *p;
4910 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004911 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912
Benny Halevyc0eae662009-08-14 17:20:14 +03004913 p = xdr_inline_decode(xdr, 4);
4914 if (unlikely(!p))
4915 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004916 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4918 res->delegation_type = 0;
4919 return 0;
4920 }
Benny Halevy07d30432009-08-14 17:19:52 +03004921 status = decode_stateid(xdr, &res->delegation);
4922 if (unlikely(status))
4923 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004924 p = xdr_inline_decode(xdr, 4);
4925 if (unlikely(!p))
4926 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004927 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004928
Linus Torvalds1da177e2005-04-16 15:20:36 -07004929 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004930 case NFS4_OPEN_DELEGATE_READ:
4931 res->delegation_type = FMODE_READ;
4932 break;
4933 case NFS4_OPEN_DELEGATE_WRITE:
4934 res->delegation_type = FMODE_WRITE|FMODE_READ;
4935 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936 return -EIO;
4937 }
David Howells7539bba2006-08-22 20:06:09 -04004938 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004939out_overflow:
4940 print_overflow_msg(__func__, xdr);
4941 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004942}
4943
4944static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4945{
Andy Adamson05d564f2008-12-23 16:06:15 -05004946 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004947 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004948 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004949
Andy Adamson05d564f2008-12-23 16:06:15 -05004950 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004951 if (status != -EIO)
4952 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004953 if (!status)
4954 status = decode_stateid(xdr, &res->stateid);
4955 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004956 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957
Andy Adamson05d564f2008-12-23 16:06:15 -05004958 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959
Benny Halevyc0eae662009-08-14 17:20:14 +03004960 p = xdr_inline_decode(xdr, 8);
4961 if (unlikely(!p))
4962 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004963 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004964 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004965 if (bmlen > 10)
4966 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967
Benny Halevyc0eae662009-08-14 17:20:14 +03004968 p = xdr_inline_decode(xdr, bmlen << 2);
4969 if (unlikely(!p))
4970 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004971 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4972 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004973 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004974 for (; i < NFS4_BITMAP_SIZE; i++)
4975 res->attrset[i] = 0;
4976
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977 return decode_delegation(xdr, res);
4978xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004979 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004981out_overflow:
4982 print_overflow_msg(__func__, xdr);
4983 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984}
4985
4986static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4987{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988 int status;
4989
Andy Adamson05d564f2008-12-23 16:06:15 -05004990 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004991 if (status != -EIO)
4992 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004993 if (!status)
4994 status = decode_stateid(xdr, &res->stateid);
4995 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996}
4997
4998static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4999{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000 int status;
5001
5002 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005003 if (status != -EIO)
5004 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005005 if (!status)
5006 status = decode_stateid(xdr, &res->stateid);
5007 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008}
5009
5010static int decode_putfh(struct xdr_stream *xdr)
5011{
5012 return decode_op_hdr(xdr, OP_PUTFH);
5013}
5014
5015static int decode_putrootfh(struct xdr_stream *xdr)
5016{
5017 return decode_op_hdr(xdr, OP_PUTROOTFH);
5018}
5019
5020static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
5021{
Al Viro8687b632006-10-19 23:28:48 -07005022 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005023 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024 int status;
5025
5026 status = decode_op_hdr(xdr, OP_READ);
5027 if (status)
5028 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005029 p = xdr_inline_decode(xdr, 8);
5030 if (unlikely(!p))
5031 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005032 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005033 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005034 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005036 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005037 "count %u > recvd %u\n", count, recvd);
5038 count = recvd;
5039 eof = 0;
5040 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041 res->eof = eof;
5042 res->count = count;
5043 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005044out_overflow:
5045 print_overflow_msg(__func__, xdr);
5046 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047}
5048
5049static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5050{
Chuck Leverbcecff72007-10-26 13:32:03 -04005051 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005052 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053
5054 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005055 if (!status)
5056 status = decode_verifier(xdr, readdir->verifier.data);
5057 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005059 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005060 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005061 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005062 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063}
5064
5065static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5066{
5067 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005068 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005069 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005070 int status;
5071
5072 status = decode_op_hdr(xdr, OP_READLINK);
5073 if (status)
5074 return status;
5075
5076 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005077 p = xdr_inline_decode(xdr, 4);
5078 if (unlikely(!p))
5079 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005080 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005082 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083 return -ENAMETOOLONG;
5084 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005085 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005087 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 "count %u > recvd %u\n", len, recvd);
5089 return -EIO;
5090 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 /*
5092 * The XDR encode routine has set things up so that
5093 * the link text will be copied directly into the
5094 * buffer. We just have to do overflow-checking,
5095 * and and null-terminate the text (the VFS expects
5096 * null-termination).
5097 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005098 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005100out_overflow:
5101 print_overflow_msg(__func__, xdr);
5102 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103}
5104
5105static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5106{
5107 int status;
5108
5109 status = decode_op_hdr(xdr, OP_REMOVE);
5110 if (status)
5111 goto out;
5112 status = decode_change_info(xdr, cinfo);
5113out:
5114 return status;
5115}
5116
5117static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5118 struct nfs4_change_info *new_cinfo)
5119{
5120 int status;
5121
5122 status = decode_op_hdr(xdr, OP_RENAME);
5123 if (status)
5124 goto out;
5125 if ((status = decode_change_info(xdr, old_cinfo)))
5126 goto out;
5127 status = decode_change_info(xdr, new_cinfo);
5128out:
5129 return status;
5130}
5131
5132static int decode_renew(struct xdr_stream *xdr)
5133{
5134 return decode_op_hdr(xdr, OP_RENEW);
5135}
5136
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005137static int
5138decode_restorefh(struct xdr_stream *xdr)
5139{
5140 return decode_op_hdr(xdr, OP_RESTOREFH);
5141}
5142
J. Bruce Fields029d1052005-06-22 17:16:22 +00005143static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005144 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005145{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005146 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005147 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005148 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005149 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005150 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005151
Andy Adamsonbf118a32011-12-07 11:55:27 -05005152 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005153 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5154 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005155
Trond Myklebust519d3952012-08-14 17:30:10 -04005156 xdr_enter_page(xdr, xdr->buf->page_len);
5157
Trond Myklebustcff298c2012-08-14 17:14:17 -04005158 /* Calculate the offset of the page data */
5159 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005160
J. Bruce Fields029d1052005-06-22 17:16:22 +00005161 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5162 goto out;
5163 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5164 goto out;
5165
5166 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5167 return -EIO;
5168 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005169
Andy Adamsonbf118a32011-12-07 11:55:27 -05005170 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5171 * are stored with the acl data to handle the problem of
5172 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005173 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005174 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005175
5176 /* Check for receive buffer overflow */
5177 if (res->acl_len > (xdr->nwords << 2) ||
5178 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5179 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005180 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005181 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005182 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005183 } else
5184 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005185
5186out:
5187 return status;
5188}
5189
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190static int
5191decode_savefh(struct xdr_stream *xdr)
5192{
5193 return decode_op_hdr(xdr, OP_SAVEFH);
5194}
5195
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005196static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197{
Al Viro8687b632006-10-19 23:28:48 -07005198 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199 uint32_t bmlen;
5200 int status;
5201
Linus Torvalds1da177e2005-04-16 15:20:36 -07005202 status = decode_op_hdr(xdr, OP_SETATTR);
5203 if (status)
5204 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005205 p = xdr_inline_decode(xdr, 4);
5206 if (unlikely(!p))
5207 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005208 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005209 p = xdr_inline_decode(xdr, bmlen << 2);
5210 if (likely(p))
5211 return 0;
5212out_overflow:
5213 print_overflow_msg(__func__, xdr);
5214 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215}
5216
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005217static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218{
Al Viro8687b632006-10-19 23:28:48 -07005219 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 uint32_t opnum;
5221 int32_t nfserr;
5222
Benny Halevyc0eae662009-08-14 17:20:14 +03005223 p = xdr_inline_decode(xdr, 8);
5224 if (unlikely(!p))
5225 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005226 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005228 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005229 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230 return -EIO;
5231 }
Benny Halevycccddf42009-08-14 17:20:19 +03005232 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005234 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5235 if (unlikely(!p))
5236 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005237 p = xdr_decode_hyper(p, &res->clientid);
5238 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239 } else if (nfserr == NFSERR_CLID_INUSE) {
5240 uint32_t len;
5241
5242 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005243 p = xdr_inline_decode(xdr, 4);
5244 if (unlikely(!p))
5245 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005246 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005247 p = xdr_inline_decode(xdr, len);
5248 if (unlikely(!p))
5249 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250
5251 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005252 p = xdr_inline_decode(xdr, 4);
5253 if (unlikely(!p))
5254 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005255 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005256 p = xdr_inline_decode(xdr, len);
5257 if (unlikely(!p))
5258 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005259 return -NFSERR_CLID_INUSE;
5260 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005261 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262
5263 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005264out_overflow:
5265 print_overflow_msg(__func__, xdr);
5266 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267}
5268
5269static int decode_setclientid_confirm(struct xdr_stream *xdr)
5270{
5271 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5272}
5273
5274static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5275{
Al Viro8687b632006-10-19 23:28:48 -07005276 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277 int status;
5278
5279 status = decode_op_hdr(xdr, OP_WRITE);
5280 if (status)
5281 return status;
5282
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005283 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005284 if (unlikely(!p))
5285 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005286 res->count = be32_to_cpup(p++);
5287 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005288 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005289out_overflow:
5290 print_overflow_msg(__func__, xdr);
5291 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005292}
5293
5294static int decode_delegreturn(struct xdr_stream *xdr)
5295{
5296 return decode_op_hdr(xdr, OP_DELEGRETURN);
5297}
5298
Chuck Leverfb15b262013-03-16 15:54:34 -04005299static int decode_secinfo_gss(struct xdr_stream *xdr,
5300 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005301{
Chuck Leverfb15b262013-03-16 15:54:34 -04005302 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005303 __be32 *p;
5304
5305 p = xdr_inline_decode(xdr, 4);
5306 if (unlikely(!p))
5307 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005308 oid_len = be32_to_cpup(p);
5309 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005310 goto out_err;
5311
Chuck Leverfb15b262013-03-16 15:54:34 -04005312 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005313 if (unlikely(!p))
5314 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005315 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5316 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005317
5318 p = xdr_inline_decode(xdr, 8);
5319 if (unlikely(!p))
5320 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005321 flavor->flavor_info.qop = be32_to_cpup(p++);
5322 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005323
5324 return 0;
5325
5326out_overflow:
5327 print_overflow_msg(__func__, xdr);
5328 return -EIO;
5329out_err:
5330 return -EINVAL;
5331}
5332
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005333static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005334{
Chuck Leverfb15b262013-03-16 15:54:34 -04005335 struct nfs4_secinfo4 *sec_flavor;
5336 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005337 int status;
5338 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005339
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005340 p = xdr_inline_decode(xdr, 4);
5341 if (unlikely(!p))
5342 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005343
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005344 res->flavors->num_flavors = 0;
5345 num_flavors = be32_to_cpup(p);
5346
5347 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005348 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005349 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005350 break;
5351
5352 p = xdr_inline_decode(xdr, 4);
5353 if (unlikely(!p))
5354 goto out_overflow;
5355 sec_flavor->flavor = be32_to_cpup(p);
5356
5357 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005358 status = decode_secinfo_gss(xdr, sec_flavor);
5359 if (status)
5360 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005361 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005362 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005363 }
5364
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005365 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005366out:
5367 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005368out_overflow:
5369 print_overflow_msg(__func__, xdr);
5370 return -EIO;
5371}
5372
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005373static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5374{
5375 int status = decode_op_hdr(xdr, OP_SECINFO);
5376 if (status)
5377 return status;
5378 return decode_secinfo_common(xdr, res);
5379}
5380
Benny Halevy99fe60d2009-04-01 09:22:29 -04005381#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005382static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5383{
5384 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5385 if (status)
5386 return status;
5387 return decode_secinfo_common(xdr, res);
5388}
5389
Benny Halevy99fe60d2009-04-01 09:22:29 -04005390static int decode_exchange_id(struct xdr_stream *xdr,
5391 struct nfs41_exchange_id_res *res)
5392{
5393 __be32 *p;
5394 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005395 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005396 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005397 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005398
5399 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5400 if (status)
5401 return status;
5402
Benny Halevyc0eae662009-08-14 17:20:14 +03005403 p = xdr_inline_decode(xdr, 8);
5404 if (unlikely(!p))
5405 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005406 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005407 p = xdr_inline_decode(xdr, 12);
5408 if (unlikely(!p))
5409 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005410 res->seqid = be32_to_cpup(p++);
5411 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005412
5413 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005414 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005415 if (dummy != SP4_NONE)
5416 return -EIO;
5417
Chuck Leveracdeb692012-05-21 22:46:16 -04005418 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005419 p = xdr_inline_decode(xdr, 8);
5420 if (unlikely(!p))
5421 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005422 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005423
Chuck Leveracdeb692012-05-21 22:46:16 -04005424 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005425 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5426 if (unlikely(status))
5427 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005428 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5429 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005430 memcpy(res->server_owner->major_id, dummy_str, dummy);
5431 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005432
Chuck Leveracdeb692012-05-21 22:46:16 -04005433 /* server_scope4 */
5434 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5435 if (unlikely(status))
5436 return status;
5437 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5438 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005439 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5440 res->server_scope->server_scope_sz = dummy;
5441
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005442 /* Implementation Id */
5443 p = xdr_inline_decode(xdr, 4);
5444 if (unlikely(!p))
5445 goto out_overflow;
5446 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005447
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005448 if (impl_id_count) {
5449 /* nii_domain */
5450 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5451 if (unlikely(status))
5452 return status;
5453 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5454 return -EIO;
5455 memcpy(res->impl_id->domain, dummy_str, dummy);
5456
5457 /* nii_name */
5458 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5459 if (unlikely(status))
5460 return status;
5461 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5462 return -EIO;
5463 memcpy(res->impl_id->name, dummy_str, dummy);
5464
5465 /* nii_date */
5466 p = xdr_inline_decode(xdr, 12);
5467 if (unlikely(!p))
5468 goto out_overflow;
5469 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5470 res->impl_id->date.nseconds = be32_to_cpup(p);
5471
5472 /* if there's more than one entry, ignore the rest */
5473 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005474 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005475out_overflow:
5476 print_overflow_msg(__func__, xdr);
5477 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005478}
Andy Adamsonfc931582009-04-01 09:22:31 -04005479
5480static int decode_chan_attrs(struct xdr_stream *xdr,
5481 struct nfs4_channel_attrs *attrs)
5482{
5483 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005484 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005485
Benny Halevyc0eae662009-08-14 17:20:14 +03005486 p = xdr_inline_decode(xdr, 28);
5487 if (unlikely(!p))
5488 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005489 val = be32_to_cpup(p++); /* headerpadsz */
5490 if (val)
5491 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005492 attrs->max_rqst_sz = be32_to_cpup(p++);
5493 attrs->max_resp_sz = be32_to_cpup(p++);
5494 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5495 attrs->max_ops = be32_to_cpup(p++);
5496 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005497 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005498 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005499 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5500 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005501 return -EINVAL;
5502 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005503 if (nr_attrs == 1) {
5504 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5505 if (unlikely(!p))
5506 goto out_overflow;
5507 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005508 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005509out_overflow:
5510 print_overflow_msg(__func__, xdr);
5511 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005512}
5513
Benny Halevye78291e2009-08-14 17:20:00 +03005514static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5515{
5516 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005517}
5518
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005519static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5520 struct nfs41_bind_conn_to_session_res *res)
5521{
5522 __be32 *p;
5523 int status;
5524
5525 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5526 if (!status)
5527 status = decode_sessionid(xdr, &res->session->sess_id);
5528 if (unlikely(status))
5529 return status;
5530
5531 /* dir flags, rdma mode bool */
5532 p = xdr_inline_decode(xdr, 8);
5533 if (unlikely(!p))
5534 goto out_overflow;
5535
5536 res->dir = be32_to_cpup(p++);
5537 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5538 return -EIO;
5539 if (be32_to_cpup(p) == 0)
5540 res->use_conn_in_rdma_mode = false;
5541 else
5542 res->use_conn_in_rdma_mode = true;
5543
5544 return 0;
5545out_overflow:
5546 print_overflow_msg(__func__, xdr);
5547 return -EIO;
5548}
5549
Andy Adamsonfc931582009-04-01 09:22:31 -04005550static int decode_create_session(struct xdr_stream *xdr,
5551 struct nfs41_create_session_res *res)
5552{
5553 __be32 *p;
5554 int status;
5555 struct nfs_client *clp = res->client;
5556 struct nfs4_session *session = clp->cl_session;
5557
5558 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005559 if (!status)
5560 status = decode_sessionid(xdr, &session->sess_id);
5561 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005562 return status;
5563
Andy Adamsonfc931582009-04-01 09:22:31 -04005564 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005565 p = xdr_inline_decode(xdr, 8);
5566 if (unlikely(!p))
5567 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005568 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005569 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005570
5571 /* Channel attributes */
5572 status = decode_chan_attrs(xdr, &session->fc_attrs);
5573 if (!status)
5574 status = decode_chan_attrs(xdr, &session->bc_attrs);
5575 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005576out_overflow:
5577 print_overflow_msg(__func__, xdr);
5578 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005579}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005580
5581static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5582{
5583 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5584}
Ricardo Labiaga18019752009-12-05 16:08:40 -05005585
Trond Myklebust66245532012-05-25 17:18:09 -04005586static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5587{
5588 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5589}
5590
Ricardo Labiaga18019752009-12-05 16:08:40 -05005591static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5592{
5593 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5594}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005595#endif /* CONFIG_NFS_V4_1 */
5596
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005597static int decode_sequence(struct xdr_stream *xdr,
5598 struct nfs4_sequence_res *res,
5599 struct rpc_rqst *rqstp)
5600{
5601#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005602 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005603 struct nfs4_sessionid id;
5604 u32 dummy;
5605 int status;
5606 __be32 *p;
5607
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005608 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005609 return 0;
5610
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005611 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005612 if (!status)
5613 status = decode_sessionid(xdr, &id);
5614 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005615 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005616
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005617 /*
5618 * If the server returns different values for sessionID, slotID or
5619 * sequence number, the server is looney tunes.
5620 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005621 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005622 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005623
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005624 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005625 NFS4_MAX_SESSIONID_LEN)) {
5626 dprintk("%s Invalid session id\n", __func__);
5627 goto out_err;
5628 }
Benny Halevye78291e2009-08-14 17:20:00 +03005629
Benny Halevyc0eae662009-08-14 17:20:14 +03005630 p = xdr_inline_decode(xdr, 20);
5631 if (unlikely(!p))
5632 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005633
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005634 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005635 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005636 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005637 dprintk("%s Invalid sequence number\n", __func__);
5638 goto out_err;
5639 }
5640 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005641 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005642 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005643 dprintk("%s Invalid slot id\n", __func__);
5644 goto out_err;
5645 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005646 /* highest slot id */
5647 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005648 /* target highest slot id */
5649 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005650 /* result flags */
5651 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005652 status = 0;
5653out_err:
5654 res->sr_status = status;
5655 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005656out_overflow:
5657 print_overflow_msg(__func__, xdr);
5658 status = -EIO;
5659 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005660#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005661 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005662#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005663}
5664
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005665#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005666/*
5667 * TODO: Need to handle case when EOF != true;
5668 */
5669static int decode_getdevicelist(struct xdr_stream *xdr,
5670 struct pnfs_devicelist *res)
5671{
5672 __be32 *p;
5673 int status, i;
Trond Myklebust98d94522012-06-08 12:01:14 -04005674 nfs4_verifier verftemp;
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005675
5676 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5677 if (status)
5678 return status;
5679
5680 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5681 if (unlikely(!p))
5682 goto out_overflow;
5683
5684 /* TODO: Skip cookie for now */
5685 p += 2;
5686
5687 /* Read verifier */
Trond Myklebust98d94522012-06-08 12:01:14 -04005688 p = xdr_decode_opaque_fixed(p, verftemp.data, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005689
5690 res->num_devs = be32_to_cpup(p);
5691
5692 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5693
5694 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005695 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005696 __func__, res->num_devs);
5697 return -EIO;
5698 }
5699
5700 p = xdr_inline_decode(xdr,
5701 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5702 if (unlikely(!p))
5703 goto out_overflow;
5704 for (i = 0; i < res->num_devs; i++)
5705 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5706 NFS4_DEVICEID4_SIZE);
5707 res->eof = be32_to_cpup(p);
5708 return 0;
5709out_overflow:
5710 print_overflow_msg(__func__, xdr);
5711 return -EIO;
5712}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005713
5714static int decode_getdeviceinfo(struct xdr_stream *xdr,
5715 struct pnfs_device *pdev)
5716{
5717 __be32 *p;
5718 uint32_t len, type;
5719 int status;
5720
5721 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5722 if (status) {
5723 if (status == -ETOOSMALL) {
5724 p = xdr_inline_decode(xdr, 4);
5725 if (unlikely(!p))
5726 goto out_overflow;
5727 pdev->mincount = be32_to_cpup(p);
5728 dprintk("%s: Min count too small. mincnt = %u\n",
5729 __func__, pdev->mincount);
5730 }
5731 return status;
5732 }
5733
5734 p = xdr_inline_decode(xdr, 8);
5735 if (unlikely(!p))
5736 goto out_overflow;
5737 type = be32_to_cpup(p++);
5738 if (type != pdev->layout_type) {
5739 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5740 __func__, pdev->layout_type, type);
5741 return -EINVAL;
5742 }
5743 /*
5744 * Get the length of the opaque device_addr4. xdr_read_pages places
5745 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5746 * and places the remaining xdr data in xdr_buf->tail
5747 */
5748 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005749 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5750 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005751
5752 /* Parse notification bitmap, verifying that it is zero. */
5753 p = xdr_inline_decode(xdr, 4);
5754 if (unlikely(!p))
5755 goto out_overflow;
5756 len = be32_to_cpup(p);
5757 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005758 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005759
5760 p = xdr_inline_decode(xdr, 4 * len);
5761 if (unlikely(!p))
5762 goto out_overflow;
5763 for (i = 0; i < len; i++, p++) {
5764 if (be32_to_cpup(p)) {
5765 dprintk("%s: notifications not supported\n",
5766 __func__);
5767 return -EIO;
5768 }
5769 }
5770 }
5771 return 0;
5772out_overflow:
5773 print_overflow_msg(__func__, xdr);
5774 return -EIO;
5775}
5776
5777static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5778 struct nfs4_layoutget_res *res)
5779{
5780 __be32 *p;
5781 int status;
5782 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005783 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005784
5785 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5786 if (status)
5787 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005788 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005789 if (unlikely(!p))
5790 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005791 res->return_on_close = be32_to_cpup(p);
5792 decode_stateid(xdr, &res->stateid);
5793 p = xdr_inline_decode(xdr, 4);
5794 if (unlikely(!p))
5795 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005796 layout_count = be32_to_cpup(p);
5797 if (!layout_count) {
5798 dprintk("%s: server responded with empty layout array\n",
5799 __func__);
5800 return -EINVAL;
5801 }
5802
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005803 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005804 if (unlikely(!p))
5805 goto out_overflow;
5806 p = xdr_decode_hyper(p, &res->range.offset);
5807 p = xdr_decode_hyper(p, &res->range.length);
5808 res->range.iomode = be32_to_cpup(p++);
5809 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005810 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005811
5812 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5813 __func__,
5814 (unsigned long)res->range.offset,
5815 (unsigned long)res->range.length,
5816 res->range.iomode,
5817 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005818 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005819
Trond Myklebust64bd5772012-06-20 22:35:05 -04005820 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005821 if (res->layoutp->len > recvd) {
5822 dprintk("NFS: server cheating in layoutget reply: "
5823 "layout len %u > recvd %u\n",
5824 res->layoutp->len, recvd);
5825 return -EINVAL;
5826 }
5827
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005828 if (layout_count > 1) {
5829 /* We only handle a length one array at the moment. Any
5830 * further entries are just ignored. Note that this means
5831 * the client may see a response that is less than the
5832 * minimum it requested.
5833 */
5834 dprintk("%s: server responded with %d layouts, dropping tail\n",
5835 __func__, layout_count);
5836 }
5837
5838 return 0;
5839out_overflow:
5840 print_overflow_msg(__func__, xdr);
5841 return -EIO;
5842}
Andy Adamson863a3c62011-03-23 13:27:54 +00005843
Benny Halevycbe82602011-05-22 19:52:37 +03005844static int decode_layoutreturn(struct xdr_stream *xdr,
5845 struct nfs4_layoutreturn_res *res)
5846{
5847 __be32 *p;
5848 int status;
5849
5850 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5851 if (status)
5852 return status;
5853 p = xdr_inline_decode(xdr, 4);
5854 if (unlikely(!p))
5855 goto out_overflow;
5856 res->lrs_present = be32_to_cpup(p);
5857 if (res->lrs_present)
5858 status = decode_stateid(xdr, &res->stateid);
5859 return status;
5860out_overflow:
5861 print_overflow_msg(__func__, xdr);
5862 return -EIO;
5863}
5864
Andy Adamson863a3c62011-03-23 13:27:54 +00005865static int decode_layoutcommit(struct xdr_stream *xdr,
5866 struct rpc_rqst *req,
5867 struct nfs4_layoutcommit_res *res)
5868{
5869 __be32 *p;
5870 __u32 sizechanged;
5871 int status;
5872
5873 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005874 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005875 if (status)
5876 return status;
5877
5878 p = xdr_inline_decode(xdr, 4);
5879 if (unlikely(!p))
5880 goto out_overflow;
5881 sizechanged = be32_to_cpup(p);
5882
5883 if (sizechanged) {
5884 /* throw away new size */
5885 p = xdr_inline_decode(xdr, 8);
5886 if (unlikely(!p))
5887 goto out_overflow;
5888 }
5889 return 0;
5890out_overflow:
5891 print_overflow_msg(__func__, xdr);
5892 return -EIO;
5893}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005894
5895static int decode_test_stateid(struct xdr_stream *xdr,
5896 struct nfs41_test_stateid_res *res)
5897{
5898 __be32 *p;
5899 int status;
5900 int num_res;
5901
5902 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5903 if (status)
5904 return status;
5905
5906 p = xdr_inline_decode(xdr, 4);
5907 if (unlikely(!p))
5908 goto out_overflow;
5909 num_res = be32_to_cpup(p++);
5910 if (num_res != 1)
5911 goto out;
5912
5913 p = xdr_inline_decode(xdr, 4);
5914 if (unlikely(!p))
5915 goto out_overflow;
5916 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005917
5918 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005919out_overflow:
5920 print_overflow_msg(__func__, xdr);
5921out:
5922 return -EIO;
5923}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005924
5925static int decode_free_stateid(struct xdr_stream *xdr,
5926 struct nfs41_free_stateid_res *res)
5927{
5928 __be32 *p;
5929 int status;
5930
5931 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5932 if (status)
5933 return status;
5934
5935 p = xdr_inline_decode(xdr, 4);
5936 if (unlikely(!p))
5937 goto out_overflow;
5938 res->status = be32_to_cpup(p++);
5939 return res->status;
5940out_overflow:
5941 print_overflow_msg(__func__, xdr);
5942 return -EIO;
5943}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005944#endif /* CONFIG_NFS_V4_1 */
5945
Linus Torvalds1da177e2005-04-16 15:20:36 -07005946/*
Benny Halevy49c25592008-12-23 16:06:16 -05005947 * END OF "GENERIC" DECODE ROUTINES.
5948 */
5949
5950/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951 * Decode OPEN_DOWNGRADE response
5952 */
Chuck Leverbf269552010-12-14 14:59:29 +00005953static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5954 struct xdr_stream *xdr,
5955 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005956{
Andy Adamson05d564f2008-12-23 16:06:15 -05005957 struct compound_hdr hdr;
5958 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005959
Chuck Leverbf269552010-12-14 14:59:29 +00005960 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005961 if (status)
5962 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005963 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005964 if (status)
5965 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005966 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005967 if (status)
5968 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005970 if (status != 0)
5971 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005972 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005973out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005974 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005975}
5976
5977/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005978 * Decode ACCESS response
5979 */
Chuck Leverbf269552010-12-14 14:59:29 +00005980static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5981 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005983 struct compound_hdr hdr;
5984 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005985
Chuck Leverbf269552010-12-14 14:59:29 +00005986 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005987 if (status)
5988 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005989 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005990 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005991 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005992 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005993 if (status != 0)
5994 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04005995 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04005996 if (status != 0)
5997 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005998 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999out:
6000 return status;
6001}
6002
6003/*
6004 * Decode LOOKUP response
6005 */
Chuck Leverbf269552010-12-14 14:59:29 +00006006static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6007 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006009 struct compound_hdr hdr;
6010 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006011
Chuck Leverbf269552010-12-14 14:59:29 +00006012 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006013 if (status)
6014 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006015 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006016 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006017 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006018 status = decode_putfh(xdr);
6019 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006021 status = decode_lookup(xdr);
6022 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006023 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006024 status = decode_getfh(xdr, res->fh);
6025 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006026 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006027 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006028out:
6029 return status;
6030}
6031
6032/*
6033 * Decode LOOKUP_ROOT response
6034 */
Chuck Leverbf269552010-12-14 14:59:29 +00006035static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6036 struct xdr_stream *xdr,
6037 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006038{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039 struct compound_hdr hdr;
6040 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006041
Chuck Leverbf269552010-12-14 14:59:29 +00006042 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006043 if (status)
6044 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006045 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006046 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006048 status = decode_putrootfh(xdr);
6049 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006050 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006051 status = decode_getfh(xdr, res->fh);
6052 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006053 status = decode_getfattr_label(xdr, res->fattr,
6054 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055out:
6056 return status;
6057}
6058
6059/*
6060 * Decode REMOVE response
6061 */
Chuck Leverbf269552010-12-14 14:59:29 +00006062static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6063 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006064{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065 struct compound_hdr hdr;
6066 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006067
Chuck Leverbf269552010-12-14 14:59:29 +00006068 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006069 if (status)
6070 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006071 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006072 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006074 status = decode_putfh(xdr);
6075 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006076 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006077 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006078out:
6079 return status;
6080}
6081
6082/*
6083 * Decode RENAME response
6084 */
Chuck Leverbf269552010-12-14 14:59:29 +00006085static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6086 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006087{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006088 struct compound_hdr hdr;
6089 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006090
Chuck Leverbf269552010-12-14 14:59:29 +00006091 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006092 if (status)
6093 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006094 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006095 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006097 status = decode_putfh(xdr);
6098 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006100 status = decode_savefh(xdr);
6101 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006102 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006103 status = decode_putfh(xdr);
6104 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006105 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006106 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107out:
6108 return status;
6109}
6110
6111/*
6112 * Decode LINK response
6113 */
Chuck Leverbf269552010-12-14 14:59:29 +00006114static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6115 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117 struct compound_hdr hdr;
6118 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006119
Chuck Leverbf269552010-12-14 14:59:29 +00006120 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006121 if (status)
6122 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006123 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006124 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006126 status = decode_putfh(xdr);
6127 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006129 status = decode_savefh(xdr);
6130 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006131 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006132 status = decode_putfh(xdr);
6133 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006134 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006135 status = decode_link(xdr, &res->cinfo);
6136 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006137 goto out;
6138 /*
6139 * Note order: OP_LINK leaves the directory as the current
6140 * filehandle.
6141 */
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_restorefh(xdr);
6143 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006144 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006145 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146out:
6147 return status;
6148}
6149
6150/*
6151 * Decode CREATE response
6152 */
Chuck Leverbf269552010-12-14 14:59:29 +00006153static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6154 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006156 struct compound_hdr hdr;
6157 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006158
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006160 if (status)
6161 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006162 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006163 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_putfh(xdr);
6166 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006168 status = decode_create(xdr, &res->dir_cinfo);
6169 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006171 status = decode_getfh(xdr, res->fh);
6172 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006174 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175out:
6176 return status;
6177}
6178
6179/*
6180 * Decode SYMLINK response
6181 */
Chuck Leverbf269552010-12-14 14:59:29 +00006182static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6183 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184{
Chuck Leverbf269552010-12-14 14:59:29 +00006185 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186}
6187
6188/*
6189 * Decode GETATTR response
6190 */
Chuck Leverbf269552010-12-14 14:59:29 +00006191static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6192 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194 struct compound_hdr hdr;
6195 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006196
Chuck Leverbf269552010-12-14 14:59:29 +00006197 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198 if (status)
6199 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006200 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006201 if (status)
6202 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006203 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204 if (status)
6205 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006206 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207out:
6208 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209}
6210
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006211/*
6212 * Encode an SETACL request
6213 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006214static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6215 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006216{
Andy Adamson05d564f2008-12-23 16:06:15 -05006217 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006218 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006219 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006220
Chuck Lever9f06c712010-12-14 14:59:18 +00006221 encode_compound_hdr(xdr, req, &hdr);
6222 encode_sequence(xdr, &args->seq_args, &hdr);
6223 encode_putfh(xdr, args->fh, &hdr);
6224 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006225 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006226}
Andy Adamson05d564f2008-12-23 16:06:15 -05006227
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006228/*
6229 * Decode SETACL response
6230 */
6231static int
Chuck Leverbf269552010-12-14 14:59:29 +00006232nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006233 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006234{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006235 struct compound_hdr hdr;
6236 int status;
6237
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006239 if (status)
6240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006242 if (status)
6243 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006244 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006245 if (status)
6246 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006247 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006248out:
6249 return status;
6250}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251
6252/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006253 * Decode GETACL response
6254 */
6255static int
Chuck Leverbf269552010-12-14 14:59:29 +00006256nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006257 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006258{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006259 struct compound_hdr hdr;
6260 int status;
6261
Trond Myklebust331818f2012-02-03 18:30:53 -05006262 if (res->acl_scratch != NULL) {
6263 void *p = page_address(res->acl_scratch);
6264 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6265 }
Chuck Leverbf269552010-12-14 14:59:29 +00006266 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006267 if (status)
6268 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006269 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006270 if (status)
6271 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006272 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006273 if (status)
6274 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006275 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006276
6277out:
6278 return status;
6279}
6280
6281/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282 * Decode CLOSE response
6283 */
Chuck Leverbf269552010-12-14 14:59:29 +00006284static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6285 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006286{
Andy Adamson05d564f2008-12-23 16:06:15 -05006287 struct compound_hdr hdr;
6288 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289
Chuck Leverbf269552010-12-14 14:59:29 +00006290 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006291 if (status)
6292 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006293 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006294 if (status)
6295 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006296 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006297 if (status)
6298 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006299 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006300 if (status != 0)
6301 goto out;
6302 /*
6303 * Note: Server may do delete on close for this file
6304 * in which case the getattr call will fail with
6305 * an ESTALE error. Shouldn't be a problem,
6306 * though, since fattr->valid will remain unset.
6307 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006308 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006310 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311}
6312
6313/*
6314 * Decode OPEN response
6315 */
Chuck Leverbf269552010-12-14 14:59:29 +00006316static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6317 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318{
Andy Adamson05d564f2008-12-23 16:06:15 -05006319 struct compound_hdr hdr;
6320 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321
Chuck Leverbf269552010-12-14 14:59:29 +00006322 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006323 if (status)
6324 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006326 if (status)
6327 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006329 if (status)
6330 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006331 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006332 if (status)
6333 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006334 status = decode_getfh(xdr, &res->fh);
6335 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006336 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006337 if (res->access_request)
6338 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006339 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006341 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006342}
6343
6344/*
6345 * Decode OPEN_CONFIRM response
6346 */
Chuck Leverbf269552010-12-14 14:59:29 +00006347static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6348 struct xdr_stream *xdr,
6349 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350{
Andy Adamson05d564f2008-12-23 16:06:15 -05006351 struct compound_hdr hdr;
6352 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353
Chuck Leverbf269552010-12-14 14:59:29 +00006354 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006355 if (status)
6356 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006357 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006358 if (status)
6359 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006360 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006362 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363}
6364
6365/*
6366 * Decode OPEN response
6367 */
Chuck Leverbf269552010-12-14 14:59:29 +00006368static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6369 struct xdr_stream *xdr,
6370 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006371{
Andy Adamson05d564f2008-12-23 16:06:15 -05006372 struct compound_hdr hdr;
6373 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374
Chuck Leverbf269552010-12-14 14:59:29 +00006375 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006376 if (status)
6377 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006378 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006379 if (status)
6380 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006381 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006382 if (status)
6383 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006384 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006385 if (status)
6386 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006387 if (res->access_request)
6388 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006389 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006390out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006391 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392}
6393
6394/*
6395 * Decode SETATTR response
6396 */
Chuck Leverbf269552010-12-14 14:59:29 +00006397static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6398 struct xdr_stream *xdr,
6399 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400{
Andy Adamson05d564f2008-12-23 16:06:15 -05006401 struct compound_hdr hdr;
6402 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006403
Chuck Leverbf269552010-12-14 14:59:29 +00006404 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006405 if (status)
6406 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006407 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006408 if (status)
6409 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006411 if (status)
6412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006414 if (status)
6415 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006416 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006417out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006418 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006419}
6420
6421/*
6422 * Decode LOCK response
6423 */
Chuck Leverbf269552010-12-14 14:59:29 +00006424static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6425 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427 struct compound_hdr hdr;
6428 int status;
6429
Chuck Leverbf269552010-12-14 14:59:29 +00006430 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 if (status)
6432 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006434 if (status)
6435 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006436 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437 if (status)
6438 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006439 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440out:
6441 return status;
6442}
6443
6444/*
6445 * Decode LOCKT response
6446 */
Chuck Leverbf269552010-12-14 14:59:29 +00006447static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6448 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006449{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 struct compound_hdr hdr;
6451 int status;
6452
Chuck Leverbf269552010-12-14 14:59:29 +00006453 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 if (status)
6455 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006456 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006457 if (status)
6458 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006459 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460 if (status)
6461 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006462 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463out:
6464 return status;
6465}
6466
6467/*
6468 * Decode LOCKU response
6469 */
Chuck Leverbf269552010-12-14 14:59:29 +00006470static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6471 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006473 struct compound_hdr hdr;
6474 int status;
6475
Chuck Leverbf269552010-12-14 14:59:29 +00006476 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477 if (status)
6478 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006479 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006480 if (status)
6481 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006482 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483 if (status)
6484 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006485 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486out:
6487 return status;
6488}
6489
Chuck Leverbf269552010-12-14 14:59:29 +00006490static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6491 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006492{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006493 struct compound_hdr hdr;
6494 int status;
6495
Chuck Leverbf269552010-12-14 14:59:29 +00006496 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006497 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006498 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006499 return status;
6500}
6501
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502/*
6503 * Decode READLINK response
6504 */
Chuck Leverbf269552010-12-14 14:59:29 +00006505static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6506 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006507 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006509 struct compound_hdr hdr;
6510 int status;
6511
Chuck Leverbf269552010-12-14 14:59:29 +00006512 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513 if (status)
6514 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006515 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006516 if (status)
6517 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006518 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519 if (status)
6520 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006521 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006522out:
6523 return status;
6524}
6525
6526/*
6527 * Decode READDIR response
6528 */
Chuck Leverbf269552010-12-14 14:59:29 +00006529static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6530 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006531{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532 struct compound_hdr hdr;
6533 int status;
6534
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 if (status)
6537 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006538 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006539 if (status)
6540 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006541 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006542 if (status)
6543 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006544 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006545out:
6546 return status;
6547}
6548
6549/*
6550 * Decode Read response
6551 */
Chuck Leverbf269552010-12-14 14:59:29 +00006552static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6553 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006554{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555 struct compound_hdr hdr;
6556 int status;
6557
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006559 if (status)
6560 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006562 if (status)
6563 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565 if (status)
6566 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006567 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006568 if (!status)
6569 status = res->count;
6570out:
6571 return status;
6572}
6573
6574/*
6575 * Decode WRITE response
6576 */
Chuck Leverbf269552010-12-14 14:59:29 +00006577static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6578 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006579{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006580 struct compound_hdr hdr;
6581 int status;
6582
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584 if (status)
6585 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006586 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006587 if (status)
6588 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006589 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590 if (status)
6591 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006592 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006593 if (status)
6594 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006595 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006596 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597 if (!status)
6598 status = res->count;
6599out:
6600 return status;
6601}
6602
6603/*
6604 * Decode COMMIT response
6605 */
Chuck Leverbf269552010-12-14 14:59:29 +00006606static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006607 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006608{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006609 struct compound_hdr hdr;
6610 int status;
6611
Chuck Leverbf269552010-12-14 14:59:29 +00006612 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613 if (status)
6614 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006615 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006616 if (status)
6617 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006618 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619 if (status)
6620 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006621 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622out:
6623 return status;
6624}
6625
6626/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006627 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006628 */
Chuck Leverbf269552010-12-14 14:59:29 +00006629static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006630 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006631{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006632 struct compound_hdr hdr;
6633 int status;
6634
Chuck Leverbf269552010-12-14 14:59:29 +00006635 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006636 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006637 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006638 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006639 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006641 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642 return status;
6643}
6644
6645/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006646 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647 */
Chuck Leverbf269552010-12-14 14:59:29 +00006648static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006649 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006651 struct compound_hdr hdr;
6652 int status;
6653
Chuck Leverbf269552010-12-14 14:59:29 +00006654 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006656 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006657 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006658 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006660 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006661 return status;
6662}
6663
6664/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006665 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666 */
Chuck Leverbf269552010-12-14 14:59:29 +00006667static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006668 struct nfs4_statfs_res *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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006674 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006675 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006676 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006677 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006678 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006679 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680 return status;
6681}
6682
6683/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006684 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006685 */
Chuck Leverbf269552010-12-14 14:59:29 +00006686static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6687 struct xdr_stream *xdr,
6688 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006690 struct compound_hdr hdr;
6691 int status;
6692
Chuck Leverbf269552010-12-14 14:59:29 +00006693 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006694 if (status)
6695 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006696 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006697 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006698 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006699 status = decode_putfh(xdr);
6700 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006701 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006702 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006703out:
6704 return status;
6705}
6706
6707/*
6708 * Decode RENEW response
6709 */
Chuck Leverbf269552010-12-14 14:59:29 +00006710static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6711 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006713 struct compound_hdr hdr;
6714 int status;
6715
Chuck Leverbf269552010-12-14 14:59:29 +00006716 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006717 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006718 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006719 return status;
6720}
6721
6722/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006723 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724 */
Chuck Leverbf269552010-12-14 14:59:29 +00006725static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6726 struct xdr_stream *xdr,
6727 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006728{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006729 struct compound_hdr hdr;
6730 int status;
6731
Chuck Leverbf269552010-12-14 14:59:29 +00006732 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006733 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006734 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006735 return status;
6736}
6737
6738/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006739 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006740 */
Chuck Leverbf269552010-12-14 14:59:29 +00006741static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006742 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006743{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744 struct compound_hdr hdr;
6745 int status;
6746
Chuck Leverbf269552010-12-14 14:59:29 +00006747 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006748 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006749 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006750 return status;
6751}
6752
6753/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006754 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006755 */
Chuck Leverbf269552010-12-14 14:59:29 +00006756static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6757 struct xdr_stream *xdr,
6758 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006760 struct compound_hdr hdr;
6761 int status;
6762
Chuck Leverbf269552010-12-14 14:59:29 +00006763 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006764 if (status)
6765 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006766 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006767 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006768 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006769 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006770 if (status != 0)
6771 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006772 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006773 if (status != 0)
6774 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006775 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006776out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006777 return status;
6778}
6779
Trond Myklebust683b57b2006-06-09 09:34:22 -04006780/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006781 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006782 */
Chuck Leverbf269552010-12-14 14:59:29 +00006783static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6784 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006785 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006786{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006787 struct compound_hdr hdr;
6788 int status;
6789
Chuck Leverbf269552010-12-14 14:59:29 +00006790 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006791 if (status)
6792 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006793 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006794 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006795 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006796 status = decode_putfh(xdr);
6797 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006798 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006799 status = decode_lookup(xdr);
6800 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006801 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006802 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006803 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6804 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006805 NULL, res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006806out:
6807 return status;
6808}
6809
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006810/*
6811 * Decode SECINFO response
6812 */
6813static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6814 struct xdr_stream *xdr,
6815 struct nfs4_secinfo_res *res)
6816{
6817 struct compound_hdr hdr;
6818 int status;
6819
6820 status = decode_compound_hdr(xdr, &hdr);
6821 if (status)
6822 goto out;
6823 status = decode_sequence(xdr, &res->seq_res, rqstp);
6824 if (status)
6825 goto out;
6826 status = decode_putfh(xdr);
6827 if (status)
6828 goto out;
6829 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006830out:
6831 return status;
6832}
6833
Benny Halevy99fe60d2009-04-01 09:22:29 -04006834#if defined(CONFIG_NFS_V4_1)
6835/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04006836 * Decode BIND_CONN_TO_SESSION response
6837 */
6838static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
6839 struct xdr_stream *xdr,
6840 void *res)
6841{
6842 struct compound_hdr hdr;
6843 int status;
6844
6845 status = decode_compound_hdr(xdr, &hdr);
6846 if (!status)
6847 status = decode_bind_conn_to_session(xdr, res);
6848 return status;
6849}
6850
6851/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006852 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006853 */
Chuck Leverbf269552010-12-14 14:59:29 +00006854static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6855 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006856 void *res)
6857{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006858 struct compound_hdr hdr;
6859 int status;
6860
Chuck Leverbf269552010-12-14 14:59:29 +00006861 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006862 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006863 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006864 return status;
6865}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006866
6867/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006868 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006869 */
Chuck Leverbf269552010-12-14 14:59:29 +00006870static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6871 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006872 struct nfs41_create_session_res *res)
6873{
Andy Adamsonfc931582009-04-01 09:22:31 -04006874 struct compound_hdr hdr;
6875 int status;
6876
Chuck Leverbf269552010-12-14 14:59:29 +00006877 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006878 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006879 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006880 return status;
6881}
6882
6883/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006884 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006885 */
Chuck Leverbf269552010-12-14 14:59:29 +00006886static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6887 struct xdr_stream *xdr,
6888 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006889{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006890 struct compound_hdr hdr;
6891 int status;
6892
Chuck Leverbf269552010-12-14 14:59:29 +00006893 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006894 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006895 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006896 return status;
6897}
6898
6899/*
Trond Myklebust66245532012-05-25 17:18:09 -04006900 * Decode DESTROY_CLIENTID response
6901 */
6902static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
6903 struct xdr_stream *xdr,
6904 void *res)
6905{
6906 struct compound_hdr hdr;
6907 int status;
6908
6909 status = decode_compound_hdr(xdr, &hdr);
6910 if (!status)
6911 status = decode_destroy_clientid(xdr, res);
6912 return status;
6913}
6914
6915/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006916 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006917 */
Chuck Leverbf269552010-12-14 14:59:29 +00006918static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6919 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006920 struct nfs4_sequence_res *res)
6921{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006922 struct compound_hdr hdr;
6923 int status;
6924
Chuck Leverbf269552010-12-14 14:59:29 +00006925 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006926 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006927 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006928 return status;
6929}
6930
6931/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006932 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006933 */
Chuck Leverbf269552010-12-14 14:59:29 +00006934static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6935 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006936 struct nfs4_get_lease_time_res *res)
6937{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006938 struct compound_hdr hdr;
6939 int status;
6940
Chuck Leverbf269552010-12-14 14:59:29 +00006941 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006942 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006943 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006944 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006945 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006946 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006947 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006948 return status;
6949}
Ricardo Labiaga18019752009-12-05 16:08:40 -05006950
6951/*
6952 * Decode RECLAIM_COMPLETE response
6953 */
Chuck Leverbf269552010-12-14 14:59:29 +00006954static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6955 struct xdr_stream *xdr,
Ricardo Labiaga18019752009-12-05 16:08:40 -05006956 struct nfs41_reclaim_complete_res *res)
6957{
Ricardo Labiaga18019752009-12-05 16:08:40 -05006958 struct compound_hdr hdr;
6959 int status;
6960
Chuck Leverbf269552010-12-14 14:59:29 +00006961 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006962 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006963 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006964 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006965 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006966 return status;
6967}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006968
6969/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006970 * Decode GETDEVICELIST response
6971 */
6972static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6973 struct xdr_stream *xdr,
6974 struct nfs4_getdevicelist_res *res)
6975{
6976 struct compound_hdr hdr;
6977 int status;
6978
6979 dprintk("encoding getdevicelist!\n");
6980
6981 status = decode_compound_hdr(xdr, &hdr);
6982 if (status != 0)
6983 goto out;
6984 status = decode_sequence(xdr, &res->seq_res, rqstp);
6985 if (status != 0)
6986 goto out;
6987 status = decode_putfh(xdr);
6988 if (status != 0)
6989 goto out;
6990 status = decode_getdevicelist(xdr, res->devlist);
6991out:
6992 return status;
6993}
6994
6995/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006996 * Decode GETDEVINFO response
6997 */
Chuck Leverbf269552010-12-14 14:59:29 +00006998static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6999 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007000 struct nfs4_getdeviceinfo_res *res)
7001{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007002 struct compound_hdr hdr;
7003 int status;
7004
Chuck Leverbf269552010-12-14 14:59:29 +00007005 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007006 if (status != 0)
7007 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007008 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007009 if (status != 0)
7010 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007011 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007012out:
7013 return status;
7014}
7015
7016/*
7017 * Decode LAYOUTGET response
7018 */
Chuck Leverbf269552010-12-14 14:59:29 +00007019static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7020 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007021 struct nfs4_layoutget_res *res)
7022{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007023 struct compound_hdr hdr;
7024 int status;
7025
Chuck Leverbf269552010-12-14 14:59:29 +00007026 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007027 if (status)
7028 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007029 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007030 if (status)
7031 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007032 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007033 if (status)
7034 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007035 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007036out:
7037 return status;
7038}
Andy Adamson863a3c62011-03-23 13:27:54 +00007039
7040/*
Benny Halevycbe82602011-05-22 19:52:37 +03007041 * Decode LAYOUTRETURN response
7042 */
7043static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7044 struct xdr_stream *xdr,
7045 struct nfs4_layoutreturn_res *res)
7046{
7047 struct compound_hdr hdr;
7048 int status;
7049
7050 status = decode_compound_hdr(xdr, &hdr);
7051 if (status)
7052 goto out;
7053 status = decode_sequence(xdr, &res->seq_res, rqstp);
7054 if (status)
7055 goto out;
7056 status = decode_putfh(xdr);
7057 if (status)
7058 goto out;
7059 status = decode_layoutreturn(xdr, res);
7060out:
7061 return status;
7062}
7063
7064/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007065 * Decode LAYOUTCOMMIT response
7066 */
7067static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7068 struct xdr_stream *xdr,
7069 struct nfs4_layoutcommit_res *res)
7070{
7071 struct compound_hdr hdr;
7072 int status;
7073
7074 status = decode_compound_hdr(xdr, &hdr);
7075 if (status)
7076 goto out;
7077 status = decode_sequence(xdr, &res->seq_res, rqstp);
7078 if (status)
7079 goto out;
7080 status = decode_putfh(xdr);
7081 if (status)
7082 goto out;
7083 status = decode_layoutcommit(xdr, rqstp, res);
7084 if (status)
7085 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007086 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007087out:
7088 return status;
7089}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007090
7091/*
7092 * Decode SECINFO_NO_NAME response
7093 */
7094static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7095 struct xdr_stream *xdr,
7096 struct nfs4_secinfo_res *res)
7097{
7098 struct compound_hdr hdr;
7099 int status;
7100
7101 status = decode_compound_hdr(xdr, &hdr);
7102 if (status)
7103 goto out;
7104 status = decode_sequence(xdr, &res->seq_res, rqstp);
7105 if (status)
7106 goto out;
7107 status = decode_putrootfh(xdr);
7108 if (status)
7109 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007110 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007111out:
7112 return status;
7113}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007114
7115/*
7116 * Decode TEST_STATEID response
7117 */
7118static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7119 struct xdr_stream *xdr,
7120 struct nfs41_test_stateid_res *res)
7121{
7122 struct compound_hdr hdr;
7123 int status;
7124
7125 status = decode_compound_hdr(xdr, &hdr);
7126 if (status)
7127 goto out;
7128 status = decode_sequence(xdr, &res->seq_res, rqstp);
7129 if (status)
7130 goto out;
7131 status = decode_test_stateid(xdr, res);
7132out:
7133 return status;
7134}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007135
7136/*
7137 * Decode FREE_STATEID response
7138 */
7139static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7140 struct xdr_stream *xdr,
7141 struct nfs41_free_stateid_res *res)
7142{
7143 struct compound_hdr hdr;
7144 int status;
7145
7146 status = decode_compound_hdr(xdr, &hdr);
7147 if (status)
7148 goto out;
7149 status = decode_sequence(xdr, &res->seq_res, rqstp);
7150 if (status)
7151 goto out;
7152 status = decode_free_stateid(xdr, res);
7153out:
7154 return status;
7155}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007156#endif /* CONFIG_NFS_V4_1 */
7157
Chuck Lever573c4e12010-12-14 14:58:11 +00007158/**
7159 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7160 * the local page cache.
7161 * @xdr: XDR stream where entry resides
7162 * @entry: buffer to fill in with entry data
7163 * @plus: boolean indicating whether this should be a readdirplus entry
7164 *
7165 * Returns zero if successful, otherwise a negative errno value is
7166 * returned.
7167 *
7168 * This function is not invoked during READDIR reply decoding, but
7169 * rather whenever an application invokes the getdents(2) system call
7170 * on a directory already in our cache.
7171 */
7172int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7173 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007174{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007175 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007176 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007177 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007178 __be32 *p = xdr_inline_decode(xdr, 4);
7179 if (unlikely(!p))
7180 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007181 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007182 p = xdr_inline_decode(xdr, 4);
7183 if (unlikely(!p))
7184 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007185 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007186 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007187 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007188 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007189 }
7190
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007191 p = xdr_inline_decode(xdr, 12);
7192 if (unlikely(!p))
7193 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007194 entry->prev_cookie = entry->cookie;
7195 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007196 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007197
Trond Myklebust9af8c222010-10-24 11:52:55 -04007198 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007199 if (unlikely(!p))
7200 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007201 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007202
7203 /*
7204 * In case the server doesn't return an inode number,
7205 * we fake one here. (We don't use inode number 0,
7206 * since glibc seems to choke on it...)
7207 */
7208 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007209 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007210
Trond Myklebust9af8c222010-10-24 11:52:55 -04007211 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007212 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007213
Trond Myklebust256e48b2012-06-21 11:18:13 -04007214 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007215 goto out_overflow;
7216
Chuck Lever573c4e12010-12-14 14:58:11 +00007217 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007218 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007219 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007220 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7221 entry->ino = entry->fattr->mounted_on_fileid;
7222 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007223 entry->ino = entry->fattr->fileid;
7224
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007225 entry->d_type = DT_UNKNOWN;
7226 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7227 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7228
Chuck Lever573c4e12010-12-14 14:58:11 +00007229 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007230
7231out_overflow:
7232 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007233 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007234}
7235
7236/*
7237 * We need to translate between nfs status return values and
7238 * the local errno values which may not be the same.
7239 */
7240static struct {
7241 int stat;
7242 int errno;
7243} nfs_errtbl[] = {
7244 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007245 { NFS4ERR_PERM, -EPERM },
7246 { NFS4ERR_NOENT, -ENOENT },
7247 { NFS4ERR_IO, -errno_NFSERR_IO},
7248 { NFS4ERR_NXIO, -ENXIO },
7249 { NFS4ERR_ACCESS, -EACCES },
7250 { NFS4ERR_EXIST, -EEXIST },
7251 { NFS4ERR_XDEV, -EXDEV },
7252 { NFS4ERR_NOTDIR, -ENOTDIR },
7253 { NFS4ERR_ISDIR, -EISDIR },
7254 { NFS4ERR_INVAL, -EINVAL },
7255 { NFS4ERR_FBIG, -EFBIG },
7256 { NFS4ERR_NOSPC, -ENOSPC },
7257 { NFS4ERR_ROFS, -EROFS },
7258 { NFS4ERR_MLINK, -EMLINK },
7259 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7260 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7261 { NFS4ERR_DQUOT, -EDQUOT },
7262 { NFS4ERR_STALE, -ESTALE },
7263 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007264 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7265 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7266 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007267 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007268 { NFS4ERR_BADTYPE, -EBADTYPE },
7269 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007270 { NFS4ERR_SYMLINK, -ELOOP },
7271 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7272 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007273 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007274};
7275
7276/*
7277 * Convert an NFS error code to a local one.
7278 * This one is used jointly by NFSv2 and NFSv3.
7279 */
7280static int
David Howells0a8ea432006-08-22 20:06:08 -04007281nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007282{
7283 int i;
7284 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7285 if (nfs_errtbl[i].stat == stat)
7286 return nfs_errtbl[i].errno;
7287 }
7288 if (stat <= 10000 || stat > 10100) {
7289 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007290 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007291 }
7292 /* If we cannot translate the error, the recovery routines should
7293 * handle it.
7294 * Note: remaining NFSv4 error codes have values > 10000, so should
7295 * not conflict with native Linux error codes.
7296 */
Benny Halevy856dff32008-03-31 17:39:06 +03007297 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007298}
7299
Linus Torvalds1da177e2005-04-16 15:20:36 -07007300#define PROC(proc, argtype, restype) \
7301[NFSPROC4_CLNT_##proc] = { \
7302 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007303 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007304 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007305 .p_arglen = NFS4_##argtype##_sz, \
7306 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007307 .p_statidx = NFSPROC4_CLNT_##proc, \
7308 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007309}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007310
7311struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007312 PROC(READ, enc_read, dec_read),
7313 PROC(WRITE, enc_write, dec_write),
7314 PROC(COMMIT, enc_commit, dec_commit),
7315 PROC(OPEN, enc_open, dec_open),
7316 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7317 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7318 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7319 PROC(CLOSE, enc_close, dec_close),
7320 PROC(SETATTR, enc_setattr, dec_setattr),
7321 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7322 PROC(RENEW, enc_renew, dec_renew),
7323 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7324 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7325 PROC(LOCK, enc_lock, dec_lock),
7326 PROC(LOCKT, enc_lockt, dec_lockt),
7327 PROC(LOCKU, enc_locku, dec_locku),
7328 PROC(ACCESS, enc_access, dec_access),
7329 PROC(GETATTR, enc_getattr, dec_getattr),
7330 PROC(LOOKUP, enc_lookup, dec_lookup),
7331 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7332 PROC(REMOVE, enc_remove, dec_remove),
7333 PROC(RENAME, enc_rename, dec_rename),
7334 PROC(LINK, enc_link, dec_link),
7335 PROC(SYMLINK, enc_symlink, dec_symlink),
7336 PROC(CREATE, enc_create, dec_create),
7337 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7338 PROC(STATFS, enc_statfs, dec_statfs),
7339 PROC(READLINK, enc_readlink, dec_readlink),
7340 PROC(READDIR, enc_readdir, dec_readdir),
7341 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7342 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7343 PROC(GETACL, enc_getacl, dec_getacl),
7344 PROC(SETACL, enc_setacl, dec_setacl),
7345 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7346 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007347 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007348#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007349 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7350 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7351 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7352 PROC(SEQUENCE, enc_sequence, dec_sequence),
7353 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7354 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7355 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7356 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007357 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007358 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007359 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007360 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007361 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007362 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007363 PROC(BIND_CONN_TO_SESSION,
7364 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007365 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007366#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007367};
7368
Trond Myklebusta613fa12012-01-20 13:53:56 -05007369const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007370 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007371 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007372 .procs = nfs4_procedures
7373};
7374
7375/*
7376 * Local variables:
7377 * c-basic-offset: 8
7378 * End:
7379 */