blob: 98afcf947aa4886011461583bec349900abe9271 [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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
117#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;
2969 }
2970 return 0;
2971out_overflow:
2972 print_overflow_msg(__func__, xdr);
2973 return -EIO;
2974}
2975
2976static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
2977{
2978 __be32 *p;
2979 int len;
2980
Trond Myklebust7ad07352010-10-23 15:34:20 -04002981 if (fh != NULL)
2982 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04002983
2984 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
2985 return -EIO;
2986 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
2987 p = xdr_inline_decode(xdr, 4);
2988 if (unlikely(!p))
2989 goto out_overflow;
2990 len = be32_to_cpup(p);
2991 if (len > NFS4_FHSIZE)
2992 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04002993 p = xdr_inline_decode(xdr, len);
2994 if (unlikely(!p))
2995 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04002996 if (fh != NULL) {
2997 memcpy(fh->data, p, len);
2998 fh->size = len;
2999 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003000 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3001 }
3002 return 0;
3003out_overflow:
3004 print_overflow_msg(__func__, xdr);
3005 return -EIO;
3006}
3007
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3009{
Al Viro8687b632006-10-19 23:28:48 -07003010 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011
3012 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3013 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3014 return -EIO;
3015 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003016 p = xdr_inline_decode(xdr, 4);
3017 if (unlikely(!p))
3018 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003019 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3021 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003022 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003024out_overflow:
3025 print_overflow_msg(__func__, xdr);
3026 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027}
3028
3029static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3030{
Al Viro8687b632006-10-19 23:28:48 -07003031 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003032 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033
3034 *fileid = 0;
3035 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3036 return -EIO;
3037 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003038 p = xdr_inline_decode(xdr, 8);
3039 if (unlikely(!p))
3040 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003041 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003043 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003045 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003046 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003047out_overflow:
3048 print_overflow_msg(__func__, xdr);
3049 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050}
3051
Manoj Naik99baf622006-06-09 09:34:24 -04003052static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3053{
Al Viro8687b632006-10-19 23:28:48 -07003054 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003055 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003056
3057 *fileid = 0;
3058 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3059 return -EIO;
3060 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003061 p = xdr_inline_decode(xdr, 8);
3062 if (unlikely(!p))
3063 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003064 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003065 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003066 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003067 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003068 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003069 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003070out_overflow:
3071 print_overflow_msg(__func__, xdr);
3072 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003073}
3074
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3076{
Al Viro8687b632006-10-19 23:28:48 -07003077 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078 int status = 0;
3079
3080 *res = 0;
3081 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3082 return -EIO;
3083 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003084 p = xdr_inline_decode(xdr, 8);
3085 if (unlikely(!p))
3086 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003087 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3089 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003090 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003092out_overflow:
3093 print_overflow_msg(__func__, xdr);
3094 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095}
3096
3097static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3098{
Al Viro8687b632006-10-19 23:28:48 -07003099 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 int status = 0;
3101
3102 *res = 0;
3103 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3104 return -EIO;
3105 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003106 p = xdr_inline_decode(xdr, 8);
3107 if (unlikely(!p))
3108 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003109 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3111 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003112 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003114out_overflow:
3115 print_overflow_msg(__func__, xdr);
3116 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117}
3118
3119static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3120{
Al Viro8687b632006-10-19 23:28:48 -07003121 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 int status = 0;
3123
3124 *res = 0;
3125 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3126 return -EIO;
3127 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003128 p = xdr_inline_decode(xdr, 8);
3129 if (unlikely(!p))
3130 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003131 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3133 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003134 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003136out_overflow:
3137 print_overflow_msg(__func__, xdr);
3138 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139}
3140
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003141static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3142{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003143 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003144 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003145 int status = 0;
3146
Benny Halevyc0eae662009-08-14 17:20:14 +03003147 p = xdr_inline_decode(xdr, 4);
3148 if (unlikely(!p))
3149 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003150 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003151 if (n == 0)
3152 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003153 dprintk("path ");
3154 path->ncomponents = 0;
3155 while (path->ncomponents < n) {
3156 struct nfs4_string *component = &path->components[path->ncomponents];
3157 status = decode_opaque_inline(xdr, &component->len, &component->data);
3158 if (unlikely(status != 0))
3159 goto out_eio;
3160 if (path->ncomponents != n)
3161 dprintk("/");
3162 dprintk("%s", component->data);
3163 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3164 path->ncomponents++;
3165 else {
3166 dprintk("cannot parse %d components in path\n", n);
3167 goto out_eio;
3168 }
3169 }
3170out:
3171 dprintk("\n");
3172 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003173root_path:
3174/* a root pathname is sent as a zero component4 */
3175 path->ncomponents = 1;
3176 path->components[0].len=0;
3177 path->components[0].data=NULL;
3178 dprintk("path /\n");
3179 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003180out_eio:
3181 dprintk(" status %d", status);
3182 status = -EIO;
3183 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003184out_overflow:
3185 print_overflow_msg(__func__, xdr);
3186 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003187}
3188
3189static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003190{
3191 int n;
Al Viro8687b632006-10-19 23:28:48 -07003192 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003193 int status = -EIO;
3194
3195 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3196 goto out;
3197 status = 0;
3198 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3199 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003200 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003201 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003202 if (unlikely(status != 0))
3203 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003204 p = xdr_inline_decode(xdr, 4);
3205 if (unlikely(!p))
3206 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003207 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003208 if (n <= 0)
3209 goto out_eio;
3210 res->nlocations = 0;
3211 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003212 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003213 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003214
Benny Halevyc0eae662009-08-14 17:20:14 +03003215 p = xdr_inline_decode(xdr, 4);
3216 if (unlikely(!p))
3217 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003218 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003219
3220 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003221 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003222 while (loc->nservers < m) {
3223 struct nfs4_string *server = &loc->servers[loc->nservers];
3224 status = decode_opaque_inline(xdr, &server->len, &server->data);
3225 if (unlikely(status != 0))
3226 goto out_eio;
3227 dprintk("%s ", server->data);
3228 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3229 loc->nservers++;
3230 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003231 unsigned int i;
3232 dprintk("%s: using first %u of %u servers "
3233 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003234 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003235 NFS4_FS_LOCATION_MAXSERVERS,
3236 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003237 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003238 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003239 char *data;
3240 status = decode_opaque_inline(xdr, &len, &data);
3241 if (unlikely(status != 0))
3242 goto out_eio;
3243 }
3244 }
3245 }
3246 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003247 if (unlikely(status != 0))
3248 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003249 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003250 res->nlocations++;
3251 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003252 if (res->nlocations != 0)
3253 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003254out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003255 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003256 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003257out_overflow:
3258 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003259out_eio:
3260 status = -EIO;
3261 goto out;
3262}
3263
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3265{
Al Viro8687b632006-10-19 23:28:48 -07003266 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 int status = 0;
3268
3269 *res = 0;
3270 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3271 return -EIO;
3272 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003273 p = xdr_inline_decode(xdr, 8);
3274 if (unlikely(!p))
3275 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003276 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3278 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003279 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003281out_overflow:
3282 print_overflow_msg(__func__, xdr);
3283 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284}
3285
3286static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3287{
Al Viro8687b632006-10-19 23:28:48 -07003288 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 int status = 0;
3290
3291 *maxlink = 1;
3292 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3293 return -EIO;
3294 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003295 p = xdr_inline_decode(xdr, 4);
3296 if (unlikely(!p))
3297 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003298 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3300 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003301 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003303out_overflow:
3304 print_overflow_msg(__func__, xdr);
3305 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306}
3307
3308static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3309{
Al Viro8687b632006-10-19 23:28:48 -07003310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 int status = 0;
3312
3313 *maxname = 1024;
3314 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3315 return -EIO;
3316 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003317 p = xdr_inline_decode(xdr, 4);
3318 if (unlikely(!p))
3319 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003320 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3322 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003323 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003325out_overflow:
3326 print_overflow_msg(__func__, xdr);
3327 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328}
3329
3330static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3331{
Al Viro8687b632006-10-19 23:28:48 -07003332 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 int status = 0;
3334
3335 *res = 1024;
3336 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3337 return -EIO;
3338 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3339 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003340 p = xdr_inline_decode(xdr, 8);
3341 if (unlikely(!p))
3342 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003343 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 if (maxread > 0x7FFFFFFF)
3345 maxread = 0x7FFFFFFF;
3346 *res = (uint32_t)maxread;
3347 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3348 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003349 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003351out_overflow:
3352 print_overflow_msg(__func__, xdr);
3353 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354}
3355
3356static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3357{
Al Viro8687b632006-10-19 23:28:48 -07003358 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 int status = 0;
3360
3361 *res = 1024;
3362 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3363 return -EIO;
3364 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3365 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003366 p = xdr_inline_decode(xdr, 8);
3367 if (unlikely(!p))
3368 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003369 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 if (maxwrite > 0x7FFFFFFF)
3371 maxwrite = 0x7FFFFFFF;
3372 *res = (uint32_t)maxwrite;
3373 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3374 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003375 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003377out_overflow:
3378 print_overflow_msg(__func__, xdr);
3379 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380}
3381
Trond Myklebustbca79472009-03-11 14:10:26 -04003382static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383{
Trond Myklebustbca79472009-03-11 14:10:26 -04003384 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003385 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003386 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387
3388 *mode = 0;
3389 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3390 return -EIO;
3391 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003392 p = xdr_inline_decode(xdr, 4);
3393 if (unlikely(!p))
3394 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003395 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003396 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003398 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003400 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003401 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003402out_overflow:
3403 print_overflow_msg(__func__, xdr);
3404 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405}
3406
3407static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3408{
Al Viro8687b632006-10-19 23:28:48 -07003409 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003410 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411
3412 *nlink = 1;
3413 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3414 return -EIO;
3415 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003416 p = xdr_inline_decode(xdr, 4);
3417 if (unlikely(!p))
3418 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003419 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003421 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003423 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003424 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003425out_overflow:
3426 print_overflow_msg(__func__, xdr);
3427 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428}
3429
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003430static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003431 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432{
Al Viro8687b632006-10-19 23:28:48 -07003433 uint32_t len;
3434 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003435 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436
3437 *uid = -2;
3438 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3439 return -EIO;
3440 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003441 p = xdr_inline_decode(xdr, 4);
3442 if (unlikely(!p))
3443 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003444 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003445 p = xdr_inline_decode(xdr, len);
3446 if (unlikely(!p))
3447 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003448 if (!may_sleep) {
3449 /* do nothing */
3450 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003451 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003452 ret = NFS_ATTR_FATTR_OWNER;
3453 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003455 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003457 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003458 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3460 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003461 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003462 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003463out_overflow:
3464 print_overflow_msg(__func__, xdr);
3465 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466}
3467
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003468static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003469 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470{
Al Viro8687b632006-10-19 23:28:48 -07003471 uint32_t len;
3472 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003473 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474
3475 *gid = -2;
3476 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3477 return -EIO;
3478 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003479 p = xdr_inline_decode(xdr, 4);
3480 if (unlikely(!p))
3481 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003482 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003483 p = xdr_inline_decode(xdr, len);
3484 if (unlikely(!p))
3485 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003486 if (!may_sleep) {
3487 /* do nothing */
3488 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003489 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003490 ret = NFS_ATTR_FATTR_GROUP;
3491 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003493 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003495 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003496 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3498 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003499 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003500 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003501out_overflow:
3502 print_overflow_msg(__func__, xdr);
3503 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504}
3505
3506static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3507{
Al Viro8687b632006-10-19 23:28:48 -07003508 uint32_t major = 0, minor = 0;
3509 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003510 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511
3512 *rdev = MKDEV(0,0);
3513 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3514 return -EIO;
3515 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3516 dev_t tmp;
3517
Benny Halevyc0eae662009-08-14 17:20:14 +03003518 p = xdr_inline_decode(xdr, 8);
3519 if (unlikely(!p))
3520 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003521 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003522 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 tmp = MKDEV(major, minor);
3524 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3525 *rdev = tmp;
3526 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003527 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003529 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003530 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003531out_overflow:
3532 print_overflow_msg(__func__, xdr);
3533 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534}
3535
3536static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3537{
Al Viro8687b632006-10-19 23:28:48 -07003538 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 int status = 0;
3540
3541 *res = 0;
3542 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3543 return -EIO;
3544 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003545 p = xdr_inline_decode(xdr, 8);
3546 if (unlikely(!p))
3547 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003548 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3550 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003551 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003553out_overflow:
3554 print_overflow_msg(__func__, xdr);
3555 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556}
3557
3558static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3559{
Al Viro8687b632006-10-19 23:28:48 -07003560 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561 int status = 0;
3562
3563 *res = 0;
3564 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3565 return -EIO;
3566 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003567 p = xdr_inline_decode(xdr, 8);
3568 if (unlikely(!p))
3569 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003570 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3572 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003573 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003575out_overflow:
3576 print_overflow_msg(__func__, xdr);
3577 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578}
3579
3580static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3581{
Al Viro8687b632006-10-19 23:28:48 -07003582 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 int status = 0;
3584
3585 *res = 0;
3586 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3587 return -EIO;
3588 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003589 p = xdr_inline_decode(xdr, 8);
3590 if (unlikely(!p))
3591 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003592 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3594 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003595 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003597out_overflow:
3598 print_overflow_msg(__func__, xdr);
3599 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600}
3601
3602static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3603{
Al Viro8687b632006-10-19 23:28:48 -07003604 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003605 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606
3607 *used = 0;
3608 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3609 return -EIO;
3610 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003611 p = xdr_inline_decode(xdr, 8);
3612 if (unlikely(!p))
3613 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003614 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003616 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003618 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003620 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003621out_overflow:
3622 print_overflow_msg(__func__, xdr);
3623 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624}
3625
3626static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3627{
Al Viro8687b632006-10-19 23:28:48 -07003628 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 uint64_t sec;
3630 uint32_t nsec;
3631
Benny Halevyc0eae662009-08-14 17:20:14 +03003632 p = xdr_inline_decode(xdr, 12);
3633 if (unlikely(!p))
3634 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003635 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003636 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 time->tv_sec = (time_t)sec;
3638 time->tv_nsec = (long)nsec;
3639 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003640out_overflow:
3641 print_overflow_msg(__func__, xdr);
3642 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643}
3644
3645static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3646{
3647 int status = 0;
3648
3649 time->tv_sec = 0;
3650 time->tv_nsec = 0;
3651 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3652 return -EIO;
3653 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3654 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003655 if (status == 0)
3656 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3658 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003659 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 return status;
3661}
3662
3663static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3664{
3665 int status = 0;
3666
3667 time->tv_sec = 0;
3668 time->tv_nsec = 0;
3669 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3670 return -EIO;
3671 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3672 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003673 if (status == 0)
3674 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3676 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003677 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 return status;
3679}
3680
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003681static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3682 struct timespec *time)
3683{
3684 int status = 0;
3685
3686 time->tv_sec = 0;
3687 time->tv_nsec = 0;
3688 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3689 return -EIO;
3690 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3691 status = decode_attr_time(xdr, time);
3692 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3693 }
3694 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3695 (long)time->tv_nsec);
3696 return status;
3697}
3698
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3700{
3701 int status = 0;
3702
3703 time->tv_sec = 0;
3704 time->tv_nsec = 0;
3705 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3706 return -EIO;
3707 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3708 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003709 if (status == 0)
3710 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3712 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003713 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 return status;
3715}
3716
Al Viro8687b632006-10-19 23:28:48 -07003717static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718{
3719 unsigned int attrwords = XDR_QUADLEN(attrlen);
3720 unsigned int nwords = xdr->p - savep;
3721
3722 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003723 dprintk("%s: server returned incorrect attribute length: "
3724 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003725 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 attrwords << 2,
3727 (attrwords < nwords) ? '<' : '>',
3728 nwords << 2);
3729 return -EIO;
3730 }
3731 return 0;
3732}
3733
3734static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3735{
Al Viro8687b632006-10-19 23:28:48 -07003736 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737
Benny Halevyc0eae662009-08-14 17:20:14 +03003738 p = xdr_inline_decode(xdr, 20);
3739 if (unlikely(!p))
3740 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003741 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003742 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003743 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003745out_overflow:
3746 print_overflow_msg(__func__, xdr);
3747 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748}
3749
3750static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3751{
Al Viro8687b632006-10-19 23:28:48 -07003752 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 uint32_t supp, acc;
3754 int status;
3755
3756 status = decode_op_hdr(xdr, OP_ACCESS);
3757 if (status)
3758 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003759 p = xdr_inline_decode(xdr, 8);
3760 if (unlikely(!p))
3761 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003762 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003763 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764 access->supported = supp;
3765 access->access = acc;
3766 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003767out_overflow:
3768 print_overflow_msg(__func__, xdr);
3769 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770}
3771
Benny Halevy07d30432009-08-14 17:19:52 +03003772static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773{
Al Viro8687b632006-10-19 23:28:48 -07003774 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003775
3776 p = xdr_inline_decode(xdr, len);
3777 if (likely(p)) {
3778 memcpy(buf, p, len);
3779 return 0;
3780 }
3781 print_overflow_msg(__func__, xdr);
3782 return -EIO;
3783}
3784
3785static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3786{
3787 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788}
3789
3790static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3791{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 int status;
3793
3794 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003795 if (status != -EIO)
3796 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003797 if (!status)
3798 status = decode_stateid(xdr, &res->stateid);
3799 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800}
3801
Benny Halevydb942bb2009-08-14 17:19:56 +03003802static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3803{
3804 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805}
3806
3807static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3808{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 int status;
3810
3811 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003812 if (!status)
3813 status = decode_verifier(xdr, res->verf->verifier);
3814 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815}
3816
3817static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3818{
Al Viro8687b632006-10-19 23:28:48 -07003819 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 uint32_t bmlen;
3821 int status;
3822
3823 status = decode_op_hdr(xdr, OP_CREATE);
3824 if (status)
3825 return status;
3826 if ((status = decode_change_info(xdr, cinfo)))
3827 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003828 p = xdr_inline_decode(xdr, 4);
3829 if (unlikely(!p))
3830 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003831 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003832 p = xdr_inline_decode(xdr, bmlen << 2);
3833 if (likely(p))
3834 return 0;
3835out_overflow:
3836 print_overflow_msg(__func__, xdr);
3837 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838}
3839
3840static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3841{
Al Viro8687b632006-10-19 23:28:48 -07003842 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003843 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 int status;
3845
3846 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3847 goto xdr_error;
3848 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3849 goto xdr_error;
3850 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3851 goto xdr_error;
3852 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3853 goto xdr_error;
3854 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3855 goto xdr_error;
3856 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3857 goto xdr_error;
3858 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3859 goto xdr_error;
3860 status = verify_attr_len(xdr, savep, attrlen);
3861xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003862 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 return status;
3864}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003865
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3867{
Al Viro8687b632006-10-19 23:28:48 -07003868 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003869 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003871
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3873 goto xdr_error;
3874 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3875 goto xdr_error;
3876 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3877 goto xdr_error;
3878
3879 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3880 goto xdr_error;
3881 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3882 goto xdr_error;
3883 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3884 goto xdr_error;
3885 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3886 goto xdr_error;
3887 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3888 goto xdr_error;
3889 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3890 goto xdr_error;
3891
3892 status = verify_attr_len(xdr, savep, attrlen);
3893xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003894 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 return status;
3896}
3897
3898static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3899{
Al Viro8687b632006-10-19 23:28:48 -07003900 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003901 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003903
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3905 goto xdr_error;
3906 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3907 goto xdr_error;
3908 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3909 goto xdr_error;
3910
3911 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3912 goto xdr_error;
3913 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3914 goto xdr_error;
3915
3916 status = verify_attr_len(xdr, savep, attrlen);
3917xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003918 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 return status;
3920}
3921
Bryan Schumakerae42c702010-10-21 16:33:17 -04003922static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
3923 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003924 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925{
Trond Myklebustbca79472009-03-11 14:10:26 -04003926 int status;
3927 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003928 uint64_t fileid;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003929 uint32_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003931 status = decode_attr_type(xdr, bitmap, &type);
3932 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003934 fattr->mode = 0;
3935 if (status != 0) {
3936 fattr->mode |= nfs_type2fmt[type];
3937 fattr->valid |= status;
3938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003940 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3941 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003943 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003944
3945 status = decode_attr_size(xdr, bitmap, &fattr->size);
3946 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003948 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003949
3950 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3951 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003953 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003954
Bryan Schumakerae42c702010-10-21 16:33:17 -04003955 status = decode_attr_error(xdr, bitmap);
3956 if (status < 0)
3957 goto xdr_error;
3958
3959 status = decode_attr_filehandle(xdr, bitmap, fh);
3960 if (status < 0)
3961 goto xdr_error;
3962
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003963 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3964 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003966 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003967
3968 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003969 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003970 fattr));
3971 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003972 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003973 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003974
3975 status = decode_attr_mode(xdr, bitmap, &fmode);
3976 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003978 if (status != 0) {
3979 fattr->mode |= fmode;
3980 fattr->valid |= status;
3981 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003982
3983 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3984 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003986 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003987
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003988 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003989 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_group(xdr, bitmap, server, &fattr->gid, 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
3998 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3999 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_space_used(xdr, bitmap, &fattr->du.nfs3.used);
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_time_access(xdr, bitmap, &fattr->atime);
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_metadata(xdr, bitmap, &fattr->ctime);
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_modify(xdr, bitmap, &fattr->mtime);
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_mounted_on_fileid(xdr, bitmap, &fileid);
4024 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004025 goto xdr_error;
Trond Myklebust3201f3d2010-10-23 15:43:10 -04004026 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04004027 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04004028 fattr->valid |= status;
4029 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004030
Bryan Schumakerae42c702010-10-21 16:33:17 -04004031xdr_error:
4032 dprintk("%s: xdr returned %d\n", __func__, -status);
4033 return status;
4034}
4035
4036static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4037 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4038{
4039 __be32 *savep;
4040 uint32_t attrlen,
4041 bitmap[2] = {0};
4042 int status;
4043
4044 status = decode_op_hdr(xdr, OP_GETATTR);
4045 if (status < 0)
4046 goto xdr_error;
4047
4048 status = decode_attr_bitmap(xdr, bitmap);
4049 if (status < 0)
4050 goto xdr_error;
4051
4052 status = decode_attr_length(xdr, &attrlen, &savep);
4053 if (status < 0)
4054 goto xdr_error;
4055
4056 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4057 if (status < 0)
4058 goto xdr_error;
4059
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004060 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004062 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 return status;
4064}
4065
Bryan Schumakerae42c702010-10-21 16:33:17 -04004066static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4067 const struct nfs_server *server, int may_sleep)
4068{
4069 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4070}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071
Andy Adamson504913f2010-10-20 00:17:57 -04004072/*
4073 * Decode potentially multiple layout types. Currently we only support
4074 * one layout driver per file system.
4075 */
4076static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4077 uint32_t *layouttype)
4078{
4079 uint32_t *p;
4080 int num;
4081
4082 p = xdr_inline_decode(xdr, 4);
4083 if (unlikely(!p))
4084 goto out_overflow;
4085 num = be32_to_cpup(p);
4086
4087 /* pNFS is not supported by the underlying file system */
4088 if (num == 0) {
4089 *layouttype = 0;
4090 return 0;
4091 }
4092 if (num > 1)
4093 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4094 "per filesystem not supported\n", __func__);
4095
4096 /* Decode and set first layout type, move xdr->p past unused types */
4097 p = xdr_inline_decode(xdr, num * 4);
4098 if (unlikely(!p))
4099 goto out_overflow;
4100 *layouttype = be32_to_cpup(p);
4101 return 0;
4102out_overflow:
4103 print_overflow_msg(__func__, xdr);
4104 return -EIO;
4105}
4106
4107/*
4108 * The type of file system exported.
4109 * Note we must ensure that layouttype is set in any non-error case.
4110 */
4111static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4112 uint32_t *layouttype)
4113{
4114 int status = 0;
4115
4116 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4117 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4118 return -EIO;
4119 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4120 status = decode_first_pnfs_layout_type(xdr, layouttype);
4121 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4122 } else
4123 *layouttype = 0;
4124 return status;
4125}
4126
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4128{
Al Viro8687b632006-10-19 23:28:48 -07004129 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130 uint32_t attrlen, bitmap[2];
4131 int status;
4132
4133 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4134 goto xdr_error;
4135 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4136 goto xdr_error;
4137 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4138 goto xdr_error;
4139
4140 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4141
4142 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4143 goto xdr_error;
4144 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4145 goto xdr_error;
4146 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4147 goto xdr_error;
4148 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4149 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4150 goto xdr_error;
4151 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004152 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4153 if (status != 0)
4154 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004155 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4156 if (status != 0)
4157 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158
4159 status = verify_attr_len(xdr, savep, attrlen);
4160xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004161 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162 return status;
4163}
4164
4165static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4166{
Al Viro8687b632006-10-19 23:28:48 -07004167 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168 uint32_t len;
4169 int status;
4170
Trond Myklebust99367812007-07-17 21:52:41 -04004171 /* Zero handle first to allow comparisons */
4172 memset(fh, 0, sizeof(*fh));
4173
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 status = decode_op_hdr(xdr, OP_GETFH);
4175 if (status)
4176 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177
Benny Halevyc0eae662009-08-14 17:20:14 +03004178 p = xdr_inline_decode(xdr, 4);
4179 if (unlikely(!p))
4180 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004181 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 if (len > NFS4_FHSIZE)
4183 return -EIO;
4184 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004185 p = xdr_inline_decode(xdr, len);
4186 if (unlikely(!p))
4187 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004188 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004190out_overflow:
4191 print_overflow_msg(__func__, xdr);
4192 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193}
4194
4195static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4196{
4197 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004198
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 status = decode_op_hdr(xdr, OP_LINK);
4200 if (status)
4201 return status;
4202 return decode_change_info(xdr, cinfo);
4203}
4204
4205/*
4206 * We create the owner, so we know a proper owner.id length is 4.
4207 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004208static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004210 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004211 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004212 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004214 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004215 if (unlikely(!p))
4216 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004217 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004218 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004219 type = be32_to_cpup(p++); /* 4 byte read */
4220 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004221 fl->fl_start = (loff_t)offset;
4222 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4223 if (length == ~(uint64_t)0)
4224 fl->fl_end = OFFSET_MAX;
4225 fl->fl_type = F_WRLCK;
4226 if (type & 1)
4227 fl->fl_type = F_RDLCK;
4228 fl->fl_pid = 0;
4229 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004230 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4231 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4232 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004233 if (likely(p))
4234 return -NFS4ERR_DENIED;
4235out_overflow:
4236 print_overflow_msg(__func__, xdr);
4237 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238}
4239
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004240static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004241{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242 int status;
4243
4244 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004245 if (status == -EIO)
4246 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004248 status = decode_stateid(xdr, &res->stateid);
4249 if (unlikely(status))
4250 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004252 status = decode_lock_denied(xdr, NULL);
4253 if (res->open_seqid != NULL)
4254 nfs_increment_open_seqid(status, res->open_seqid);
4255 nfs_increment_lock_seqid(status, res->lock_seqid);
4256out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 return status;
4258}
4259
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004260static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004261{
4262 int status;
4263 status = decode_op_hdr(xdr, OP_LOCKT);
4264 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004265 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004266 return status;
4267}
4268
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004269static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271 int status;
4272
4273 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004274 if (status != -EIO)
4275 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004276 if (status == 0)
4277 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 return status;
4279}
4280
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004281static int decode_release_lockowner(struct xdr_stream *xdr)
4282{
4283 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4284}
4285
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286static int decode_lookup(struct xdr_stream *xdr)
4287{
4288 return decode_op_hdr(xdr, OP_LOOKUP);
4289}
4290
4291/* This is too sick! */
4292static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4293{
Andy Adamson05d564f2008-12-23 16:06:15 -05004294 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295 uint32_t limit_type, nblocks, blocksize;
4296
Benny Halevyc0eae662009-08-14 17:20:14 +03004297 p = xdr_inline_decode(xdr, 12);
4298 if (unlikely(!p))
4299 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004300 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004302 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004303 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004304 break;
4305 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004306 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004307 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004308 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 }
4310 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004311out_overflow:
4312 print_overflow_msg(__func__, xdr);
4313 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314}
4315
4316static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4317{
Andy Adamson05d564f2008-12-23 16:06:15 -05004318 __be32 *p;
4319 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004320 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321
Benny Halevyc0eae662009-08-14 17:20:14 +03004322 p = xdr_inline_decode(xdr, 4);
4323 if (unlikely(!p))
4324 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004325 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4327 res->delegation_type = 0;
4328 return 0;
4329 }
Benny Halevy07d30432009-08-14 17:19:52 +03004330 status = decode_stateid(xdr, &res->delegation);
4331 if (unlikely(status))
4332 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004333 p = xdr_inline_decode(xdr, 4);
4334 if (unlikely(!p))
4335 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004336 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004337
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004339 case NFS4_OPEN_DELEGATE_READ:
4340 res->delegation_type = FMODE_READ;
4341 break;
4342 case NFS4_OPEN_DELEGATE_WRITE:
4343 res->delegation_type = FMODE_WRITE|FMODE_READ;
4344 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 return -EIO;
4346 }
David Howells7539bba2006-08-22 20:06:09 -04004347 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004348out_overflow:
4349 print_overflow_msg(__func__, xdr);
4350 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351}
4352
4353static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4354{
Andy Adamson05d564f2008-12-23 16:06:15 -05004355 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004356 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004357 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358
Andy Adamson05d564f2008-12-23 16:06:15 -05004359 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004360 if (status != -EIO)
4361 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004362 if (!status)
4363 status = decode_stateid(xdr, &res->stateid);
4364 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004365 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366
Andy Adamson05d564f2008-12-23 16:06:15 -05004367 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368
Benny Halevyc0eae662009-08-14 17:20:14 +03004369 p = xdr_inline_decode(xdr, 8);
4370 if (unlikely(!p))
4371 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004372 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004373 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004374 if (bmlen > 10)
4375 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376
Benny Halevyc0eae662009-08-14 17:20:14 +03004377 p = xdr_inline_decode(xdr, bmlen << 2);
4378 if (unlikely(!p))
4379 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004380 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4381 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004382 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004383 for (; i < NFS4_BITMAP_SIZE; i++)
4384 res->attrset[i] = 0;
4385
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 return decode_delegation(xdr, res);
4387xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004388 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004390out_overflow:
4391 print_overflow_msg(__func__, xdr);
4392 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393}
4394
4395static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4396{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 int status;
4398
Andy Adamson05d564f2008-12-23 16:06:15 -05004399 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004400 if (status != -EIO)
4401 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004402 if (!status)
4403 status = decode_stateid(xdr, &res->stateid);
4404 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405}
4406
4407static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4408{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409 int status;
4410
4411 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004412 if (status != -EIO)
4413 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004414 if (!status)
4415 status = decode_stateid(xdr, &res->stateid);
4416 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417}
4418
4419static int decode_putfh(struct xdr_stream *xdr)
4420{
4421 return decode_op_hdr(xdr, OP_PUTFH);
4422}
4423
4424static int decode_putrootfh(struct xdr_stream *xdr)
4425{
4426 return decode_op_hdr(xdr, OP_PUTROOTFH);
4427}
4428
4429static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4430{
4431 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004432 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433 uint32_t count, eof, recvd, hdrlen;
4434 int status;
4435
4436 status = decode_op_hdr(xdr, OP_READ);
4437 if (status)
4438 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004439 p = xdr_inline_decode(xdr, 8);
4440 if (unlikely(!p))
4441 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004442 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004443 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004444 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445 recvd = req->rq_rcv_buf.len - hdrlen;
4446 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004447 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 "count %u > recvd %u\n", count, recvd);
4449 count = recvd;
4450 eof = 0;
4451 }
4452 xdr_read_pages(xdr, count);
4453 res->eof = eof;
4454 res->count = count;
4455 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004456out_overflow:
4457 print_overflow_msg(__func__, xdr);
4458 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459}
4460
4461static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4462{
4463 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004465 size_t hdrlen;
4466 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004467 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468
4469 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004470 if (!status)
4471 status = decode_verifier(xdr, readdir->verifier.data);
4472 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004474 dprintk("%s: verifier = %08x:%08x\n",
4475 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004476 ((u32 *)readdir->verifier.data)[0],
4477 ((u32 *)readdir->verifier.data)[1]);
4478
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479
Benny Halevydb942bb2009-08-14 17:19:56 +03004480 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481 recvd = rcvbuf->len - hdrlen;
4482 if (pglen > recvd)
4483 pglen = recvd;
4484 xdr_read_pages(xdr, pglen);
4485
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004486
Trond Myklebustac396122010-11-15 20:26:22 -05004487 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488}
4489
4490static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4491{
4492 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4493 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004494 size_t hdrlen;
4495 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004496 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 int status;
4498
4499 status = decode_op_hdr(xdr, OP_READLINK);
4500 if (status)
4501 return status;
4502
4503 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004504 p = xdr_inline_decode(xdr, 4);
4505 if (unlikely(!p))
4506 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004507 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004509 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510 return -ENAMETOOLONG;
4511 }
4512 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4513 recvd = req->rq_rcv_buf.len - hdrlen;
4514 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004515 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 "count %u > recvd %u\n", len, recvd);
4517 return -EIO;
4518 }
4519 xdr_read_pages(xdr, len);
4520 /*
4521 * The XDR encode routine has set things up so that
4522 * the link text will be copied directly into the
4523 * buffer. We just have to do overflow-checking,
4524 * and and null-terminate the text (the VFS expects
4525 * null-termination).
4526 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004527 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004529out_overflow:
4530 print_overflow_msg(__func__, xdr);
4531 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532}
4533
4534static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4535{
4536 int status;
4537
4538 status = decode_op_hdr(xdr, OP_REMOVE);
4539 if (status)
4540 goto out;
4541 status = decode_change_info(xdr, cinfo);
4542out:
4543 return status;
4544}
4545
4546static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4547 struct nfs4_change_info *new_cinfo)
4548{
4549 int status;
4550
4551 status = decode_op_hdr(xdr, OP_RENAME);
4552 if (status)
4553 goto out;
4554 if ((status = decode_change_info(xdr, old_cinfo)))
4555 goto out;
4556 status = decode_change_info(xdr, new_cinfo);
4557out:
4558 return status;
4559}
4560
4561static int decode_renew(struct xdr_stream *xdr)
4562{
4563 return decode_op_hdr(xdr, OP_RENEW);
4564}
4565
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004566static int
4567decode_restorefh(struct xdr_stream *xdr)
4568{
4569 return decode_op_hdr(xdr, OP_RESTOREFH);
4570}
4571
J. Bruce Fields029d1052005-06-22 17:16:22 +00004572static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4573 size_t *acl_len)
4574{
Al Viro8687b632006-10-19 23:28:48 -07004575 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004576 uint32_t attrlen,
4577 bitmap[2] = {0};
4578 struct kvec *iov = req->rq_rcv_buf.head;
4579 int status;
4580
4581 *acl_len = 0;
4582 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4583 goto out;
4584 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4585 goto out;
4586 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4587 goto out;
4588
4589 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4590 return -EIO;
4591 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004592 size_t hdrlen;
4593 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004594
4595 /* We ignore &savep and don't do consistency checks on
4596 * the attr length. Let userspace figure it out.... */
4597 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4598 recvd = req->rq_rcv_buf.len - hdrlen;
4599 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004600 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004601 " acl reply: attrlen %u > recvd %u\n",
4602 attrlen, recvd);
4603 return -EINVAL;
4604 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004605 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004606 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004607 } else
4608 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004609
4610out:
4611 return status;
4612}
4613
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614static int
4615decode_savefh(struct xdr_stream *xdr)
4616{
4617 return decode_op_hdr(xdr, OP_SAVEFH);
4618}
4619
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004620static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621{
Al Viro8687b632006-10-19 23:28:48 -07004622 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623 uint32_t bmlen;
4624 int status;
4625
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626 status = decode_op_hdr(xdr, OP_SETATTR);
4627 if (status)
4628 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004629 p = xdr_inline_decode(xdr, 4);
4630 if (unlikely(!p))
4631 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004632 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004633 p = xdr_inline_decode(xdr, bmlen << 2);
4634 if (likely(p))
4635 return 0;
4636out_overflow:
4637 print_overflow_msg(__func__, xdr);
4638 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639}
4640
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004641static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642{
Al Viro8687b632006-10-19 23:28:48 -07004643 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 uint32_t opnum;
4645 int32_t nfserr;
4646
Benny Halevyc0eae662009-08-14 17:20:14 +03004647 p = xdr_inline_decode(xdr, 8);
4648 if (unlikely(!p))
4649 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004650 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004652 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004653 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 return -EIO;
4655 }
Benny Halevycccddf42009-08-14 17:20:19 +03004656 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004658 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4659 if (unlikely(!p))
4660 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004661 p = xdr_decode_hyper(p, &res->clientid);
4662 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004663 } else if (nfserr == NFSERR_CLID_INUSE) {
4664 uint32_t len;
4665
4666 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004667 p = xdr_inline_decode(xdr, 4);
4668 if (unlikely(!p))
4669 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004670 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004671 p = xdr_inline_decode(xdr, len);
4672 if (unlikely(!p))
4673 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674
4675 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004676 p = xdr_inline_decode(xdr, 4);
4677 if (unlikely(!p))
4678 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004679 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004680 p = xdr_inline_decode(xdr, len);
4681 if (unlikely(!p))
4682 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683 return -NFSERR_CLID_INUSE;
4684 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004685 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686
4687 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004688out_overflow:
4689 print_overflow_msg(__func__, xdr);
4690 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691}
4692
4693static int decode_setclientid_confirm(struct xdr_stream *xdr)
4694{
4695 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4696}
4697
4698static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4699{
Al Viro8687b632006-10-19 23:28:48 -07004700 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701 int status;
4702
4703 status = decode_op_hdr(xdr, OP_WRITE);
4704 if (status)
4705 return status;
4706
Benny Halevyc0eae662009-08-14 17:20:14 +03004707 p = xdr_inline_decode(xdr, 16);
4708 if (unlikely(!p))
4709 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004710 res->count = be32_to_cpup(p++);
4711 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004712 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004714out_overflow:
4715 print_overflow_msg(__func__, xdr);
4716 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004717}
4718
4719static int decode_delegreturn(struct xdr_stream *xdr)
4720{
4721 return decode_op_hdr(xdr, OP_DELEGRETURN);
4722}
4723
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004724static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
4725{
4726 __be32 *p;
4727
4728 p = xdr_inline_decode(xdr, 4);
4729 if (unlikely(!p))
4730 goto out_overflow;
4731 flavor->gss.sec_oid4.len = be32_to_cpup(p);
4732 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
4733 goto out_err;
4734
4735 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
4736 if (unlikely(!p))
4737 goto out_overflow;
4738 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
4739
4740 p = xdr_inline_decode(xdr, 8);
4741 if (unlikely(!p))
4742 goto out_overflow;
4743 flavor->gss.qop4 = be32_to_cpup(p++);
4744 flavor->gss.service = be32_to_cpup(p);
4745
4746 return 0;
4747
4748out_overflow:
4749 print_overflow_msg(__func__, xdr);
4750 return -EIO;
4751out_err:
4752 return -EINVAL;
4753}
4754
4755static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
4756{
4757 struct nfs4_secinfo_flavor *sec_flavor;
4758 int status;
4759 __be32 *p;
4760 int i;
4761
4762 status = decode_op_hdr(xdr, OP_SECINFO);
4763 p = xdr_inline_decode(xdr, 4);
4764 if (unlikely(!p))
4765 goto out_overflow;
4766 res->flavors->num_flavors = be32_to_cpup(p);
4767
4768 for (i = 0; i < res->flavors->num_flavors; i++) {
4769 sec_flavor = &res->flavors->flavors[i];
4770 if ((char *)&sec_flavor[1] - (char *)res > PAGE_SIZE)
4771 break;
4772
4773 p = xdr_inline_decode(xdr, 4);
4774 if (unlikely(!p))
4775 goto out_overflow;
4776 sec_flavor->flavor = be32_to_cpup(p);
4777
4778 if (sec_flavor->flavor == RPC_AUTH_GSS) {
4779 if (decode_secinfo_gss(xdr, sec_flavor))
4780 break;
4781 }
4782 }
4783
4784 return 0;
4785
4786out_overflow:
4787 print_overflow_msg(__func__, xdr);
4788 return -EIO;
4789}
4790
Benny Halevy99fe60d2009-04-01 09:22:29 -04004791#if defined(CONFIG_NFS_V4_1)
4792static int decode_exchange_id(struct xdr_stream *xdr,
4793 struct nfs41_exchange_id_res *res)
4794{
4795 __be32 *p;
4796 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004797 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004798 int status;
4799 struct nfs_client *clp = res->client;
4800
4801 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4802 if (status)
4803 return status;
4804
Benny Halevyc0eae662009-08-14 17:20:14 +03004805 p = xdr_inline_decode(xdr, 8);
4806 if (unlikely(!p))
4807 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05004808 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004809 p = xdr_inline_decode(xdr, 12);
4810 if (unlikely(!p))
4811 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004812 clp->cl_seqid = be32_to_cpup(p++);
4813 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004814
4815 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004816 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004817 if (dummy != SP4_NONE)
4818 return -EIO;
4819
4820 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004821 p = xdr_inline_decode(xdr, 8);
4822 if (unlikely(!p))
4823 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004824
4825 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004826 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4827 if (unlikely(status))
4828 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004829
4830 /* Throw away server_scope */
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 Implementation id array */
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 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004841out_overflow:
4842 print_overflow_msg(__func__, xdr);
4843 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004844}
Andy Adamsonfc931582009-04-01 09:22:31 -04004845
4846static int decode_chan_attrs(struct xdr_stream *xdr,
4847 struct nfs4_channel_attrs *attrs)
4848{
4849 __be32 *p;
4850 u32 nr_attrs;
4851
Benny Halevyc0eae662009-08-14 17:20:14 +03004852 p = xdr_inline_decode(xdr, 28);
4853 if (unlikely(!p))
4854 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004855 attrs->headerpadsz = be32_to_cpup(p++);
4856 attrs->max_rqst_sz = be32_to_cpup(p++);
4857 attrs->max_resp_sz = be32_to_cpup(p++);
4858 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4859 attrs->max_ops = be32_to_cpup(p++);
4860 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004861 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004862 if (unlikely(nr_attrs > 1)) {
4863 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4864 __func__, nr_attrs);
4865 return -EINVAL;
4866 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004867 if (nr_attrs == 1) {
4868 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4869 if (unlikely(!p))
4870 goto out_overflow;
4871 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004872 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004873out_overflow:
4874 print_overflow_msg(__func__, xdr);
4875 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004876}
4877
Benny Halevye78291e2009-08-14 17:20:00 +03004878static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4879{
4880 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004881}
4882
4883static int decode_create_session(struct xdr_stream *xdr,
4884 struct nfs41_create_session_res *res)
4885{
4886 __be32 *p;
4887 int status;
4888 struct nfs_client *clp = res->client;
4889 struct nfs4_session *session = clp->cl_session;
4890
4891 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004892 if (!status)
4893 status = decode_sessionid(xdr, &session->sess_id);
4894 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004895 return status;
4896
Andy Adamsonfc931582009-04-01 09:22:31 -04004897 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004898 p = xdr_inline_decode(xdr, 8);
4899 if (unlikely(!p))
4900 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004901 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004902 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004903
4904 /* Channel attributes */
4905 status = decode_chan_attrs(xdr, &session->fc_attrs);
4906 if (!status)
4907 status = decode_chan_attrs(xdr, &session->bc_attrs);
4908 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004909out_overflow:
4910 print_overflow_msg(__func__, xdr);
4911 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004912}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004913
4914static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4915{
4916 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4917}
Ricardo Labiaga180197532009-12-05 16:08:40 -05004918
4919static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4920{
4921 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4922}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004923#endif /* CONFIG_NFS_V4_1 */
4924
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004925static int decode_sequence(struct xdr_stream *xdr,
4926 struct nfs4_sequence_res *res,
4927 struct rpc_rqst *rqstp)
4928{
4929#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004930 struct nfs4_sessionid id;
4931 u32 dummy;
4932 int status;
4933 __be32 *p;
4934
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004935 if (!res->sr_session)
4936 return 0;
4937
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004938 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004939 if (!status)
4940 status = decode_sessionid(xdr, &id);
4941 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004942 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004943
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004944 /*
4945 * If the server returns different values for sessionID, slotID or
4946 * sequence number, the server is looney tunes.
4947 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05004948 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004949
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004950 if (memcmp(id.data, res->sr_session->sess_id.data,
4951 NFS4_MAX_SESSIONID_LEN)) {
4952 dprintk("%s Invalid session id\n", __func__);
4953 goto out_err;
4954 }
Benny Halevye78291e2009-08-14 17:20:00 +03004955
Benny Halevyc0eae662009-08-14 17:20:14 +03004956 p = xdr_inline_decode(xdr, 20);
4957 if (unlikely(!p))
4958 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004959
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004960 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03004961 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004962 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004963 dprintk("%s Invalid sequence number\n", __func__);
4964 goto out_err;
4965 }
4966 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004967 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04004968 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004969 dprintk("%s Invalid slot id\n", __func__);
4970 goto out_err;
4971 }
4972 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004973 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004974 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004975 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05004976 /* result flags */
4977 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004978 status = 0;
4979out_err:
4980 res->sr_status = status;
4981 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004982out_overflow:
4983 print_overflow_msg(__func__, xdr);
4984 status = -EIO;
4985 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004986#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004987 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004988#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004989}
4990
Andy Adamsonb1f69b72010-10-20 00:18:03 -04004991#if defined(CONFIG_NFS_V4_1)
4992
4993static int decode_getdeviceinfo(struct xdr_stream *xdr,
4994 struct pnfs_device *pdev)
4995{
4996 __be32 *p;
4997 uint32_t len, type;
4998 int status;
4999
5000 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5001 if (status) {
5002 if (status == -ETOOSMALL) {
5003 p = xdr_inline_decode(xdr, 4);
5004 if (unlikely(!p))
5005 goto out_overflow;
5006 pdev->mincount = be32_to_cpup(p);
5007 dprintk("%s: Min count too small. mincnt = %u\n",
5008 __func__, pdev->mincount);
5009 }
5010 return status;
5011 }
5012
5013 p = xdr_inline_decode(xdr, 8);
5014 if (unlikely(!p))
5015 goto out_overflow;
5016 type = be32_to_cpup(p++);
5017 if (type != pdev->layout_type) {
5018 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5019 __func__, pdev->layout_type, type);
5020 return -EINVAL;
5021 }
5022 /*
5023 * Get the length of the opaque device_addr4. xdr_read_pages places
5024 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5025 * and places the remaining xdr data in xdr_buf->tail
5026 */
5027 pdev->mincount = be32_to_cpup(p);
5028 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5029
5030 /* Parse notification bitmap, verifying that it is zero. */
5031 p = xdr_inline_decode(xdr, 4);
5032 if (unlikely(!p))
5033 goto out_overflow;
5034 len = be32_to_cpup(p);
5035 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005036 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005037
5038 p = xdr_inline_decode(xdr, 4 * len);
5039 if (unlikely(!p))
5040 goto out_overflow;
5041 for (i = 0; i < len; i++, p++) {
5042 if (be32_to_cpup(p)) {
5043 dprintk("%s: notifications not supported\n",
5044 __func__);
5045 return -EIO;
5046 }
5047 }
5048 }
5049 return 0;
5050out_overflow:
5051 print_overflow_msg(__func__, xdr);
5052 return -EIO;
5053}
5054
5055static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5056 struct nfs4_layoutget_res *res)
5057{
5058 __be32 *p;
5059 int status;
5060 u32 layout_count;
5061
5062 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5063 if (status)
5064 return status;
5065 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5066 if (unlikely(!p))
5067 goto out_overflow;
5068 res->return_on_close = be32_to_cpup(p++);
5069 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5070 layout_count = be32_to_cpup(p);
5071 if (!layout_count) {
5072 dprintk("%s: server responded with empty layout array\n",
5073 __func__);
5074 return -EINVAL;
5075 }
5076
5077 p = xdr_inline_decode(xdr, 24);
5078 if (unlikely(!p))
5079 goto out_overflow;
5080 p = xdr_decode_hyper(p, &res->range.offset);
5081 p = xdr_decode_hyper(p, &res->range.length);
5082 res->range.iomode = be32_to_cpup(p++);
5083 res->type = be32_to_cpup(p++);
5084
5085 status = decode_opaque_inline(xdr, &res->layout.len, (char **)&p);
5086 if (unlikely(status))
5087 return status;
5088
5089 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5090 __func__,
5091 (unsigned long)res->range.offset,
5092 (unsigned long)res->range.length,
5093 res->range.iomode,
5094 res->type,
5095 res->layout.len);
5096
5097 /* nfs4_proc_layoutget allocated a single page */
5098 if (res->layout.len > PAGE_SIZE)
5099 return -ENOMEM;
5100 memcpy(res->layout.buf, p, res->layout.len);
5101
5102 if (layout_count > 1) {
5103 /* We only handle a length one array at the moment. Any
5104 * further entries are just ignored. Note that this means
5105 * the client may see a response that is less than the
5106 * minimum it requested.
5107 */
5108 dprintk("%s: server responded with %d layouts, dropping tail\n",
5109 __func__, layout_count);
5110 }
5111
5112 return 0;
5113out_overflow:
5114 print_overflow_msg(__func__, xdr);
5115 return -EIO;
5116}
5117#endif /* CONFIG_NFS_V4_1 */
5118
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119/*
Benny Halevy49c25592008-12-23 16:06:16 -05005120 * END OF "GENERIC" DECODE ROUTINES.
5121 */
5122
5123/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124 * Decode OPEN_DOWNGRADE response
5125 */
Chuck Leverbf269552010-12-14 14:59:29 +00005126static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5127 struct xdr_stream *xdr,
5128 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129{
Andy Adamson05d564f2008-12-23 16:06:15 -05005130 struct compound_hdr hdr;
5131 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132
Chuck Leverbf269552010-12-14 14:59:29 +00005133 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005134 if (status)
5135 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005136 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005137 if (status)
5138 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005139 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005140 if (status)
5141 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005142 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005143 if (status != 0)
5144 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005145 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005146 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005148 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149}
5150
5151/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152 * Decode ACCESS response
5153 */
Chuck Leverbf269552010-12-14 14:59:29 +00005154static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5155 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 struct compound_hdr hdr;
5158 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005159
Chuck Leverbf269552010-12-14 14:59:29 +00005160 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005161 if (status)
5162 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005163 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005164 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005166 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005167 if (status != 0)
5168 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005169 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005170 if (status != 0)
5171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005172 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005173 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005174out:
5175 return status;
5176}
5177
5178/*
5179 * Decode LOOKUP response
5180 */
Chuck Leverbf269552010-12-14 14:59:29 +00005181static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5182 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005183{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005184 struct compound_hdr hdr;
5185 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005186
Chuck Leverbf269552010-12-14 14:59:29 +00005187 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005188 if (status)
5189 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005190 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005191 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005192 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005193 status = decode_putfh(xdr);
5194 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005196 status = decode_lookup(xdr);
5197 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005198 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005199 status = decode_getfh(xdr, res->fh);
5200 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005201 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005202 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005203 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204out:
5205 return status;
5206}
5207
5208/*
5209 * Decode LOOKUP_ROOT response
5210 */
Chuck Leverbf269552010-12-14 14:59:29 +00005211static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5212 struct xdr_stream *xdr,
5213 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215 struct compound_hdr hdr;
5216 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005217
Chuck Leverbf269552010-12-14 14:59:29 +00005218 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005219 if (status)
5220 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005221 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005222 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005224 status = decode_putrootfh(xdr);
5225 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005226 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005227 status = decode_getfh(xdr, res->fh);
5228 if (status == 0)
5229 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005230 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231out:
5232 return status;
5233}
5234
5235/*
5236 * Decode REMOVE response
5237 */
Chuck Leverbf269552010-12-14 14:59:29 +00005238static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5239 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241 struct compound_hdr hdr;
5242 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005243
Chuck Leverbf269552010-12-14 14:59:29 +00005244 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005245 if (status)
5246 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005247 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005248 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005250 status = decode_putfh(xdr);
5251 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005252 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005253 status = decode_remove(xdr, &res->cinfo);
5254 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005255 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005256 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005257 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258out:
5259 return status;
5260}
5261
5262/*
5263 * Decode RENAME response
5264 */
Chuck Leverbf269552010-12-14 14:59:29 +00005265static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5266 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005268 struct compound_hdr hdr;
5269 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005270
Chuck Leverbf269552010-12-14 14:59:29 +00005271 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005272 if (status)
5273 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005274 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005275 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005277 status = decode_putfh(xdr);
5278 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005280 status = decode_savefh(xdr);
5281 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005283 status = decode_putfh(xdr);
5284 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005286 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5287 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005288 goto out;
5289 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005290 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005291 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005292 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005293 status = decode_restorefh(xdr);
5294 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005295 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005296 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005297 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298out:
5299 return status;
5300}
5301
5302/*
5303 * Decode LINK response
5304 */
Chuck Leverbf269552010-12-14 14:59:29 +00005305static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5306 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005307{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308 struct compound_hdr hdr;
5309 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005310
Chuck Leverbf269552010-12-14 14:59:29 +00005311 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005312 if (status)
5313 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005314 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005315 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005317 status = decode_putfh(xdr);
5318 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005320 status = decode_savefh(xdr);
5321 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005322 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005323 status = decode_putfh(xdr);
5324 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005326 status = decode_link(xdr, &res->cinfo);
5327 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005328 goto out;
5329 /*
5330 * Note order: OP_LINK leaves the directory as the current
5331 * filehandle.
5332 */
Chuck Leverbf269552010-12-14 14:59:29 +00005333 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005334 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005335 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005336 status = decode_restorefh(xdr);
5337 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005338 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005339 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005340 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005341out:
5342 return status;
5343}
5344
5345/*
5346 * Decode CREATE response
5347 */
Chuck Leverbf269552010-12-14 14:59:29 +00005348static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5349 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005350{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351 struct compound_hdr hdr;
5352 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005353
Chuck Leverbf269552010-12-14 14:59:29 +00005354 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005355 if (status)
5356 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005357 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005358 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005359 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005360 status = decode_putfh(xdr);
5361 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005362 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005363 status = decode_savefh(xdr);
5364 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005365 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005366 status = decode_create(xdr, &res->dir_cinfo);
5367 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005368 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005369 status = decode_getfh(xdr, res->fh);
5370 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005371 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005372 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005373 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005374 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005375 status = decode_restorefh(xdr);
5376 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005377 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005378 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005379 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005380out:
5381 return status;
5382}
5383
5384/*
5385 * Decode SYMLINK response
5386 */
Chuck Leverbf269552010-12-14 14:59:29 +00005387static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5388 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389{
Chuck Leverbf269552010-12-14 14:59:29 +00005390 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005391}
5392
5393/*
5394 * Decode GETATTR response
5395 */
Chuck Leverbf269552010-12-14 14:59:29 +00005396static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5397 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005398{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005399 struct compound_hdr hdr;
5400 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005401
Chuck Leverbf269552010-12-14 14:59:29 +00005402 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005403 if (status)
5404 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005405 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005406 if (status)
5407 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005408 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005409 if (status)
5410 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005411 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005412 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413out:
5414 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005415}
5416
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005417/*
5418 * Encode an SETACL request
5419 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005420static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5421 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005422{
Andy Adamson05d564f2008-12-23 16:06:15 -05005423 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005424 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005425 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005426
Chuck Lever9f06c712010-12-14 14:59:18 +00005427 encode_compound_hdr(xdr, req, &hdr);
5428 encode_sequence(xdr, &args->seq_args, &hdr);
5429 encode_putfh(xdr, args->fh, &hdr);
5430 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005431 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005432}
Andy Adamson05d564f2008-12-23 16:06:15 -05005433
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005434/*
5435 * Decode SETACL response
5436 */
5437static int
Chuck Leverbf269552010-12-14 14:59:29 +00005438nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005439 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005440{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005441 struct compound_hdr hdr;
5442 int status;
5443
Chuck Leverbf269552010-12-14 14:59:29 +00005444 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005445 if (status)
5446 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005447 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005448 if (status)
5449 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005450 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005451 if (status)
5452 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005453 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005454out:
5455 return status;
5456}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005457
5458/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005459 * Decode GETACL response
5460 */
5461static int
Chuck Leverbf269552010-12-14 14:59:29 +00005462nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005463 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005464{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005465 struct compound_hdr hdr;
5466 int status;
5467
Chuck Leverbf269552010-12-14 14:59:29 +00005468 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005469 if (status)
5470 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005471 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005472 if (status)
5473 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005474 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005475 if (status)
5476 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005477 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005478
5479out:
5480 return status;
5481}
5482
5483/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005484 * Decode CLOSE response
5485 */
Chuck Leverbf269552010-12-14 14:59:29 +00005486static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5487 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005488{
Andy Adamson05d564f2008-12-23 16:06:15 -05005489 struct compound_hdr hdr;
5490 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005491
Chuck Leverbf269552010-12-14 14:59:29 +00005492 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005493 if (status)
5494 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005495 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005496 if (status)
5497 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005498 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005499 if (status)
5500 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005501 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005502 if (status != 0)
5503 goto out;
5504 /*
5505 * Note: Server may do delete on close for this file
5506 * in which case the getattr call will fail with
5507 * an ESTALE error. Shouldn't be a problem,
5508 * though, since fattr->valid will remain unset.
5509 */
Chuck Leverbf269552010-12-14 14:59:29 +00005510 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005511 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005512out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005513 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514}
5515
5516/*
5517 * Decode OPEN response
5518 */
Chuck Leverbf269552010-12-14 14:59:29 +00005519static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5520 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005521{
Andy Adamson05d564f2008-12-23 16:06:15 -05005522 struct compound_hdr hdr;
5523 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524
Chuck Leverbf269552010-12-14 14:59:29 +00005525 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005526 if (status)
5527 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005528 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005529 if (status)
5530 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005531 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005532 if (status)
5533 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005534 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005535 if (status)
5536 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005537 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005538 if (status)
5539 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005540 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005541 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005542 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005543 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005544 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005545 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005546 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005547 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005548 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005549out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005550 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005551}
5552
5553/*
5554 * Decode OPEN_CONFIRM response
5555 */
Chuck Leverbf269552010-12-14 14:59:29 +00005556static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5557 struct xdr_stream *xdr,
5558 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559{
Andy Adamson05d564f2008-12-23 16:06:15 -05005560 struct compound_hdr hdr;
5561 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005562
Chuck Leverbf269552010-12-14 14:59:29 +00005563 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005564 if (status)
5565 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005566 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005567 if (status)
5568 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005569 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005570out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005571 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005572}
5573
5574/*
5575 * Decode OPEN response
5576 */
Chuck Leverbf269552010-12-14 14:59:29 +00005577static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5578 struct xdr_stream *xdr,
5579 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005580{
Andy Adamson05d564f2008-12-23 16:06:15 -05005581 struct compound_hdr hdr;
5582 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005583
Chuck Leverbf269552010-12-14 14:59:29 +00005584 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005585 if (status)
5586 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005587 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005588 if (status)
5589 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005590 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005591 if (status)
5592 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005593 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005594 if (status)
5595 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005596 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005597 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005599 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005600}
5601
5602/*
5603 * Decode SETATTR response
5604 */
Chuck Leverbf269552010-12-14 14:59:29 +00005605static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5606 struct xdr_stream *xdr,
5607 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005608{
Andy Adamson05d564f2008-12-23 16:06:15 -05005609 struct compound_hdr hdr;
5610 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611
Chuck Leverbf269552010-12-14 14:59:29 +00005612 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005613 if (status)
5614 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005615 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005616 if (status)
5617 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005618 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005619 if (status)
5620 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005621 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005622 if (status)
5623 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005624 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005625 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005626out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005627 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005628}
5629
5630/*
5631 * Decode LOCK response
5632 */
Chuck Leverbf269552010-12-14 14:59:29 +00005633static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5634 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005635{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005636 struct compound_hdr hdr;
5637 int status;
5638
Chuck Leverbf269552010-12-14 14:59:29 +00005639 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005640 if (status)
5641 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005642 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005643 if (status)
5644 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005645 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005646 if (status)
5647 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005648 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005649out:
5650 return status;
5651}
5652
5653/*
5654 * Decode LOCKT response
5655 */
Chuck Leverbf269552010-12-14 14:59:29 +00005656static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5657 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005658{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005659 struct compound_hdr hdr;
5660 int status;
5661
Chuck Leverbf269552010-12-14 14:59:29 +00005662 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005663 if (status)
5664 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005665 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005666 if (status)
5667 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005668 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005669 if (status)
5670 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005671 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005672out:
5673 return status;
5674}
5675
5676/*
5677 * Decode LOCKU response
5678 */
Chuck Leverbf269552010-12-14 14:59:29 +00005679static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5680 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005681{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005682 struct compound_hdr hdr;
5683 int status;
5684
Chuck Leverbf269552010-12-14 14:59:29 +00005685 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686 if (status)
5687 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005688 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005689 if (status)
5690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005691 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692 if (status)
5693 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005694 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005695out:
5696 return status;
5697}
5698
Chuck Leverbf269552010-12-14 14:59:29 +00005699static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5700 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005701{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005702 struct compound_hdr hdr;
5703 int status;
5704
Chuck Leverbf269552010-12-14 14:59:29 +00005705 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005706 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005707 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005708 return status;
5709}
5710
Linus Torvalds1da177e2005-04-16 15:20:36 -07005711/*
5712 * Decode READLINK response
5713 */
Chuck Leverbf269552010-12-14 14:59:29 +00005714static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5715 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04005716 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005718 struct compound_hdr hdr;
5719 int status;
5720
Chuck Leverbf269552010-12-14 14:59:29 +00005721 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005722 if (status)
5723 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005724 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005725 if (status)
5726 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005727 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005728 if (status)
5729 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005730 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005731out:
5732 return status;
5733}
5734
5735/*
5736 * Decode READDIR response
5737 */
Chuck Leverbf269552010-12-14 14:59:29 +00005738static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5739 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005741 struct compound_hdr hdr;
5742 int status;
5743
Chuck Leverbf269552010-12-14 14:59:29 +00005744 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745 if (status)
5746 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005747 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005748 if (status)
5749 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005750 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005751 if (status)
5752 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005753 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005754out:
5755 return status;
5756}
5757
5758/*
5759 * Decode Read response
5760 */
Chuck Leverbf269552010-12-14 14:59:29 +00005761static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5762 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005764 struct compound_hdr hdr;
5765 int status;
5766
Chuck Leverbf269552010-12-14 14:59:29 +00005767 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005768 if (status)
5769 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005770 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005771 if (status)
5772 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005773 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005774 if (status)
5775 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005776 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005777 if (!status)
5778 status = res->count;
5779out:
5780 return status;
5781}
5782
5783/*
5784 * Decode WRITE response
5785 */
Chuck Leverbf269552010-12-14 14:59:29 +00005786static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5787 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005789 struct compound_hdr hdr;
5790 int status;
5791
Chuck Leverbf269552010-12-14 14:59:29 +00005792 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005793 if (status)
5794 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005795 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005796 if (status)
5797 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005798 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799 if (status)
5800 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005801 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005802 if (status)
5803 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00005804 if (res->fattr)
5805 decode_getfattr(xdr, res->fattr, res->server,
5806 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005807 if (!status)
5808 status = res->count;
5809out:
5810 return status;
5811}
5812
5813/*
5814 * Decode COMMIT response
5815 */
Chuck Leverbf269552010-12-14 14:59:29 +00005816static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5817 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005818{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005819 struct compound_hdr hdr;
5820 int status;
5821
Chuck Leverbf269552010-12-14 14:59:29 +00005822 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005823 if (status)
5824 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005825 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005826 if (status)
5827 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005828 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829 if (status)
5830 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005831 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005832 if (status)
5833 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005834 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005835 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836out:
5837 return status;
5838}
5839
5840/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005841 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842 */
Chuck Leverbf269552010-12-14 14:59:29 +00005843static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04005844 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005846 struct compound_hdr hdr;
5847 int status;
5848
Chuck Leverbf269552010-12-14 14:59:29 +00005849 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005851 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005852 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005853 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005855 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005856 return status;
5857}
5858
5859/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005860 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005861 */
Chuck Leverbf269552010-12-14 14:59:29 +00005862static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04005863 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005864{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865 struct compound_hdr hdr;
5866 int status;
5867
Chuck Leverbf269552010-12-14 14:59:29 +00005868 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005869 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005870 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005871 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005872 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005873 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005874 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005875 return status;
5876}
5877
5878/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005879 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005880 */
Chuck Leverbf269552010-12-14 14:59:29 +00005881static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04005882 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005883{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005884 struct compound_hdr hdr;
5885 int status;
5886
Chuck Leverbf269552010-12-14 14:59:29 +00005887 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005889 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005890 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005891 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005893 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894 return status;
5895}
5896
5897/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005898 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005899 */
Chuck Leverbf269552010-12-14 14:59:29 +00005900static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
5901 struct xdr_stream *xdr,
5902 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005904 struct compound_hdr hdr;
5905 int status;
5906
Chuck Leverbf269552010-12-14 14:59:29 +00005907 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005908 if (status)
5909 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005910 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005911 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005912 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005913 status = decode_putfh(xdr);
5914 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005915 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005916 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005917out:
5918 return status;
5919}
5920
5921/*
5922 * Decode RENEW response
5923 */
Chuck Leverbf269552010-12-14 14:59:29 +00005924static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5925 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927 struct compound_hdr hdr;
5928 int status;
5929
Chuck Leverbf269552010-12-14 14:59:29 +00005930 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005932 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005933 return status;
5934}
5935
5936/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005937 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005938 */
Chuck Leverbf269552010-12-14 14:59:29 +00005939static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
5940 struct xdr_stream *xdr,
5941 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005942{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005943 struct compound_hdr hdr;
5944 int status;
5945
Chuck Leverbf269552010-12-14 14:59:29 +00005946 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005948 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949 return status;
5950}
5951
5952/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005953 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954 */
Chuck Leverbf269552010-12-14 14:59:29 +00005955static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
5956 struct xdr_stream *xdr,
5957 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005958{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005959 struct compound_hdr hdr;
5960 int status;
5961
Chuck Leverbf269552010-12-14 14:59:29 +00005962 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005963 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005964 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005965 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005966 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005968 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005969 return status;
5970}
5971
5972/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005973 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974 */
Chuck Leverbf269552010-12-14 14:59:29 +00005975static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
5976 struct xdr_stream *xdr,
5977 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005978{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979 struct compound_hdr hdr;
5980 int status;
5981
Chuck Leverbf269552010-12-14 14:59:29 +00005982 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005983 if (status)
5984 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005985 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005986 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005987 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005988 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01005989 if (status != 0)
5990 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005991 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04005992 if (status != 0)
5993 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005994 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005995 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005996out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997 return status;
5998}
5999
Trond Myklebust683b57b2006-06-09 09:34:22 -04006000/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006001 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006002 */
Chuck Leverbf269552010-12-14 14:59:29 +00006003static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6004 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006005 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006006{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006007 struct compound_hdr hdr;
6008 int status;
6009
Chuck Leverbf269552010-12-14 14:59:29 +00006010 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006011 if (status)
6012 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006013 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006014 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006015 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006016 status = decode_putfh(xdr);
6017 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006018 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006019 status = decode_lookup(xdr);
6020 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006021 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006022 xdr_enter_page(xdr, PAGE_SIZE);
6023 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006024 res->fs_locations->server,
6025 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006026out:
6027 return status;
6028}
6029
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006030/*
6031 * Decode SECINFO response
6032 */
6033static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6034 struct xdr_stream *xdr,
6035 struct nfs4_secinfo_res *res)
6036{
6037 struct compound_hdr hdr;
6038 int status;
6039
6040 status = decode_compound_hdr(xdr, &hdr);
6041 if (status)
6042 goto out;
6043 status = decode_sequence(xdr, &res->seq_res, rqstp);
6044 if (status)
6045 goto out;
6046 status = decode_putfh(xdr);
6047 if (status)
6048 goto out;
6049 status = decode_secinfo(xdr, res);
6050 if (status)
6051 goto out;
6052out:
6053 return status;
6054}
6055
Benny Halevy99fe60d2009-04-01 09:22:29 -04006056#if defined(CONFIG_NFS_V4_1)
6057/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006058 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006059 */
Chuck Leverbf269552010-12-14 14:59:29 +00006060static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6061 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006062 void *res)
6063{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006064 struct compound_hdr hdr;
6065 int status;
6066
Chuck Leverbf269552010-12-14 14:59:29 +00006067 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006068 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006069 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006070 return status;
6071}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006072
6073/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006074 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006075 */
Chuck Leverbf269552010-12-14 14:59:29 +00006076static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6077 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006078 struct nfs41_create_session_res *res)
6079{
Andy Adamsonfc931582009-04-01 09:22:31 -04006080 struct compound_hdr hdr;
6081 int status;
6082
Chuck Leverbf269552010-12-14 14:59:29 +00006083 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006084 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006085 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006086 return status;
6087}
6088
6089/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006090 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006091 */
Chuck Leverbf269552010-12-14 14:59:29 +00006092static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6093 struct xdr_stream *xdr,
6094 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006095{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006096 struct compound_hdr hdr;
6097 int status;
6098
Chuck Leverbf269552010-12-14 14:59:29 +00006099 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006100 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006101 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006102 return status;
6103}
6104
6105/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006106 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006107 */
Chuck Leverbf269552010-12-14 14:59:29 +00006108static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6109 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006110 struct nfs4_sequence_res *res)
6111{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006112 struct compound_hdr hdr;
6113 int status;
6114
Chuck Leverbf269552010-12-14 14:59:29 +00006115 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006116 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006117 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006118 return status;
6119}
6120
6121/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006122 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006123 */
Chuck Leverbf269552010-12-14 14:59:29 +00006124static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6125 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006126 struct nfs4_get_lease_time_res *res)
6127{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006128 struct compound_hdr hdr;
6129 int status;
6130
Chuck Leverbf269552010-12-14 14:59:29 +00006131 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006132 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006133 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006134 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006135 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006136 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006137 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006138 return status;
6139}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006140
6141/*
6142 * Decode RECLAIM_COMPLETE response
6143 */
Chuck Leverbf269552010-12-14 14:59:29 +00006144static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6145 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006146 struct nfs41_reclaim_complete_res *res)
6147{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006148 struct compound_hdr hdr;
6149 int status;
6150
Chuck Leverbf269552010-12-14 14:59:29 +00006151 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006152 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006154 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006155 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006156 return status;
6157}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006158
6159/*
6160 * Decode GETDEVINFO response
6161 */
Chuck Leverbf269552010-12-14 14:59:29 +00006162static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6163 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006164 struct nfs4_getdeviceinfo_res *res)
6165{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006166 struct compound_hdr hdr;
6167 int status;
6168
Chuck Leverbf269552010-12-14 14:59:29 +00006169 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006170 if (status != 0)
6171 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006172 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006173 if (status != 0)
6174 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006175 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006176out:
6177 return status;
6178}
6179
6180/*
6181 * Decode LAYOUTGET response
6182 */
Chuck Leverbf269552010-12-14 14:59:29 +00006183static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6184 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006185 struct nfs4_layoutget_res *res)
6186{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006187 struct compound_hdr hdr;
6188 int status;
6189
Chuck Leverbf269552010-12-14 14:59:29 +00006190 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006191 if (status)
6192 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006193 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006194 if (status)
6195 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006196 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006197 if (status)
6198 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006199 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006200out:
6201 return status;
6202}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006203#endif /* CONFIG_NFS_V4_1 */
6204
Chuck Lever573c4e12010-12-14 14:58:11 +00006205/**
6206 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6207 * the local page cache.
6208 * @xdr: XDR stream where entry resides
6209 * @entry: buffer to fill in with entry data
6210 * @plus: boolean indicating whether this should be a readdirplus entry
6211 *
6212 * Returns zero if successful, otherwise a negative errno value is
6213 * returned.
6214 *
6215 * This function is not invoked during READDIR reply decoding, but
6216 * rather whenever an application invokes the getdents(2) system call
6217 * on a directory already in our cache.
6218 */
6219int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6220 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221{
6222 uint32_t bitmap[2] = {0};
6223 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006224 __be32 *p = xdr_inline_decode(xdr, 4);
6225 if (unlikely(!p))
6226 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006227 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006228 p = xdr_inline_decode(xdr, 4);
6229 if (unlikely(!p))
6230 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006231 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006232 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006234 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235 }
6236
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006237 p = xdr_inline_decode(xdr, 12);
6238 if (unlikely(!p))
6239 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240 entry->prev_cookie = entry->cookie;
6241 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006242 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006243
Trond Myklebust9af8c222010-10-24 11:52:55 -04006244 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006245 if (unlikely(!p))
6246 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006247 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006248
6249 /*
6250 * In case the server doesn't return an inode number,
6251 * we fake one here. (We don't use inode number 0,
6252 * since glibc seems to choke on it...)
6253 */
6254 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006255 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006256
Trond Myklebust9af8c222010-10-24 11:52:55 -04006257 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006258 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006259
6260 if (decode_attr_length(xdr, &len, &p) < 0)
6261 goto out_overflow;
6262
Chuck Lever573c4e12010-12-14 14:58:11 +00006263 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6264 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006265 goto out_overflow;
6266 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6267 entry->ino = entry->fattr->fileid;
6268
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006269 entry->d_type = DT_UNKNOWN;
6270 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6271 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6272
Chuck Lever573c4e12010-12-14 14:58:11 +00006273 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006274
6275out_overflow:
6276 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006277 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006278}
6279
6280/*
6281 * We need to translate between nfs status return values and
6282 * the local errno values which may not be the same.
6283 */
6284static struct {
6285 int stat;
6286 int errno;
6287} nfs_errtbl[] = {
6288 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006289 { NFS4ERR_PERM, -EPERM },
6290 { NFS4ERR_NOENT, -ENOENT },
6291 { NFS4ERR_IO, -errno_NFSERR_IO},
6292 { NFS4ERR_NXIO, -ENXIO },
6293 { NFS4ERR_ACCESS, -EACCES },
6294 { NFS4ERR_EXIST, -EEXIST },
6295 { NFS4ERR_XDEV, -EXDEV },
6296 { NFS4ERR_NOTDIR, -ENOTDIR },
6297 { NFS4ERR_ISDIR, -EISDIR },
6298 { NFS4ERR_INVAL, -EINVAL },
6299 { NFS4ERR_FBIG, -EFBIG },
6300 { NFS4ERR_NOSPC, -ENOSPC },
6301 { NFS4ERR_ROFS, -EROFS },
6302 { NFS4ERR_MLINK, -EMLINK },
6303 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6304 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6305 { NFS4ERR_DQUOT, -EDQUOT },
6306 { NFS4ERR_STALE, -ESTALE },
6307 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006308 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6309 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6310 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006311 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006312 { NFS4ERR_BADTYPE, -EBADTYPE },
6313 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006314 { NFS4ERR_SYMLINK, -ELOOP },
6315 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6316 { NFS4ERR_DEADLOCK, -EDEADLK },
6317 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318 * to be handled by a
6319 * middle-layer.
6320 */
Benny Halevy856dff32008-03-31 17:39:06 +03006321 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322};
6323
6324/*
6325 * Convert an NFS error code to a local one.
6326 * This one is used jointly by NFSv2 and NFSv3.
6327 */
6328static int
David Howells0a8ea432006-08-22 20:06:08 -04006329nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330{
6331 int i;
6332 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6333 if (nfs_errtbl[i].stat == stat)
6334 return nfs_errtbl[i].errno;
6335 }
6336 if (stat <= 10000 || stat > 10100) {
6337 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006338 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339 }
6340 /* If we cannot translate the error, the recovery routines should
6341 * handle it.
6342 * Note: remaining NFSv4 error codes have values > 10000, so should
6343 * not conflict with native Linux error codes.
6344 */
Benny Halevy856dff32008-03-31 17:39:06 +03006345 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006346}
6347
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348#define PROC(proc, argtype, restype) \
6349[NFSPROC4_CLNT_##proc] = { \
6350 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006351 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006352 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006353 .p_arglen = NFS4_##argtype##_sz, \
6354 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006355 .p_statidx = NFSPROC4_CLNT_##proc, \
6356 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006357}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358
6359struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006360 PROC(READ, enc_read, dec_read),
6361 PROC(WRITE, enc_write, dec_write),
6362 PROC(COMMIT, enc_commit, dec_commit),
6363 PROC(OPEN, enc_open, dec_open),
6364 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6365 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6366 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6367 PROC(CLOSE, enc_close, dec_close),
6368 PROC(SETATTR, enc_setattr, dec_setattr),
6369 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6370 PROC(RENEW, enc_renew, dec_renew),
6371 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6372 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6373 PROC(LOCK, enc_lock, dec_lock),
6374 PROC(LOCKT, enc_lockt, dec_lockt),
6375 PROC(LOCKU, enc_locku, dec_locku),
6376 PROC(ACCESS, enc_access, dec_access),
6377 PROC(GETATTR, enc_getattr, dec_getattr),
6378 PROC(LOOKUP, enc_lookup, dec_lookup),
6379 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6380 PROC(REMOVE, enc_remove, dec_remove),
6381 PROC(RENAME, enc_rename, dec_rename),
6382 PROC(LINK, enc_link, dec_link),
6383 PROC(SYMLINK, enc_symlink, dec_symlink),
6384 PROC(CREATE, enc_create, dec_create),
6385 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6386 PROC(STATFS, enc_statfs, dec_statfs),
6387 PROC(READLINK, enc_readlink, dec_readlink),
6388 PROC(READDIR, enc_readdir, dec_readdir),
6389 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6390 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6391 PROC(GETACL, enc_getacl, dec_getacl),
6392 PROC(SETACL, enc_setacl, dec_setacl),
6393 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6394 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006395 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006396#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006397 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6398 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6399 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6400 PROC(SEQUENCE, enc_sequence, dec_sequence),
6401 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6402 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6403 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6404 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006405#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406};
6407
6408struct rpc_version nfs_version4 = {
6409 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006410 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411 .procs = nfs4_procedures
6412};
6413
6414/*
6415 * Local variables:
6416 * c-basic-offset: 8
6417 * End:
6418 */