blob: 5ad2b2c2aecb1a0808f7de04e70b93edde3b7a4d [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"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040059#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040060#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#define NFSDBG_FACILITY NFSDBG_XDR
63
64/* Mapping from NFS error code to "errno" error code. */
65#define errno_NFSERR_IO EIO
66
David Howells0a8ea432006-08-22 20:06:08 -040067static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
70#ifdef DEBUG
71#define NFS4_MAXTAGLEN 20
72#else
73#define NFS4_MAXTAGLEN 0
74#endif
75
Andy Adamson6c0195a2008-12-23 16:06:15 -050076/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040077 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040079#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050080#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040081#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
83#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
84#define op_encode_hdr_maxsz (1)
85#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040086#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
87#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
88#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
89#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
91 (NFS4_FHSIZE >> 2))
92#define decode_putfh_maxsz (op_decode_hdr_maxsz)
93#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
94#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
95#define encode_getfh_maxsz (op_encode_hdr_maxsz)
96#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
97 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040098#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000099#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
101#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400102#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
103#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000104/* This is based on getfattr, which uses the most attributes: */
105#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400106 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000107#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
108 nfs4_fattr_value_maxsz)
109#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400110#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
111 1 + 2 + 1 + \
112 nfs4_owner_maxsz + \
113 nfs4_group_maxsz + \
114 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#define encode_savefh_maxsz (op_encode_hdr_maxsz)
116#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400117#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
118#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200119#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400120/* The 5 accounts for the PNFS attributes, and assumes that at most three
121 * layout types will be returned.
122 */
123#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
124 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
126#define decode_renew_maxsz (op_decode_hdr_maxsz)
127#define encode_setclientid_maxsz \
128 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500129 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
130 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
131 1 /* sc_prog */ + \
132 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
133 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
134 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#define decode_setclientid_maxsz \
136 (op_decode_hdr_maxsz + \
137 2 + \
138 1024) /* large value for CLID_INUSE */
139#define encode_setclientid_confirm_maxsz \
140 (op_encode_hdr_maxsz + \
141 3 + (NFS4_VERIFIER_SIZE >> 2))
142#define decode_setclientid_confirm_maxsz \
143 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400144#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
145#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400146#define encode_share_access_maxsz \
147 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500148#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400149#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
150#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
151#define encode_open_maxsz (op_encode_hdr_maxsz + \
152 2 + encode_share_access_maxsz + 2 + \
153 open_owner_id_maxsz + \
154 encode_opentype_maxsz + \
155 encode_claim_null_maxsz)
156#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400157#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400158 decode_ace_maxsz)
159#define decode_change_info_maxsz (5)
160#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400161 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400162 decode_change_info_maxsz + 1 + \
163 nfs4_fattr_bitmap_maxsz + \
164 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400165#define encode_open_confirm_maxsz \
166 (op_encode_hdr_maxsz + \
167 encode_stateid_maxsz + 1)
168#define decode_open_confirm_maxsz \
169 (op_decode_hdr_maxsz + \
170 decode_stateid_maxsz)
171#define encode_open_downgrade_maxsz \
172 (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + 1 + \
174 encode_share_access_maxsz)
175#define decode_open_downgrade_maxsz \
176 (op_decode_hdr_maxsz + \
177 decode_stateid_maxsz)
178#define encode_close_maxsz (op_encode_hdr_maxsz + \
179 1 + encode_stateid_maxsz)
180#define decode_close_maxsz (op_decode_hdr_maxsz + \
181 decode_stateid_maxsz)
182#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
183 encode_stateid_maxsz + \
184 encode_attrs_maxsz)
185#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
186 nfs4_fattr_bitmap_maxsz)
187#define encode_read_maxsz (op_encode_hdr_maxsz + \
188 encode_stateid_maxsz + 3)
189#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
190#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
191 2 + encode_verifier_maxsz + 5)
192#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
193 decode_verifier_maxsz)
194#define encode_readlink_maxsz (op_encode_hdr_maxsz)
195#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
196#define encode_write_maxsz (op_encode_hdr_maxsz + \
197 encode_stateid_maxsz + 4)
198#define decode_write_maxsz (op_decode_hdr_maxsz + \
199 2 + decode_verifier_maxsz)
200#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
201#define decode_commit_maxsz (op_decode_hdr_maxsz + \
202 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#define encode_remove_maxsz (op_encode_hdr_maxsz + \
204 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400205#define decode_remove_maxsz (op_decode_hdr_maxsz + \
206 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#define encode_rename_maxsz (op_encode_hdr_maxsz + \
208 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400209#define decode_rename_maxsz (op_decode_hdr_maxsz + \
210 decode_change_info_maxsz + \
211 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#define encode_link_maxsz (op_encode_hdr_maxsz + \
213 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400214#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400215#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400216#define encode_lock_maxsz (op_encode_hdr_maxsz + \
217 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400218 1 + encode_stateid_maxsz + 1 + \
219 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400220#define decode_lock_denied_maxsz \
221 (8 + decode_lockowner_maxsz)
222#define decode_lock_maxsz (op_decode_hdr_maxsz + \
223 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400224#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
225 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400226#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
227 decode_lock_denied_maxsz)
228#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
229 encode_stateid_maxsz + \
230 4)
231#define decode_locku_maxsz (op_decode_hdr_maxsz + \
232 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400233#define encode_release_lockowner_maxsz \
234 (op_encode_hdr_maxsz + \
235 encode_lockowner_maxsz)
236#define decode_release_lockowner_maxsz \
237 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400238#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
239#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
241 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400242 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000243 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
245#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400246 1 + 2 + nfs4_name_maxsz + \
247 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400248#define decode_create_maxsz (op_decode_hdr_maxsz + \
249 decode_change_info_maxsz + \
250 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400251#define encode_statfs_maxsz (encode_getattr_maxsz)
252#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
254#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400255#define encode_getacl_maxsz (encode_getattr_maxsz)
256#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
257 nfs4_fattr_bitmap_maxsz + 1)
258#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
259 encode_stateid_maxsz + 3)
260#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400261#define encode_fs_locations_maxsz \
262 (encode_getattr_maxsz)
263#define decode_fs_locations_maxsz \
264 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000265#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400266#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 -0400267
268#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400269#define NFS4_MAX_MACHINE_NAME_LEN (64)
270
Benny Halevy99fe60d2009-04-01 09:22:29 -0400271#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
272 encode_verifier_maxsz + \
273 1 /* co_ownerid.len */ + \
274 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
275 1 /* flags */ + \
276 1 /* spa_how */ + \
277 0 /* SP4_NONE (for now) */ + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500278 1 /* implementation id array of size 1 */ + \
279 1 /* nii_domain */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281 1 /* nii_name */ + \
282 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
283 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400284#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
285 2 /* eir_clientid */ + \
286 1 /* eir_sequenceid */ + \
287 1 /* eir_flags */ + \
288 1 /* spr_how */ + \
289 0 /* SP4_NONE (for now) */ + \
290 2 /* eir_server_owner.so_minor_id */ + \
291 /* eir_server_owner.so_major_id<> */ \
292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
293 /* eir_server_scope<> */ \
294 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
295 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500296 1 /* nii_domain */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 1 /* nii_name */ + \
299 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
300 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400301#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
302#define decode_channel_attrs_maxsz (6 + \
303 1 /* ca_rdma_ird.len */ + \
304 1 /* ca_rdma_ird */)
305#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
306 2 /* csa_clientid */ + \
307 1 /* csa_sequence */ + \
308 1 /* csa_flags */ + \
309 encode_channel_attrs_maxsz + \
310 encode_channel_attrs_maxsz + \
311 1 /* csa_cb_program */ + \
312 1 /* csa_sec_parms.len (1) */ + \
313 1 /* cb_secflavor (AUTH_SYS) */ + \
314 1 /* stamp */ + \
315 1 /* machinename.len */ + \
316 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
317 1 /* uid */ + \
318 1 /* gid */ + \
319 1 /* gids.len (0) */)
320#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
321 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
322 1 /* csr_sequence */ + \
323 1 /* csr_flags */ + \
324 decode_channel_attrs_maxsz + \
325 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400326#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
327#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400328#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
329 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
330#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
331 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500332#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
333#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400334#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
335 encode_verifier_maxsz)
336#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
337 2 /* nfs_cookie4 gdlr_cookie */ + \
338 decode_verifier_maxsz \
339 /* verifier4 gdlr_verifier */ + \
340 1 /* gdlr_deviceid_list count */ + \
341 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
342 NFS4_DEVICEID4_SIZE) \
343 /* gdlr_deviceid_list */ + \
344 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400345#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
346 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
347#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
348 1 /* layout type */ + \
349 1 /* opaque devaddr4 length */ + \
350 /* devaddr4 payload is read into page */ \
351 1 /* notification bitmap length */ + \
352 1 /* notification bitmap */)
353#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
354 encode_stateid_maxsz)
355#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
356 decode_stateid_maxsz + \
357 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000358#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
359 2 /* offset */ + \
360 2 /* length */ + \
361 1 /* reclaim */ + \
362 encode_stateid_maxsz + \
363 1 /* new offset (true) */ + \
364 2 /* last byte written */ + \
365 1 /* nt_timechanged (false) */ + \
366 1 /* layoutupdate4 layout type */ + \
367 1 /* NULL filelayout layoutupdate4 payload */)
368#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300369#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
370 encode_stateid_maxsz + \
371 1 /* FIXME: opaque lrf_body always empty at the moment */)
372#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
373 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400374#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
375#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400376#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
377 XDR_QUADLEN(NFS4_STATEID_SIZE))
378#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400379#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
380 XDR_QUADLEN(NFS4_STATEID_SIZE))
381#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400382#else /* CONFIG_NFS_V4_1 */
383#define encode_sequence_maxsz 0
384#define decode_sequence_maxsz 0
385#endif /* CONFIG_NFS_V4_1 */
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
388#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
389#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400390 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400392 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400394 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400396 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400398 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400400 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400402 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400404 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400406 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400408 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400410 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400412 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400414 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400416 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400417 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400419 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400421 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400422 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400424 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400426 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400430 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400433 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400434 encode_open_maxsz + \
435 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400436 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400439 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400440 decode_open_maxsz + \
441 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400442 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400443#define NFS4_enc_open_confirm_sz \
444 (compound_encode_hdr_maxsz + \
445 encode_putfh_maxsz + \
446 encode_open_confirm_maxsz)
447#define NFS4_dec_open_confirm_sz \
448 (compound_decode_hdr_maxsz + \
449 decode_putfh_maxsz + \
450 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400454 encode_open_maxsz + \
455 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400457 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400459 decode_open_maxsz + \
460 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#define NFS4_enc_open_downgrade_sz \
462 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400464 encode_putfh_maxsz + \
465 encode_open_downgrade_maxsz + \
466 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_dec_open_downgrade_sz \
468 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 decode_putfh_maxsz + \
471 decode_open_downgrade_maxsz + \
472 decode_getattr_maxsz)
473#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400474 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400475 encode_putfh_maxsz + \
476 encode_close_maxsz + \
477 encode_getattr_maxsz)
478#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400479 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400480 decode_putfh_maxsz + \
481 decode_close_maxsz + \
482 decode_getattr_maxsz)
483#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400484 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400485 encode_putfh_maxsz + \
486 encode_setattr_maxsz + \
487 encode_getattr_maxsz)
488#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400490 decode_putfh_maxsz + \
491 decode_setattr_maxsz + \
492 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400494 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 encode_putfh_maxsz + \
496 encode_fsinfo_maxsz)
497#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400498 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 decode_putfh_maxsz + \
500 decode_fsinfo_maxsz)
501#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
502 encode_renew_maxsz)
503#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
504 decode_renew_maxsz)
505#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
506 encode_setclientid_maxsz)
507#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
508 decode_setclientid_maxsz)
509#define NFS4_enc_setclientid_confirm_sz \
510 (compound_encode_hdr_maxsz + \
511 encode_setclientid_confirm_maxsz + \
512 encode_putrootfh_maxsz + \
513 encode_fsinfo_maxsz)
514#define NFS4_dec_setclientid_confirm_sz \
515 (compound_decode_hdr_maxsz + \
516 decode_setclientid_confirm_maxsz + \
517 decode_putrootfh_maxsz + \
518 decode_fsinfo_maxsz)
519#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400522 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400526 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400528 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400530 encode_lockt_maxsz)
531#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400533 decode_putfh_maxsz + \
534 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400536 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400538 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400540 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400542 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400543#define NFS4_enc_release_lockowner_sz \
544 (compound_encode_hdr_maxsz + \
545 encode_lockowner_maxsz)
546#define NFS4_dec_release_lockowner_sz \
547 (compound_decode_hdr_maxsz + \
548 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400552 encode_access_maxsz + \
553 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400555 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400557 decode_access_maxsz + \
558 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_enc_getattr_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 + \
562 encode_getattr_maxsz)
563#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 decode_putfh_maxsz + \
566 decode_getattr_maxsz)
567#define NFS4_enc_lookup_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 + \
570 encode_lookup_maxsz + \
571 encode_getattr_maxsz + \
572 encode_getfh_maxsz)
573#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400576 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 decode_getattr_maxsz + \
578 decode_getfh_maxsz)
579#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 encode_putrootfh_maxsz + \
582 encode_getattr_maxsz + \
583 encode_getfh_maxsz)
584#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400585 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 decode_putrootfh_maxsz + \
587 decode_getattr_maxsz + \
588 decode_getfh_maxsz)
589#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400592 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400594 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400596 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 encode_putfh_maxsz + \
600 encode_savefh_maxsz + \
601 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400602 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400604 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 decode_putfh_maxsz + \
606 decode_savefh_maxsz + \
607 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400608 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 encode_putfh_maxsz + \
612 encode_savefh_maxsz + \
613 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400614 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400615 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400616 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400618 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 decode_putfh_maxsz + \
620 decode_savefh_maxsz + \
621 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400622 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400623 decode_restorefh_maxsz + \
624 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 encode_putfh_maxsz + \
628 encode_symlink_maxsz + \
629 encode_getattr_maxsz + \
630 encode_getfh_maxsz)
631#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400632 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 decode_putfh_maxsz + \
634 decode_symlink_maxsz + \
635 decode_getattr_maxsz + \
636 decode_getfh_maxsz)
637#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 encode_putfh_maxsz + \
640 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400641 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400642 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400644 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 decode_putfh_maxsz + \
646 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400647 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400648 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 encode_putfh_maxsz + \
652 encode_getattr_maxsz)
653#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 decode_putfh_maxsz + \
656 decode_getattr_maxsz)
657#define NFS4_enc_statfs_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 + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400660 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400662 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400664 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800667 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 encode_getattr_maxsz)
669#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400670 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800671 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 decode_getattr_maxsz)
673#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400674 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100676 encode_delegreturn_maxsz + \
677 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400679 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100680 decode_delegreturn_maxsz + \
681 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000682#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400683 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000684 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400685 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000686#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400687 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000688 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400689 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000690#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400691 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000692 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400693 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000694#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400695 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000696 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400697 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400698#define NFS4_enc_fs_locations_sz \
699 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400700 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400701 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400702 encode_lookup_maxsz + \
703 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400704#define NFS4_dec_fs_locations_sz \
705 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400707 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400708 decode_lookup_maxsz + \
709 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000710#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
711 encode_sequence_maxsz + \
712 encode_putfh_maxsz + \
713 encode_secinfo_maxsz)
714#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
715 decode_sequence_maxsz + \
716 decode_putfh_maxsz + \
717 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400718#if defined(CONFIG_NFS_V4_1)
719#define NFS4_enc_exchange_id_sz \
720 (compound_encode_hdr_maxsz + \
721 encode_exchange_id_maxsz)
722#define NFS4_dec_exchange_id_sz \
723 (compound_decode_hdr_maxsz + \
724 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400725#define NFS4_enc_create_session_sz \
726 (compound_encode_hdr_maxsz + \
727 encode_create_session_maxsz)
728#define NFS4_dec_create_session_sz \
729 (compound_decode_hdr_maxsz + \
730 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400731#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
732 encode_destroy_session_maxsz)
733#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
734 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400735#define NFS4_enc_sequence_sz \
736 (compound_decode_hdr_maxsz + \
737 encode_sequence_maxsz)
738#define NFS4_dec_sequence_sz \
739 (compound_decode_hdr_maxsz + \
740 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400741#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
742 encode_sequence_maxsz + \
743 encode_putrootfh_maxsz + \
744 encode_fsinfo_maxsz)
745#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
746 decode_sequence_maxsz + \
747 decode_putrootfh_maxsz + \
748 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500749#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
750 encode_sequence_maxsz + \
751 encode_reclaim_complete_maxsz)
752#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
753 decode_sequence_maxsz + \
754 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400755#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
756 encode_sequence_maxsz + \
757 encode_putfh_maxsz + \
758 encode_getdevicelist_maxsz)
759#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
760 decode_sequence_maxsz + \
761 decode_putfh_maxsz + \
762 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400763#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
764 encode_sequence_maxsz +\
765 encode_getdeviceinfo_maxsz)
766#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
767 decode_sequence_maxsz + \
768 decode_getdeviceinfo_maxsz)
769#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
770 encode_sequence_maxsz + \
771 encode_putfh_maxsz + \
772 encode_layoutget_maxsz)
773#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
774 decode_sequence_maxsz + \
775 decode_putfh_maxsz + \
776 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000777#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz +\
779 encode_putfh_maxsz + \
780 encode_layoutcommit_maxsz + \
781 encode_getattr_maxsz)
782#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
783 decode_sequence_maxsz + \
784 decode_putfh_maxsz + \
785 decode_layoutcommit_maxsz + \
786 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300787#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
788 encode_sequence_maxsz + \
789 encode_putfh_maxsz + \
790 encode_layoutreturn_maxsz)
791#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
792 decode_sequence_maxsz + \
793 decode_putfh_maxsz + \
794 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400795#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
796 encode_sequence_maxsz + \
797 encode_putrootfh_maxsz +\
798 encode_secinfo_no_name_maxsz)
799#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
800 decode_sequence_maxsz + \
801 decode_putrootfh_maxsz + \
802 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400803#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
804 encode_sequence_maxsz + \
805 encode_test_stateid_maxsz)
806#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
807 decode_sequence_maxsz + \
808 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400809#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
810 encode_sequence_maxsz + \
811 encode_free_stateid_maxsz)
812#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
813 decode_sequence_maxsz + \
814 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500815
816const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
817 compound_encode_hdr_maxsz +
818 encode_sequence_maxsz +
819 encode_putfh_maxsz +
820 encode_getattr_maxsz) *
821 XDR_UNIT);
822
823const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
824 compound_decode_hdr_maxsz +
825 decode_sequence_maxsz +
826 decode_putfh_maxsz) *
827 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400828#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500830static unsigned short send_implementation_id = 1;
831
832module_param(send_implementation_id, ushort, 0644);
833MODULE_PARM_DESC(send_implementation_id,
834 "Send implementation ID with NFSv4.1 exchange_id");
835
Trond Myklebustbca79472009-03-11 14:10:26 -0400836static const umode_t nfs_type2fmt[] = {
837 [NF4BAD] = 0,
838 [NF4REG] = S_IFREG,
839 [NF4DIR] = S_IFDIR,
840 [NF4BLK] = S_IFBLK,
841 [NF4CHR] = S_IFCHR,
842 [NF4LNK] = S_IFLNK,
843 [NF4SOCK] = S_IFSOCK,
844 [NF4FIFO] = S_IFIFO,
845 [NF4ATTRDIR] = 0,
846 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847};
848
849struct compound_hdr {
850 int32_t status;
851 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500852 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 uint32_t taglen;
854 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400855 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400856 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857};
858
Benny Halevy13c65ce2009-08-14 17:19:25 +0300859static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
860{
861 __be32 *p = xdr_reserve_space(xdr, nbytes);
862 BUG_ON(!p);
863 return p;
864}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Trond Myklebustcb17e552012-03-04 18:13:56 -0500866static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
867{
868 __be32 *p;
869
870 p = xdr_reserve_space(xdr, len);
871 xdr_encode_opaque_fixed(p, buf, len);
872}
873
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
875{
Al Viro8687b632006-10-19 23:28:48 -0700876 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500878 p = reserve_space(xdr, 4 + len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 xdr_encode_opaque(p, str, len);
880}
881
Trond Myklebust4ade9822012-03-04 18:13:57 -0500882static void encode_uint32(struct xdr_stream *xdr, u32 n)
883{
884 __be32 *p;
885
886 p = reserve_space(xdr, 4);
887 *p = cpu_to_be32(n);
888}
889
Trond Myklebustff2eb682012-03-05 11:40:12 -0500890static void encode_uint64(struct xdr_stream *xdr, u64 n)
891{
892 __be32 *p;
893
894 p = reserve_space(xdr, 8);
895 xdr_encode_hyper(p, n);
896}
897
Trond Myklebust4ade9822012-03-04 18:13:57 -0500898static void encode_nfs4_seqid(struct xdr_stream *xdr,
899 const struct nfs_seqid *seqid)
900{
901 encode_uint32(xdr, seqid->sequence->counter);
902}
903
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400904static void encode_compound_hdr(struct xdr_stream *xdr,
905 struct rpc_rqst *req,
906 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907{
Al Viro8687b632006-10-19 23:28:48 -0700908 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400909 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400910
911 /* initialize running count of expected bytes in reply.
912 * NOTE: the replied tag SHOULD be the same is the one sent,
913 * but this is not required as a MUST for the server to do so. */
914 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500917 encode_string(xdr, hdr->taglen, hdr->tag);
918 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300919 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500920 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300921 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500922}
923
Trond Myklebustab19b482012-03-04 18:13:57 -0500924static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
925 uint32_t replen,
926 struct compound_hdr *hdr)
927{
928 encode_uint32(xdr, op);
929 hdr->nops++;
930 hdr->replen += replen;
931}
932
Andy Adamsond0179312008-12-23 16:06:17 -0500933static void encode_nops(struct compound_hdr *hdr)
934{
Andy Adamsonfc931582009-04-01 09:22:31 -0400935 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500936 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937}
938
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500939static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
940{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500941 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500942}
943
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
945{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500946 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
948
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500949static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
951 char owner_name[IDMAP_NAMESZ];
952 char owner_group[IDMAP_NAMESZ];
953 int owner_namelen = 0;
954 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700955 __be32 *p;
956 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 int len;
958 uint32_t bmval0 = 0;
959 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 /*
962 * We reserve enough space to write the entire attribute buffer at once.
963 * In the worst-case, this would be
964 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
965 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000966 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 */
968 len = 16;
969
970 /* Sigh */
971 if (iap->ia_valid & ATTR_SIZE)
972 len += 8;
973 if (iap->ia_valid & ATTR_MODE)
974 len += 4;
975 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800976 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400978 dprintk("nfs: couldn't resolve uid %d to string\n",
979 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 /* XXX */
981 strcpy(owner_name, "nobody");
982 owner_namelen = sizeof("nobody") - 1;
983 /* goto out; */
984 }
985 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
986 }
987 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800988 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400990 dprintk("nfs: couldn't resolve gid %d to string\n",
991 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 strcpy(owner_group, "nobody");
993 owner_grouplen = sizeof("nobody") - 1;
994 /* goto out; */
995 }
996 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
997 }
998 if (iap->ia_valid & ATTR_ATIME_SET)
999 len += 16;
1000 else if (iap->ia_valid & ATTR_ATIME)
1001 len += 4;
1002 if (iap->ia_valid & ATTR_MTIME_SET)
1003 len += 16;
1004 else if (iap->ia_valid & ATTR_MTIME)
1005 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001006 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
1008 /*
1009 * We write the bitmap length now, but leave the bitmap and the attribute
1010 * buffer length to be backfilled at the end of this routine.
1011 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001012 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 q = p;
1014 p += 3;
1015
1016 if (iap->ia_valid & ATTR_SIZE) {
1017 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +03001018 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 }
1020 if (iap->ia_valid & ATTR_MODE) {
1021 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001022 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
1024 if (iap->ia_valid & ATTR_UID) {
1025 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +03001026 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 }
1028 if (iap->ia_valid & ATTR_GID) {
1029 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +03001030 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 }
1032 if (iap->ia_valid & ATTR_ATIME_SET) {
1033 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001034 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1035 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001036 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1037 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 }
1039 else if (iap->ia_valid & ATTR_ATIME) {
1040 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001041 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 }
1043 if (iap->ia_valid & ATTR_MTIME_SET) {
1044 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001045 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1046 *p++ = cpu_to_be32(0);
1047 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1048 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 }
1050 else if (iap->ia_valid & ATTR_MTIME) {
1051 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001052 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001054
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 /*
1056 * Now we backfill the bitmap and the attribute buffer length.
1057 */
1058 if (len != ((char *)p - (char *)q) + 4) {
Weston Andros Adamsonf9fd2d92012-01-26 13:32:22 -05001059 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 len, ((char *)p - (char *)q) + 4);
1061 BUG();
1062 }
1063 len = (char *)p - (char *)q - 12;
1064 *q++ = htonl(bmval0);
1065 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001066 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069}
1070
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001071static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001073 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1074 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075}
1076
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001077static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
Trond Myklebustab19b482012-03-04 18:13:57 -05001079 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001080 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001081 encode_nfs4_stateid(xdr, arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082}
1083
Fred Isaman0b7c0152012-04-20 14:47:39 -04001084static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085{
Al Viro8687b632006-10-19 23:28:48 -07001086 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001087
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001088 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1089 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001090 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001091 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092}
1093
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001094static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095{
Al Viro8687b632006-10-19 23:28:48 -07001096 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001097
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001098 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1099 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
1101 switch (create->ftype) {
1102 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001103 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001104 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001105 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 break;
1107
1108 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001109 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001110 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001111 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 break;
1113
1114 default:
1115 break;
1116 }
1117
Benny Halevy811652b2009-08-14 17:19:34 +03001118 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001119 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120}
1121
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001122static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
Andy Adamson05d564f2008-12-23 16:06:15 -05001124 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001126 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1127 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001128 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001129 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130}
1131
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001132static 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 -07001133{
Andy Adamson05d564f2008-12-23 16:06:15 -05001134 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001136 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1137 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001138 *p++ = cpu_to_be32(2);
1139 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001140 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
Fred Isamandae100c2011-07-30 20:52:37 -04001143static void
1144encode_getattr_three(struct xdr_stream *xdr,
1145 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1146 struct compound_hdr *hdr)
1147{
1148 __be32 *p;
1149
Trond Myklebustab19b482012-03-04 18:13:57 -05001150 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001151 if (bm2) {
1152 p = reserve_space(xdr, 16);
1153 *p++ = cpu_to_be32(3);
1154 *p++ = cpu_to_be32(bm0);
1155 *p++ = cpu_to_be32(bm1);
1156 *p = cpu_to_be32(bm2);
1157 } else if (bm1) {
1158 p = reserve_space(xdr, 12);
1159 *p++ = cpu_to_be32(2);
1160 *p++ = cpu_to_be32(bm0);
1161 *p = cpu_to_be32(bm1);
1162 } else {
1163 p = reserve_space(xdr, 8);
1164 *p++ = cpu_to_be32(1);
1165 *p = cpu_to_be32(bm0);
1166 }
Fred Isamandae100c2011-07-30 20:52:37 -04001167}
1168
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001169static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001171 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1172 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001175static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
Fred Isamandae100c2011-07-30 20:52:37 -04001177 encode_getattr_three(xdr,
1178 bitmask[0] & nfs4_fsinfo_bitmap[0],
1179 bitmask[1] & nfs4_fsinfo_bitmap[1],
1180 bitmask[2] & nfs4_fsinfo_bitmap[2],
1181 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182}
1183
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001184static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001185{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001186 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1187 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001188}
1189
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001190static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191{
Trond Myklebustab19b482012-03-04 18:13:57 -05001192 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193}
1194
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001195static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
Trond Myklebustab19b482012-03-04 18:13:57 -05001197 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001198 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199}
1200
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001201static inline int nfs4_lock_type(struct file_lock *fl, int block)
1202{
1203 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1204 return block ? NFS4_READW_LT : NFS4_READ_LT;
1205 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1206}
1207
1208static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1209{
1210 if (fl->fl_end == OFFSET_MAX)
1211 return ~(uint64_t)0;
1212 return fl->fl_end - fl->fl_start + 1;
1213}
1214
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001215static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1216{
1217 __be32 *p;
1218
Trond Myklebustd035c362010-12-21 10:45:27 -05001219 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001220 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001221 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001222 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001223 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001224 xdr_encode_hyper(p, lowner->id);
1225}
1226
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227/*
1228 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1229 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1230 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001231static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232{
Al Viro8687b632006-10-19 23:28:48 -07001233 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001235 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1236 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001237 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1238 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001239 p = xdr_encode_hyper(p, args->fl->fl_start);
1240 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001241 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001242 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001243 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001244 encode_nfs4_stateid(xdr, args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001245 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001246 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 }
1248 else {
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001249 encode_nfs4_stateid(xdr, args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001250 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001254static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255{
Al Viro8687b632006-10-19 23:28:48 -07001256 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001258 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1259 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001260 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001261 p = xdr_encode_hyper(p, args->fl->fl_start);
1262 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001263 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264}
1265
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001266static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267{
Al Viro8687b632006-10-19 23:28:48 -07001268 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001270 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1271 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001272 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001273 encode_nfs4_stateid(xdr, args->stateid);
1274 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001275 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001276 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001279static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1280{
Trond Myklebustab19b482012-03-04 18:13:57 -05001281 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001282 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001283}
1284
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001285static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
Trond Myklebustab19b482012-03-04 18:13:57 -05001287 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001288 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289}
1290
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001291static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
Al Viro8687b632006-10-19 23:28:48 -07001293 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Benny Halevy13c65ce2009-08-14 17:19:25 +03001295 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001296 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001297 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001298 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001299 break;
1300 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001301 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001302 break;
1303 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001304 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001305 break;
1306 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001307 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 }
Benny Halevy34558512009-08-14 17:19:30 +03001309 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310}
1311
1312static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1313{
Al Viro8687b632006-10-19 23:28:48 -07001314 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 /*
1316 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1317 * owner 4 = 32
1318 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001319 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001320 encode_share_access(xdr, arg->fmode);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001321 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001322 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001323 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001324 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001325 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001326 *p++ = cpu_to_be32(arg->id.uniquifier);
1327 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328}
1329
1330static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1331{
Al Viro8687b632006-10-19 23:28:48 -07001332 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001333 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
Benny Halevy13c65ce2009-08-14 17:19:25 +03001335 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001337 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001338 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001339 encode_attrs(xdr, arg->u.attrs, arg->server);
1340 break;
1341 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001342 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001343 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001344 if (nfs4_has_persistent_session(clp)) {
1345 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1346 encode_attrs(xdr, arg->u.attrs, arg->server);
1347 } else {
1348 struct iattr dummy;
1349
1350 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1351 encode_nfs4_verifier(xdr, &arg->u.verifier);
1352 dummy.ia_valid = 0;
1353 encode_attrs(xdr, &dummy, arg->server);
1354 }
1355 } else {
1356 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1357 encode_nfs4_verifier(xdr, &arg->u.verifier);
1358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 }
1360}
1361
1362static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1363{
Al Viro8687b632006-10-19 23:28:48 -07001364 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Benny Halevy13c65ce2009-08-14 17:19:25 +03001366 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001368 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001369 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001370 break;
1371 default:
1372 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001373 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001374 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 }
1376}
1377
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001378static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379{
Al Viro8687b632006-10-19 23:28:48 -07001380 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
Benny Halevy13c65ce2009-08-14 17:19:25 +03001382 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001384 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001385 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001386 break;
1387 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001388 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001389 break;
1390 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001391 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001392 break;
1393 default:
1394 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 }
1396}
1397
1398static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1399{
Al Viro8687b632006-10-19 23:28:48 -07001400 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
Benny Halevy13c65ce2009-08-14 17:19:25 +03001402 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001403 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 encode_string(xdr, name->len, name->name);
1405}
1406
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001407static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408{
Al Viro8687b632006-10-19 23:28:48 -07001409 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Benny Halevy13c65ce2009-08-14 17:19:25 +03001411 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001412 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 encode_delegation_type(xdr, type);
1414}
1415
1416static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1417{
Al Viro8687b632006-10-19 23:28:48 -07001418 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001420 p = reserve_space(xdr, 4);
1421 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1422 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 encode_string(xdr, name->len, name->name);
1424}
1425
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001426static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
Trond Myklebustab19b482012-03-04 18:13:57 -05001428 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 encode_openhdr(xdr, arg);
1430 encode_opentype(xdr, arg);
1431 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001432 case NFS4_OPEN_CLAIM_NULL:
1433 encode_claim_null(xdr, arg->name);
1434 break;
1435 case NFS4_OPEN_CLAIM_PREVIOUS:
1436 encode_claim_previous(xdr, arg->u.delegation_type);
1437 break;
1438 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1439 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1440 break;
1441 default:
1442 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444}
1445
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001446static 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 -07001447{
Trond Myklebustab19b482012-03-04 18:13:57 -05001448 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001449 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001450 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451}
1452
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001453static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
Trond Myklebustab19b482012-03-04 18:13:57 -05001455 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001456 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001457 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001458 encode_share_access(xdr, arg->fmode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459}
1460
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001461static void
Andy Adamsond0179312008-12-23 16:06:17 -05001462encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463{
Trond Myklebustab19b482012-03-04 18:13:57 -05001464 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001465 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466}
1467
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001468static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
Trond Myklebustab19b482012-03-04 18:13:57 -05001470 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471}
1472
Trond Myklebust4fc87962012-03-08 17:42:01 -05001473static void encode_open_stateid(struct xdr_stream *xdr,
1474 const struct nfs_open_context *ctx,
1475 const struct nfs_lock_context *l_ctx,
1476 fmode_t fmode,
1477 int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 nfs4_stateid stateid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 if (ctx->state != NULL) {
Trond Myklebust4fc87962012-03-08 17:42:01 -05001482 nfs4_select_rw_stateid(&stateid, ctx->state,
1483 fmode, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001484 if (zero_seqid)
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001485 stateid.seqid = 0;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001486 encode_nfs4_stateid(xdr, &stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 } else
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001488 encode_nfs4_stateid(xdr, &zero_stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489}
1490
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001491static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492{
Al Viro8687b632006-10-19 23:28:48 -07001493 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Trond Myklebustab19b482012-03-04 18:13:57 -05001495 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001496 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001497 FMODE_READ, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Benny Halevy13c65ce2009-08-14 17:19:25 +03001499 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001500 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001501 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502}
1503
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001504static 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 -07001505{
Trond Myklebust28331a42011-04-27 13:47:52 -04001506 uint32_t attrs[2] = {
1507 FATTR4_WORD0_RDATTR_ERROR,
1508 FATTR4_WORD1_MOUNTED_ON_FILEID,
1509 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001510 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001511 __be32 *p, verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001513 if (readdir->plus) {
1514 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001515 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001516 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1517 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1518 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1519 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001520 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001521 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001522 /* Use mounted_on_fileid only if the server supports it */
1523 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1524 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001525
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001526 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001527 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001528 encode_nfs4_verifier(xdr, &readdir->verifier);
1529 p = reserve_space(xdr, 20);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001530 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001531 *p++ = cpu_to_be32(readdir->count);
1532 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001533
Benny Halevye75bc1c2009-08-14 17:18:54 +03001534 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001535 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Chuck Levercd937102012-03-02 17:14:31 -05001536 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03001537 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1538 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001539 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001540 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001541 attrs[0] & readdir->bitmask[0],
1542 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001545static 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 -07001546{
Trond Myklebustab19b482012-03-04 18:13:57 -05001547 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001550static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
Trond Myklebustab19b482012-03-04 18:13:57 -05001552 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001553 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001556static 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 -07001557{
Trond Myklebustab19b482012-03-04 18:13:57 -05001558 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001559 encode_string(xdr, oldname->len, oldname->name);
1560 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561}
1562
Chuck Leverbb4dae52012-03-01 17:01:48 -05001563static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1564 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001566 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001567 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568}
1569
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001570static void
Andy Adamsond0179312008-12-23 16:06:17 -05001571encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001572{
Trond Myklebustab19b482012-03-04 18:13:57 -05001573 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001574}
1575
Chuck Lever9f06c712010-12-14 14:59:18 +00001576static void
Andy Adamsond0179312008-12-23 16:06:17 -05001577encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001578{
Al Viro8687b632006-10-19 23:28:48 -07001579 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001580
Trond Myklebustab19b482012-03-04 18:13:57 -05001581 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001582 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001583 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001584 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001585 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001586 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001587 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001588 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001589 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001590}
1591
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001592static void
Andy Adamsond0179312008-12-23 16:06:17 -05001593encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594{
Trond Myklebustab19b482012-03-04 18:13:57 -05001595 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596}
1597
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001598static 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 -07001599{
Trond Myklebustab19b482012-03-04 18:13:57 -05001600 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001601 encode_nfs4_stateid(xdr, &arg->stateid);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001602 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603}
1604
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001605static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606{
Al Viro8687b632006-10-19 23:28:48 -07001607 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Trond Myklebust70019512012-03-04 20:49:32 -05001609 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001610 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001613 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001614 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1616 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001617 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001618 *p = cpu_to_be32(setclientid->sc_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619}
1620
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001621static 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 -07001622{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001623 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1624 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001625 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001626 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001629static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630{
Al Viro8687b632006-10-19 23:28:48 -07001631 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
Trond Myklebustab19b482012-03-04 18:13:57 -05001633 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebustd0b496d2012-03-04 18:13:56 -05001634 encode_open_stateid(xdr, args->context, args->lock_context,
Trond Myklebust4fc87962012-03-08 17:42:01 -05001635 FMODE_WRITE, hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
Benny Halevy13c65ce2009-08-14 17:19:25 +03001637 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001638 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001639 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001640 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
1642 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643}
1644
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001645static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
Trond Myklebustab19b482012-03-04 18:13:57 -05001647 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001648 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001650
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001651static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1652{
Trond Myklebustab19b482012-03-04 18:13:57 -05001653 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001654 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001655}
1656
Benny Halevy99fe60d2009-04-01 09:22:29 -04001657#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001658/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001659static void encode_exchange_id(struct xdr_stream *xdr,
1660 struct nfs41_exchange_id_args *args,
1661 struct compound_hdr *hdr)
1662{
1663 __be32 *p;
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001664 char impl_name[NFS4_OPAQUE_LIMIT];
1665 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001666
Trond Myklebust70019512012-03-04 20:49:32 -05001667 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001668 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001669
1670 encode_string(xdr, args->id_len, args->id);
1671
Benny Halevy13c65ce2009-08-14 17:19:25 +03001672 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001673 *p++ = cpu_to_be32(args->flags);
1674 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001675
1676 if (send_implementation_id &&
1677 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1678 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1679 <= NFS4_OPAQUE_LIMIT + 1)
1680 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1681 utsname()->sysname, utsname()->release,
1682 utsname()->version, utsname()->machine);
1683
1684 if (len > 0) {
1685 *p = cpu_to_be32(1); /* implementation id array length=1 */
1686
1687 encode_string(xdr,
1688 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1689 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1690 encode_string(xdr, len, impl_name);
1691 /* just send zeros for nii_date - the date is in nii_name */
1692 p = reserve_space(xdr, 12);
1693 p = xdr_encode_hyper(p, 0);
1694 *p = cpu_to_be32(0);
1695 } else
1696 *p = cpu_to_be32(0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001697}
Andy Adamsonfc931582009-04-01 09:22:31 -04001698
1699static void encode_create_session(struct xdr_stream *xdr,
1700 struct nfs41_create_session_args *args,
1701 struct compound_hdr *hdr)
1702{
1703 __be32 *p;
1704 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1705 uint32_t len;
1706 struct nfs_client *clp = args->client;
Chuck Leverf0920752012-05-21 22:45:41 -04001707 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001708 u32 max_resp_sz_cached;
1709
1710 /*
1711 * Assumes OPEN is the biggest non-idempotent compound.
1712 * 2 is the verifier.
1713 */
1714 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1715 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001716
Andy Adamsonfc931582009-04-01 09:22:31 -04001717 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1718 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001719
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001720 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1721 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
Andy Adamson114f64b2011-03-09 13:13:45 -05001722 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001723 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1724 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001725
Andy Adamsonfc931582009-04-01 09:22:31 -04001726 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001727 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001728 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1729 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001730 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001731 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1732 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1733 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001734
1735 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001736 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001737 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1738 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1739 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1740 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1741 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1742 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001743
Benny Halevye75bc1c2009-08-14 17:18:54 +03001744 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001745 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001746 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001747
1748 /* authsys_parms rfc1831 */
Chuck Leverf0920752012-05-21 22:45:41 -04001749 *p++ = (__be32)nn->boot_time.tv_nsec; /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001750 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001751 *p++ = cpu_to_be32(0); /* UID */
1752 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001753 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001754}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001755
1756static void encode_destroy_session(struct xdr_stream *xdr,
1757 struct nfs4_session *session,
1758 struct compound_hdr *hdr)
1759{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001760 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1761 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001762}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001763
1764static void encode_reclaim_complete(struct xdr_stream *xdr,
1765 struct nfs41_reclaim_complete_args *args,
1766 struct compound_hdr *hdr)
1767{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001768 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1769 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001770}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001771#endif /* CONFIG_NFS_V4_1 */
1772
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001773static void encode_sequence(struct xdr_stream *xdr,
1774 const struct nfs4_sequence_args *args,
1775 struct compound_hdr *hdr)
1776{
1777#if defined(CONFIG_NFS_V4_1)
1778 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001779 struct nfs4_slot_table *tp;
1780 struct nfs4_slot *slot;
1781 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001782
1783 if (!session)
1784 return;
1785
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001786 tp = &session->fc_slot_table;
1787
1788 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1789 slot = tp->slots + args->sa_slotid;
1790
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001791 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001792
1793 /*
1794 * Sessionid + seqid + slotid + max slotid + cache_this
1795 */
1796 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1797 "max_slotid=%d cache_this=%d\n",
1798 __func__,
1799 ((u32 *)session->sess_id.data)[0],
1800 ((u32 *)session->sess_id.data)[1],
1801 ((u32 *)session->sess_id.data)[2],
1802 ((u32 *)session->sess_id.data)[3],
1803 slot->seq_nr, args->sa_slotid,
1804 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001805 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001806 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001807 *p++ = cpu_to_be32(slot->seq_nr);
1808 *p++ = cpu_to_be32(args->sa_slotid);
1809 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001810 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001811#endif /* CONFIG_NFS_V4_1 */
1812}
1813
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001814#ifdef CONFIG_NFS_V4_1
1815static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001816encode_getdevicelist(struct xdr_stream *xdr,
1817 const struct nfs4_getdevicelist_args *args,
1818 struct compound_hdr *hdr)
1819{
1820 __be32 *p;
1821 nfs4_verifier dummy = {
1822 .data = "dummmmmy",
1823 };
1824
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001825 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1826 p = reserve_space(xdr, 16);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001827 *p++ = cpu_to_be32(args->layoutclass);
1828 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1829 xdr_encode_hyper(p, 0ULL); /* cookie */
1830 encode_nfs4_verifier(xdr, &dummy);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001831}
1832
1833static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001834encode_getdeviceinfo(struct xdr_stream *xdr,
1835 const struct nfs4_getdeviceinfo_args *args,
1836 struct compound_hdr *hdr)
1837{
1838 __be32 *p;
1839
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001840 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1841 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001842 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1843 NFS4_DEVICEID4_SIZE);
1844 *p++ = cpu_to_be32(args->pdev->layout_type);
1845 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1846 *p++ = cpu_to_be32(0); /* bitmap length 0 */
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001847}
1848
1849static void
1850encode_layoutget(struct xdr_stream *xdr,
1851 const struct nfs4_layoutget_args *args,
1852 struct compound_hdr *hdr)
1853{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001854 __be32 *p;
1855
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001856 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1857 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001858 *p++ = cpu_to_be32(0); /* Signal layout available */
1859 *p++ = cpu_to_be32(args->type);
1860 *p++ = cpu_to_be32(args->range.iomode);
1861 p = xdr_encode_hyper(p, args->range.offset);
1862 p = xdr_encode_hyper(p, args->range.length);
1863 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001864 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001865 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001866
1867 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1868 __func__,
1869 args->type,
1870 args->range.iomode,
1871 (unsigned long)args->range.offset,
1872 (unsigned long)args->range.length,
1873 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001874}
Andy Adamson863a3c62011-03-23 13:27:54 +00001875
1876static int
1877encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001878 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001879 const struct nfs4_layoutcommit_args *args,
1880 struct compound_hdr *hdr)
1881{
1882 __be32 *p;
1883
1884 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1885 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1886
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001887 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1888 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001889 /* Only whole file layouts */
1890 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001891 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001892 *p = cpu_to_be32(0); /* reclaim */
1893 encode_nfs4_stateid(xdr, &args->stateid);
1894 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001895 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1896 p = xdr_encode_hyper(p, args->lastbytewritten);
1897 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1898 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001899
1900 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1901 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1902 NFS_I(inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001903 else
1904 encode_uint32(xdr, 0); /* no layout-type payload */
Andy Adamson863a3c62011-03-23 13:27:54 +00001905
Andy Adamson863a3c62011-03-23 13:27:54 +00001906 return 0;
1907}
Benny Halevycbe82602011-05-22 19:52:37 +03001908
1909static void
1910encode_layoutreturn(struct xdr_stream *xdr,
1911 const struct nfs4_layoutreturn_args *args,
1912 struct compound_hdr *hdr)
1913{
1914 __be32 *p;
1915
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001916 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
1917 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001918 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1919 *p++ = cpu_to_be32(args->layout_type);
1920 *p++ = cpu_to_be32(IOMODE_ANY);
1921 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001922 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03001923 p = xdr_encode_hyper(p, 0);
1924 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1925 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001926 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03001927 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001928 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1929 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1930 NFS_I(args->inode)->layout, xdr, args);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001931 } else
1932 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03001933}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001934
1935static int
1936encode_secinfo_no_name(struct xdr_stream *xdr,
1937 const struct nfs41_secinfo_no_name_args *args,
1938 struct compound_hdr *hdr)
1939{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001940 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
1941 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001942 return 0;
1943}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001944
1945static void encode_test_stateid(struct xdr_stream *xdr,
1946 struct nfs41_test_stateid_args *args,
1947 struct compound_hdr *hdr)
1948{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001949 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
1950 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001951 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04001952}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001953
1954static void encode_free_stateid(struct xdr_stream *xdr,
1955 struct nfs41_free_stateid_args *args,
1956 struct compound_hdr *hdr)
1957{
Trond Myklebustab19b482012-03-04 18:13:57 -05001958 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001959 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04001960}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001961#endif /* CONFIG_NFS_V4_1 */
1962
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963/*
1964 * END OF "GENERIC" ENCODE ROUTINES.
1965 */
1966
Benny Halevy66cc0422009-04-01 09:22:10 -04001967static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1968{
1969#if defined(CONFIG_NFS_V4_1)
1970 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001971 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001972#endif /* CONFIG_NFS_V4_1 */
1973 return 0;
1974}
1975
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976/*
1977 * Encode an ACCESS request
1978 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001979static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1980 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001983 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985
Chuck Lever9f06c712010-12-14 14:59:18 +00001986 encode_compound_hdr(xdr, req, &hdr);
1987 encode_sequence(xdr, &args->seq_args, &hdr);
1988 encode_putfh(xdr, args->fh, &hdr);
1989 encode_access(xdr, args->access, &hdr);
1990 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001991 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992}
1993
1994/*
1995 * Encode LOOKUP request
1996 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001997static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1998 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002001 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
Chuck Lever9f06c712010-12-14 14:59:18 +00002004 encode_compound_hdr(xdr, req, &hdr);
2005 encode_sequence(xdr, &args->seq_args, &hdr);
2006 encode_putfh(xdr, args->dir_fh, &hdr);
2007 encode_lookup(xdr, args->name, &hdr);
2008 encode_getfh(xdr, &hdr);
2009 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002010 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011}
2012
2013/*
2014 * Encode LOOKUP_ROOT request
2015 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002016static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2017 struct xdr_stream *xdr,
2018 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002021 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
Chuck Lever9f06c712010-12-14 14:59:18 +00002024 encode_compound_hdr(xdr, req, &hdr);
2025 encode_sequence(xdr, &args->seq_args, &hdr);
2026 encode_putrootfh(xdr, &hdr);
2027 encode_getfh(xdr, &hdr);
2028 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002029 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030}
2031
2032/*
2033 * Encode REMOVE request
2034 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002035static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2036 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002039 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
Chuck Lever9f06c712010-12-14 14:59:18 +00002042 encode_compound_hdr(xdr, req, &hdr);
2043 encode_sequence(xdr, &args->seq_args, &hdr);
2044 encode_putfh(xdr, args->fh, &hdr);
2045 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002046 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047}
2048
2049/*
2050 * Encode RENAME request
2051 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002052static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2053 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002056 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058
Chuck Lever9f06c712010-12-14 14:59:18 +00002059 encode_compound_hdr(xdr, req, &hdr);
2060 encode_sequence(xdr, &args->seq_args, &hdr);
2061 encode_putfh(xdr, args->old_dir, &hdr);
2062 encode_savefh(xdr, &hdr);
2063 encode_putfh(xdr, args->new_dir, &hdr);
2064 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002065 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066}
2067
2068/*
2069 * Encode LINK request
2070 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002071static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2072 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002075 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
Chuck Lever9f06c712010-12-14 14:59:18 +00002078 encode_compound_hdr(xdr, req, &hdr);
2079 encode_sequence(xdr, &args->seq_args, &hdr);
2080 encode_putfh(xdr, args->fh, &hdr);
2081 encode_savefh(xdr, &hdr);
2082 encode_putfh(xdr, args->dir_fh, &hdr);
2083 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002084 encode_restorefh(xdr, &hdr);
2085 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002086 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087}
2088
2089/*
2090 * Encode CREATE request
2091 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002092static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2093 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002096 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Chuck Lever9f06c712010-12-14 14:59:18 +00002099 encode_compound_hdr(xdr, req, &hdr);
2100 encode_sequence(xdr, &args->seq_args, &hdr);
2101 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002102 encode_create(xdr, args, &hdr);
2103 encode_getfh(xdr, &hdr);
2104 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002105 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
2108/*
2109 * Encode SYMLINK request
2110 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002111static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2112 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
Chuck Lever9f06c712010-12-14 14:59:18 +00002114 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115}
2116
2117/*
2118 * Encode GETATTR request
2119 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002120static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2121 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002124 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
Chuck Lever9f06c712010-12-14 14:59:18 +00002127 encode_compound_hdr(xdr, req, &hdr);
2128 encode_sequence(xdr, &args->seq_args, &hdr);
2129 encode_putfh(xdr, args->fh, &hdr);
2130 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002131 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132}
2133
2134/*
2135 * Encode a CLOSE request
2136 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002137static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2138 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139{
Andy Adamson05d564f2008-12-23 16:06:15 -05002140 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002141 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002142 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
Chuck Lever9f06c712010-12-14 14:59:18 +00002144 encode_compound_hdr(xdr, req, &hdr);
2145 encode_sequence(xdr, &args->seq_args, &hdr);
2146 encode_putfh(xdr, args->fh, &hdr);
2147 encode_close(xdr, args, &hdr);
2148 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002149 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150}
2151
2152/*
2153 * Encode an OPEN request
2154 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002155static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2156 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002159 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
Chuck Lever9f06c712010-12-14 14:59:18 +00002162 encode_compound_hdr(xdr, req, &hdr);
2163 encode_sequence(xdr, &args->seq_args, &hdr);
2164 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002165 encode_open(xdr, args, &hdr);
2166 encode_getfh(xdr, &hdr);
2167 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002168 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169}
2170
2171/*
2172 * Encode an OPEN_CONFIRM request
2173 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002174static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2175 struct xdr_stream *xdr,
2176 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002179 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
Chuck Lever9f06c712010-12-14 14:59:18 +00002182 encode_compound_hdr(xdr, req, &hdr);
2183 encode_putfh(xdr, args->fh, &hdr);
2184 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002185 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
2188/*
2189 * Encode an OPEN request with no attributes.
2190 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002191static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2192 struct xdr_stream *xdr,
2193 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002196 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
Chuck Lever9f06c712010-12-14 14:59:18 +00002199 encode_compound_hdr(xdr, req, &hdr);
2200 encode_sequence(xdr, &args->seq_args, &hdr);
2201 encode_putfh(xdr, args->fh, &hdr);
2202 encode_open(xdr, args, &hdr);
2203 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002204 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205}
2206
2207/*
2208 * Encode an OPEN_DOWNGRADE request
2209 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002210static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2211 struct xdr_stream *xdr,
2212 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002215 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
Chuck Lever9f06c712010-12-14 14:59:18 +00002218 encode_compound_hdr(xdr, req, &hdr);
2219 encode_sequence(xdr, &args->seq_args, &hdr);
2220 encode_putfh(xdr, args->fh, &hdr);
2221 encode_open_downgrade(xdr, args, &hdr);
2222 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002223 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224}
2225
2226/*
2227 * Encode a LOCK request
2228 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002229static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2230 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002233 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
Chuck Lever9f06c712010-12-14 14:59:18 +00002236 encode_compound_hdr(xdr, req, &hdr);
2237 encode_sequence(xdr, &args->seq_args, &hdr);
2238 encode_putfh(xdr, args->fh, &hdr);
2239 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002240 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241}
2242
2243/*
2244 * Encode a LOCKT request
2245 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002246static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2247 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002250 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
Chuck Lever9f06c712010-12-14 14:59:18 +00002253 encode_compound_hdr(xdr, req, &hdr);
2254 encode_sequence(xdr, &args->seq_args, &hdr);
2255 encode_putfh(xdr, args->fh, &hdr);
2256 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002257 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258}
2259
2260/*
2261 * Encode a LOCKU request
2262 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002263static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2264 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002267 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
Chuck Lever9f06c712010-12-14 14:59:18 +00002270 encode_compound_hdr(xdr, req, &hdr);
2271 encode_sequence(xdr, &args->seq_args, &hdr);
2272 encode_putfh(xdr, args->fh, &hdr);
2273 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002274 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275}
2276
Chuck Lever9f06c712010-12-14 14:59:18 +00002277static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2278 struct xdr_stream *xdr,
2279 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002280{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002281 struct compound_hdr hdr = {
2282 .minorversion = 0,
2283 };
2284
Chuck Lever9f06c712010-12-14 14:59:18 +00002285 encode_compound_hdr(xdr, req, &hdr);
2286 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002287 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002288}
2289
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290/*
2291 * Encode a READLINK request
2292 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002293static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2294 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002297 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
Chuck Lever9f06c712010-12-14 14:59:18 +00002300 encode_compound_hdr(xdr, req, &hdr);
2301 encode_sequence(xdr, &args->seq_args, &hdr);
2302 encode_putfh(xdr, args->fh, &hdr);
2303 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002304
Benny Halevy28f56692009-04-01 09:22:09 -04002305 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002306 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002307 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308}
2309
2310/*
2311 * Encode a READDIR request
2312 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002313static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2314 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002317 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319
Chuck Lever9f06c712010-12-14 14:59:18 +00002320 encode_compound_hdr(xdr, req, &hdr);
2321 encode_sequence(xdr, &args->seq_args, &hdr);
2322 encode_putfh(xdr, args->fh, &hdr);
2323 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002324
Benny Halevy28f56692009-04-01 09:22:09 -04002325 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002326 args->pgbase, args->count);
2327 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002328 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002329 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002330 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331}
2332
2333/*
2334 * Encode a READ request
2335 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002336static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2337 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002340 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
Chuck Lever9f06c712010-12-14 14:59:18 +00002343 encode_compound_hdr(xdr, req, &hdr);
2344 encode_sequence(xdr, &args->seq_args, &hdr);
2345 encode_putfh(xdr, args->fh, &hdr);
2346 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
Benny Halevy28f56692009-04-01 09:22:09 -04002348 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002350 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002351 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352}
2353
2354/*
2355 * Encode an SETATTR request
2356 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002357static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2358 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359{
Andy Adamson05d564f2008-12-23 16:06:15 -05002360 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002361 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002362 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363
Chuck Lever9f06c712010-12-14 14:59:18 +00002364 encode_compound_hdr(xdr, req, &hdr);
2365 encode_sequence(xdr, &args->seq_args, &hdr);
2366 encode_putfh(xdr, args->fh, &hdr);
2367 encode_setattr(xdr, args, args->server, &hdr);
2368 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002369 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370}
2371
2372/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002373 * Encode a GETACL request
2374 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002375static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2376 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002377{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002378 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002379 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002380 };
Benny Halevy28f56692009-04-01 09:22:09 -04002381 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002382
Chuck Lever9f06c712010-12-14 14:59:18 +00002383 encode_compound_hdr(xdr, req, &hdr);
2384 encode_sequence(xdr, &args->seq_args, &hdr);
2385 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002386 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002387 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002388
Benny Halevy28f56692009-04-01 09:22:09 -04002389 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002390 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002391
Andy Adamsond0179312008-12-23 16:06:17 -05002392 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002393}
2394
2395/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 * Encode a WRITE request
2397 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002398static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2399 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002402 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
Chuck Lever9f06c712010-12-14 14:59:18 +00002405 encode_compound_hdr(xdr, req, &hdr);
2406 encode_sequence(xdr, &args->seq_args, &hdr);
2407 encode_putfh(xdr, args->fh, &hdr);
2408 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002409 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002410 if (args->bitmask)
2411 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002412 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413}
2414
2415/*
2416 * a COMMIT request
2417 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002418static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002419 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002422 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
Chuck Lever9f06c712010-12-14 14:59:18 +00002425 encode_compound_hdr(xdr, req, &hdr);
2426 encode_sequence(xdr, &args->seq_args, &hdr);
2427 encode_putfh(xdr, args->fh, &hdr);
2428 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002429 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430}
2431
2432/*
2433 * FSINFO request
2434 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002435static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2436 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002439 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
Chuck Lever9f06c712010-12-14 14:59:18 +00002442 encode_compound_hdr(xdr, req, &hdr);
2443 encode_sequence(xdr, &args->seq_args, &hdr);
2444 encode_putfh(xdr, args->fh, &hdr);
2445 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002446 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447}
2448
2449/*
2450 * a PATHCONF request
2451 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002452static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2453 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002456 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458
Chuck Lever9f06c712010-12-14 14:59:18 +00002459 encode_compound_hdr(xdr, req, &hdr);
2460 encode_sequence(xdr, &args->seq_args, &hdr);
2461 encode_putfh(xdr, args->fh, &hdr);
2462 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002463 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002464 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465}
2466
2467/*
2468 * a STATFS request
2469 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002470static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2471 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002474 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476
Chuck Lever9f06c712010-12-14 14:59:18 +00002477 encode_compound_hdr(xdr, req, &hdr);
2478 encode_sequence(xdr, &args->seq_args, &hdr);
2479 encode_putfh(xdr, args->fh, &hdr);
2480 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002481 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002482 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483}
2484
2485/*
2486 * GETATTR_BITMAP request
2487 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002488static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2489 struct xdr_stream *xdr,
2490 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002493 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
Chuck Lever9f06c712010-12-14 14:59:18 +00002496 encode_compound_hdr(xdr, req, &hdr);
2497 encode_sequence(xdr, &args->seq_args, &hdr);
2498 encode_putfh(xdr, args->fhandle, &hdr);
2499 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Chuck Lever264e6352012-03-01 17:02:05 -05002500 FATTR4_WORD0_FH_EXPIRE_TYPE|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002501 FATTR4_WORD0_LINK_SUPPORT|
2502 FATTR4_WORD0_SYMLINK_SUPPORT|
2503 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002504 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505}
2506
2507/*
2508 * a RENEW request
2509 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002510static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2511 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002514 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 };
2516
Chuck Lever9f06c712010-12-14 14:59:18 +00002517 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002518 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002519 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520}
2521
2522/*
2523 * a SETCLIENTID request
2524 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002525static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2526 struct xdr_stream *xdr,
2527 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002530 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 };
2532
Chuck Lever9f06c712010-12-14 14:59:18 +00002533 encode_compound_hdr(xdr, req, &hdr);
2534 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002535 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536}
2537
2538/*
2539 * a SETCLIENTID_CONFIRM request
2540 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002541static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2542 struct xdr_stream *xdr,
2543 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002546 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 };
Fred Isamandae100c2011-07-30 20:52:37 -04002548 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
Chuck Lever9f06c712010-12-14 14:59:18 +00002550 encode_compound_hdr(xdr, req, &hdr);
2551 encode_setclientid_confirm(xdr, arg, &hdr);
2552 encode_putrootfh(xdr, &hdr);
2553 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002554 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555}
2556
2557/*
2558 * DELEGRETURN request
2559 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002560static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2561 struct xdr_stream *xdr,
2562 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002565 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567
Chuck Lever9f06c712010-12-14 14:59:18 +00002568 encode_compound_hdr(xdr, req, &hdr);
2569 encode_sequence(xdr, &args->seq_args, &hdr);
2570 encode_putfh(xdr, args->fhandle, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002571 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002572 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002573 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574}
2575
2576/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002577 * Encode FS_LOCATIONS request
2578 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002579static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2580 struct xdr_stream *xdr,
2581 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002582{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002583 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002584 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002585 };
Benny Halevy28f56692009-04-01 09:22:09 -04002586 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002587
Chuck Lever9f06c712010-12-14 14:59:18 +00002588 encode_compound_hdr(xdr, req, &hdr);
2589 encode_sequence(xdr, &args->seq_args, &hdr);
2590 encode_putfh(xdr, args->dir_fh, &hdr);
2591 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002592 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002593 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002594
Benny Halevy28f56692009-04-01 09:22:09 -04002595 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002596 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002597 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002598}
2599
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002600/*
2601 * Encode SECINFO request
2602 */
2603static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2604 struct xdr_stream *xdr,
2605 struct nfs4_secinfo_arg *args)
2606{
2607 struct compound_hdr hdr = {
2608 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2609 };
2610
2611 encode_compound_hdr(xdr, req, &hdr);
2612 encode_sequence(xdr, &args->seq_args, &hdr);
2613 encode_putfh(xdr, args->dir_fh, &hdr);
2614 encode_secinfo(xdr, args->name, &hdr);
2615 encode_nops(&hdr);
2616}
2617
Benny Halevy99fe60d2009-04-01 09:22:29 -04002618#if defined(CONFIG_NFS_V4_1)
2619/*
2620 * EXCHANGE_ID request
2621 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002622static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2623 struct xdr_stream *xdr,
2624 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002625{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002626 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002627 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002628 };
2629
Chuck Lever9f06c712010-12-14 14:59:18 +00002630 encode_compound_hdr(xdr, req, &hdr);
2631 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002632 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002633}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002634
2635/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002636 * a CREATE_SESSION request
2637 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002638static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2639 struct xdr_stream *xdr,
2640 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002641{
Andy Adamsonfc931582009-04-01 09:22:31 -04002642 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002643 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002644 };
2645
Chuck Lever9f06c712010-12-14 14:59:18 +00002646 encode_compound_hdr(xdr, req, &hdr);
2647 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002648 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002649}
2650
2651/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002652 * a DESTROY_SESSION request
2653 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002654static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2655 struct xdr_stream *xdr,
2656 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002657{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002658 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002659 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002660 };
2661
Chuck Lever9f06c712010-12-14 14:59:18 +00002662 encode_compound_hdr(xdr, req, &hdr);
2663 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002664 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002665}
2666
2667/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002668 * a SEQUENCE request
2669 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002670static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2671 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002672{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002673 struct compound_hdr hdr = {
2674 .minorversion = nfs4_xdr_minorversion(args),
2675 };
2676
Chuck Lever9f06c712010-12-14 14:59:18 +00002677 encode_compound_hdr(xdr, req, &hdr);
2678 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002679 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002680}
2681
2682/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002683 * a GET_LEASE_TIME request
2684 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002685static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2686 struct xdr_stream *xdr,
2687 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002688{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002689 struct compound_hdr hdr = {
2690 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2691 };
Fred Isamandae100c2011-07-30 20:52:37 -04002692 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002693
Chuck Lever9f06c712010-12-14 14:59:18 +00002694 encode_compound_hdr(xdr, req, &hdr);
2695 encode_sequence(xdr, &args->la_seq_args, &hdr);
2696 encode_putrootfh(xdr, &hdr);
2697 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002698 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002699}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002700
2701/*
2702 * a RECLAIM_COMPLETE request
2703 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002704static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2705 struct xdr_stream *xdr,
2706 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002707{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002708 struct compound_hdr hdr = {
2709 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2710 };
2711
Chuck Lever9f06c712010-12-14 14:59:18 +00002712 encode_compound_hdr(xdr, req, &hdr);
2713 encode_sequence(xdr, &args->seq_args, &hdr);
2714 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002715 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002716}
2717
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002718/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002719 * Encode GETDEVICELIST request
2720 */
2721static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2722 struct xdr_stream *xdr,
2723 struct nfs4_getdevicelist_args *args)
2724{
2725 struct compound_hdr hdr = {
2726 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2727 };
2728
2729 encode_compound_hdr(xdr, req, &hdr);
2730 encode_sequence(xdr, &args->seq_args, &hdr);
2731 encode_putfh(xdr, args->fh, &hdr);
2732 encode_getdevicelist(xdr, args, &hdr);
2733 encode_nops(&hdr);
2734}
2735
2736/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002737 * Encode GETDEVICEINFO request
2738 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002739static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2740 struct xdr_stream *xdr,
2741 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002742{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002743 struct compound_hdr hdr = {
2744 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2745 };
2746
Chuck Lever9f06c712010-12-14 14:59:18 +00002747 encode_compound_hdr(xdr, req, &hdr);
2748 encode_sequence(xdr, &args->seq_args, &hdr);
2749 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002750
2751 /* set up reply kvec. Subtract notification bitmap max size (2)
2752 * so that notification bitmap is put in xdr_buf tail */
2753 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2754 args->pdev->pages, args->pdev->pgbase,
2755 args->pdev->pglen);
2756
2757 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002758}
2759
2760/*
2761 * Encode LAYOUTGET request
2762 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002763static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2764 struct xdr_stream *xdr,
2765 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002766{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002767 struct compound_hdr hdr = {
2768 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2769 };
2770
Chuck Lever9f06c712010-12-14 14:59:18 +00002771 encode_compound_hdr(xdr, req, &hdr);
2772 encode_sequence(xdr, &args->seq_args, &hdr);
2773 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2774 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002775
2776 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2777 args->layout.pages, 0, args->layout.pglen);
2778
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002779 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002780}
Andy Adamson863a3c62011-03-23 13:27:54 +00002781
2782/*
2783 * Encode LAYOUTCOMMIT request
2784 */
Benny Halevycbe82602011-05-22 19:52:37 +03002785static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2786 struct xdr_stream *xdr,
2787 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002788{
Benny Halevyac7db722011-05-22 19:53:48 +03002789 struct nfs4_layoutcommit_data *data =
2790 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002791 struct compound_hdr hdr = {
2792 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2793 };
2794
2795 encode_compound_hdr(xdr, req, &hdr);
2796 encode_sequence(xdr, &args->seq_args, &hdr);
2797 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002798 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002799 encode_getfattr(xdr, args->bitmask, &hdr);
2800 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002801}
2802
2803/*
2804 * Encode LAYOUTRETURN request
2805 */
2806static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2807 struct xdr_stream *xdr,
2808 struct nfs4_layoutreturn_args *args)
2809{
2810 struct compound_hdr hdr = {
2811 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2812 };
2813
2814 encode_compound_hdr(xdr, req, &hdr);
2815 encode_sequence(xdr, &args->seq_args, &hdr);
2816 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2817 encode_layoutreturn(xdr, args, &hdr);
2818 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002819}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002820
2821/*
2822 * Encode SECINFO_NO_NAME request
2823 */
2824static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2825 struct xdr_stream *xdr,
2826 struct nfs41_secinfo_no_name_args *args)
2827{
2828 struct compound_hdr hdr = {
2829 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2830 };
2831
2832 encode_compound_hdr(xdr, req, &hdr);
2833 encode_sequence(xdr, &args->seq_args, &hdr);
2834 encode_putrootfh(xdr, &hdr);
2835 encode_secinfo_no_name(xdr, args, &hdr);
2836 encode_nops(&hdr);
2837 return 0;
2838}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002839
2840/*
2841 * Encode TEST_STATEID request
2842 */
2843static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2844 struct xdr_stream *xdr,
2845 struct nfs41_test_stateid_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_test_stateid(xdr, args, &hdr);
2854 encode_nops(&hdr);
2855}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002856
2857/*
2858 * Encode FREE_STATEID request
2859 */
2860static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2861 struct xdr_stream *xdr,
2862 struct nfs41_free_stateid_args *args)
2863{
2864 struct compound_hdr hdr = {
2865 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2866 };
2867
2868 encode_compound_hdr(xdr, req, &hdr);
2869 encode_sequence(xdr, &args->seq_args, &hdr);
2870 encode_free_stateid(xdr, args, &hdr);
2871 encode_nops(&hdr);
2872}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002873#endif /* CONFIG_NFS_V4_1 */
2874
Benny Halevy686841b2009-08-14 17:19:48 +03002875static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2876{
2877 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2878 "Remaining buffer length is %tu words.\n",
2879 func, xdr->end - xdr->p);
2880}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881
Trond Myklebust683b57b2006-06-09 09:34:22 -04002882static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883{
Al Viro8687b632006-10-19 23:28:48 -07002884 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885
Benny Halevyc0eae662009-08-14 17:20:14 +03002886 p = xdr_inline_decode(xdr, 4);
2887 if (unlikely(!p))
2888 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002889 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002890 p = xdr_inline_decode(xdr, *len);
2891 if (unlikely(!p))
2892 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 *string = (char *)p;
2894 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002895out_overflow:
2896 print_overflow_msg(__func__, xdr);
2897 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898}
2899
2900static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2901{
Al Viro8687b632006-10-19 23:28:48 -07002902 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903
Benny Halevyc0eae662009-08-14 17:20:14 +03002904 p = xdr_inline_decode(xdr, 8);
2905 if (unlikely(!p))
2906 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002907 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002908 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002909
Benny Halevyc0eae662009-08-14 17:20:14 +03002910 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2911 if (unlikely(!p))
2912 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 hdr->tag = (char *)p;
2914 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002915 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002916 if (unlikely(hdr->nops < 1))
2917 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002919out_overflow:
2920 print_overflow_msg(__func__, xdr);
2921 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922}
2923
2924static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2925{
Al Viro8687b632006-10-19 23:28:48 -07002926 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 uint32_t opnum;
2928 int32_t nfserr;
2929
Benny Halevyc0eae662009-08-14 17:20:14 +03002930 p = xdr_inline_decode(xdr, 8);
2931 if (unlikely(!p))
2932 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002933 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002935 dprintk("nfs: Server returned operation"
2936 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 opnum, expected);
2938 return -EIO;
2939 }
Benny Halevycccddf42009-08-14 17:20:19 +03002940 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002942 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002944out_overflow:
2945 print_overflow_msg(__func__, xdr);
2946 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947}
2948
2949/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002950static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951{
Al Viro8687b632006-10-19 23:28:48 -07002952 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002953 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 char *str;
2955
Benny Halevyc0eae662009-08-14 17:20:14 +03002956 p = xdr_inline_decode(xdr, 12);
2957 if (likely(p))
2958 return decode_opaque_inline(xdr, &strlen, &str);
2959 print_overflow_msg(__func__, xdr);
2960 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961}
2962
2963static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2964{
Al Viro8687b632006-10-19 23:28:48 -07002965 uint32_t bmlen;
2966 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
Benny Halevyc0eae662009-08-14 17:20:14 +03002968 p = xdr_inline_decode(xdr, 4);
2969 if (unlikely(!p))
2970 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002971 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972
Fred Isamandae100c2011-07-30 20:52:37 -04002973 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002974 p = xdr_inline_decode(xdr, (bmlen << 2));
2975 if (unlikely(!p))
2976 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002978 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04002979 if (bmlen > 1) {
2980 bitmap[1] = be32_to_cpup(p++);
2981 if (bmlen > 2)
2982 bitmap[2] = be32_to_cpup(p);
2983 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 }
2985 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002986out_overflow:
2987 print_overflow_msg(__func__, xdr);
2988 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989}
2990
Al Viro8687b632006-10-19 23:28:48 -07002991static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992{
Al Viro8687b632006-10-19 23:28:48 -07002993 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994
Benny Halevyc0eae662009-08-14 17:20:14 +03002995 p = xdr_inline_decode(xdr, 4);
2996 if (unlikely(!p))
2997 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002998 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 *savep = xdr->p;
3000 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003001out_overflow:
3002 print_overflow_msg(__func__, xdr);
3003 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004}
3005
3006static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3007{
3008 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003009 int ret;
3010 ret = decode_attr_bitmap(xdr, bitmask);
3011 if (unlikely(ret < 0))
3012 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3014 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003015 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3016 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3017 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 return 0;
3019}
3020
3021static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3022{
Al Viro8687b632006-10-19 23:28:48 -07003023 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003024 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025
3026 *type = 0;
3027 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3028 return -EIO;
3029 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003030 p = xdr_inline_decode(xdr, 4);
3031 if (unlikely(!p))
3032 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003033 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003035 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 return -EIO;
3037 }
3038 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003039 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003041 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003042 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003043out_overflow:
3044 print_overflow_msg(__func__, xdr);
3045 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046}
3047
Chuck Lever264e6352012-03-01 17:02:05 -05003048static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3049 uint32_t *bitmap, uint32_t *type)
3050{
3051 __be32 *p;
3052
3053 *type = 0;
3054 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3055 return -EIO;
3056 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3057 p = xdr_inline_decode(xdr, 4);
3058 if (unlikely(!p))
3059 goto out_overflow;
3060 *type = be32_to_cpup(p);
3061 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3062 }
3063 dprintk("%s: expire type=0x%x\n", __func__, *type);
3064 return 0;
3065out_overflow:
3066 print_overflow_msg(__func__, xdr);
3067 return -EIO;
3068}
3069
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3071{
Al Viro8687b632006-10-19 23:28:48 -07003072 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003073 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074
3075 *change = 0;
3076 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3077 return -EIO;
3078 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003079 p = xdr_inline_decode(xdr, 8);
3080 if (unlikely(!p))
3081 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003082 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003084 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003086 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003088 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003089out_overflow:
3090 print_overflow_msg(__func__, xdr);
3091 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092}
3093
3094static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3095{
Al Viro8687b632006-10-19 23:28:48 -07003096 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003097 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098
3099 *size = 0;
3100 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3101 return -EIO;
3102 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003103 p = xdr_inline_decode(xdr, 8);
3104 if (unlikely(!p))
3105 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003106 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003108 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003110 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003111 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003112out_overflow:
3113 print_overflow_msg(__func__, xdr);
3114 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115}
3116
3117static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3118{
Al Viro8687b632006-10-19 23:28:48 -07003119 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120
3121 *res = 0;
3122 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3123 return -EIO;
3124 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003125 p = xdr_inline_decode(xdr, 4);
3126 if (unlikely(!p))
3127 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003128 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3130 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003131 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003133out_overflow:
3134 print_overflow_msg(__func__, xdr);
3135 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136}
3137
3138static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3139{
Al Viro8687b632006-10-19 23:28:48 -07003140 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141
3142 *res = 0;
3143 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3144 return -EIO;
3145 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003146 p = xdr_inline_decode(xdr, 4);
3147 if (unlikely(!p))
3148 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003149 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3151 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003152 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003154out_overflow:
3155 print_overflow_msg(__func__, xdr);
3156 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157}
3158
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003159static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160{
Al Viro8687b632006-10-19 23:28:48 -07003161 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003162 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163
3164 fsid->major = 0;
3165 fsid->minor = 0;
3166 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3167 return -EIO;
3168 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003169 p = xdr_inline_decode(xdr, 16);
3170 if (unlikely(!p))
3171 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003172 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003173 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003175 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003177 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 (unsigned long long)fsid->major,
3179 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003180 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003181out_overflow:
3182 print_overflow_msg(__func__, xdr);
3183 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184}
3185
3186static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3187{
Al Viro8687b632006-10-19 23:28:48 -07003188 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189
3190 *res = 60;
3191 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3192 return -EIO;
3193 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003194 p = xdr_inline_decode(xdr, 4);
3195 if (unlikely(!p))
3196 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003197 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3199 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003200 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003202out_overflow:
3203 print_overflow_msg(__func__, xdr);
3204 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205}
3206
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003207static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003208{
3209 __be32 *p;
3210
3211 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3212 return -EIO;
3213 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3214 p = xdr_inline_decode(xdr, 4);
3215 if (unlikely(!p))
3216 goto out_overflow;
3217 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003218 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003219 }
3220 return 0;
3221out_overflow:
3222 print_overflow_msg(__func__, xdr);
3223 return -EIO;
3224}
3225
3226static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3227{
3228 __be32 *p;
3229 int len;
3230
Trond Myklebust7ad07352010-10-23 15:34:20 -04003231 if (fh != NULL)
3232 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003233
3234 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3235 return -EIO;
3236 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3237 p = xdr_inline_decode(xdr, 4);
3238 if (unlikely(!p))
3239 goto out_overflow;
3240 len = be32_to_cpup(p);
3241 if (len > NFS4_FHSIZE)
3242 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003243 p = xdr_inline_decode(xdr, len);
3244 if (unlikely(!p))
3245 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003246 if (fh != NULL) {
3247 memcpy(fh->data, p, len);
3248 fh->size = len;
3249 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003250 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3251 }
3252 return 0;
3253out_overflow:
3254 print_overflow_msg(__func__, xdr);
3255 return -EIO;
3256}
3257
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3259{
Al Viro8687b632006-10-19 23:28:48 -07003260 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261
3262 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3263 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3264 return -EIO;
3265 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003266 p = xdr_inline_decode(xdr, 4);
3267 if (unlikely(!p))
3268 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003269 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3271 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003272 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003274out_overflow:
3275 print_overflow_msg(__func__, xdr);
3276 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277}
3278
3279static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3280{
Al Viro8687b632006-10-19 23:28:48 -07003281 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003282 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283
3284 *fileid = 0;
3285 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3286 return -EIO;
3287 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003288 p = xdr_inline_decode(xdr, 8);
3289 if (unlikely(!p))
3290 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003291 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003293 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003295 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003296 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003297out_overflow:
3298 print_overflow_msg(__func__, xdr);
3299 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300}
3301
Manoj Naik99baf622006-06-09 09:34:24 -04003302static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3303{
Al Viro8687b632006-10-19 23:28:48 -07003304 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003305 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003306
3307 *fileid = 0;
3308 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3309 return -EIO;
3310 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003311 p = xdr_inline_decode(xdr, 8);
3312 if (unlikely(!p))
3313 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003314 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003315 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003316 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003317 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003318 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003319 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003320out_overflow:
3321 print_overflow_msg(__func__, xdr);
3322 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003323}
3324
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3326{
Al Viro8687b632006-10-19 23:28:48 -07003327 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 int status = 0;
3329
3330 *res = 0;
3331 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3332 return -EIO;
3333 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003334 p = xdr_inline_decode(xdr, 8);
3335 if (unlikely(!p))
3336 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003337 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3339 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003340 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003342out_overflow:
3343 print_overflow_msg(__func__, xdr);
3344 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345}
3346
3347static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3348{
Al Viro8687b632006-10-19 23:28:48 -07003349 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 int status = 0;
3351
3352 *res = 0;
3353 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3354 return -EIO;
3355 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003356 p = xdr_inline_decode(xdr, 8);
3357 if (unlikely(!p))
3358 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003359 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3361 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003362 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003364out_overflow:
3365 print_overflow_msg(__func__, xdr);
3366 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367}
3368
3369static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3370{
Al Viro8687b632006-10-19 23:28:48 -07003371 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 int status = 0;
3373
3374 *res = 0;
3375 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3376 return -EIO;
3377 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003378 p = xdr_inline_decode(xdr, 8);
3379 if (unlikely(!p))
3380 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003381 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3383 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003384 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003386out_overflow:
3387 print_overflow_msg(__func__, xdr);
3388 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389}
3390
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003391static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3392{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003393 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003394 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003395 int status = 0;
3396
Benny Halevyc0eae662009-08-14 17:20:14 +03003397 p = xdr_inline_decode(xdr, 4);
3398 if (unlikely(!p))
3399 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003400 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003401 if (n == 0)
3402 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003403 dprintk("pathname4: ");
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003404 path->ncomponents = 0;
3405 while (path->ncomponents < n) {
3406 struct nfs4_string *component = &path->components[path->ncomponents];
3407 status = decode_opaque_inline(xdr, &component->len, &component->data);
3408 if (unlikely(status != 0))
3409 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003410 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003411 pr_cont("%s%.*s ",
3412 (path->ncomponents != n ? "/ " : ""),
3413 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003414 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3415 path->ncomponents++;
3416 else {
3417 dprintk("cannot parse %d components in path\n", n);
3418 goto out_eio;
3419 }
3420 }
3421out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003422 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003423root_path:
3424/* a root pathname is sent as a zero component4 */
3425 path->ncomponents = 1;
3426 path->components[0].len=0;
3427 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003428 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003429 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003430out_eio:
3431 dprintk(" status %d", status);
3432 status = -EIO;
3433 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003434out_overflow:
3435 print_overflow_msg(__func__, xdr);
3436 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003437}
3438
3439static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003440{
3441 int n;
Al Viro8687b632006-10-19 23:28:48 -07003442 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003443 int status = -EIO;
3444
3445 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3446 goto out;
3447 status = 0;
3448 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3449 goto out;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003450 status = -EIO;
3451 /* Ignore borken servers that return unrequested attrs */
3452 if (unlikely(res == NULL))
3453 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003454 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003455 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003456 if (unlikely(status != 0))
3457 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003458 p = xdr_inline_decode(xdr, 4);
3459 if (unlikely(!p))
3460 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003461 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003462 if (n <= 0)
3463 goto out_eio;
3464 res->nlocations = 0;
3465 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003466 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003467 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003468
Benny Halevyc0eae662009-08-14 17:20:14 +03003469 p = xdr_inline_decode(xdr, 4);
3470 if (unlikely(!p))
3471 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003472 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003473
3474 loc->nservers = 0;
Chuck Lever02a29762012-03-01 17:00:31 -05003475 dprintk("%s: servers:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003476 while (loc->nservers < m) {
3477 struct nfs4_string *server = &loc->servers[loc->nservers];
3478 status = decode_opaque_inline(xdr, &server->len, &server->data);
3479 if (unlikely(status != 0))
3480 goto out_eio;
3481 dprintk("%s ", server->data);
3482 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3483 loc->nservers++;
3484 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003485 unsigned int i;
3486 dprintk("%s: using first %u of %u servers "
3487 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003488 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003489 NFS4_FS_LOCATION_MAXSERVERS,
3490 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003491 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003492 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003493 char *data;
3494 status = decode_opaque_inline(xdr, &len, &data);
3495 if (unlikely(status != 0))
3496 goto out_eio;
3497 }
3498 }
3499 }
3500 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003501 if (unlikely(status != 0))
3502 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003503 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003504 res->nlocations++;
3505 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003506 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003507 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003508out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003509 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003510 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003511out_overflow:
3512 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003513out_eio:
3514 status = -EIO;
3515 goto out;
3516}
3517
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3519{
Al Viro8687b632006-10-19 23:28:48 -07003520 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 int status = 0;
3522
3523 *res = 0;
3524 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3525 return -EIO;
3526 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003527 p = xdr_inline_decode(xdr, 8);
3528 if (unlikely(!p))
3529 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003530 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3532 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003533 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003535out_overflow:
3536 print_overflow_msg(__func__, xdr);
3537 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538}
3539
3540static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3541{
Al Viro8687b632006-10-19 23:28:48 -07003542 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543 int status = 0;
3544
3545 *maxlink = 1;
3546 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3547 return -EIO;
3548 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003549 p = xdr_inline_decode(xdr, 4);
3550 if (unlikely(!p))
3551 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003552 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3554 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003555 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003557out_overflow:
3558 print_overflow_msg(__func__, xdr);
3559 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560}
3561
3562static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3563{
Al Viro8687b632006-10-19 23:28:48 -07003564 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565 int status = 0;
3566
3567 *maxname = 1024;
3568 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3569 return -EIO;
3570 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003571 p = xdr_inline_decode(xdr, 4);
3572 if (unlikely(!p))
3573 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003574 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3576 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003577 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003579out_overflow:
3580 print_overflow_msg(__func__, xdr);
3581 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582}
3583
3584static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3585{
Al Viro8687b632006-10-19 23:28:48 -07003586 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587 int status = 0;
3588
3589 *res = 1024;
3590 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3591 return -EIO;
3592 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3593 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003594 p = xdr_inline_decode(xdr, 8);
3595 if (unlikely(!p))
3596 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003597 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 if (maxread > 0x7FFFFFFF)
3599 maxread = 0x7FFFFFFF;
3600 *res = (uint32_t)maxread;
3601 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3602 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003603 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003605out_overflow:
3606 print_overflow_msg(__func__, xdr);
3607 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608}
3609
3610static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3611{
Al Viro8687b632006-10-19 23:28:48 -07003612 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 int status = 0;
3614
3615 *res = 1024;
3616 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3617 return -EIO;
3618 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3619 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003620 p = xdr_inline_decode(xdr, 8);
3621 if (unlikely(!p))
3622 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003623 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 if (maxwrite > 0x7FFFFFFF)
3625 maxwrite = 0x7FFFFFFF;
3626 *res = (uint32_t)maxwrite;
3627 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3628 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003629 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003631out_overflow:
3632 print_overflow_msg(__func__, xdr);
3633 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634}
3635
Trond Myklebustbca79472009-03-11 14:10:26 -04003636static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637{
Trond Myklebustbca79472009-03-11 14:10:26 -04003638 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003639 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003640 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641
3642 *mode = 0;
3643 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3644 return -EIO;
3645 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003646 p = xdr_inline_decode(xdr, 4);
3647 if (unlikely(!p))
3648 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003649 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003650 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003652 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003654 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003655 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003656out_overflow:
3657 print_overflow_msg(__func__, xdr);
3658 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659}
3660
3661static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3662{
Al Viro8687b632006-10-19 23:28:48 -07003663 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003664 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665
3666 *nlink = 1;
3667 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3668 return -EIO;
3669 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003670 p = xdr_inline_decode(xdr, 4);
3671 if (unlikely(!p))
3672 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003673 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003675 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003677 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003678 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003679out_overflow:
3680 print_overflow_msg(__func__, xdr);
3681 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682}
3683
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003684static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003685 const struct nfs_server *server, uint32_t *uid,
3686 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687{
Al Viro8687b632006-10-19 23:28:48 -07003688 uint32_t len;
3689 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003690 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691
3692 *uid = -2;
3693 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3694 return -EIO;
3695 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003696 p = xdr_inline_decode(xdr, 4);
3697 if (unlikely(!p))
3698 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003699 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003700 p = xdr_inline_decode(xdr, len);
3701 if (unlikely(!p))
3702 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003703 if (owner_name != NULL) {
3704 owner_name->data = kmemdup(p, len, GFP_NOWAIT);
3705 if (owner_name->data != NULL) {
3706 owner_name->len = len;
3707 ret = NFS_ATTR_FATTR_OWNER_NAME;
3708 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003709 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003710 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003711 ret = NFS_ATTR_FATTR_OWNER;
3712 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003714 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003716 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003717 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3719 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003720 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003721 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003722out_overflow:
3723 print_overflow_msg(__func__, xdr);
3724 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725}
3726
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003727static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003728 const struct nfs_server *server, uint32_t *gid,
3729 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730{
Al Viro8687b632006-10-19 23:28:48 -07003731 uint32_t len;
3732 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003733 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734
3735 *gid = -2;
3736 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3737 return -EIO;
3738 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003739 p = xdr_inline_decode(xdr, 4);
3740 if (unlikely(!p))
3741 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003742 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003743 p = xdr_inline_decode(xdr, len);
3744 if (unlikely(!p))
3745 goto out_overflow;
Trond Myklebust6926afd2012-01-07 13:22:46 -05003746 if (group_name != NULL) {
3747 group_name->data = kmemdup(p, len, GFP_NOWAIT);
3748 if (group_name->data != NULL) {
3749 group_name->len = len;
3750 ret = NFS_ATTR_FATTR_GROUP_NAME;
3751 }
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003752 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003753 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003754 ret = NFS_ATTR_FATTR_GROUP;
3755 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003757 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003759 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003760 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3762 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003763 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003764 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003765out_overflow:
3766 print_overflow_msg(__func__, xdr);
3767 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768}
3769
3770static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3771{
Al Viro8687b632006-10-19 23:28:48 -07003772 uint32_t major = 0, minor = 0;
3773 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003774 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775
3776 *rdev = MKDEV(0,0);
3777 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3778 return -EIO;
3779 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3780 dev_t tmp;
3781
Benny Halevyc0eae662009-08-14 17:20:14 +03003782 p = xdr_inline_decode(xdr, 8);
3783 if (unlikely(!p))
3784 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003785 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003786 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 tmp = MKDEV(major, minor);
3788 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3789 *rdev = tmp;
3790 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003791 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003793 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003794 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003795out_overflow:
3796 print_overflow_msg(__func__, xdr);
3797 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798}
3799
3800static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3801{
Al Viro8687b632006-10-19 23:28:48 -07003802 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 int status = 0;
3804
3805 *res = 0;
3806 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3807 return -EIO;
3808 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003809 p = xdr_inline_decode(xdr, 8);
3810 if (unlikely(!p))
3811 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003812 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3814 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003815 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003817out_overflow:
3818 print_overflow_msg(__func__, xdr);
3819 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820}
3821
3822static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3823{
Al Viro8687b632006-10-19 23:28:48 -07003824 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 int status = 0;
3826
3827 *res = 0;
3828 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3829 return -EIO;
3830 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003831 p = xdr_inline_decode(xdr, 8);
3832 if (unlikely(!p))
3833 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003834 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3836 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003837 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003839out_overflow:
3840 print_overflow_msg(__func__, xdr);
3841 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842}
3843
3844static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3845{
Al Viro8687b632006-10-19 23:28:48 -07003846 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 int status = 0;
3848
3849 *res = 0;
3850 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3851 return -EIO;
3852 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003853 p = xdr_inline_decode(xdr, 8);
3854 if (unlikely(!p))
3855 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003856 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3858 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003859 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003861out_overflow:
3862 print_overflow_msg(__func__, xdr);
3863 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864}
3865
3866static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3867{
Al Viro8687b632006-10-19 23:28:48 -07003868 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003869 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870
3871 *used = 0;
3872 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3873 return -EIO;
3874 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003875 p = xdr_inline_decode(xdr, 8);
3876 if (unlikely(!p))
3877 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003878 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003880 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003882 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003884 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003885out_overflow:
3886 print_overflow_msg(__func__, xdr);
3887 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888}
3889
3890static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3891{
Al Viro8687b632006-10-19 23:28:48 -07003892 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 uint64_t sec;
3894 uint32_t nsec;
3895
Benny Halevyc0eae662009-08-14 17:20:14 +03003896 p = xdr_inline_decode(xdr, 12);
3897 if (unlikely(!p))
3898 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003899 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003900 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 time->tv_sec = (time_t)sec;
3902 time->tv_nsec = (long)nsec;
3903 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003904out_overflow:
3905 print_overflow_msg(__func__, xdr);
3906 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907}
3908
3909static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3910{
3911 int status = 0;
3912
3913 time->tv_sec = 0;
3914 time->tv_nsec = 0;
3915 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3916 return -EIO;
3917 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3918 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003919 if (status == 0)
3920 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3922 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003923 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924 return status;
3925}
3926
3927static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3928{
3929 int status = 0;
3930
3931 time->tv_sec = 0;
3932 time->tv_nsec = 0;
3933 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3934 return -EIO;
3935 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3936 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003937 if (status == 0)
3938 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3940 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003941 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 return status;
3943}
3944
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003945static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3946 struct timespec *time)
3947{
3948 int status = 0;
3949
3950 time->tv_sec = 0;
3951 time->tv_nsec = 0;
3952 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3953 return -EIO;
3954 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3955 status = decode_attr_time(xdr, time);
3956 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3957 }
3958 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3959 (long)time->tv_nsec);
3960 return status;
3961}
3962
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3964{
3965 int status = 0;
3966
3967 time->tv_sec = 0;
3968 time->tv_nsec = 0;
3969 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3970 return -EIO;
3971 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3972 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003973 if (status == 0)
3974 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3976 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003977 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 return status;
3979}
3980
Al Viro8687b632006-10-19 23:28:48 -07003981static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982{
3983 unsigned int attrwords = XDR_QUADLEN(attrlen);
3984 unsigned int nwords = xdr->p - savep;
3985
3986 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003987 dprintk("%s: server returned incorrect attribute length: "
3988 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003989 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 attrwords << 2,
3991 (attrwords < nwords) ? '<' : '>',
3992 nwords << 2);
3993 return -EIO;
3994 }
3995 return 0;
3996}
3997
3998static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3999{
Al Viro8687b632006-10-19 23:28:48 -07004000 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001
Benny Halevyc0eae662009-08-14 17:20:14 +03004002 p = xdr_inline_decode(xdr, 20);
4003 if (unlikely(!p))
4004 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004005 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004006 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004007 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004009out_overflow:
4010 print_overflow_msg(__func__, xdr);
4011 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012}
4013
4014static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4015{
Al Viro8687b632006-10-19 23:28:48 -07004016 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 uint32_t supp, acc;
4018 int status;
4019
4020 status = decode_op_hdr(xdr, OP_ACCESS);
4021 if (status)
4022 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004023 p = xdr_inline_decode(xdr, 8);
4024 if (unlikely(!p))
4025 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004026 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004027 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 access->supported = supp;
4029 access->access = acc;
4030 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004031out_overflow:
4032 print_overflow_msg(__func__, xdr);
4033 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034}
4035
Benny Halevy07d30432009-08-14 17:19:52 +03004036static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037{
Al Viro8687b632006-10-19 23:28:48 -07004038 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004039
4040 p = xdr_inline_decode(xdr, len);
4041 if (likely(p)) {
4042 memcpy(buf, p, len);
4043 return 0;
4044 }
4045 print_overflow_msg(__func__, xdr);
4046 return -EIO;
4047}
4048
4049static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4050{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004051 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052}
4053
4054static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4055{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 int status;
4057
4058 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004059 if (status != -EIO)
4060 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004061 if (!status)
4062 status = decode_stateid(xdr, &res->stateid);
4063 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064}
4065
Benny Halevydb942bb2009-08-14 17:19:56 +03004066static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4067{
Chuck Levercd937102012-03-02 17:14:31 -05004068 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069}
4070
Fred Isaman0b7c0152012-04-20 14:47:39 -04004071static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 int status;
4074
4075 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004076 if (!status)
4077 status = decode_verifier(xdr, res->verf->verifier);
4078 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079}
4080
4081static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4082{
Al Viro8687b632006-10-19 23:28:48 -07004083 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 uint32_t bmlen;
4085 int status;
4086
4087 status = decode_op_hdr(xdr, OP_CREATE);
4088 if (status)
4089 return status;
4090 if ((status = decode_change_info(xdr, cinfo)))
4091 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004092 p = xdr_inline_decode(xdr, 4);
4093 if (unlikely(!p))
4094 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004095 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004096 p = xdr_inline_decode(xdr, bmlen << 2);
4097 if (likely(p))
4098 return 0;
4099out_overflow:
4100 print_overflow_msg(__func__, xdr);
4101 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102}
4103
4104static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4105{
Al Viro8687b632006-10-19 23:28:48 -07004106 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004107 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108 int status;
4109
4110 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4111 goto xdr_error;
4112 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4113 goto xdr_error;
4114 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4115 goto xdr_error;
4116 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4117 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004118 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4119 &res->fh_expire_type)) != 0)
4120 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4122 goto xdr_error;
4123 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4124 goto xdr_error;
4125 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4126 goto xdr_error;
4127 status = verify_attr_len(xdr, savep, attrlen);
4128xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004129 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130 return status;
4131}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004132
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4134{
Al Viro8687b632006-10-19 23:28:48 -07004135 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004136 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004138
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4140 goto xdr_error;
4141 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4142 goto xdr_error;
4143 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4144 goto xdr_error;
4145
4146 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4147 goto xdr_error;
4148 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4149 goto xdr_error;
4150 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4151 goto xdr_error;
4152 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4153 goto xdr_error;
4154 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4155 goto xdr_error;
4156 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4157 goto xdr_error;
4158
4159 status = verify_attr_len(xdr, savep, attrlen);
4160xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004161 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162 return status;
4163}
4164
4165static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4166{
Al Viro8687b632006-10-19 23:28:48 -07004167 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004168 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004170
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4172 goto xdr_error;
4173 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4174 goto xdr_error;
4175 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4176 goto xdr_error;
4177
4178 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4179 goto xdr_error;
4180 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4181 goto xdr_error;
4182
4183 status = verify_attr_len(xdr, savep, attrlen);
4184xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004185 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 return status;
4187}
4188
Bryan Schumakerae42c702010-10-21 16:33:17 -04004189static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4190 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004191 struct nfs4_fs_locations *fs_loc,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004192 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193{
Trond Myklebustbca79472009-03-11 14:10:26 -04004194 int status;
4195 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004196 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004197 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004199 status = decode_attr_type(xdr, bitmap, &type);
4200 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004202 fattr->mode = 0;
4203 if (status != 0) {
4204 fattr->mode |= nfs_type2fmt[type];
4205 fattr->valid |= status;
4206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004208 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4209 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004211 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004212
4213 status = decode_attr_size(xdr, bitmap, &fattr->size);
4214 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004216 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004217
4218 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4219 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004221 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004222
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004223 err = 0;
4224 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004225 if (status < 0)
4226 goto xdr_error;
4227
4228 status = decode_attr_filehandle(xdr, bitmap, fh);
4229 if (status < 0)
4230 goto xdr_error;
4231
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004232 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4233 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004235 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004236
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004237 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004238 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004239 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004240 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004241
4242 status = decode_attr_mode(xdr, bitmap, &fmode);
4243 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004245 if (status != 0) {
4246 fattr->mode |= fmode;
4247 fattr->valid |= status;
4248 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004249
4250 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4251 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004253 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004254
Trond Myklebust6926afd2012-01-07 13:22:46 -05004255 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004256 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004258 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004259
Trond Myklebust6926afd2012-01-07 13:22:46 -05004260 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004261 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004263 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004264
4265 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4266 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004268 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004269
4270 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4271 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004273 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004274
4275 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4276 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004278 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004279
4280 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4281 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004283 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004284
4285 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4286 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004288 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004289
Trond Myklebust28331a42011-04-27 13:47:52 -04004290 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004291 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004292 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004293 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004294
Bryan Schumakerae42c702010-10-21 16:33:17 -04004295xdr_error:
4296 dprintk("%s: xdr returned %d\n", __func__, -status);
4297 return status;
4298}
4299
4300static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004301 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4302 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004303{
4304 __be32 *savep;
4305 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004306 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004307 int status;
4308
4309 status = decode_op_hdr(xdr, OP_GETATTR);
4310 if (status < 0)
4311 goto xdr_error;
4312
4313 status = decode_attr_bitmap(xdr, bitmap);
4314 if (status < 0)
4315 goto xdr_error;
4316
4317 status = decode_attr_length(xdr, &attrlen, &savep);
4318 if (status < 0)
4319 goto xdr_error;
4320
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004321 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004322 if (status < 0)
4323 goto xdr_error;
4324
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004325 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004327 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 return status;
4329}
4330
Bryan Schumakerae42c702010-10-21 16:33:17 -04004331static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004332 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004333{
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004334 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004335}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336
Andy Adamson504913f2010-10-20 00:17:57 -04004337/*
4338 * Decode potentially multiple layout types. Currently we only support
4339 * one layout driver per file system.
4340 */
4341static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4342 uint32_t *layouttype)
4343{
4344 uint32_t *p;
4345 int num;
4346
4347 p = xdr_inline_decode(xdr, 4);
4348 if (unlikely(!p))
4349 goto out_overflow;
4350 num = be32_to_cpup(p);
4351
4352 /* pNFS is not supported by the underlying file system */
4353 if (num == 0) {
4354 *layouttype = 0;
4355 return 0;
4356 }
4357 if (num > 1)
Weston Andros Adamsona0308892012-01-26 13:32:23 -05004358 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4359 "drivers per filesystem not supported\n", __func__);
Andy Adamson504913f2010-10-20 00:17:57 -04004360
4361 /* Decode and set first layout type, move xdr->p past unused types */
4362 p = xdr_inline_decode(xdr, num * 4);
4363 if (unlikely(!p))
4364 goto out_overflow;
4365 *layouttype = be32_to_cpup(p);
4366 return 0;
4367out_overflow:
4368 print_overflow_msg(__func__, xdr);
4369 return -EIO;
4370}
4371
4372/*
4373 * The type of file system exported.
4374 * Note we must ensure that layouttype is set in any non-error case.
4375 */
4376static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4377 uint32_t *layouttype)
4378{
4379 int status = 0;
4380
4381 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4382 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4383 return -EIO;
4384 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4385 status = decode_first_pnfs_layout_type(xdr, layouttype);
4386 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4387 } else
4388 *layouttype = 0;
4389 return status;
4390}
4391
Fred Isamandae100c2011-07-30 20:52:37 -04004392/*
4393 * The prefered block size for layout directed io
4394 */
4395static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4396 uint32_t *res)
4397{
4398 __be32 *p;
4399
4400 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4401 *res = 0;
4402 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4403 p = xdr_inline_decode(xdr, 4);
4404 if (unlikely(!p)) {
4405 print_overflow_msg(__func__, xdr);
4406 return -EIO;
4407 }
4408 *res = be32_to_cpup(p);
4409 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4410 }
4411 return 0;
4412}
4413
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4415{
Al Viro8687b632006-10-19 23:28:48 -07004416 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004417 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 int status;
4419
4420 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4421 goto xdr_error;
4422 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4423 goto xdr_error;
4424 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4425 goto xdr_error;
4426
4427 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4428
4429 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4430 goto xdr_error;
4431 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4432 goto xdr_error;
4433 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4434 goto xdr_error;
4435 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4436 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4437 goto xdr_error;
4438 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004439 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4440 if (status != 0)
4441 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004442 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4443 if (status != 0)
4444 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004445 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4446 if (status)
4447 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448
4449 status = verify_attr_len(xdr, savep, attrlen);
4450xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004451 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004452 return status;
4453}
4454
4455static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4456{
Al Viro8687b632006-10-19 23:28:48 -07004457 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 uint32_t len;
4459 int status;
4460
Trond Myklebust99367812007-07-17 21:52:41 -04004461 /* Zero handle first to allow comparisons */
4462 memset(fh, 0, sizeof(*fh));
4463
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 status = decode_op_hdr(xdr, OP_GETFH);
4465 if (status)
4466 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467
Benny Halevyc0eae662009-08-14 17:20:14 +03004468 p = xdr_inline_decode(xdr, 4);
4469 if (unlikely(!p))
4470 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004471 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472 if (len > NFS4_FHSIZE)
4473 return -EIO;
4474 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004475 p = xdr_inline_decode(xdr, len);
4476 if (unlikely(!p))
4477 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004478 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004480out_overflow:
4481 print_overflow_msg(__func__, xdr);
4482 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483}
4484
4485static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4486{
4487 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004488
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 status = decode_op_hdr(xdr, OP_LINK);
4490 if (status)
4491 return status;
4492 return decode_change_info(xdr, cinfo);
4493}
4494
4495/*
4496 * We create the owner, so we know a proper owner.id length is 4.
4497 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004498static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004500 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004501 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004502 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004504 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004505 if (unlikely(!p))
4506 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004507 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004508 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004509 type = be32_to_cpup(p++); /* 4 byte read */
4510 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004511 fl->fl_start = (loff_t)offset;
4512 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4513 if (length == ~(uint64_t)0)
4514 fl->fl_end = OFFSET_MAX;
4515 fl->fl_type = F_WRLCK;
4516 if (type & 1)
4517 fl->fl_type = F_RDLCK;
4518 fl->fl_pid = 0;
4519 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004520 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4521 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4522 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004523 if (likely(p))
4524 return -NFS4ERR_DENIED;
4525out_overflow:
4526 print_overflow_msg(__func__, xdr);
4527 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528}
4529
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004530static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532 int status;
4533
4534 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004535 if (status == -EIO)
4536 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004538 status = decode_stateid(xdr, &res->stateid);
4539 if (unlikely(status))
4540 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004542 status = decode_lock_denied(xdr, NULL);
4543 if (res->open_seqid != NULL)
4544 nfs_increment_open_seqid(status, res->open_seqid);
4545 nfs_increment_lock_seqid(status, res->lock_seqid);
4546out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547 return status;
4548}
4549
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004550static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551{
4552 int status;
4553 status = decode_op_hdr(xdr, OP_LOCKT);
4554 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004555 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556 return status;
4557}
4558
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004559static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561 int status;
4562
4563 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004564 if (status != -EIO)
4565 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004566 if (status == 0)
4567 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 return status;
4569}
4570
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004571static int decode_release_lockowner(struct xdr_stream *xdr)
4572{
4573 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4574}
4575
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576static int decode_lookup(struct xdr_stream *xdr)
4577{
4578 return decode_op_hdr(xdr, OP_LOOKUP);
4579}
4580
4581/* This is too sick! */
4582static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4583{
Andy Adamson05d564f2008-12-23 16:06:15 -05004584 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585 uint32_t limit_type, nblocks, blocksize;
4586
Benny Halevyc0eae662009-08-14 17:20:14 +03004587 p = xdr_inline_decode(xdr, 12);
4588 if (unlikely(!p))
4589 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004590 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004591 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004592 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004593 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004594 break;
4595 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004596 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004597 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004598 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599 }
4600 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004601out_overflow:
4602 print_overflow_msg(__func__, xdr);
4603 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604}
4605
4606static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4607{
Andy Adamson05d564f2008-12-23 16:06:15 -05004608 __be32 *p;
4609 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004610 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611
Benny Halevyc0eae662009-08-14 17:20:14 +03004612 p = xdr_inline_decode(xdr, 4);
4613 if (unlikely(!p))
4614 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004615 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4617 res->delegation_type = 0;
4618 return 0;
4619 }
Benny Halevy07d30432009-08-14 17:19:52 +03004620 status = decode_stateid(xdr, &res->delegation);
4621 if (unlikely(status))
4622 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004623 p = xdr_inline_decode(xdr, 4);
4624 if (unlikely(!p))
4625 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004626 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004627
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004629 case NFS4_OPEN_DELEGATE_READ:
4630 res->delegation_type = FMODE_READ;
4631 break;
4632 case NFS4_OPEN_DELEGATE_WRITE:
4633 res->delegation_type = FMODE_WRITE|FMODE_READ;
4634 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635 return -EIO;
4636 }
David Howells7539bba2006-08-22 20:06:09 -04004637 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004638out_overflow:
4639 print_overflow_msg(__func__, xdr);
4640 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641}
4642
4643static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4644{
Andy Adamson05d564f2008-12-23 16:06:15 -05004645 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004646 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004647 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648
Andy Adamson05d564f2008-12-23 16:06:15 -05004649 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004650 if (status != -EIO)
4651 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004652 if (!status)
4653 status = decode_stateid(xdr, &res->stateid);
4654 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004655 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656
Andy Adamson05d564f2008-12-23 16:06:15 -05004657 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658
Benny Halevyc0eae662009-08-14 17:20:14 +03004659 p = xdr_inline_decode(xdr, 8);
4660 if (unlikely(!p))
4661 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004662 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004663 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004664 if (bmlen > 10)
4665 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666
Benny Halevyc0eae662009-08-14 17:20:14 +03004667 p = xdr_inline_decode(xdr, bmlen << 2);
4668 if (unlikely(!p))
4669 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004670 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4671 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004672 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004673 for (; i < NFS4_BITMAP_SIZE; i++)
4674 res->attrset[i] = 0;
4675
Linus Torvalds1da177e2005-04-16 15:20:36 -07004676 return decode_delegation(xdr, res);
4677xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004678 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004679 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004680out_overflow:
4681 print_overflow_msg(__func__, xdr);
4682 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683}
4684
4685static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4686{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004687 int status;
4688
Andy Adamson05d564f2008-12-23 16:06:15 -05004689 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004690 if (status != -EIO)
4691 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004692 if (!status)
4693 status = decode_stateid(xdr, &res->stateid);
4694 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695}
4696
4697static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4698{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004699 int status;
4700
4701 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004702 if (status != -EIO)
4703 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004704 if (!status)
4705 status = decode_stateid(xdr, &res->stateid);
4706 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707}
4708
4709static int decode_putfh(struct xdr_stream *xdr)
4710{
4711 return decode_op_hdr(xdr, OP_PUTFH);
4712}
4713
4714static int decode_putrootfh(struct xdr_stream *xdr)
4715{
4716 return decode_op_hdr(xdr, OP_PUTROOTFH);
4717}
4718
4719static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4720{
4721 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004722 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 uint32_t count, eof, recvd, hdrlen;
4724 int status;
4725
4726 status = decode_op_hdr(xdr, OP_READ);
4727 if (status)
4728 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004729 p = xdr_inline_decode(xdr, 8);
4730 if (unlikely(!p))
4731 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004732 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004733 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004734 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 recvd = req->rq_rcv_buf.len - hdrlen;
4736 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004737 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004738 "count %u > recvd %u\n", count, recvd);
4739 count = recvd;
4740 eof = 0;
4741 }
4742 xdr_read_pages(xdr, count);
4743 res->eof = eof;
4744 res->count = count;
4745 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004746out_overflow:
4747 print_overflow_msg(__func__, xdr);
4748 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749}
4750
4751static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4752{
4753 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004755 size_t hdrlen;
4756 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004757 int status;
Chuck Levercd937102012-03-02 17:14:31 -05004758 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759
4760 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004761 if (!status)
4762 status = decode_verifier(xdr, readdir->verifier.data);
4763 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764 return status;
Chuck Levercd937102012-03-02 17:14:31 -05004765 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03004766 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05004767 __func__, verf[0], verf[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768
Benny Halevydb942bb2009-08-14 17:19:56 +03004769 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 recvd = rcvbuf->len - hdrlen;
4771 if (pglen > recvd)
4772 pglen = recvd;
4773 xdr_read_pages(xdr, pglen);
4774
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004775
Trond Myklebustac396122010-11-15 20:26:22 -05004776 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777}
4778
4779static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4780{
4781 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4782 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004783 size_t hdrlen;
4784 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004785 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 int status;
4787
4788 status = decode_op_hdr(xdr, OP_READLINK);
4789 if (status)
4790 return status;
4791
4792 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004793 p = xdr_inline_decode(xdr, 4);
4794 if (unlikely(!p))
4795 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004796 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004798 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799 return -ENAMETOOLONG;
4800 }
4801 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4802 recvd = req->rq_rcv_buf.len - hdrlen;
4803 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004804 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004805 "count %u > recvd %u\n", len, recvd);
4806 return -EIO;
4807 }
4808 xdr_read_pages(xdr, len);
4809 /*
4810 * The XDR encode routine has set things up so that
4811 * the link text will be copied directly into the
4812 * buffer. We just have to do overflow-checking,
4813 * and and null-terminate the text (the VFS expects
4814 * null-termination).
4815 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004816 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004818out_overflow:
4819 print_overflow_msg(__func__, xdr);
4820 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004821}
4822
4823static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4824{
4825 int status;
4826
4827 status = decode_op_hdr(xdr, OP_REMOVE);
4828 if (status)
4829 goto out;
4830 status = decode_change_info(xdr, cinfo);
4831out:
4832 return status;
4833}
4834
4835static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4836 struct nfs4_change_info *new_cinfo)
4837{
4838 int status;
4839
4840 status = decode_op_hdr(xdr, OP_RENAME);
4841 if (status)
4842 goto out;
4843 if ((status = decode_change_info(xdr, old_cinfo)))
4844 goto out;
4845 status = decode_change_info(xdr, new_cinfo);
4846out:
4847 return status;
4848}
4849
4850static int decode_renew(struct xdr_stream *xdr)
4851{
4852 return decode_op_hdr(xdr, OP_RENEW);
4853}
4854
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004855static int
4856decode_restorefh(struct xdr_stream *xdr)
4857{
4858 return decode_op_hdr(xdr, OP_RESTOREFH);
4859}
4860
J. Bruce Fields029d1052005-06-22 17:16:22 +00004861static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05004862 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004863{
Andy Adamsonbf118a32011-12-07 11:55:27 -05004864 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004865 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004866 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00004867 struct kvec *iov = req->rq_rcv_buf.head;
4868 int status;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004869 size_t page_len = xdr->buf->page_len;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004870
Andy Adamsonbf118a32011-12-07 11:55:27 -05004871 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004872 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4873 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004874
Andy Adamsonbf118a32011-12-07 11:55:27 -05004875 bm_p = xdr->p;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004876 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4877 res->acl_data_offset <<= 2;
4878 /* Check if the acl data starts beyond the allocated buffer */
4879 if (res->acl_data_offset > page_len)
4880 return -ERANGE;
4881
J. Bruce Fields029d1052005-06-22 17:16:22 +00004882 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4883 goto out;
4884 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4885 goto out;
4886
4887 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4888 return -EIO;
4889 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004890 size_t hdrlen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004891
Andy Adamsonbf118a32011-12-07 11:55:27 -05004892 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
4893 * are stored with the acl data to handle the problem of
4894 * variable length bitmaps.*/
4895 xdr->p = bm_p;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004896
J. Bruce Fields029d1052005-06-22 17:16:22 +00004897 /* We ignore &savep and don't do consistency checks on
4898 * the attr length. Let userspace figure it out.... */
4899 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004900 attrlen += res->acl_data_offset;
Sachin Prabhu5a006892012-04-17 14:35:39 +01004901 if (attrlen > page_len) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05004902 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
4903 /* getxattr interface called with a NULL buf */
4904 res->acl_len = attrlen;
4905 goto out;
4906 }
Sachin Prabhu5794d212012-04-17 14:36:40 +01004907 dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
Sachin Prabhu5a006892012-04-17 14:35:39 +01004908 attrlen, page_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004909 return -EINVAL;
4910 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004911 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05004912 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004913 } else
4914 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004915
4916out:
4917 return status;
4918}
4919
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920static int
4921decode_savefh(struct xdr_stream *xdr)
4922{
4923 return decode_op_hdr(xdr, OP_SAVEFH);
4924}
4925
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004926static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004927{
Al Viro8687b632006-10-19 23:28:48 -07004928 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004929 uint32_t bmlen;
4930 int status;
4931
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932 status = decode_op_hdr(xdr, OP_SETATTR);
4933 if (status)
4934 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004935 p = xdr_inline_decode(xdr, 4);
4936 if (unlikely(!p))
4937 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004938 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004939 p = xdr_inline_decode(xdr, bmlen << 2);
4940 if (likely(p))
4941 return 0;
4942out_overflow:
4943 print_overflow_msg(__func__, xdr);
4944 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945}
4946
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004947static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948{
Al Viro8687b632006-10-19 23:28:48 -07004949 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950 uint32_t opnum;
4951 int32_t nfserr;
4952
Benny Halevyc0eae662009-08-14 17:20:14 +03004953 p = xdr_inline_decode(xdr, 8);
4954 if (unlikely(!p))
4955 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004956 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004957 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004958 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004959 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960 return -EIO;
4961 }
Benny Halevycccddf42009-08-14 17:20:19 +03004962 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004964 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4965 if (unlikely(!p))
4966 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004967 p = xdr_decode_hyper(p, &res->clientid);
4968 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969 } else if (nfserr == NFSERR_CLID_INUSE) {
4970 uint32_t len;
4971
4972 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004973 p = xdr_inline_decode(xdr, 4);
4974 if (unlikely(!p))
4975 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004976 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004977 p = xdr_inline_decode(xdr, len);
4978 if (unlikely(!p))
4979 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980
4981 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004982 p = xdr_inline_decode(xdr, 4);
4983 if (unlikely(!p))
4984 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004985 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004986 p = xdr_inline_decode(xdr, len);
4987 if (unlikely(!p))
4988 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989 return -NFSERR_CLID_INUSE;
4990 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004991 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992
4993 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004994out_overflow:
4995 print_overflow_msg(__func__, xdr);
4996 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997}
4998
4999static int decode_setclientid_confirm(struct xdr_stream *xdr)
5000{
5001 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5002}
5003
5004static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5005{
Al Viro8687b632006-10-19 23:28:48 -07005006 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 int status;
5008
5009 status = decode_op_hdr(xdr, OP_WRITE);
5010 if (status)
5011 return status;
5012
Benny Halevyc0eae662009-08-14 17:20:14 +03005013 p = xdr_inline_decode(xdr, 16);
5014 if (unlikely(!p))
5015 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005016 res->count = be32_to_cpup(p++);
5017 res->verf->committed = be32_to_cpup(p++);
Chuck Levercd937102012-03-02 17:14:31 -05005018 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005020out_overflow:
5021 print_overflow_msg(__func__, xdr);
5022 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023}
5024
5025static int decode_delegreturn(struct xdr_stream *xdr)
5026{
5027 return decode_op_hdr(xdr, OP_DELEGRETURN);
5028}
5029
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005030static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5031{
5032 __be32 *p;
5033
5034 p = xdr_inline_decode(xdr, 4);
5035 if (unlikely(!p))
5036 goto out_overflow;
5037 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5038 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5039 goto out_err;
5040
5041 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5042 if (unlikely(!p))
5043 goto out_overflow;
5044 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5045
5046 p = xdr_inline_decode(xdr, 8);
5047 if (unlikely(!p))
5048 goto out_overflow;
5049 flavor->gss.qop4 = be32_to_cpup(p++);
5050 flavor->gss.service = be32_to_cpup(p);
5051
5052 return 0;
5053
5054out_overflow:
5055 print_overflow_msg(__func__, xdr);
5056 return -EIO;
5057out_err:
5058 return -EINVAL;
5059}
5060
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005061static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005062{
5063 struct nfs4_secinfo_flavor *sec_flavor;
5064 int status;
5065 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005066 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005067
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005068 p = xdr_inline_decode(xdr, 4);
5069 if (unlikely(!p))
5070 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005071
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005072 res->flavors->num_flavors = 0;
5073 num_flavors = be32_to_cpup(p);
5074
5075 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005076 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005077 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005078 break;
5079
5080 p = xdr_inline_decode(xdr, 4);
5081 if (unlikely(!p))
5082 goto out_overflow;
5083 sec_flavor->flavor = be32_to_cpup(p);
5084
5085 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005086 status = decode_secinfo_gss(xdr, sec_flavor);
5087 if (status)
5088 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005089 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005090 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005091 }
5092
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005093 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005094out:
5095 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005096out_overflow:
5097 print_overflow_msg(__func__, xdr);
5098 return -EIO;
5099}
5100
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005101static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5102{
5103 int status = decode_op_hdr(xdr, OP_SECINFO);
5104 if (status)
5105 return status;
5106 return decode_secinfo_common(xdr, res);
5107}
5108
Benny Halevy99fe60d2009-04-01 09:22:29 -04005109#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005110static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5111{
5112 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5113 if (status)
5114 return status;
5115 return decode_secinfo_common(xdr, res);
5116}
5117
Benny Halevy99fe60d2009-04-01 09:22:29 -04005118static int decode_exchange_id(struct xdr_stream *xdr,
5119 struct nfs41_exchange_id_res *res)
5120{
5121 __be32 *p;
5122 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005123 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005124 int status;
5125 struct nfs_client *clp = res->client;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005126 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005127
5128 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5129 if (status)
5130 return status;
5131
Benny Halevyc0eae662009-08-14 17:20:14 +03005132 p = xdr_inline_decode(xdr, 8);
5133 if (unlikely(!p))
5134 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005135 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005136 p = xdr_inline_decode(xdr, 12);
5137 if (unlikely(!p))
5138 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005139 clp->cl_seqid = be32_to_cpup(p++);
5140 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005141
5142 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005143 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005144 if (dummy != SP4_NONE)
5145 return -EIO;
5146
Chuck Leveracdeb692012-05-21 22:46:16 -04005147 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005148 p = xdr_inline_decode(xdr, 8);
5149 if (unlikely(!p))
5150 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005151 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005152
Chuck Leveracdeb692012-05-21 22:46:16 -04005153 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005154 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5155 if (unlikely(status))
5156 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005157 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5158 return -EIO;
Chuck Leveracdeb692012-05-21 22:46:16 -04005159 memcpy(res->server_owner->major_id, dummy_str, dummy);
5160 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005161
Chuck Leveracdeb692012-05-21 22:46:16 -04005162 /* server_scope4 */
5163 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5164 if (unlikely(status))
5165 return status;
5166 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5167 return -EIO;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005168 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5169 res->server_scope->server_scope_sz = dummy;
5170
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005171 /* Implementation Id */
5172 p = xdr_inline_decode(xdr, 4);
5173 if (unlikely(!p))
5174 goto out_overflow;
5175 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005176
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005177 if (impl_id_count) {
5178 /* nii_domain */
5179 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5180 if (unlikely(status))
5181 return status;
5182 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5183 return -EIO;
5184 memcpy(res->impl_id->domain, dummy_str, dummy);
5185
5186 /* nii_name */
5187 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5188 if (unlikely(status))
5189 return status;
5190 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5191 return -EIO;
5192 memcpy(res->impl_id->name, dummy_str, dummy);
5193
5194 /* nii_date */
5195 p = xdr_inline_decode(xdr, 12);
5196 if (unlikely(!p))
5197 goto out_overflow;
5198 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5199 res->impl_id->date.nseconds = be32_to_cpup(p);
5200
5201 /* if there's more than one entry, ignore the rest */
5202 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005203 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005204out_overflow:
5205 print_overflow_msg(__func__, xdr);
5206 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005207}
Andy Adamsonfc931582009-04-01 09:22:31 -04005208
5209static int decode_chan_attrs(struct xdr_stream *xdr,
5210 struct nfs4_channel_attrs *attrs)
5211{
5212 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005213 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005214
Benny Halevyc0eae662009-08-14 17:20:14 +03005215 p = xdr_inline_decode(xdr, 28);
5216 if (unlikely(!p))
5217 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005218 val = be32_to_cpup(p++); /* headerpadsz */
5219 if (val)
5220 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005221 attrs->max_rqst_sz = be32_to_cpup(p++);
5222 attrs->max_resp_sz = be32_to_cpup(p++);
5223 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5224 attrs->max_ops = be32_to_cpup(p++);
5225 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005226 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005227 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005228 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5229 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005230 return -EINVAL;
5231 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005232 if (nr_attrs == 1) {
5233 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5234 if (unlikely(!p))
5235 goto out_overflow;
5236 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005237 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005238out_overflow:
5239 print_overflow_msg(__func__, xdr);
5240 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005241}
5242
Benny Halevye78291e2009-08-14 17:20:00 +03005243static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5244{
5245 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005246}
5247
5248static int decode_create_session(struct xdr_stream *xdr,
5249 struct nfs41_create_session_res *res)
5250{
5251 __be32 *p;
5252 int status;
5253 struct nfs_client *clp = res->client;
5254 struct nfs4_session *session = clp->cl_session;
5255
5256 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005257 if (!status)
5258 status = decode_sessionid(xdr, &session->sess_id);
5259 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005260 return status;
5261
Andy Adamsonfc931582009-04-01 09:22:31 -04005262 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005263 p = xdr_inline_decode(xdr, 8);
5264 if (unlikely(!p))
5265 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005266 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005267 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005268
5269 /* Channel attributes */
5270 status = decode_chan_attrs(xdr, &session->fc_attrs);
5271 if (!status)
5272 status = decode_chan_attrs(xdr, &session->bc_attrs);
5273 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005274out_overflow:
5275 print_overflow_msg(__func__, xdr);
5276 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005277}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005278
5279static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5280{
5281 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5282}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005283
5284static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5285{
5286 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5287}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005288#endif /* CONFIG_NFS_V4_1 */
5289
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005290static int decode_sequence(struct xdr_stream *xdr,
5291 struct nfs4_sequence_res *res,
5292 struct rpc_rqst *rqstp)
5293{
5294#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005295 struct nfs4_sessionid id;
5296 u32 dummy;
5297 int status;
5298 __be32 *p;
5299
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005300 if (!res->sr_session)
5301 return 0;
5302
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005303 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005304 if (!status)
5305 status = decode_sessionid(xdr, &id);
5306 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005307 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005308
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005309 /*
5310 * If the server returns different values for sessionID, slotID or
5311 * sequence number, the server is looney tunes.
5312 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005313 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005314
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005315 if (memcmp(id.data, res->sr_session->sess_id.data,
5316 NFS4_MAX_SESSIONID_LEN)) {
5317 dprintk("%s Invalid session id\n", __func__);
5318 goto out_err;
5319 }
Benny Halevye78291e2009-08-14 17:20:00 +03005320
Benny Halevyc0eae662009-08-14 17:20:14 +03005321 p = xdr_inline_decode(xdr, 20);
5322 if (unlikely(!p))
5323 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005324
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005325 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005326 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005327 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005328 dprintk("%s Invalid sequence number\n", __func__);
5329 goto out_err;
5330 }
5331 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005332 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005333 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005334 dprintk("%s Invalid slot id\n", __func__);
5335 goto out_err;
5336 }
5337 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005338 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005339 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005340 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005341 /* result flags */
5342 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005343 status = 0;
5344out_err:
5345 res->sr_status = status;
5346 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005347out_overflow:
5348 print_overflow_msg(__func__, xdr);
5349 status = -EIO;
5350 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005351#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005352 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005353#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005354}
5355
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005356#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005357/*
5358 * TODO: Need to handle case when EOF != true;
5359 */
5360static int decode_getdevicelist(struct xdr_stream *xdr,
5361 struct pnfs_devicelist *res)
5362{
5363 __be32 *p;
5364 int status, i;
5365 struct nfs_writeverf verftemp;
5366
5367 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5368 if (status)
5369 return status;
5370
5371 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5372 if (unlikely(!p))
5373 goto out_overflow;
5374
5375 /* TODO: Skip cookie for now */
5376 p += 2;
5377
5378 /* Read verifier */
Chuck Levercd937102012-03-02 17:14:31 -05005379 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005380
5381 res->num_devs = be32_to_cpup(p);
5382
5383 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5384
5385 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005386 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005387 __func__, res->num_devs);
5388 return -EIO;
5389 }
5390
5391 p = xdr_inline_decode(xdr,
5392 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5393 if (unlikely(!p))
5394 goto out_overflow;
5395 for (i = 0; i < res->num_devs; i++)
5396 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5397 NFS4_DEVICEID4_SIZE);
5398 res->eof = be32_to_cpup(p);
5399 return 0;
5400out_overflow:
5401 print_overflow_msg(__func__, xdr);
5402 return -EIO;
5403}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005404
5405static int decode_getdeviceinfo(struct xdr_stream *xdr,
5406 struct pnfs_device *pdev)
5407{
5408 __be32 *p;
5409 uint32_t len, type;
5410 int status;
5411
5412 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5413 if (status) {
5414 if (status == -ETOOSMALL) {
5415 p = xdr_inline_decode(xdr, 4);
5416 if (unlikely(!p))
5417 goto out_overflow;
5418 pdev->mincount = be32_to_cpup(p);
5419 dprintk("%s: Min count too small. mincnt = %u\n",
5420 __func__, pdev->mincount);
5421 }
5422 return status;
5423 }
5424
5425 p = xdr_inline_decode(xdr, 8);
5426 if (unlikely(!p))
5427 goto out_overflow;
5428 type = be32_to_cpup(p++);
5429 if (type != pdev->layout_type) {
5430 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5431 __func__, pdev->layout_type, type);
5432 return -EINVAL;
5433 }
5434 /*
5435 * Get the length of the opaque device_addr4. xdr_read_pages places
5436 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5437 * and places the remaining xdr data in xdr_buf->tail
5438 */
5439 pdev->mincount = be32_to_cpup(p);
5440 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5441
5442 /* Parse notification bitmap, verifying that it is zero. */
5443 p = xdr_inline_decode(xdr, 4);
5444 if (unlikely(!p))
5445 goto out_overflow;
5446 len = be32_to_cpup(p);
5447 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005448 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005449
5450 p = xdr_inline_decode(xdr, 4 * len);
5451 if (unlikely(!p))
5452 goto out_overflow;
5453 for (i = 0; i < len; i++, p++) {
5454 if (be32_to_cpup(p)) {
5455 dprintk("%s: notifications not supported\n",
5456 __func__);
5457 return -EIO;
5458 }
5459 }
5460 }
5461 return 0;
5462out_overflow:
5463 print_overflow_msg(__func__, xdr);
5464 return -EIO;
5465}
5466
5467static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5468 struct nfs4_layoutget_res *res)
5469{
5470 __be32 *p;
5471 int status;
5472 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005473 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5474 struct kvec *iov = rcvbuf->head;
5475 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005476
5477 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5478 if (status)
5479 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005480 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005481 if (unlikely(!p))
5482 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005483 res->return_on_close = be32_to_cpup(p);
5484 decode_stateid(xdr, &res->stateid);
5485 p = xdr_inline_decode(xdr, 4);
5486 if (unlikely(!p))
5487 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005488 layout_count = be32_to_cpup(p);
5489 if (!layout_count) {
5490 dprintk("%s: server responded with empty layout array\n",
5491 __func__);
5492 return -EINVAL;
5493 }
5494
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005495 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005496 if (unlikely(!p))
5497 goto out_overflow;
5498 p = xdr_decode_hyper(p, &res->range.offset);
5499 p = xdr_decode_hyper(p, &res->range.length);
5500 res->range.iomode = be32_to_cpup(p++);
5501 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005502 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005503
5504 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5505 __func__,
5506 (unsigned long)res->range.offset,
5507 (unsigned long)res->range.length,
5508 res->range.iomode,
5509 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005510 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005511
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005512 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5513 recvd = req->rq_rcv_buf.len - hdrlen;
5514 if (res->layoutp->len > recvd) {
5515 dprintk("NFS: server cheating in layoutget reply: "
5516 "layout len %u > recvd %u\n",
5517 res->layoutp->len, recvd);
5518 return -EINVAL;
5519 }
5520
5521 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005522
5523 if (layout_count > 1) {
5524 /* We only handle a length one array at the moment. Any
5525 * further entries are just ignored. Note that this means
5526 * the client may see a response that is less than the
5527 * minimum it requested.
5528 */
5529 dprintk("%s: server responded with %d layouts, dropping tail\n",
5530 __func__, layout_count);
5531 }
5532
5533 return 0;
5534out_overflow:
5535 print_overflow_msg(__func__, xdr);
5536 return -EIO;
5537}
Andy Adamson863a3c62011-03-23 13:27:54 +00005538
Benny Halevycbe82602011-05-22 19:52:37 +03005539static int decode_layoutreturn(struct xdr_stream *xdr,
5540 struct nfs4_layoutreturn_res *res)
5541{
5542 __be32 *p;
5543 int status;
5544
5545 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5546 if (status)
5547 return status;
5548 p = xdr_inline_decode(xdr, 4);
5549 if (unlikely(!p))
5550 goto out_overflow;
5551 res->lrs_present = be32_to_cpup(p);
5552 if (res->lrs_present)
5553 status = decode_stateid(xdr, &res->stateid);
5554 return status;
5555out_overflow:
5556 print_overflow_msg(__func__, xdr);
5557 return -EIO;
5558}
5559
Andy Adamson863a3c62011-03-23 13:27:54 +00005560static int decode_layoutcommit(struct xdr_stream *xdr,
5561 struct rpc_rqst *req,
5562 struct nfs4_layoutcommit_res *res)
5563{
5564 __be32 *p;
5565 __u32 sizechanged;
5566 int status;
5567
5568 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005569 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005570 if (status)
5571 return status;
5572
5573 p = xdr_inline_decode(xdr, 4);
5574 if (unlikely(!p))
5575 goto out_overflow;
5576 sizechanged = be32_to_cpup(p);
5577
5578 if (sizechanged) {
5579 /* throw away new size */
5580 p = xdr_inline_decode(xdr, 8);
5581 if (unlikely(!p))
5582 goto out_overflow;
5583 }
5584 return 0;
5585out_overflow:
5586 print_overflow_msg(__func__, xdr);
5587 return -EIO;
5588}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005589
5590static int decode_test_stateid(struct xdr_stream *xdr,
5591 struct nfs41_test_stateid_res *res)
5592{
5593 __be32 *p;
5594 int status;
5595 int num_res;
5596
5597 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5598 if (status)
5599 return status;
5600
5601 p = xdr_inline_decode(xdr, 4);
5602 if (unlikely(!p))
5603 goto out_overflow;
5604 num_res = be32_to_cpup(p++);
5605 if (num_res != 1)
5606 goto out;
5607
5608 p = xdr_inline_decode(xdr, 4);
5609 if (unlikely(!p))
5610 goto out_overflow;
5611 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05005612
5613 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04005614out_overflow:
5615 print_overflow_msg(__func__, xdr);
5616out:
5617 return -EIO;
5618}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005619
5620static int decode_free_stateid(struct xdr_stream *xdr,
5621 struct nfs41_free_stateid_res *res)
5622{
5623 __be32 *p;
5624 int status;
5625
5626 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5627 if (status)
5628 return status;
5629
5630 p = xdr_inline_decode(xdr, 4);
5631 if (unlikely(!p))
5632 goto out_overflow;
5633 res->status = be32_to_cpup(p++);
5634 return res->status;
5635out_overflow:
5636 print_overflow_msg(__func__, xdr);
5637 return -EIO;
5638}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005639#endif /* CONFIG_NFS_V4_1 */
5640
Linus Torvalds1da177e2005-04-16 15:20:36 -07005641/*
Benny Halevy49c25592008-12-23 16:06:16 -05005642 * END OF "GENERIC" DECODE ROUTINES.
5643 */
5644
5645/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005646 * Decode OPEN_DOWNGRADE response
5647 */
Chuck Leverbf269552010-12-14 14:59:29 +00005648static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5649 struct xdr_stream *xdr,
5650 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005651{
Andy Adamson05d564f2008-12-23 16:06:15 -05005652 struct compound_hdr hdr;
5653 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005654
Chuck Leverbf269552010-12-14 14:59:29 +00005655 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005656 if (status)
5657 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005658 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005659 if (status)
5660 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005661 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005662 if (status)
5663 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005664 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005665 if (status != 0)
5666 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005667 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005668out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005669 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005670}
5671
5672/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005673 * Decode ACCESS response
5674 */
Chuck Leverbf269552010-12-14 14:59:29 +00005675static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5676 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005677{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005678 struct compound_hdr hdr;
5679 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005680
Chuck Leverbf269552010-12-14 14:59:29 +00005681 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005682 if (status)
5683 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005684 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005685 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005687 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005688 if (status != 0)
5689 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005690 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005691 if (status != 0)
5692 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005693 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005694out:
5695 return status;
5696}
5697
5698/*
5699 * Decode LOOKUP response
5700 */
Chuck Leverbf269552010-12-14 14:59:29 +00005701static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5702 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005703{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005704 struct compound_hdr hdr;
5705 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005706
Chuck Leverbf269552010-12-14 14:59:29 +00005707 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005708 if (status)
5709 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005710 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005711 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005712 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005713 status = decode_putfh(xdr);
5714 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005715 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005716 status = decode_lookup(xdr);
5717 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005718 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005719 status = decode_getfh(xdr, res->fh);
5720 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005721 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005722 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005723out:
5724 return status;
5725}
5726
5727/*
5728 * Decode LOOKUP_ROOT response
5729 */
Chuck Leverbf269552010-12-14 14:59:29 +00005730static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5731 struct xdr_stream *xdr,
5732 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005733{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734 struct compound_hdr hdr;
5735 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005736
Chuck Leverbf269552010-12-14 14:59:29 +00005737 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005738 if (status)
5739 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005740 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005741 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005742 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005743 status = decode_putrootfh(xdr);
5744 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005746 status = decode_getfh(xdr, res->fh);
5747 if (status == 0)
Trond Myklebust6926afd2012-01-07 13:22:46 -05005748 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005749out:
5750 return status;
5751}
5752
5753/*
5754 * Decode REMOVE response
5755 */
Chuck Leverbf269552010-12-14 14:59:29 +00005756static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5757 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759 struct compound_hdr hdr;
5760 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005761
Chuck Leverbf269552010-12-14 14:59:29 +00005762 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005763 if (status)
5764 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005765 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005766 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005768 status = decode_putfh(xdr);
5769 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005770 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005771 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005772out:
5773 return status;
5774}
5775
5776/*
5777 * Decode RENAME response
5778 */
Chuck Leverbf269552010-12-14 14:59:29 +00005779static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5780 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005781{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005782 struct compound_hdr hdr;
5783 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005784
Chuck Leverbf269552010-12-14 14:59:29 +00005785 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005786 if (status)
5787 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005788 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005789 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005790 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005791 status = decode_putfh(xdr);
5792 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005794 status = decode_savefh(xdr);
5795 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005796 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005797 status = decode_putfh(xdr);
5798 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005800 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005801out:
5802 return status;
5803}
5804
5805/*
5806 * Decode LINK response
5807 */
Chuck Leverbf269552010-12-14 14:59:29 +00005808static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5809 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005810{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005811 struct compound_hdr hdr;
5812 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005813
Chuck Leverbf269552010-12-14 14:59:29 +00005814 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005815 if (status)
5816 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005817 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005818 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005819 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005820 status = decode_putfh(xdr);
5821 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005822 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005823 status = decode_savefh(xdr);
5824 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005825 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005826 status = decode_putfh(xdr);
5827 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005828 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005829 status = decode_link(xdr, &res->cinfo);
5830 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005831 goto out;
5832 /*
5833 * Note order: OP_LINK leaves the directory as the current
5834 * filehandle.
5835 */
Chuck Leverbf269552010-12-14 14:59:29 +00005836 status = decode_restorefh(xdr);
5837 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005838 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005839 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005840out:
5841 return status;
5842}
5843
5844/*
5845 * Decode CREATE response
5846 */
Chuck Leverbf269552010-12-14 14:59:29 +00005847static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5848 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005849{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 struct compound_hdr hdr;
5851 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005852
Chuck Leverbf269552010-12-14 14:59:29 +00005853 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005854 if (status)
5855 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005856 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005857 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005858 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005859 status = decode_putfh(xdr);
5860 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005861 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005862 status = decode_create(xdr, &res->dir_cinfo);
5863 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005864 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005865 status = decode_getfh(xdr, res->fh);
5866 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867 goto out;
Trond Myklebust7c317fc2012-04-27 13:48:18 -04005868 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005869out:
5870 return status;
5871}
5872
5873/*
5874 * Decode SYMLINK response
5875 */
Chuck Leverbf269552010-12-14 14:59:29 +00005876static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5877 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005878{
Chuck Leverbf269552010-12-14 14:59:29 +00005879 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005880}
5881
5882/*
5883 * Decode GETATTR response
5884 */
Chuck Leverbf269552010-12-14 14:59:29 +00005885static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5886 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005887{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888 struct compound_hdr hdr;
5889 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005890
Chuck Leverbf269552010-12-14 14:59:29 +00005891 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892 if (status)
5893 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005894 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005895 if (status)
5896 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005897 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005898 if (status)
5899 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05005900 status = decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005901out:
5902 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903}
5904
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005905/*
5906 * Encode an SETACL request
5907 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005908static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5909 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005910{
Andy Adamson05d564f2008-12-23 16:06:15 -05005911 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005912 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005913 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005914
Chuck Lever9f06c712010-12-14 14:59:18 +00005915 encode_compound_hdr(xdr, req, &hdr);
5916 encode_sequence(xdr, &args->seq_args, &hdr);
5917 encode_putfh(xdr, args->fh, &hdr);
5918 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005919 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005920}
Andy Adamson05d564f2008-12-23 16:06:15 -05005921
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005922/*
5923 * Decode SETACL response
5924 */
5925static int
Chuck Leverbf269552010-12-14 14:59:29 +00005926nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005927 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005928{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005929 struct compound_hdr hdr;
5930 int status;
5931
Chuck Leverbf269552010-12-14 14:59:29 +00005932 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005933 if (status)
5934 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005935 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005936 if (status)
5937 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005938 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005939 if (status)
5940 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005941 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005942out:
5943 return status;
5944}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945
5946/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005947 * Decode GETACL response
5948 */
5949static int
Chuck Leverbf269552010-12-14 14:59:29 +00005950nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005951 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005952{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005953 struct compound_hdr hdr;
5954 int status;
5955
Trond Myklebust331818f2012-02-03 18:30:53 -05005956 if (res->acl_scratch != NULL) {
5957 void *p = page_address(res->acl_scratch);
5958 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
5959 }
Chuck Leverbf269552010-12-14 14:59:29 +00005960 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005961 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);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005967 if (status)
5968 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05005969 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005970
5971out:
5972 return status;
5973}
5974
5975/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976 * Decode CLOSE response
5977 */
Chuck Leverbf269552010-12-14 14:59:29 +00005978static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5979 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005980{
Andy Adamson05d564f2008-12-23 16:06:15 -05005981 struct compound_hdr hdr;
5982 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005983
Chuck Leverbf269552010-12-14 14:59:29 +00005984 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005985 if (status)
5986 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005987 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005988 if (status)
5989 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005990 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005991 if (status)
5992 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005993 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005994 if (status != 0)
5995 goto out;
5996 /*
5997 * Note: Server may do delete on close for this file
5998 * in which case the getattr call will fail with
5999 * an ESTALE error. Shouldn't be a problem,
6000 * though, since fattr->valid will remain unset.
6001 */
Trond Myklebust6926afd2012-01-07 13:22:46 -05006002 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006004 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006005}
6006
6007/*
6008 * Decode OPEN response
6009 */
Chuck Leverbf269552010-12-14 14:59:29 +00006010static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6011 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012{
Andy Adamson05d564f2008-12-23 16:06:15 -05006013 struct compound_hdr hdr;
6014 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006015
Chuck Leverbf269552010-12-14 14:59:29 +00006016 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006017 if (status)
6018 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006019 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006020 if (status)
6021 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006022 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006023 if (status)
6024 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006025 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006026 if (status)
6027 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006028 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006029 goto out;
Trond Myklebust90ff0c52012-04-27 13:48:18 -04006030 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006031out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006032 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006033}
6034
6035/*
6036 * Decode OPEN_CONFIRM response
6037 */
Chuck Leverbf269552010-12-14 14:59:29 +00006038static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6039 struct xdr_stream *xdr,
6040 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006041{
Andy Adamson05d564f2008-12-23 16:06:15 -05006042 struct compound_hdr hdr;
6043 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044
Chuck Leverbf269552010-12-14 14:59:29 +00006045 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006046 if (status)
6047 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006048 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006049 if (status)
6050 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006051 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006052out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006053 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054}
6055
6056/*
6057 * Decode OPEN response
6058 */
Chuck Leverbf269552010-12-14 14:59:29 +00006059static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6060 struct xdr_stream *xdr,
6061 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006062{
Andy Adamson05d564f2008-12-23 16:06:15 -05006063 struct compound_hdr hdr;
6064 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065
Chuck Leverbf269552010-12-14 14:59:29 +00006066 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006067 if (status)
6068 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006069 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006070 if (status)
6071 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006072 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006073 if (status)
6074 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006075 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006076 if (status)
6077 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006078 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006079out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006080 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081}
6082
6083/*
6084 * Decode SETATTR response
6085 */
Chuck Leverbf269552010-12-14 14:59:29 +00006086static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6087 struct xdr_stream *xdr,
6088 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089{
Andy Adamson05d564f2008-12-23 16:06:15 -05006090 struct compound_hdr hdr;
6091 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092
Chuck Leverbf269552010-12-14 14:59:29 +00006093 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006094 if (status)
6095 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006096 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006097 if (status)
6098 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006099 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006100 if (status)
6101 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006102 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006103 if (status)
6104 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006105 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006107 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108}
6109
6110/*
6111 * Decode LOCK response
6112 */
Chuck Leverbf269552010-12-14 14:59:29 +00006113static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6114 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006115{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116 struct compound_hdr hdr;
6117 int status;
6118
Chuck Leverbf269552010-12-14 14:59:29 +00006119 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006120 if (status)
6121 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006122 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006123 if (status)
6124 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006125 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006126 if (status)
6127 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006128 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129out:
6130 return status;
6131}
6132
6133/*
6134 * Decode LOCKT response
6135 */
Chuck Leverbf269552010-12-14 14:59:29 +00006136static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6137 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006138{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139 struct compound_hdr hdr;
6140 int status;
6141
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143 if (status)
6144 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006145 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006146 if (status)
6147 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006148 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006149 if (status)
6150 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006151 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152out:
6153 return status;
6154}
6155
6156/*
6157 * Decode LOCKU response
6158 */
Chuck Leverbf269552010-12-14 14:59:29 +00006159static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6160 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162 struct compound_hdr hdr;
6163 int status;
6164
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006166 if (status)
6167 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006168 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006169 if (status)
6170 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006171 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172 if (status)
6173 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006174 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175out:
6176 return status;
6177}
6178
Chuck Leverbf269552010-12-14 14:59:29 +00006179static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6180 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006181{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006182 struct compound_hdr hdr;
6183 int status;
6184
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006186 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006187 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006188 return status;
6189}
6190
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191/*
6192 * Decode READLINK response
6193 */
Chuck Leverbf269552010-12-14 14:59:29 +00006194static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6195 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006196 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198 struct compound_hdr hdr;
6199 int status;
6200
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202 if (status)
6203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006205 if (status)
6206 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006207 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208 if (status)
6209 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006210 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211out:
6212 return status;
6213}
6214
6215/*
6216 * Decode READDIR response
6217 */
Chuck Leverbf269552010-12-14 14:59:29 +00006218static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6219 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006220{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221 struct compound_hdr hdr;
6222 int status;
6223
Chuck Leverbf269552010-12-14 14:59:29 +00006224 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225 if (status)
6226 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006227 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006228 if (status)
6229 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006230 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006231 if (status)
6232 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006233 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006234out:
6235 return status;
6236}
6237
6238/*
6239 * Decode Read response
6240 */
Chuck Leverbf269552010-12-14 14:59:29 +00006241static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6242 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006244 struct compound_hdr hdr;
6245 int status;
6246
Chuck Leverbf269552010-12-14 14:59:29 +00006247 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248 if (status)
6249 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006250 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006251 if (status)
6252 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006253 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006254 if (status)
6255 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006256 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257 if (!status)
6258 status = res->count;
6259out:
6260 return status;
6261}
6262
6263/*
6264 * Decode WRITE response
6265 */
Chuck Leverbf269552010-12-14 14:59:29 +00006266static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6267 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006268{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269 struct compound_hdr hdr;
6270 int status;
6271
Chuck Leverbf269552010-12-14 14:59:29 +00006272 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273 if (status)
6274 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006276 if (status)
6277 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006278 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006279 if (status)
6280 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006281 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006282 if (status)
6283 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006284 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006285 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006286 if (!status)
6287 status = res->count;
6288out:
6289 return status;
6290}
6291
6292/*
6293 * Decode COMMIT response
6294 */
Chuck Leverbf269552010-12-14 14:59:29 +00006295static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006296 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298 struct compound_hdr hdr;
6299 int status;
6300
Chuck Leverbf269552010-12-14 14:59:29 +00006301 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302 if (status)
6303 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006304 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006305 if (status)
6306 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006308 if (status)
6309 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311out:
6312 return status;
6313}
6314
6315/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006316 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317 */
Chuck Leverbf269552010-12-14 14:59:29 +00006318static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006319 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006320{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321 struct compound_hdr hdr;
6322 int status;
6323
Chuck Leverbf269552010-12-14 14:59:29 +00006324 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006326 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006327 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006328 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006329 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006330 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331 return status;
6332}
6333
6334/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006335 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006336 */
Chuck Leverbf269552010-12-14 14:59:29 +00006337static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006338 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340 struct compound_hdr hdr;
6341 int status;
6342
Chuck Leverbf269552010-12-14 14:59:29 +00006343 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006344 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006345 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006346 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006347 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006349 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350 return status;
6351}
6352
6353/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006354 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355 */
Chuck Leverbf269552010-12-14 14:59:29 +00006356static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006357 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359 struct compound_hdr hdr;
6360 int status;
6361
Chuck Leverbf269552010-12-14 14:59:29 +00006362 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006363 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006365 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006366 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369 return status;
6370}
6371
6372/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006373 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374 */
Chuck Leverbf269552010-12-14 14:59:29 +00006375static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6376 struct xdr_stream *xdr,
6377 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006379 struct compound_hdr hdr;
6380 int status;
6381
Chuck Leverbf269552010-12-14 14:59:29 +00006382 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006383 if (status)
6384 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006386 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006388 status = decode_putfh(xdr);
6389 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006390 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006391 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392out:
6393 return status;
6394}
6395
6396/*
6397 * Decode RENEW response
6398 */
Chuck Leverbf269552010-12-14 14:59:29 +00006399static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6400 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006401{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402 struct compound_hdr hdr;
6403 int status;
6404
Chuck Leverbf269552010-12-14 14:59:29 +00006405 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006407 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408 return status;
6409}
6410
6411/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006412 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006413 */
Chuck Leverbf269552010-12-14 14:59:29 +00006414static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6415 struct xdr_stream *xdr,
6416 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006417{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006418 struct compound_hdr hdr;
6419 int status;
6420
Chuck Leverbf269552010-12-14 14:59:29 +00006421 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006422 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006423 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006424 return status;
6425}
6426
6427/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006428 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429 */
Chuck Leverbf269552010-12-14 14:59:29 +00006430static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6431 struct xdr_stream *xdr,
6432 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006433{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006434 struct compound_hdr hdr;
6435 int status;
6436
Chuck Leverbf269552010-12-14 14:59:29 +00006437 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006439 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006441 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 return status;
6445}
6446
6447/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006448 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006449 */
Chuck Leverbf269552010-12-14 14:59:29 +00006450static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6451 struct xdr_stream *xdr,
6452 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 struct compound_hdr hdr;
6455 int status;
6456
Chuck Leverbf269552010-12-14 14:59:29 +00006457 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006458 if (status)
6459 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006460 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006461 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006462 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006463 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006464 if (status != 0)
6465 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006466 status = decode_getfattr(xdr, res->fattr, res->server);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006467 if (status != 0)
6468 goto out;
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006469 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006470out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006471 return status;
6472}
6473
Trond Myklebust683b57b2006-06-09 09:34:22 -04006474/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006475 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006476 */
Chuck Leverbf269552010-12-14 14:59:29 +00006477static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6478 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006479 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006480{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006481 struct compound_hdr hdr;
6482 int status;
6483
Chuck Leverbf269552010-12-14 14:59:29 +00006484 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006485 if (status)
6486 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006487 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006488 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006489 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006490 status = decode_putfh(xdr);
6491 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006492 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006493 status = decode_lookup(xdr);
6494 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006495 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006496 xdr_enter_page(xdr, PAGE_SIZE);
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006497 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6498 NULL, res->fs_locations,
6499 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04006500out:
6501 return status;
6502}
6503
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006504/*
6505 * Decode SECINFO response
6506 */
6507static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6508 struct xdr_stream *xdr,
6509 struct nfs4_secinfo_res *res)
6510{
6511 struct compound_hdr hdr;
6512 int status;
6513
6514 status = decode_compound_hdr(xdr, &hdr);
6515 if (status)
6516 goto out;
6517 status = decode_sequence(xdr, &res->seq_res, rqstp);
6518 if (status)
6519 goto out;
6520 status = decode_putfh(xdr);
6521 if (status)
6522 goto out;
6523 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006524out:
6525 return status;
6526}
6527
Benny Halevy99fe60d2009-04-01 09:22:29 -04006528#if defined(CONFIG_NFS_V4_1)
6529/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006530 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006531 */
Chuck Leverbf269552010-12-14 14:59:29 +00006532static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6533 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006534 void *res)
6535{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006536 struct compound_hdr hdr;
6537 int status;
6538
Chuck Leverbf269552010-12-14 14:59:29 +00006539 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006540 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006541 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006542 return status;
6543}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006544
6545/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006546 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006547 */
Chuck Leverbf269552010-12-14 14:59:29 +00006548static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6549 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006550 struct nfs41_create_session_res *res)
6551{
Andy Adamsonfc931582009-04-01 09:22:31 -04006552 struct compound_hdr hdr;
6553 int status;
6554
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006556 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006557 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006558 return status;
6559}
6560
6561/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006562 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006563 */
Chuck Leverbf269552010-12-14 14:59:29 +00006564static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6565 struct xdr_stream *xdr,
6566 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006567{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006568 struct compound_hdr hdr;
6569 int status;
6570
Chuck Leverbf269552010-12-14 14:59:29 +00006571 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006572 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006573 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006574 return status;
6575}
6576
6577/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006578 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006579 */
Chuck Leverbf269552010-12-14 14:59:29 +00006580static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6581 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006582 struct nfs4_sequence_res *res)
6583{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006584 struct compound_hdr hdr;
6585 int status;
6586
Chuck Leverbf269552010-12-14 14:59:29 +00006587 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006588 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006589 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006590 return status;
6591}
6592
6593/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006594 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006595 */
Chuck Leverbf269552010-12-14 14:59:29 +00006596static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6597 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006598 struct nfs4_get_lease_time_res *res)
6599{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006600 struct compound_hdr hdr;
6601 int status;
6602
Chuck Leverbf269552010-12-14 14:59:29 +00006603 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006604 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006605 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006606 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006607 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006608 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006609 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006610 return status;
6611}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006612
6613/*
6614 * Decode RECLAIM_COMPLETE response
6615 */
Chuck Leverbf269552010-12-14 14:59:29 +00006616static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6617 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006618 struct nfs41_reclaim_complete_res *res)
6619{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006620 struct compound_hdr hdr;
6621 int status;
6622
Chuck Leverbf269552010-12-14 14:59:29 +00006623 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006624 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006625 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006626 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006627 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006628 return status;
6629}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006630
6631/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006632 * Decode GETDEVICELIST response
6633 */
6634static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6635 struct xdr_stream *xdr,
6636 struct nfs4_getdevicelist_res *res)
6637{
6638 struct compound_hdr hdr;
6639 int status;
6640
6641 dprintk("encoding getdevicelist!\n");
6642
6643 status = decode_compound_hdr(xdr, &hdr);
6644 if (status != 0)
6645 goto out;
6646 status = decode_sequence(xdr, &res->seq_res, rqstp);
6647 if (status != 0)
6648 goto out;
6649 status = decode_putfh(xdr);
6650 if (status != 0)
6651 goto out;
6652 status = decode_getdevicelist(xdr, res->devlist);
6653out:
6654 return status;
6655}
6656
6657/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006658 * Decode GETDEVINFO response
6659 */
Chuck Leverbf269552010-12-14 14:59:29 +00006660static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6661 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006662 struct nfs4_getdeviceinfo_res *res)
6663{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006664 struct compound_hdr hdr;
6665 int status;
6666
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006668 if (status != 0)
6669 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006670 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006671 if (status != 0)
6672 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006673 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006674out:
6675 return status;
6676}
6677
6678/*
6679 * Decode LAYOUTGET response
6680 */
Chuck Leverbf269552010-12-14 14:59:29 +00006681static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6682 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006683 struct nfs4_layoutget_res *res)
6684{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006685 struct compound_hdr hdr;
6686 int status;
6687
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006689 if (status)
6690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006691 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006692 if (status)
6693 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006694 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006695 if (status)
6696 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006697 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006698out:
6699 return status;
6700}
Andy Adamson863a3c62011-03-23 13:27:54 +00006701
6702/*
Benny Halevycbe82602011-05-22 19:52:37 +03006703 * Decode LAYOUTRETURN response
6704 */
6705static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6706 struct xdr_stream *xdr,
6707 struct nfs4_layoutreturn_res *res)
6708{
6709 struct compound_hdr hdr;
6710 int status;
6711
6712 status = decode_compound_hdr(xdr, &hdr);
6713 if (status)
6714 goto out;
6715 status = decode_sequence(xdr, &res->seq_res, rqstp);
6716 if (status)
6717 goto out;
6718 status = decode_putfh(xdr);
6719 if (status)
6720 goto out;
6721 status = decode_layoutreturn(xdr, res);
6722out:
6723 return status;
6724}
6725
6726/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006727 * Decode LAYOUTCOMMIT response
6728 */
6729static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6730 struct xdr_stream *xdr,
6731 struct nfs4_layoutcommit_res *res)
6732{
6733 struct compound_hdr hdr;
6734 int status;
6735
6736 status = decode_compound_hdr(xdr, &hdr);
6737 if (status)
6738 goto out;
6739 status = decode_sequence(xdr, &res->seq_res, rqstp);
6740 if (status)
6741 goto out;
6742 status = decode_putfh(xdr);
6743 if (status)
6744 goto out;
6745 status = decode_layoutcommit(xdr, rqstp, res);
6746 if (status)
6747 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006748 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00006749out:
6750 return status;
6751}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006752
6753/*
6754 * Decode SECINFO_NO_NAME response
6755 */
6756static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6757 struct xdr_stream *xdr,
6758 struct nfs4_secinfo_res *res)
6759{
6760 struct compound_hdr hdr;
6761 int status;
6762
6763 status = decode_compound_hdr(xdr, &hdr);
6764 if (status)
6765 goto out;
6766 status = decode_sequence(xdr, &res->seq_res, rqstp);
6767 if (status)
6768 goto out;
6769 status = decode_putrootfh(xdr);
6770 if (status)
6771 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04006772 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006773out:
6774 return status;
6775}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006776
6777/*
6778 * Decode TEST_STATEID response
6779 */
6780static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6781 struct xdr_stream *xdr,
6782 struct nfs41_test_stateid_res *res)
6783{
6784 struct compound_hdr hdr;
6785 int status;
6786
6787 status = decode_compound_hdr(xdr, &hdr);
6788 if (status)
6789 goto out;
6790 status = decode_sequence(xdr, &res->seq_res, rqstp);
6791 if (status)
6792 goto out;
6793 status = decode_test_stateid(xdr, res);
6794out:
6795 return status;
6796}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006797
6798/*
6799 * Decode FREE_STATEID response
6800 */
6801static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6802 struct xdr_stream *xdr,
6803 struct nfs41_free_stateid_res *res)
6804{
6805 struct compound_hdr hdr;
6806 int status;
6807
6808 status = decode_compound_hdr(xdr, &hdr);
6809 if (status)
6810 goto out;
6811 status = decode_sequence(xdr, &res->seq_res, rqstp);
6812 if (status)
6813 goto out;
6814 status = decode_free_stateid(xdr, res);
6815out:
6816 return status;
6817}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006818#endif /* CONFIG_NFS_V4_1 */
6819
Chuck Lever573c4e12010-12-14 14:58:11 +00006820/**
6821 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6822 * the local page cache.
6823 * @xdr: XDR stream where entry resides
6824 * @entry: buffer to fill in with entry data
6825 * @plus: boolean indicating whether this should be a readdirplus entry
6826 *
6827 * Returns zero if successful, otherwise a negative errno value is
6828 * returned.
6829 *
6830 * This function is not invoked during READDIR reply decoding, but
6831 * rather whenever an application invokes the getdents(2) system call
6832 * on a directory already in our cache.
6833 */
6834int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6835 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006836{
Fred Isamandae100c2011-07-30 20:52:37 -04006837 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006838 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006839 __be32 *p = xdr_inline_decode(xdr, 4);
6840 if (unlikely(!p))
6841 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006842 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006843 p = xdr_inline_decode(xdr, 4);
6844 if (unlikely(!p))
6845 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006846 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006847 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006848 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006849 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006850 }
6851
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006852 p = xdr_inline_decode(xdr, 12);
6853 if (unlikely(!p))
6854 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006855 entry->prev_cookie = entry->cookie;
6856 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006857 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006858
Trond Myklebust9af8c222010-10-24 11:52:55 -04006859 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006860 if (unlikely(!p))
6861 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006862 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006863
6864 /*
6865 * In case the server doesn't return an inode number,
6866 * we fake one here. (We don't use inode number 0,
6867 * since glibc seems to choke on it...)
6868 */
6869 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006870 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006871
Trond Myklebust9af8c222010-10-24 11:52:55 -04006872 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006873 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006874
6875 if (decode_attr_length(xdr, &len, &p) < 0)
6876 goto out_overflow;
6877
Chuck Lever573c4e12010-12-14 14:58:11 +00006878 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006879 NULL, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006880 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006881 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6882 entry->ino = entry->fattr->mounted_on_fileid;
6883 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006884 entry->ino = entry->fattr->fileid;
6885
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006886 entry->d_type = DT_UNKNOWN;
6887 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6888 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6889
Chuck Lever573c4e12010-12-14 14:58:11 +00006890 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006891
6892out_overflow:
6893 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006894 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006895}
6896
6897/*
6898 * We need to translate between nfs status return values and
6899 * the local errno values which may not be the same.
6900 */
6901static struct {
6902 int stat;
6903 int errno;
6904} nfs_errtbl[] = {
6905 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006906 { NFS4ERR_PERM, -EPERM },
6907 { NFS4ERR_NOENT, -ENOENT },
6908 { NFS4ERR_IO, -errno_NFSERR_IO},
6909 { NFS4ERR_NXIO, -ENXIO },
6910 { NFS4ERR_ACCESS, -EACCES },
6911 { NFS4ERR_EXIST, -EEXIST },
6912 { NFS4ERR_XDEV, -EXDEV },
6913 { NFS4ERR_NOTDIR, -ENOTDIR },
6914 { NFS4ERR_ISDIR, -EISDIR },
6915 { NFS4ERR_INVAL, -EINVAL },
6916 { NFS4ERR_FBIG, -EFBIG },
6917 { NFS4ERR_NOSPC, -ENOSPC },
6918 { NFS4ERR_ROFS, -EROFS },
6919 { NFS4ERR_MLINK, -EMLINK },
6920 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6921 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6922 { NFS4ERR_DQUOT, -EDQUOT },
6923 { NFS4ERR_STALE, -ESTALE },
6924 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006925 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6926 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6927 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006928 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006929 { NFS4ERR_BADTYPE, -EBADTYPE },
6930 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006931 { NFS4ERR_SYMLINK, -ELOOP },
6932 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6933 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006934 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006935};
6936
6937/*
6938 * Convert an NFS error code to a local one.
6939 * This one is used jointly by NFSv2 and NFSv3.
6940 */
6941static int
David Howells0a8ea432006-08-22 20:06:08 -04006942nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006943{
6944 int i;
6945 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6946 if (nfs_errtbl[i].stat == stat)
6947 return nfs_errtbl[i].errno;
6948 }
6949 if (stat <= 10000 || stat > 10100) {
6950 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006951 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006952 }
6953 /* If we cannot translate the error, the recovery routines should
6954 * handle it.
6955 * Note: remaining NFSv4 error codes have values > 10000, so should
6956 * not conflict with native Linux error codes.
6957 */
Benny Halevy856dff32008-03-31 17:39:06 +03006958 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006959}
6960
Linus Torvalds1da177e2005-04-16 15:20:36 -07006961#define PROC(proc, argtype, restype) \
6962[NFSPROC4_CLNT_##proc] = { \
6963 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006964 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006965 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006966 .p_arglen = NFS4_##argtype##_sz, \
6967 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006968 .p_statidx = NFSPROC4_CLNT_##proc, \
6969 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006970}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006971
6972struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006973 PROC(READ, enc_read, dec_read),
6974 PROC(WRITE, enc_write, dec_write),
6975 PROC(COMMIT, enc_commit, dec_commit),
6976 PROC(OPEN, enc_open, dec_open),
6977 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6978 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6979 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6980 PROC(CLOSE, enc_close, dec_close),
6981 PROC(SETATTR, enc_setattr, dec_setattr),
6982 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6983 PROC(RENEW, enc_renew, dec_renew),
6984 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6985 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6986 PROC(LOCK, enc_lock, dec_lock),
6987 PROC(LOCKT, enc_lockt, dec_lockt),
6988 PROC(LOCKU, enc_locku, dec_locku),
6989 PROC(ACCESS, enc_access, dec_access),
6990 PROC(GETATTR, enc_getattr, dec_getattr),
6991 PROC(LOOKUP, enc_lookup, dec_lookup),
6992 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6993 PROC(REMOVE, enc_remove, dec_remove),
6994 PROC(RENAME, enc_rename, dec_rename),
6995 PROC(LINK, enc_link, dec_link),
6996 PROC(SYMLINK, enc_symlink, dec_symlink),
6997 PROC(CREATE, enc_create, dec_create),
6998 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6999 PROC(STATFS, enc_statfs, dec_statfs),
7000 PROC(READLINK, enc_readlink, dec_readlink),
7001 PROC(READDIR, enc_readdir, dec_readdir),
7002 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7003 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7004 PROC(GETACL, enc_getacl, dec_getacl),
7005 PROC(SETACL, enc_setacl, dec_setacl),
7006 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7007 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007008 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007009#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007010 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7011 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7012 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7013 PROC(SEQUENCE, enc_sequence, dec_sequence),
7014 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7015 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7016 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7017 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007018 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007019 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007020 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007021 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007022 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007023 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007024#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007025};
7026
Trond Myklebusta613fa12012-01-20 13:53:56 -05007027const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007028 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007029 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007030 .procs = nfs4_procedures
7031};
7032
7033/*
7034 * Local variables:
7035 * c-basic-offset: 8
7036 * End:
7037 */