blob: 21c3004b72d524c1d5852b04b123586df6863336 [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))
J. Bruce Fields96928202005-06-22 17:16:22 +000094#define nfs4_fattr_bitmap_maxsz 3
95#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)
258#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 4 + (NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)))
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 Adamsonb1f69b72010-10-20 00:18:03 -0400317#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
318 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
319#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
320 1 /* layout type */ + \
321 1 /* opaque devaddr4 length */ + \
322 /* devaddr4 payload is read into page */ \
323 1 /* notification bitmap length */ + \
324 1 /* notification bitmap */)
325#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
326 encode_stateid_maxsz)
327#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
328 decode_stateid_maxsz + \
329 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400330#else /* CONFIG_NFS_V4_1 */
331#define encode_sequence_maxsz 0
332#define decode_sequence_maxsz 0
333#endif /* CONFIG_NFS_V4_1 */
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
336#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
337#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400338 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400340 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400342 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400344 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400346 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400348 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400350 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400352 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400354 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400356 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400358 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400360 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400362 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400364 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400365 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400367 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400369 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400370 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400372 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400374 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400375 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376#define NFS4_dec_commit_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_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400380 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400382 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400383 encode_putfh_maxsz + \
384 encode_savefh_maxsz + \
385 encode_open_maxsz + \
386 encode_getfh_maxsz + \
387 encode_getattr_maxsz + \
388 encode_restorefh_maxsz + \
389 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400391 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400392 decode_putfh_maxsz + \
393 decode_savefh_maxsz + \
394 decode_open_maxsz + \
395 decode_getfh_maxsz + \
396 decode_getattr_maxsz + \
397 decode_restorefh_maxsz + \
398 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400399#define NFS4_enc_open_confirm_sz \
400 (compound_encode_hdr_maxsz + \
401 encode_putfh_maxsz + \
402 encode_open_confirm_maxsz)
403#define NFS4_dec_open_confirm_sz \
404 (compound_decode_hdr_maxsz + \
405 decode_putfh_maxsz + \
406 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400408 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400410 encode_open_maxsz + \
411 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400413 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400415 decode_open_maxsz + \
416 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#define NFS4_enc_open_downgrade_sz \
418 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400419 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400420 encode_putfh_maxsz + \
421 encode_open_downgrade_maxsz + \
422 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_dec_open_downgrade_sz \
424 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400425 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400426 decode_putfh_maxsz + \
427 decode_open_downgrade_maxsz + \
428 decode_getattr_maxsz)
429#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400431 encode_putfh_maxsz + \
432 encode_close_maxsz + \
433 encode_getattr_maxsz)
434#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400435 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 decode_putfh_maxsz + \
437 decode_close_maxsz + \
438 decode_getattr_maxsz)
439#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400440 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400441 encode_putfh_maxsz + \
442 encode_setattr_maxsz + \
443 encode_getattr_maxsz)
444#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400445 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400446 decode_putfh_maxsz + \
447 decode_setattr_maxsz + \
448 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400450 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 encode_putfh_maxsz + \
452 encode_fsinfo_maxsz)
453#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 decode_putfh_maxsz + \
456 decode_fsinfo_maxsz)
457#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
458 encode_renew_maxsz)
459#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
460 decode_renew_maxsz)
461#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
462 encode_setclientid_maxsz)
463#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
464 decode_setclientid_maxsz)
465#define NFS4_enc_setclientid_confirm_sz \
466 (compound_encode_hdr_maxsz + \
467 encode_setclientid_confirm_maxsz + \
468 encode_putrootfh_maxsz + \
469 encode_fsinfo_maxsz)
470#define NFS4_dec_setclientid_confirm_sz \
471 (compound_decode_hdr_maxsz + \
472 decode_setclientid_confirm_maxsz + \
473 decode_putrootfh_maxsz + \
474 decode_fsinfo_maxsz)
475#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400476 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400478 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400480 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400482 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400484 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 encode_lockt_maxsz)
487#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400488 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400489 decode_putfh_maxsz + \
490 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400494 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400498 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400499#define NFS4_enc_release_lockowner_sz \
500 (compound_encode_hdr_maxsz + \
501 encode_lockowner_maxsz)
502#define NFS4_dec_release_lockowner_sz \
503 (compound_decode_hdr_maxsz + \
504 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400506 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400508 encode_access_maxsz + \
509 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400511 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400513 decode_access_maxsz + \
514 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400516 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 encode_putfh_maxsz + \
518 encode_getattr_maxsz)
519#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400520 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 decode_putfh_maxsz + \
522 decode_getattr_maxsz)
523#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 encode_putfh_maxsz + \
526 encode_lookup_maxsz + \
527 encode_getattr_maxsz + \
528 encode_getfh_maxsz)
529#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400532 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 decode_getattr_maxsz + \
534 decode_getfh_maxsz)
535#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400536 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 encode_putrootfh_maxsz + \
538 encode_getattr_maxsz + \
539 encode_getfh_maxsz)
540#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400541 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 decode_putrootfh_maxsz + \
543 decode_getattr_maxsz + \
544 decode_getfh_maxsz)
545#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400548 encode_remove_maxsz + \
549 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400551 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400553 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400554 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400556 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 encode_putfh_maxsz + \
558 encode_savefh_maxsz + \
559 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400560 encode_rename_maxsz + \
561 encode_getattr_maxsz + \
562 encode_restorefh_maxsz + \
563 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564#define NFS4_dec_rename_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 + \
567 decode_savefh_maxsz + \
568 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400569 decode_rename_maxsz + \
570 decode_getattr_maxsz + \
571 decode_restorefh_maxsz + \
572 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 encode_putfh_maxsz + \
576 encode_savefh_maxsz + \
577 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400578 encode_link_maxsz + \
579 decode_getattr_maxsz + \
580 encode_restorefh_maxsz + \
581 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400583 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 decode_putfh_maxsz + \
585 decode_savefh_maxsz + \
586 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400587 decode_link_maxsz + \
588 decode_getattr_maxsz + \
589 decode_restorefh_maxsz + \
590 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 encode_putfh_maxsz + \
594 encode_symlink_maxsz + \
595 encode_getattr_maxsz + \
596 encode_getfh_maxsz)
597#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400598 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 decode_putfh_maxsz + \
600 decode_symlink_maxsz + \
601 decode_getattr_maxsz + \
602 decode_getfh_maxsz)
603#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400604 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400606 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400608 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400610 encode_restorefh_maxsz + \
611 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400613 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400615 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400617 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400619 decode_restorefh_maxsz + \
620 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 encode_putfh_maxsz + \
624 encode_getattr_maxsz)
625#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 decode_putfh_maxsz + \
628 decode_getattr_maxsz)
629#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400630 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400632 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400636 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800639 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 encode_getattr_maxsz)
641#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800643 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 decode_getattr_maxsz)
645#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100648 encode_delegreturn_maxsz + \
649 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400651 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100652 decode_delegreturn_maxsz + \
653 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000654#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400655 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000656 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400657 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000658#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400659 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000660 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400661 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000662#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000664 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400665 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000666#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400667 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000668 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400669 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400670#define NFS4_enc_fs_locations_sz \
671 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400673 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400674 encode_lookup_maxsz + \
675 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400676#define NFS4_dec_fs_locations_sz \
677 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400678 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400679 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400680 decode_lookup_maxsz + \
681 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000682#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
683 encode_sequence_maxsz + \
684 encode_putfh_maxsz + \
685 encode_secinfo_maxsz)
686#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
687 decode_sequence_maxsz + \
688 decode_putfh_maxsz + \
689 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400690#if defined(CONFIG_NFS_V4_1)
691#define NFS4_enc_exchange_id_sz \
692 (compound_encode_hdr_maxsz + \
693 encode_exchange_id_maxsz)
694#define NFS4_dec_exchange_id_sz \
695 (compound_decode_hdr_maxsz + \
696 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400697#define NFS4_enc_create_session_sz \
698 (compound_encode_hdr_maxsz + \
699 encode_create_session_maxsz)
700#define NFS4_dec_create_session_sz \
701 (compound_decode_hdr_maxsz + \
702 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400703#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
704 encode_destroy_session_maxsz)
705#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
706 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400707#define NFS4_enc_sequence_sz \
708 (compound_decode_hdr_maxsz + \
709 encode_sequence_maxsz)
710#define NFS4_dec_sequence_sz \
711 (compound_decode_hdr_maxsz + \
712 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400713#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
714 encode_sequence_maxsz + \
715 encode_putrootfh_maxsz + \
716 encode_fsinfo_maxsz)
717#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
718 decode_sequence_maxsz + \
719 decode_putrootfh_maxsz + \
720 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500721#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
722 encode_sequence_maxsz + \
723 encode_reclaim_complete_maxsz)
724#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
725 decode_sequence_maxsz + \
726 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400727#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
728 encode_sequence_maxsz +\
729 encode_getdeviceinfo_maxsz)
730#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
731 decode_sequence_maxsz + \
732 decode_getdeviceinfo_maxsz)
733#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
734 encode_sequence_maxsz + \
735 encode_putfh_maxsz + \
736 encode_layoutget_maxsz)
737#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
738 decode_sequence_maxsz + \
739 decode_putfh_maxsz + \
740 decode_layoutget_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500741
742const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
743 compound_encode_hdr_maxsz +
744 encode_sequence_maxsz +
745 encode_putfh_maxsz +
746 encode_getattr_maxsz) *
747 XDR_UNIT);
748
749const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
750 compound_decode_hdr_maxsz +
751 decode_sequence_maxsz +
752 decode_putfh_maxsz) *
753 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400754#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
Trond Myklebustbca79472009-03-11 14:10:26 -0400756static const umode_t nfs_type2fmt[] = {
757 [NF4BAD] = 0,
758 [NF4REG] = S_IFREG,
759 [NF4DIR] = S_IFDIR,
760 [NF4BLK] = S_IFBLK,
761 [NF4CHR] = S_IFCHR,
762 [NF4LNK] = S_IFLNK,
763 [NF4SOCK] = S_IFSOCK,
764 [NF4FIFO] = S_IFIFO,
765 [NF4ATTRDIR] = 0,
766 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767};
768
769struct compound_hdr {
770 int32_t status;
771 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500772 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 uint32_t taglen;
774 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400775 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400776 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777};
778
Benny Halevy13c65ce2009-08-14 17:19:25 +0300779static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
780{
781 __be32 *p = xdr_reserve_space(xdr, nbytes);
782 BUG_ON(!p);
783 return p;
784}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
786static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
787{
Al Viro8687b632006-10-19 23:28:48 -0700788 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 p = xdr_reserve_space(xdr, 4 + len);
791 BUG_ON(p == NULL);
792 xdr_encode_opaque(p, str, len);
793}
794
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400795static void encode_compound_hdr(struct xdr_stream *xdr,
796 struct rpc_rqst *req,
797 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
Al Viro8687b632006-10-19 23:28:48 -0700799 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400800 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400801
802 /* initialize running count of expected bytes in reply.
803 * NOTE: the replied tag SHOULD be the same is the one sent,
804 * but this is not required as a MUST for the server to do so. */
805 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
807 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
808 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300809 p = reserve_space(xdr, 4 + hdr->taglen + 8);
810 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300811 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500812 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300813 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500814}
815
816static void encode_nops(struct compound_hdr *hdr)
817{
Andy Adamsonfc931582009-04-01 09:22:31 -0400818 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500819 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820}
821
822static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
823{
Al Viro8687b632006-10-19 23:28:48 -0700824 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
827 BUG_ON(p == NULL);
828 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
829}
830
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500831static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
833 char owner_name[IDMAP_NAMESZ];
834 char owner_group[IDMAP_NAMESZ];
835 int owner_namelen = 0;
836 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700837 __be32 *p;
838 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 int len;
840 uint32_t bmval0 = 0;
841 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 /*
844 * We reserve enough space to write the entire attribute buffer at once.
845 * In the worst-case, this would be
846 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
847 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000848 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 */
850 len = 16;
851
852 /* Sigh */
853 if (iap->ia_valid & ATTR_SIZE)
854 len += 8;
855 if (iap->ia_valid & ATTR_MODE)
856 len += 4;
857 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800858 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400860 dprintk("nfs: couldn't resolve uid %d to string\n",
861 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 /* XXX */
863 strcpy(owner_name, "nobody");
864 owner_namelen = sizeof("nobody") - 1;
865 /* goto out; */
866 }
867 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
868 }
869 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800870 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400872 dprintk("nfs: couldn't resolve gid %d to string\n",
873 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 strcpy(owner_group, "nobody");
875 owner_grouplen = sizeof("nobody") - 1;
876 /* goto out; */
877 }
878 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
879 }
880 if (iap->ia_valid & ATTR_ATIME_SET)
881 len += 16;
882 else if (iap->ia_valid & ATTR_ATIME)
883 len += 4;
884 if (iap->ia_valid & ATTR_MTIME_SET)
885 len += 16;
886 else if (iap->ia_valid & ATTR_MTIME)
887 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300888 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890 /*
891 * We write the bitmap length now, but leave the bitmap and the attribute
892 * buffer length to be backfilled at the end of this routine.
893 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300894 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 q = p;
896 p += 3;
897
898 if (iap->ia_valid & ATTR_SIZE) {
899 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300900 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 }
902 if (iap->ia_valid & ATTR_MODE) {
903 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300904 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 }
906 if (iap->ia_valid & ATTR_UID) {
907 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300908 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
910 if (iap->ia_valid & ATTR_GID) {
911 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300912 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
914 if (iap->ia_valid & ATTR_ATIME_SET) {
915 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300916 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
917 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400918 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
919 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
921 else if (iap->ia_valid & ATTR_ATIME) {
922 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300923 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
925 if (iap->ia_valid & ATTR_MTIME_SET) {
926 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300927 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
928 *p++ = cpu_to_be32(0);
929 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
930 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 }
932 else if (iap->ia_valid & ATTR_MTIME) {
933 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300934 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500936
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 /*
938 * Now we backfill the bitmap and the attribute buffer length.
939 */
940 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400941 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 len, ((char *)p - (char *)q) + 4);
943 BUG();
944 }
945 len = (char *)p - (char *)q - 12;
946 *q++ = htonl(bmval0);
947 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300948 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951}
952
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500953static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
Al Viro8687b632006-10-19 23:28:48 -0700955 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Benny Halevy13c65ce2009-08-14 17:19:25 +0300957 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300958 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300959 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500960 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400961 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962}
963
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500964static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965{
Al Viro8687b632006-10-19 23:28:48 -0700966 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Benny Halevy13c65ce2009-08-14 17:19:25 +0300968 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300969 *p++ = cpu_to_be32(OP_CLOSE);
970 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300971 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500972 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400973 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974}
975
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500976static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977{
Al Viro8687b632006-10-19 23:28:48 -0700978 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500979
Benny Halevy13c65ce2009-08-14 17:19:25 +0300980 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300981 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +0300982 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +0300983 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500984 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400985 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986}
987
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500988static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989{
Al Viro8687b632006-10-19 23:28:48 -0700990 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500991
Benny Halevy13c65ce2009-08-14 17:19:25 +0300992 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300993 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +0300994 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
996 switch (create->ftype) {
997 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300998 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300999 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001000 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 break;
1002
1003 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001004 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001005 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001006 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 break;
1008
1009 default:
1010 break;
1011 }
1012
Benny Halevy811652b2009-08-14 17:19:34 +03001013 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001014 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001015 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001017 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018}
1019
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001020static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021{
Andy Adamson05d564f2008-12-23 16:06:15 -05001022 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Benny Halevy13c65ce2009-08-14 17:19:25 +03001024 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001025 *p++ = cpu_to_be32(OP_GETATTR);
1026 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001027 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001028 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001029 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001032static 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 -07001033{
Andy Adamson05d564f2008-12-23 16:06:15 -05001034 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Benny Halevy13c65ce2009-08-14 17:19:25 +03001036 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001037 *p++ = cpu_to_be32(OP_GETATTR);
1038 *p++ = cpu_to_be32(2);
1039 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001040 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001041 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001042 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043}
1044
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001045static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001047 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1048 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049}
1050
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001051static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001053 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1054 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055}
1056
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001057static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001058{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001059 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1060 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001061}
1062
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001063static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
Al Viro8687b632006-10-19 23:28:48 -07001065 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Benny Halevy13c65ce2009-08-14 17:19:25 +03001067 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001068 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001069 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001070 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001073static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
Al Viro8687b632006-10-19 23:28:48 -07001075 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Benny Halevy13c65ce2009-08-14 17:19:25 +03001077 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001078 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001079 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001080 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001081 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082}
1083
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001084static inline int nfs4_lock_type(struct file_lock *fl, int block)
1085{
1086 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1087 return block ? NFS4_READW_LT : NFS4_READ_LT;
1088 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1089}
1090
1091static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1092{
1093 if (fl->fl_end == OFFSET_MAX)
1094 return ~(uint64_t)0;
1095 return fl->fl_end - fl->fl_start + 1;
1096}
1097
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001098static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1099{
1100 __be32 *p;
1101
Trond Myklebustd035c362010-12-21 10:45:27 -05001102 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001103 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001104 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001105 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001106 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001107 xdr_encode_hyper(p, lowner->id);
1108}
1109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110/*
1111 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1112 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1113 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001114static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115{
Al Viro8687b632006-10-19 23:28:48 -07001116 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Benny Halevy13c65ce2009-08-14 17:19:25 +03001118 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001119 *p++ = cpu_to_be32(OP_LOCK);
1120 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1121 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001122 p = xdr_encode_hyper(p, args->fl->fl_start);
1123 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001124 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001125 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001126 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001127 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001128 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001129 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001130 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 }
1132 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001133 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001134 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001135 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 }
Andy Adamsond0179312008-12-23 16:06:17 -05001137 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001138 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Al Viro8687b632006-10-19 23:28:48 -07001143 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001145 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001146 *p++ = cpu_to_be32(OP_LOCKT);
1147 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001148 p = xdr_encode_hyper(p, args->fl->fl_start);
1149 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001150 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001151 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001152 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153}
1154
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001155static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156{
Al Viro8687b632006-10-19 23:28:48 -07001157 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Benny Halevy13c65ce2009-08-14 17:19:25 +03001159 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001160 *p++ = cpu_to_be32(OP_LOCKU);
1161 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1162 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001163 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001164 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001165 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001166 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001167 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168}
1169
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001170static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1171{
1172 __be32 *p;
1173
1174 p = reserve_space(xdr, 4);
1175 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1176 encode_lockowner(xdr, lowner);
1177 hdr->nops++;
1178 hdr->replen += decode_release_lockowner_maxsz;
1179}
1180
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001181static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182{
1183 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001184 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185
Benny Halevy13c65ce2009-08-14 17:19:25 +03001186 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001187 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001188 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001189 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001190 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191}
1192
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001193static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194{
Al Viro8687b632006-10-19 23:28:48 -07001195 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Benny Halevy13c65ce2009-08-14 17:19:25 +03001197 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001198 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001199 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001200 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001201 break;
1202 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001203 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001204 break;
1205 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001206 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001207 break;
1208 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001209 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 }
Benny Halevy34558512009-08-14 17:19:30 +03001211 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212}
1213
1214static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1215{
Al Viro8687b632006-10-19 23:28:48 -07001216 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 /*
1218 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1219 * owner 4 = 32
1220 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001221 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001222 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001223 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001224 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001225 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001226 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001227 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001228 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001229 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001230 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231}
1232
1233static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1234{
Al Viro8687b632006-10-19 23:28:48 -07001235 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001236 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Benny Halevy13c65ce2009-08-14 17:19:25 +03001238 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001240 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001241 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001242 encode_attrs(xdr, arg->u.attrs, arg->server);
1243 break;
1244 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001245 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001246 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001247 if (nfs4_has_persistent_session(clp)) {
1248 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1249 encode_attrs(xdr, arg->u.attrs, arg->server);
1250 } else {
1251 struct iattr dummy;
1252
1253 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1254 encode_nfs4_verifier(xdr, &arg->u.verifier);
1255 dummy.ia_valid = 0;
1256 encode_attrs(xdr, &dummy, arg->server);
1257 }
1258 } else {
1259 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1260 encode_nfs4_verifier(xdr, &arg->u.verifier);
1261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 }
1263}
1264
1265static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1266{
Al Viro8687b632006-10-19 23:28:48 -07001267 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Benny Halevy13c65ce2009-08-14 17:19:25 +03001269 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001271 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001272 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001273 break;
1274 default:
1275 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001276 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001277 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 }
1279}
1280
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001281static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282{
Al Viro8687b632006-10-19 23:28:48 -07001283 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
Benny Halevy13c65ce2009-08-14 17:19:25 +03001285 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001287 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001288 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001289 break;
1290 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001291 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001292 break;
1293 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001294 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001295 break;
1296 default:
1297 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 }
1299}
1300
1301static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1302{
Al Viro8687b632006-10-19 23:28:48 -07001303 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Benny Halevy13c65ce2009-08-14 17:19:25 +03001305 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001306 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 encode_string(xdr, name->len, name->name);
1308}
1309
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001310static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311{
Al Viro8687b632006-10-19 23:28:48 -07001312 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Benny Halevy13c65ce2009-08-14 17:19:25 +03001314 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001315 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 encode_delegation_type(xdr, type);
1317}
1318
1319static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1320{
Al Viro8687b632006-10-19 23:28:48 -07001321 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
Benny Halevy13c65ce2009-08-14 17:19:25 +03001323 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001324 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001325 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 encode_string(xdr, name->len, name->name);
1327}
1328
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001329static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330{
1331 encode_openhdr(xdr, arg);
1332 encode_opentype(xdr, arg);
1333 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001334 case NFS4_OPEN_CLAIM_NULL:
1335 encode_claim_null(xdr, arg->name);
1336 break;
1337 case NFS4_OPEN_CLAIM_PREVIOUS:
1338 encode_claim_previous(xdr, arg->u.delegation_type);
1339 break;
1340 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1341 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1342 break;
1343 default:
1344 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 }
Andy Adamsond0179312008-12-23 16:06:17 -05001346 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001347 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348}
1349
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001350static 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 -07001351{
Al Viro8687b632006-10-19 23:28:48 -07001352 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
Benny Halevy13c65ce2009-08-14 17:19:25 +03001354 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001355 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001356 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001357 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001358 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001359 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360}
1361
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001362static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
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+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001367 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001368 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001369 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001370 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001371 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001372 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373}
1374
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001375static void
Andy Adamsond0179312008-12-23 16:06:17 -05001376encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377{
1378 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001379 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Benny Halevy13c65ce2009-08-14 17:19:25 +03001381 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001382 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001383 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001384 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001385 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386}
1387
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001388static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389{
Andy Adamson05d564f2008-12-23 16:06:15 -05001390 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001391
Benny Halevy13c65ce2009-08-14 17:19:25 +03001392 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001393 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001394 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001395 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396}
1397
Andy Adamson89d1ea62011-03-01 01:34:09 +00001398static 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 -07001399{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001401 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Benny Halevy13c65ce2009-08-14 17:19:25 +03001403 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001405 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001406 if (zero_seqid)
1407 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001408 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 } else
Benny Halevy34558512009-08-14 17:19:30 +03001410 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411}
1412
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001413static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414{
Al Viro8687b632006-10-19 23:28:48 -07001415 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Benny Halevy13c65ce2009-08-14 17:19:25 +03001417 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001418 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Andy Adamson89d1ea62011-03-01 01:34:09 +00001420 encode_stateid(xdr, args->context, args->lock_context,
1421 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
Benny Halevy13c65ce2009-08-14 17:19:25 +03001423 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001424 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001425 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001426 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001427 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428}
1429
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001430static 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 -07001431{
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001432 uint32_t attrs[2] = {0, 0};
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001433 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001434 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001436 if (readdir->plus) {
1437 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1438 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE;
1439 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1440 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1441 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1442 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001443 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001444 }
1445 attrs[0] |= FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID;
1446 attrs[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001447 /* Switch to mounted_on_fileid if the server supports it */
1448 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1449 attrs[0] &= ~FATTR4_WORD0_FILEID;
1450 else
1451 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001452
Benny Halevy13c65ce2009-08-14 17:19:25 +03001453 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001454 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001455 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001456 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001457 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001458 *p++ = cpu_to_be32(readdir->count);
1459 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001460
Benny Halevye75bc1c2009-08-14 17:18:54 +03001461 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001462 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001463 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001464 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001465 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1466 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001467 (unsigned long long)readdir->cookie,
1468 ((u32 *)readdir->verifier.data)[0],
1469 ((u32 *)readdir->verifier.data)[1],
1470 attrs[0] & readdir->bitmask[0],
1471 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472}
1473
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001474static 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 -07001475{
Al Viro8687b632006-10-19 23:28:48 -07001476 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Benny Halevy13c65ce2009-08-14 17:19:25 +03001478 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001479 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001480 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001481 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482}
1483
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001484static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485{
Al Viro8687b632006-10-19 23:28:48 -07001486 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Benny Halevy13c65ce2009-08-14 17:19:25 +03001488 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001489 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001490 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001491 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001492 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493}
1494
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001495static 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 -07001496{
Al Viro8687b632006-10-19 23:28:48 -07001497 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
Benny Halevy811652b2009-08-14 17:19:34 +03001499 p = reserve_space(xdr, 4);
1500 *p = cpu_to_be32(OP_RENAME);
1501 encode_string(xdr, oldname->len, oldname->name);
1502 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001503 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001504 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Al Viro8687b632006-10-19 23:28:48 -07001509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Benny Halevy13c65ce2009-08-14 17:19:25 +03001511 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001512 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001513 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001514 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001515 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516}
1517
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001518static void
Andy Adamsond0179312008-12-23 16:06:17 -05001519encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001520{
Al Viro8687b632006-10-19 23:28:48 -07001521 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001522
Benny Halevy13c65ce2009-08-14 17:19:25 +03001523 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001524 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001525 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001526 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001527}
1528
Chuck Lever9f06c712010-12-14 14:59:18 +00001529static void
Andy Adamsond0179312008-12-23 16:06:17 -05001530encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001531{
Al Viro8687b632006-10-19 23:28:48 -07001532 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001533
Benny Halevy13c65ce2009-08-14 17:19:25 +03001534 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001535 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001536 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001537 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001538 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001539 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001540 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001541 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001542 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001543 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001544 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001545 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001546}
1547
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001548static void
Andy Adamsond0179312008-12-23 16:06:17 -05001549encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550{
Al Viro8687b632006-10-19 23:28:48 -07001551 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Benny Halevy13c65ce2009-08-14 17:19:25 +03001553 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001554 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001555 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001556 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557}
1558
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001559static 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 -07001560{
Al Viro8687b632006-10-19 23:28:48 -07001561 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001562
Benny Halevy13c65ce2009-08-14 17:19:25 +03001563 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001564 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001565 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001566 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001567 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001568 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569}
1570
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001571static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572{
Al Viro8687b632006-10-19 23:28:48 -07001573 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Benny Halevy13c65ce2009-08-14 17:19:25 +03001575 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001576 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001577 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
1579 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001580 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001581 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1583 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001584 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001585 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001586 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001587 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588}
1589
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001590static 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 -07001591{
Andy Adamson05d564f2008-12-23 16:06:15 -05001592 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
Benny Halevy13c65ce2009-08-14 17:19:25 +03001594 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001595 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001596 p = xdr_encode_hyper(p, arg->clientid);
1597 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001598 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001599 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001602static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603{
Al Viro8687b632006-10-19 23:28:48 -07001604 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
Benny Halevy13c65ce2009-08-14 17:19:25 +03001606 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001607 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Andy Adamson89d1ea62011-03-01 01:34:09 +00001609 encode_stateid(xdr, args->context, args->lock_context,
1610 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
Benny Halevy13c65ce2009-08-14 17:19:25 +03001612 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001613 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001614 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001615 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
1617 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001618 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001619 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
1621
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001622static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623{
Al Viro8687b632006-10-19 23:28:48 -07001624 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
Benny Halevy13c65ce2009-08-14 17:19:25 +03001626 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
Benny Halevye75bc1c2009-08-14 17:18:54 +03001628 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001629 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001630 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001631 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001633
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001634static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1635{
1636 int len = name->len;
1637 __be32 *p;
1638
1639 p = reserve_space(xdr, 8 + len);
1640 *p++ = cpu_to_be32(OP_SECINFO);
1641 xdr_encode_opaque(p, name->name, len);
1642 hdr->nops++;
1643 hdr->replen += decode_secinfo_maxsz;
1644}
1645
Benny Halevy99fe60d2009-04-01 09:22:29 -04001646#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001647/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001648static void encode_exchange_id(struct xdr_stream *xdr,
1649 struct nfs41_exchange_id_args *args,
1650 struct compound_hdr *hdr)
1651{
1652 __be32 *p;
1653
Benny Halevy13c65ce2009-08-14 17:19:25 +03001654 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001655 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001656 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001657
1658 encode_string(xdr, args->id_len, args->id);
1659
Benny Halevy13c65ce2009-08-14 17:19:25 +03001660 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001661 *p++ = cpu_to_be32(args->flags);
1662 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001663 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001664 hdr->nops++;
1665 hdr->replen += decode_exchange_id_maxsz;
1666}
Andy Adamsonfc931582009-04-01 09:22:31 -04001667
1668static void encode_create_session(struct xdr_stream *xdr,
1669 struct nfs41_create_session_args *args,
1670 struct compound_hdr *hdr)
1671{
1672 __be32 *p;
1673 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1674 uint32_t len;
1675 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001676 u32 max_resp_sz_cached;
1677
1678 /*
1679 * Assumes OPEN is the biggest non-idempotent compound.
1680 * 2 is the verifier.
1681 */
1682 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1683 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001684
Andy Adamsonfc931582009-04-01 09:22:31 -04001685 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1686 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001687
Benny Halevy13c65ce2009-08-14 17:19:25 +03001688 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001689 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001690 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001691 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1692 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001693
Andy Adamsonfc931582009-04-01 09:22:31 -04001694 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001695 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1696 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1697 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001698 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001699 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1700 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1701 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001702
1703 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001704 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1705 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1706 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1707 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1708 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1709 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1710 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001711
Benny Halevye75bc1c2009-08-14 17:18:54 +03001712 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001713 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001714 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001715
1716 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001717 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001718 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001719 *p++ = cpu_to_be32(0); /* UID */
1720 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001721 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001722 hdr->nops++;
1723 hdr->replen += decode_create_session_maxsz;
1724}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001725
1726static void encode_destroy_session(struct xdr_stream *xdr,
1727 struct nfs4_session *session,
1728 struct compound_hdr *hdr)
1729{
1730 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001731 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001732 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001733 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001734 hdr->nops++;
1735 hdr->replen += decode_destroy_session_maxsz;
1736}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001737
1738static void encode_reclaim_complete(struct xdr_stream *xdr,
1739 struct nfs41_reclaim_complete_args *args,
1740 struct compound_hdr *hdr)
1741{
1742 __be32 *p;
1743
1744 p = reserve_space(xdr, 8);
1745 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1746 *p++ = cpu_to_be32(args->one_fs);
1747 hdr->nops++;
1748 hdr->replen += decode_reclaim_complete_maxsz;
1749}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001750#endif /* CONFIG_NFS_V4_1 */
1751
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001752static void encode_sequence(struct xdr_stream *xdr,
1753 const struct nfs4_sequence_args *args,
1754 struct compound_hdr *hdr)
1755{
1756#if defined(CONFIG_NFS_V4_1)
1757 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001758 struct nfs4_slot_table *tp;
1759 struct nfs4_slot *slot;
1760 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001761
1762 if (!session)
1763 return;
1764
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001765 tp = &session->fc_slot_table;
1766
1767 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1768 slot = tp->slots + args->sa_slotid;
1769
Benny Halevy13c65ce2009-08-14 17:19:25 +03001770 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001771 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001772
1773 /*
1774 * Sessionid + seqid + slotid + max slotid + cache_this
1775 */
1776 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1777 "max_slotid=%d cache_this=%d\n",
1778 __func__,
1779 ((u32 *)session->sess_id.data)[0],
1780 ((u32 *)session->sess_id.data)[1],
1781 ((u32 *)session->sess_id.data)[2],
1782 ((u32 *)session->sess_id.data)[3],
1783 slot->seq_nr, args->sa_slotid,
1784 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001785 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001786 *p++ = cpu_to_be32(slot->seq_nr);
1787 *p++ = cpu_to_be32(args->sa_slotid);
1788 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001789 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001790 hdr->nops++;
1791 hdr->replen += decode_sequence_maxsz;
1792#endif /* CONFIG_NFS_V4_1 */
1793}
1794
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001795#ifdef CONFIG_NFS_V4_1
1796static void
1797encode_getdeviceinfo(struct xdr_stream *xdr,
1798 const struct nfs4_getdeviceinfo_args *args,
1799 struct compound_hdr *hdr)
1800{
1801 __be32 *p;
1802
1803 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1804 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1805 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1806 NFS4_DEVICEID4_SIZE);
1807 *p++ = cpu_to_be32(args->pdev->layout_type);
1808 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1809 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1810 hdr->nops++;
1811 hdr->replen += decode_getdeviceinfo_maxsz;
1812}
1813
1814static void
1815encode_layoutget(struct xdr_stream *xdr,
1816 const struct nfs4_layoutget_args *args,
1817 struct compound_hdr *hdr)
1818{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001819 __be32 *p;
1820
1821 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1822 *p++ = cpu_to_be32(OP_LAYOUTGET);
1823 *p++ = cpu_to_be32(0); /* Signal layout available */
1824 *p++ = cpu_to_be32(args->type);
1825 *p++ = cpu_to_be32(args->range.iomode);
1826 p = xdr_encode_hyper(p, args->range.offset);
1827 p = xdr_encode_hyper(p, args->range.length);
1828 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001829 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001830 *p = cpu_to_be32(args->maxcount);
1831
1832 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1833 __func__,
1834 args->type,
1835 args->range.iomode,
1836 (unsigned long)args->range.offset,
1837 (unsigned long)args->range.length,
1838 args->maxcount);
1839 hdr->nops++;
1840 hdr->replen += decode_layoutget_maxsz;
1841}
1842#endif /* CONFIG_NFS_V4_1 */
1843
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844/*
1845 * END OF "GENERIC" ENCODE ROUTINES.
1846 */
1847
Benny Halevy66cc0422009-04-01 09:22:10 -04001848static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1849{
1850#if defined(CONFIG_NFS_V4_1)
1851 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001852 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001853#endif /* CONFIG_NFS_V4_1 */
1854 return 0;
1855}
1856
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857/*
1858 * Encode an ACCESS request
1859 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001860static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1861 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001864 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
Chuck Lever9f06c712010-12-14 14:59:18 +00001867 encode_compound_hdr(xdr, req, &hdr);
1868 encode_sequence(xdr, &args->seq_args, &hdr);
1869 encode_putfh(xdr, args->fh, &hdr);
1870 encode_access(xdr, args->access, &hdr);
1871 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001872 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873}
1874
1875/*
1876 * Encode LOOKUP request
1877 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001878static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1879 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001882 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
Chuck Lever9f06c712010-12-14 14:59:18 +00001885 encode_compound_hdr(xdr, req, &hdr);
1886 encode_sequence(xdr, &args->seq_args, &hdr);
1887 encode_putfh(xdr, args->dir_fh, &hdr);
1888 encode_lookup(xdr, args->name, &hdr);
1889 encode_getfh(xdr, &hdr);
1890 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001891 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892}
1893
1894/*
1895 * Encode LOOKUP_ROOT request
1896 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001897static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1898 struct xdr_stream *xdr,
1899 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001902 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
Chuck Lever9f06c712010-12-14 14:59:18 +00001905 encode_compound_hdr(xdr, req, &hdr);
1906 encode_sequence(xdr, &args->seq_args, &hdr);
1907 encode_putrootfh(xdr, &hdr);
1908 encode_getfh(xdr, &hdr);
1909 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001910 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911}
1912
1913/*
1914 * Encode REMOVE request
1915 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001916static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
1917 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001920 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
Chuck Lever9f06c712010-12-14 14:59:18 +00001923 encode_compound_hdr(xdr, req, &hdr);
1924 encode_sequence(xdr, &args->seq_args, &hdr);
1925 encode_putfh(xdr, args->fh, &hdr);
1926 encode_remove(xdr, &args->name, &hdr);
1927 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001928 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929}
1930
1931/*
1932 * Encode RENAME request
1933 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001934static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
1935 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001938 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
Chuck Lever9f06c712010-12-14 14:59:18 +00001941 encode_compound_hdr(xdr, req, &hdr);
1942 encode_sequence(xdr, &args->seq_args, &hdr);
1943 encode_putfh(xdr, args->old_dir, &hdr);
1944 encode_savefh(xdr, &hdr);
1945 encode_putfh(xdr, args->new_dir, &hdr);
1946 encode_rename(xdr, args->old_name, args->new_name, &hdr);
1947 encode_getfattr(xdr, args->bitmask, &hdr);
1948 encode_restorefh(xdr, &hdr);
1949 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001950 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951}
1952
1953/*
1954 * Encode LINK request
1955 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001956static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
1957 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001960 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
Chuck Lever9f06c712010-12-14 14:59:18 +00001963 encode_compound_hdr(xdr, req, &hdr);
1964 encode_sequence(xdr, &args->seq_args, &hdr);
1965 encode_putfh(xdr, args->fh, &hdr);
1966 encode_savefh(xdr, &hdr);
1967 encode_putfh(xdr, args->dir_fh, &hdr);
1968 encode_link(xdr, args->name, &hdr);
1969 encode_getfattr(xdr, args->bitmask, &hdr);
1970 encode_restorefh(xdr, &hdr);
1971 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001972 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973}
1974
1975/*
1976 * Encode CREATE request
1977 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001978static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
1979 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001982 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984
Chuck Lever9f06c712010-12-14 14:59:18 +00001985 encode_compound_hdr(xdr, req, &hdr);
1986 encode_sequence(xdr, &args->seq_args, &hdr);
1987 encode_putfh(xdr, args->dir_fh, &hdr);
1988 encode_savefh(xdr, &hdr);
1989 encode_create(xdr, args, &hdr);
1990 encode_getfh(xdr, &hdr);
1991 encode_getfattr(xdr, args->bitmask, &hdr);
1992 encode_restorefh(xdr, &hdr);
1993 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001994 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995}
1996
1997/*
1998 * Encode SYMLINK request
1999 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002000static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2001 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002{
Chuck Lever9f06c712010-12-14 14:59:18 +00002003 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004}
2005
2006/*
2007 * Encode GETATTR request
2008 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002009static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2010 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002013 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
Chuck Lever9f06c712010-12-14 14:59:18 +00002016 encode_compound_hdr(xdr, req, &hdr);
2017 encode_sequence(xdr, &args->seq_args, &hdr);
2018 encode_putfh(xdr, args->fh, &hdr);
2019 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002020 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021}
2022
2023/*
2024 * Encode a CLOSE request
2025 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002026static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2027 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028{
Andy Adamson05d564f2008-12-23 16:06:15 -05002029 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002030 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002031 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
Chuck Lever9f06c712010-12-14 14:59:18 +00002033 encode_compound_hdr(xdr, req, &hdr);
2034 encode_sequence(xdr, &args->seq_args, &hdr);
2035 encode_putfh(xdr, args->fh, &hdr);
2036 encode_close(xdr, args, &hdr);
2037 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002038 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039}
2040
2041/*
2042 * Encode an OPEN request
2043 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002044static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2045 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002048 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
Chuck Lever9f06c712010-12-14 14:59:18 +00002051 encode_compound_hdr(xdr, req, &hdr);
2052 encode_sequence(xdr, &args->seq_args, &hdr);
2053 encode_putfh(xdr, args->fh, &hdr);
2054 encode_savefh(xdr, &hdr);
2055 encode_open(xdr, args, &hdr);
2056 encode_getfh(xdr, &hdr);
2057 encode_getfattr(xdr, args->bitmask, &hdr);
2058 encode_restorefh(xdr, &hdr);
2059 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002060 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061}
2062
2063/*
2064 * Encode an OPEN_CONFIRM request
2065 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002066static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2067 struct xdr_stream *xdr,
2068 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002071 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073
Chuck Lever9f06c712010-12-14 14:59:18 +00002074 encode_compound_hdr(xdr, req, &hdr);
2075 encode_putfh(xdr, args->fh, &hdr);
2076 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002077 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078}
2079
2080/*
2081 * Encode an OPEN request with no attributes.
2082 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002083static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2084 struct xdr_stream *xdr,
2085 struct nfs_openargs *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->fh, &hdr);
2094 encode_open(xdr, args, &hdr);
2095 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002096 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097}
2098
2099/*
2100 * Encode an OPEN_DOWNGRADE request
2101 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002102static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2103 struct xdr_stream *xdr,
2104 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002107 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
Chuck Lever9f06c712010-12-14 14:59:18 +00002110 encode_compound_hdr(xdr, req, &hdr);
2111 encode_sequence(xdr, &args->seq_args, &hdr);
2112 encode_putfh(xdr, args->fh, &hdr);
2113 encode_open_downgrade(xdr, args, &hdr);
2114 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002115 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116}
2117
2118/*
2119 * Encode a LOCK request
2120 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002121static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2122 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002125 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
Chuck Lever9f06c712010-12-14 14:59:18 +00002128 encode_compound_hdr(xdr, req, &hdr);
2129 encode_sequence(xdr, &args->seq_args, &hdr);
2130 encode_putfh(xdr, args->fh, &hdr);
2131 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002132 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133}
2134
2135/*
2136 * Encode a LOCKT request
2137 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002138static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2139 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002142 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
Chuck Lever9f06c712010-12-14 14:59:18 +00002145 encode_compound_hdr(xdr, req, &hdr);
2146 encode_sequence(xdr, &args->seq_args, &hdr);
2147 encode_putfh(xdr, args->fh, &hdr);
2148 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002149 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150}
2151
2152/*
2153 * Encode a LOCKU request
2154 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002155static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2156 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002159 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
Chuck Lever9f06c712010-12-14 14:59:18 +00002162 encode_compound_hdr(xdr, req, &hdr);
2163 encode_sequence(xdr, &args->seq_args, &hdr);
2164 encode_putfh(xdr, args->fh, &hdr);
2165 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002166 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167}
2168
Chuck Lever9f06c712010-12-14 14:59:18 +00002169static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2170 struct xdr_stream *xdr,
2171 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002172{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002173 struct compound_hdr hdr = {
2174 .minorversion = 0,
2175 };
2176
Chuck Lever9f06c712010-12-14 14:59:18 +00002177 encode_compound_hdr(xdr, req, &hdr);
2178 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002179 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002180}
2181
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182/*
2183 * Encode a READLINK request
2184 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002185static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2186 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002189 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
Chuck Lever9f06c712010-12-14 14:59:18 +00002192 encode_compound_hdr(xdr, req, &hdr);
2193 encode_sequence(xdr, &args->seq_args, &hdr);
2194 encode_putfh(xdr, args->fh, &hdr);
2195 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002196
Benny Halevy28f56692009-04-01 09:22:09 -04002197 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002198 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002199 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200}
2201
2202/*
2203 * Encode a READDIR request
2204 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002205static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2206 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002209 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
Chuck Lever9f06c712010-12-14 14:59:18 +00002212 encode_compound_hdr(xdr, req, &hdr);
2213 encode_sequence(xdr, &args->seq_args, &hdr);
2214 encode_putfh(xdr, args->fh, &hdr);
2215 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002216
Benny Halevy28f56692009-04-01 09:22:09 -04002217 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002218 args->pgbase, args->count);
2219 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002220 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002221 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002222 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223}
2224
2225/*
2226 * Encode a READ request
2227 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002228static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2229 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002232 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
Chuck Lever9f06c712010-12-14 14:59:18 +00002235 encode_compound_hdr(xdr, req, &hdr);
2236 encode_sequence(xdr, &args->seq_args, &hdr);
2237 encode_putfh(xdr, args->fh, &hdr);
2238 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
Benny Halevy28f56692009-04-01 09:22:09 -04002240 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002242 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002243 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244}
2245
2246/*
2247 * Encode an SETATTR request
2248 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002249static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2250 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251{
Andy Adamson05d564f2008-12-23 16:06:15 -05002252 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002253 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002254 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Chuck Lever9f06c712010-12-14 14:59:18 +00002256 encode_compound_hdr(xdr, req, &hdr);
2257 encode_sequence(xdr, &args->seq_args, &hdr);
2258 encode_putfh(xdr, args->fh, &hdr);
2259 encode_setattr(xdr, args, args->server, &hdr);
2260 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002261 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262}
2263
2264/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002265 * Encode a GETACL request
2266 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002267static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2268 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002269{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002270 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002271 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002272 };
Benny Halevy28f56692009-04-01 09:22:09 -04002273 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002274
Chuck Lever9f06c712010-12-14 14:59:18 +00002275 encode_compound_hdr(xdr, req, &hdr);
2276 encode_sequence(xdr, &args->seq_args, &hdr);
2277 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002278 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002279 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002280
Benny Halevy28f56692009-04-01 09:22:09 -04002281 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002282 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002283 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002284}
2285
2286/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 * Encode a WRITE request
2288 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002289static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2290 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002293 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
Chuck Lever9f06c712010-12-14 14:59:18 +00002296 encode_compound_hdr(xdr, req, &hdr);
2297 encode_sequence(xdr, &args->seq_args, &hdr);
2298 encode_putfh(xdr, args->fh, &hdr);
2299 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002300 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002301 if (args->bitmask)
2302 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002303 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304}
2305
2306/*
2307 * a COMMIT request
2308 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002309static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2310 struct nfs_writeargs *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_commit(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 * FSINFO request
2326 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002327static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2328 struct nfs4_fsinfo_arg *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_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002338 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339}
2340
2341/*
2342 * a PATHCONF request
2343 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002344static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2345 const struct nfs4_pathconf_arg *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_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002355 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002356 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357}
2358
2359/*
2360 * a STATFS request
2361 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002362static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2363 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002366 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
Chuck Lever9f06c712010-12-14 14:59:18 +00002369 encode_compound_hdr(xdr, req, &hdr);
2370 encode_sequence(xdr, &args->seq_args, &hdr);
2371 encode_putfh(xdr, args->fh, &hdr);
2372 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002373 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002374 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375}
2376
2377/*
2378 * GETATTR_BITMAP request
2379 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002380static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2381 struct xdr_stream *xdr,
2382 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002385 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
Chuck Lever9f06c712010-12-14 14:59:18 +00002388 encode_compound_hdr(xdr, req, &hdr);
2389 encode_sequence(xdr, &args->seq_args, &hdr);
2390 encode_putfh(xdr, args->fhandle, &hdr);
2391 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002392 FATTR4_WORD0_LINK_SUPPORT|
2393 FATTR4_WORD0_SYMLINK_SUPPORT|
2394 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002395 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396}
2397
2398/*
2399 * a RENEW request
2400 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002401static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2402 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002405 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 };
2407
Chuck Lever9f06c712010-12-14 14:59:18 +00002408 encode_compound_hdr(xdr, req, &hdr);
2409 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002410 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411}
2412
2413/*
2414 * a SETCLIENTID request
2415 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002416static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2417 struct xdr_stream *xdr,
2418 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002421 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 };
2423
Chuck Lever9f06c712010-12-14 14:59:18 +00002424 encode_compound_hdr(xdr, req, &hdr);
2425 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002426 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427}
2428
2429/*
2430 * a SETCLIENTID_CONFIRM request
2431 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002432static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2433 struct xdr_stream *xdr,
2434 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002437 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 };
2439 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440
Chuck Lever9f06c712010-12-14 14:59:18 +00002441 encode_compound_hdr(xdr, req, &hdr);
2442 encode_setclientid_confirm(xdr, arg, &hdr);
2443 encode_putrootfh(xdr, &hdr);
2444 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002445 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446}
2447
2448/*
2449 * DELEGRETURN request
2450 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002451static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2452 struct xdr_stream *xdr,
2453 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002456 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458
Chuck Lever9f06c712010-12-14 14:59:18 +00002459 encode_compound_hdr(xdr, req, &hdr);
2460 encode_sequence(xdr, &args->seq_args, &hdr);
2461 encode_putfh(xdr, args->fhandle, &hdr);
2462 encode_delegreturn(xdr, args->stateid, &hdr);
2463 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002464 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465}
2466
2467/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002468 * Encode FS_LOCATIONS request
2469 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002470static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2471 struct xdr_stream *xdr,
2472 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002473{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002474 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002475 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002476 };
Benny Halevy28f56692009-04-01 09:22:09 -04002477 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002478
Chuck Lever9f06c712010-12-14 14:59:18 +00002479 encode_compound_hdr(xdr, req, &hdr);
2480 encode_sequence(xdr, &args->seq_args, &hdr);
2481 encode_putfh(xdr, args->dir_fh, &hdr);
2482 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002483 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002484 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002485
Benny Halevy28f56692009-04-01 09:22:09 -04002486 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002487 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002488 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002489}
2490
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002491/*
2492 * Encode SECINFO request
2493 */
2494static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2495 struct xdr_stream *xdr,
2496 struct nfs4_secinfo_arg *args)
2497{
2498 struct compound_hdr hdr = {
2499 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2500 };
2501
2502 encode_compound_hdr(xdr, req, &hdr);
2503 encode_sequence(xdr, &args->seq_args, &hdr);
2504 encode_putfh(xdr, args->dir_fh, &hdr);
2505 encode_secinfo(xdr, args->name, &hdr);
2506 encode_nops(&hdr);
2507}
2508
Benny Halevy99fe60d2009-04-01 09:22:29 -04002509#if defined(CONFIG_NFS_V4_1)
2510/*
2511 * EXCHANGE_ID request
2512 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002513static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2514 struct xdr_stream *xdr,
2515 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002516{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002517 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002518 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002519 };
2520
Chuck Lever9f06c712010-12-14 14:59:18 +00002521 encode_compound_hdr(xdr, req, &hdr);
2522 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002523 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002524}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002525
2526/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002527 * a CREATE_SESSION request
2528 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002529static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2530 struct xdr_stream *xdr,
2531 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002532{
Andy Adamsonfc931582009-04-01 09:22:31 -04002533 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002534 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002535 };
2536
Chuck Lever9f06c712010-12-14 14:59:18 +00002537 encode_compound_hdr(xdr, req, &hdr);
2538 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002539 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002540}
2541
2542/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002543 * a DESTROY_SESSION request
2544 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002545static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2546 struct xdr_stream *xdr,
2547 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002548{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002549 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002550 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002551 };
2552
Chuck Lever9f06c712010-12-14 14:59:18 +00002553 encode_compound_hdr(xdr, req, &hdr);
2554 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002555 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002556}
2557
2558/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002559 * a SEQUENCE request
2560 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002561static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2562 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002563{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002564 struct compound_hdr hdr = {
2565 .minorversion = nfs4_xdr_minorversion(args),
2566 };
2567
Chuck Lever9f06c712010-12-14 14:59:18 +00002568 encode_compound_hdr(xdr, req, &hdr);
2569 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002570 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002571}
2572
2573/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002574 * a GET_LEASE_TIME request
2575 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002576static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2577 struct xdr_stream *xdr,
2578 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002579{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002580 struct compound_hdr hdr = {
2581 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2582 };
2583 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2584
Chuck Lever9f06c712010-12-14 14:59:18 +00002585 encode_compound_hdr(xdr, req, &hdr);
2586 encode_sequence(xdr, &args->la_seq_args, &hdr);
2587 encode_putrootfh(xdr, &hdr);
2588 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002589 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002590}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002591
2592/*
2593 * a RECLAIM_COMPLETE request
2594 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002595static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2596 struct xdr_stream *xdr,
2597 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002598{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002599 struct compound_hdr hdr = {
2600 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2601 };
2602
Chuck Lever9f06c712010-12-14 14:59:18 +00002603 encode_compound_hdr(xdr, req, &hdr);
2604 encode_sequence(xdr, &args->seq_args, &hdr);
2605 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002606 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002607}
2608
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002609/*
2610 * Encode GETDEVICEINFO request
2611 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002612static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2613 struct xdr_stream *xdr,
2614 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002615{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002616 struct compound_hdr hdr = {
2617 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2618 };
2619
Chuck Lever9f06c712010-12-14 14:59:18 +00002620 encode_compound_hdr(xdr, req, &hdr);
2621 encode_sequence(xdr, &args->seq_args, &hdr);
2622 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002623
2624 /* set up reply kvec. Subtract notification bitmap max size (2)
2625 * so that notification bitmap is put in xdr_buf tail */
2626 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2627 args->pdev->pages, args->pdev->pgbase,
2628 args->pdev->pglen);
2629
2630 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002631}
2632
2633/*
2634 * Encode LAYOUTGET request
2635 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002636static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2637 struct xdr_stream *xdr,
2638 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002639{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002640 struct compound_hdr hdr = {
2641 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2642 };
2643
Chuck Lever9f06c712010-12-14 14:59:18 +00002644 encode_compound_hdr(xdr, req, &hdr);
2645 encode_sequence(xdr, &args->seq_args, &hdr);
2646 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2647 encode_layoutget(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002648 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002649}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002650#endif /* CONFIG_NFS_V4_1 */
2651
Benny Halevy686841b2009-08-14 17:19:48 +03002652static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2653{
2654 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2655 "Remaining buffer length is %tu words.\n",
2656 func, xdr->end - xdr->p);
2657}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
Trond Myklebust683b57b2006-06-09 09:34:22 -04002659static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660{
Al Viro8687b632006-10-19 23:28:48 -07002661 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
Benny Halevyc0eae662009-08-14 17:20:14 +03002663 p = xdr_inline_decode(xdr, 4);
2664 if (unlikely(!p))
2665 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002666 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002667 p = xdr_inline_decode(xdr, *len);
2668 if (unlikely(!p))
2669 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 *string = (char *)p;
2671 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002672out_overflow:
2673 print_overflow_msg(__func__, xdr);
2674 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675}
2676
2677static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2678{
Al Viro8687b632006-10-19 23:28:48 -07002679 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680
Benny Halevyc0eae662009-08-14 17:20:14 +03002681 p = xdr_inline_decode(xdr, 8);
2682 if (unlikely(!p))
2683 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002684 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002685 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002686
Benny Halevyc0eae662009-08-14 17:20:14 +03002687 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2688 if (unlikely(!p))
2689 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 hdr->tag = (char *)p;
2691 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002692 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002693 if (unlikely(hdr->nops < 1))
2694 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002696out_overflow:
2697 print_overflow_msg(__func__, xdr);
2698 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699}
2700
2701static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2702{
Al Viro8687b632006-10-19 23:28:48 -07002703 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 uint32_t opnum;
2705 int32_t nfserr;
2706
Benny Halevyc0eae662009-08-14 17:20:14 +03002707 p = xdr_inline_decode(xdr, 8);
2708 if (unlikely(!p))
2709 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002710 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002712 dprintk("nfs: Server returned operation"
2713 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 opnum, expected);
2715 return -EIO;
2716 }
Benny Halevycccddf42009-08-14 17:20:19 +03002717 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002719 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002721out_overflow:
2722 print_overflow_msg(__func__, xdr);
2723 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724}
2725
2726/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002727static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728{
Al Viro8687b632006-10-19 23:28:48 -07002729 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002730 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 char *str;
2732
Benny Halevyc0eae662009-08-14 17:20:14 +03002733 p = xdr_inline_decode(xdr, 12);
2734 if (likely(p))
2735 return decode_opaque_inline(xdr, &strlen, &str);
2736 print_overflow_msg(__func__, xdr);
2737 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738}
2739
2740static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2741{
Al Viro8687b632006-10-19 23:28:48 -07002742 uint32_t bmlen;
2743 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744
Benny Halevyc0eae662009-08-14 17:20:14 +03002745 p = xdr_inline_decode(xdr, 4);
2746 if (unlikely(!p))
2747 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002748 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749
2750 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002751 p = xdr_inline_decode(xdr, (bmlen << 2));
2752 if (unlikely(!p))
2753 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002755 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002757 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 }
2759 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002760out_overflow:
2761 print_overflow_msg(__func__, xdr);
2762 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763}
2764
Al Viro8687b632006-10-19 23:28:48 -07002765static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766{
Al Viro8687b632006-10-19 23:28:48 -07002767 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768
Benny Halevyc0eae662009-08-14 17:20:14 +03002769 p = xdr_inline_decode(xdr, 4);
2770 if (unlikely(!p))
2771 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002772 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 *savep = xdr->p;
2774 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002775out_overflow:
2776 print_overflow_msg(__func__, xdr);
2777 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778}
2779
2780static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2781{
2782 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04002783 int ret;
2784 ret = decode_attr_bitmap(xdr, bitmask);
2785 if (unlikely(ret < 0))
2786 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2788 } else
2789 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002790 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 return 0;
2792}
2793
2794static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2795{
Al Viro8687b632006-10-19 23:28:48 -07002796 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002797 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798
2799 *type = 0;
2800 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2801 return -EIO;
2802 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002803 p = xdr_inline_decode(xdr, 4);
2804 if (unlikely(!p))
2805 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002806 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002808 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 return -EIO;
2810 }
2811 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002812 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002814 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002815 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002816out_overflow:
2817 print_overflow_msg(__func__, xdr);
2818 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819}
2820
2821static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2822{
Al Viro8687b632006-10-19 23:28:48 -07002823 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002824 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825
2826 *change = 0;
2827 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2828 return -EIO;
2829 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002830 p = xdr_inline_decode(xdr, 8);
2831 if (unlikely(!p))
2832 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002833 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002835 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002837 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002839 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002840out_overflow:
2841 print_overflow_msg(__func__, xdr);
2842 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843}
2844
2845static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2846{
Al Viro8687b632006-10-19 23:28:48 -07002847 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002848 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849
2850 *size = 0;
2851 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2852 return -EIO;
2853 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002854 p = xdr_inline_decode(xdr, 8);
2855 if (unlikely(!p))
2856 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002857 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002859 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002861 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002862 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002863out_overflow:
2864 print_overflow_msg(__func__, xdr);
2865 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866}
2867
2868static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2869{
Al Viro8687b632006-10-19 23:28:48 -07002870 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871
2872 *res = 0;
2873 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2874 return -EIO;
2875 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002876 p = xdr_inline_decode(xdr, 4);
2877 if (unlikely(!p))
2878 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002879 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2881 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002882 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002884out_overflow:
2885 print_overflow_msg(__func__, xdr);
2886 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887}
2888
2889static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2890{
Al Viro8687b632006-10-19 23:28:48 -07002891 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892
2893 *res = 0;
2894 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2895 return -EIO;
2896 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002897 p = xdr_inline_decode(xdr, 4);
2898 if (unlikely(!p))
2899 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002900 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2902 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002903 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002905out_overflow:
2906 print_overflow_msg(__func__, xdr);
2907 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908}
2909
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002910static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911{
Al Viro8687b632006-10-19 23:28:48 -07002912 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002913 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914
2915 fsid->major = 0;
2916 fsid->minor = 0;
2917 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2918 return -EIO;
2919 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002920 p = xdr_inline_decode(xdr, 16);
2921 if (unlikely(!p))
2922 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002923 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002924 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002926 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002928 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 (unsigned long long)fsid->major,
2930 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002931 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002932out_overflow:
2933 print_overflow_msg(__func__, xdr);
2934 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935}
2936
2937static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2938{
Al Viro8687b632006-10-19 23:28:48 -07002939 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940
2941 *res = 60;
2942 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2943 return -EIO;
2944 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002945 p = xdr_inline_decode(xdr, 4);
2946 if (unlikely(!p))
2947 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002948 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2950 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002951 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002953out_overflow:
2954 print_overflow_msg(__func__, xdr);
2955 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956}
2957
Bryan Schumakerae42c702010-10-21 16:33:17 -04002958static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
2959{
2960 __be32 *p;
2961
2962 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
2963 return -EIO;
2964 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
2965 p = xdr_inline_decode(xdr, 4);
2966 if (unlikely(!p))
2967 goto out_overflow;
2968 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Bryan Schumaker7ebb9312011-03-24 17:12:30 +00002969 return -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04002970 }
2971 return 0;
2972out_overflow:
2973 print_overflow_msg(__func__, xdr);
2974 return -EIO;
2975}
2976
2977static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
2978{
2979 __be32 *p;
2980 int len;
2981
Trond Myklebust7ad07352010-10-23 15:34:20 -04002982 if (fh != NULL)
2983 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04002984
2985 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
2986 return -EIO;
2987 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
2988 p = xdr_inline_decode(xdr, 4);
2989 if (unlikely(!p))
2990 goto out_overflow;
2991 len = be32_to_cpup(p);
2992 if (len > NFS4_FHSIZE)
2993 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04002994 p = xdr_inline_decode(xdr, len);
2995 if (unlikely(!p))
2996 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04002997 if (fh != NULL) {
2998 memcpy(fh->data, p, len);
2999 fh->size = len;
3000 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003001 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3002 }
3003 return 0;
3004out_overflow:
3005 print_overflow_msg(__func__, xdr);
3006 return -EIO;
3007}
3008
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3010{
Al Viro8687b632006-10-19 23:28:48 -07003011 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012
3013 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3014 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3015 return -EIO;
3016 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003017 p = xdr_inline_decode(xdr, 4);
3018 if (unlikely(!p))
3019 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003020 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3022 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003023 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003025out_overflow:
3026 print_overflow_msg(__func__, xdr);
3027 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028}
3029
3030static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3031{
Al Viro8687b632006-10-19 23:28:48 -07003032 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003033 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034
3035 *fileid = 0;
3036 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3037 return -EIO;
3038 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003039 p = xdr_inline_decode(xdr, 8);
3040 if (unlikely(!p))
3041 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003042 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003044 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003046 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003047 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003048out_overflow:
3049 print_overflow_msg(__func__, xdr);
3050 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051}
3052
Manoj Naik99baf622006-06-09 09:34:24 -04003053static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3054{
Al Viro8687b632006-10-19 23:28:48 -07003055 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003056 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003057
3058 *fileid = 0;
3059 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3060 return -EIO;
3061 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003062 p = xdr_inline_decode(xdr, 8);
3063 if (unlikely(!p))
3064 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003065 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003066 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003067 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003068 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003069 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003070 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003071out_overflow:
3072 print_overflow_msg(__func__, xdr);
3073 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003074}
3075
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3077{
Al Viro8687b632006-10-19 23:28:48 -07003078 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 int status = 0;
3080
3081 *res = 0;
3082 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3083 return -EIO;
3084 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003085 p = xdr_inline_decode(xdr, 8);
3086 if (unlikely(!p))
3087 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003088 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3090 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003091 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003093out_overflow:
3094 print_overflow_msg(__func__, xdr);
3095 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096}
3097
3098static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3099{
Al Viro8687b632006-10-19 23:28:48 -07003100 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 int status = 0;
3102
3103 *res = 0;
3104 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3105 return -EIO;
3106 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003107 p = xdr_inline_decode(xdr, 8);
3108 if (unlikely(!p))
3109 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003110 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3112 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003113 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003115out_overflow:
3116 print_overflow_msg(__func__, xdr);
3117 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118}
3119
3120static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3121{
Al Viro8687b632006-10-19 23:28:48 -07003122 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 int status = 0;
3124
3125 *res = 0;
3126 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3127 return -EIO;
3128 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003129 p = xdr_inline_decode(xdr, 8);
3130 if (unlikely(!p))
3131 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003132 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3134 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003135 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 return status;
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
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003142static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3143{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003144 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003145 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003146 int status = 0;
3147
Benny Halevyc0eae662009-08-14 17:20:14 +03003148 p = xdr_inline_decode(xdr, 4);
3149 if (unlikely(!p))
3150 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003151 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003152 if (n == 0)
3153 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003154 dprintk("path ");
3155 path->ncomponents = 0;
3156 while (path->ncomponents < n) {
3157 struct nfs4_string *component = &path->components[path->ncomponents];
3158 status = decode_opaque_inline(xdr, &component->len, &component->data);
3159 if (unlikely(status != 0))
3160 goto out_eio;
3161 if (path->ncomponents != n)
3162 dprintk("/");
3163 dprintk("%s", component->data);
3164 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3165 path->ncomponents++;
3166 else {
3167 dprintk("cannot parse %d components in path\n", n);
3168 goto out_eio;
3169 }
3170 }
3171out:
3172 dprintk("\n");
3173 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003174root_path:
3175/* a root pathname is sent as a zero component4 */
3176 path->ncomponents = 1;
3177 path->components[0].len=0;
3178 path->components[0].data=NULL;
3179 dprintk("path /\n");
3180 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003181out_eio:
3182 dprintk(" status %d", status);
3183 status = -EIO;
3184 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003185out_overflow:
3186 print_overflow_msg(__func__, xdr);
3187 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003188}
3189
3190static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003191{
3192 int n;
Al Viro8687b632006-10-19 23:28:48 -07003193 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003194 int status = -EIO;
3195
3196 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3197 goto out;
3198 status = 0;
3199 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3200 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003201 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003202 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003203 if (unlikely(status != 0))
3204 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003205 p = xdr_inline_decode(xdr, 4);
3206 if (unlikely(!p))
3207 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003208 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003209 if (n <= 0)
3210 goto out_eio;
3211 res->nlocations = 0;
3212 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003213 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003214 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003215
Benny Halevyc0eae662009-08-14 17:20:14 +03003216 p = xdr_inline_decode(xdr, 4);
3217 if (unlikely(!p))
3218 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003219 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003220
3221 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003222 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003223 while (loc->nservers < m) {
3224 struct nfs4_string *server = &loc->servers[loc->nservers];
3225 status = decode_opaque_inline(xdr, &server->len, &server->data);
3226 if (unlikely(status != 0))
3227 goto out_eio;
3228 dprintk("%s ", server->data);
3229 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3230 loc->nservers++;
3231 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003232 unsigned int i;
3233 dprintk("%s: using first %u of %u servers "
3234 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003235 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003236 NFS4_FS_LOCATION_MAXSERVERS,
3237 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003238 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003239 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003240 char *data;
3241 status = decode_opaque_inline(xdr, &len, &data);
3242 if (unlikely(status != 0))
3243 goto out_eio;
3244 }
3245 }
3246 }
3247 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003248 if (unlikely(status != 0))
3249 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003250 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003251 res->nlocations++;
3252 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003253 if (res->nlocations != 0)
3254 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003255out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003256 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003257 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003258out_overflow:
3259 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003260out_eio:
3261 status = -EIO;
3262 goto out;
3263}
3264
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3266{
Al Viro8687b632006-10-19 23:28:48 -07003267 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 int status = 0;
3269
3270 *res = 0;
3271 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3272 return -EIO;
3273 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003274 p = xdr_inline_decode(xdr, 8);
3275 if (unlikely(!p))
3276 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003277 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3279 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003280 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003282out_overflow:
3283 print_overflow_msg(__func__, xdr);
3284 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285}
3286
3287static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3288{
Al Viro8687b632006-10-19 23:28:48 -07003289 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 int status = 0;
3291
3292 *maxlink = 1;
3293 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3294 return -EIO;
3295 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003296 p = xdr_inline_decode(xdr, 4);
3297 if (unlikely(!p))
3298 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003299 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3301 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003302 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003304out_overflow:
3305 print_overflow_msg(__func__, xdr);
3306 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307}
3308
3309static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3310{
Al Viro8687b632006-10-19 23:28:48 -07003311 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 int status = 0;
3313
3314 *maxname = 1024;
3315 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3316 return -EIO;
3317 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003318 p = xdr_inline_decode(xdr, 4);
3319 if (unlikely(!p))
3320 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003321 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3323 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003324 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003326out_overflow:
3327 print_overflow_msg(__func__, xdr);
3328 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329}
3330
3331static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3332{
Al Viro8687b632006-10-19 23:28:48 -07003333 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 int status = 0;
3335
3336 *res = 1024;
3337 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3338 return -EIO;
3339 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3340 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003341 p = xdr_inline_decode(xdr, 8);
3342 if (unlikely(!p))
3343 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003344 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 if (maxread > 0x7FFFFFFF)
3346 maxread = 0x7FFFFFFF;
3347 *res = (uint32_t)maxread;
3348 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3349 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003350 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003352out_overflow:
3353 print_overflow_msg(__func__, xdr);
3354 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355}
3356
3357static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3358{
Al Viro8687b632006-10-19 23:28:48 -07003359 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 int status = 0;
3361
3362 *res = 1024;
3363 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3364 return -EIO;
3365 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3366 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003367 p = xdr_inline_decode(xdr, 8);
3368 if (unlikely(!p))
3369 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003370 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 if (maxwrite > 0x7FFFFFFF)
3372 maxwrite = 0x7FFFFFFF;
3373 *res = (uint32_t)maxwrite;
3374 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3375 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003376 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003378out_overflow:
3379 print_overflow_msg(__func__, xdr);
3380 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381}
3382
Trond Myklebustbca79472009-03-11 14:10:26 -04003383static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384{
Trond Myklebustbca79472009-03-11 14:10:26 -04003385 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003386 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003387 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388
3389 *mode = 0;
3390 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3391 return -EIO;
3392 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003393 p = xdr_inline_decode(xdr, 4);
3394 if (unlikely(!p))
3395 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003396 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003397 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003399 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003401 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003402 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003403out_overflow:
3404 print_overflow_msg(__func__, xdr);
3405 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406}
3407
3408static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3409{
Al Viro8687b632006-10-19 23:28:48 -07003410 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003411 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412
3413 *nlink = 1;
3414 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3415 return -EIO;
3416 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003417 p = xdr_inline_decode(xdr, 4);
3418 if (unlikely(!p))
3419 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003420 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003422 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003424 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003425 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003426out_overflow:
3427 print_overflow_msg(__func__, xdr);
3428 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429}
3430
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003431static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003432 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433{
Al Viro8687b632006-10-19 23:28:48 -07003434 uint32_t len;
3435 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003436 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437
3438 *uid = -2;
3439 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3440 return -EIO;
3441 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003442 p = xdr_inline_decode(xdr, 4);
3443 if (unlikely(!p))
3444 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003445 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003446 p = xdr_inline_decode(xdr, len);
3447 if (unlikely(!p))
3448 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003449 if (!may_sleep) {
3450 /* do nothing */
3451 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003452 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003453 ret = NFS_ATTR_FATTR_OWNER;
3454 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003456 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003458 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003459 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3461 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003462 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003463 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003464out_overflow:
3465 print_overflow_msg(__func__, xdr);
3466 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467}
3468
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003469static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003470 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471{
Al Viro8687b632006-10-19 23:28:48 -07003472 uint32_t len;
3473 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003474 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475
3476 *gid = -2;
3477 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3478 return -EIO;
3479 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003480 p = xdr_inline_decode(xdr, 4);
3481 if (unlikely(!p))
3482 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003483 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003484 p = xdr_inline_decode(xdr, len);
3485 if (unlikely(!p))
3486 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003487 if (!may_sleep) {
3488 /* do nothing */
3489 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003490 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003491 ret = NFS_ATTR_FATTR_GROUP;
3492 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003494 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003496 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003497 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3499 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003500 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003501 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003502out_overflow:
3503 print_overflow_msg(__func__, xdr);
3504 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505}
3506
3507static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3508{
Al Viro8687b632006-10-19 23:28:48 -07003509 uint32_t major = 0, minor = 0;
3510 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003511 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512
3513 *rdev = MKDEV(0,0);
3514 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3515 return -EIO;
3516 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3517 dev_t tmp;
3518
Benny Halevyc0eae662009-08-14 17:20:14 +03003519 p = xdr_inline_decode(xdr, 8);
3520 if (unlikely(!p))
3521 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003522 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003523 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 tmp = MKDEV(major, minor);
3525 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3526 *rdev = tmp;
3527 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003528 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003530 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003531 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003532out_overflow:
3533 print_overflow_msg(__func__, xdr);
3534 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535}
3536
3537static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3538{
Al Viro8687b632006-10-19 23:28:48 -07003539 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 int status = 0;
3541
3542 *res = 0;
3543 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3544 return -EIO;
3545 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003546 p = xdr_inline_decode(xdr, 8);
3547 if (unlikely(!p))
3548 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003549 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3551 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003552 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003554out_overflow:
3555 print_overflow_msg(__func__, xdr);
3556 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557}
3558
3559static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3560{
Al Viro8687b632006-10-19 23:28:48 -07003561 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 int status = 0;
3563
3564 *res = 0;
3565 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3566 return -EIO;
3567 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003568 p = xdr_inline_decode(xdr, 8);
3569 if (unlikely(!p))
3570 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003571 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3573 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003574 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003576out_overflow:
3577 print_overflow_msg(__func__, xdr);
3578 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579}
3580
3581static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3582{
Al Viro8687b632006-10-19 23:28:48 -07003583 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 int status = 0;
3585
3586 *res = 0;
3587 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3588 return -EIO;
3589 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003590 p = xdr_inline_decode(xdr, 8);
3591 if (unlikely(!p))
3592 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003593 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3595 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003596 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003598out_overflow:
3599 print_overflow_msg(__func__, xdr);
3600 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601}
3602
3603static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3604{
Al Viro8687b632006-10-19 23:28:48 -07003605 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003606 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607
3608 *used = 0;
3609 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3610 return -EIO;
3611 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003612 p = xdr_inline_decode(xdr, 8);
3613 if (unlikely(!p))
3614 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003615 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003617 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003619 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003621 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003622out_overflow:
3623 print_overflow_msg(__func__, xdr);
3624 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625}
3626
3627static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3628{
Al Viro8687b632006-10-19 23:28:48 -07003629 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 uint64_t sec;
3631 uint32_t nsec;
3632
Benny Halevyc0eae662009-08-14 17:20:14 +03003633 p = xdr_inline_decode(xdr, 12);
3634 if (unlikely(!p))
3635 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003636 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003637 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 time->tv_sec = (time_t)sec;
3639 time->tv_nsec = (long)nsec;
3640 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003641out_overflow:
3642 print_overflow_msg(__func__, xdr);
3643 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644}
3645
3646static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3647{
3648 int status = 0;
3649
3650 time->tv_sec = 0;
3651 time->tv_nsec = 0;
3652 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3653 return -EIO;
3654 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3655 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003656 if (status == 0)
3657 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3659 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003660 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661 return status;
3662}
3663
3664static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3665{
3666 int status = 0;
3667
3668 time->tv_sec = 0;
3669 time->tv_nsec = 0;
3670 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3671 return -EIO;
3672 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3673 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003674 if (status == 0)
3675 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3677 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003678 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 return status;
3680}
3681
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003682static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3683 struct timespec *time)
3684{
3685 int status = 0;
3686
3687 time->tv_sec = 0;
3688 time->tv_nsec = 0;
3689 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3690 return -EIO;
3691 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3692 status = decode_attr_time(xdr, time);
3693 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3694 }
3695 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3696 (long)time->tv_nsec);
3697 return status;
3698}
3699
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3701{
3702 int status = 0;
3703
3704 time->tv_sec = 0;
3705 time->tv_nsec = 0;
3706 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3707 return -EIO;
3708 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3709 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003710 if (status == 0)
3711 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3713 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003714 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 return status;
3716}
3717
Al Viro8687b632006-10-19 23:28:48 -07003718static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719{
3720 unsigned int attrwords = XDR_QUADLEN(attrlen);
3721 unsigned int nwords = xdr->p - savep;
3722
3723 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003724 dprintk("%s: server returned incorrect attribute length: "
3725 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003726 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727 attrwords << 2,
3728 (attrwords < nwords) ? '<' : '>',
3729 nwords << 2);
3730 return -EIO;
3731 }
3732 return 0;
3733}
3734
3735static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3736{
Al Viro8687b632006-10-19 23:28:48 -07003737 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738
Benny Halevyc0eae662009-08-14 17:20:14 +03003739 p = xdr_inline_decode(xdr, 20);
3740 if (unlikely(!p))
3741 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003742 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003743 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003744 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003746out_overflow:
3747 print_overflow_msg(__func__, xdr);
3748 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749}
3750
3751static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3752{
Al Viro8687b632006-10-19 23:28:48 -07003753 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 uint32_t supp, acc;
3755 int status;
3756
3757 status = decode_op_hdr(xdr, OP_ACCESS);
3758 if (status)
3759 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003760 p = xdr_inline_decode(xdr, 8);
3761 if (unlikely(!p))
3762 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003763 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003764 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 access->supported = supp;
3766 access->access = acc;
3767 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003768out_overflow:
3769 print_overflow_msg(__func__, xdr);
3770 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771}
3772
Benny Halevy07d30432009-08-14 17:19:52 +03003773static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774{
Al Viro8687b632006-10-19 23:28:48 -07003775 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003776
3777 p = xdr_inline_decode(xdr, len);
3778 if (likely(p)) {
3779 memcpy(buf, p, len);
3780 return 0;
3781 }
3782 print_overflow_msg(__func__, xdr);
3783 return -EIO;
3784}
3785
3786static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3787{
3788 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789}
3790
3791static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3792{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 int status;
3794
3795 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003796 if (status != -EIO)
3797 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003798 if (!status)
3799 status = decode_stateid(xdr, &res->stateid);
3800 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801}
3802
Benny Halevydb942bb2009-08-14 17:19:56 +03003803static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3804{
3805 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806}
3807
3808static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3809{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 int status;
3811
3812 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003813 if (!status)
3814 status = decode_verifier(xdr, res->verf->verifier);
3815 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816}
3817
3818static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3819{
Al Viro8687b632006-10-19 23:28:48 -07003820 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 uint32_t bmlen;
3822 int status;
3823
3824 status = decode_op_hdr(xdr, OP_CREATE);
3825 if (status)
3826 return status;
3827 if ((status = decode_change_info(xdr, cinfo)))
3828 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003829 p = xdr_inline_decode(xdr, 4);
3830 if (unlikely(!p))
3831 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003832 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003833 p = xdr_inline_decode(xdr, bmlen << 2);
3834 if (likely(p))
3835 return 0;
3836out_overflow:
3837 print_overflow_msg(__func__, xdr);
3838 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839}
3840
3841static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3842{
Al Viro8687b632006-10-19 23:28:48 -07003843 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003844 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 int status;
3846
3847 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3848 goto xdr_error;
3849 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3850 goto xdr_error;
3851 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3852 goto xdr_error;
3853 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3854 goto xdr_error;
3855 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3856 goto xdr_error;
3857 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3858 goto xdr_error;
3859 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3860 goto xdr_error;
3861 status = verify_attr_len(xdr, savep, attrlen);
3862xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003863 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 return status;
3865}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003866
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3868{
Al Viro8687b632006-10-19 23:28:48 -07003869 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003870 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003872
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3874 goto xdr_error;
3875 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3876 goto xdr_error;
3877 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3878 goto xdr_error;
3879
3880 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3881 goto xdr_error;
3882 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3883 goto xdr_error;
3884 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3885 goto xdr_error;
3886 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3887 goto xdr_error;
3888 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3889 goto xdr_error;
3890 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3891 goto xdr_error;
3892
3893 status = verify_attr_len(xdr, savep, attrlen);
3894xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003895 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 return status;
3897}
3898
3899static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3900{
Al Viro8687b632006-10-19 23:28:48 -07003901 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003902 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003904
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3906 goto xdr_error;
3907 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3908 goto xdr_error;
3909 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3910 goto xdr_error;
3911
3912 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3913 goto xdr_error;
3914 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3915 goto xdr_error;
3916
3917 status = verify_attr_len(xdr, savep, attrlen);
3918xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003919 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 return status;
3921}
3922
Bryan Schumakerae42c702010-10-21 16:33:17 -04003923static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
3924 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003925 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926{
Trond Myklebustbca79472009-03-11 14:10:26 -04003927 int status;
3928 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003929 uint64_t fileid;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003930 uint32_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003932 status = decode_attr_type(xdr, bitmap, &type);
3933 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003935 fattr->mode = 0;
3936 if (status != 0) {
3937 fattr->mode |= nfs_type2fmt[type];
3938 fattr->valid |= status;
3939 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003941 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3942 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003944 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003945
3946 status = decode_attr_size(xdr, bitmap, &fattr->size);
3947 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003949 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003950
3951 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3952 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003954 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003955
Bryan Schumakerae42c702010-10-21 16:33:17 -04003956 status = decode_attr_error(xdr, bitmap);
Bryan Schumaker7ebb9312011-03-24 17:12:30 +00003957 if (status == -NFS4ERR_WRONGSEC) {
3958 nfs_fixup_secinfo_attributes(fattr, fh);
3959 status = 0;
3960 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003961 if (status < 0)
3962 goto xdr_error;
3963
3964 status = decode_attr_filehandle(xdr, bitmap, fh);
3965 if (status < 0)
3966 goto xdr_error;
3967
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003968 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3969 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003971 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003972
3973 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003974 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003975 fattr));
3976 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003977 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003978 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003979
3980 status = decode_attr_mode(xdr, bitmap, &fmode);
3981 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003983 if (status != 0) {
3984 fattr->mode |= fmode;
3985 fattr->valid |= status;
3986 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003987
3988 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3989 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003991 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003992
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003993 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003994 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003996 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003997
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003998 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003999 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004001 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004002
4003 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4004 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004006 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004007
4008 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4009 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004011 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004012
4013 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4014 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004016 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004017
4018 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4019 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004021 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004022
4023 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4024 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004026 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004027
4028 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
4029 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004030 goto xdr_error;
Trond Myklebust3201f3d2010-10-23 15:43:10 -04004031 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04004032 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04004033 fattr->valid |= status;
4034 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004035
Bryan Schumakerae42c702010-10-21 16:33:17 -04004036xdr_error:
4037 dprintk("%s: xdr returned %d\n", __func__, -status);
4038 return status;
4039}
4040
4041static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4042 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4043{
4044 __be32 *savep;
4045 uint32_t attrlen,
4046 bitmap[2] = {0};
4047 int status;
4048
4049 status = decode_op_hdr(xdr, OP_GETATTR);
4050 if (status < 0)
4051 goto xdr_error;
4052
4053 status = decode_attr_bitmap(xdr, bitmap);
4054 if (status < 0)
4055 goto xdr_error;
4056
4057 status = decode_attr_length(xdr, &attrlen, &savep);
4058 if (status < 0)
4059 goto xdr_error;
4060
4061 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4062 if (status < 0)
4063 goto xdr_error;
4064
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004065 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004067 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 return status;
4069}
4070
Bryan Schumakerae42c702010-10-21 16:33:17 -04004071static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4072 const struct nfs_server *server, int may_sleep)
4073{
4074 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4075}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076
Andy Adamson504913f2010-10-20 00:17:57 -04004077/*
4078 * Decode potentially multiple layout types. Currently we only support
4079 * one layout driver per file system.
4080 */
4081static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4082 uint32_t *layouttype)
4083{
4084 uint32_t *p;
4085 int num;
4086
4087 p = xdr_inline_decode(xdr, 4);
4088 if (unlikely(!p))
4089 goto out_overflow;
4090 num = be32_to_cpup(p);
4091
4092 /* pNFS is not supported by the underlying file system */
4093 if (num == 0) {
4094 *layouttype = 0;
4095 return 0;
4096 }
4097 if (num > 1)
4098 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4099 "per filesystem not supported\n", __func__);
4100
4101 /* Decode and set first layout type, move xdr->p past unused types */
4102 p = xdr_inline_decode(xdr, num * 4);
4103 if (unlikely(!p))
4104 goto out_overflow;
4105 *layouttype = be32_to_cpup(p);
4106 return 0;
4107out_overflow:
4108 print_overflow_msg(__func__, xdr);
4109 return -EIO;
4110}
4111
4112/*
4113 * The type of file system exported.
4114 * Note we must ensure that layouttype is set in any non-error case.
4115 */
4116static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4117 uint32_t *layouttype)
4118{
4119 int status = 0;
4120
4121 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4122 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4123 return -EIO;
4124 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4125 status = decode_first_pnfs_layout_type(xdr, layouttype);
4126 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4127 } else
4128 *layouttype = 0;
4129 return status;
4130}
4131
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4133{
Al Viro8687b632006-10-19 23:28:48 -07004134 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 uint32_t attrlen, bitmap[2];
4136 int status;
4137
4138 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4139 goto xdr_error;
4140 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4141 goto xdr_error;
4142 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4143 goto xdr_error;
4144
4145 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4146
4147 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4148 goto xdr_error;
4149 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4150 goto xdr_error;
4151 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4152 goto xdr_error;
4153 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4154 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4155 goto xdr_error;
4156 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004157 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4158 if (status != 0)
4159 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004160 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4161 if (status != 0)
4162 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163
4164 status = verify_attr_len(xdr, savep, attrlen);
4165xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004166 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 return status;
4168}
4169
4170static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4171{
Al Viro8687b632006-10-19 23:28:48 -07004172 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 uint32_t len;
4174 int status;
4175
Trond Myklebust99367812007-07-17 21:52:41 -04004176 /* Zero handle first to allow comparisons */
4177 memset(fh, 0, sizeof(*fh));
4178
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 status = decode_op_hdr(xdr, OP_GETFH);
4180 if (status)
4181 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182
Benny Halevyc0eae662009-08-14 17:20:14 +03004183 p = xdr_inline_decode(xdr, 4);
4184 if (unlikely(!p))
4185 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004186 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 if (len > NFS4_FHSIZE)
4188 return -EIO;
4189 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004190 p = xdr_inline_decode(xdr, len);
4191 if (unlikely(!p))
4192 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004193 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004195out_overflow:
4196 print_overflow_msg(__func__, xdr);
4197 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198}
4199
4200static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4201{
4202 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004203
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204 status = decode_op_hdr(xdr, OP_LINK);
4205 if (status)
4206 return status;
4207 return decode_change_info(xdr, cinfo);
4208}
4209
4210/*
4211 * We create the owner, so we know a proper owner.id length is 4.
4212 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004213static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004215 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004216 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004217 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004219 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004220 if (unlikely(!p))
4221 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004222 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004223 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004224 type = be32_to_cpup(p++); /* 4 byte read */
4225 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004226 fl->fl_start = (loff_t)offset;
4227 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4228 if (length == ~(uint64_t)0)
4229 fl->fl_end = OFFSET_MAX;
4230 fl->fl_type = F_WRLCK;
4231 if (type & 1)
4232 fl->fl_type = F_RDLCK;
4233 fl->fl_pid = 0;
4234 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004235 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4236 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4237 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004238 if (likely(p))
4239 return -NFS4ERR_DENIED;
4240out_overflow:
4241 print_overflow_msg(__func__, xdr);
4242 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243}
4244
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004245static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 int status;
4248
4249 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004250 if (status == -EIO)
4251 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004253 status = decode_stateid(xdr, &res->stateid);
4254 if (unlikely(status))
4255 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004257 status = decode_lock_denied(xdr, NULL);
4258 if (res->open_seqid != NULL)
4259 nfs_increment_open_seqid(status, res->open_seqid);
4260 nfs_increment_lock_seqid(status, res->lock_seqid);
4261out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262 return status;
4263}
4264
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004265static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004266{
4267 int status;
4268 status = decode_op_hdr(xdr, OP_LOCKT);
4269 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004270 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271 return status;
4272}
4273
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004274static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276 int status;
4277
4278 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004279 if (status != -EIO)
4280 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004281 if (status == 0)
4282 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 return status;
4284}
4285
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004286static int decode_release_lockowner(struct xdr_stream *xdr)
4287{
4288 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4289}
4290
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291static int decode_lookup(struct xdr_stream *xdr)
4292{
4293 return decode_op_hdr(xdr, OP_LOOKUP);
4294}
4295
4296/* This is too sick! */
4297static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4298{
Andy Adamson05d564f2008-12-23 16:06:15 -05004299 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300 uint32_t limit_type, nblocks, blocksize;
4301
Benny Halevyc0eae662009-08-14 17:20:14 +03004302 p = xdr_inline_decode(xdr, 12);
4303 if (unlikely(!p))
4304 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004305 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004307 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004308 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004309 break;
4310 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004311 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004312 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004313 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 }
4315 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004316out_overflow:
4317 print_overflow_msg(__func__, xdr);
4318 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319}
4320
4321static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4322{
Andy Adamson05d564f2008-12-23 16:06:15 -05004323 __be32 *p;
4324 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004325 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326
Benny Halevyc0eae662009-08-14 17:20:14 +03004327 p = xdr_inline_decode(xdr, 4);
4328 if (unlikely(!p))
4329 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004330 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4332 res->delegation_type = 0;
4333 return 0;
4334 }
Benny Halevy07d30432009-08-14 17:19:52 +03004335 status = decode_stateid(xdr, &res->delegation);
4336 if (unlikely(status))
4337 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004338 p = xdr_inline_decode(xdr, 4);
4339 if (unlikely(!p))
4340 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004341 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004342
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004344 case NFS4_OPEN_DELEGATE_READ:
4345 res->delegation_type = FMODE_READ;
4346 break;
4347 case NFS4_OPEN_DELEGATE_WRITE:
4348 res->delegation_type = FMODE_WRITE|FMODE_READ;
4349 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 return -EIO;
4351 }
David Howells7539bba2006-08-22 20:06:09 -04004352 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004353out_overflow:
4354 print_overflow_msg(__func__, xdr);
4355 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356}
4357
4358static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4359{
Andy Adamson05d564f2008-12-23 16:06:15 -05004360 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004361 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004362 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363
Andy Adamson05d564f2008-12-23 16:06:15 -05004364 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004365 if (status != -EIO)
4366 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004367 if (!status)
4368 status = decode_stateid(xdr, &res->stateid);
4369 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004370 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371
Andy Adamson05d564f2008-12-23 16:06:15 -05004372 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373
Benny Halevyc0eae662009-08-14 17:20:14 +03004374 p = xdr_inline_decode(xdr, 8);
4375 if (unlikely(!p))
4376 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004377 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004378 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004379 if (bmlen > 10)
4380 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381
Benny Halevyc0eae662009-08-14 17:20:14 +03004382 p = xdr_inline_decode(xdr, bmlen << 2);
4383 if (unlikely(!p))
4384 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004385 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4386 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004387 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004388 for (; i < NFS4_BITMAP_SIZE; i++)
4389 res->attrset[i] = 0;
4390
Linus Torvalds1da177e2005-04-16 15:20:36 -07004391 return decode_delegation(xdr, res);
4392xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004393 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004395out_overflow:
4396 print_overflow_msg(__func__, xdr);
4397 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398}
4399
4400static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4401{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402 int status;
4403
Andy Adamson05d564f2008-12-23 16:06:15 -05004404 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004405 if (status != -EIO)
4406 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004407 if (!status)
4408 status = decode_stateid(xdr, &res->stateid);
4409 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410}
4411
4412static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4413{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 int status;
4415
4416 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004417 if (status != -EIO)
4418 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004419 if (!status)
4420 status = decode_stateid(xdr, &res->stateid);
4421 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422}
4423
4424static int decode_putfh(struct xdr_stream *xdr)
4425{
4426 return decode_op_hdr(xdr, OP_PUTFH);
4427}
4428
4429static int decode_putrootfh(struct xdr_stream *xdr)
4430{
4431 return decode_op_hdr(xdr, OP_PUTROOTFH);
4432}
4433
4434static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4435{
4436 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004437 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 uint32_t count, eof, recvd, hdrlen;
4439 int status;
4440
4441 status = decode_op_hdr(xdr, OP_READ);
4442 if (status)
4443 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004444 p = xdr_inline_decode(xdr, 8);
4445 if (unlikely(!p))
4446 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004447 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004448 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004449 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 recvd = req->rq_rcv_buf.len - hdrlen;
4451 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004452 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 "count %u > recvd %u\n", count, recvd);
4454 count = recvd;
4455 eof = 0;
4456 }
4457 xdr_read_pages(xdr, count);
4458 res->eof = eof;
4459 res->count = count;
4460 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004461out_overflow:
4462 print_overflow_msg(__func__, xdr);
4463 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464}
4465
4466static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4467{
4468 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004470 size_t hdrlen;
4471 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004472 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473
4474 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004475 if (!status)
4476 status = decode_verifier(xdr, readdir->verifier.data);
4477 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004479 dprintk("%s: verifier = %08x:%08x\n",
4480 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004481 ((u32 *)readdir->verifier.data)[0],
4482 ((u32 *)readdir->verifier.data)[1]);
4483
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484
Benny Halevydb942bb2009-08-14 17:19:56 +03004485 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486 recvd = rcvbuf->len - hdrlen;
4487 if (pglen > recvd)
4488 pglen = recvd;
4489 xdr_read_pages(xdr, pglen);
4490
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004491
Trond Myklebustac396122010-11-15 20:26:22 -05004492 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493}
4494
4495static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4496{
4497 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4498 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004499 size_t hdrlen;
4500 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004501 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502 int status;
4503
4504 status = decode_op_hdr(xdr, OP_READLINK);
4505 if (status)
4506 return status;
4507
4508 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004509 p = xdr_inline_decode(xdr, 4);
4510 if (unlikely(!p))
4511 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004512 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004514 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515 return -ENAMETOOLONG;
4516 }
4517 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4518 recvd = req->rq_rcv_buf.len - hdrlen;
4519 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004520 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 "count %u > recvd %u\n", len, recvd);
4522 return -EIO;
4523 }
4524 xdr_read_pages(xdr, len);
4525 /*
4526 * The XDR encode routine has set things up so that
4527 * the link text will be copied directly into the
4528 * buffer. We just have to do overflow-checking,
4529 * and and null-terminate the text (the VFS expects
4530 * null-termination).
4531 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004532 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004534out_overflow:
4535 print_overflow_msg(__func__, xdr);
4536 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537}
4538
4539static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4540{
4541 int status;
4542
4543 status = decode_op_hdr(xdr, OP_REMOVE);
4544 if (status)
4545 goto out;
4546 status = decode_change_info(xdr, cinfo);
4547out:
4548 return status;
4549}
4550
4551static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4552 struct nfs4_change_info *new_cinfo)
4553{
4554 int status;
4555
4556 status = decode_op_hdr(xdr, OP_RENAME);
4557 if (status)
4558 goto out;
4559 if ((status = decode_change_info(xdr, old_cinfo)))
4560 goto out;
4561 status = decode_change_info(xdr, new_cinfo);
4562out:
4563 return status;
4564}
4565
4566static int decode_renew(struct xdr_stream *xdr)
4567{
4568 return decode_op_hdr(xdr, OP_RENEW);
4569}
4570
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004571static int
4572decode_restorefh(struct xdr_stream *xdr)
4573{
4574 return decode_op_hdr(xdr, OP_RESTOREFH);
4575}
4576
J. Bruce Fields029d1052005-06-22 17:16:22 +00004577static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4578 size_t *acl_len)
4579{
Al Viro8687b632006-10-19 23:28:48 -07004580 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004581 uint32_t attrlen,
4582 bitmap[2] = {0};
4583 struct kvec *iov = req->rq_rcv_buf.head;
4584 int status;
4585
4586 *acl_len = 0;
4587 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4588 goto out;
4589 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4590 goto out;
4591 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4592 goto out;
4593
4594 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4595 return -EIO;
4596 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004597 size_t hdrlen;
4598 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004599
4600 /* We ignore &savep and don't do consistency checks on
4601 * the attr length. Let userspace figure it out.... */
4602 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4603 recvd = req->rq_rcv_buf.len - hdrlen;
4604 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004605 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004606 " acl reply: attrlen %u > recvd %u\n",
4607 attrlen, recvd);
4608 return -EINVAL;
4609 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004610 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004611 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004612 } else
4613 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004614
4615out:
4616 return status;
4617}
4618
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619static int
4620decode_savefh(struct xdr_stream *xdr)
4621{
4622 return decode_op_hdr(xdr, OP_SAVEFH);
4623}
4624
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004625static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626{
Al Viro8687b632006-10-19 23:28:48 -07004627 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 uint32_t bmlen;
4629 int status;
4630
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 status = decode_op_hdr(xdr, OP_SETATTR);
4632 if (status)
4633 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004634 p = xdr_inline_decode(xdr, 4);
4635 if (unlikely(!p))
4636 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004637 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004638 p = xdr_inline_decode(xdr, bmlen << 2);
4639 if (likely(p))
4640 return 0;
4641out_overflow:
4642 print_overflow_msg(__func__, xdr);
4643 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644}
4645
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004646static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647{
Al Viro8687b632006-10-19 23:28:48 -07004648 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649 uint32_t opnum;
4650 int32_t nfserr;
4651
Benny Halevyc0eae662009-08-14 17:20:14 +03004652 p = xdr_inline_decode(xdr, 8);
4653 if (unlikely(!p))
4654 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004655 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004657 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004658 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 return -EIO;
4660 }
Benny Halevycccddf42009-08-14 17:20:19 +03004661 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004663 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4664 if (unlikely(!p))
4665 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004666 p = xdr_decode_hyper(p, &res->clientid);
4667 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668 } else if (nfserr == NFSERR_CLID_INUSE) {
4669 uint32_t len;
4670
4671 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004672 p = xdr_inline_decode(xdr, 4);
4673 if (unlikely(!p))
4674 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004675 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004676 p = xdr_inline_decode(xdr, len);
4677 if (unlikely(!p))
4678 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004679
4680 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004681 p = xdr_inline_decode(xdr, 4);
4682 if (unlikely(!p))
4683 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004684 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004685 p = xdr_inline_decode(xdr, len);
4686 if (unlikely(!p))
4687 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004688 return -NFSERR_CLID_INUSE;
4689 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004690 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691
4692 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004693out_overflow:
4694 print_overflow_msg(__func__, xdr);
4695 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696}
4697
4698static int decode_setclientid_confirm(struct xdr_stream *xdr)
4699{
4700 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4701}
4702
4703static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4704{
Al Viro8687b632006-10-19 23:28:48 -07004705 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706 int status;
4707
4708 status = decode_op_hdr(xdr, OP_WRITE);
4709 if (status)
4710 return status;
4711
Benny Halevyc0eae662009-08-14 17:20:14 +03004712 p = xdr_inline_decode(xdr, 16);
4713 if (unlikely(!p))
4714 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004715 res->count = be32_to_cpup(p++);
4716 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004717 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004719out_overflow:
4720 print_overflow_msg(__func__, xdr);
4721 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722}
4723
4724static int decode_delegreturn(struct xdr_stream *xdr)
4725{
4726 return decode_op_hdr(xdr, OP_DELEGRETURN);
4727}
4728
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004729static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
4730{
4731 __be32 *p;
4732
4733 p = xdr_inline_decode(xdr, 4);
4734 if (unlikely(!p))
4735 goto out_overflow;
4736 flavor->gss.sec_oid4.len = be32_to_cpup(p);
4737 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
4738 goto out_err;
4739
4740 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
4741 if (unlikely(!p))
4742 goto out_overflow;
4743 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
4744
4745 p = xdr_inline_decode(xdr, 8);
4746 if (unlikely(!p))
4747 goto out_overflow;
4748 flavor->gss.qop4 = be32_to_cpup(p++);
4749 flavor->gss.service = be32_to_cpup(p);
4750
4751 return 0;
4752
4753out_overflow:
4754 print_overflow_msg(__func__, xdr);
4755 return -EIO;
4756out_err:
4757 return -EINVAL;
4758}
4759
4760static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
4761{
4762 struct nfs4_secinfo_flavor *sec_flavor;
4763 int status;
4764 __be32 *p;
4765 int i;
4766
4767 status = decode_op_hdr(xdr, OP_SECINFO);
4768 p = xdr_inline_decode(xdr, 4);
4769 if (unlikely(!p))
4770 goto out_overflow;
4771 res->flavors->num_flavors = be32_to_cpup(p);
4772
4773 for (i = 0; i < res->flavors->num_flavors; i++) {
4774 sec_flavor = &res->flavors->flavors[i];
4775 if ((char *)&sec_flavor[1] - (char *)res > PAGE_SIZE)
4776 break;
4777
4778 p = xdr_inline_decode(xdr, 4);
4779 if (unlikely(!p))
4780 goto out_overflow;
4781 sec_flavor->flavor = be32_to_cpup(p);
4782
4783 if (sec_flavor->flavor == RPC_AUTH_GSS) {
4784 if (decode_secinfo_gss(xdr, sec_flavor))
4785 break;
4786 }
4787 }
4788
4789 return 0;
4790
4791out_overflow:
4792 print_overflow_msg(__func__, xdr);
4793 return -EIO;
4794}
4795
Benny Halevy99fe60d2009-04-01 09:22:29 -04004796#if defined(CONFIG_NFS_V4_1)
4797static int decode_exchange_id(struct xdr_stream *xdr,
4798 struct nfs41_exchange_id_res *res)
4799{
4800 __be32 *p;
4801 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004802 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004803 int status;
4804 struct nfs_client *clp = res->client;
4805
4806 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4807 if (status)
4808 return status;
4809
Benny Halevyc0eae662009-08-14 17:20:14 +03004810 p = xdr_inline_decode(xdr, 8);
4811 if (unlikely(!p))
4812 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05004813 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004814 p = xdr_inline_decode(xdr, 12);
4815 if (unlikely(!p))
4816 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004817 clp->cl_seqid = be32_to_cpup(p++);
4818 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004819
4820 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004821 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004822 if (dummy != SP4_NONE)
4823 return -EIO;
4824
4825 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004826 p = xdr_inline_decode(xdr, 8);
4827 if (unlikely(!p))
4828 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004829
4830 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004831 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4832 if (unlikely(status))
4833 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004834
4835 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004836 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4837 if (unlikely(status))
4838 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004839
4840 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004841 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4842 if (unlikely(status))
4843 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004844
4845 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004846out_overflow:
4847 print_overflow_msg(__func__, xdr);
4848 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004849}
Andy Adamsonfc931582009-04-01 09:22:31 -04004850
4851static int decode_chan_attrs(struct xdr_stream *xdr,
4852 struct nfs4_channel_attrs *attrs)
4853{
4854 __be32 *p;
4855 u32 nr_attrs;
4856
Benny Halevyc0eae662009-08-14 17:20:14 +03004857 p = xdr_inline_decode(xdr, 28);
4858 if (unlikely(!p))
4859 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004860 attrs->headerpadsz = be32_to_cpup(p++);
4861 attrs->max_rqst_sz = be32_to_cpup(p++);
4862 attrs->max_resp_sz = be32_to_cpup(p++);
4863 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4864 attrs->max_ops = be32_to_cpup(p++);
4865 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004866 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004867 if (unlikely(nr_attrs > 1)) {
4868 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4869 __func__, nr_attrs);
4870 return -EINVAL;
4871 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004872 if (nr_attrs == 1) {
4873 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4874 if (unlikely(!p))
4875 goto out_overflow;
4876 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004877 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004878out_overflow:
4879 print_overflow_msg(__func__, xdr);
4880 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004881}
4882
Benny Halevye78291e2009-08-14 17:20:00 +03004883static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4884{
4885 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004886}
4887
4888static int decode_create_session(struct xdr_stream *xdr,
4889 struct nfs41_create_session_res *res)
4890{
4891 __be32 *p;
4892 int status;
4893 struct nfs_client *clp = res->client;
4894 struct nfs4_session *session = clp->cl_session;
4895
4896 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004897 if (!status)
4898 status = decode_sessionid(xdr, &session->sess_id);
4899 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004900 return status;
4901
Andy Adamsonfc931582009-04-01 09:22:31 -04004902 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004903 p = xdr_inline_decode(xdr, 8);
4904 if (unlikely(!p))
4905 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004906 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004907 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004908
4909 /* Channel attributes */
4910 status = decode_chan_attrs(xdr, &session->fc_attrs);
4911 if (!status)
4912 status = decode_chan_attrs(xdr, &session->bc_attrs);
4913 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004914out_overflow:
4915 print_overflow_msg(__func__, xdr);
4916 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004917}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004918
4919static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4920{
4921 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4922}
Ricardo Labiaga180197532009-12-05 16:08:40 -05004923
4924static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4925{
4926 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4927}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004928#endif /* CONFIG_NFS_V4_1 */
4929
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004930static int decode_sequence(struct xdr_stream *xdr,
4931 struct nfs4_sequence_res *res,
4932 struct rpc_rqst *rqstp)
4933{
4934#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004935 struct nfs4_sessionid id;
4936 u32 dummy;
4937 int status;
4938 __be32 *p;
4939
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004940 if (!res->sr_session)
4941 return 0;
4942
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004943 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004944 if (!status)
4945 status = decode_sessionid(xdr, &id);
4946 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004947 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004948
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004949 /*
4950 * If the server returns different values for sessionID, slotID or
4951 * sequence number, the server is looney tunes.
4952 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05004953 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004954
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004955 if (memcmp(id.data, res->sr_session->sess_id.data,
4956 NFS4_MAX_SESSIONID_LEN)) {
4957 dprintk("%s Invalid session id\n", __func__);
4958 goto out_err;
4959 }
Benny Halevye78291e2009-08-14 17:20:00 +03004960
Benny Halevyc0eae662009-08-14 17:20:14 +03004961 p = xdr_inline_decode(xdr, 20);
4962 if (unlikely(!p))
4963 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004964
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004965 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03004966 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004967 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004968 dprintk("%s Invalid sequence number\n", __func__);
4969 goto out_err;
4970 }
4971 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004972 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004973 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004974 dprintk("%s Invalid slot id\n", __func__);
4975 goto out_err;
4976 }
4977 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004978 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004979 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004980 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05004981 /* result flags */
4982 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004983 status = 0;
4984out_err:
4985 res->sr_status = status;
4986 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004987out_overflow:
4988 print_overflow_msg(__func__, xdr);
4989 status = -EIO;
4990 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004991#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004992 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004993#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004994}
4995
Andy Adamsonb1f69b72010-10-20 00:18:03 -04004996#if defined(CONFIG_NFS_V4_1)
4997
4998static int decode_getdeviceinfo(struct xdr_stream *xdr,
4999 struct pnfs_device *pdev)
5000{
5001 __be32 *p;
5002 uint32_t len, type;
5003 int status;
5004
5005 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5006 if (status) {
5007 if (status == -ETOOSMALL) {
5008 p = xdr_inline_decode(xdr, 4);
5009 if (unlikely(!p))
5010 goto out_overflow;
5011 pdev->mincount = be32_to_cpup(p);
5012 dprintk("%s: Min count too small. mincnt = %u\n",
5013 __func__, pdev->mincount);
5014 }
5015 return status;
5016 }
5017
5018 p = xdr_inline_decode(xdr, 8);
5019 if (unlikely(!p))
5020 goto out_overflow;
5021 type = be32_to_cpup(p++);
5022 if (type != pdev->layout_type) {
5023 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5024 __func__, pdev->layout_type, type);
5025 return -EINVAL;
5026 }
5027 /*
5028 * Get the length of the opaque device_addr4. xdr_read_pages places
5029 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5030 * and places the remaining xdr data in xdr_buf->tail
5031 */
5032 pdev->mincount = be32_to_cpup(p);
5033 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5034
5035 /* Parse notification bitmap, verifying that it is zero. */
5036 p = xdr_inline_decode(xdr, 4);
5037 if (unlikely(!p))
5038 goto out_overflow;
5039 len = be32_to_cpup(p);
5040 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005041 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005042
5043 p = xdr_inline_decode(xdr, 4 * len);
5044 if (unlikely(!p))
5045 goto out_overflow;
5046 for (i = 0; i < len; i++, p++) {
5047 if (be32_to_cpup(p)) {
5048 dprintk("%s: notifications not supported\n",
5049 __func__);
5050 return -EIO;
5051 }
5052 }
5053 }
5054 return 0;
5055out_overflow:
5056 print_overflow_msg(__func__, xdr);
5057 return -EIO;
5058}
5059
5060static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5061 struct nfs4_layoutget_res *res)
5062{
5063 __be32 *p;
5064 int status;
5065 u32 layout_count;
5066
5067 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5068 if (status)
5069 return status;
5070 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5071 if (unlikely(!p))
5072 goto out_overflow;
5073 res->return_on_close = be32_to_cpup(p++);
5074 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5075 layout_count = be32_to_cpup(p);
5076 if (!layout_count) {
5077 dprintk("%s: server responded with empty layout array\n",
5078 __func__);
5079 return -EINVAL;
5080 }
5081
5082 p = xdr_inline_decode(xdr, 24);
5083 if (unlikely(!p))
5084 goto out_overflow;
5085 p = xdr_decode_hyper(p, &res->range.offset);
5086 p = xdr_decode_hyper(p, &res->range.length);
5087 res->range.iomode = be32_to_cpup(p++);
5088 res->type = be32_to_cpup(p++);
5089
5090 status = decode_opaque_inline(xdr, &res->layout.len, (char **)&p);
5091 if (unlikely(status))
5092 return status;
5093
5094 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5095 __func__,
5096 (unsigned long)res->range.offset,
5097 (unsigned long)res->range.length,
5098 res->range.iomode,
5099 res->type,
5100 res->layout.len);
5101
5102 /* nfs4_proc_layoutget allocated a single page */
5103 if (res->layout.len > PAGE_SIZE)
5104 return -ENOMEM;
5105 memcpy(res->layout.buf, p, res->layout.len);
5106
5107 if (layout_count > 1) {
5108 /* We only handle a length one array at the moment. Any
5109 * further entries are just ignored. Note that this means
5110 * the client may see a response that is less than the
5111 * minimum it requested.
5112 */
5113 dprintk("%s: server responded with %d layouts, dropping tail\n",
5114 __func__, layout_count);
5115 }
5116
5117 return 0;
5118out_overflow:
5119 print_overflow_msg(__func__, xdr);
5120 return -EIO;
5121}
5122#endif /* CONFIG_NFS_V4_1 */
5123
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124/*
Benny Halevy49c25592008-12-23 16:06:16 -05005125 * END OF "GENERIC" DECODE ROUTINES.
5126 */
5127
5128/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129 * Decode OPEN_DOWNGRADE response
5130 */
Chuck Leverbf269552010-12-14 14:59:29 +00005131static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5132 struct xdr_stream *xdr,
5133 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134{
Andy Adamson05d564f2008-12-23 16:06:15 -05005135 struct compound_hdr hdr;
5136 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137
Chuck Leverbf269552010-12-14 14:59:29 +00005138 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005139 if (status)
5140 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005141 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005142 if (status)
5143 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005144 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005145 if (status)
5146 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005147 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005148 if (status != 0)
5149 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005150 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005151 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005153 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005154}
5155
5156/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 * Decode ACCESS response
5158 */
Chuck Leverbf269552010-12-14 14:59:29 +00005159static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5160 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162 struct compound_hdr hdr;
5163 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005164
Chuck Leverbf269552010-12-14 14:59:29 +00005165 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005166 if (status)
5167 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005168 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005169 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005171 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005172 if (status != 0)
5173 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005174 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005175 if (status != 0)
5176 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005177 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005178 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005179out:
5180 return status;
5181}
5182
5183/*
5184 * Decode LOOKUP response
5185 */
Chuck Leverbf269552010-12-14 14:59:29 +00005186static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5187 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005189 struct compound_hdr hdr;
5190 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005191
Chuck Leverbf269552010-12-14 14:59:29 +00005192 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005193 if (status)
5194 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005195 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005196 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005198 status = decode_putfh(xdr);
5199 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005201 status = decode_lookup(xdr);
5202 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005204 status = decode_getfh(xdr, res->fh);
5205 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005207 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005208 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209out:
5210 return status;
5211}
5212
5213/*
5214 * Decode LOOKUP_ROOT response
5215 */
Chuck Leverbf269552010-12-14 14:59:29 +00005216static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5217 struct xdr_stream *xdr,
5218 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220 struct compound_hdr hdr;
5221 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005222
Chuck Leverbf269552010-12-14 14:59:29 +00005223 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005224 if (status)
5225 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005226 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005227 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005229 status = decode_putrootfh(xdr);
5230 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005232 status = decode_getfh(xdr, res->fh);
5233 if (status == 0)
5234 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005235 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236out:
5237 return status;
5238}
5239
5240/*
5241 * Decode REMOVE response
5242 */
Chuck Leverbf269552010-12-14 14:59:29 +00005243static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5244 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246 struct compound_hdr hdr;
5247 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005248
Chuck Leverbf269552010-12-14 14:59:29 +00005249 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005250 if (status)
5251 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005252 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005253 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005255 status = decode_putfh(xdr);
5256 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005258 status = decode_remove(xdr, &res->cinfo);
5259 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005260 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005261 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005262 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263out:
5264 return status;
5265}
5266
5267/*
5268 * Decode RENAME response
5269 */
Chuck Leverbf269552010-12-14 14:59:29 +00005270static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5271 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273 struct compound_hdr hdr;
5274 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005275
Chuck Leverbf269552010-12-14 14:59:29 +00005276 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005277 if (status)
5278 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005279 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005280 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005281 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005282 status = decode_putfh(xdr);
5283 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005285 status = decode_savefh(xdr);
5286 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005287 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005288 status = decode_putfh(xdr);
5289 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005291 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5292 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005293 goto out;
5294 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005295 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005296 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005297 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005298 status = decode_restorefh(xdr);
5299 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005300 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005301 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005302 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303out:
5304 return status;
5305}
5306
5307/*
5308 * Decode LINK response
5309 */
Chuck Leverbf269552010-12-14 14:59:29 +00005310static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5311 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005313 struct compound_hdr hdr;
5314 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005315
Chuck Leverbf269552010-12-14 14:59:29 +00005316 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005317 if (status)
5318 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005319 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005320 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005322 status = decode_putfh(xdr);
5323 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005324 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005325 status = decode_savefh(xdr);
5326 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005327 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005328 status = decode_putfh(xdr);
5329 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005331 status = decode_link(xdr, &res->cinfo);
5332 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005333 goto out;
5334 /*
5335 * Note order: OP_LINK leaves the directory as the current
5336 * filehandle.
5337 */
Chuck Leverbf269552010-12-14 14:59:29 +00005338 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005339 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005340 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005341 status = decode_restorefh(xdr);
5342 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005343 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005344 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005345 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005346out:
5347 return status;
5348}
5349
5350/*
5351 * Decode CREATE response
5352 */
Chuck Leverbf269552010-12-14 14:59:29 +00005353static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5354 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005355{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005356 struct compound_hdr hdr;
5357 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005358
Chuck Leverbf269552010-12-14 14:59:29 +00005359 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005360 if (status)
5361 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005362 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005363 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005364 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005365 status = decode_putfh(xdr);
5366 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005367 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005368 status = decode_savefh(xdr);
5369 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005370 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005371 status = decode_create(xdr, &res->dir_cinfo);
5372 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005374 status = decode_getfh(xdr, res->fh);
5375 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005376 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005377 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005378 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005379 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005380 status = decode_restorefh(xdr);
5381 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005382 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005383 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005384 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385out:
5386 return status;
5387}
5388
5389/*
5390 * Decode SYMLINK response
5391 */
Chuck Leverbf269552010-12-14 14:59:29 +00005392static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5393 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394{
Chuck Leverbf269552010-12-14 14:59:29 +00005395 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005396}
5397
5398/*
5399 * Decode GETATTR response
5400 */
Chuck Leverbf269552010-12-14 14:59:29 +00005401static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5402 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005403{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404 struct compound_hdr hdr;
5405 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005406
Chuck Leverbf269552010-12-14 14:59:29 +00005407 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408 if (status)
5409 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005410 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005411 if (status)
5412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005413 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414 if (status)
5415 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005416 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005417 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005418out:
5419 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005420}
5421
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005422/*
5423 * Encode an SETACL request
5424 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005425static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5426 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005427{
Andy Adamson05d564f2008-12-23 16:06:15 -05005428 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005429 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005430 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005431
Chuck Lever9f06c712010-12-14 14:59:18 +00005432 encode_compound_hdr(xdr, req, &hdr);
5433 encode_sequence(xdr, &args->seq_args, &hdr);
5434 encode_putfh(xdr, args->fh, &hdr);
5435 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005436 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005437}
Andy Adamson05d564f2008-12-23 16:06:15 -05005438
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005439/*
5440 * Decode SETACL response
5441 */
5442static int
Chuck Leverbf269552010-12-14 14:59:29 +00005443nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005444 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005445{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005446 struct compound_hdr hdr;
5447 int status;
5448
Chuck Leverbf269552010-12-14 14:59:29 +00005449 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005450 if (status)
5451 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005452 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005453 if (status)
5454 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005455 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005456 if (status)
5457 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005458 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005459out:
5460 return status;
5461}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005462
5463/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005464 * Decode GETACL response
5465 */
5466static int
Chuck Leverbf269552010-12-14 14:59:29 +00005467nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005468 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005469{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005470 struct compound_hdr hdr;
5471 int status;
5472
Chuck Leverbf269552010-12-14 14:59:29 +00005473 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005474 if (status)
5475 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005476 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005477 if (status)
5478 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005479 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005480 if (status)
5481 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005482 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005483
5484out:
5485 return status;
5486}
5487
5488/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005489 * Decode CLOSE response
5490 */
Chuck Leverbf269552010-12-14 14:59:29 +00005491static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5492 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005493{
Andy Adamson05d564f2008-12-23 16:06:15 -05005494 struct compound_hdr hdr;
5495 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005496
Chuck Leverbf269552010-12-14 14:59:29 +00005497 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005498 if (status)
5499 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005500 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005501 if (status)
5502 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005503 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005504 if (status)
5505 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005506 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005507 if (status != 0)
5508 goto out;
5509 /*
5510 * Note: Server may do delete on close for this file
5511 * in which case the getattr call will fail with
5512 * an ESTALE error. Shouldn't be a problem,
5513 * though, since fattr->valid will remain unset.
5514 */
Chuck Leverbf269552010-12-14 14:59:29 +00005515 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005516 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005517out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005518 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005519}
5520
5521/*
5522 * Decode OPEN response
5523 */
Chuck Leverbf269552010-12-14 14:59:29 +00005524static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5525 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005526{
Andy Adamson05d564f2008-12-23 16:06:15 -05005527 struct compound_hdr hdr;
5528 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005529
Chuck Leverbf269552010-12-14 14:59:29 +00005530 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005531 if (status)
5532 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005533 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005534 if (status)
5535 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005536 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005537 if (status)
5538 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005539 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005540 if (status)
5541 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005542 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005543 if (status)
5544 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005545 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005547 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005548 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005549 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005550 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005551 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005552 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005553 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005554out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005555 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005556}
5557
5558/*
5559 * Decode OPEN_CONFIRM response
5560 */
Chuck Leverbf269552010-12-14 14:59:29 +00005561static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5562 struct xdr_stream *xdr,
5563 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005564{
Andy Adamson05d564f2008-12-23 16:06:15 -05005565 struct compound_hdr hdr;
5566 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567
Chuck Leverbf269552010-12-14 14:59:29 +00005568 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005569 if (status)
5570 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005571 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005572 if (status)
5573 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005574 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005575out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005576 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005577}
5578
5579/*
5580 * Decode OPEN response
5581 */
Chuck Leverbf269552010-12-14 14:59:29 +00005582static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5583 struct xdr_stream *xdr,
5584 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005585{
Andy Adamson05d564f2008-12-23 16:06:15 -05005586 struct compound_hdr hdr;
5587 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005588
Chuck Leverbf269552010-12-14 14:59:29 +00005589 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005590 if (status)
5591 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005592 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005593 if (status)
5594 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005595 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005596 if (status)
5597 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005598 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005599 if (status)
5600 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005601 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005602 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005603out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005604 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605}
5606
5607/*
5608 * Decode SETATTR response
5609 */
Chuck Leverbf269552010-12-14 14:59:29 +00005610static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5611 struct xdr_stream *xdr,
5612 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005613{
Andy Adamson05d564f2008-12-23 16:06:15 -05005614 struct compound_hdr hdr;
5615 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005616
Chuck Leverbf269552010-12-14 14:59:29 +00005617 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005618 if (status)
5619 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005620 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005621 if (status)
5622 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005623 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005624 if (status)
5625 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005626 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005627 if (status)
5628 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005629 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005630 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005631out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005632 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005633}
5634
5635/*
5636 * Decode LOCK response
5637 */
Chuck Leverbf269552010-12-14 14:59:29 +00005638static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5639 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005640{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005641 struct compound_hdr hdr;
5642 int status;
5643
Chuck Leverbf269552010-12-14 14:59:29 +00005644 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005645 if (status)
5646 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005647 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005648 if (status)
5649 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005650 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005651 if (status)
5652 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005653 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005654out:
5655 return status;
5656}
5657
5658/*
5659 * Decode LOCKT response
5660 */
Chuck Leverbf269552010-12-14 14:59:29 +00005661static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5662 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005663{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005664 struct compound_hdr hdr;
5665 int status;
5666
Chuck Leverbf269552010-12-14 14:59:29 +00005667 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005668 if (status)
5669 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005670 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005671 if (status)
5672 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005673 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005674 if (status)
5675 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005676 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005677out:
5678 return status;
5679}
5680
5681/*
5682 * Decode LOCKU response
5683 */
Chuck Leverbf269552010-12-14 14:59:29 +00005684static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5685 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005687 struct compound_hdr hdr;
5688 int status;
5689
Chuck Leverbf269552010-12-14 14:59:29 +00005690 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005691 if (status)
5692 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005693 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005694 if (status)
5695 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005696 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005697 if (status)
5698 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005699 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005700out:
5701 return status;
5702}
5703
Chuck Leverbf269552010-12-14 14:59:29 +00005704static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5705 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005706{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005707 struct compound_hdr hdr;
5708 int status;
5709
Chuck Leverbf269552010-12-14 14:59:29 +00005710 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005711 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005712 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005713 return status;
5714}
5715
Linus Torvalds1da177e2005-04-16 15:20:36 -07005716/*
5717 * Decode READLINK response
5718 */
Chuck Leverbf269552010-12-14 14:59:29 +00005719static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5720 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04005721 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005722{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005723 struct compound_hdr hdr;
5724 int status;
5725
Chuck Leverbf269552010-12-14 14:59:29 +00005726 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005727 if (status)
5728 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005729 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005730 if (status)
5731 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005732 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005733 if (status)
5734 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005735 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005736out:
5737 return status;
5738}
5739
5740/*
5741 * Decode READDIR response
5742 */
Chuck Leverbf269552010-12-14 14:59:29 +00005743static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5744 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005746 struct compound_hdr hdr;
5747 int status;
5748
Chuck Leverbf269552010-12-14 14:59:29 +00005749 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750 if (status)
5751 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005752 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005753 if (status)
5754 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005755 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005756 if (status)
5757 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005758 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759out:
5760 return status;
5761}
5762
5763/*
5764 * Decode Read response
5765 */
Chuck Leverbf269552010-12-14 14:59:29 +00005766static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5767 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005768{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005769 struct compound_hdr hdr;
5770 int status;
5771
Chuck Leverbf269552010-12-14 14:59:29 +00005772 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005773 if (status)
5774 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005775 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005776 if (status)
5777 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005778 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005779 if (status)
5780 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005781 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005782 if (!status)
5783 status = res->count;
5784out:
5785 return status;
5786}
5787
5788/*
5789 * Decode WRITE response
5790 */
Chuck Leverbf269552010-12-14 14:59:29 +00005791static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5792 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005794 struct compound_hdr hdr;
5795 int status;
5796
Chuck Leverbf269552010-12-14 14:59:29 +00005797 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005798 if (status)
5799 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005800 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005801 if (status)
5802 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005803 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005804 if (status)
5805 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005806 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005807 if (status)
5808 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00005809 if (res->fattr)
5810 decode_getfattr(xdr, res->fattr, res->server,
5811 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005812 if (!status)
5813 status = res->count;
5814out:
5815 return status;
5816}
5817
5818/*
5819 * Decode COMMIT response
5820 */
Chuck Leverbf269552010-12-14 14:59:29 +00005821static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5822 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005823{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824 struct compound_hdr hdr;
5825 int status;
5826
Chuck Leverbf269552010-12-14 14:59:29 +00005827 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005828 if (status)
5829 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005830 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005831 if (status)
5832 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005833 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834 if (status)
5835 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005836 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005837 if (status)
5838 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005839 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005840 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005841out:
5842 return status;
5843}
5844
5845/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005846 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005847 */
Chuck Leverbf269552010-12-14 14:59:29 +00005848static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04005849 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005851 struct compound_hdr hdr;
5852 int status;
5853
Chuck Leverbf269552010-12-14 14:59:29 +00005854 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005856 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005857 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005858 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005860 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005861 return status;
5862}
5863
5864/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005865 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005866 */
Chuck Leverbf269552010-12-14 14:59:29 +00005867static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04005868 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005869{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005870 struct compound_hdr hdr;
5871 int status;
5872
Chuck Leverbf269552010-12-14 14:59:29 +00005873 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005874 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005875 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005876 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005877 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005878 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005879 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005880 return status;
5881}
5882
5883/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005884 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885 */
Chuck Leverbf269552010-12-14 14:59:29 +00005886static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04005887 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005889 struct compound_hdr hdr;
5890 int status;
5891
Chuck Leverbf269552010-12-14 14:59:29 +00005892 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005893 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005894 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005895 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005896 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005897 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005898 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005899 return status;
5900}
5901
5902/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005903 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005904 */
Chuck Leverbf269552010-12-14 14:59:29 +00005905static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
5906 struct xdr_stream *xdr,
5907 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005908{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909 struct compound_hdr hdr;
5910 int status;
5911
Chuck Leverbf269552010-12-14 14:59:29 +00005912 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005913 if (status)
5914 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005915 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005916 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005917 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005918 status = decode_putfh(xdr);
5919 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005920 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005921 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005922out:
5923 return status;
5924}
5925
5926/*
5927 * Decode RENEW response
5928 */
Chuck Leverbf269552010-12-14 14:59:29 +00005929static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5930 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932 struct compound_hdr hdr;
5933 int status;
5934
Chuck Leverbf269552010-12-14 14:59:29 +00005935 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005936 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005937 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005938 return status;
5939}
5940
5941/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005942 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005943 */
Chuck Leverbf269552010-12-14 14:59:29 +00005944static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
5945 struct xdr_stream *xdr,
5946 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948 struct compound_hdr hdr;
5949 int status;
5950
Chuck Leverbf269552010-12-14 14:59:29 +00005951 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005952 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005953 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954 return status;
5955}
5956
5957/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005958 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005959 */
Chuck Leverbf269552010-12-14 14:59:29 +00005960static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
5961 struct xdr_stream *xdr,
5962 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005964 struct compound_hdr hdr;
5965 int status;
5966
Chuck Leverbf269552010-12-14 14:59:29 +00005967 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005968 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005969 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005971 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005973 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974 return status;
5975}
5976
5977/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005978 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979 */
Chuck Leverbf269552010-12-14 14:59:29 +00005980static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
5981 struct xdr_stream *xdr,
5982 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005983{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984 struct compound_hdr hdr;
5985 int status;
5986
Chuck Leverbf269552010-12-14 14:59:29 +00005987 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005988 if (status)
5989 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005990 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005991 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005992 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005993 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01005994 if (status != 0)
5995 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005996 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04005997 if (status != 0)
5998 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005999 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006000 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01006001out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002 return status;
6003}
6004
Trond Myklebust683b57b2006-06-09 09:34:22 -04006005/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006006 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006007 */
Chuck Leverbf269552010-12-14 14:59:29 +00006008static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6009 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006010 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006011{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006012 struct compound_hdr hdr;
6013 int status;
6014
Chuck Leverbf269552010-12-14 14:59:29 +00006015 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006016 if (status)
6017 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006018 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006019 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006020 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006021 status = decode_putfh(xdr);
6022 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006023 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006024 status = decode_lookup(xdr);
6025 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006026 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006027 xdr_enter_page(xdr, PAGE_SIZE);
6028 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006029 res->fs_locations->server,
6030 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006031out:
6032 return status;
6033}
6034
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006035/*
6036 * Decode SECINFO response
6037 */
6038static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6039 struct xdr_stream *xdr,
6040 struct nfs4_secinfo_res *res)
6041{
6042 struct compound_hdr hdr;
6043 int status;
6044
6045 status = decode_compound_hdr(xdr, &hdr);
6046 if (status)
6047 goto out;
6048 status = decode_sequence(xdr, &res->seq_res, rqstp);
6049 if (status)
6050 goto out;
6051 status = decode_putfh(xdr);
6052 if (status)
6053 goto out;
6054 status = decode_secinfo(xdr, res);
6055 if (status)
6056 goto out;
6057out:
6058 return status;
6059}
6060
Benny Halevy99fe60d2009-04-01 09:22:29 -04006061#if defined(CONFIG_NFS_V4_1)
6062/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006063 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006064 */
Chuck Leverbf269552010-12-14 14:59:29 +00006065static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6066 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006067 void *res)
6068{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006069 struct compound_hdr hdr;
6070 int status;
6071
Chuck Leverbf269552010-12-14 14:59:29 +00006072 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006073 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006074 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006075 return status;
6076}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006077
6078/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006079 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006080 */
Chuck Leverbf269552010-12-14 14:59:29 +00006081static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6082 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006083 struct nfs41_create_session_res *res)
6084{
Andy Adamsonfc931582009-04-01 09:22:31 -04006085 struct compound_hdr hdr;
6086 int status;
6087
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006089 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006090 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006091 return status;
6092}
6093
6094/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006095 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006096 */
Chuck Leverbf269552010-12-14 14:59:29 +00006097static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6098 struct xdr_stream *xdr,
6099 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006100{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006101 struct compound_hdr hdr;
6102 int status;
6103
Chuck Leverbf269552010-12-14 14:59:29 +00006104 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006105 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006106 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006107 return status;
6108}
6109
6110/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006111 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006112 */
Chuck Leverbf269552010-12-14 14:59:29 +00006113static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6114 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006115 struct nfs4_sequence_res *res)
6116{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006117 struct compound_hdr hdr;
6118 int status;
6119
Chuck Leverbf269552010-12-14 14:59:29 +00006120 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006121 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006122 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006123 return status;
6124}
6125
6126/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006127 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006128 */
Chuck Leverbf269552010-12-14 14:59:29 +00006129static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6130 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006131 struct nfs4_get_lease_time_res *res)
6132{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006133 struct compound_hdr hdr;
6134 int status;
6135
Chuck Leverbf269552010-12-14 14:59:29 +00006136 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006137 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006138 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006139 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006140 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006141 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006142 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006143 return status;
6144}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006145
6146/*
6147 * Decode RECLAIM_COMPLETE response
6148 */
Chuck Leverbf269552010-12-14 14:59:29 +00006149static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6150 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006151 struct nfs41_reclaim_complete_res *res)
6152{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006153 struct compound_hdr hdr;
6154 int status;
6155
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006157 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006158 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006159 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006160 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006161 return status;
6162}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006163
6164/*
6165 * Decode GETDEVINFO response
6166 */
Chuck Leverbf269552010-12-14 14:59:29 +00006167static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6168 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006169 struct nfs4_getdeviceinfo_res *res)
6170{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006171 struct compound_hdr hdr;
6172 int status;
6173
Chuck Leverbf269552010-12-14 14:59:29 +00006174 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006175 if (status != 0)
6176 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006178 if (status != 0)
6179 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006180 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006181out:
6182 return status;
6183}
6184
6185/*
6186 * Decode LAYOUTGET response
6187 */
Chuck Leverbf269552010-12-14 14:59:29 +00006188static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6189 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006190 struct nfs4_layoutget_res *res)
6191{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006192 struct compound_hdr hdr;
6193 int status;
6194
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006196 if (status)
6197 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006199 if (status)
6200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006202 if (status)
6203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006205out:
6206 return status;
6207}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006208#endif /* CONFIG_NFS_V4_1 */
6209
Chuck Lever573c4e12010-12-14 14:58:11 +00006210/**
6211 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6212 * the local page cache.
6213 * @xdr: XDR stream where entry resides
6214 * @entry: buffer to fill in with entry data
6215 * @plus: boolean indicating whether this should be a readdirplus entry
6216 *
6217 * Returns zero if successful, otherwise a negative errno value is
6218 * returned.
6219 *
6220 * This function is not invoked during READDIR reply decoding, but
6221 * rather whenever an application invokes the getdents(2) system call
6222 * on a directory already in our cache.
6223 */
6224int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6225 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226{
6227 uint32_t bitmap[2] = {0};
6228 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006229 __be32 *p = xdr_inline_decode(xdr, 4);
6230 if (unlikely(!p))
6231 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006232 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006233 p = xdr_inline_decode(xdr, 4);
6234 if (unlikely(!p))
6235 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006236 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006237 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006239 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240 }
6241
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006242 p = xdr_inline_decode(xdr, 12);
6243 if (unlikely(!p))
6244 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245 entry->prev_cookie = entry->cookie;
6246 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006247 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006248
Trond Myklebust9af8c222010-10-24 11:52:55 -04006249 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006250 if (unlikely(!p))
6251 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006252 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253
6254 /*
6255 * In case the server doesn't return an inode number,
6256 * we fake one here. (We don't use inode number 0,
6257 * since glibc seems to choke on it...)
6258 */
6259 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006260 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261
Trond Myklebust9af8c222010-10-24 11:52:55 -04006262 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006263 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006264
6265 if (decode_attr_length(xdr, &len, &p) < 0)
6266 goto out_overflow;
6267
Chuck Lever573c4e12010-12-14 14:58:11 +00006268 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6269 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006270 goto out_overflow;
6271 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6272 entry->ino = entry->fattr->fileid;
6273
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006274 entry->d_type = DT_UNKNOWN;
6275 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6276 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6277
Chuck Lever573c4e12010-12-14 14:58:11 +00006278 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006279
6280out_overflow:
6281 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006282 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006283}
6284
6285/*
6286 * We need to translate between nfs status return values and
6287 * the local errno values which may not be the same.
6288 */
6289static struct {
6290 int stat;
6291 int errno;
6292} nfs_errtbl[] = {
6293 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006294 { NFS4ERR_PERM, -EPERM },
6295 { NFS4ERR_NOENT, -ENOENT },
6296 { NFS4ERR_IO, -errno_NFSERR_IO},
6297 { NFS4ERR_NXIO, -ENXIO },
6298 { NFS4ERR_ACCESS, -EACCES },
6299 { NFS4ERR_EXIST, -EEXIST },
6300 { NFS4ERR_XDEV, -EXDEV },
6301 { NFS4ERR_NOTDIR, -ENOTDIR },
6302 { NFS4ERR_ISDIR, -EISDIR },
6303 { NFS4ERR_INVAL, -EINVAL },
6304 { NFS4ERR_FBIG, -EFBIG },
6305 { NFS4ERR_NOSPC, -ENOSPC },
6306 { NFS4ERR_ROFS, -EROFS },
6307 { NFS4ERR_MLINK, -EMLINK },
6308 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6309 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6310 { NFS4ERR_DQUOT, -EDQUOT },
6311 { NFS4ERR_STALE, -ESTALE },
6312 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006313 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6314 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6315 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006316 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006317 { NFS4ERR_BADTYPE, -EBADTYPE },
6318 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006319 { NFS4ERR_SYMLINK, -ELOOP },
6320 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6321 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006322 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323};
6324
6325/*
6326 * Convert an NFS error code to a local one.
6327 * This one is used jointly by NFSv2 and NFSv3.
6328 */
6329static int
David Howells0a8ea432006-08-22 20:06:08 -04006330nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331{
6332 int i;
6333 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6334 if (nfs_errtbl[i].stat == stat)
6335 return nfs_errtbl[i].errno;
6336 }
6337 if (stat <= 10000 || stat > 10100) {
6338 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006339 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340 }
6341 /* If we cannot translate the error, the recovery routines should
6342 * handle it.
6343 * Note: remaining NFSv4 error codes have values > 10000, so should
6344 * not conflict with native Linux error codes.
6345 */
Benny Halevy856dff32008-03-31 17:39:06 +03006346 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006347}
6348
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349#define PROC(proc, argtype, restype) \
6350[NFSPROC4_CLNT_##proc] = { \
6351 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006352 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006353 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006354 .p_arglen = NFS4_##argtype##_sz, \
6355 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006356 .p_statidx = NFSPROC4_CLNT_##proc, \
6357 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006358}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359
6360struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006361 PROC(READ, enc_read, dec_read),
6362 PROC(WRITE, enc_write, dec_write),
6363 PROC(COMMIT, enc_commit, dec_commit),
6364 PROC(OPEN, enc_open, dec_open),
6365 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6366 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6367 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6368 PROC(CLOSE, enc_close, dec_close),
6369 PROC(SETATTR, enc_setattr, dec_setattr),
6370 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6371 PROC(RENEW, enc_renew, dec_renew),
6372 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6373 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6374 PROC(LOCK, enc_lock, dec_lock),
6375 PROC(LOCKT, enc_lockt, dec_lockt),
6376 PROC(LOCKU, enc_locku, dec_locku),
6377 PROC(ACCESS, enc_access, dec_access),
6378 PROC(GETATTR, enc_getattr, dec_getattr),
6379 PROC(LOOKUP, enc_lookup, dec_lookup),
6380 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6381 PROC(REMOVE, enc_remove, dec_remove),
6382 PROC(RENAME, enc_rename, dec_rename),
6383 PROC(LINK, enc_link, dec_link),
6384 PROC(SYMLINK, enc_symlink, dec_symlink),
6385 PROC(CREATE, enc_create, dec_create),
6386 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6387 PROC(STATFS, enc_statfs, dec_statfs),
6388 PROC(READLINK, enc_readlink, dec_readlink),
6389 PROC(READDIR, enc_readdir, dec_readdir),
6390 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6391 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6392 PROC(GETACL, enc_getacl, dec_getacl),
6393 PROC(SETACL, enc_setacl, dec_setacl),
6394 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6395 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006396 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006397#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006398 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6399 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6400 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6401 PROC(SEQUENCE, enc_sequence, dec_sequence),
6402 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6403 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6404 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6405 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006406#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407};
6408
6409struct rpc_version nfs_version4 = {
6410 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006411 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006412 .procs = nfs4_procedures
6413};
6414
6415/*
6416 * Local variables:
6417 * c-basic-offset: 8
6418 * End:
6419 */