blob: 5f769f8d05b0ae1bc16e60f3c1b227e4675b8e84 [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>
47#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050048#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000049#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/nfs.h>
51#include <linux/nfs4.h>
52#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000054#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050055#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040056#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#define NFSDBG_FACILITY NFSDBG_XDR
59
60/* Mapping from NFS error code to "errno" error code. */
61#define errno_NFSERR_IO EIO
62
David Howells0a8ea432006-08-22 20:06:08 -040063static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
66#ifdef DEBUG
67#define NFS4_MAXTAGLEN 20
68#else
69#define NFS4_MAXTAGLEN 0
70#endif
71
Andy Adamson6c0195a2008-12-23 16:06:15 -050072/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 */
Trond Myklebustd035c362010-12-21 10:45:27 -050075#define open_owner_id_maxsz (1 + 1 + 4)
76#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040077#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
80#define op_encode_hdr_maxsz (1)
81#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
84#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
85#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
87 (NFS4_FHSIZE >> 2))
88#define decode_putfh_maxsz (op_decode_hdr_maxsz)
89#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
90#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
91#define encode_getfh_maxsz (op_encode_hdr_maxsz)
92#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
93 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040094#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000095#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
97#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040098#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
99#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000100/* This is based on getfattr, which uses the most attributes: */
101#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400102 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000103#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
104 nfs4_fattr_value_maxsz)
105#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400106#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
107 1 + 2 + 1 + \
108 nfs4_owner_maxsz + \
109 nfs4_group_maxsz + \
110 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define encode_savefh_maxsz (op_encode_hdr_maxsz)
112#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400113#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
114#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200115#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Bryan Schumaker7ebb9312011-03-24 17:12:30 +0000116#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
118#define decode_renew_maxsz (op_decode_hdr_maxsz)
119#define encode_setclientid_maxsz \
120 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500121 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
122 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
123 1 /* sc_prog */ + \
124 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
125 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
126 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define decode_setclientid_maxsz \
128 (op_decode_hdr_maxsz + \
129 2 + \
130 1024) /* large value for CLID_INUSE */
131#define encode_setclientid_confirm_maxsz \
132 (op_encode_hdr_maxsz + \
133 3 + (NFS4_VERIFIER_SIZE >> 2))
134#define decode_setclientid_confirm_maxsz \
135 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400136#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
137#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400138#define encode_share_access_maxsz \
139 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500140#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400141#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
142#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
143#define encode_open_maxsz (op_encode_hdr_maxsz + \
144 2 + encode_share_access_maxsz + 2 + \
145 open_owner_id_maxsz + \
146 encode_opentype_maxsz + \
147 encode_claim_null_maxsz)
148#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400149#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400150 decode_ace_maxsz)
151#define decode_change_info_maxsz (5)
152#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400153 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400154 decode_change_info_maxsz + 1 + \
155 nfs4_fattr_bitmap_maxsz + \
156 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400157#define encode_open_confirm_maxsz \
158 (op_encode_hdr_maxsz + \
159 encode_stateid_maxsz + 1)
160#define decode_open_confirm_maxsz \
161 (op_decode_hdr_maxsz + \
162 decode_stateid_maxsz)
163#define encode_open_downgrade_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1 + \
166 encode_share_access_maxsz)
167#define decode_open_downgrade_maxsz \
168 (op_decode_hdr_maxsz + \
169 decode_stateid_maxsz)
170#define encode_close_maxsz (op_encode_hdr_maxsz + \
171 1 + encode_stateid_maxsz)
172#define decode_close_maxsz (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
175 encode_stateid_maxsz + \
176 encode_attrs_maxsz)
177#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
178 nfs4_fattr_bitmap_maxsz)
179#define encode_read_maxsz (op_encode_hdr_maxsz + \
180 encode_stateid_maxsz + 3)
181#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
182#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
183 2 + encode_verifier_maxsz + 5)
184#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
185 decode_verifier_maxsz)
186#define encode_readlink_maxsz (op_encode_hdr_maxsz)
187#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
188#define encode_write_maxsz (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 4)
190#define decode_write_maxsz (op_decode_hdr_maxsz + \
191 2 + decode_verifier_maxsz)
192#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
193#define decode_commit_maxsz (op_decode_hdr_maxsz + \
194 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#define encode_remove_maxsz (op_encode_hdr_maxsz + \
196 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400197#define decode_remove_maxsz (op_decode_hdr_maxsz + \
198 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199#define encode_rename_maxsz (op_encode_hdr_maxsz + \
200 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400201#define decode_rename_maxsz (op_decode_hdr_maxsz + \
202 decode_change_info_maxsz + \
203 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#define encode_link_maxsz (op_encode_hdr_maxsz + \
205 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400206#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400207#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400208#define encode_lock_maxsz (op_encode_hdr_maxsz + \
209 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400210 1 + encode_stateid_maxsz + 1 + \
211 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400212#define decode_lock_denied_maxsz \
213 (8 + decode_lockowner_maxsz)
214#define decode_lock_maxsz (op_decode_hdr_maxsz + \
215 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
219 decode_lock_denied_maxsz)
220#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
221 encode_stateid_maxsz + \
222 4)
223#define decode_locku_maxsz (op_decode_hdr_maxsz + \
224 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400225#define encode_release_lockowner_maxsz \
226 (op_encode_hdr_maxsz + \
227 encode_lockowner_maxsz)
228#define decode_release_lockowner_maxsz \
229 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400230#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
231#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
233 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400234 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000235 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
237#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400238 1 + 2 + nfs4_name_maxsz + \
239 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400240#define decode_create_maxsz (op_decode_hdr_maxsz + \
241 decode_change_info_maxsz + \
242 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400243#define encode_statfs_maxsz (encode_getattr_maxsz)
244#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
246#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400247#define encode_getacl_maxsz (encode_getattr_maxsz)
248#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
249 nfs4_fattr_bitmap_maxsz + 1)
250#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
251 encode_stateid_maxsz + 3)
252#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400253#define encode_fs_locations_maxsz \
254 (encode_getattr_maxsz)
255#define decode_fs_locations_maxsz \
256 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000257#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400258#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 -0400259
260#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400261#define NFS4_MAX_MACHINE_NAME_LEN (64)
262
Benny Halevy99fe60d2009-04-01 09:22:29 -0400263#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
264 encode_verifier_maxsz + \
265 1 /* co_ownerid.len */ + \
266 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
267 1 /* flags */ + \
268 1 /* spa_how */ + \
269 0 /* SP4_NONE (for now) */ + \
270 1 /* zero implemetation id array */)
271#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
272 2 /* eir_clientid */ + \
273 1 /* eir_sequenceid */ + \
274 1 /* eir_flags */ + \
275 1 /* spr_how */ + \
276 0 /* SP4_NONE (for now) */ + \
277 2 /* eir_server_owner.so_minor_id */ + \
278 /* eir_server_owner.so_major_id<> */ \
279 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
280 /* eir_server_scope<> */ \
281 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
282 1 /* eir_server_impl_id array length */ + \
283 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400284#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
285#define decode_channel_attrs_maxsz (6 + \
286 1 /* ca_rdma_ird.len */ + \
287 1 /* ca_rdma_ird */)
288#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
289 2 /* csa_clientid */ + \
290 1 /* csa_sequence */ + \
291 1 /* csa_flags */ + \
292 encode_channel_attrs_maxsz + \
293 encode_channel_attrs_maxsz + \
294 1 /* csa_cb_program */ + \
295 1 /* csa_sec_parms.len (1) */ + \
296 1 /* cb_secflavor (AUTH_SYS) */ + \
297 1 /* stamp */ + \
298 1 /* machinename.len */ + \
299 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
300 1 /* uid */ + \
301 1 /* gid */ + \
302 1 /* gids.len (0) */)
303#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
304 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
305 1 /* csr_sequence */ + \
306 1 /* csr_flags */ + \
307 decode_channel_attrs_maxsz + \
308 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400309#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
310#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400311#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
312 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
313#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
314 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500315#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
316#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400317#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
318 encode_verifier_maxsz)
319#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
320 2 /* nfs_cookie4 gdlr_cookie */ + \
321 decode_verifier_maxsz \
322 /* verifier4 gdlr_verifier */ + \
323 1 /* gdlr_deviceid_list count */ + \
324 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
325 NFS4_DEVICEID4_SIZE) \
326 /* gdlr_deviceid_list */ + \
327 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400328#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
329 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
330#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
331 1 /* layout type */ + \
332 1 /* opaque devaddr4 length */ + \
333 /* devaddr4 payload is read into page */ \
334 1 /* notification bitmap length */ + \
335 1 /* notification bitmap */)
336#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
337 encode_stateid_maxsz)
338#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
339 decode_stateid_maxsz + \
340 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000341#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
342 2 /* offset */ + \
343 2 /* length */ + \
344 1 /* reclaim */ + \
345 encode_stateid_maxsz + \
346 1 /* new offset (true) */ + \
347 2 /* last byte written */ + \
348 1 /* nt_timechanged (false) */ + \
349 1 /* layoutupdate4 layout type */ + \
350 1 /* NULL filelayout layoutupdate4 payload */)
351#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300352#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
353 encode_stateid_maxsz + \
354 1 /* FIXME: opaque lrf_body always empty at the moment */)
355#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
356 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400357#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
358#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400359#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
360 XDR_QUADLEN(NFS4_STATEID_SIZE))
361#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400362#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
363 XDR_QUADLEN(NFS4_STATEID_SIZE))
364#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400365#else /* CONFIG_NFS_V4_1 */
366#define encode_sequence_maxsz 0
367#define decode_sequence_maxsz 0
368#endif /* CONFIG_NFS_V4_1 */
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
371#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
372#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400373 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400375 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400377 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400379 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400381 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400383 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400385 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400387 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400389 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400391 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400393 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400395 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400397 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400399 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400400 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401#define NFS4_dec_write_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_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400405 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400407 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400409 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400410 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400414 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400415 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400417 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400418 encode_putfh_maxsz + \
419 encode_savefh_maxsz + \
420 encode_open_maxsz + \
421 encode_getfh_maxsz + \
422 encode_getattr_maxsz + \
423 encode_restorefh_maxsz + \
424 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400427 decode_putfh_maxsz + \
428 decode_savefh_maxsz + \
429 decode_open_maxsz + \
430 decode_getfh_maxsz + \
431 decode_getattr_maxsz + \
432 decode_restorefh_maxsz + \
433 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400434#define NFS4_enc_open_confirm_sz \
435 (compound_encode_hdr_maxsz + \
436 encode_putfh_maxsz + \
437 encode_open_confirm_maxsz)
438#define NFS4_dec_open_confirm_sz \
439 (compound_decode_hdr_maxsz + \
440 decode_putfh_maxsz + \
441 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400443 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400445 encode_open_maxsz + \
446 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400448 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400450 decode_open_maxsz + \
451 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452#define NFS4_enc_open_downgrade_sz \
453 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400455 encode_putfh_maxsz + \
456 encode_open_downgrade_maxsz + \
457 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#define NFS4_dec_open_downgrade_sz \
459 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400461 decode_putfh_maxsz + \
462 decode_open_downgrade_maxsz + \
463 decode_getattr_maxsz)
464#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400465 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400466 encode_putfh_maxsz + \
467 encode_close_maxsz + \
468 encode_getattr_maxsz)
469#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400470 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400471 decode_putfh_maxsz + \
472 decode_close_maxsz + \
473 decode_getattr_maxsz)
474#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400476 encode_putfh_maxsz + \
477 encode_setattr_maxsz + \
478 encode_getattr_maxsz)
479#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400480 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400481 decode_putfh_maxsz + \
482 decode_setattr_maxsz + \
483 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 encode_putfh_maxsz + \
487 encode_fsinfo_maxsz)
488#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 decode_putfh_maxsz + \
491 decode_fsinfo_maxsz)
492#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
493 encode_renew_maxsz)
494#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
495 decode_renew_maxsz)
496#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
497 encode_setclientid_maxsz)
498#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
499 decode_setclientid_maxsz)
500#define NFS4_enc_setclientid_confirm_sz \
501 (compound_encode_hdr_maxsz + \
502 encode_setclientid_confirm_maxsz + \
503 encode_putrootfh_maxsz + \
504 encode_fsinfo_maxsz)
505#define NFS4_dec_setclientid_confirm_sz \
506 (compound_decode_hdr_maxsz + \
507 decode_setclientid_confirm_maxsz + \
508 decode_putrootfh_maxsz + \
509 decode_fsinfo_maxsz)
510#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400511 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400513 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400515 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400517 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400519 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400521 encode_lockt_maxsz)
522#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400524 decode_putfh_maxsz + \
525 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400527 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400529 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400531 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400533 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400534#define NFS4_enc_release_lockowner_sz \
535 (compound_encode_hdr_maxsz + \
536 encode_lockowner_maxsz)
537#define NFS4_dec_release_lockowner_sz \
538 (compound_decode_hdr_maxsz + \
539 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400541 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400543 encode_access_maxsz + \
544 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400548 decode_access_maxsz + \
549 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400551 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 encode_putfh_maxsz + \
553 encode_getattr_maxsz)
554#define NFS4_dec_getattr_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 + \
557 decode_getattr_maxsz)
558#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400559 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 encode_putfh_maxsz + \
561 encode_lookup_maxsz + \
562 encode_getattr_maxsz + \
563 encode_getfh_maxsz)
564#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400565 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400567 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 decode_getattr_maxsz + \
569 decode_getfh_maxsz)
570#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400571 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 encode_putrootfh_maxsz + \
573 encode_getattr_maxsz + \
574 encode_getfh_maxsz)
575#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400576 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 decode_putrootfh_maxsz + \
578 decode_getattr_maxsz + \
579 decode_getfh_maxsz)
580#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400581 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400583 encode_remove_maxsz + \
584 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400588 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400589 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400591 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 encode_putfh_maxsz + \
593 encode_savefh_maxsz + \
594 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400595 encode_rename_maxsz + \
596 encode_getattr_maxsz + \
597 encode_restorefh_maxsz + \
598 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 decode_putfh_maxsz + \
602 decode_savefh_maxsz + \
603 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400604 decode_rename_maxsz + \
605 decode_getattr_maxsz + \
606 decode_restorefh_maxsz + \
607 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400609 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 encode_putfh_maxsz + \
611 encode_savefh_maxsz + \
612 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400613 encode_link_maxsz + \
614 decode_getattr_maxsz + \
615 encode_restorefh_maxsz + \
616 decode_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 + \
623 decode_getattr_maxsz + \
624 decode_restorefh_maxsz + \
625 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400627 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 encode_putfh_maxsz + \
629 encode_symlink_maxsz + \
630 encode_getattr_maxsz + \
631 encode_getfh_maxsz)
632#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400633 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 decode_putfh_maxsz + \
635 decode_symlink_maxsz + \
636 decode_getattr_maxsz + \
637 decode_getfh_maxsz)
638#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400639 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400641 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400643 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400645 encode_restorefh_maxsz + \
646 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400650 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400652 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400654 decode_restorefh_maxsz + \
655 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400657 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 encode_putfh_maxsz + \
659 encode_getattr_maxsz)
660#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400661 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 decode_putfh_maxsz + \
663 decode_getattr_maxsz)
664#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400665 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400667 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400669 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400671 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400673 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800674 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 encode_getattr_maxsz)
676#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400677 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800678 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 decode_getattr_maxsz)
680#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400681 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100683 encode_delegreturn_maxsz + \
684 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400686 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100687 decode_delegreturn_maxsz + \
688 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000689#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000691 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400692 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000693#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000695 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400696 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000697#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000699 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400700 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000701#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000703 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400704 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400705#define NFS4_enc_fs_locations_sz \
706 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400707 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400708 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400709 encode_lookup_maxsz + \
710 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400711#define NFS4_dec_fs_locations_sz \
712 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400713 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400714 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400715 decode_lookup_maxsz + \
716 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000717#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
718 encode_sequence_maxsz + \
719 encode_putfh_maxsz + \
720 encode_secinfo_maxsz)
721#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
722 decode_sequence_maxsz + \
723 decode_putfh_maxsz + \
724 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400725#if defined(CONFIG_NFS_V4_1)
726#define NFS4_enc_exchange_id_sz \
727 (compound_encode_hdr_maxsz + \
728 encode_exchange_id_maxsz)
729#define NFS4_dec_exchange_id_sz \
730 (compound_decode_hdr_maxsz + \
731 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400732#define NFS4_enc_create_session_sz \
733 (compound_encode_hdr_maxsz + \
734 encode_create_session_maxsz)
735#define NFS4_dec_create_session_sz \
736 (compound_decode_hdr_maxsz + \
737 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400738#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
739 encode_destroy_session_maxsz)
740#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
741 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400742#define NFS4_enc_sequence_sz \
743 (compound_decode_hdr_maxsz + \
744 encode_sequence_maxsz)
745#define NFS4_dec_sequence_sz \
746 (compound_decode_hdr_maxsz + \
747 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400748#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
749 encode_sequence_maxsz + \
750 encode_putrootfh_maxsz + \
751 encode_fsinfo_maxsz)
752#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
753 decode_sequence_maxsz + \
754 decode_putrootfh_maxsz + \
755 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500756#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
757 encode_sequence_maxsz + \
758 encode_reclaim_complete_maxsz)
759#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
760 decode_sequence_maxsz + \
761 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400762#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
763 encode_sequence_maxsz + \
764 encode_putfh_maxsz + \
765 encode_getdevicelist_maxsz)
766#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
767 decode_sequence_maxsz + \
768 decode_putfh_maxsz + \
769 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400770#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
771 encode_sequence_maxsz +\
772 encode_getdeviceinfo_maxsz)
773#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
774 decode_sequence_maxsz + \
775 decode_getdeviceinfo_maxsz)
776#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
777 encode_sequence_maxsz + \
778 encode_putfh_maxsz + \
779 encode_layoutget_maxsz)
780#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
781 decode_sequence_maxsz + \
782 decode_putfh_maxsz + \
783 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000784#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
785 encode_sequence_maxsz +\
786 encode_putfh_maxsz + \
787 encode_layoutcommit_maxsz + \
788 encode_getattr_maxsz)
789#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
790 decode_sequence_maxsz + \
791 decode_putfh_maxsz + \
792 decode_layoutcommit_maxsz + \
793 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300794#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
795 encode_sequence_maxsz + \
796 encode_putfh_maxsz + \
797 encode_layoutreturn_maxsz)
798#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
799 decode_sequence_maxsz + \
800 decode_putfh_maxsz + \
801 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400802#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
803 encode_sequence_maxsz + \
804 encode_putrootfh_maxsz +\
805 encode_secinfo_no_name_maxsz)
806#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
807 decode_sequence_maxsz + \
808 decode_putrootfh_maxsz + \
809 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400810#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
811 encode_sequence_maxsz + \
812 encode_test_stateid_maxsz)
813#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
814 decode_sequence_maxsz + \
815 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400816#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
817 encode_sequence_maxsz + \
818 encode_free_stateid_maxsz)
819#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
820 decode_sequence_maxsz + \
821 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500822
823const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
824 compound_encode_hdr_maxsz +
825 encode_sequence_maxsz +
826 encode_putfh_maxsz +
827 encode_getattr_maxsz) *
828 XDR_UNIT);
829
830const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
831 compound_decode_hdr_maxsz +
832 decode_sequence_maxsz +
833 decode_putfh_maxsz) *
834 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400835#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Trond Myklebustbca79472009-03-11 14:10:26 -0400837static const umode_t nfs_type2fmt[] = {
838 [NF4BAD] = 0,
839 [NF4REG] = S_IFREG,
840 [NF4DIR] = S_IFDIR,
841 [NF4BLK] = S_IFBLK,
842 [NF4CHR] = S_IFCHR,
843 [NF4LNK] = S_IFLNK,
844 [NF4SOCK] = S_IFSOCK,
845 [NF4FIFO] = S_IFIFO,
846 [NF4ATTRDIR] = 0,
847 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848};
849
850struct compound_hdr {
851 int32_t status;
852 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500853 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 uint32_t taglen;
855 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400856 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400857 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858};
859
Benny Halevy13c65ce2009-08-14 17:19:25 +0300860static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
861{
862 __be32 *p = xdr_reserve_space(xdr, nbytes);
863 BUG_ON(!p);
864 return p;
865}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
867static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
868{
Al Viro8687b632006-10-19 23:28:48 -0700869 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 p = xdr_reserve_space(xdr, 4 + len);
872 BUG_ON(p == NULL);
873 xdr_encode_opaque(p, str, len);
874}
875
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400876static void encode_compound_hdr(struct xdr_stream *xdr,
877 struct rpc_rqst *req,
878 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
Al Viro8687b632006-10-19 23:28:48 -0700880 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400881 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400882
883 /* initialize running count of expected bytes in reply.
884 * NOTE: the replied tag SHOULD be the same is the one sent,
885 * but this is not required as a MUST for the server to do so. */
886 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
889 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300890 p = reserve_space(xdr, 4 + hdr->taglen + 8);
891 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300892 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500893 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300894 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500895}
896
897static void encode_nops(struct compound_hdr *hdr)
898{
Andy Adamsonfc931582009-04-01 09:22:31 -0400899 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500900 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901}
902
903static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
904{
Al Viro8687b632006-10-19 23:28:48 -0700905 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
907 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
908 BUG_ON(p == NULL);
909 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
910}
911
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500912static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913{
914 char owner_name[IDMAP_NAMESZ];
915 char owner_group[IDMAP_NAMESZ];
916 int owner_namelen = 0;
917 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700918 __be32 *p;
919 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 int len;
921 uint32_t bmval0 = 0;
922 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 /*
925 * We reserve enough space to write the entire attribute buffer at once.
926 * In the worst-case, this would be
927 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
928 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000929 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 */
931 len = 16;
932
933 /* Sigh */
934 if (iap->ia_valid & ATTR_SIZE)
935 len += 8;
936 if (iap->ia_valid & ATTR_MODE)
937 len += 4;
938 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800939 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400941 dprintk("nfs: couldn't resolve uid %d to string\n",
942 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 /* XXX */
944 strcpy(owner_name, "nobody");
945 owner_namelen = sizeof("nobody") - 1;
946 /* goto out; */
947 }
948 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
949 }
950 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800951 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400953 dprintk("nfs: couldn't resolve gid %d to string\n",
954 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 strcpy(owner_group, "nobody");
956 owner_grouplen = sizeof("nobody") - 1;
957 /* goto out; */
958 }
959 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
960 }
961 if (iap->ia_valid & ATTR_ATIME_SET)
962 len += 16;
963 else if (iap->ia_valid & ATTR_ATIME)
964 len += 4;
965 if (iap->ia_valid & ATTR_MTIME_SET)
966 len += 16;
967 else if (iap->ia_valid & ATTR_MTIME)
968 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300969 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
971 /*
972 * We write the bitmap length now, but leave the bitmap and the attribute
973 * buffer length to be backfilled at the end of this routine.
974 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300975 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 q = p;
977 p += 3;
978
979 if (iap->ia_valid & ATTR_SIZE) {
980 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300981 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 }
983 if (iap->ia_valid & ATTR_MODE) {
984 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300985 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 }
987 if (iap->ia_valid & ATTR_UID) {
988 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300989 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 }
991 if (iap->ia_valid & ATTR_GID) {
992 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300993 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 }
995 if (iap->ia_valid & ATTR_ATIME_SET) {
996 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300997 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
998 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400999 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1000 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 }
1002 else if (iap->ia_valid & ATTR_ATIME) {
1003 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001004 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 }
1006 if (iap->ia_valid & ATTR_MTIME_SET) {
1007 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001008 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1009 *p++ = cpu_to_be32(0);
1010 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1011 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 }
1013 else if (iap->ia_valid & ATTR_MTIME) {
1014 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001015 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001017
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 /*
1019 * Now we backfill the bitmap and the attribute buffer length.
1020 */
1021 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001022 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 len, ((char *)p - (char *)q) + 4);
1024 BUG();
1025 }
1026 len = (char *)p - (char *)q - 12;
1027 *q++ = htonl(bmval0);
1028 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001029 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032}
1033
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001034static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
Al Viro8687b632006-10-19 23:28:48 -07001036 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
Benny Halevy13c65ce2009-08-14 17:19:25 +03001038 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001039 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001040 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001041 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001042 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043}
1044
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001045static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046{
Al Viro8687b632006-10-19 23:28:48 -07001047 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Benny Halevy13c65ce2009-08-14 17:19:25 +03001049 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001050 *p++ = cpu_to_be32(OP_CLOSE);
1051 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001052 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001053 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001054 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055}
1056
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001057static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058{
Al Viro8687b632006-10-19 23:28:48 -07001059 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001060
Benny Halevy13c65ce2009-08-14 17:19:25 +03001061 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001062 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001063 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001064 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001065 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001066 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067}
1068
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001069static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070{
Al Viro8687b632006-10-19 23:28:48 -07001071 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001072
Benny Halevy13c65ce2009-08-14 17:19:25 +03001073 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001074 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001075 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
1077 switch (create->ftype) {
1078 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001079 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001080 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001081 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 break;
1083
1084 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001085 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001086 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001087 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 break;
1089
1090 default:
1091 break;
1092 }
1093
Benny Halevy811652b2009-08-14 17:19:34 +03001094 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001095 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001096 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001098 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099}
1100
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001101static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102{
Andy Adamson05d564f2008-12-23 16:06:15 -05001103 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Benny Halevy13c65ce2009-08-14 17:19:25 +03001105 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001106 *p++ = cpu_to_be32(OP_GETATTR);
1107 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001108 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001109 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001110 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111}
1112
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001113static 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 -07001114{
Andy Adamson05d564f2008-12-23 16:06:15 -05001115 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Benny Halevy13c65ce2009-08-14 17:19:25 +03001117 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001118 *p++ = cpu_to_be32(OP_GETATTR);
1119 *p++ = cpu_to_be32(2);
1120 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001121 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001122 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001123 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124}
1125
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001126static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001128 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1129 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130}
1131
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001132static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001134 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1135 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136}
1137
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001138static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001139{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001140 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1141 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001142}
1143
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001144static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Al Viro8687b632006-10-19 23:28:48 -07001146 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Benny Halevy13c65ce2009-08-14 17:19:25 +03001148 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001149 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001150 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001151 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001154static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155{
Al Viro8687b632006-10-19 23:28:48 -07001156 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Benny Halevy13c65ce2009-08-14 17:19:25 +03001158 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001159 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001160 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001161 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001162 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001165static inline int nfs4_lock_type(struct file_lock *fl, int block)
1166{
1167 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1168 return block ? NFS4_READW_LT : NFS4_READ_LT;
1169 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1170}
1171
1172static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1173{
1174 if (fl->fl_end == OFFSET_MAX)
1175 return ~(uint64_t)0;
1176 return fl->fl_end - fl->fl_start + 1;
1177}
1178
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001179static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1180{
1181 __be32 *p;
1182
Trond Myklebustd035c362010-12-21 10:45:27 -05001183 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001184 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001185 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001186 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001187 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001188 xdr_encode_hyper(p, lowner->id);
1189}
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191/*
1192 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1193 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1194 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001195static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
Al Viro8687b632006-10-19 23:28:48 -07001197 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Benny Halevy13c65ce2009-08-14 17:19:25 +03001199 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001200 *p++ = cpu_to_be32(OP_LOCK);
1201 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1202 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001203 p = xdr_encode_hyper(p, args->fl->fl_start);
1204 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001205 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001206 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001207 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001208 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001209 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001210 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001211 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 }
1213 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001214 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001215 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001216 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 }
Andy Adamsond0179312008-12-23 16:06:17 -05001218 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001219 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220}
1221
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001222static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223{
Al Viro8687b632006-10-19 23:28:48 -07001224 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001226 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001227 *p++ = cpu_to_be32(OP_LOCKT);
1228 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001229 p = xdr_encode_hyper(p, args->fl->fl_start);
1230 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001231 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001232 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001233 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234}
1235
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001236static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237{
Al Viro8687b632006-10-19 23:28:48 -07001238 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Benny Halevy13c65ce2009-08-14 17:19:25 +03001240 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001241 *p++ = cpu_to_be32(OP_LOCKU);
1242 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1243 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001244 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001245 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001246 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001247 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001248 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249}
1250
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001251static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1252{
1253 __be32 *p;
1254
1255 p = reserve_space(xdr, 4);
1256 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1257 encode_lockowner(xdr, lowner);
1258 hdr->nops++;
1259 hdr->replen += decode_release_lockowner_maxsz;
1260}
1261
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001262static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
1264 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001265 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Benny Halevy13c65ce2009-08-14 17:19:25 +03001267 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001268 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001269 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001270 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001271 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272}
1273
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001274static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275{
Al Viro8687b632006-10-19 23:28:48 -07001276 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Benny Halevy13c65ce2009-08-14 17:19:25 +03001278 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001279 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001280 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001281 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001282 break;
1283 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001284 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001285 break;
1286 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001287 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001288 break;
1289 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001290 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 }
Benny Halevy34558512009-08-14 17:19:30 +03001292 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293}
1294
1295static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1296{
Al Viro8687b632006-10-19 23:28:48 -07001297 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 /*
1299 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1300 * owner 4 = 32
1301 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001302 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001303 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001304 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001305 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001306 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001307 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001308 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001309 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001310 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001311 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312}
1313
1314static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1315{
Al Viro8687b632006-10-19 23:28:48 -07001316 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001317 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Benny Halevy13c65ce2009-08-14 17:19:25 +03001319 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001321 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001322 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001323 encode_attrs(xdr, arg->u.attrs, arg->server);
1324 break;
1325 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001326 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001327 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001328 if (nfs4_has_persistent_session(clp)) {
1329 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1330 encode_attrs(xdr, arg->u.attrs, arg->server);
1331 } else {
1332 struct iattr dummy;
1333
1334 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1335 encode_nfs4_verifier(xdr, &arg->u.verifier);
1336 dummy.ia_valid = 0;
1337 encode_attrs(xdr, &dummy, arg->server);
1338 }
1339 } else {
1340 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1341 encode_nfs4_verifier(xdr, &arg->u.verifier);
1342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 }
1344}
1345
1346static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1347{
Al Viro8687b632006-10-19 23:28:48 -07001348 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Benny Halevy13c65ce2009-08-14 17:19:25 +03001350 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001352 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001353 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001354 break;
1355 default:
1356 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001357 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001358 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 }
1360}
1361
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001362static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363{
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 (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001368 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001369 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001370 break;
1371 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001372 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001373 break;
1374 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001375 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001376 break;
1377 default:
1378 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
1380}
1381
1382static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1383{
Al Viro8687b632006-10-19 23:28:48 -07001384 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Benny Halevy13c65ce2009-08-14 17:19:25 +03001386 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001387 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 encode_string(xdr, name->len, name->name);
1389}
1390
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001391static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392{
Al Viro8687b632006-10-19 23:28:48 -07001393 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Benny Halevy13c65ce2009-08-14 17:19:25 +03001395 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001396 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 encode_delegation_type(xdr, type);
1398}
1399
1400static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1401{
Al Viro8687b632006-10-19 23:28:48 -07001402 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
Benny Halevy13c65ce2009-08-14 17:19:25 +03001404 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001405 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001406 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 encode_string(xdr, name->len, name->name);
1408}
1409
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001410static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411{
1412 encode_openhdr(xdr, arg);
1413 encode_opentype(xdr, arg);
1414 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001415 case NFS4_OPEN_CLAIM_NULL:
1416 encode_claim_null(xdr, arg->name);
1417 break;
1418 case NFS4_OPEN_CLAIM_PREVIOUS:
1419 encode_claim_previous(xdr, arg->u.delegation_type);
1420 break;
1421 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1422 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1423 break;
1424 default:
1425 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 }
Andy Adamsond0179312008-12-23 16:06:17 -05001427 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001428 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429}
1430
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001431static 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 -07001432{
Al Viro8687b632006-10-19 23:28:48 -07001433 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Benny Halevy13c65ce2009-08-14 17:19:25 +03001435 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001436 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001437 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001438 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001439 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001440 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441}
1442
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001443static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
Al Viro8687b632006-10-19 23:28:48 -07001445 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Benny Halevy13c65ce2009-08-14 17:19:25 +03001447 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001448 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001449 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001450 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001451 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001452 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001453 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454}
1455
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001456static void
Andy Adamsond0179312008-12-23 16:06:17 -05001457encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458{
1459 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001460 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Benny Halevy13c65ce2009-08-14 17:19:25 +03001462 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001463 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001464 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001465 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001466 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467}
1468
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001469static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470{
Andy Adamson05d564f2008-12-23 16:06:15 -05001471 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001472
Benny Halevy13c65ce2009-08-14 17:19:25 +03001473 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001474 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001475 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001476 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477}
1478
Andy Adamson89d1ea62011-03-01 01:34:09 +00001479static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001482 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Benny Halevy13c65ce2009-08-14 17:19:25 +03001484 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001486 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001487 if (zero_seqid)
1488 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001489 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 } else
Benny Halevy34558512009-08-14 17:19:30 +03001491 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492}
1493
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001494static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495{
Al Viro8687b632006-10-19 23:28:48 -07001496 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
Benny Halevy13c65ce2009-08-14 17:19:25 +03001498 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001499 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Andy Adamson89d1ea62011-03-01 01:34:09 +00001501 encode_stateid(xdr, args->context, args->lock_context,
1502 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503
Benny Halevy13c65ce2009-08-14 17:19:25 +03001504 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001505 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001506 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001507 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001508 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509}
1510
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001511static 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 -07001512{
Trond Myklebust28331a42011-04-27 13:47:52 -04001513 uint32_t attrs[2] = {
1514 FATTR4_WORD0_RDATTR_ERROR,
1515 FATTR4_WORD1_MOUNTED_ON_FILEID,
1516 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001517 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001518 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001520 if (readdir->plus) {
1521 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001522 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001523 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1524 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1525 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1526 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001527 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001528 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001529 /* Use mounted_on_fileid only if the server supports it */
1530 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1531 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001532
Benny Halevy13c65ce2009-08-14 17:19:25 +03001533 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001534 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001535 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001536 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001537 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001538 *p++ = cpu_to_be32(readdir->count);
1539 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001540
Benny Halevye75bc1c2009-08-14 17:18:54 +03001541 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001542 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001543 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001544 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001545 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1546 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001547 (unsigned long long)readdir->cookie,
1548 ((u32 *)readdir->verifier.data)[0],
1549 ((u32 *)readdir->verifier.data)[1],
1550 attrs[0] & readdir->bitmask[0],
1551 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001554static 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 -07001555{
Al Viro8687b632006-10-19 23:28:48 -07001556 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
Benny Halevy13c65ce2009-08-14 17:19:25 +03001558 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001559 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001560 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001561 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562}
1563
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001564static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
Al Viro8687b632006-10-19 23:28:48 -07001566 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
Benny Halevy13c65ce2009-08-14 17:19:25 +03001568 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001569 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001570 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001571 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001572 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573}
1574
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001575static 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 -07001576{
Al Viro8687b632006-10-19 23:28:48 -07001577 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Benny Halevy811652b2009-08-14 17:19:34 +03001579 p = reserve_space(xdr, 4);
1580 *p = cpu_to_be32(OP_RENAME);
1581 encode_string(xdr, oldname->len, oldname->name);
1582 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001583 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001584 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585}
1586
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001587static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588{
Al Viro8687b632006-10-19 23:28:48 -07001589 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Benny Halevy13c65ce2009-08-14 17:19:25 +03001591 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001592 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001593 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001594 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001595 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596}
1597
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001598static void
Andy Adamsond0179312008-12-23 16:06:17 -05001599encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001600{
Al Viro8687b632006-10-19 23:28:48 -07001601 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001602
Benny Halevy13c65ce2009-08-14 17:19:25 +03001603 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001604 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001605 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001606 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001607}
1608
Chuck Lever9f06c712010-12-14 14:59:18 +00001609static void
Andy Adamsond0179312008-12-23 16:06:17 -05001610encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001611{
Al Viro8687b632006-10-19 23:28:48 -07001612 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001613
Benny Halevy13c65ce2009-08-14 17:19:25 +03001614 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001615 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001616 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001617 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001618 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001619 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001620 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001621 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001622 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001623 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001624 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001625 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001626}
1627
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001628static void
Andy Adamsond0179312008-12-23 16:06:17 -05001629encode_savefh(struct xdr_stream *xdr, 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
Benny Halevy13c65ce2009-08-14 17:19:25 +03001633 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001634 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001635 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001636 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637}
1638
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001639static 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 -07001640{
Al Viro8687b632006-10-19 23:28:48 -07001641 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001642
Benny Halevy13c65ce2009-08-14 17:19:25 +03001643 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001644 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001645 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001646 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001647 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001648 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001651static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652{
Al Viro8687b632006-10-19 23:28:48 -07001653 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
Benny Halevy13c65ce2009-08-14 17:19:25 +03001655 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001656 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001657 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
1659 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001660 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001661 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1663 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001664 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001665 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001666 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001667 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668}
1669
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001670static 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 -07001671{
Andy Adamson05d564f2008-12-23 16:06:15 -05001672 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Benny Halevy13c65ce2009-08-14 17:19:25 +03001674 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001675 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001676 p = xdr_encode_hyper(p, arg->clientid);
1677 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001678 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001679 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680}
1681
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001682static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683{
Al Viro8687b632006-10-19 23:28:48 -07001684 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Benny Halevy13c65ce2009-08-14 17:19:25 +03001686 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001687 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Andy Adamson89d1ea62011-03-01 01:34:09 +00001689 encode_stateid(xdr, args->context, args->lock_context,
1690 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Benny Halevy13c65ce2009-08-14 17:19:25 +03001692 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001693 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001694 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001695 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
1697 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001698 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001699 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
1701
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001702static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703{
Al Viro8687b632006-10-19 23:28:48 -07001704 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
Benny Halevy13c65ce2009-08-14 17:19:25 +03001706 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Benny Halevye75bc1c2009-08-14 17:18:54 +03001708 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001709 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001710 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001711 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001713
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001714static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1715{
1716 int len = name->len;
1717 __be32 *p;
1718
1719 p = reserve_space(xdr, 8 + len);
1720 *p++ = cpu_to_be32(OP_SECINFO);
1721 xdr_encode_opaque(p, name->name, len);
1722 hdr->nops++;
1723 hdr->replen += decode_secinfo_maxsz;
1724}
1725
Benny Halevy99fe60d2009-04-01 09:22:29 -04001726#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001727/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001728static void encode_exchange_id(struct xdr_stream *xdr,
1729 struct nfs41_exchange_id_args *args,
1730 struct compound_hdr *hdr)
1731{
1732 __be32 *p;
1733
Benny Halevy13c65ce2009-08-14 17:19:25 +03001734 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001735 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001736 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001737
1738 encode_string(xdr, args->id_len, args->id);
1739
Benny Halevy13c65ce2009-08-14 17:19:25 +03001740 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001741 *p++ = cpu_to_be32(args->flags);
1742 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001743 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001744 hdr->nops++;
1745 hdr->replen += decode_exchange_id_maxsz;
1746}
Andy Adamsonfc931582009-04-01 09:22:31 -04001747
1748static void encode_create_session(struct xdr_stream *xdr,
1749 struct nfs41_create_session_args *args,
1750 struct compound_hdr *hdr)
1751{
1752 __be32 *p;
1753 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1754 uint32_t len;
1755 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001756 u32 max_resp_sz_cached;
1757
1758 /*
1759 * Assumes OPEN is the biggest non-idempotent compound.
1760 * 2 is the verifier.
1761 */
1762 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1763 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001764
Andy Adamsonfc931582009-04-01 09:22:31 -04001765 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1766 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001767
Benny Halevy13c65ce2009-08-14 17:19:25 +03001768 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001769 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001770 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001771 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1772 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001773
Andy Adamsonfc931582009-04-01 09:22:31 -04001774 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001775 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001776 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1777 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001778 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001779 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1780 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1781 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001782
1783 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001784 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001785 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1786 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1787 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1788 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1789 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1790 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001791
Benny Halevye75bc1c2009-08-14 17:18:54 +03001792 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001793 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001794 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001795
1796 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001797 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001798 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001799 *p++ = cpu_to_be32(0); /* UID */
1800 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001801 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001802 hdr->nops++;
1803 hdr->replen += decode_create_session_maxsz;
1804}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001805
1806static void encode_destroy_session(struct xdr_stream *xdr,
1807 struct nfs4_session *session,
1808 struct compound_hdr *hdr)
1809{
1810 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001811 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001812 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001813 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001814 hdr->nops++;
1815 hdr->replen += decode_destroy_session_maxsz;
1816}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001817
1818static void encode_reclaim_complete(struct xdr_stream *xdr,
1819 struct nfs41_reclaim_complete_args *args,
1820 struct compound_hdr *hdr)
1821{
1822 __be32 *p;
1823
1824 p = reserve_space(xdr, 8);
1825 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1826 *p++ = cpu_to_be32(args->one_fs);
1827 hdr->nops++;
1828 hdr->replen += decode_reclaim_complete_maxsz;
1829}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001830#endif /* CONFIG_NFS_V4_1 */
1831
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001832static void encode_sequence(struct xdr_stream *xdr,
1833 const struct nfs4_sequence_args *args,
1834 struct compound_hdr *hdr)
1835{
1836#if defined(CONFIG_NFS_V4_1)
1837 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001838 struct nfs4_slot_table *tp;
1839 struct nfs4_slot *slot;
1840 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001841
1842 if (!session)
1843 return;
1844
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001845 tp = &session->fc_slot_table;
1846
1847 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1848 slot = tp->slots + args->sa_slotid;
1849
Benny Halevy13c65ce2009-08-14 17:19:25 +03001850 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001851 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001852
1853 /*
1854 * Sessionid + seqid + slotid + max slotid + cache_this
1855 */
1856 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1857 "max_slotid=%d cache_this=%d\n",
1858 __func__,
1859 ((u32 *)session->sess_id.data)[0],
1860 ((u32 *)session->sess_id.data)[1],
1861 ((u32 *)session->sess_id.data)[2],
1862 ((u32 *)session->sess_id.data)[3],
1863 slot->seq_nr, args->sa_slotid,
1864 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001865 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001866 *p++ = cpu_to_be32(slot->seq_nr);
1867 *p++ = cpu_to_be32(args->sa_slotid);
1868 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001869 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001870 hdr->nops++;
1871 hdr->replen += decode_sequence_maxsz;
1872#endif /* CONFIG_NFS_V4_1 */
1873}
1874
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001875#ifdef CONFIG_NFS_V4_1
1876static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001877encode_getdevicelist(struct xdr_stream *xdr,
1878 const struct nfs4_getdevicelist_args *args,
1879 struct compound_hdr *hdr)
1880{
1881 __be32 *p;
1882 nfs4_verifier dummy = {
1883 .data = "dummmmmy",
1884 };
1885
1886 p = reserve_space(xdr, 20);
1887 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1888 *p++ = cpu_to_be32(args->layoutclass);
1889 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1890 xdr_encode_hyper(p, 0ULL); /* cookie */
1891 encode_nfs4_verifier(xdr, &dummy);
1892 hdr->nops++;
1893 hdr->replen += decode_getdevicelist_maxsz;
1894}
1895
1896static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001897encode_getdeviceinfo(struct xdr_stream *xdr,
1898 const struct nfs4_getdeviceinfo_args *args,
1899 struct compound_hdr *hdr)
1900{
1901 __be32 *p;
1902
1903 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1904 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1905 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1906 NFS4_DEVICEID4_SIZE);
1907 *p++ = cpu_to_be32(args->pdev->layout_type);
1908 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1909 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1910 hdr->nops++;
1911 hdr->replen += decode_getdeviceinfo_maxsz;
1912}
1913
1914static void
1915encode_layoutget(struct xdr_stream *xdr,
1916 const struct nfs4_layoutget_args *args,
1917 struct compound_hdr *hdr)
1918{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001919 __be32 *p;
1920
1921 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1922 *p++ = cpu_to_be32(OP_LAYOUTGET);
1923 *p++ = cpu_to_be32(0); /* Signal layout available */
1924 *p++ = cpu_to_be32(args->type);
1925 *p++ = cpu_to_be32(args->range.iomode);
1926 p = xdr_encode_hyper(p, args->range.offset);
1927 p = xdr_encode_hyper(p, args->range.length);
1928 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001929 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001930 *p = cpu_to_be32(args->maxcount);
1931
1932 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1933 __func__,
1934 args->type,
1935 args->range.iomode,
1936 (unsigned long)args->range.offset,
1937 (unsigned long)args->range.length,
1938 args->maxcount);
1939 hdr->nops++;
1940 hdr->replen += decode_layoutget_maxsz;
1941}
Andy Adamson863a3c62011-03-23 13:27:54 +00001942
1943static int
1944encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001945 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001946 const struct nfs4_layoutcommit_args *args,
1947 struct compound_hdr *hdr)
1948{
1949 __be32 *p;
1950
1951 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1952 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1953
Benny Halevyac7db722011-05-22 19:53:48 +03001954 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
Andy Adamson863a3c62011-03-23 13:27:54 +00001955 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1956 /* Only whole file layouts */
1957 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001958 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Andy Adamson863a3c62011-03-23 13:27:54 +00001959 *p++ = cpu_to_be32(0); /* reclaim */
1960 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1961 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1962 p = xdr_encode_hyper(p, args->lastbytewritten);
1963 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1964 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001965
1966 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1967 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1968 NFS_I(inode)->layout, xdr, args);
1969 else {
1970 p = reserve_space(xdr, 4);
1971 *p = cpu_to_be32(0); /* no layout-type payload */
1972 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001973
1974 hdr->nops++;
1975 hdr->replen += decode_layoutcommit_maxsz;
1976 return 0;
1977}
Benny Halevycbe82602011-05-22 19:52:37 +03001978
1979static void
1980encode_layoutreturn(struct xdr_stream *xdr,
1981 const struct nfs4_layoutreturn_args *args,
1982 struct compound_hdr *hdr)
1983{
1984 __be32 *p;
1985
1986 p = reserve_space(xdr, 20);
1987 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
1988 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1989 *p++ = cpu_to_be32(args->layout_type);
1990 *p++ = cpu_to_be32(IOMODE_ANY);
1991 *p = cpu_to_be32(RETURN_FILE);
1992 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
1993 p = xdr_encode_hyper(p, 0);
1994 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1995 spin_lock(&args->inode->i_lock);
1996 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1997 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001998 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1999 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2000 NFS_I(args->inode)->layout, xdr, args);
2001 } else {
2002 p = reserve_space(xdr, 4);
2003 *p = cpu_to_be32(0);
2004 }
Benny Halevycbe82602011-05-22 19:52:37 +03002005 hdr->nops++;
2006 hdr->replen += decode_layoutreturn_maxsz;
2007}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002008
2009static int
2010encode_secinfo_no_name(struct xdr_stream *xdr,
2011 const struct nfs41_secinfo_no_name_args *args,
2012 struct compound_hdr *hdr)
2013{
2014 __be32 *p;
2015 p = reserve_space(xdr, 8);
2016 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2017 *p++ = cpu_to_be32(args->style);
2018 hdr->nops++;
2019 hdr->replen += decode_secinfo_no_name_maxsz;
2020 return 0;
2021}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002022
2023static void encode_test_stateid(struct xdr_stream *xdr,
2024 struct nfs41_test_stateid_args *args,
2025 struct compound_hdr *hdr)
2026{
2027 __be32 *p;
2028
2029 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
2030 *p++ = cpu_to_be32(OP_TEST_STATEID);
2031 *p++ = cpu_to_be32(1);
2032 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2033 hdr->nops++;
2034 hdr->replen += decode_test_stateid_maxsz;
2035}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002036
2037static void encode_free_stateid(struct xdr_stream *xdr,
2038 struct nfs41_free_stateid_args *args,
2039 struct compound_hdr *hdr)
2040{
2041 __be32 *p;
2042 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2043 *p++ = cpu_to_be32(OP_FREE_STATEID);
2044 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2045 hdr->nops++;
2046 hdr->replen += decode_free_stateid_maxsz;
2047}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002048#endif /* CONFIG_NFS_V4_1 */
2049
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050/*
2051 * END OF "GENERIC" ENCODE ROUTINES.
2052 */
2053
Benny Halevy66cc0422009-04-01 09:22:10 -04002054static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2055{
2056#if defined(CONFIG_NFS_V4_1)
2057 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002058 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002059#endif /* CONFIG_NFS_V4_1 */
2060 return 0;
2061}
2062
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063/*
2064 * Encode an ACCESS request
2065 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002066static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2067 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002070 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072
Chuck Lever9f06c712010-12-14 14:59:18 +00002073 encode_compound_hdr(xdr, req, &hdr);
2074 encode_sequence(xdr, &args->seq_args, &hdr);
2075 encode_putfh(xdr, args->fh, &hdr);
2076 encode_access(xdr, args->access, &hdr);
2077 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002078 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079}
2080
2081/*
2082 * Encode LOOKUP request
2083 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002084static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2085 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002088 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
Chuck Lever9f06c712010-12-14 14:59:18 +00002091 encode_compound_hdr(xdr, req, &hdr);
2092 encode_sequence(xdr, &args->seq_args, &hdr);
2093 encode_putfh(xdr, args->dir_fh, &hdr);
2094 encode_lookup(xdr, args->name, &hdr);
2095 encode_getfh(xdr, &hdr);
2096 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002097 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098}
2099
2100/*
2101 * Encode LOOKUP_ROOT request
2102 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002103static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2104 struct xdr_stream *xdr,
2105 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002108 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110
Chuck Lever9f06c712010-12-14 14:59:18 +00002111 encode_compound_hdr(xdr, req, &hdr);
2112 encode_sequence(xdr, &args->seq_args, &hdr);
2113 encode_putrootfh(xdr, &hdr);
2114 encode_getfh(xdr, &hdr);
2115 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002116 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117}
2118
2119/*
2120 * Encode REMOVE request
2121 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002122static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2123 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002126 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128
Chuck Lever9f06c712010-12-14 14:59:18 +00002129 encode_compound_hdr(xdr, req, &hdr);
2130 encode_sequence(xdr, &args->seq_args, &hdr);
2131 encode_putfh(xdr, args->fh, &hdr);
2132 encode_remove(xdr, &args->name, &hdr);
2133 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002134 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135}
2136
2137/*
2138 * Encode RENAME request
2139 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002140static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2141 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002144 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
Chuck Lever9f06c712010-12-14 14:59:18 +00002147 encode_compound_hdr(xdr, req, &hdr);
2148 encode_sequence(xdr, &args->seq_args, &hdr);
2149 encode_putfh(xdr, args->old_dir, &hdr);
2150 encode_savefh(xdr, &hdr);
2151 encode_putfh(xdr, args->new_dir, &hdr);
2152 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2153 encode_getfattr(xdr, args->bitmask, &hdr);
2154 encode_restorefh(xdr, &hdr);
2155 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002156 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157}
2158
2159/*
2160 * Encode LINK request
2161 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002162static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2163 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002166 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
Chuck Lever9f06c712010-12-14 14:59:18 +00002169 encode_compound_hdr(xdr, req, &hdr);
2170 encode_sequence(xdr, &args->seq_args, &hdr);
2171 encode_putfh(xdr, args->fh, &hdr);
2172 encode_savefh(xdr, &hdr);
2173 encode_putfh(xdr, args->dir_fh, &hdr);
2174 encode_link(xdr, args->name, &hdr);
2175 encode_getfattr(xdr, args->bitmask, &hdr);
2176 encode_restorefh(xdr, &hdr);
2177 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002178 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179}
2180
2181/*
2182 * Encode CREATE request
2183 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002184static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2185 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002188 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190
Chuck Lever9f06c712010-12-14 14:59:18 +00002191 encode_compound_hdr(xdr, req, &hdr);
2192 encode_sequence(xdr, &args->seq_args, &hdr);
2193 encode_putfh(xdr, args->dir_fh, &hdr);
2194 encode_savefh(xdr, &hdr);
2195 encode_create(xdr, args, &hdr);
2196 encode_getfh(xdr, &hdr);
2197 encode_getfattr(xdr, args->bitmask, &hdr);
2198 encode_restorefh(xdr, &hdr);
2199 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002200 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201}
2202
2203/*
2204 * Encode SYMLINK request
2205 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002206static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2207 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208{
Chuck Lever9f06c712010-12-14 14:59:18 +00002209 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210}
2211
2212/*
2213 * Encode GETATTR request
2214 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002215static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2216 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002219 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
Chuck Lever9f06c712010-12-14 14:59:18 +00002222 encode_compound_hdr(xdr, req, &hdr);
2223 encode_sequence(xdr, &args->seq_args, &hdr);
2224 encode_putfh(xdr, args->fh, &hdr);
2225 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002226 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227}
2228
2229/*
2230 * Encode a CLOSE request
2231 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002232static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2233 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234{
Andy Adamson05d564f2008-12-23 16:06:15 -05002235 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002236 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002237 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238
Chuck Lever9f06c712010-12-14 14:59:18 +00002239 encode_compound_hdr(xdr, req, &hdr);
2240 encode_sequence(xdr, &args->seq_args, &hdr);
2241 encode_putfh(xdr, args->fh, &hdr);
2242 encode_close(xdr, args, &hdr);
2243 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002244 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245}
2246
2247/*
2248 * Encode an OPEN request
2249 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002250static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2251 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002254 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
Chuck Lever9f06c712010-12-14 14:59:18 +00002257 encode_compound_hdr(xdr, req, &hdr);
2258 encode_sequence(xdr, &args->seq_args, &hdr);
2259 encode_putfh(xdr, args->fh, &hdr);
2260 encode_savefh(xdr, &hdr);
2261 encode_open(xdr, args, &hdr);
2262 encode_getfh(xdr, &hdr);
2263 encode_getfattr(xdr, args->bitmask, &hdr);
2264 encode_restorefh(xdr, &hdr);
2265 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002266 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267}
2268
2269/*
2270 * Encode an OPEN_CONFIRM request
2271 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002272static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2273 struct xdr_stream *xdr,
2274 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002277 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
Chuck Lever9f06c712010-12-14 14:59:18 +00002280 encode_compound_hdr(xdr, req, &hdr);
2281 encode_putfh(xdr, args->fh, &hdr);
2282 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002283 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284}
2285
2286/*
2287 * Encode an OPEN request with no attributes.
2288 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002289static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2290 struct xdr_stream *xdr,
2291 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002294 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296
Chuck Lever9f06c712010-12-14 14:59:18 +00002297 encode_compound_hdr(xdr, req, &hdr);
2298 encode_sequence(xdr, &args->seq_args, &hdr);
2299 encode_putfh(xdr, args->fh, &hdr);
2300 encode_open(xdr, args, &hdr);
2301 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002302 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303}
2304
2305/*
2306 * Encode an OPEN_DOWNGRADE request
2307 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002308static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2309 struct xdr_stream *xdr,
2310 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002313 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Chuck Lever9f06c712010-12-14 14:59:18 +00002316 encode_compound_hdr(xdr, req, &hdr);
2317 encode_sequence(xdr, &args->seq_args, &hdr);
2318 encode_putfh(xdr, args->fh, &hdr);
2319 encode_open_downgrade(xdr, args, &hdr);
2320 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002321 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322}
2323
2324/*
2325 * Encode a LOCK request
2326 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002327static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2328 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002331 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
Chuck Lever9f06c712010-12-14 14:59:18 +00002334 encode_compound_hdr(xdr, req, &hdr);
2335 encode_sequence(xdr, &args->seq_args, &hdr);
2336 encode_putfh(xdr, args->fh, &hdr);
2337 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002338 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339}
2340
2341/*
2342 * Encode a LOCKT request
2343 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002344static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2345 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002348 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350
Chuck Lever9f06c712010-12-14 14:59:18 +00002351 encode_compound_hdr(xdr, req, &hdr);
2352 encode_sequence(xdr, &args->seq_args, &hdr);
2353 encode_putfh(xdr, args->fh, &hdr);
2354 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002355 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356}
2357
2358/*
2359 * Encode a LOCKU request
2360 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002361static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2362 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002365 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367
Chuck Lever9f06c712010-12-14 14:59:18 +00002368 encode_compound_hdr(xdr, req, &hdr);
2369 encode_sequence(xdr, &args->seq_args, &hdr);
2370 encode_putfh(xdr, args->fh, &hdr);
2371 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002372 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373}
2374
Chuck Lever9f06c712010-12-14 14:59:18 +00002375static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2376 struct xdr_stream *xdr,
2377 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002378{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002379 struct compound_hdr hdr = {
2380 .minorversion = 0,
2381 };
2382
Chuck Lever9f06c712010-12-14 14:59:18 +00002383 encode_compound_hdr(xdr, req, &hdr);
2384 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002385 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002386}
2387
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388/*
2389 * Encode a READLINK request
2390 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002391static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2392 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002395 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397
Chuck Lever9f06c712010-12-14 14:59:18 +00002398 encode_compound_hdr(xdr, req, &hdr);
2399 encode_sequence(xdr, &args->seq_args, &hdr);
2400 encode_putfh(xdr, args->fh, &hdr);
2401 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002402
Benny Halevy28f56692009-04-01 09:22:09 -04002403 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002404 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002405 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406}
2407
2408/*
2409 * Encode a READDIR request
2410 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002411static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2412 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002415 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Chuck Lever9f06c712010-12-14 14:59:18 +00002418 encode_compound_hdr(xdr, req, &hdr);
2419 encode_sequence(xdr, &args->seq_args, &hdr);
2420 encode_putfh(xdr, args->fh, &hdr);
2421 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002422
Benny Halevy28f56692009-04-01 09:22:09 -04002423 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002424 args->pgbase, args->count);
2425 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002426 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002427 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002428 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429}
2430
2431/*
2432 * Encode a READ request
2433 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002434static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2435 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002438 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
Chuck Lever9f06c712010-12-14 14:59:18 +00002441 encode_compound_hdr(xdr, req, &hdr);
2442 encode_sequence(xdr, &args->seq_args, &hdr);
2443 encode_putfh(xdr, args->fh, &hdr);
2444 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Benny Halevy28f56692009-04-01 09:22:09 -04002446 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002448 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002449 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450}
2451
2452/*
2453 * Encode an SETATTR request
2454 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002455static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2456 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457{
Andy Adamson05d564f2008-12-23 16:06:15 -05002458 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002459 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002460 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461
Chuck Lever9f06c712010-12-14 14:59:18 +00002462 encode_compound_hdr(xdr, req, &hdr);
2463 encode_sequence(xdr, &args->seq_args, &hdr);
2464 encode_putfh(xdr, args->fh, &hdr);
2465 encode_setattr(xdr, args, args->server, &hdr);
2466 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002467 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468}
2469
2470/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002471 * Encode a GETACL request
2472 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002473static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2474 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002475{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002476 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002477 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002478 };
Benny Halevy28f56692009-04-01 09:22:09 -04002479 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002480
Chuck Lever9f06c712010-12-14 14:59:18 +00002481 encode_compound_hdr(xdr, req, &hdr);
2482 encode_sequence(xdr, &args->seq_args, &hdr);
2483 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002484 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002485 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002486
Benny Halevy28f56692009-04-01 09:22:09 -04002487 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002488 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002489 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002490}
2491
2492/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 * Encode a WRITE request
2494 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002495static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2496 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002499 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
Chuck Lever9f06c712010-12-14 14:59:18 +00002502 encode_compound_hdr(xdr, req, &hdr);
2503 encode_sequence(xdr, &args->seq_args, &hdr);
2504 encode_putfh(xdr, args->fh, &hdr);
2505 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002506 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002507 if (args->bitmask)
2508 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002509 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510}
2511
2512/*
2513 * a COMMIT request
2514 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002515static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2516 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002519 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
Chuck Lever9f06c712010-12-14 14:59:18 +00002522 encode_compound_hdr(xdr, req, &hdr);
2523 encode_sequence(xdr, &args->seq_args, &hdr);
2524 encode_putfh(xdr, args->fh, &hdr);
2525 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002526 if (args->bitmask)
2527 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002528 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529}
2530
2531/*
2532 * FSINFO request
2533 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002534static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2535 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002538 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
Chuck Lever9f06c712010-12-14 14:59:18 +00002541 encode_compound_hdr(xdr, req, &hdr);
2542 encode_sequence(xdr, &args->seq_args, &hdr);
2543 encode_putfh(xdr, args->fh, &hdr);
2544 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002545 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546}
2547
2548/*
2549 * a PATHCONF request
2550 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002551static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2552 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002555 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557
Chuck Lever9f06c712010-12-14 14:59:18 +00002558 encode_compound_hdr(xdr, req, &hdr);
2559 encode_sequence(xdr, &args->seq_args, &hdr);
2560 encode_putfh(xdr, args->fh, &hdr);
2561 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002562 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002563 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564}
2565
2566/*
2567 * a STATFS request
2568 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002569static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2570 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002573 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
Chuck Lever9f06c712010-12-14 14:59:18 +00002576 encode_compound_hdr(xdr, req, &hdr);
2577 encode_sequence(xdr, &args->seq_args, &hdr);
2578 encode_putfh(xdr, args->fh, &hdr);
2579 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002580 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002581 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582}
2583
2584/*
2585 * GETATTR_BITMAP request
2586 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002587static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2588 struct xdr_stream *xdr,
2589 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002592 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594
Chuck Lever9f06c712010-12-14 14:59:18 +00002595 encode_compound_hdr(xdr, req, &hdr);
2596 encode_sequence(xdr, &args->seq_args, &hdr);
2597 encode_putfh(xdr, args->fhandle, &hdr);
2598 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002599 FATTR4_WORD0_LINK_SUPPORT|
2600 FATTR4_WORD0_SYMLINK_SUPPORT|
2601 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002602 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603}
2604
2605/*
2606 * a RENEW request
2607 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002608static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2609 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002612 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 };
2614
Chuck Lever9f06c712010-12-14 14:59:18 +00002615 encode_compound_hdr(xdr, req, &hdr);
2616 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002617 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618}
2619
2620/*
2621 * a SETCLIENTID request
2622 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002623static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2624 struct xdr_stream *xdr,
2625 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002628 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 };
2630
Chuck Lever9f06c712010-12-14 14:59:18 +00002631 encode_compound_hdr(xdr, req, &hdr);
2632 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002633 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634}
2635
2636/*
2637 * a SETCLIENTID_CONFIRM request
2638 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002639static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2640 struct xdr_stream *xdr,
2641 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002644 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 };
2646 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
Chuck Lever9f06c712010-12-14 14:59:18 +00002648 encode_compound_hdr(xdr, req, &hdr);
2649 encode_setclientid_confirm(xdr, arg, &hdr);
2650 encode_putrootfh(xdr, &hdr);
2651 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002652 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653}
2654
2655/*
2656 * DELEGRETURN request
2657 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002658static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2659 struct xdr_stream *xdr,
2660 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002663 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
Chuck Lever9f06c712010-12-14 14:59:18 +00002666 encode_compound_hdr(xdr, req, &hdr);
2667 encode_sequence(xdr, &args->seq_args, &hdr);
2668 encode_putfh(xdr, args->fhandle, &hdr);
2669 encode_delegreturn(xdr, args->stateid, &hdr);
2670 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002671 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672}
2673
2674/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002675 * Encode FS_LOCATIONS request
2676 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002677static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2678 struct xdr_stream *xdr,
2679 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002680{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002681 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002682 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002683 };
Benny Halevy28f56692009-04-01 09:22:09 -04002684 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002685
Chuck Lever9f06c712010-12-14 14:59:18 +00002686 encode_compound_hdr(xdr, req, &hdr);
2687 encode_sequence(xdr, &args->seq_args, &hdr);
2688 encode_putfh(xdr, args->dir_fh, &hdr);
2689 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002690 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002691 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002692
Benny Halevy28f56692009-04-01 09:22:09 -04002693 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002694 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002695 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002696}
2697
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002698/*
2699 * Encode SECINFO request
2700 */
2701static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2702 struct xdr_stream *xdr,
2703 struct nfs4_secinfo_arg *args)
2704{
2705 struct compound_hdr hdr = {
2706 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2707 };
2708
2709 encode_compound_hdr(xdr, req, &hdr);
2710 encode_sequence(xdr, &args->seq_args, &hdr);
2711 encode_putfh(xdr, args->dir_fh, &hdr);
2712 encode_secinfo(xdr, args->name, &hdr);
2713 encode_nops(&hdr);
2714}
2715
Benny Halevy99fe60d2009-04-01 09:22:29 -04002716#if defined(CONFIG_NFS_V4_1)
2717/*
2718 * EXCHANGE_ID request
2719 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002720static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2721 struct xdr_stream *xdr,
2722 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002723{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002724 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002725 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002726 };
2727
Chuck Lever9f06c712010-12-14 14:59:18 +00002728 encode_compound_hdr(xdr, req, &hdr);
2729 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002730 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002731}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002732
2733/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002734 * a CREATE_SESSION request
2735 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002736static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2737 struct xdr_stream *xdr,
2738 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002739{
Andy Adamsonfc931582009-04-01 09:22:31 -04002740 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002741 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002742 };
2743
Chuck Lever9f06c712010-12-14 14:59:18 +00002744 encode_compound_hdr(xdr, req, &hdr);
2745 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002746 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002747}
2748
2749/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002750 * a DESTROY_SESSION request
2751 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002752static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2753 struct xdr_stream *xdr,
2754 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002755{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002756 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002757 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002758 };
2759
Chuck Lever9f06c712010-12-14 14:59:18 +00002760 encode_compound_hdr(xdr, req, &hdr);
2761 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002762 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002763}
2764
2765/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002766 * a SEQUENCE request
2767 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002768static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2769 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002770{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002771 struct compound_hdr hdr = {
2772 .minorversion = nfs4_xdr_minorversion(args),
2773 };
2774
Chuck Lever9f06c712010-12-14 14:59:18 +00002775 encode_compound_hdr(xdr, req, &hdr);
2776 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002777 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002778}
2779
2780/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002781 * a GET_LEASE_TIME request
2782 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002783static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2784 struct xdr_stream *xdr,
2785 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002786{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002787 struct compound_hdr hdr = {
2788 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2789 };
2790 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2791
Chuck Lever9f06c712010-12-14 14:59:18 +00002792 encode_compound_hdr(xdr, req, &hdr);
2793 encode_sequence(xdr, &args->la_seq_args, &hdr);
2794 encode_putrootfh(xdr, &hdr);
2795 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002796 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002797}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002798
2799/*
2800 * a RECLAIM_COMPLETE request
2801 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002802static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2803 struct xdr_stream *xdr,
2804 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002805{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002806 struct compound_hdr hdr = {
2807 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2808 };
2809
Chuck Lever9f06c712010-12-14 14:59:18 +00002810 encode_compound_hdr(xdr, req, &hdr);
2811 encode_sequence(xdr, &args->seq_args, &hdr);
2812 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002813 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002814}
2815
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002816/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002817 * Encode GETDEVICELIST request
2818 */
2819static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2820 struct xdr_stream *xdr,
2821 struct nfs4_getdevicelist_args *args)
2822{
2823 struct compound_hdr hdr = {
2824 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2825 };
2826
2827 encode_compound_hdr(xdr, req, &hdr);
2828 encode_sequence(xdr, &args->seq_args, &hdr);
2829 encode_putfh(xdr, args->fh, &hdr);
2830 encode_getdevicelist(xdr, args, &hdr);
2831 encode_nops(&hdr);
2832}
2833
2834/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002835 * Encode GETDEVICEINFO request
2836 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002837static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2838 struct xdr_stream *xdr,
2839 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002840{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002841 struct compound_hdr hdr = {
2842 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2843 };
2844
Chuck Lever9f06c712010-12-14 14:59:18 +00002845 encode_compound_hdr(xdr, req, &hdr);
2846 encode_sequence(xdr, &args->seq_args, &hdr);
2847 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002848
2849 /* set up reply kvec. Subtract notification bitmap max size (2)
2850 * so that notification bitmap is put in xdr_buf tail */
2851 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2852 args->pdev->pages, args->pdev->pgbase,
2853 args->pdev->pglen);
2854
2855 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002856}
2857
2858/*
2859 * Encode LAYOUTGET request
2860 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002861static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2862 struct xdr_stream *xdr,
2863 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002864{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002865 struct compound_hdr hdr = {
2866 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2867 };
2868
Chuck Lever9f06c712010-12-14 14:59:18 +00002869 encode_compound_hdr(xdr, req, &hdr);
2870 encode_sequence(xdr, &args->seq_args, &hdr);
2871 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2872 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002873
2874 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2875 args->layout.pages, 0, args->layout.pglen);
2876
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002877 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002878}
Andy Adamson863a3c62011-03-23 13:27:54 +00002879
2880/*
2881 * Encode LAYOUTCOMMIT request
2882 */
Benny Halevycbe82602011-05-22 19:52:37 +03002883static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2884 struct xdr_stream *xdr,
2885 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002886{
Benny Halevyac7db722011-05-22 19:53:48 +03002887 struct nfs4_layoutcommit_data *data =
2888 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002889 struct compound_hdr hdr = {
2890 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2891 };
2892
2893 encode_compound_hdr(xdr, req, &hdr);
2894 encode_sequence(xdr, &args->seq_args, &hdr);
2895 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002896 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002897 encode_getfattr(xdr, args->bitmask, &hdr);
2898 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002899}
2900
2901/*
2902 * Encode LAYOUTRETURN request
2903 */
2904static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2905 struct xdr_stream *xdr,
2906 struct nfs4_layoutreturn_args *args)
2907{
2908 struct compound_hdr hdr = {
2909 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2910 };
2911
2912 encode_compound_hdr(xdr, req, &hdr);
2913 encode_sequence(xdr, &args->seq_args, &hdr);
2914 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2915 encode_layoutreturn(xdr, args, &hdr);
2916 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002917}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002918
2919/*
2920 * Encode SECINFO_NO_NAME request
2921 */
2922static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2923 struct xdr_stream *xdr,
2924 struct nfs41_secinfo_no_name_args *args)
2925{
2926 struct compound_hdr hdr = {
2927 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2928 };
2929
2930 encode_compound_hdr(xdr, req, &hdr);
2931 encode_sequence(xdr, &args->seq_args, &hdr);
2932 encode_putrootfh(xdr, &hdr);
2933 encode_secinfo_no_name(xdr, args, &hdr);
2934 encode_nops(&hdr);
2935 return 0;
2936}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002937
2938/*
2939 * Encode TEST_STATEID request
2940 */
2941static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2942 struct xdr_stream *xdr,
2943 struct nfs41_test_stateid_args *args)
2944{
2945 struct compound_hdr hdr = {
2946 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2947 };
2948
2949 encode_compound_hdr(xdr, req, &hdr);
2950 encode_sequence(xdr, &args->seq_args, &hdr);
2951 encode_test_stateid(xdr, args, &hdr);
2952 encode_nops(&hdr);
2953}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002954
2955/*
2956 * Encode FREE_STATEID request
2957 */
2958static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2959 struct xdr_stream *xdr,
2960 struct nfs41_free_stateid_args *args)
2961{
2962 struct compound_hdr hdr = {
2963 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2964 };
2965
2966 encode_compound_hdr(xdr, req, &hdr);
2967 encode_sequence(xdr, &args->seq_args, &hdr);
2968 encode_free_stateid(xdr, args, &hdr);
2969 encode_nops(&hdr);
2970}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002971#endif /* CONFIG_NFS_V4_1 */
2972
Benny Halevy686841b2009-08-14 17:19:48 +03002973static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2974{
2975 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2976 "Remaining buffer length is %tu words.\n",
2977 func, xdr->end - xdr->p);
2978}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979
Trond Myklebust683b57b2006-06-09 09:34:22 -04002980static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981{
Al Viro8687b632006-10-19 23:28:48 -07002982 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983
Benny Halevyc0eae662009-08-14 17:20:14 +03002984 p = xdr_inline_decode(xdr, 4);
2985 if (unlikely(!p))
2986 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002987 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002988 p = xdr_inline_decode(xdr, *len);
2989 if (unlikely(!p))
2990 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 *string = (char *)p;
2992 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002993out_overflow:
2994 print_overflow_msg(__func__, xdr);
2995 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996}
2997
2998static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2999{
Al Viro8687b632006-10-19 23:28:48 -07003000 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001
Benny Halevyc0eae662009-08-14 17:20:14 +03003002 p = xdr_inline_decode(xdr, 8);
3003 if (unlikely(!p))
3004 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003005 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003006 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003007
Benny Halevyc0eae662009-08-14 17:20:14 +03003008 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3009 if (unlikely(!p))
3010 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 hdr->tag = (char *)p;
3012 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003013 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003014 if (unlikely(hdr->nops < 1))
3015 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003017out_overflow:
3018 print_overflow_msg(__func__, xdr);
3019 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020}
3021
3022static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3023{
Al Viro8687b632006-10-19 23:28:48 -07003024 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 uint32_t opnum;
3026 int32_t nfserr;
3027
Benny Halevyc0eae662009-08-14 17:20:14 +03003028 p = xdr_inline_decode(xdr, 8);
3029 if (unlikely(!p))
3030 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003031 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003033 dprintk("nfs: Server returned operation"
3034 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 opnum, expected);
3036 return -EIO;
3037 }
Benny Halevycccddf42009-08-14 17:20:19 +03003038 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003040 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003042out_overflow:
3043 print_overflow_msg(__func__, xdr);
3044 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045}
3046
3047/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003048static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049{
Al Viro8687b632006-10-19 23:28:48 -07003050 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003051 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 char *str;
3053
Benny Halevyc0eae662009-08-14 17:20:14 +03003054 p = xdr_inline_decode(xdr, 12);
3055 if (likely(p))
3056 return decode_opaque_inline(xdr, &strlen, &str);
3057 print_overflow_msg(__func__, xdr);
3058 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059}
3060
3061static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3062{
Al Viro8687b632006-10-19 23:28:48 -07003063 uint32_t bmlen;
3064 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065
Benny Halevyc0eae662009-08-14 17:20:14 +03003066 p = xdr_inline_decode(xdr, 4);
3067 if (unlikely(!p))
3068 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003069 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070
3071 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003072 p = xdr_inline_decode(xdr, (bmlen << 2));
3073 if (unlikely(!p))
3074 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003076 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03003078 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 }
3080 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003081out_overflow:
3082 print_overflow_msg(__func__, xdr);
3083 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084}
3085
Al Viro8687b632006-10-19 23:28:48 -07003086static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087{
Al Viro8687b632006-10-19 23:28:48 -07003088 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089
Benny Halevyc0eae662009-08-14 17:20:14 +03003090 p = xdr_inline_decode(xdr, 4);
3091 if (unlikely(!p))
3092 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003093 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 *savep = xdr->p;
3095 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003096out_overflow:
3097 print_overflow_msg(__func__, xdr);
3098 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099}
3100
3101static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3102{
3103 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003104 int ret;
3105 ret = decode_attr_bitmap(xdr, bitmask);
3106 if (unlikely(ret < 0))
3107 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3109 } else
3110 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03003111 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 return 0;
3113}
3114
3115static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3116{
Al Viro8687b632006-10-19 23:28:48 -07003117 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003118 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119
3120 *type = 0;
3121 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3122 return -EIO;
3123 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003124 p = xdr_inline_decode(xdr, 4);
3125 if (unlikely(!p))
3126 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003127 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003129 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 return -EIO;
3131 }
3132 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003133 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003135 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003136 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003137out_overflow:
3138 print_overflow_msg(__func__, xdr);
3139 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140}
3141
3142static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3143{
Al Viro8687b632006-10-19 23:28:48 -07003144 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003145 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146
3147 *change = 0;
3148 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3149 return -EIO;
3150 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003151 p = xdr_inline_decode(xdr, 8);
3152 if (unlikely(!p))
3153 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003154 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003156 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003158 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003160 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003161out_overflow:
3162 print_overflow_msg(__func__, xdr);
3163 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164}
3165
3166static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3167{
Al Viro8687b632006-10-19 23:28:48 -07003168 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003169 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170
3171 *size = 0;
3172 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3173 return -EIO;
3174 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003175 p = xdr_inline_decode(xdr, 8);
3176 if (unlikely(!p))
3177 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003178 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003180 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003182 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003183 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003184out_overflow:
3185 print_overflow_msg(__func__, xdr);
3186 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187}
3188
3189static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3190{
Al Viro8687b632006-10-19 23:28:48 -07003191 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192
3193 *res = 0;
3194 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3195 return -EIO;
3196 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003197 p = xdr_inline_decode(xdr, 4);
3198 if (unlikely(!p))
3199 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003200 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3202 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003203 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003205out_overflow:
3206 print_overflow_msg(__func__, xdr);
3207 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208}
3209
3210static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3211{
Al Viro8687b632006-10-19 23:28:48 -07003212 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213
3214 *res = 0;
3215 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3216 return -EIO;
3217 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003218 p = xdr_inline_decode(xdr, 4);
3219 if (unlikely(!p))
3220 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003221 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3223 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003224 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003226out_overflow:
3227 print_overflow_msg(__func__, xdr);
3228 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229}
3230
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003231static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232{
Al Viro8687b632006-10-19 23:28:48 -07003233 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003234 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235
3236 fsid->major = 0;
3237 fsid->minor = 0;
3238 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3239 return -EIO;
3240 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003241 p = xdr_inline_decode(xdr, 16);
3242 if (unlikely(!p))
3243 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003244 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003245 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003247 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003249 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 (unsigned long long)fsid->major,
3251 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003252 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003253out_overflow:
3254 print_overflow_msg(__func__, xdr);
3255 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256}
3257
3258static int decode_attr_lease_time(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 = 60;
3263 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3264 return -EIO;
3265 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
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_LEASE_TIME;
3271 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003272 dprintk("%s: file size=%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
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003279static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003280{
3281 __be32 *p;
3282
3283 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3284 return -EIO;
3285 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3286 p = xdr_inline_decode(xdr, 4);
3287 if (unlikely(!p))
3288 goto out_overflow;
3289 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003290 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003291 }
3292 return 0;
3293out_overflow:
3294 print_overflow_msg(__func__, xdr);
3295 return -EIO;
3296}
3297
3298static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3299{
3300 __be32 *p;
3301 int len;
3302
Trond Myklebust7ad07352010-10-23 15:34:20 -04003303 if (fh != NULL)
3304 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003305
3306 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3307 return -EIO;
3308 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3309 p = xdr_inline_decode(xdr, 4);
3310 if (unlikely(!p))
3311 goto out_overflow;
3312 len = be32_to_cpup(p);
3313 if (len > NFS4_FHSIZE)
3314 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003315 p = xdr_inline_decode(xdr, len);
3316 if (unlikely(!p))
3317 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003318 if (fh != NULL) {
3319 memcpy(fh->data, p, len);
3320 fh->size = len;
3321 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003322 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3323 }
3324 return 0;
3325out_overflow:
3326 print_overflow_msg(__func__, xdr);
3327 return -EIO;
3328}
3329
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3331{
Al Viro8687b632006-10-19 23:28:48 -07003332 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333
3334 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3335 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3336 return -EIO;
3337 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003338 p = xdr_inline_decode(xdr, 4);
3339 if (unlikely(!p))
3340 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003341 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3343 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003344 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003346out_overflow:
3347 print_overflow_msg(__func__, xdr);
3348 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349}
3350
3351static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3352{
Al Viro8687b632006-10-19 23:28:48 -07003353 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003354 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355
3356 *fileid = 0;
3357 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3358 return -EIO;
3359 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003360 p = xdr_inline_decode(xdr, 8);
3361 if (unlikely(!p))
3362 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003363 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003365 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003367 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003368 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003369out_overflow:
3370 print_overflow_msg(__func__, xdr);
3371 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372}
3373
Manoj Naik99baf622006-06-09 09:34:24 -04003374static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3375{
Al Viro8687b632006-10-19 23:28:48 -07003376 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003377 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003378
3379 *fileid = 0;
3380 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3381 return -EIO;
3382 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003383 p = xdr_inline_decode(xdr, 8);
3384 if (unlikely(!p))
3385 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003386 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003387 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003388 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003389 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003390 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003391 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003392out_overflow:
3393 print_overflow_msg(__func__, xdr);
3394 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003395}
3396
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3398{
Al Viro8687b632006-10-19 23:28:48 -07003399 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 int status = 0;
3401
3402 *res = 0;
3403 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3404 return -EIO;
3405 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003406 p = xdr_inline_decode(xdr, 8);
3407 if (unlikely(!p))
3408 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003409 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3411 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003412 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003414out_overflow:
3415 print_overflow_msg(__func__, xdr);
3416 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417}
3418
3419static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3420{
Al Viro8687b632006-10-19 23:28:48 -07003421 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 int status = 0;
3423
3424 *res = 0;
3425 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3426 return -EIO;
3427 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003428 p = xdr_inline_decode(xdr, 8);
3429 if (unlikely(!p))
3430 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003431 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3433 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003434 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003436out_overflow:
3437 print_overflow_msg(__func__, xdr);
3438 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439}
3440
3441static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3442{
Al Viro8687b632006-10-19 23:28:48 -07003443 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 int status = 0;
3445
3446 *res = 0;
3447 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3448 return -EIO;
3449 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003450 p = xdr_inline_decode(xdr, 8);
3451 if (unlikely(!p))
3452 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003453 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3455 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003456 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003458out_overflow:
3459 print_overflow_msg(__func__, xdr);
3460 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461}
3462
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003463static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3464{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003465 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003466 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003467 int status = 0;
3468
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 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003473 if (n == 0)
3474 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003475 dprintk("path ");
3476 path->ncomponents = 0;
3477 while (path->ncomponents < n) {
3478 struct nfs4_string *component = &path->components[path->ncomponents];
3479 status = decode_opaque_inline(xdr, &component->len, &component->data);
3480 if (unlikely(status != 0))
3481 goto out_eio;
3482 if (path->ncomponents != n)
3483 dprintk("/");
3484 dprintk("%s", component->data);
3485 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3486 path->ncomponents++;
3487 else {
3488 dprintk("cannot parse %d components in path\n", n);
3489 goto out_eio;
3490 }
3491 }
3492out:
3493 dprintk("\n");
3494 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003495root_path:
3496/* a root pathname is sent as a zero component4 */
3497 path->ncomponents = 1;
3498 path->components[0].len=0;
3499 path->components[0].data=NULL;
3500 dprintk("path /\n");
3501 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003502out_eio:
3503 dprintk(" status %d", status);
3504 status = -EIO;
3505 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003506out_overflow:
3507 print_overflow_msg(__func__, xdr);
3508 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003509}
3510
3511static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003512{
3513 int n;
Al Viro8687b632006-10-19 23:28:48 -07003514 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003515 int status = -EIO;
3516
3517 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3518 goto out;
3519 status = 0;
3520 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3521 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003522 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003523 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003524 if (unlikely(status != 0))
3525 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003526 p = xdr_inline_decode(xdr, 4);
3527 if (unlikely(!p))
3528 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003529 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003530 if (n <= 0)
3531 goto out_eio;
3532 res->nlocations = 0;
3533 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003534 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003535 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003536
Benny Halevyc0eae662009-08-14 17:20:14 +03003537 p = xdr_inline_decode(xdr, 4);
3538 if (unlikely(!p))
3539 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003540 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003541
3542 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003543 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003544 while (loc->nservers < m) {
3545 struct nfs4_string *server = &loc->servers[loc->nservers];
3546 status = decode_opaque_inline(xdr, &server->len, &server->data);
3547 if (unlikely(status != 0))
3548 goto out_eio;
3549 dprintk("%s ", server->data);
3550 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3551 loc->nservers++;
3552 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003553 unsigned int i;
3554 dprintk("%s: using first %u of %u servers "
3555 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003556 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003557 NFS4_FS_LOCATION_MAXSERVERS,
3558 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003559 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003560 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003561 char *data;
3562 status = decode_opaque_inline(xdr, &len, &data);
3563 if (unlikely(status != 0))
3564 goto out_eio;
3565 }
3566 }
3567 }
3568 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003569 if (unlikely(status != 0))
3570 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003571 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003572 res->nlocations++;
3573 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003574 if (res->nlocations != 0)
3575 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003576out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003577 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003578 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003579out_overflow:
3580 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003581out_eio:
3582 status = -EIO;
3583 goto out;
3584}
3585
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3587{
Al Viro8687b632006-10-19 23:28:48 -07003588 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589 int status = 0;
3590
3591 *res = 0;
3592 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3593 return -EIO;
3594 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003595 p = xdr_inline_decode(xdr, 8);
3596 if (unlikely(!p))
3597 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003598 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3600 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003601 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003603out_overflow:
3604 print_overflow_msg(__func__, xdr);
3605 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606}
3607
3608static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3609{
Al Viro8687b632006-10-19 23:28:48 -07003610 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 int status = 0;
3612
3613 *maxlink = 1;
3614 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3615 return -EIO;
3616 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003617 p = xdr_inline_decode(xdr, 4);
3618 if (unlikely(!p))
3619 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003620 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3622 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003623 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003625out_overflow:
3626 print_overflow_msg(__func__, xdr);
3627 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628}
3629
3630static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3631{
Al Viro8687b632006-10-19 23:28:48 -07003632 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 int status = 0;
3634
3635 *maxname = 1024;
3636 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3637 return -EIO;
3638 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003639 p = xdr_inline_decode(xdr, 4);
3640 if (unlikely(!p))
3641 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003642 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3644 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003645 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003647out_overflow:
3648 print_overflow_msg(__func__, xdr);
3649 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650}
3651
3652static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3653{
Al Viro8687b632006-10-19 23:28:48 -07003654 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655 int status = 0;
3656
3657 *res = 1024;
3658 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3659 return -EIO;
3660 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3661 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003662 p = xdr_inline_decode(xdr, 8);
3663 if (unlikely(!p))
3664 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003665 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666 if (maxread > 0x7FFFFFFF)
3667 maxread = 0x7FFFFFFF;
3668 *res = (uint32_t)maxread;
3669 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3670 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003671 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003673out_overflow:
3674 print_overflow_msg(__func__, xdr);
3675 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676}
3677
3678static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3679{
Al Viro8687b632006-10-19 23:28:48 -07003680 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 int status = 0;
3682
3683 *res = 1024;
3684 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3685 return -EIO;
3686 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3687 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003688 p = xdr_inline_decode(xdr, 8);
3689 if (unlikely(!p))
3690 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003691 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 if (maxwrite > 0x7FFFFFFF)
3693 maxwrite = 0x7FFFFFFF;
3694 *res = (uint32_t)maxwrite;
3695 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3696 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003697 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003699out_overflow:
3700 print_overflow_msg(__func__, xdr);
3701 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702}
3703
Trond Myklebustbca79472009-03-11 14:10:26 -04003704static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705{
Trond Myklebustbca79472009-03-11 14:10:26 -04003706 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003707 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003708 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709
3710 *mode = 0;
3711 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3712 return -EIO;
3713 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003714 p = xdr_inline_decode(xdr, 4);
3715 if (unlikely(!p))
3716 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003717 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003718 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003720 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003722 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003723 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003724out_overflow:
3725 print_overflow_msg(__func__, xdr);
3726 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727}
3728
3729static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3730{
Al Viro8687b632006-10-19 23:28:48 -07003731 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003732 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733
3734 *nlink = 1;
3735 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3736 return -EIO;
3737 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003738 p = xdr_inline_decode(xdr, 4);
3739 if (unlikely(!p))
3740 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003741 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003743 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003745 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003746 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003747out_overflow:
3748 print_overflow_msg(__func__, xdr);
3749 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750}
3751
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003752static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003753 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754{
Al Viro8687b632006-10-19 23:28:48 -07003755 uint32_t len;
3756 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003757 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758
3759 *uid = -2;
3760 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3761 return -EIO;
3762 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003763 p = xdr_inline_decode(xdr, 4);
3764 if (unlikely(!p))
3765 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003766 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003767 p = xdr_inline_decode(xdr, len);
3768 if (unlikely(!p))
3769 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003770 if (!may_sleep) {
3771 /* do nothing */
3772 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003773 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003774 ret = NFS_ATTR_FATTR_OWNER;
3775 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003777 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003779 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003780 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3782 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003783 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003784 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003785out_overflow:
3786 print_overflow_msg(__func__, xdr);
3787 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788}
3789
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003790static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003791 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792{
Al Viro8687b632006-10-19 23:28:48 -07003793 uint32_t len;
3794 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003795 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796
3797 *gid = -2;
3798 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3799 return -EIO;
3800 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003801 p = xdr_inline_decode(xdr, 4);
3802 if (unlikely(!p))
3803 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003804 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003805 p = xdr_inline_decode(xdr, len);
3806 if (unlikely(!p))
3807 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003808 if (!may_sleep) {
3809 /* do nothing */
3810 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003811 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003812 ret = NFS_ATTR_FATTR_GROUP;
3813 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003815 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003817 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003818 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3820 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003821 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003822 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003823out_overflow:
3824 print_overflow_msg(__func__, xdr);
3825 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826}
3827
3828static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3829{
Al Viro8687b632006-10-19 23:28:48 -07003830 uint32_t major = 0, minor = 0;
3831 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003832 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833
3834 *rdev = MKDEV(0,0);
3835 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3836 return -EIO;
3837 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3838 dev_t tmp;
3839
Benny Halevyc0eae662009-08-14 17:20:14 +03003840 p = xdr_inline_decode(xdr, 8);
3841 if (unlikely(!p))
3842 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003843 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003844 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 tmp = MKDEV(major, minor);
3846 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3847 *rdev = tmp;
3848 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003849 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003851 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003852 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003853out_overflow:
3854 print_overflow_msg(__func__, xdr);
3855 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856}
3857
3858static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3859{
Al Viro8687b632006-10-19 23:28:48 -07003860 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 int status = 0;
3862
3863 *res = 0;
3864 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3865 return -EIO;
3866 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003867 p = xdr_inline_decode(xdr, 8);
3868 if (unlikely(!p))
3869 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003870 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3872 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003873 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003875out_overflow:
3876 print_overflow_msg(__func__, xdr);
3877 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878}
3879
3880static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3881{
Al Viro8687b632006-10-19 23:28:48 -07003882 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 int status = 0;
3884
3885 *res = 0;
3886 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3887 return -EIO;
3888 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003889 p = xdr_inline_decode(xdr, 8);
3890 if (unlikely(!p))
3891 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003892 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3894 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003895 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003897out_overflow:
3898 print_overflow_msg(__func__, xdr);
3899 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900}
3901
3902static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3903{
Al Viro8687b632006-10-19 23:28:48 -07003904 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 int status = 0;
3906
3907 *res = 0;
3908 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3909 return -EIO;
3910 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003911 p = xdr_inline_decode(xdr, 8);
3912 if (unlikely(!p))
3913 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003914 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3916 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003917 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003919out_overflow:
3920 print_overflow_msg(__func__, xdr);
3921 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922}
3923
3924static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3925{
Al Viro8687b632006-10-19 23:28:48 -07003926 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003927 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928
3929 *used = 0;
3930 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3931 return -EIO;
3932 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003933 p = xdr_inline_decode(xdr, 8);
3934 if (unlikely(!p))
3935 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003936 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003938 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003940 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003942 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003943out_overflow:
3944 print_overflow_msg(__func__, xdr);
3945 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946}
3947
3948static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3949{
Al Viro8687b632006-10-19 23:28:48 -07003950 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 uint64_t sec;
3952 uint32_t nsec;
3953
Benny Halevyc0eae662009-08-14 17:20:14 +03003954 p = xdr_inline_decode(xdr, 12);
3955 if (unlikely(!p))
3956 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003957 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003958 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959 time->tv_sec = (time_t)sec;
3960 time->tv_nsec = (long)nsec;
3961 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003962out_overflow:
3963 print_overflow_msg(__func__, xdr);
3964 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965}
3966
3967static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3968{
3969 int status = 0;
3970
3971 time->tv_sec = 0;
3972 time->tv_nsec = 0;
3973 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3974 return -EIO;
3975 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3976 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003977 if (status == 0)
3978 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3980 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003981 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 return status;
3983}
3984
3985static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3986{
3987 int status = 0;
3988
3989 time->tv_sec = 0;
3990 time->tv_nsec = 0;
3991 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3992 return -EIO;
3993 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3994 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003995 if (status == 0)
3996 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3998 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003999 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 return status;
4001}
4002
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004003static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4004 struct timespec *time)
4005{
4006 int status = 0;
4007
4008 time->tv_sec = 0;
4009 time->tv_nsec = 0;
4010 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4011 return -EIO;
4012 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4013 status = decode_attr_time(xdr, time);
4014 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4015 }
4016 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4017 (long)time->tv_nsec);
4018 return status;
4019}
4020
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4022{
4023 int status = 0;
4024
4025 time->tv_sec = 0;
4026 time->tv_nsec = 0;
4027 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4028 return -EIO;
4029 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4030 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004031 if (status == 0)
4032 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4034 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004035 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 return status;
4037}
4038
Al Viro8687b632006-10-19 23:28:48 -07004039static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040{
4041 unsigned int attrwords = XDR_QUADLEN(attrlen);
4042 unsigned int nwords = xdr->p - savep;
4043
4044 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004045 dprintk("%s: server returned incorrect attribute length: "
4046 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004047 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 attrwords << 2,
4049 (attrwords < nwords) ? '<' : '>',
4050 nwords << 2);
4051 return -EIO;
4052 }
4053 return 0;
4054}
4055
4056static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4057{
Al Viro8687b632006-10-19 23:28:48 -07004058 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059
Benny Halevyc0eae662009-08-14 17:20:14 +03004060 p = xdr_inline_decode(xdr, 20);
4061 if (unlikely(!p))
4062 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004063 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004064 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004065 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004067out_overflow:
4068 print_overflow_msg(__func__, xdr);
4069 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070}
4071
4072static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4073{
Al Viro8687b632006-10-19 23:28:48 -07004074 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 uint32_t supp, acc;
4076 int status;
4077
4078 status = decode_op_hdr(xdr, OP_ACCESS);
4079 if (status)
4080 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004081 p = xdr_inline_decode(xdr, 8);
4082 if (unlikely(!p))
4083 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004084 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004085 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 access->supported = supp;
4087 access->access = acc;
4088 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004089out_overflow:
4090 print_overflow_msg(__func__, xdr);
4091 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092}
4093
Benny Halevy07d30432009-08-14 17:19:52 +03004094static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095{
Al Viro8687b632006-10-19 23:28:48 -07004096 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004097
4098 p = xdr_inline_decode(xdr, len);
4099 if (likely(p)) {
4100 memcpy(buf, p, len);
4101 return 0;
4102 }
4103 print_overflow_msg(__func__, xdr);
4104 return -EIO;
4105}
4106
4107static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4108{
4109 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110}
4111
4112static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4113{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114 int status;
4115
4116 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004117 if (status != -EIO)
4118 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004119 if (!status)
4120 status = decode_stateid(xdr, &res->stateid);
4121 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122}
4123
Benny Halevydb942bb2009-08-14 17:19:56 +03004124static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4125{
4126 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127}
4128
4129static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4130{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 int status;
4132
4133 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004134 if (!status)
4135 status = decode_verifier(xdr, res->verf->verifier);
4136 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137}
4138
4139static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4140{
Al Viro8687b632006-10-19 23:28:48 -07004141 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 uint32_t bmlen;
4143 int status;
4144
4145 status = decode_op_hdr(xdr, OP_CREATE);
4146 if (status)
4147 return status;
4148 if ((status = decode_change_info(xdr, cinfo)))
4149 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004150 p = xdr_inline_decode(xdr, 4);
4151 if (unlikely(!p))
4152 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004153 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004154 p = xdr_inline_decode(xdr, bmlen << 2);
4155 if (likely(p))
4156 return 0;
4157out_overflow:
4158 print_overflow_msg(__func__, xdr);
4159 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160}
4161
4162static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4163{
Al Viro8687b632006-10-19 23:28:48 -07004164 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004165 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 int status;
4167
4168 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4169 goto xdr_error;
4170 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4171 goto xdr_error;
4172 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4173 goto xdr_error;
4174 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4175 goto xdr_error;
4176 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4177 goto xdr_error;
4178 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4179 goto xdr_error;
4180 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4181 goto xdr_error;
4182 status = verify_attr_len(xdr, savep, attrlen);
4183xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004184 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 return status;
4186}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004187
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4189{
Al Viro8687b632006-10-19 23:28:48 -07004190 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004191 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004193
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4195 goto xdr_error;
4196 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4197 goto xdr_error;
4198 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4199 goto xdr_error;
4200
4201 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4202 goto xdr_error;
4203 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4204 goto xdr_error;
4205 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4206 goto xdr_error;
4207 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4208 goto xdr_error;
4209 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4210 goto xdr_error;
4211 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4212 goto xdr_error;
4213
4214 status = verify_attr_len(xdr, savep, attrlen);
4215xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004216 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 return status;
4218}
4219
4220static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4221{
Al Viro8687b632006-10-19 23:28:48 -07004222 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004223 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004225
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4227 goto xdr_error;
4228 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4229 goto xdr_error;
4230 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4231 goto xdr_error;
4232
4233 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4234 goto xdr_error;
4235 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4236 goto xdr_error;
4237
4238 status = verify_attr_len(xdr, savep, attrlen);
4239xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004240 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241 return status;
4242}
4243
Bryan Schumakerae42c702010-10-21 16:33:17 -04004244static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4245 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004246 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247{
Trond Myklebustbca79472009-03-11 14:10:26 -04004248 int status;
4249 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004250 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004251 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004253 status = decode_attr_type(xdr, bitmap, &type);
4254 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004255 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004256 fattr->mode = 0;
4257 if (status != 0) {
4258 fattr->mode |= nfs_type2fmt[type];
4259 fattr->valid |= status;
4260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004262 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4263 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004265 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004266
4267 status = decode_attr_size(xdr, bitmap, &fattr->size);
4268 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004270 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004271
4272 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4273 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004275 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004276
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004277 err = 0;
4278 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004279 if (status < 0)
4280 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004281 if (err == -NFS4ERR_WRONGSEC)
4282 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004283
4284 status = decode_attr_filehandle(xdr, bitmap, fh);
4285 if (status < 0)
4286 goto xdr_error;
4287
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004288 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4289 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004291 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004292
4293 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04004294 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004295 fattr));
4296 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004297 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004298 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004299
4300 status = decode_attr_mode(xdr, bitmap, &fmode);
4301 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004303 if (status != 0) {
4304 fattr->mode |= fmode;
4305 fattr->valid |= status;
4306 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004307
4308 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4309 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004311 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004312
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004313 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004314 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004316 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004317
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004318 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004319 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004321 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004322
4323 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4324 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004326 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004327
4328 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4329 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004331 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004332
4333 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4334 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004335 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004336 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004337
4338 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4339 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004340 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004341 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004342
4343 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4344 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004346 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004347
Trond Myklebust28331a42011-04-27 13:47:52 -04004348 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004349 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004350 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004351 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004352
Bryan Schumakerae42c702010-10-21 16:33:17 -04004353xdr_error:
4354 dprintk("%s: xdr returned %d\n", __func__, -status);
4355 return status;
4356}
4357
4358static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4359 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4360{
4361 __be32 *savep;
4362 uint32_t attrlen,
4363 bitmap[2] = {0};
4364 int status;
4365
4366 status = decode_op_hdr(xdr, OP_GETATTR);
4367 if (status < 0)
4368 goto xdr_error;
4369
4370 status = decode_attr_bitmap(xdr, bitmap);
4371 if (status < 0)
4372 goto xdr_error;
4373
4374 status = decode_attr_length(xdr, &attrlen, &savep);
4375 if (status < 0)
4376 goto xdr_error;
4377
4378 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4379 if (status < 0)
4380 goto xdr_error;
4381
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004382 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004384 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385 return status;
4386}
4387
Bryan Schumakerae42c702010-10-21 16:33:17 -04004388static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4389 const struct nfs_server *server, int may_sleep)
4390{
4391 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4392}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393
Andy Adamson504913f2010-10-20 00:17:57 -04004394/*
4395 * Decode potentially multiple layout types. Currently we only support
4396 * one layout driver per file system.
4397 */
4398static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4399 uint32_t *layouttype)
4400{
4401 uint32_t *p;
4402 int num;
4403
4404 p = xdr_inline_decode(xdr, 4);
4405 if (unlikely(!p))
4406 goto out_overflow;
4407 num = be32_to_cpup(p);
4408
4409 /* pNFS is not supported by the underlying file system */
4410 if (num == 0) {
4411 *layouttype = 0;
4412 return 0;
4413 }
4414 if (num > 1)
4415 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4416 "per filesystem not supported\n", __func__);
4417
4418 /* Decode and set first layout type, move xdr->p past unused types */
4419 p = xdr_inline_decode(xdr, num * 4);
4420 if (unlikely(!p))
4421 goto out_overflow;
4422 *layouttype = be32_to_cpup(p);
4423 return 0;
4424out_overflow:
4425 print_overflow_msg(__func__, xdr);
4426 return -EIO;
4427}
4428
4429/*
4430 * The type of file system exported.
4431 * Note we must ensure that layouttype is set in any non-error case.
4432 */
4433static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4434 uint32_t *layouttype)
4435{
4436 int status = 0;
4437
4438 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4439 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4440 return -EIO;
4441 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4442 status = decode_first_pnfs_layout_type(xdr, layouttype);
4443 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4444 } else
4445 *layouttype = 0;
4446 return status;
4447}
4448
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4450{
Al Viro8687b632006-10-19 23:28:48 -07004451 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004452 uint32_t attrlen, bitmap[2];
4453 int status;
4454
4455 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4456 goto xdr_error;
4457 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4458 goto xdr_error;
4459 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4460 goto xdr_error;
4461
4462 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4463
4464 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4465 goto xdr_error;
4466 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4467 goto xdr_error;
4468 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4469 goto xdr_error;
4470 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4471 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4472 goto xdr_error;
4473 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004474 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4475 if (status != 0)
4476 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004477 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4478 if (status != 0)
4479 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480
4481 status = verify_attr_len(xdr, savep, attrlen);
4482xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004483 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484 return status;
4485}
4486
4487static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4488{
Al Viro8687b632006-10-19 23:28:48 -07004489 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 uint32_t len;
4491 int status;
4492
Trond Myklebust99367812007-07-17 21:52:41 -04004493 /* Zero handle first to allow comparisons */
4494 memset(fh, 0, sizeof(*fh));
4495
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 status = decode_op_hdr(xdr, OP_GETFH);
4497 if (status)
4498 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499
Benny Halevyc0eae662009-08-14 17:20:14 +03004500 p = xdr_inline_decode(xdr, 4);
4501 if (unlikely(!p))
4502 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004503 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004504 if (len > NFS4_FHSIZE)
4505 return -EIO;
4506 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004507 p = xdr_inline_decode(xdr, len);
4508 if (unlikely(!p))
4509 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004510 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004512out_overflow:
4513 print_overflow_msg(__func__, xdr);
4514 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515}
4516
4517static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4518{
4519 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004520
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 status = decode_op_hdr(xdr, OP_LINK);
4522 if (status)
4523 return status;
4524 return decode_change_info(xdr, cinfo);
4525}
4526
4527/*
4528 * We create the owner, so we know a proper owner.id length is 4.
4529 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004530static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004532 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004533 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004534 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004536 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004537 if (unlikely(!p))
4538 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004539 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004540 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004541 type = be32_to_cpup(p++); /* 4 byte read */
4542 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004543 fl->fl_start = (loff_t)offset;
4544 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4545 if (length == ~(uint64_t)0)
4546 fl->fl_end = OFFSET_MAX;
4547 fl->fl_type = F_WRLCK;
4548 if (type & 1)
4549 fl->fl_type = F_RDLCK;
4550 fl->fl_pid = 0;
4551 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004552 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4553 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4554 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004555 if (likely(p))
4556 return -NFS4ERR_DENIED;
4557out_overflow:
4558 print_overflow_msg(__func__, xdr);
4559 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560}
4561
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004562static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564 int status;
4565
4566 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004567 if (status == -EIO)
4568 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004570 status = decode_stateid(xdr, &res->stateid);
4571 if (unlikely(status))
4572 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004574 status = decode_lock_denied(xdr, NULL);
4575 if (res->open_seqid != NULL)
4576 nfs_increment_open_seqid(status, res->open_seqid);
4577 nfs_increment_lock_seqid(status, res->lock_seqid);
4578out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 return status;
4580}
4581
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004582static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583{
4584 int status;
4585 status = decode_op_hdr(xdr, OP_LOCKT);
4586 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004587 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588 return status;
4589}
4590
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004591static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593 int status;
4594
4595 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004596 if (status != -EIO)
4597 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004598 if (status == 0)
4599 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 return status;
4601}
4602
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004603static int decode_release_lockowner(struct xdr_stream *xdr)
4604{
4605 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4606}
4607
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608static int decode_lookup(struct xdr_stream *xdr)
4609{
4610 return decode_op_hdr(xdr, OP_LOOKUP);
4611}
4612
4613/* This is too sick! */
4614static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4615{
Andy Adamson05d564f2008-12-23 16:06:15 -05004616 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617 uint32_t limit_type, nblocks, blocksize;
4618
Benny Halevyc0eae662009-08-14 17:20:14 +03004619 p = xdr_inline_decode(xdr, 12);
4620 if (unlikely(!p))
4621 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004622 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004624 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004625 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004626 break;
4627 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004628 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004629 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004630 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 }
4632 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004633out_overflow:
4634 print_overflow_msg(__func__, xdr);
4635 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636}
4637
4638static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4639{
Andy Adamson05d564f2008-12-23 16:06:15 -05004640 __be32 *p;
4641 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004642 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004643
Benny Halevyc0eae662009-08-14 17:20:14 +03004644 p = xdr_inline_decode(xdr, 4);
4645 if (unlikely(!p))
4646 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004647 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4649 res->delegation_type = 0;
4650 return 0;
4651 }
Benny Halevy07d30432009-08-14 17:19:52 +03004652 status = decode_stateid(xdr, &res->delegation);
4653 if (unlikely(status))
4654 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004655 p = xdr_inline_decode(xdr, 4);
4656 if (unlikely(!p))
4657 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004658 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004659
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004661 case NFS4_OPEN_DELEGATE_READ:
4662 res->delegation_type = FMODE_READ;
4663 break;
4664 case NFS4_OPEN_DELEGATE_WRITE:
4665 res->delegation_type = FMODE_WRITE|FMODE_READ;
4666 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004667 return -EIO;
4668 }
David Howells7539bba2006-08-22 20:06:09 -04004669 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004670out_overflow:
4671 print_overflow_msg(__func__, xdr);
4672 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673}
4674
4675static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4676{
Andy Adamson05d564f2008-12-23 16:06:15 -05004677 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004678 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004679 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004680
Andy Adamson05d564f2008-12-23 16:06:15 -05004681 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004682 if (status != -EIO)
4683 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004684 if (!status)
4685 status = decode_stateid(xdr, &res->stateid);
4686 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004687 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004688
Andy Adamson05d564f2008-12-23 16:06:15 -05004689 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690
Benny Halevyc0eae662009-08-14 17:20:14 +03004691 p = xdr_inline_decode(xdr, 8);
4692 if (unlikely(!p))
4693 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004694 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004695 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004696 if (bmlen > 10)
4697 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698
Benny Halevyc0eae662009-08-14 17:20:14 +03004699 p = xdr_inline_decode(xdr, bmlen << 2);
4700 if (unlikely(!p))
4701 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004702 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4703 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004704 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004705 for (; i < NFS4_BITMAP_SIZE; i++)
4706 res->attrset[i] = 0;
4707
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708 return decode_delegation(xdr, res);
4709xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004710 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004712out_overflow:
4713 print_overflow_msg(__func__, xdr);
4714 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715}
4716
4717static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4718{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719 int status;
4720
Andy Adamson05d564f2008-12-23 16:06:15 -05004721 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004722 if (status != -EIO)
4723 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004724 if (!status)
4725 status = decode_stateid(xdr, &res->stateid);
4726 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727}
4728
4729static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4730{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731 int status;
4732
4733 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004734 if (status != -EIO)
4735 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004736 if (!status)
4737 status = decode_stateid(xdr, &res->stateid);
4738 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739}
4740
4741static int decode_putfh(struct xdr_stream *xdr)
4742{
4743 return decode_op_hdr(xdr, OP_PUTFH);
4744}
4745
4746static int decode_putrootfh(struct xdr_stream *xdr)
4747{
4748 return decode_op_hdr(xdr, OP_PUTROOTFH);
4749}
4750
4751static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4752{
4753 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004754 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755 uint32_t count, eof, recvd, hdrlen;
4756 int status;
4757
4758 status = decode_op_hdr(xdr, OP_READ);
4759 if (status)
4760 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004761 p = xdr_inline_decode(xdr, 8);
4762 if (unlikely(!p))
4763 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004764 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004765 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004766 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 recvd = req->rq_rcv_buf.len - hdrlen;
4768 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004769 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 "count %u > recvd %u\n", count, recvd);
4771 count = recvd;
4772 eof = 0;
4773 }
4774 xdr_read_pages(xdr, count);
4775 res->eof = eof;
4776 res->count = count;
4777 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004778out_overflow:
4779 print_overflow_msg(__func__, xdr);
4780 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781}
4782
4783static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4784{
4785 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004787 size_t hdrlen;
4788 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004789 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790
4791 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004792 if (!status)
4793 status = decode_verifier(xdr, readdir->verifier.data);
4794 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004796 dprintk("%s: verifier = %08x:%08x\n",
4797 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004798 ((u32 *)readdir->verifier.data)[0],
4799 ((u32 *)readdir->verifier.data)[1]);
4800
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801
Benny Halevydb942bb2009-08-14 17:19:56 +03004802 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803 recvd = rcvbuf->len - hdrlen;
4804 if (pglen > recvd)
4805 pglen = recvd;
4806 xdr_read_pages(xdr, pglen);
4807
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004808
Trond Myklebustac396122010-11-15 20:26:22 -05004809 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810}
4811
4812static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4813{
4814 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4815 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004816 size_t hdrlen;
4817 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004818 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819 int status;
4820
4821 status = decode_op_hdr(xdr, OP_READLINK);
4822 if (status)
4823 return status;
4824
4825 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004826 p = xdr_inline_decode(xdr, 4);
4827 if (unlikely(!p))
4828 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004829 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004831 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832 return -ENAMETOOLONG;
4833 }
4834 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4835 recvd = req->rq_rcv_buf.len - hdrlen;
4836 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004837 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838 "count %u > recvd %u\n", len, recvd);
4839 return -EIO;
4840 }
4841 xdr_read_pages(xdr, len);
4842 /*
4843 * The XDR encode routine has set things up so that
4844 * the link text will be copied directly into the
4845 * buffer. We just have to do overflow-checking,
4846 * and and null-terminate the text (the VFS expects
4847 * null-termination).
4848 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004849 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004851out_overflow:
4852 print_overflow_msg(__func__, xdr);
4853 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854}
4855
4856static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4857{
4858 int status;
4859
4860 status = decode_op_hdr(xdr, OP_REMOVE);
4861 if (status)
4862 goto out;
4863 status = decode_change_info(xdr, cinfo);
4864out:
4865 return status;
4866}
4867
4868static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4869 struct nfs4_change_info *new_cinfo)
4870{
4871 int status;
4872
4873 status = decode_op_hdr(xdr, OP_RENAME);
4874 if (status)
4875 goto out;
4876 if ((status = decode_change_info(xdr, old_cinfo)))
4877 goto out;
4878 status = decode_change_info(xdr, new_cinfo);
4879out:
4880 return status;
4881}
4882
4883static int decode_renew(struct xdr_stream *xdr)
4884{
4885 return decode_op_hdr(xdr, OP_RENEW);
4886}
4887
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004888static int
4889decode_restorefh(struct xdr_stream *xdr)
4890{
4891 return decode_op_hdr(xdr, OP_RESTOREFH);
4892}
4893
J. Bruce Fields029d1052005-06-22 17:16:22 +00004894static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4895 size_t *acl_len)
4896{
Al Viro8687b632006-10-19 23:28:48 -07004897 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004898 uint32_t attrlen,
4899 bitmap[2] = {0};
4900 struct kvec *iov = req->rq_rcv_buf.head;
4901 int status;
4902
4903 *acl_len = 0;
4904 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4905 goto out;
4906 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4907 goto out;
4908 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4909 goto out;
4910
4911 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4912 return -EIO;
4913 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004914 size_t hdrlen;
4915 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004916
4917 /* We ignore &savep and don't do consistency checks on
4918 * the attr length. Let userspace figure it out.... */
4919 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4920 recvd = req->rq_rcv_buf.len - hdrlen;
4921 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004922 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004923 " acl reply: attrlen %u > recvd %u\n",
4924 attrlen, recvd);
4925 return -EINVAL;
4926 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004927 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004928 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004929 } else
4930 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004931
4932out:
4933 return status;
4934}
4935
Linus Torvalds1da177e2005-04-16 15:20:36 -07004936static int
4937decode_savefh(struct xdr_stream *xdr)
4938{
4939 return decode_op_hdr(xdr, OP_SAVEFH);
4940}
4941
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004942static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943{
Al Viro8687b632006-10-19 23:28:48 -07004944 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945 uint32_t bmlen;
4946 int status;
4947
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948 status = decode_op_hdr(xdr, OP_SETATTR);
4949 if (status)
4950 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004951 p = xdr_inline_decode(xdr, 4);
4952 if (unlikely(!p))
4953 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004954 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004955 p = xdr_inline_decode(xdr, bmlen << 2);
4956 if (likely(p))
4957 return 0;
4958out_overflow:
4959 print_overflow_msg(__func__, xdr);
4960 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961}
4962
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004963static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964{
Al Viro8687b632006-10-19 23:28:48 -07004965 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966 uint32_t opnum;
4967 int32_t nfserr;
4968
Benny Halevyc0eae662009-08-14 17:20:14 +03004969 p = xdr_inline_decode(xdr, 8);
4970 if (unlikely(!p))
4971 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004972 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004974 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004975 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976 return -EIO;
4977 }
Benny Halevycccddf42009-08-14 17:20:19 +03004978 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004980 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4981 if (unlikely(!p))
4982 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004983 p = xdr_decode_hyper(p, &res->clientid);
4984 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 } else if (nfserr == NFSERR_CLID_INUSE) {
4986 uint32_t len;
4987
4988 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004989 p = xdr_inline_decode(xdr, 4);
4990 if (unlikely(!p))
4991 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004992 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004993 p = xdr_inline_decode(xdr, len);
4994 if (unlikely(!p))
4995 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996
4997 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004998 p = xdr_inline_decode(xdr, 4);
4999 if (unlikely(!p))
5000 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005001 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005002 p = xdr_inline_decode(xdr, len);
5003 if (unlikely(!p))
5004 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005005 return -NFSERR_CLID_INUSE;
5006 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005007 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008
5009 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005010out_overflow:
5011 print_overflow_msg(__func__, xdr);
5012 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013}
5014
5015static int decode_setclientid_confirm(struct xdr_stream *xdr)
5016{
5017 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5018}
5019
5020static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5021{
Al Viro8687b632006-10-19 23:28:48 -07005022 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023 int status;
5024
5025 status = decode_op_hdr(xdr, OP_WRITE);
5026 if (status)
5027 return status;
5028
Benny Halevyc0eae662009-08-14 17:20:14 +03005029 p = xdr_inline_decode(xdr, 16);
5030 if (unlikely(!p))
5031 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005032 res->count = be32_to_cpup(p++);
5033 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03005034 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005036out_overflow:
5037 print_overflow_msg(__func__, xdr);
5038 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039}
5040
5041static int decode_delegreturn(struct xdr_stream *xdr)
5042{
5043 return decode_op_hdr(xdr, OP_DELEGRETURN);
5044}
5045
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005046static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5047{
5048 __be32 *p;
5049
5050 p = xdr_inline_decode(xdr, 4);
5051 if (unlikely(!p))
5052 goto out_overflow;
5053 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5054 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5055 goto out_err;
5056
5057 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5058 if (unlikely(!p))
5059 goto out_overflow;
5060 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5061
5062 p = xdr_inline_decode(xdr, 8);
5063 if (unlikely(!p))
5064 goto out_overflow;
5065 flavor->gss.qop4 = be32_to_cpup(p++);
5066 flavor->gss.service = be32_to_cpup(p);
5067
5068 return 0;
5069
5070out_overflow:
5071 print_overflow_msg(__func__, xdr);
5072 return -EIO;
5073out_err:
5074 return -EINVAL;
5075}
5076
5077static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5078{
5079 struct nfs4_secinfo_flavor *sec_flavor;
5080 int status;
5081 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005082 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005083
5084 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005085 if (status)
5086 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005087 p = xdr_inline_decode(xdr, 4);
5088 if (unlikely(!p))
5089 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005090
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005091 res->flavors->num_flavors = 0;
5092 num_flavors = be32_to_cpup(p);
5093
5094 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005095 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005096 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005097 break;
5098
5099 p = xdr_inline_decode(xdr, 4);
5100 if (unlikely(!p))
5101 goto out_overflow;
5102 sec_flavor->flavor = be32_to_cpup(p);
5103
5104 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005105 status = decode_secinfo_gss(xdr, sec_flavor);
5106 if (status)
5107 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005108 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005109 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005110 }
5111
Bryan Schumaker613e9012011-04-27 15:28:44 -04005112out:
5113 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005114out_overflow:
5115 print_overflow_msg(__func__, xdr);
5116 return -EIO;
5117}
5118
Benny Halevy99fe60d2009-04-01 09:22:29 -04005119#if defined(CONFIG_NFS_V4_1)
5120static int decode_exchange_id(struct xdr_stream *xdr,
5121 struct nfs41_exchange_id_res *res)
5122{
5123 __be32 *p;
5124 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005125 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005126 int status;
5127 struct nfs_client *clp = res->client;
5128
5129 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5130 if (status)
5131 return status;
5132
Benny Halevyc0eae662009-08-14 17:20:14 +03005133 p = xdr_inline_decode(xdr, 8);
5134 if (unlikely(!p))
5135 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005136 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005137 p = xdr_inline_decode(xdr, 12);
5138 if (unlikely(!p))
5139 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005140 clp->cl_seqid = be32_to_cpup(p++);
5141 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005142
5143 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005144 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005145 if (dummy != SP4_NONE)
5146 return -EIO;
5147
5148 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005149 p = xdr_inline_decode(xdr, 8);
5150 if (unlikely(!p))
5151 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005152
5153 /* Throw away 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;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005157
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005158 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005159 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5160 if (unlikely(status))
5161 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005162
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005163 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5164 return -EIO;
5165
5166 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5167 res->server_scope->server_scope_sz = dummy;
5168
Benny Halevy99fe60d2009-04-01 09:22:29 -04005169 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03005170 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5171 if (unlikely(status))
5172 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005173
5174 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005175out_overflow:
5176 print_overflow_msg(__func__, xdr);
5177 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005178}
Andy Adamsonfc931582009-04-01 09:22:31 -04005179
5180static int decode_chan_attrs(struct xdr_stream *xdr,
5181 struct nfs4_channel_attrs *attrs)
5182{
5183 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005184 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005185
Benny Halevyc0eae662009-08-14 17:20:14 +03005186 p = xdr_inline_decode(xdr, 28);
5187 if (unlikely(!p))
5188 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005189 val = be32_to_cpup(p++); /* headerpadsz */
5190 if (val)
5191 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005192 attrs->max_rqst_sz = be32_to_cpup(p++);
5193 attrs->max_resp_sz = be32_to_cpup(p++);
5194 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5195 attrs->max_ops = be32_to_cpup(p++);
5196 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005197 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005198 if (unlikely(nr_attrs > 1)) {
5199 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
5200 __func__, nr_attrs);
5201 return -EINVAL;
5202 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005203 if (nr_attrs == 1) {
5204 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5205 if (unlikely(!p))
5206 goto out_overflow;
5207 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005208 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005209out_overflow:
5210 print_overflow_msg(__func__, xdr);
5211 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005212}
5213
Benny Halevye78291e2009-08-14 17:20:00 +03005214static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5215{
5216 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005217}
5218
5219static int decode_create_session(struct xdr_stream *xdr,
5220 struct nfs41_create_session_res *res)
5221{
5222 __be32 *p;
5223 int status;
5224 struct nfs_client *clp = res->client;
5225 struct nfs4_session *session = clp->cl_session;
5226
5227 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005228 if (!status)
5229 status = decode_sessionid(xdr, &session->sess_id);
5230 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005231 return status;
5232
Andy Adamsonfc931582009-04-01 09:22:31 -04005233 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005234 p = xdr_inline_decode(xdr, 8);
5235 if (unlikely(!p))
5236 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005237 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005238 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005239
5240 /* Channel attributes */
5241 status = decode_chan_attrs(xdr, &session->fc_attrs);
5242 if (!status)
5243 status = decode_chan_attrs(xdr, &session->bc_attrs);
5244 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005245out_overflow:
5246 print_overflow_msg(__func__, xdr);
5247 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005248}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005249
5250static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5251{
5252 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5253}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005254
5255static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5256{
5257 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5258}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005259#endif /* CONFIG_NFS_V4_1 */
5260
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005261static int decode_sequence(struct xdr_stream *xdr,
5262 struct nfs4_sequence_res *res,
5263 struct rpc_rqst *rqstp)
5264{
5265#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005266 struct nfs4_sessionid id;
5267 u32 dummy;
5268 int status;
5269 __be32 *p;
5270
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005271 if (!res->sr_session)
5272 return 0;
5273
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005274 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005275 if (!status)
5276 status = decode_sessionid(xdr, &id);
5277 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005278 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005279
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005280 /*
5281 * If the server returns different values for sessionID, slotID or
5282 * sequence number, the server is looney tunes.
5283 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005284 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005285
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005286 if (memcmp(id.data, res->sr_session->sess_id.data,
5287 NFS4_MAX_SESSIONID_LEN)) {
5288 dprintk("%s Invalid session id\n", __func__);
5289 goto out_err;
5290 }
Benny Halevye78291e2009-08-14 17:20:00 +03005291
Benny Halevyc0eae662009-08-14 17:20:14 +03005292 p = xdr_inline_decode(xdr, 20);
5293 if (unlikely(!p))
5294 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005295
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005296 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005297 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005298 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005299 dprintk("%s Invalid sequence number\n", __func__);
5300 goto out_err;
5301 }
5302 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005303 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005304 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005305 dprintk("%s Invalid slot id\n", __func__);
5306 goto out_err;
5307 }
5308 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005309 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005310 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005311 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005312 /* result flags */
5313 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005314 status = 0;
5315out_err:
5316 res->sr_status = status;
5317 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005318out_overflow:
5319 print_overflow_msg(__func__, xdr);
5320 status = -EIO;
5321 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005322#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005323 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005324#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005325}
5326
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005327#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005328/*
5329 * TODO: Need to handle case when EOF != true;
5330 */
5331static int decode_getdevicelist(struct xdr_stream *xdr,
5332 struct pnfs_devicelist *res)
5333{
5334 __be32 *p;
5335 int status, i;
5336 struct nfs_writeverf verftemp;
5337
5338 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5339 if (status)
5340 return status;
5341
5342 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5343 if (unlikely(!p))
5344 goto out_overflow;
5345
5346 /* TODO: Skip cookie for now */
5347 p += 2;
5348
5349 /* Read verifier */
5350 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5351
5352 res->num_devs = be32_to_cpup(p);
5353
5354 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5355
5356 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5357 printk(KERN_ERR "%s too many result dev_num %u\n",
5358 __func__, res->num_devs);
5359 return -EIO;
5360 }
5361
5362 p = xdr_inline_decode(xdr,
5363 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5364 if (unlikely(!p))
5365 goto out_overflow;
5366 for (i = 0; i < res->num_devs; i++)
5367 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5368 NFS4_DEVICEID4_SIZE);
5369 res->eof = be32_to_cpup(p);
5370 return 0;
5371out_overflow:
5372 print_overflow_msg(__func__, xdr);
5373 return -EIO;
5374}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005375
5376static int decode_getdeviceinfo(struct xdr_stream *xdr,
5377 struct pnfs_device *pdev)
5378{
5379 __be32 *p;
5380 uint32_t len, type;
5381 int status;
5382
5383 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5384 if (status) {
5385 if (status == -ETOOSMALL) {
5386 p = xdr_inline_decode(xdr, 4);
5387 if (unlikely(!p))
5388 goto out_overflow;
5389 pdev->mincount = be32_to_cpup(p);
5390 dprintk("%s: Min count too small. mincnt = %u\n",
5391 __func__, pdev->mincount);
5392 }
5393 return status;
5394 }
5395
5396 p = xdr_inline_decode(xdr, 8);
5397 if (unlikely(!p))
5398 goto out_overflow;
5399 type = be32_to_cpup(p++);
5400 if (type != pdev->layout_type) {
5401 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5402 __func__, pdev->layout_type, type);
5403 return -EINVAL;
5404 }
5405 /*
5406 * Get the length of the opaque device_addr4. xdr_read_pages places
5407 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5408 * and places the remaining xdr data in xdr_buf->tail
5409 */
5410 pdev->mincount = be32_to_cpup(p);
5411 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5412
5413 /* Parse notification bitmap, verifying that it is zero. */
5414 p = xdr_inline_decode(xdr, 4);
5415 if (unlikely(!p))
5416 goto out_overflow;
5417 len = be32_to_cpup(p);
5418 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005419 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005420
5421 p = xdr_inline_decode(xdr, 4 * len);
5422 if (unlikely(!p))
5423 goto out_overflow;
5424 for (i = 0; i < len; i++, p++) {
5425 if (be32_to_cpup(p)) {
5426 dprintk("%s: notifications not supported\n",
5427 __func__);
5428 return -EIO;
5429 }
5430 }
5431 }
5432 return 0;
5433out_overflow:
5434 print_overflow_msg(__func__, xdr);
5435 return -EIO;
5436}
5437
5438static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5439 struct nfs4_layoutget_res *res)
5440{
5441 __be32 *p;
5442 int status;
5443 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005444 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5445 struct kvec *iov = rcvbuf->head;
5446 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005447
5448 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5449 if (status)
5450 return status;
5451 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5452 if (unlikely(!p))
5453 goto out_overflow;
5454 res->return_on_close = be32_to_cpup(p++);
5455 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5456 layout_count = be32_to_cpup(p);
5457 if (!layout_count) {
5458 dprintk("%s: server responded with empty layout array\n",
5459 __func__);
5460 return -EINVAL;
5461 }
5462
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005463 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005464 if (unlikely(!p))
5465 goto out_overflow;
5466 p = xdr_decode_hyper(p, &res->range.offset);
5467 p = xdr_decode_hyper(p, &res->range.length);
5468 res->range.iomode = be32_to_cpup(p++);
5469 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005470 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005471
5472 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5473 __func__,
5474 (unsigned long)res->range.offset,
5475 (unsigned long)res->range.length,
5476 res->range.iomode,
5477 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005478 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005479
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005480 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5481 recvd = req->rq_rcv_buf.len - hdrlen;
5482 if (res->layoutp->len > recvd) {
5483 dprintk("NFS: server cheating in layoutget reply: "
5484 "layout len %u > recvd %u\n",
5485 res->layoutp->len, recvd);
5486 return -EINVAL;
5487 }
5488
5489 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005490
5491 if (layout_count > 1) {
5492 /* We only handle a length one array at the moment. Any
5493 * further entries are just ignored. Note that this means
5494 * the client may see a response that is less than the
5495 * minimum it requested.
5496 */
5497 dprintk("%s: server responded with %d layouts, dropping tail\n",
5498 __func__, layout_count);
5499 }
5500
5501 return 0;
5502out_overflow:
5503 print_overflow_msg(__func__, xdr);
5504 return -EIO;
5505}
Andy Adamson863a3c62011-03-23 13:27:54 +00005506
Benny Halevycbe82602011-05-22 19:52:37 +03005507static int decode_layoutreturn(struct xdr_stream *xdr,
5508 struct nfs4_layoutreturn_res *res)
5509{
5510 __be32 *p;
5511 int status;
5512
5513 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5514 if (status)
5515 return status;
5516 p = xdr_inline_decode(xdr, 4);
5517 if (unlikely(!p))
5518 goto out_overflow;
5519 res->lrs_present = be32_to_cpup(p);
5520 if (res->lrs_present)
5521 status = decode_stateid(xdr, &res->stateid);
5522 return status;
5523out_overflow:
5524 print_overflow_msg(__func__, xdr);
5525 return -EIO;
5526}
5527
Andy Adamson863a3c62011-03-23 13:27:54 +00005528static int decode_layoutcommit(struct xdr_stream *xdr,
5529 struct rpc_rqst *req,
5530 struct nfs4_layoutcommit_res *res)
5531{
5532 __be32 *p;
5533 __u32 sizechanged;
5534 int status;
5535
5536 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5537 if (status)
5538 return status;
5539
5540 p = xdr_inline_decode(xdr, 4);
5541 if (unlikely(!p))
5542 goto out_overflow;
5543 sizechanged = be32_to_cpup(p);
5544
5545 if (sizechanged) {
5546 /* throw away new size */
5547 p = xdr_inline_decode(xdr, 8);
5548 if (unlikely(!p))
5549 goto out_overflow;
5550 }
5551 return 0;
5552out_overflow:
5553 print_overflow_msg(__func__, xdr);
5554 return -EIO;
5555}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005556
5557static int decode_test_stateid(struct xdr_stream *xdr,
5558 struct nfs41_test_stateid_res *res)
5559{
5560 __be32 *p;
5561 int status;
5562 int num_res;
5563
5564 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5565 if (status)
5566 return status;
5567
5568 p = xdr_inline_decode(xdr, 4);
5569 if (unlikely(!p))
5570 goto out_overflow;
5571 num_res = be32_to_cpup(p++);
5572 if (num_res != 1)
5573 goto out;
5574
5575 p = xdr_inline_decode(xdr, 4);
5576 if (unlikely(!p))
5577 goto out_overflow;
5578 res->status = be32_to_cpup(p++);
5579 return res->status;
5580out_overflow:
5581 print_overflow_msg(__func__, xdr);
5582out:
5583 return -EIO;
5584}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005585
5586static int decode_free_stateid(struct xdr_stream *xdr,
5587 struct nfs41_free_stateid_res *res)
5588{
5589 __be32 *p;
5590 int status;
5591
5592 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5593 if (status)
5594 return status;
5595
5596 p = xdr_inline_decode(xdr, 4);
5597 if (unlikely(!p))
5598 goto out_overflow;
5599 res->status = be32_to_cpup(p++);
5600 return res->status;
5601out_overflow:
5602 print_overflow_msg(__func__, xdr);
5603 return -EIO;
5604}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005605#endif /* CONFIG_NFS_V4_1 */
5606
Linus Torvalds1da177e2005-04-16 15:20:36 -07005607/*
Benny Halevy49c25592008-12-23 16:06:16 -05005608 * END OF "GENERIC" DECODE ROUTINES.
5609 */
5610
5611/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005612 * Decode OPEN_DOWNGRADE response
5613 */
Chuck Leverbf269552010-12-14 14:59:29 +00005614static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5615 struct xdr_stream *xdr,
5616 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005617{
Andy Adamson05d564f2008-12-23 16:06:15 -05005618 struct compound_hdr hdr;
5619 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005620
Chuck Leverbf269552010-12-14 14:59:29 +00005621 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005622 if (status)
5623 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005624 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005625 if (status)
5626 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005627 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005628 if (status)
5629 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005630 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005631 if (status != 0)
5632 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005633 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005634 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005635out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005636 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005637}
5638
5639/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005640 * Decode ACCESS response
5641 */
Chuck Leverbf269552010-12-14 14:59:29 +00005642static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5643 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005644{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005645 struct compound_hdr hdr;
5646 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005647
Chuck Leverbf269552010-12-14 14:59:29 +00005648 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005649 if (status)
5650 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005651 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005652 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005653 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005654 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005655 if (status != 0)
5656 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005657 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005658 if (status != 0)
5659 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005660 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005661 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005662out:
5663 return status;
5664}
5665
5666/*
5667 * Decode LOOKUP response
5668 */
Chuck Leverbf269552010-12-14 14:59:29 +00005669static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5670 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005671{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005672 struct compound_hdr hdr;
5673 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005674
Chuck Leverbf269552010-12-14 14:59:29 +00005675 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005676 if (status)
5677 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005678 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005679 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005680 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005681 status = decode_putfh(xdr);
5682 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005683 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005684 status = decode_lookup(xdr);
5685 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005687 status = decode_getfh(xdr, res->fh);
5688 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005689 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005690 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005691 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692out:
5693 return status;
5694}
5695
5696/*
5697 * Decode LOOKUP_ROOT response
5698 */
Chuck Leverbf269552010-12-14 14:59:29 +00005699static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5700 struct xdr_stream *xdr,
5701 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005702{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005703 struct compound_hdr hdr;
5704 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005705
Chuck Leverbf269552010-12-14 14:59:29 +00005706 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005707 if (status)
5708 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005709 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005710 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005711 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005712 status = decode_putrootfh(xdr);
5713 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005714 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005715 status = decode_getfh(xdr, res->fh);
5716 if (status == 0)
5717 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005718 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005719out:
5720 return status;
5721}
5722
5723/*
5724 * Decode REMOVE response
5725 */
Chuck Leverbf269552010-12-14 14:59:29 +00005726static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5727 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005728{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005729 struct compound_hdr hdr;
5730 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005731
Chuck Leverbf269552010-12-14 14:59:29 +00005732 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005733 if (status)
5734 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005735 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005736 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005738 status = decode_putfh(xdr);
5739 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005740 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005741 status = decode_remove(xdr, &res->cinfo);
5742 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005743 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005744 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005745 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005746out:
5747 return status;
5748}
5749
5750/*
5751 * Decode RENAME response
5752 */
Chuck Leverbf269552010-12-14 14:59:29 +00005753static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5754 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005756 struct compound_hdr hdr;
5757 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005758
Chuck Leverbf269552010-12-14 14:59:29 +00005759 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005760 if (status)
5761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005762 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005763 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005764 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005765 status = decode_putfh(xdr);
5766 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005768 status = decode_savefh(xdr);
5769 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005770 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005771 status = decode_putfh(xdr);
5772 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005773 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005774 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5775 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005776 goto out;
5777 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005778 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005779 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005780 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005781 status = decode_restorefh(xdr);
5782 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005783 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005784 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005785 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005786out:
5787 return status;
5788}
5789
5790/*
5791 * Decode LINK response
5792 */
Chuck Leverbf269552010-12-14 14:59:29 +00005793static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5794 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005795{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005796 struct compound_hdr hdr;
5797 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005798
Chuck Leverbf269552010-12-14 14:59:29 +00005799 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005800 if (status)
5801 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005802 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005803 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005804 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005805 status = decode_putfh(xdr);
5806 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005807 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005808 status = decode_savefh(xdr);
5809 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005810 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005811 status = decode_putfh(xdr);
5812 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005814 status = decode_link(xdr, &res->cinfo);
5815 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005816 goto out;
5817 /*
5818 * Note order: OP_LINK leaves the directory as the current
5819 * filehandle.
5820 */
Chuck Leverbf269552010-12-14 14:59:29 +00005821 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005822 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005823 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005824 status = decode_restorefh(xdr);
5825 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005826 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005827 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005828 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829out:
5830 return status;
5831}
5832
5833/*
5834 * Decode CREATE response
5835 */
Chuck Leverbf269552010-12-14 14:59:29 +00005836static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5837 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005838{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839 struct compound_hdr hdr;
5840 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005841
Chuck Leverbf269552010-12-14 14:59:29 +00005842 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005843 if (status)
5844 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005845 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005846 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005847 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005848 status = decode_putfh(xdr);
5849 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005851 status = decode_savefh(xdr);
5852 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005853 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005854 status = decode_create(xdr, &res->dir_cinfo);
5855 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005856 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005857 status = decode_getfh(xdr, res->fh);
5858 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005860 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005861 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005862 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005863 status = decode_restorefh(xdr);
5864 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005865 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005866 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005867 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868out:
5869 return status;
5870}
5871
5872/*
5873 * Decode SYMLINK response
5874 */
Chuck Leverbf269552010-12-14 14:59:29 +00005875static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5876 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877{
Chuck Leverbf269552010-12-14 14:59:29 +00005878 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879}
5880
5881/*
5882 * Decode GETATTR response
5883 */
Chuck Leverbf269552010-12-14 14:59:29 +00005884static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5885 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005886{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005887 struct compound_hdr hdr;
5888 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005889
Chuck Leverbf269552010-12-14 14:59:29 +00005890 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891 if (status)
5892 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005893 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005894 if (status)
5895 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005896 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005897 if (status)
5898 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005899 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005900 !RPC_IS_ASYNC(rqstp->rq_task));
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
Chuck Leverbf269552010-12-14 14:59:29 +00005956 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005957 if (status)
5958 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005959 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005960 if (status)
5961 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005962 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005963 if (status)
5964 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005965 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005966
5967out:
5968 return status;
5969}
5970
5971/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972 * Decode CLOSE response
5973 */
Chuck Leverbf269552010-12-14 14:59:29 +00005974static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5975 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976{
Andy Adamson05d564f2008-12-23 16:06:15 -05005977 struct compound_hdr hdr;
5978 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979
Chuck Leverbf269552010-12-14 14:59:29 +00005980 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005981 if (status)
5982 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005983 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005984 if (status)
5985 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005986 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005987 if (status)
5988 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005989 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005990 if (status != 0)
5991 goto out;
5992 /*
5993 * Note: Server may do delete on close for this file
5994 * in which case the getattr call will fail with
5995 * an ESTALE error. Shouldn't be a problem,
5996 * though, since fattr->valid will remain unset.
5997 */
Chuck Leverbf269552010-12-14 14:59:29 +00005998 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005999 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006000out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006001 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002}
6003
6004/*
6005 * Decode OPEN response
6006 */
Chuck Leverbf269552010-12-14 14:59:29 +00006007static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6008 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006009{
Andy Adamson05d564f2008-12-23 16:06:15 -05006010 struct compound_hdr hdr;
6011 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012
Chuck Leverbf269552010-12-14 14:59:29 +00006013 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006014 if (status)
6015 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006016 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006017 if (status)
6018 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006019 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006020 if (status)
6021 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006022 status = decode_savefh(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;
Chuck Leverbf269552010-12-14 14:59:29 +00006030 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006031 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006032 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006033 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006034 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006035 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006036 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006038 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006039}
6040
6041/*
6042 * Decode OPEN_CONFIRM response
6043 */
Chuck Leverbf269552010-12-14 14:59:29 +00006044static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6045 struct xdr_stream *xdr,
6046 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006047{
Andy Adamson05d564f2008-12-23 16:06:15 -05006048 struct compound_hdr hdr;
6049 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006050
Chuck Leverbf269552010-12-14 14:59:29 +00006051 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006052 if (status)
6053 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006054 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006055 if (status)
6056 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006057 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006058out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006059 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060}
6061
6062/*
6063 * Decode OPEN response
6064 */
Chuck Leverbf269552010-12-14 14:59:29 +00006065static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6066 struct xdr_stream *xdr,
6067 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006068{
Andy Adamson05d564f2008-12-23 16:06:15 -05006069 struct compound_hdr hdr;
6070 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071
Chuck Leverbf269552010-12-14 14:59:29 +00006072 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006073 if (status)
6074 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006075 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006076 if (status)
6077 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006078 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006079 if (status)
6080 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006081 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006082 if (status)
6083 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006084 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006085 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006087 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006088}
6089
6090/*
6091 * Decode SETATTR response
6092 */
Chuck Leverbf269552010-12-14 14:59:29 +00006093static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6094 struct xdr_stream *xdr,
6095 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096{
Andy Adamson05d564f2008-12-23 16:06:15 -05006097 struct compound_hdr hdr;
6098 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006099
Chuck Leverbf269552010-12-14 14:59:29 +00006100 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006101 if (status)
6102 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006103 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006104 if (status)
6105 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006106 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006107 if (status)
6108 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006109 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006110 if (status)
6111 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006112 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006113 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006115 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116}
6117
6118/*
6119 * Decode LOCK response
6120 */
Chuck Leverbf269552010-12-14 14:59:29 +00006121static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6122 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006124 struct compound_hdr hdr;
6125 int status;
6126
Chuck Leverbf269552010-12-14 14:59:29 +00006127 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128 if (status)
6129 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006131 if (status)
6132 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006134 if (status)
6135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137out:
6138 return status;
6139}
6140
6141/*
6142 * Decode LOCKT response
6143 */
Chuck Leverbf269552010-12-14 14:59:29 +00006144static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6145 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147 struct compound_hdr hdr;
6148 int status;
6149
Chuck Leverbf269552010-12-14 14:59:29 +00006150 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151 if (status)
6152 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006154 if (status)
6155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006157 if (status)
6158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160out:
6161 return status;
6162}
6163
6164/*
6165 * Decode LOCKU response
6166 */
Chuck Leverbf269552010-12-14 14:59:29 +00006167static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6168 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170 struct compound_hdr hdr;
6171 int status;
6172
Chuck Leverbf269552010-12-14 14:59:29 +00006173 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174 if (status)
6175 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006176 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006177 if (status)
6178 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180 if (status)
6181 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183out:
6184 return status;
6185}
6186
Chuck Leverbf269552010-12-14 14:59:29 +00006187static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6188 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006189{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006190 struct compound_hdr hdr;
6191 int status;
6192
Chuck Leverbf269552010-12-14 14:59:29 +00006193 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006194 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006196 return status;
6197}
6198
Linus Torvalds1da177e2005-04-16 15:20:36 -07006199/*
6200 * Decode READLINK response
6201 */
Chuck Leverbf269552010-12-14 14:59:29 +00006202static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6203 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006204 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006206 struct compound_hdr hdr;
6207 int status;
6208
Chuck Leverbf269552010-12-14 14:59:29 +00006209 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210 if (status)
6211 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006213 if (status)
6214 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006215 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216 if (status)
6217 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006218 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219out:
6220 return status;
6221}
6222
6223/*
6224 * Decode READDIR response
6225 */
Chuck Leverbf269552010-12-14 14:59:29 +00006226static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6227 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229 struct compound_hdr hdr;
6230 int status;
6231
Chuck Leverbf269552010-12-14 14:59:29 +00006232 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233 if (status)
6234 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006235 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006236 if (status)
6237 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006238 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 if (status)
6240 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006241 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242out:
6243 return status;
6244}
6245
6246/*
6247 * Decode Read response
6248 */
Chuck Leverbf269552010-12-14 14:59:29 +00006249static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6250 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006252 struct compound_hdr hdr;
6253 int status;
6254
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006256 if (status)
6257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006259 if (status)
6260 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262 if (status)
6263 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006264 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265 if (!status)
6266 status = res->count;
6267out:
6268 return status;
6269}
6270
6271/*
6272 * Decode WRITE response
6273 */
Chuck Leverbf269552010-12-14 14:59:29 +00006274static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6275 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277 struct compound_hdr hdr;
6278 int status;
6279
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281 if (status)
6282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006283 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006284 if (status)
6285 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006286 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287 if (status)
6288 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006289 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006290 if (status)
6291 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006292 if (res->fattr)
6293 decode_getfattr(xdr, res->fattr, res->server,
6294 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295 if (!status)
6296 status = res->count;
6297out:
6298 return status;
6299}
6300
6301/*
6302 * Decode COMMIT response
6303 */
Chuck Leverbf269552010-12-14 14:59:29 +00006304static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6305 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006307 struct compound_hdr hdr;
6308 int status;
6309
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311 if (status)
6312 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006314 if (status)
6315 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006316 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006317 if (status)
6318 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006320 if (status)
6321 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006322 if (res->fattr)
6323 decode_getfattr(xdr, res->fattr, res->server,
6324 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325out:
6326 return status;
6327}
6328
6329/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006330 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331 */
Chuck Leverbf269552010-12-14 14:59:29 +00006332static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006333 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006334{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335 struct compound_hdr hdr;
6336 int status;
6337
Chuck Leverbf269552010-12-14 14:59:29 +00006338 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006340 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006341 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006342 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006343 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006344 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 return status;
6346}
6347
6348/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006349 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350 */
Chuck Leverbf269552010-12-14 14:59:29 +00006351static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006352 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354 struct compound_hdr hdr;
6355 int status;
6356
Chuck Leverbf269552010-12-14 14:59:29 +00006357 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006359 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006360 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006363 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364 return status;
6365}
6366
6367/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006368 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369 */
Chuck Leverbf269552010-12-14 14:59:29 +00006370static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006371 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006373 struct compound_hdr hdr;
6374 int status;
6375
Chuck Leverbf269552010-12-14 14:59:29 +00006376 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006377 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006378 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006379 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006380 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006382 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006383 return status;
6384}
6385
6386/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006387 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388 */
Chuck Leverbf269552010-12-14 14:59:29 +00006389static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6390 struct xdr_stream *xdr,
6391 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006393 struct compound_hdr hdr;
6394 int status;
6395
Chuck Leverbf269552010-12-14 14:59:29 +00006396 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006397 if (status)
6398 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006399 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006400 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006401 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006402 status = decode_putfh(xdr);
6403 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006404 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006405 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406out:
6407 return status;
6408}
6409
6410/*
6411 * Decode RENEW response
6412 */
Chuck Leverbf269552010-12-14 14:59:29 +00006413static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6414 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416 struct compound_hdr hdr;
6417 int status;
6418
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006421 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006422 return status;
6423}
6424
6425/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006426 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427 */
Chuck Leverbf269552010-12-14 14:59:29 +00006428static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6429 struct xdr_stream *xdr,
6430 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006432 struct compound_hdr hdr;
6433 int status;
6434
Chuck Leverbf269552010-12-14 14:59:29 +00006435 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006437 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438 return status;
6439}
6440
6441/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006442 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443 */
Chuck Leverbf269552010-12-14 14:59:29 +00006444static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6445 struct xdr_stream *xdr,
6446 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006447{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448 struct compound_hdr hdr;
6449 int status;
6450
Chuck Leverbf269552010-12-14 14:59:29 +00006451 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006452 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006453 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006455 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006456 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006457 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458 return status;
6459}
6460
6461/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006462 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006463 */
Chuck Leverbf269552010-12-14 14:59:29 +00006464static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6465 struct xdr_stream *xdr,
6466 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468 struct compound_hdr hdr;
6469 int status;
6470
Chuck Leverbf269552010-12-14 14:59:29 +00006471 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006472 if (status)
6473 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006474 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006475 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006476 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006477 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006478 if (status != 0)
6479 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006480 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006481 if (status != 0)
6482 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006483 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006484 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01006485out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006486 return status;
6487}
6488
Trond Myklebust683b57b2006-06-09 09:34:22 -04006489/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006490 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006491 */
Chuck Leverbf269552010-12-14 14:59:29 +00006492static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6493 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006494 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006495{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006496 struct compound_hdr hdr;
6497 int status;
6498
Chuck Leverbf269552010-12-14 14:59:29 +00006499 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006500 if (status)
6501 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006502 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006503 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006504 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006505 status = decode_putfh(xdr);
6506 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006507 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006508 status = decode_lookup(xdr);
6509 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006510 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006511 xdr_enter_page(xdr, PAGE_SIZE);
6512 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006513 res->fs_locations->server,
6514 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006515out:
6516 return status;
6517}
6518
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006519/*
6520 * Decode SECINFO response
6521 */
6522static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6523 struct xdr_stream *xdr,
6524 struct nfs4_secinfo_res *res)
6525{
6526 struct compound_hdr hdr;
6527 int status;
6528
6529 status = decode_compound_hdr(xdr, &hdr);
6530 if (status)
6531 goto out;
6532 status = decode_sequence(xdr, &res->seq_res, rqstp);
6533 if (status)
6534 goto out;
6535 status = decode_putfh(xdr);
6536 if (status)
6537 goto out;
6538 status = decode_secinfo(xdr, res);
6539 if (status)
6540 goto out;
6541out:
6542 return status;
6543}
6544
Benny Halevy99fe60d2009-04-01 09:22:29 -04006545#if defined(CONFIG_NFS_V4_1)
6546/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006547 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006548 */
Chuck Leverbf269552010-12-14 14:59:29 +00006549static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6550 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006551 void *res)
6552{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006553 struct compound_hdr hdr;
6554 int status;
6555
Chuck Leverbf269552010-12-14 14:59:29 +00006556 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006557 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006559 return status;
6560}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006561
6562/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006563 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006564 */
Chuck Leverbf269552010-12-14 14:59:29 +00006565static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6566 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006567 struct nfs41_create_session_res *res)
6568{
Andy Adamsonfc931582009-04-01 09:22:31 -04006569 struct compound_hdr hdr;
6570 int status;
6571
Chuck Leverbf269552010-12-14 14:59:29 +00006572 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006573 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006574 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006575 return status;
6576}
6577
6578/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006579 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006580 */
Chuck Leverbf269552010-12-14 14:59:29 +00006581static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6582 struct xdr_stream *xdr,
6583 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006584{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006585 struct compound_hdr hdr;
6586 int status;
6587
Chuck Leverbf269552010-12-14 14:59:29 +00006588 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006589 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006590 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006591 return status;
6592}
6593
6594/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006595 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006596 */
Chuck Leverbf269552010-12-14 14:59:29 +00006597static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6598 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006599 struct nfs4_sequence_res *res)
6600{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006601 struct compound_hdr hdr;
6602 int status;
6603
Chuck Leverbf269552010-12-14 14:59:29 +00006604 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006605 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006606 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006607 return status;
6608}
6609
6610/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006611 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006612 */
Chuck Leverbf269552010-12-14 14:59:29 +00006613static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6614 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006615 struct nfs4_get_lease_time_res *res)
6616{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006617 struct compound_hdr hdr;
6618 int status;
6619
Chuck Leverbf269552010-12-14 14:59:29 +00006620 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006621 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006622 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006623 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006624 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006625 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006626 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006627 return status;
6628}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006629
6630/*
6631 * Decode RECLAIM_COMPLETE response
6632 */
Chuck Leverbf269552010-12-14 14:59:29 +00006633static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6634 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006635 struct nfs41_reclaim_complete_res *res)
6636{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006637 struct compound_hdr hdr;
6638 int status;
6639
Chuck Leverbf269552010-12-14 14:59:29 +00006640 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006641 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006642 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006643 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006644 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006645 return status;
6646}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006647
6648/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006649 * Decode GETDEVICELIST response
6650 */
6651static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6652 struct xdr_stream *xdr,
6653 struct nfs4_getdevicelist_res *res)
6654{
6655 struct compound_hdr hdr;
6656 int status;
6657
6658 dprintk("encoding getdevicelist!\n");
6659
6660 status = decode_compound_hdr(xdr, &hdr);
6661 if (status != 0)
6662 goto out;
6663 status = decode_sequence(xdr, &res->seq_res, rqstp);
6664 if (status != 0)
6665 goto out;
6666 status = decode_putfh(xdr);
6667 if (status != 0)
6668 goto out;
6669 status = decode_getdevicelist(xdr, res->devlist);
6670out:
6671 return status;
6672}
6673
6674/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006675 * Decode GETDEVINFO response
6676 */
Chuck Leverbf269552010-12-14 14:59:29 +00006677static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6678 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006679 struct nfs4_getdeviceinfo_res *res)
6680{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006681 struct compound_hdr hdr;
6682 int status;
6683
Chuck Leverbf269552010-12-14 14:59:29 +00006684 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006685 if (status != 0)
6686 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006687 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006688 if (status != 0)
6689 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006690 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006691out:
6692 return status;
6693}
6694
6695/*
6696 * Decode LAYOUTGET response
6697 */
Chuck Leverbf269552010-12-14 14:59:29 +00006698static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6699 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006700 struct nfs4_layoutget_res *res)
6701{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006702 struct compound_hdr hdr;
6703 int status;
6704
Chuck Leverbf269552010-12-14 14:59:29 +00006705 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006706 if (status)
6707 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006708 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006709 if (status)
6710 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006711 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006712 if (status)
6713 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006714 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006715out:
6716 return status;
6717}
Andy Adamson863a3c62011-03-23 13:27:54 +00006718
6719/*
Benny Halevycbe82602011-05-22 19:52:37 +03006720 * Decode LAYOUTRETURN response
6721 */
6722static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6723 struct xdr_stream *xdr,
6724 struct nfs4_layoutreturn_res *res)
6725{
6726 struct compound_hdr hdr;
6727 int status;
6728
6729 status = decode_compound_hdr(xdr, &hdr);
6730 if (status)
6731 goto out;
6732 status = decode_sequence(xdr, &res->seq_res, rqstp);
6733 if (status)
6734 goto out;
6735 status = decode_putfh(xdr);
6736 if (status)
6737 goto out;
6738 status = decode_layoutreturn(xdr, res);
6739out:
6740 return status;
6741}
6742
6743/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006744 * Decode LAYOUTCOMMIT response
6745 */
6746static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6747 struct xdr_stream *xdr,
6748 struct nfs4_layoutcommit_res *res)
6749{
6750 struct compound_hdr hdr;
6751 int status;
6752
6753 status = decode_compound_hdr(xdr, &hdr);
6754 if (status)
6755 goto out;
6756 status = decode_sequence(xdr, &res->seq_res, rqstp);
6757 if (status)
6758 goto out;
6759 status = decode_putfh(xdr);
6760 if (status)
6761 goto out;
6762 status = decode_layoutcommit(xdr, rqstp, res);
6763 if (status)
6764 goto out;
6765 decode_getfattr(xdr, res->fattr, res->server,
6766 !RPC_IS_ASYNC(rqstp->rq_task));
6767out:
6768 return status;
6769}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006770
6771/*
6772 * Decode SECINFO_NO_NAME response
6773 */
6774static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6775 struct xdr_stream *xdr,
6776 struct nfs4_secinfo_res *res)
6777{
6778 struct compound_hdr hdr;
6779 int status;
6780
6781 status = decode_compound_hdr(xdr, &hdr);
6782 if (status)
6783 goto out;
6784 status = decode_sequence(xdr, &res->seq_res, rqstp);
6785 if (status)
6786 goto out;
6787 status = decode_putrootfh(xdr);
6788 if (status)
6789 goto out;
6790 status = decode_secinfo(xdr, res);
6791out:
6792 return status;
6793}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006794
6795/*
6796 * Decode TEST_STATEID response
6797 */
6798static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6799 struct xdr_stream *xdr,
6800 struct nfs41_test_stateid_res *res)
6801{
6802 struct compound_hdr hdr;
6803 int status;
6804
6805 status = decode_compound_hdr(xdr, &hdr);
6806 if (status)
6807 goto out;
6808 status = decode_sequence(xdr, &res->seq_res, rqstp);
6809 if (status)
6810 goto out;
6811 status = decode_test_stateid(xdr, res);
6812out:
6813 return status;
6814}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006815
6816/*
6817 * Decode FREE_STATEID response
6818 */
6819static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6820 struct xdr_stream *xdr,
6821 struct nfs41_free_stateid_res *res)
6822{
6823 struct compound_hdr hdr;
6824 int status;
6825
6826 status = decode_compound_hdr(xdr, &hdr);
6827 if (status)
6828 goto out;
6829 status = decode_sequence(xdr, &res->seq_res, rqstp);
6830 if (status)
6831 goto out;
6832 status = decode_free_stateid(xdr, res);
6833out:
6834 return status;
6835}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006836#endif /* CONFIG_NFS_V4_1 */
6837
Chuck Lever573c4e12010-12-14 14:58:11 +00006838/**
6839 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6840 * the local page cache.
6841 * @xdr: XDR stream where entry resides
6842 * @entry: buffer to fill in with entry data
6843 * @plus: boolean indicating whether this should be a readdirplus entry
6844 *
6845 * Returns zero if successful, otherwise a negative errno value is
6846 * returned.
6847 *
6848 * This function is not invoked during READDIR reply decoding, but
6849 * rather whenever an application invokes the getdents(2) system call
6850 * on a directory already in our cache.
6851 */
6852int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6853 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006854{
6855 uint32_t bitmap[2] = {0};
6856 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006857 __be32 *p = xdr_inline_decode(xdr, 4);
6858 if (unlikely(!p))
6859 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006860 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006861 p = xdr_inline_decode(xdr, 4);
6862 if (unlikely(!p))
6863 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006864 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006865 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006866 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006867 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006868 }
6869
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006870 p = xdr_inline_decode(xdr, 12);
6871 if (unlikely(!p))
6872 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006873 entry->prev_cookie = entry->cookie;
6874 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006875 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006876
Trond Myklebust9af8c222010-10-24 11:52:55 -04006877 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006878 if (unlikely(!p))
6879 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006880 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006881
6882 /*
6883 * In case the server doesn't return an inode number,
6884 * we fake one here. (We don't use inode number 0,
6885 * since glibc seems to choke on it...)
6886 */
6887 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006888 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006889
Trond Myklebust9af8c222010-10-24 11:52:55 -04006890 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006891 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006892
6893 if (decode_attr_length(xdr, &len, &p) < 0)
6894 goto out_overflow;
6895
Chuck Lever573c4e12010-12-14 14:58:11 +00006896 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6897 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006898 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006899 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6900 entry->ino = entry->fattr->mounted_on_fileid;
6901 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006902 entry->ino = entry->fattr->fileid;
6903
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006904 entry->d_type = DT_UNKNOWN;
6905 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6906 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6907
Chuck Lever573c4e12010-12-14 14:58:11 +00006908 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006909
6910out_overflow:
6911 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006912 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006913}
6914
6915/*
6916 * We need to translate between nfs status return values and
6917 * the local errno values which may not be the same.
6918 */
6919static struct {
6920 int stat;
6921 int errno;
6922} nfs_errtbl[] = {
6923 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006924 { NFS4ERR_PERM, -EPERM },
6925 { NFS4ERR_NOENT, -ENOENT },
6926 { NFS4ERR_IO, -errno_NFSERR_IO},
6927 { NFS4ERR_NXIO, -ENXIO },
6928 { NFS4ERR_ACCESS, -EACCES },
6929 { NFS4ERR_EXIST, -EEXIST },
6930 { NFS4ERR_XDEV, -EXDEV },
6931 { NFS4ERR_NOTDIR, -ENOTDIR },
6932 { NFS4ERR_ISDIR, -EISDIR },
6933 { NFS4ERR_INVAL, -EINVAL },
6934 { NFS4ERR_FBIG, -EFBIG },
6935 { NFS4ERR_NOSPC, -ENOSPC },
6936 { NFS4ERR_ROFS, -EROFS },
6937 { NFS4ERR_MLINK, -EMLINK },
6938 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6939 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6940 { NFS4ERR_DQUOT, -EDQUOT },
6941 { NFS4ERR_STALE, -ESTALE },
6942 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006943 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6944 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6945 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006946 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006947 { NFS4ERR_BADTYPE, -EBADTYPE },
6948 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006949 { NFS4ERR_SYMLINK, -ELOOP },
6950 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6951 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006952 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006953};
6954
6955/*
6956 * Convert an NFS error code to a local one.
6957 * This one is used jointly by NFSv2 and NFSv3.
6958 */
6959static int
David Howells0a8ea432006-08-22 20:06:08 -04006960nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006961{
6962 int i;
6963 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6964 if (nfs_errtbl[i].stat == stat)
6965 return nfs_errtbl[i].errno;
6966 }
6967 if (stat <= 10000 || stat > 10100) {
6968 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006969 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006970 }
6971 /* If we cannot translate the error, the recovery routines should
6972 * handle it.
6973 * Note: remaining NFSv4 error codes have values > 10000, so should
6974 * not conflict with native Linux error codes.
6975 */
Benny Halevy856dff32008-03-31 17:39:06 +03006976 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006977}
6978
Linus Torvalds1da177e2005-04-16 15:20:36 -07006979#define PROC(proc, argtype, restype) \
6980[NFSPROC4_CLNT_##proc] = { \
6981 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006982 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006983 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006984 .p_arglen = NFS4_##argtype##_sz, \
6985 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006986 .p_statidx = NFSPROC4_CLNT_##proc, \
6987 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006988}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006989
6990struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006991 PROC(READ, enc_read, dec_read),
6992 PROC(WRITE, enc_write, dec_write),
6993 PROC(COMMIT, enc_commit, dec_commit),
6994 PROC(OPEN, enc_open, dec_open),
6995 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6996 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6997 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6998 PROC(CLOSE, enc_close, dec_close),
6999 PROC(SETATTR, enc_setattr, dec_setattr),
7000 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7001 PROC(RENEW, enc_renew, dec_renew),
7002 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7003 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7004 PROC(LOCK, enc_lock, dec_lock),
7005 PROC(LOCKT, enc_lockt, dec_lockt),
7006 PROC(LOCKU, enc_locku, dec_locku),
7007 PROC(ACCESS, enc_access, dec_access),
7008 PROC(GETATTR, enc_getattr, dec_getattr),
7009 PROC(LOOKUP, enc_lookup, dec_lookup),
7010 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7011 PROC(REMOVE, enc_remove, dec_remove),
7012 PROC(RENAME, enc_rename, dec_rename),
7013 PROC(LINK, enc_link, dec_link),
7014 PROC(SYMLINK, enc_symlink, dec_symlink),
7015 PROC(CREATE, enc_create, dec_create),
7016 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7017 PROC(STATFS, enc_statfs, dec_statfs),
7018 PROC(READLINK, enc_readlink, dec_readlink),
7019 PROC(READDIR, enc_readdir, dec_readdir),
7020 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7021 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7022 PROC(GETACL, enc_getacl, dec_getacl),
7023 PROC(SETACL, enc_setacl, dec_setacl),
7024 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7025 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007026 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007027#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007028 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7029 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7030 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7031 PROC(SEQUENCE, enc_sequence, dec_sequence),
7032 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7033 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7034 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7035 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007036 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007037 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007038 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007039 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007040 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007041 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007042#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007043};
7044
7045struct rpc_version nfs_version4 = {
7046 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007047 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007048 .procs = nfs4_procedures
7049};
7050
7051/*
7052 * Local variables:
7053 * c-basic-offset: 8
7054 * End:
7055 */