blob: 3cbdd0c80a2d1600b061f7cbf783615a07b79c7d [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/nfs.h>
50#include <linux/nfs4.h>
51#include <linux/nfs_fs.h>
52#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000053#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050054#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040055#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#define NFSDBG_FACILITY NFSDBG_XDR
58
59/* Mapping from NFS error code to "errno" error code. */
60#define errno_NFSERR_IO EIO
61
David Howells0a8ea432006-08-22 20:06:08 -040062static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
65#ifdef DEBUG
66#define NFS4_MAXTAGLEN 20
67#else
68#define NFS4_MAXTAGLEN 0
69#endif
70
Andy Adamson6c0195a2008-12-23 16:06:15 -050071/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040072 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 */
Trond Myklebust9f958ab2007-07-02 13:58:33 -040074#define open_owner_id_maxsz (1 + 4)
75#define lock_owner_id_maxsz (1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040076#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79#define op_encode_hdr_maxsz (1)
80#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040081#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
84#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
86 (NFS4_FHSIZE >> 2))
87#define decode_putfh_maxsz (op_decode_hdr_maxsz)
88#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
89#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
90#define encode_getfh_maxsz (op_encode_hdr_maxsz)
91#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
92 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000093#define nfs4_fattr_bitmap_maxsz 3
94#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
96#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040097#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
98#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +000099/* This is based on getfattr, which uses the most attributes: */
100#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400101 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000102#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
103 nfs4_fattr_value_maxsz)
104#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400105#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
106 1 + 2 + 1 + \
107 nfs4_owner_maxsz + \
108 nfs4_group_maxsz + \
109 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#define encode_savefh_maxsz (op_encode_hdr_maxsz)
111#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400112#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
113#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200114#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
116#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
117#define decode_renew_maxsz (op_decode_hdr_maxsz)
118#define encode_setclientid_maxsz \
119 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500120 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
121 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
122 1 /* sc_prog */ + \
123 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
124 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
125 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#define decode_setclientid_maxsz \
127 (op_decode_hdr_maxsz + \
128 2 + \
129 1024) /* large value for CLID_INUSE */
130#define encode_setclientid_confirm_maxsz \
131 (op_encode_hdr_maxsz + \
132 3 + (NFS4_VERIFIER_SIZE >> 2))
133#define decode_setclientid_confirm_maxsz \
134 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400135#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
136#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400137#define encode_share_access_maxsz \
138 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500139#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400140#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
141#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
142#define encode_open_maxsz (op_encode_hdr_maxsz + \
143 2 + encode_share_access_maxsz + 2 + \
144 open_owner_id_maxsz + \
145 encode_opentype_maxsz + \
146 encode_claim_null_maxsz)
147#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400148#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400149 decode_ace_maxsz)
150#define decode_change_info_maxsz (5)
151#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400152 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400153 decode_change_info_maxsz + 1 + \
154 nfs4_fattr_bitmap_maxsz + \
155 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400156#define encode_open_confirm_maxsz \
157 (op_encode_hdr_maxsz + \
158 encode_stateid_maxsz + 1)
159#define decode_open_confirm_maxsz \
160 (op_decode_hdr_maxsz + \
161 decode_stateid_maxsz)
162#define encode_open_downgrade_maxsz \
163 (op_encode_hdr_maxsz + \
164 encode_stateid_maxsz + 1 + \
165 encode_share_access_maxsz)
166#define decode_open_downgrade_maxsz \
167 (op_decode_hdr_maxsz + \
168 decode_stateid_maxsz)
169#define encode_close_maxsz (op_encode_hdr_maxsz + \
170 1 + encode_stateid_maxsz)
171#define decode_close_maxsz (op_decode_hdr_maxsz + \
172 decode_stateid_maxsz)
173#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
174 encode_stateid_maxsz + \
175 encode_attrs_maxsz)
176#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
177 nfs4_fattr_bitmap_maxsz)
178#define encode_read_maxsz (op_encode_hdr_maxsz + \
179 encode_stateid_maxsz + 3)
180#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
181#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
182 2 + encode_verifier_maxsz + 5)
183#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
184 decode_verifier_maxsz)
185#define encode_readlink_maxsz (op_encode_hdr_maxsz)
186#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
187#define encode_write_maxsz (op_encode_hdr_maxsz + \
188 encode_stateid_maxsz + 4)
189#define decode_write_maxsz (op_decode_hdr_maxsz + \
190 2 + decode_verifier_maxsz)
191#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
192#define decode_commit_maxsz (op_decode_hdr_maxsz + \
193 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194#define encode_remove_maxsz (op_encode_hdr_maxsz + \
195 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400196#define decode_remove_maxsz (op_decode_hdr_maxsz + \
197 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#define encode_rename_maxsz (op_encode_hdr_maxsz + \
199 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400200#define decode_rename_maxsz (op_decode_hdr_maxsz + \
201 decode_change_info_maxsz + \
202 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#define encode_link_maxsz (op_encode_hdr_maxsz + \
204 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400205#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400206#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400207#define encode_lock_maxsz (op_encode_hdr_maxsz + \
208 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400209 1 + encode_stateid_maxsz + 1 + \
210 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400211#define decode_lock_denied_maxsz \
212 (8 + decode_lockowner_maxsz)
213#define decode_lock_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400215#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
216 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400217#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
218 decode_lock_denied_maxsz)
219#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
220 encode_stateid_maxsz + \
221 4)
222#define decode_locku_maxsz (op_decode_hdr_maxsz + \
223 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400224#define encode_release_lockowner_maxsz \
225 (op_encode_hdr_maxsz + \
226 encode_lockowner_maxsz)
227#define decode_release_lockowner_maxsz \
228 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400229#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
230#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
232 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400233 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000234 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
236#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400237 1 + 2 + nfs4_name_maxsz + \
238 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400239#define decode_create_maxsz (op_decode_hdr_maxsz + \
240 decode_change_info_maxsz + \
241 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400242#define encode_statfs_maxsz (encode_getattr_maxsz)
243#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
245#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400246#define encode_getacl_maxsz (encode_getattr_maxsz)
247#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
248 nfs4_fattr_bitmap_maxsz + 1)
249#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
250 encode_stateid_maxsz + 3)
251#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400252#define encode_fs_locations_maxsz \
253 (encode_getattr_maxsz)
254#define decode_fs_locations_maxsz \
255 (0)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400256
257#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400258#define NFS4_MAX_MACHINE_NAME_LEN (64)
259
Benny Halevy99fe60d2009-04-01 09:22:29 -0400260#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
261 encode_verifier_maxsz + \
262 1 /* co_ownerid.len */ + \
263 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
264 1 /* flags */ + \
265 1 /* spa_how */ + \
266 0 /* SP4_NONE (for now) */ + \
267 1 /* zero implemetation id array */)
268#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
269 2 /* eir_clientid */ + \
270 1 /* eir_sequenceid */ + \
271 1 /* eir_flags */ + \
272 1 /* spr_how */ + \
273 0 /* SP4_NONE (for now) */ + \
274 2 /* eir_server_owner.so_minor_id */ + \
275 /* eir_server_owner.so_major_id<> */ \
276 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
277 /* eir_server_scope<> */ \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
279 1 /* eir_server_impl_id array length */ + \
280 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400281#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
282#define decode_channel_attrs_maxsz (6 + \
283 1 /* ca_rdma_ird.len */ + \
284 1 /* ca_rdma_ird */)
285#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
286 2 /* csa_clientid */ + \
287 1 /* csa_sequence */ + \
288 1 /* csa_flags */ + \
289 encode_channel_attrs_maxsz + \
290 encode_channel_attrs_maxsz + \
291 1 /* csa_cb_program */ + \
292 1 /* csa_sec_parms.len (1) */ + \
293 1 /* cb_secflavor (AUTH_SYS) */ + \
294 1 /* stamp */ + \
295 1 /* machinename.len */ + \
296 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
297 1 /* uid */ + \
298 1 /* gid */ + \
299 1 /* gids.len (0) */)
300#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
301 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
302 1 /* csr_sequence */ + \
303 1 /* csr_flags */ + \
304 decode_channel_attrs_maxsz + \
305 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400306#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
307#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400308#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
309 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
310#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
311 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga18019752009-12-05 16:08:40 -0500312#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
313#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400314#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
315 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
316#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
317 1 /* layout type */ + \
318 1 /* opaque devaddr4 length */ + \
319 /* devaddr4 payload is read into page */ \
320 1 /* notification bitmap length */ + \
321 1 /* notification bitmap */)
322#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
323 encode_stateid_maxsz)
324#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
325 decode_stateid_maxsz + \
326 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400327#else /* CONFIG_NFS_V4_1 */
328#define encode_sequence_maxsz 0
329#define decode_sequence_maxsz 0
330#endif /* CONFIG_NFS_V4_1 */
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
333#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
334#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400335 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400337 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400339 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400341 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400343 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400345 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400347 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400349 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400351 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400353 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400355 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400357 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400359 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400361 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400362 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400364 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400366 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400367 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400369 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400371 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400372 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400374 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400376 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400377 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400379 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400380 encode_putfh_maxsz + \
381 encode_savefh_maxsz + \
382 encode_open_maxsz + \
383 encode_getfh_maxsz + \
384 encode_getattr_maxsz + \
385 encode_restorefh_maxsz + \
386 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400389 decode_putfh_maxsz + \
390 decode_savefh_maxsz + \
391 decode_open_maxsz + \
392 decode_getfh_maxsz + \
393 decode_getattr_maxsz + \
394 decode_restorefh_maxsz + \
395 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400396#define NFS4_enc_open_confirm_sz \
397 (compound_encode_hdr_maxsz + \
398 encode_putfh_maxsz + \
399 encode_open_confirm_maxsz)
400#define NFS4_dec_open_confirm_sz \
401 (compound_decode_hdr_maxsz + \
402 decode_putfh_maxsz + \
403 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400405 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400407 encode_open_maxsz + \
408 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400410 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400412 decode_open_maxsz + \
413 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414#define NFS4_enc_open_downgrade_sz \
415 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400416 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400417 encode_putfh_maxsz + \
418 encode_open_downgrade_maxsz + \
419 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#define NFS4_dec_open_downgrade_sz \
421 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400422 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400423 decode_putfh_maxsz + \
424 decode_open_downgrade_maxsz + \
425 decode_getattr_maxsz)
426#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400427 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400428 encode_putfh_maxsz + \
429 encode_close_maxsz + \
430 encode_getattr_maxsz)
431#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400433 decode_putfh_maxsz + \
434 decode_close_maxsz + \
435 decode_getattr_maxsz)
436#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400438 encode_putfh_maxsz + \
439 encode_setattr_maxsz + \
440 encode_getattr_maxsz)
441#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400443 decode_putfh_maxsz + \
444 decode_setattr_maxsz + \
445 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400447 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 encode_putfh_maxsz + \
449 encode_fsinfo_maxsz)
450#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 decode_putfh_maxsz + \
453 decode_fsinfo_maxsz)
454#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
455 encode_renew_maxsz)
456#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
457 decode_renew_maxsz)
458#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
459 encode_setclientid_maxsz)
460#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
461 decode_setclientid_maxsz)
462#define NFS4_enc_setclientid_confirm_sz \
463 (compound_encode_hdr_maxsz + \
464 encode_setclientid_confirm_maxsz + \
465 encode_putrootfh_maxsz + \
466 encode_fsinfo_maxsz)
467#define NFS4_dec_setclientid_confirm_sz \
468 (compound_decode_hdr_maxsz + \
469 decode_setclientid_confirm_maxsz + \
470 decode_putrootfh_maxsz + \
471 decode_fsinfo_maxsz)
472#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400473 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400475 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400477 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400479 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400481 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400483 encode_lockt_maxsz)
484#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400485 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400486 decode_putfh_maxsz + \
487 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400491 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400493 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400495 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400496#define NFS4_enc_release_lockowner_sz \
497 (compound_encode_hdr_maxsz + \
498 encode_lockowner_maxsz)
499#define NFS4_dec_release_lockowner_sz \
500 (compound_decode_hdr_maxsz + \
501 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400503 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400505 encode_access_maxsz + \
506 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400510 decode_access_maxsz + \
511 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 encode_putfh_maxsz + \
515 encode_getattr_maxsz)
516#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400517 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 decode_putfh_maxsz + \
519 decode_getattr_maxsz)
520#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400521 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 encode_putfh_maxsz + \
523 encode_lookup_maxsz + \
524 encode_getattr_maxsz + \
525 encode_getfh_maxsz)
526#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400527 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400529 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 decode_getattr_maxsz + \
531 decode_getfh_maxsz)
532#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400533 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 encode_putrootfh_maxsz + \
535 encode_getattr_maxsz + \
536 encode_getfh_maxsz)
537#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 decode_putrootfh_maxsz + \
540 decode_getattr_maxsz + \
541 decode_getfh_maxsz)
542#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400543 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400545 encode_remove_maxsz + \
546 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400548 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400550 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400551 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400553 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 encode_putfh_maxsz + \
555 encode_savefh_maxsz + \
556 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400557 encode_rename_maxsz + \
558 encode_getattr_maxsz + \
559 encode_restorefh_maxsz + \
560 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 decode_putfh_maxsz + \
564 decode_savefh_maxsz + \
565 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400566 decode_rename_maxsz + \
567 decode_getattr_maxsz + \
568 decode_restorefh_maxsz + \
569 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400571 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 encode_putfh_maxsz + \
573 encode_savefh_maxsz + \
574 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400575 encode_link_maxsz + \
576 decode_getattr_maxsz + \
577 encode_restorefh_maxsz + \
578 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
582 decode_savefh_maxsz + \
583 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400584 decode_link_maxsz + \
585 decode_getattr_maxsz + \
586 decode_restorefh_maxsz + \
587 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400589 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 encode_putfh_maxsz + \
591 encode_symlink_maxsz + \
592 encode_getattr_maxsz + \
593 encode_getfh_maxsz)
594#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 decode_putfh_maxsz + \
597 decode_symlink_maxsz + \
598 decode_getattr_maxsz + \
599 decode_getfh_maxsz)
600#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400603 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400605 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400607 encode_restorefh_maxsz + \
608 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400612 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400614 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400616 decode_restorefh_maxsz + \
617 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400619 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 encode_putfh_maxsz + \
621 encode_getattr_maxsz)
622#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400623 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 decode_putfh_maxsz + \
625 decode_getattr_maxsz)
626#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400627 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400629 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400631 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400633 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400635 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800636 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 encode_getattr_maxsz)
638#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400639 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800640 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 decode_getattr_maxsz)
642#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400643 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100645 encode_delegreturn_maxsz + \
646 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100649 decode_delegreturn_maxsz + \
650 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000651#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400652 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000653 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400654 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000655#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400656 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000657 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400658 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000659#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000661 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400662 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000663#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000665 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400666 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400667#define NFS4_enc_fs_locations_sz \
668 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400669 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400670 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400671 encode_lookup_maxsz + \
672 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400673#define NFS4_dec_fs_locations_sz \
674 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400675 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400676 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400677 decode_lookup_maxsz + \
678 decode_fs_locations_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400679#if defined(CONFIG_NFS_V4_1)
680#define NFS4_enc_exchange_id_sz \
681 (compound_encode_hdr_maxsz + \
682 encode_exchange_id_maxsz)
683#define NFS4_dec_exchange_id_sz \
684 (compound_decode_hdr_maxsz + \
685 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400686#define NFS4_enc_create_session_sz \
687 (compound_encode_hdr_maxsz + \
688 encode_create_session_maxsz)
689#define NFS4_dec_create_session_sz \
690 (compound_decode_hdr_maxsz + \
691 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400692#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
693 encode_destroy_session_maxsz)
694#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
695 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400696#define NFS4_enc_sequence_sz \
697 (compound_decode_hdr_maxsz + \
698 encode_sequence_maxsz)
699#define NFS4_dec_sequence_sz \
700 (compound_decode_hdr_maxsz + \
701 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400702#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
703 encode_sequence_maxsz + \
704 encode_putrootfh_maxsz + \
705 encode_fsinfo_maxsz)
706#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
707 decode_sequence_maxsz + \
708 decode_putrootfh_maxsz + \
709 decode_fsinfo_maxsz)
Ricardo Labiaga18019752009-12-05 16:08:40 -0500710#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
711 encode_sequence_maxsz + \
712 encode_reclaim_complete_maxsz)
713#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
714 decode_sequence_maxsz + \
715 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400716#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
717 encode_sequence_maxsz +\
718 encode_getdeviceinfo_maxsz)
719#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
720 decode_sequence_maxsz + \
721 decode_getdeviceinfo_maxsz)
722#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
723 encode_sequence_maxsz + \
724 encode_putfh_maxsz + \
725 encode_layoutget_maxsz)
726#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
727 decode_sequence_maxsz + \
728 decode_putfh_maxsz + \
729 decode_layoutget_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500730
731const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
732 compound_encode_hdr_maxsz +
733 encode_sequence_maxsz +
734 encode_putfh_maxsz +
735 encode_getattr_maxsz) *
736 XDR_UNIT);
737
738const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
739 compound_decode_hdr_maxsz +
740 decode_sequence_maxsz +
741 decode_putfh_maxsz) *
742 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400743#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Trond Myklebustbca79472009-03-11 14:10:26 -0400745static const umode_t nfs_type2fmt[] = {
746 [NF4BAD] = 0,
747 [NF4REG] = S_IFREG,
748 [NF4DIR] = S_IFDIR,
749 [NF4BLK] = S_IFBLK,
750 [NF4CHR] = S_IFCHR,
751 [NF4LNK] = S_IFLNK,
752 [NF4SOCK] = S_IFSOCK,
753 [NF4FIFO] = S_IFIFO,
754 [NF4ATTRDIR] = 0,
755 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756};
757
758struct compound_hdr {
759 int32_t status;
760 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500761 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 uint32_t taglen;
763 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400764 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400765 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766};
767
Benny Halevy13c65ce2009-08-14 17:19:25 +0300768static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
769{
770 __be32 *p = xdr_reserve_space(xdr, nbytes);
771 BUG_ON(!p);
772 return p;
773}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
776{
Al Viro8687b632006-10-19 23:28:48 -0700777 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 p = xdr_reserve_space(xdr, 4 + len);
780 BUG_ON(p == NULL);
781 xdr_encode_opaque(p, str, len);
782}
783
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400784static void encode_compound_hdr(struct xdr_stream *xdr,
785 struct rpc_rqst *req,
786 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787{
Al Viro8687b632006-10-19 23:28:48 -0700788 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400789 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400790
791 /* initialize running count of expected bytes in reply.
792 * NOTE: the replied tag SHOULD be the same is the one sent,
793 * but this is not required as a MUST for the server to do so. */
794 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
796 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
797 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300798 p = reserve_space(xdr, 4 + hdr->taglen + 8);
799 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300800 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500801 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300802 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500803}
804
805static void encode_nops(struct compound_hdr *hdr)
806{
Andy Adamsonfc931582009-04-01 09:22:31 -0400807 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500808 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809}
810
811static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
812{
Al Viro8687b632006-10-19 23:28:48 -0700813 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
816 BUG_ON(p == NULL);
817 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
818}
819
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500820static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
822 char owner_name[IDMAP_NAMESZ];
823 char owner_group[IDMAP_NAMESZ];
824 int owner_namelen = 0;
825 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700826 __be32 *p;
827 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 int len;
829 uint32_t bmval0 = 0;
830 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 /*
833 * We reserve enough space to write the entire attribute buffer at once.
834 * In the worst-case, this would be
835 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
836 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000837 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 */
839 len = 16;
840
841 /* Sigh */
842 if (iap->ia_valid & ATTR_SIZE)
843 len += 8;
844 if (iap->ia_valid & ATTR_MODE)
845 len += 4;
846 if (iap->ia_valid & ATTR_UID) {
Bryan Schumaker955a8572010-09-29 15:41:49 -0400847 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400849 dprintk("nfs: couldn't resolve uid %d to string\n",
850 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 /* XXX */
852 strcpy(owner_name, "nobody");
853 owner_namelen = sizeof("nobody") - 1;
854 /* goto out; */
855 }
856 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
857 }
858 if (iap->ia_valid & ATTR_GID) {
Bryan Schumaker955a8572010-09-29 15:41:49 -0400859 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400861 dprintk("nfs: couldn't resolve gid %d to string\n",
862 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 strcpy(owner_group, "nobody");
864 owner_grouplen = sizeof("nobody") - 1;
865 /* goto out; */
866 }
867 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
868 }
869 if (iap->ia_valid & ATTR_ATIME_SET)
870 len += 16;
871 else if (iap->ia_valid & ATTR_ATIME)
872 len += 4;
873 if (iap->ia_valid & ATTR_MTIME_SET)
874 len += 16;
875 else if (iap->ia_valid & ATTR_MTIME)
876 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300877 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
879 /*
880 * We write the bitmap length now, but leave the bitmap and the attribute
881 * buffer length to be backfilled at the end of this routine.
882 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300883 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 q = p;
885 p += 3;
886
887 if (iap->ia_valid & ATTR_SIZE) {
888 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300889 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 }
891 if (iap->ia_valid & ATTR_MODE) {
892 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300893 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 }
895 if (iap->ia_valid & ATTR_UID) {
896 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300897 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899 if (iap->ia_valid & ATTR_GID) {
900 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300901 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 }
903 if (iap->ia_valid & ATTR_ATIME_SET) {
904 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300905 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
906 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400907 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
908 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
910 else if (iap->ia_valid & ATTR_ATIME) {
911 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300912 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
914 if (iap->ia_valid & ATTR_MTIME_SET) {
915 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300916 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
917 *p++ = cpu_to_be32(0);
918 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
919 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
921 else if (iap->ia_valid & ATTR_MTIME) {
922 bmval1 |= FATTR4_WORD1_TIME_MODIFY_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 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 /*
927 * Now we backfill the bitmap and the attribute buffer length.
928 */
929 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400930 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 len, ((char *)p - (char *)q) + 4);
932 BUG();
933 }
934 len = (char *)p - (char *)q - 12;
935 *q++ = htonl(bmval0);
936 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300937 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940}
941
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500942static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
Al Viro8687b632006-10-19 23:28:48 -0700944 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Benny Halevy13c65ce2009-08-14 17:19:25 +0300946 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300947 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300948 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500949 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400950 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951}
952
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500953static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, 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+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300958 *p++ = cpu_to_be32(OP_CLOSE);
959 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +0300960 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500961 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400962 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500965static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
Al Viro8687b632006-10-19 23:28:48 -0700967 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500968
Benny Halevy13c65ce2009-08-14 17:19:25 +0300969 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300970 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +0300971 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +0300972 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500973 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400974 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975}
976
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500977static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
Al Viro8687b632006-10-19 23:28:48 -0700979 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500980
Benny Halevy13c65ce2009-08-14 17:19:25 +0300981 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300982 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +0300983 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985 switch (create->ftype) {
986 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300987 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +0300988 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -0400989 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 break;
991
992 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +0300993 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300994 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +0300995 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 break;
997
998 default:
999 break;
1000 }
1001
Benny Halevy811652b2009-08-14 17:19:34 +03001002 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001003 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001004 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001006 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007}
1008
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001009static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010{
Andy Adamson05d564f2008-12-23 16:06:15 -05001011 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Benny Halevy13c65ce2009-08-14 17:19:25 +03001013 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001014 *p++ = cpu_to_be32(OP_GETATTR);
1015 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001016 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001017 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001018 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019}
1020
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001021static 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 -07001022{
Andy Adamson05d564f2008-12-23 16:06:15 -05001023 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Benny Halevy13c65ce2009-08-14 17:19:25 +03001025 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001026 *p++ = cpu_to_be32(OP_GETATTR);
1027 *p++ = cpu_to_be32(2);
1028 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001029 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001030 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001031 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032}
1033
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001034static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001036 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1037 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038}
1039
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001040static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001042 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1043 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044}
1045
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001046static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001047{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001048 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1049 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001050}
1051
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001052static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053{
Al Viro8687b632006-10-19 23:28:48 -07001054 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Benny Halevy13c65ce2009-08-14 17:19:25 +03001056 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001057 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001058 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001059 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060}
1061
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001062static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
Al Viro8687b632006-10-19 23:28:48 -07001064 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Benny Halevy13c65ce2009-08-14 17:19:25 +03001066 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001067 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001068 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001069 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001070 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001073static inline int nfs4_lock_type(struct file_lock *fl, int block)
1074{
1075 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1076 return block ? NFS4_READW_LT : NFS4_READ_LT;
1077 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1078}
1079
1080static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1081{
1082 if (fl->fl_end == OFFSET_MAX)
1083 return ~(uint64_t)0;
1084 return fl->fl_end - fl->fl_start + 1;
1085}
1086
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001087static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1088{
1089 __be32 *p;
1090
1091 p = reserve_space(xdr, 28);
1092 p = xdr_encode_hyper(p, lowner->clientid);
1093 *p++ = cpu_to_be32(16);
1094 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1095 xdr_encode_hyper(p, lowner->id);
1096}
1097
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098/*
1099 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1100 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1101 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001102static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103{
Al Viro8687b632006-10-19 23:28:48 -07001104 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Benny Halevy13c65ce2009-08-14 17:19:25 +03001106 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001107 *p++ = cpu_to_be32(OP_LOCK);
1108 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1109 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001110 p = xdr_encode_hyper(p, args->fl->fl_start);
1111 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001112 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001113 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001114 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001115 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001116 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001117 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001118 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
1120 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001121 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001122 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001123 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 }
Andy Adamsond0179312008-12-23 16:06:17 -05001125 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001126 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001129static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
Al Viro8687b632006-10-19 23:28:48 -07001131 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001133 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001134 *p++ = cpu_to_be32(OP_LOCKT);
1135 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001136 p = xdr_encode_hyper(p, args->fl->fl_start);
1137 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001138 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001139 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001140 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001143static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144{
Al Viro8687b632006-10-19 23:28:48 -07001145 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Benny Halevy13c65ce2009-08-14 17:19:25 +03001147 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001148 *p++ = cpu_to_be32(OP_LOCKU);
1149 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1150 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001151 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001152 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001153 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001154 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001155 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156}
1157
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001158static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1159{
1160 __be32 *p;
1161
1162 p = reserve_space(xdr, 4);
1163 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1164 encode_lockowner(xdr, lowner);
1165 hdr->nops++;
1166 hdr->replen += decode_release_lockowner_maxsz;
1167}
1168
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001169static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170{
1171 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001172 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Benny Halevy13c65ce2009-08-14 17:19:25 +03001174 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001175 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001176 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001177 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001178 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179}
1180
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001181static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182{
Al Viro8687b632006-10-19 23:28:48 -07001183 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Benny Halevy13c65ce2009-08-14 17:19:25 +03001185 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001186 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001187 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001188 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001189 break;
1190 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001191 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001192 break;
1193 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001194 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001195 break;
1196 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001197 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 }
Benny Halevy34558512009-08-14 17:19:30 +03001199 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200}
1201
1202static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1203{
Al Viro8687b632006-10-19 23:28:48 -07001204 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 /*
1206 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1207 * owner 4 = 32
1208 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001209 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001210 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001211 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001212 encode_share_access(xdr, arg->fmode);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001213 p = reserve_space(xdr, 28);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001214 p = xdr_encode_hyper(p, arg->clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001215 *p++ = cpu_to_be32(16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001216 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Benny Halevy34558512009-08-14 17:19:30 +03001217 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218}
1219
1220static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1221{
Al Viro8687b632006-10-19 23:28:48 -07001222 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001223 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Benny Halevy13c65ce2009-08-14 17:19:25 +03001225 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001227 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001228 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001229 encode_attrs(xdr, arg->u.attrs, arg->server);
1230 break;
1231 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001232 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001233 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001234 if (nfs4_has_persistent_session(clp)) {
1235 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1236 encode_attrs(xdr, arg->u.attrs, arg->server);
1237 } else {
1238 struct iattr dummy;
1239
1240 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1241 encode_nfs4_verifier(xdr, &arg->u.verifier);
1242 dummy.ia_valid = 0;
1243 encode_attrs(xdr, &dummy, arg->server);
1244 }
1245 } else {
1246 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1247 encode_nfs4_verifier(xdr, &arg->u.verifier);
1248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 }
1250}
1251
1252static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1253{
Al Viro8687b632006-10-19 23:28:48 -07001254 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
Benny Halevy13c65ce2009-08-14 17:19:25 +03001256 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001258 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001259 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001260 break;
1261 default:
1262 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001263 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001264 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 }
1266}
1267
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001268static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269{
Al Viro8687b632006-10-19 23:28:48 -07001270 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Benny Halevy13c65ce2009-08-14 17:19:25 +03001272 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001274 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001275 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001276 break;
1277 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001278 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001279 break;
1280 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001281 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001282 break;
1283 default:
1284 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 }
1286}
1287
1288static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1289{
Al Viro8687b632006-10-19 23:28:48 -07001290 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Benny Halevy13c65ce2009-08-14 17:19:25 +03001292 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001293 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 encode_string(xdr, name->len, name->name);
1295}
1296
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001297static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298{
Al Viro8687b632006-10-19 23:28:48 -07001299 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
Benny Halevy13c65ce2009-08-14 17:19:25 +03001301 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001302 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 encode_delegation_type(xdr, type);
1304}
1305
1306static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1307{
Al Viro8687b632006-10-19 23:28:48 -07001308 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
Benny Halevy13c65ce2009-08-14 17:19:25 +03001310 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001311 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001312 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 encode_string(xdr, name->len, name->name);
1314}
1315
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001316static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317{
1318 encode_openhdr(xdr, arg);
1319 encode_opentype(xdr, arg);
1320 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001321 case NFS4_OPEN_CLAIM_NULL:
1322 encode_claim_null(xdr, arg->name);
1323 break;
1324 case NFS4_OPEN_CLAIM_PREVIOUS:
1325 encode_claim_previous(xdr, arg->u.delegation_type);
1326 break;
1327 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1328 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1329 break;
1330 default:
1331 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
Andy Adamsond0179312008-12-23 16:06:17 -05001333 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001334 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335}
1336
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001337static 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 -07001338{
Al Viro8687b632006-10-19 23:28:48 -07001339 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Benny Halevy13c65ce2009-08-14 17:19:25 +03001341 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001342 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001343 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001344 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001345 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001346 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001349static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
Al Viro8687b632006-10-19 23:28:48 -07001351 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Benny Halevy13c65ce2009-08-14 17:19:25 +03001353 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001354 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001355 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001356 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001357 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001358 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001359 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360}
1361
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001362static void
Andy Adamsond0179312008-12-23 16:06:17 -05001363encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364{
1365 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001366 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Benny Halevy13c65ce2009-08-14 17:19:25 +03001368 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001369 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001370 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001371 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001372 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373}
1374
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001375static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376{
Andy Adamson05d564f2008-12-23 16:06:15 -05001377 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001378
Benny Halevy13c65ce2009-08-14 17:19:25 +03001379 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001380 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001381 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001382 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383}
1384
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001385static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001388 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Benny Halevy13c65ce2009-08-14 17:19:25 +03001390 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001392 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Benny Halevy34558512009-08-14 17:19:30 +03001393 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 } else
Benny Halevy34558512009-08-14 17:19:30 +03001395 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396}
1397
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001398static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399{
Al Viro8687b632006-10-19 23:28:48 -07001400 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
Benny Halevy13c65ce2009-08-14 17:19:25 +03001402 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001403 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001405 encode_stateid(xdr, args->context, args->lock_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Benny Halevy13c65ce2009-08-14 17:19:25 +03001407 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001408 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001409 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001410 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001411 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412}
1413
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001414static 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 -07001415{
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001416 uint32_t attrs[2] = {0, 0};
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001417 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001418 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001420 if (readdir->plus) {
1421 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
1422 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE;
1423 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1424 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1425 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1426 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001427 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001428 }
1429 attrs[0] |= FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID;
1430 attrs[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001431 /* Switch to mounted_on_fileid if the server supports it */
1432 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1433 attrs[0] &= ~FATTR4_WORD0_FILEID;
1434 else
1435 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001436
Benny Halevy13c65ce2009-08-14 17:19:25 +03001437 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001438 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001439 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001440 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001441 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001442 *p++ = cpu_to_be32(readdir->count);
1443 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001444
Benny Halevye75bc1c2009-08-14 17:18:54 +03001445 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001446 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001447 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001448 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001449 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1450 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001451 (unsigned long long)readdir->cookie,
1452 ((u32 *)readdir->verifier.data)[0],
1453 ((u32 *)readdir->verifier.data)[1],
1454 attrs[0] & readdir->bitmask[0],
1455 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456}
1457
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001458static 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 -07001459{
Al Viro8687b632006-10-19 23:28:48 -07001460 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Benny Halevy13c65ce2009-08-14 17:19:25 +03001462 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001463 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001464 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001465 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466}
1467
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001468static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
Al Viro8687b632006-10-19 23:28:48 -07001470 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Benny Halevy13c65ce2009-08-14 17:19:25 +03001472 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001473 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001474 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001475 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001476 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477}
1478
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001479static 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 -07001480{
Al Viro8687b632006-10-19 23:28:48 -07001481 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Benny Halevy811652b2009-08-14 17:19:34 +03001483 p = reserve_space(xdr, 4);
1484 *p = cpu_to_be32(OP_RENAME);
1485 encode_string(xdr, oldname->len, oldname->name);
1486 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001487 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001488 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489}
1490
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001491static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492{
Al Viro8687b632006-10-19 23:28:48 -07001493 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Benny Halevy13c65ce2009-08-14 17:19:25 +03001495 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001496 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001497 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001498 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001499 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500}
1501
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001502static void
Andy Adamsond0179312008-12-23 16:06:17 -05001503encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001504{
Al Viro8687b632006-10-19 23:28:48 -07001505 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001506
Benny Halevy13c65ce2009-08-14 17:19:25 +03001507 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001508 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001509 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001510 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001511}
1512
Chuck Lever9f06c712010-12-14 14:59:18 +00001513static void
Andy Adamsond0179312008-12-23 16:06:17 -05001514encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001515{
Al Viro8687b632006-10-19 23:28:48 -07001516 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001517
Benny Halevy13c65ce2009-08-14 17:19:25 +03001518 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001519 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001520 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001521 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001522 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001523 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001524 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001525 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001526 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001527 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001528 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001529 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001530}
1531
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001532static void
Andy Adamsond0179312008-12-23 16:06:17 -05001533encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534{
Al Viro8687b632006-10-19 23:28:48 -07001535 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Benny Halevy13c65ce2009-08-14 17:19:25 +03001537 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001538 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001539 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001540 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541}
1542
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001543static 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 -07001544{
Al Viro8687b632006-10-19 23:28:48 -07001545 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001546
Benny Halevy13c65ce2009-08-14 17:19:25 +03001547 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001548 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001549 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001550 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001551 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001552 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553}
1554
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001555static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556{
Al Viro8687b632006-10-19 23:28:48 -07001557 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Benny Halevy13c65ce2009-08-14 17:19:25 +03001559 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001560 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001561 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
1563 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001564 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001565 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1567 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001568 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001569 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001570 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001571 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572}
1573
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001574static 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 -07001575{
Andy Adamson05d564f2008-12-23 16:06:15 -05001576 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Benny Halevy13c65ce2009-08-14 17:19:25 +03001578 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001579 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001580 p = xdr_encode_hyper(p, arg->clientid);
1581 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001582 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001583 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584}
1585
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001586static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587{
Al Viro8687b632006-10-19 23:28:48 -07001588 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
Benny Halevy13c65ce2009-08-14 17:19:25 +03001590 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001591 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
Trond Myklebustf11ac8d2010-06-25 16:35:53 -04001593 encode_stateid(xdr, args->context, args->lock_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
Benny Halevy13c65ce2009-08-14 17:19:25 +03001595 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001596 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001597 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001598 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
1600 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001601 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001602 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603}
1604
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001605static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606{
Al Viro8687b632006-10-19 23:28:48 -07001607 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Benny Halevy13c65ce2009-08-14 17:19:25 +03001609 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Benny Halevye75bc1c2009-08-14 17:18:54 +03001611 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001612 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001613 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001614 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001616
Benny Halevy99fe60d2009-04-01 09:22:29 -04001617#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001618/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001619static void encode_exchange_id(struct xdr_stream *xdr,
1620 struct nfs41_exchange_id_args *args,
1621 struct compound_hdr *hdr)
1622{
1623 __be32 *p;
1624
Benny Halevy13c65ce2009-08-14 17:19:25 +03001625 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001626 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001627 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001628
1629 encode_string(xdr, args->id_len, args->id);
1630
Benny Halevy13c65ce2009-08-14 17:19:25 +03001631 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001632 *p++ = cpu_to_be32(args->flags);
1633 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001634 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001635 hdr->nops++;
1636 hdr->replen += decode_exchange_id_maxsz;
1637}
Andy Adamsonfc931582009-04-01 09:22:31 -04001638
1639static void encode_create_session(struct xdr_stream *xdr,
1640 struct nfs41_create_session_args *args,
1641 struct compound_hdr *hdr)
1642{
1643 __be32 *p;
1644 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1645 uint32_t len;
1646 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001647 u32 max_resp_sz_cached;
1648
1649 /*
1650 * Assumes OPEN is the biggest non-idempotent compound.
1651 * 2 is the verifier.
1652 */
1653 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1654 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001655
Andy Adamsonfc931582009-04-01 09:22:31 -04001656 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1657 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001658
Benny Halevy13c65ce2009-08-14 17:19:25 +03001659 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001660 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001661 p = xdr_encode_hyper(p, clp->cl_ex_clid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001662 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1663 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001664
Andy Adamsonfc931582009-04-01 09:22:31 -04001665 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001666 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1667 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1668 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001669 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001670 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1671 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1672 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001673
1674 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001675 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1676 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1677 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1678 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1679 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1680 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1681 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001682
Benny Halevye75bc1c2009-08-14 17:18:54 +03001683 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001684 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001685 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001686
1687 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001688 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001689 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001690 *p++ = cpu_to_be32(0); /* UID */
1691 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001692 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001693 hdr->nops++;
1694 hdr->replen += decode_create_session_maxsz;
1695}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001696
1697static void encode_destroy_session(struct xdr_stream *xdr,
1698 struct nfs4_session *session,
1699 struct compound_hdr *hdr)
1700{
1701 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001702 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001703 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001704 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001705 hdr->nops++;
1706 hdr->replen += decode_destroy_session_maxsz;
1707}
Ricardo Labiaga18019752009-12-05 16:08:40 -05001708
1709static void encode_reclaim_complete(struct xdr_stream *xdr,
1710 struct nfs41_reclaim_complete_args *args,
1711 struct compound_hdr *hdr)
1712{
1713 __be32 *p;
1714
1715 p = reserve_space(xdr, 8);
1716 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1717 *p++ = cpu_to_be32(args->one_fs);
1718 hdr->nops++;
1719 hdr->replen += decode_reclaim_complete_maxsz;
1720}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001721#endif /* CONFIG_NFS_V4_1 */
1722
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001723static void encode_sequence(struct xdr_stream *xdr,
1724 const struct nfs4_sequence_args *args,
1725 struct compound_hdr *hdr)
1726{
1727#if defined(CONFIG_NFS_V4_1)
1728 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001729 struct nfs4_slot_table *tp;
1730 struct nfs4_slot *slot;
1731 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001732
1733 if (!session)
1734 return;
1735
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001736 tp = &session->fc_slot_table;
1737
1738 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1739 slot = tp->slots + args->sa_slotid;
1740
Benny Halevy13c65ce2009-08-14 17:19:25 +03001741 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001742 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001743
1744 /*
1745 * Sessionid + seqid + slotid + max slotid + cache_this
1746 */
1747 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1748 "max_slotid=%d cache_this=%d\n",
1749 __func__,
1750 ((u32 *)session->sess_id.data)[0],
1751 ((u32 *)session->sess_id.data)[1],
1752 ((u32 *)session->sess_id.data)[2],
1753 ((u32 *)session->sess_id.data)[3],
1754 slot->seq_nr, args->sa_slotid,
1755 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001756 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001757 *p++ = cpu_to_be32(slot->seq_nr);
1758 *p++ = cpu_to_be32(args->sa_slotid);
1759 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001760 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001761 hdr->nops++;
1762 hdr->replen += decode_sequence_maxsz;
1763#endif /* CONFIG_NFS_V4_1 */
1764}
1765
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001766#ifdef CONFIG_NFS_V4_1
1767static void
1768encode_getdeviceinfo(struct xdr_stream *xdr,
1769 const struct nfs4_getdeviceinfo_args *args,
1770 struct compound_hdr *hdr)
1771{
1772 __be32 *p;
1773
1774 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1775 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1776 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1777 NFS4_DEVICEID4_SIZE);
1778 *p++ = cpu_to_be32(args->pdev->layout_type);
1779 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1780 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1781 hdr->nops++;
1782 hdr->replen += decode_getdeviceinfo_maxsz;
1783}
1784
1785static void
1786encode_layoutget(struct xdr_stream *xdr,
1787 const struct nfs4_layoutget_args *args,
1788 struct compound_hdr *hdr)
1789{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001790 __be32 *p;
1791
1792 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1793 *p++ = cpu_to_be32(OP_LAYOUTGET);
1794 *p++ = cpu_to_be32(0); /* Signal layout available */
1795 *p++ = cpu_to_be32(args->type);
1796 *p++ = cpu_to_be32(args->range.iomode);
1797 p = xdr_encode_hyper(p, args->range.offset);
1798 p = xdr_encode_hyper(p, args->range.length);
1799 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001800 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001801 *p = cpu_to_be32(args->maxcount);
1802
1803 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1804 __func__,
1805 args->type,
1806 args->range.iomode,
1807 (unsigned long)args->range.offset,
1808 (unsigned long)args->range.length,
1809 args->maxcount);
1810 hdr->nops++;
1811 hdr->replen += decode_layoutget_maxsz;
1812}
1813#endif /* CONFIG_NFS_V4_1 */
1814
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815/*
1816 * END OF "GENERIC" ENCODE ROUTINES.
1817 */
1818
Benny Halevy66cc0422009-04-01 09:22:10 -04001819static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1820{
1821#if defined(CONFIG_NFS_V4_1)
1822 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001823 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001824#endif /* CONFIG_NFS_V4_1 */
1825 return 0;
1826}
1827
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828/*
1829 * Encode an ACCESS request
1830 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001831static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1832 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001835 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
Chuck Lever9f06c712010-12-14 14:59:18 +00001838 encode_compound_hdr(xdr, req, &hdr);
1839 encode_sequence(xdr, &args->seq_args, &hdr);
1840 encode_putfh(xdr, args->fh, &hdr);
1841 encode_access(xdr, args->access, &hdr);
1842 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001843 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844}
1845
1846/*
1847 * Encode LOOKUP request
1848 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001849static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1850 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001853 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
Chuck Lever9f06c712010-12-14 14:59:18 +00001856 encode_compound_hdr(xdr, req, &hdr);
1857 encode_sequence(xdr, &args->seq_args, &hdr);
1858 encode_putfh(xdr, args->dir_fh, &hdr);
1859 encode_lookup(xdr, args->name, &hdr);
1860 encode_getfh(xdr, &hdr);
1861 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001862 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863}
1864
1865/*
1866 * Encode LOOKUP_ROOT request
1867 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001868static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1869 struct xdr_stream *xdr,
1870 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001873 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
Chuck Lever9f06c712010-12-14 14:59:18 +00001876 encode_compound_hdr(xdr, req, &hdr);
1877 encode_sequence(xdr, &args->seq_args, &hdr);
1878 encode_putrootfh(xdr, &hdr);
1879 encode_getfh(xdr, &hdr);
1880 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001881 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882}
1883
1884/*
1885 * Encode REMOVE request
1886 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001887static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
1888 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001891 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Chuck Lever9f06c712010-12-14 14:59:18 +00001894 encode_compound_hdr(xdr, req, &hdr);
1895 encode_sequence(xdr, &args->seq_args, &hdr);
1896 encode_putfh(xdr, args->fh, &hdr);
1897 encode_remove(xdr, &args->name, &hdr);
1898 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001899 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900}
1901
1902/*
1903 * Encode RENAME request
1904 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001905static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
1906 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001909 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
Chuck Lever9f06c712010-12-14 14:59:18 +00001912 encode_compound_hdr(xdr, req, &hdr);
1913 encode_sequence(xdr, &args->seq_args, &hdr);
1914 encode_putfh(xdr, args->old_dir, &hdr);
1915 encode_savefh(xdr, &hdr);
1916 encode_putfh(xdr, args->new_dir, &hdr);
1917 encode_rename(xdr, args->old_name, args->new_name, &hdr);
1918 encode_getfattr(xdr, args->bitmask, &hdr);
1919 encode_restorefh(xdr, &hdr);
1920 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001921 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922}
1923
1924/*
1925 * Encode LINK request
1926 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001927static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
1928 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001931 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933
Chuck Lever9f06c712010-12-14 14:59:18 +00001934 encode_compound_hdr(xdr, req, &hdr);
1935 encode_sequence(xdr, &args->seq_args, &hdr);
1936 encode_putfh(xdr, args->fh, &hdr);
1937 encode_savefh(xdr, &hdr);
1938 encode_putfh(xdr, args->dir_fh, &hdr);
1939 encode_link(xdr, args->name, &hdr);
1940 encode_getfattr(xdr, args->bitmask, &hdr);
1941 encode_restorefh(xdr, &hdr);
1942 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001943 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944}
1945
1946/*
1947 * Encode CREATE request
1948 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001949static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
1950 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001953 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
Chuck Lever9f06c712010-12-14 14:59:18 +00001956 encode_compound_hdr(xdr, req, &hdr);
1957 encode_sequence(xdr, &args->seq_args, &hdr);
1958 encode_putfh(xdr, args->dir_fh, &hdr);
1959 encode_savefh(xdr, &hdr);
1960 encode_create(xdr, args, &hdr);
1961 encode_getfh(xdr, &hdr);
1962 encode_getfattr(xdr, args->bitmask, &hdr);
1963 encode_restorefh(xdr, &hdr);
1964 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001965 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966}
1967
1968/*
1969 * Encode SYMLINK request
1970 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001971static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
1972 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973{
Chuck Lever9f06c712010-12-14 14:59:18 +00001974 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975}
1976
1977/*
1978 * Encode GETATTR request
1979 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001980static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
1981 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001984 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
Chuck Lever9f06c712010-12-14 14:59:18 +00001987 encode_compound_hdr(xdr, req, &hdr);
1988 encode_sequence(xdr, &args->seq_args, &hdr);
1989 encode_putfh(xdr, args->fh, &hdr);
1990 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001991 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992}
1993
1994/*
1995 * Encode a CLOSE request
1996 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001997static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
1998 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999{
Andy Adamson05d564f2008-12-23 16:06:15 -05002000 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002001 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002002 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
Chuck Lever9f06c712010-12-14 14:59:18 +00002004 encode_compound_hdr(xdr, req, &hdr);
2005 encode_sequence(xdr, &args->seq_args, &hdr);
2006 encode_putfh(xdr, args->fh, &hdr);
2007 encode_close(xdr, args, &hdr);
2008 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002009 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010}
2011
2012/*
2013 * Encode an OPEN request
2014 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002015static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2016 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002019 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
Chuck Lever9f06c712010-12-14 14:59:18 +00002022 encode_compound_hdr(xdr, req, &hdr);
2023 encode_sequence(xdr, &args->seq_args, &hdr);
2024 encode_putfh(xdr, args->fh, &hdr);
2025 encode_savefh(xdr, &hdr);
2026 encode_open(xdr, args, &hdr);
2027 encode_getfh(xdr, &hdr);
2028 encode_getfattr(xdr, args->bitmask, &hdr);
2029 encode_restorefh(xdr, &hdr);
2030 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002031 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032}
2033
2034/*
2035 * Encode an OPEN_CONFIRM request
2036 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002037static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2038 struct xdr_stream *xdr,
2039 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002042 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
Chuck Lever9f06c712010-12-14 14:59:18 +00002045 encode_compound_hdr(xdr, req, &hdr);
2046 encode_putfh(xdr, args->fh, &hdr);
2047 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002048 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049}
2050
2051/*
2052 * Encode an OPEN request with no attributes.
2053 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002054static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2055 struct xdr_stream *xdr,
2056 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002059 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
Chuck Lever9f06c712010-12-14 14:59:18 +00002062 encode_compound_hdr(xdr, req, &hdr);
2063 encode_sequence(xdr, &args->seq_args, &hdr);
2064 encode_putfh(xdr, args->fh, &hdr);
2065 encode_open(xdr, args, &hdr);
2066 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002067 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068}
2069
2070/*
2071 * Encode an OPEN_DOWNGRADE request
2072 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002073static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2074 struct xdr_stream *xdr,
2075 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002078 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
Chuck Lever9f06c712010-12-14 14:59:18 +00002081 encode_compound_hdr(xdr, req, &hdr);
2082 encode_sequence(xdr, &args->seq_args, &hdr);
2083 encode_putfh(xdr, args->fh, &hdr);
2084 encode_open_downgrade(xdr, args, &hdr);
2085 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002086 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087}
2088
2089/*
2090 * Encode a LOCK request
2091 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002092static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2093 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002096 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Chuck Lever9f06c712010-12-14 14:59:18 +00002099 encode_compound_hdr(xdr, req, &hdr);
2100 encode_sequence(xdr, &args->seq_args, &hdr);
2101 encode_putfh(xdr, args->fh, &hdr);
2102 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002103 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104}
2105
2106/*
2107 * Encode a LOCKT request
2108 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002109static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2110 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002113 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
Chuck Lever9f06c712010-12-14 14:59:18 +00002116 encode_compound_hdr(xdr, req, &hdr);
2117 encode_sequence(xdr, &args->seq_args, &hdr);
2118 encode_putfh(xdr, args->fh, &hdr);
2119 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002120 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121}
2122
2123/*
2124 * Encode a LOCKU request
2125 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002126static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2127 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002130 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132
Chuck Lever9f06c712010-12-14 14:59:18 +00002133 encode_compound_hdr(xdr, req, &hdr);
2134 encode_sequence(xdr, &args->seq_args, &hdr);
2135 encode_putfh(xdr, args->fh, &hdr);
2136 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002137 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138}
2139
Chuck Lever9f06c712010-12-14 14:59:18 +00002140static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2141 struct xdr_stream *xdr,
2142 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002143{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002144 struct compound_hdr hdr = {
2145 .minorversion = 0,
2146 };
2147
Chuck Lever9f06c712010-12-14 14:59:18 +00002148 encode_compound_hdr(xdr, req, &hdr);
2149 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002150 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002151}
2152
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153/*
2154 * Encode a READLINK request
2155 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002156static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2157 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002160 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
Chuck Lever9f06c712010-12-14 14:59:18 +00002163 encode_compound_hdr(xdr, req, &hdr);
2164 encode_sequence(xdr, &args->seq_args, &hdr);
2165 encode_putfh(xdr, args->fh, &hdr);
2166 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002167
Benny Halevy28f56692009-04-01 09:22:09 -04002168 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002169 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002170 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171}
2172
2173/*
2174 * Encode a READDIR request
2175 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002176static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2177 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002180 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
Chuck Lever9f06c712010-12-14 14:59:18 +00002183 encode_compound_hdr(xdr, req, &hdr);
2184 encode_sequence(xdr, &args->seq_args, &hdr);
2185 encode_putfh(xdr, args->fh, &hdr);
2186 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002187
Benny Halevy28f56692009-04-01 09:22:09 -04002188 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002189 args->pgbase, args->count);
2190 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002191 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002192 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002193 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194}
2195
2196/*
2197 * Encode a READ request
2198 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002199static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2200 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002203 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205
Chuck Lever9f06c712010-12-14 14:59:18 +00002206 encode_compound_hdr(xdr, req, &hdr);
2207 encode_sequence(xdr, &args->seq_args, &hdr);
2208 encode_putfh(xdr, args->fh, &hdr);
2209 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
Benny Halevy28f56692009-04-01 09:22:09 -04002211 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002213 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002214 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215}
2216
2217/*
2218 * Encode an SETATTR request
2219 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002220static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2221 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222{
Andy Adamson05d564f2008-12-23 16:06:15 -05002223 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002224 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002225 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
Chuck Lever9f06c712010-12-14 14:59:18 +00002227 encode_compound_hdr(xdr, req, &hdr);
2228 encode_sequence(xdr, &args->seq_args, &hdr);
2229 encode_putfh(xdr, args->fh, &hdr);
2230 encode_setattr(xdr, args, args->server, &hdr);
2231 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002232 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233}
2234
2235/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002236 * Encode a GETACL request
2237 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002238static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2239 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002240{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002241 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002242 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002243 };
Benny Halevy28f56692009-04-01 09:22:09 -04002244 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002245
Chuck Lever9f06c712010-12-14 14:59:18 +00002246 encode_compound_hdr(xdr, req, &hdr);
2247 encode_sequence(xdr, &args->seq_args, &hdr);
2248 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002249 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002250 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002251
Benny Halevy28f56692009-04-01 09:22:09 -04002252 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002253 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002254 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002255}
2256
2257/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 * Encode a WRITE request
2259 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002260static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2261 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002264 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Chuck Lever9f06c712010-12-14 14:59:18 +00002267 encode_compound_hdr(xdr, req, &hdr);
2268 encode_sequence(xdr, &args->seq_args, &hdr);
2269 encode_putfh(xdr, args->fh, &hdr);
2270 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002271 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Chuck Lever9f06c712010-12-14 14:59:18 +00002272 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002273 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274}
2275
2276/*
2277 * a COMMIT request
2278 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002279static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2280 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002283 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
Chuck Lever9f06c712010-12-14 14:59:18 +00002286 encode_compound_hdr(xdr, req, &hdr);
2287 encode_sequence(xdr, &args->seq_args, &hdr);
2288 encode_putfh(xdr, args->fh, &hdr);
2289 encode_commit(xdr, args, &hdr);
2290 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002291 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292}
2293
2294/*
2295 * FSINFO request
2296 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002297static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2298 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002301 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
Chuck Lever9f06c712010-12-14 14:59:18 +00002304 encode_compound_hdr(xdr, req, &hdr);
2305 encode_sequence(xdr, &args->seq_args, &hdr);
2306 encode_putfh(xdr, args->fh, &hdr);
2307 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002308 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309}
2310
2311/*
2312 * a PATHCONF request
2313 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002314static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2315 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002318 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Chuck Lever9f06c712010-12-14 14:59:18 +00002321 encode_compound_hdr(xdr, req, &hdr);
2322 encode_sequence(xdr, &args->seq_args, &hdr);
2323 encode_putfh(xdr, args->fh, &hdr);
2324 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002325 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002326 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327}
2328
2329/*
2330 * a STATFS request
2331 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002332static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2333 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002336 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Chuck Lever9f06c712010-12-14 14:59:18 +00002339 encode_compound_hdr(xdr, req, &hdr);
2340 encode_sequence(xdr, &args->seq_args, &hdr);
2341 encode_putfh(xdr, args->fh, &hdr);
2342 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002343 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002344 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345}
2346
2347/*
2348 * GETATTR_BITMAP request
2349 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002350static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2351 struct xdr_stream *xdr,
2352 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002355 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
Chuck Lever9f06c712010-12-14 14:59:18 +00002358 encode_compound_hdr(xdr, req, &hdr);
2359 encode_sequence(xdr, &args->seq_args, &hdr);
2360 encode_putfh(xdr, args->fhandle, &hdr);
2361 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002362 FATTR4_WORD0_LINK_SUPPORT|
2363 FATTR4_WORD0_SYMLINK_SUPPORT|
2364 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002365 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366}
2367
2368/*
2369 * a RENEW request
2370 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002371static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2372 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002375 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 };
2377
Chuck Lever9f06c712010-12-14 14:59:18 +00002378 encode_compound_hdr(xdr, req, &hdr);
2379 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002380 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381}
2382
2383/*
2384 * a SETCLIENTID request
2385 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002386static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2387 struct xdr_stream *xdr,
2388 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002391 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 };
2393
Chuck Lever9f06c712010-12-14 14:59:18 +00002394 encode_compound_hdr(xdr, req, &hdr);
2395 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002396 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397}
2398
2399/*
2400 * a SETCLIENTID_CONFIRM request
2401 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002402static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2403 struct xdr_stream *xdr,
2404 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002407 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 };
2409 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
Chuck Lever9f06c712010-12-14 14:59:18 +00002411 encode_compound_hdr(xdr, req, &hdr);
2412 encode_setclientid_confirm(xdr, arg, &hdr);
2413 encode_putrootfh(xdr, &hdr);
2414 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002415 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416}
2417
2418/*
2419 * DELEGRETURN request
2420 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002421static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2422 struct xdr_stream *xdr,
2423 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002426 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Chuck Lever9f06c712010-12-14 14:59:18 +00002429 encode_compound_hdr(xdr, req, &hdr);
2430 encode_sequence(xdr, &args->seq_args, &hdr);
2431 encode_putfh(xdr, args->fhandle, &hdr);
2432 encode_delegreturn(xdr, args->stateid, &hdr);
2433 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002434 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435}
2436
2437/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002438 * Encode FS_LOCATIONS request
2439 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002440static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2441 struct xdr_stream *xdr,
2442 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002443{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002444 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002445 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002446 };
Benny Halevy28f56692009-04-01 09:22:09 -04002447 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002448
Chuck Lever9f06c712010-12-14 14:59:18 +00002449 encode_compound_hdr(xdr, req, &hdr);
2450 encode_sequence(xdr, &args->seq_args, &hdr);
2451 encode_putfh(xdr, args->dir_fh, &hdr);
2452 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002453 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002454 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002455
Benny Halevy28f56692009-04-01 09:22:09 -04002456 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002457 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002458 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002459}
2460
Benny Halevy99fe60d2009-04-01 09:22:29 -04002461#if defined(CONFIG_NFS_V4_1)
2462/*
2463 * EXCHANGE_ID request
2464 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002465static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2466 struct xdr_stream *xdr,
2467 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002468{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002469 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002470 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002471 };
2472
Chuck Lever9f06c712010-12-14 14:59:18 +00002473 encode_compound_hdr(xdr, req, &hdr);
2474 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002475 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002476}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002477
2478/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002479 * a CREATE_SESSION request
2480 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002481static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2482 struct xdr_stream *xdr,
2483 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002484{
Andy Adamsonfc931582009-04-01 09:22:31 -04002485 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002486 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002487 };
2488
Chuck Lever9f06c712010-12-14 14:59:18 +00002489 encode_compound_hdr(xdr, req, &hdr);
2490 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002491 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002492}
2493
2494/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002495 * a DESTROY_SESSION request
2496 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002497static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2498 struct xdr_stream *xdr,
2499 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002500{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002501 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002502 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002503 };
2504
Chuck Lever9f06c712010-12-14 14:59:18 +00002505 encode_compound_hdr(xdr, req, &hdr);
2506 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002507 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002508}
2509
2510/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002511 * a SEQUENCE request
2512 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002513static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2514 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002515{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002516 struct compound_hdr hdr = {
2517 .minorversion = nfs4_xdr_minorversion(args),
2518 };
2519
Chuck Lever9f06c712010-12-14 14:59:18 +00002520 encode_compound_hdr(xdr, req, &hdr);
2521 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002522 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002523}
2524
2525/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002526 * a GET_LEASE_TIME request
2527 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002528static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2529 struct xdr_stream *xdr,
2530 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002531{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002532 struct compound_hdr hdr = {
2533 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2534 };
2535 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2536
Chuck Lever9f06c712010-12-14 14:59:18 +00002537 encode_compound_hdr(xdr, req, &hdr);
2538 encode_sequence(xdr, &args->la_seq_args, &hdr);
2539 encode_putrootfh(xdr, &hdr);
2540 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002541 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002542}
Ricardo Labiaga18019752009-12-05 16:08:40 -05002543
2544/*
2545 * a RECLAIM_COMPLETE request
2546 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002547static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2548 struct xdr_stream *xdr,
2549 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga18019752009-12-05 16:08:40 -05002550{
Ricardo Labiaga18019752009-12-05 16:08:40 -05002551 struct compound_hdr hdr = {
2552 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2553 };
2554
Chuck Lever9f06c712010-12-14 14:59:18 +00002555 encode_compound_hdr(xdr, req, &hdr);
2556 encode_sequence(xdr, &args->seq_args, &hdr);
2557 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002558 encode_nops(&hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002559}
2560
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002561/*
2562 * Encode GETDEVICEINFO request
2563 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002564static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2565 struct xdr_stream *xdr,
2566 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002567{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002568 struct compound_hdr hdr = {
2569 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2570 };
2571
Chuck Lever9f06c712010-12-14 14:59:18 +00002572 encode_compound_hdr(xdr, req, &hdr);
2573 encode_sequence(xdr, &args->seq_args, &hdr);
2574 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002575
2576 /* set up reply kvec. Subtract notification bitmap max size (2)
2577 * so that notification bitmap is put in xdr_buf tail */
2578 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2579 args->pdev->pages, args->pdev->pgbase,
2580 args->pdev->pglen);
2581
2582 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002583}
2584
2585/*
2586 * Encode LAYOUTGET request
2587 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002588static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2589 struct xdr_stream *xdr,
2590 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002591{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002592 struct compound_hdr hdr = {
2593 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2594 };
2595
Chuck Lever9f06c712010-12-14 14:59:18 +00002596 encode_compound_hdr(xdr, req, &hdr);
2597 encode_sequence(xdr, &args->seq_args, &hdr);
2598 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2599 encode_layoutget(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002600 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002601}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002602#endif /* CONFIG_NFS_V4_1 */
2603
Benny Halevy686841b2009-08-14 17:19:48 +03002604static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2605{
2606 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2607 "Remaining buffer length is %tu words.\n",
2608 func, xdr->end - xdr->p);
2609}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610
Trond Myklebust683b57b2006-06-09 09:34:22 -04002611static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612{
Al Viro8687b632006-10-19 23:28:48 -07002613 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614
Benny Halevyc0eae662009-08-14 17:20:14 +03002615 p = xdr_inline_decode(xdr, 4);
2616 if (unlikely(!p))
2617 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002618 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002619 p = xdr_inline_decode(xdr, *len);
2620 if (unlikely(!p))
2621 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 *string = (char *)p;
2623 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002624out_overflow:
2625 print_overflow_msg(__func__, xdr);
2626 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627}
2628
2629static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2630{
Al Viro8687b632006-10-19 23:28:48 -07002631 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
Benny Halevyc0eae662009-08-14 17:20:14 +03002633 p = xdr_inline_decode(xdr, 8);
2634 if (unlikely(!p))
2635 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002636 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002637 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002638
Benny Halevyc0eae662009-08-14 17:20:14 +03002639 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2640 if (unlikely(!p))
2641 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 hdr->tag = (char *)p;
2643 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002644 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002645 if (unlikely(hdr->nops < 1))
2646 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002648out_overflow:
2649 print_overflow_msg(__func__, xdr);
2650 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651}
2652
2653static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2654{
Al Viro8687b632006-10-19 23:28:48 -07002655 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 uint32_t opnum;
2657 int32_t nfserr;
2658
Benny Halevyc0eae662009-08-14 17:20:14 +03002659 p = xdr_inline_decode(xdr, 8);
2660 if (unlikely(!p))
2661 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002662 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002664 dprintk("nfs: Server returned operation"
2665 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 opnum, expected);
2667 return -EIO;
2668 }
Benny Halevycccddf42009-08-14 17:20:19 +03002669 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002671 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002673out_overflow:
2674 print_overflow_msg(__func__, xdr);
2675 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676}
2677
2678/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002679static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680{
Al Viro8687b632006-10-19 23:28:48 -07002681 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002682 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 char *str;
2684
Benny Halevyc0eae662009-08-14 17:20:14 +03002685 p = xdr_inline_decode(xdr, 12);
2686 if (likely(p))
2687 return decode_opaque_inline(xdr, &strlen, &str);
2688 print_overflow_msg(__func__, xdr);
2689 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690}
2691
2692static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2693{
Al Viro8687b632006-10-19 23:28:48 -07002694 uint32_t bmlen;
2695 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
Benny Halevyc0eae662009-08-14 17:20:14 +03002697 p = xdr_inline_decode(xdr, 4);
2698 if (unlikely(!p))
2699 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002700 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701
2702 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002703 p = xdr_inline_decode(xdr, (bmlen << 2));
2704 if (unlikely(!p))
2705 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002707 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002709 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 }
2711 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002712out_overflow:
2713 print_overflow_msg(__func__, xdr);
2714 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715}
2716
Al Viro8687b632006-10-19 23:28:48 -07002717static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718{
Al Viro8687b632006-10-19 23:28:48 -07002719 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720
Benny Halevyc0eae662009-08-14 17:20:14 +03002721 p = xdr_inline_decode(xdr, 4);
2722 if (unlikely(!p))
2723 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002724 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 *savep = xdr->p;
2726 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002727out_overflow:
2728 print_overflow_msg(__func__, xdr);
2729 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730}
2731
2732static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2733{
2734 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04002735 int ret;
2736 ret = decode_attr_bitmap(xdr, bitmask);
2737 if (unlikely(ret < 0))
2738 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2740 } else
2741 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002742 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 return 0;
2744}
2745
2746static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2747{
Al Viro8687b632006-10-19 23:28:48 -07002748 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002749 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750
2751 *type = 0;
2752 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2753 return -EIO;
2754 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002755 p = xdr_inline_decode(xdr, 4);
2756 if (unlikely(!p))
2757 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002758 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002760 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 return -EIO;
2762 }
2763 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002764 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002766 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002767 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002768out_overflow:
2769 print_overflow_msg(__func__, xdr);
2770 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771}
2772
2773static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2774{
Al Viro8687b632006-10-19 23:28:48 -07002775 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002776 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777
2778 *change = 0;
2779 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2780 return -EIO;
2781 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002782 p = xdr_inline_decode(xdr, 8);
2783 if (unlikely(!p))
2784 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002785 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002787 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002789 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002791 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002792out_overflow:
2793 print_overflow_msg(__func__, xdr);
2794 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795}
2796
2797static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2798{
Al Viro8687b632006-10-19 23:28:48 -07002799 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002800 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801
2802 *size = 0;
2803 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2804 return -EIO;
2805 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002806 p = xdr_inline_decode(xdr, 8);
2807 if (unlikely(!p))
2808 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002809 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002811 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002813 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002814 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002815out_overflow:
2816 print_overflow_msg(__func__, xdr);
2817 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818}
2819
2820static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2821{
Al Viro8687b632006-10-19 23:28:48 -07002822 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823
2824 *res = 0;
2825 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2826 return -EIO;
2827 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002828 p = xdr_inline_decode(xdr, 4);
2829 if (unlikely(!p))
2830 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002831 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2833 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002834 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002836out_overflow:
2837 print_overflow_msg(__func__, xdr);
2838 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839}
2840
2841static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2842{
Al Viro8687b632006-10-19 23:28:48 -07002843 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
2845 *res = 0;
2846 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2847 return -EIO;
2848 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002849 p = xdr_inline_decode(xdr, 4);
2850 if (unlikely(!p))
2851 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002852 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2854 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002855 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002857out_overflow:
2858 print_overflow_msg(__func__, xdr);
2859 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860}
2861
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002862static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863{
Al Viro8687b632006-10-19 23:28:48 -07002864 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002865 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866
2867 fsid->major = 0;
2868 fsid->minor = 0;
2869 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2870 return -EIO;
2871 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002872 p = xdr_inline_decode(xdr, 16);
2873 if (unlikely(!p))
2874 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03002875 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03002876 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002878 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002880 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 (unsigned long long)fsid->major,
2882 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002883 return ret;
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_lease_time(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 = 60;
2894 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2895 return -EIO;
2896 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
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_LEASE_TIME;
2902 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002903 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
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
Bryan Schumakerae42c702010-10-21 16:33:17 -04002910static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
2911{
2912 __be32 *p;
2913
2914 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
2915 return -EIO;
2916 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
2917 p = xdr_inline_decode(xdr, 4);
2918 if (unlikely(!p))
2919 goto out_overflow;
2920 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
2921 }
2922 return 0;
2923out_overflow:
2924 print_overflow_msg(__func__, xdr);
2925 return -EIO;
2926}
2927
2928static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
2929{
2930 __be32 *p;
2931 int len;
2932
Trond Myklebust7ad07352010-10-23 15:34:20 -04002933 if (fh != NULL)
2934 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04002935
2936 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
2937 return -EIO;
2938 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
2939 p = xdr_inline_decode(xdr, 4);
2940 if (unlikely(!p))
2941 goto out_overflow;
2942 len = be32_to_cpup(p);
2943 if (len > NFS4_FHSIZE)
2944 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04002945 p = xdr_inline_decode(xdr, len);
2946 if (unlikely(!p))
2947 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04002948 if (fh != NULL) {
2949 memcpy(fh->data, p, len);
2950 fh->size = len;
2951 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04002952 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
2953 }
2954 return 0;
2955out_overflow:
2956 print_overflow_msg(__func__, xdr);
2957 return -EIO;
2958}
2959
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2961{
Al Viro8687b632006-10-19 23:28:48 -07002962 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963
2964 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2965 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2966 return -EIO;
2967 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002968 p = xdr_inline_decode(xdr, 4);
2969 if (unlikely(!p))
2970 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002971 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2973 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002974 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002976out_overflow:
2977 print_overflow_msg(__func__, xdr);
2978 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979}
2980
2981static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2982{
Al Viro8687b632006-10-19 23:28:48 -07002983 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002984 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985
2986 *fileid = 0;
2987 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2988 return -EIO;
2989 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002990 p = xdr_inline_decode(xdr, 8);
2991 if (unlikely(!p))
2992 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002993 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002995 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002997 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002998 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002999out_overflow:
3000 print_overflow_msg(__func__, xdr);
3001 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002}
3003
Manoj Naik99baf622006-06-09 09:34:24 -04003004static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3005{
Al Viro8687b632006-10-19 23:28:48 -07003006 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003007 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003008
3009 *fileid = 0;
3010 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3011 return -EIO;
3012 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003013 p = xdr_inline_decode(xdr, 8);
3014 if (unlikely(!p))
3015 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003016 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003017 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003018 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003019 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003020 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003021 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003022out_overflow:
3023 print_overflow_msg(__func__, xdr);
3024 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003025}
3026
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3028{
Al Viro8687b632006-10-19 23:28:48 -07003029 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 int status = 0;
3031
3032 *res = 0;
3033 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3034 return -EIO;
3035 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003036 p = xdr_inline_decode(xdr, 8);
3037 if (unlikely(!p))
3038 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003039 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3041 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003042 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003044out_overflow:
3045 print_overflow_msg(__func__, xdr);
3046 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047}
3048
3049static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3050{
Al Viro8687b632006-10-19 23:28:48 -07003051 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 int status = 0;
3053
3054 *res = 0;
3055 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3056 return -EIO;
3057 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003058 p = xdr_inline_decode(xdr, 8);
3059 if (unlikely(!p))
3060 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003061 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3063 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003064 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003066out_overflow:
3067 print_overflow_msg(__func__, xdr);
3068 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069}
3070
3071static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3072{
Al Viro8687b632006-10-19 23:28:48 -07003073 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 int status = 0;
3075
3076 *res = 0;
3077 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3078 return -EIO;
3079 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003080 p = xdr_inline_decode(xdr, 8);
3081 if (unlikely(!p))
3082 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003083 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3085 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003086 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003088out_overflow:
3089 print_overflow_msg(__func__, xdr);
3090 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091}
3092
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003093static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3094{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003095 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003096 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003097 int status = 0;
3098
Benny Halevyc0eae662009-08-14 17:20:14 +03003099 p = xdr_inline_decode(xdr, 4);
3100 if (unlikely(!p))
3101 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003102 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003103 if (n == 0)
3104 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003105 dprintk("path ");
3106 path->ncomponents = 0;
3107 while (path->ncomponents < n) {
3108 struct nfs4_string *component = &path->components[path->ncomponents];
3109 status = decode_opaque_inline(xdr, &component->len, &component->data);
3110 if (unlikely(status != 0))
3111 goto out_eio;
3112 if (path->ncomponents != n)
3113 dprintk("/");
3114 dprintk("%s", component->data);
3115 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3116 path->ncomponents++;
3117 else {
3118 dprintk("cannot parse %d components in path\n", n);
3119 goto out_eio;
3120 }
3121 }
3122out:
3123 dprintk("\n");
3124 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003125root_path:
3126/* a root pathname is sent as a zero component4 */
3127 path->ncomponents = 1;
3128 path->components[0].len=0;
3129 path->components[0].data=NULL;
3130 dprintk("path /\n");
3131 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003132out_eio:
3133 dprintk(" status %d", status);
3134 status = -EIO;
3135 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003136out_overflow:
3137 print_overflow_msg(__func__, xdr);
3138 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003139}
3140
3141static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003142{
3143 int n;
Al Viro8687b632006-10-19 23:28:48 -07003144 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003145 int status = -EIO;
3146
3147 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3148 goto out;
3149 status = 0;
3150 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3151 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003152 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003153 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003154 if (unlikely(status != 0))
3155 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003156 p = xdr_inline_decode(xdr, 4);
3157 if (unlikely(!p))
3158 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003159 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003160 if (n <= 0)
3161 goto out_eio;
3162 res->nlocations = 0;
3163 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003164 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003165 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003166
Benny Halevyc0eae662009-08-14 17:20:14 +03003167 p = xdr_inline_decode(xdr, 4);
3168 if (unlikely(!p))
3169 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003170 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003171
3172 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003173 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003174 while (loc->nservers < m) {
3175 struct nfs4_string *server = &loc->servers[loc->nservers];
3176 status = decode_opaque_inline(xdr, &server->len, &server->data);
3177 if (unlikely(status != 0))
3178 goto out_eio;
3179 dprintk("%s ", server->data);
3180 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3181 loc->nservers++;
3182 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003183 unsigned int i;
3184 dprintk("%s: using first %u of %u servers "
3185 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003186 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003187 NFS4_FS_LOCATION_MAXSERVERS,
3188 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003189 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003190 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003191 char *data;
3192 status = decode_opaque_inline(xdr, &len, &data);
3193 if (unlikely(status != 0))
3194 goto out_eio;
3195 }
3196 }
3197 }
3198 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003199 if (unlikely(status != 0))
3200 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003201 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003202 res->nlocations++;
3203 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003204 if (res->nlocations != 0)
3205 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003206out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003207 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003208 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003209out_overflow:
3210 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003211out_eio:
3212 status = -EIO;
3213 goto out;
3214}
3215
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3217{
Al Viro8687b632006-10-19 23:28:48 -07003218 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 int status = 0;
3220
3221 *res = 0;
3222 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3223 return -EIO;
3224 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003225 p = xdr_inline_decode(xdr, 8);
3226 if (unlikely(!p))
3227 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003228 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3230 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003231 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003233out_overflow:
3234 print_overflow_msg(__func__, xdr);
3235 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236}
3237
3238static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3239{
Al Viro8687b632006-10-19 23:28:48 -07003240 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 int status = 0;
3242
3243 *maxlink = 1;
3244 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3245 return -EIO;
3246 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003247 p = xdr_inline_decode(xdr, 4);
3248 if (unlikely(!p))
3249 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003250 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3252 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003253 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003255out_overflow:
3256 print_overflow_msg(__func__, xdr);
3257 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258}
3259
3260static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3261{
Al Viro8687b632006-10-19 23:28:48 -07003262 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 int status = 0;
3264
3265 *maxname = 1024;
3266 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3267 return -EIO;
3268 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003269 p = xdr_inline_decode(xdr, 4);
3270 if (unlikely(!p))
3271 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003272 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3274 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003275 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003277out_overflow:
3278 print_overflow_msg(__func__, xdr);
3279 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280}
3281
3282static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3283{
Al Viro8687b632006-10-19 23:28:48 -07003284 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 int status = 0;
3286
3287 *res = 1024;
3288 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3289 return -EIO;
3290 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3291 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003292 p = xdr_inline_decode(xdr, 8);
3293 if (unlikely(!p))
3294 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003295 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 if (maxread > 0x7FFFFFFF)
3297 maxread = 0x7FFFFFFF;
3298 *res = (uint32_t)maxread;
3299 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3300 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003301 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
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_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3309{
Al Viro8687b632006-10-19 23:28:48 -07003310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 int status = 0;
3312
3313 *res = 1024;
3314 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3315 return -EIO;
3316 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3317 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003318 p = xdr_inline_decode(xdr, 8);
3319 if (unlikely(!p))
3320 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003321 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 if (maxwrite > 0x7FFFFFFF)
3323 maxwrite = 0x7FFFFFFF;
3324 *res = (uint32_t)maxwrite;
3325 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3326 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003327 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003329out_overflow:
3330 print_overflow_msg(__func__, xdr);
3331 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332}
3333
Trond Myklebustbca79472009-03-11 14:10:26 -04003334static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335{
Trond Myklebustbca79472009-03-11 14:10:26 -04003336 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003337 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003338 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
3340 *mode = 0;
3341 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3342 return -EIO;
3343 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003344 p = xdr_inline_decode(xdr, 4);
3345 if (unlikely(!p))
3346 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003347 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003348 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003350 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003352 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003353 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003354out_overflow:
3355 print_overflow_msg(__func__, xdr);
3356 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357}
3358
3359static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3360{
Al Viro8687b632006-10-19 23:28:48 -07003361 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003362 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363
3364 *nlink = 1;
3365 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3366 return -EIO;
3367 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003368 p = xdr_inline_decode(xdr, 4);
3369 if (unlikely(!p))
3370 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003371 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003373 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003375 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003376 return ret;
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 Myklebust80e52ac2009-08-09 15:06:19 -04003382static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3383 struct nfs_client *clp, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384{
Al Viro8687b632006-10-19 23:28:48 -07003385 uint32_t len;
3386 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003387 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388
3389 *uid = -2;
3390 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3391 return -EIO;
3392 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003393 p = xdr_inline_decode(xdr, 4);
3394 if (unlikely(!p))
3395 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003396 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003397 p = xdr_inline_decode(xdr, len);
3398 if (unlikely(!p))
3399 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003400 if (!may_sleep) {
3401 /* do nothing */
3402 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003403 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
3404 ret = NFS_ATTR_FATTR_OWNER;
3405 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003407 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003409 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003410 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3412 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003413 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003414 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003415out_overflow:
3416 print_overflow_msg(__func__, xdr);
3417 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418}
3419
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003420static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3421 struct nfs_client *clp, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422{
Al Viro8687b632006-10-19 23:28:48 -07003423 uint32_t len;
3424 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003425 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426
3427 *gid = -2;
3428 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3429 return -EIO;
3430 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003431 p = xdr_inline_decode(xdr, 4);
3432 if (unlikely(!p))
3433 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003434 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003435 p = xdr_inline_decode(xdr, len);
3436 if (unlikely(!p))
3437 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003438 if (!may_sleep) {
3439 /* do nothing */
3440 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04003441 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
3442 ret = NFS_ATTR_FATTR_GROUP;
3443 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003445 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003447 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003448 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3450 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003451 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003452 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003453out_overflow:
3454 print_overflow_msg(__func__, xdr);
3455 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456}
3457
3458static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3459{
Al Viro8687b632006-10-19 23:28:48 -07003460 uint32_t major = 0, minor = 0;
3461 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003462 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463
3464 *rdev = MKDEV(0,0);
3465 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3466 return -EIO;
3467 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3468 dev_t tmp;
3469
Benny Halevyc0eae662009-08-14 17:20:14 +03003470 p = xdr_inline_decode(xdr, 8);
3471 if (unlikely(!p))
3472 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003473 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003474 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 tmp = MKDEV(major, minor);
3476 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3477 *rdev = tmp;
3478 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003479 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003481 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003482 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003483out_overflow:
3484 print_overflow_msg(__func__, xdr);
3485 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486}
3487
3488static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3489{
Al Viro8687b632006-10-19 23:28:48 -07003490 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 int status = 0;
3492
3493 *res = 0;
3494 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3495 return -EIO;
3496 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003497 p = xdr_inline_decode(xdr, 8);
3498 if (unlikely(!p))
3499 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003500 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3502 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003503 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003505out_overflow:
3506 print_overflow_msg(__func__, xdr);
3507 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508}
3509
3510static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3511{
Al Viro8687b632006-10-19 23:28:48 -07003512 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 int status = 0;
3514
3515 *res = 0;
3516 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3517 return -EIO;
3518 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003519 p = xdr_inline_decode(xdr, 8);
3520 if (unlikely(!p))
3521 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003522 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3524 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003525 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003527out_overflow:
3528 print_overflow_msg(__func__, xdr);
3529 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530}
3531
3532static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3533{
Al Viro8687b632006-10-19 23:28:48 -07003534 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 int status = 0;
3536
3537 *res = 0;
3538 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3539 return -EIO;
3540 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003541 p = xdr_inline_decode(xdr, 8);
3542 if (unlikely(!p))
3543 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003544 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3546 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003547 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003549out_overflow:
3550 print_overflow_msg(__func__, xdr);
3551 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552}
3553
3554static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3555{
Al Viro8687b632006-10-19 23:28:48 -07003556 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003557 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558
3559 *used = 0;
3560 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3561 return -EIO;
3562 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003563 p = xdr_inline_decode(xdr, 8);
3564 if (unlikely(!p))
3565 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003566 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003568 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003570 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003572 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003573out_overflow:
3574 print_overflow_msg(__func__, xdr);
3575 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576}
3577
3578static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3579{
Al Viro8687b632006-10-19 23:28:48 -07003580 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 uint64_t sec;
3582 uint32_t nsec;
3583
Benny Halevyc0eae662009-08-14 17:20:14 +03003584 p = xdr_inline_decode(xdr, 12);
3585 if (unlikely(!p))
3586 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003587 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003588 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589 time->tv_sec = (time_t)sec;
3590 time->tv_nsec = (long)nsec;
3591 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003592out_overflow:
3593 print_overflow_msg(__func__, xdr);
3594 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595}
3596
3597static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3598{
3599 int status = 0;
3600
3601 time->tv_sec = 0;
3602 time->tv_nsec = 0;
3603 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3604 return -EIO;
3605 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3606 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003607 if (status == 0)
3608 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3610 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003611 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 return status;
3613}
3614
3615static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3616{
3617 int status = 0;
3618
3619 time->tv_sec = 0;
3620 time->tv_nsec = 0;
3621 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3622 return -EIO;
3623 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3624 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003625 if (status == 0)
3626 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3628 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003629 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 return status;
3631}
3632
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003633static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3634 struct timespec *time)
3635{
3636 int status = 0;
3637
3638 time->tv_sec = 0;
3639 time->tv_nsec = 0;
3640 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3641 return -EIO;
3642 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3643 status = decode_attr_time(xdr, time);
3644 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3645 }
3646 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3647 (long)time->tv_nsec);
3648 return status;
3649}
3650
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3652{
3653 int status = 0;
3654
3655 time->tv_sec = 0;
3656 time->tv_nsec = 0;
3657 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3658 return -EIO;
3659 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3660 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003661 if (status == 0)
3662 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3664 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003665 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666 return status;
3667}
3668
Al Viro8687b632006-10-19 23:28:48 -07003669static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670{
3671 unsigned int attrwords = XDR_QUADLEN(attrlen);
3672 unsigned int nwords = xdr->p - savep;
3673
3674 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003675 dprintk("%s: server returned incorrect attribute length: "
3676 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003677 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 attrwords << 2,
3679 (attrwords < nwords) ? '<' : '>',
3680 nwords << 2);
3681 return -EIO;
3682 }
3683 return 0;
3684}
3685
3686static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3687{
Al Viro8687b632006-10-19 23:28:48 -07003688 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689
Benny Halevyc0eae662009-08-14 17:20:14 +03003690 p = xdr_inline_decode(xdr, 20);
3691 if (unlikely(!p))
3692 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003693 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003694 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003695 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003697out_overflow:
3698 print_overflow_msg(__func__, xdr);
3699 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700}
3701
3702static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3703{
Al Viro8687b632006-10-19 23:28:48 -07003704 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 uint32_t supp, acc;
3706 int status;
3707
3708 status = decode_op_hdr(xdr, OP_ACCESS);
3709 if (status)
3710 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003711 p = xdr_inline_decode(xdr, 8);
3712 if (unlikely(!p))
3713 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003714 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003715 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 access->supported = supp;
3717 access->access = acc;
3718 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003719out_overflow:
3720 print_overflow_msg(__func__, xdr);
3721 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722}
3723
Benny Halevy07d30432009-08-14 17:19:52 +03003724static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725{
Al Viro8687b632006-10-19 23:28:48 -07003726 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003727
3728 p = xdr_inline_decode(xdr, len);
3729 if (likely(p)) {
3730 memcpy(buf, p, len);
3731 return 0;
3732 }
3733 print_overflow_msg(__func__, xdr);
3734 return -EIO;
3735}
3736
3737static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3738{
3739 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740}
3741
3742static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3743{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 int status;
3745
3746 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003747 if (status != -EIO)
3748 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003749 if (!status)
3750 status = decode_stateid(xdr, &res->stateid);
3751 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752}
3753
Benny Halevydb942bb2009-08-14 17:19:56 +03003754static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3755{
3756 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757}
3758
3759static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3760{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 int status;
3762
3763 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003764 if (!status)
3765 status = decode_verifier(xdr, res->verf->verifier);
3766 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767}
3768
3769static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3770{
Al Viro8687b632006-10-19 23:28:48 -07003771 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 uint32_t bmlen;
3773 int status;
3774
3775 status = decode_op_hdr(xdr, OP_CREATE);
3776 if (status)
3777 return status;
3778 if ((status = decode_change_info(xdr, cinfo)))
3779 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003780 p = xdr_inline_decode(xdr, 4);
3781 if (unlikely(!p))
3782 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003783 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003784 p = xdr_inline_decode(xdr, bmlen << 2);
3785 if (likely(p))
3786 return 0;
3787out_overflow:
3788 print_overflow_msg(__func__, xdr);
3789 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790}
3791
3792static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3793{
Al Viro8687b632006-10-19 23:28:48 -07003794 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003795 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796 int status;
3797
3798 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3799 goto xdr_error;
3800 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3801 goto xdr_error;
3802 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3803 goto xdr_error;
3804 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3805 goto xdr_error;
3806 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3807 goto xdr_error;
3808 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3809 goto xdr_error;
3810 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3811 goto xdr_error;
3812 status = verify_attr_len(xdr, savep, attrlen);
3813xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003814 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 return status;
3816}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003817
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3819{
Al Viro8687b632006-10-19 23:28:48 -07003820 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003821 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003823
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3825 goto xdr_error;
3826 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3827 goto xdr_error;
3828 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3829 goto xdr_error;
3830
3831 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
3832 goto xdr_error;
3833 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
3834 goto xdr_error;
3835 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
3836 goto xdr_error;
3837 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
3838 goto xdr_error;
3839 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
3840 goto xdr_error;
3841 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
3842 goto xdr_error;
3843
3844 status = verify_attr_len(xdr, savep, attrlen);
3845xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003846 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 return status;
3848}
3849
3850static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3851{
Al Viro8687b632006-10-19 23:28:48 -07003852 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003853 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003855
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3857 goto xdr_error;
3858 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3859 goto xdr_error;
3860 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3861 goto xdr_error;
3862
3863 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3864 goto xdr_error;
3865 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3866 goto xdr_error;
3867
3868 status = verify_attr_len(xdr, savep, attrlen);
3869xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003870 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 return status;
3872}
3873
Bryan Schumakerae42c702010-10-21 16:33:17 -04003874static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
3875 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003876 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877{
Trond Myklebustbca79472009-03-11 14:10:26 -04003878 int status;
3879 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003880 uint64_t fileid;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003881 uint32_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003883 status = decode_attr_type(xdr, bitmap, &type);
3884 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003886 fattr->mode = 0;
3887 if (status != 0) {
3888 fattr->mode |= nfs_type2fmt[type];
3889 fattr->valid |= status;
3890 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003892 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3893 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003895 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003896
3897 status = decode_attr_size(xdr, bitmap, &fattr->size);
3898 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003900 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003901
3902 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3903 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003905 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003906
Bryan Schumakerae42c702010-10-21 16:33:17 -04003907 status = decode_attr_error(xdr, bitmap);
3908 if (status < 0)
3909 goto xdr_error;
3910
3911 status = decode_attr_filehandle(xdr, bitmap, fh);
3912 if (status < 0)
3913 goto xdr_error;
3914
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003915 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3916 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003918 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003919
3920 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003921 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003922 fattr));
3923 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003924 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003925 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003926
3927 status = decode_attr_mode(xdr, bitmap, &fmode);
3928 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003930 if (status != 0) {
3931 fattr->mode |= fmode;
3932 fattr->valid |= status;
3933 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003934
3935 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3936 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003938 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003939
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003940 status = decode_attr_owner(xdr, bitmap, server->nfs_client,
3941 &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003942 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003944 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003945
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003946 status = decode_attr_group(xdr, bitmap, server->nfs_client,
3947 &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003948 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003950 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003951
3952 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3953 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003955 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003956
3957 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3958 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003960 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003961
3962 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3963 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003965 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003966
3967 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3968 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003970 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003971
3972 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3973 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003975 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003976
3977 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3978 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003979 goto xdr_error;
Trond Myklebust3201f3d2010-10-23 15:43:10 -04003980 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003981 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003982 fattr->valid |= status;
3983 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003984
Bryan Schumakerae42c702010-10-21 16:33:17 -04003985xdr_error:
3986 dprintk("%s: xdr returned %d\n", __func__, -status);
3987 return status;
3988}
3989
3990static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
3991 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
3992{
3993 __be32 *savep;
3994 uint32_t attrlen,
3995 bitmap[2] = {0};
3996 int status;
3997
3998 status = decode_op_hdr(xdr, OP_GETATTR);
3999 if (status < 0)
4000 goto xdr_error;
4001
4002 status = decode_attr_bitmap(xdr, bitmap);
4003 if (status < 0)
4004 goto xdr_error;
4005
4006 status = decode_attr_length(xdr, &attrlen, &savep);
4007 if (status < 0)
4008 goto xdr_error;
4009
4010 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4011 if (status < 0)
4012 goto xdr_error;
4013
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004014 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004016 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 return status;
4018}
4019
Bryan Schumakerae42c702010-10-21 16:33:17 -04004020static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4021 const struct nfs_server *server, int may_sleep)
4022{
4023 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4024}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025
Andy Adamson504913f2010-10-20 00:17:57 -04004026/*
4027 * Decode potentially multiple layout types. Currently we only support
4028 * one layout driver per file system.
4029 */
4030static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4031 uint32_t *layouttype)
4032{
4033 uint32_t *p;
4034 int num;
4035
4036 p = xdr_inline_decode(xdr, 4);
4037 if (unlikely(!p))
4038 goto out_overflow;
4039 num = be32_to_cpup(p);
4040
4041 /* pNFS is not supported by the underlying file system */
4042 if (num == 0) {
4043 *layouttype = 0;
4044 return 0;
4045 }
4046 if (num > 1)
4047 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4048 "per filesystem not supported\n", __func__);
4049
4050 /* Decode and set first layout type, move xdr->p past unused types */
4051 p = xdr_inline_decode(xdr, num * 4);
4052 if (unlikely(!p))
4053 goto out_overflow;
4054 *layouttype = be32_to_cpup(p);
4055 return 0;
4056out_overflow:
4057 print_overflow_msg(__func__, xdr);
4058 return -EIO;
4059}
4060
4061/*
4062 * The type of file system exported.
4063 * Note we must ensure that layouttype is set in any non-error case.
4064 */
4065static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4066 uint32_t *layouttype)
4067{
4068 int status = 0;
4069
4070 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4071 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4072 return -EIO;
4073 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4074 status = decode_first_pnfs_layout_type(xdr, layouttype);
4075 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4076 } else
4077 *layouttype = 0;
4078 return status;
4079}
4080
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4082{
Al Viro8687b632006-10-19 23:28:48 -07004083 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 uint32_t attrlen, bitmap[2];
4085 int status;
4086
4087 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4088 goto xdr_error;
4089 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4090 goto xdr_error;
4091 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4092 goto xdr_error;
4093
4094 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4095
4096 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4097 goto xdr_error;
4098 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4099 goto xdr_error;
4100 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4101 goto xdr_error;
4102 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4103 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4104 goto xdr_error;
4105 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004106 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4107 if (status != 0)
4108 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004109 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4110 if (status != 0)
4111 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112
4113 status = verify_attr_len(xdr, savep, attrlen);
4114xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004115 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 return status;
4117}
4118
4119static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4120{
Al Viro8687b632006-10-19 23:28:48 -07004121 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 uint32_t len;
4123 int status;
4124
Trond Myklebust99367812007-07-17 21:52:41 -04004125 /* Zero handle first to allow comparisons */
4126 memset(fh, 0, sizeof(*fh));
4127
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 status = decode_op_hdr(xdr, OP_GETFH);
4129 if (status)
4130 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131
Benny Halevyc0eae662009-08-14 17:20:14 +03004132 p = xdr_inline_decode(xdr, 4);
4133 if (unlikely(!p))
4134 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004135 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 if (len > NFS4_FHSIZE)
4137 return -EIO;
4138 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004139 p = xdr_inline_decode(xdr, len);
4140 if (unlikely(!p))
4141 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004142 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004144out_overflow:
4145 print_overflow_msg(__func__, xdr);
4146 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147}
4148
4149static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4150{
4151 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004152
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 status = decode_op_hdr(xdr, OP_LINK);
4154 if (status)
4155 return status;
4156 return decode_change_info(xdr, cinfo);
4157}
4158
4159/*
4160 * We create the owner, so we know a proper owner.id length is 4.
4161 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004162static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004164 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004165 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004166 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004168 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004169 if (unlikely(!p))
4170 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004171 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004172 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004173 type = be32_to_cpup(p++); /* 4 byte read */
4174 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004175 fl->fl_start = (loff_t)offset;
4176 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4177 if (length == ~(uint64_t)0)
4178 fl->fl_end = OFFSET_MAX;
4179 fl->fl_type = F_WRLCK;
4180 if (type & 1)
4181 fl->fl_type = F_RDLCK;
4182 fl->fl_pid = 0;
4183 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004184 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4185 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4186 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004187 if (likely(p))
4188 return -NFS4ERR_DENIED;
4189out_overflow:
4190 print_overflow_msg(__func__, xdr);
4191 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192}
4193
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004194static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 int status;
4197
4198 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004199 if (status == -EIO)
4200 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004202 status = decode_stateid(xdr, &res->stateid);
4203 if (unlikely(status))
4204 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004206 status = decode_lock_denied(xdr, NULL);
4207 if (res->open_seqid != NULL)
4208 nfs_increment_open_seqid(status, res->open_seqid);
4209 nfs_increment_lock_seqid(status, res->lock_seqid);
4210out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 return status;
4212}
4213
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004214static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215{
4216 int status;
4217 status = decode_op_hdr(xdr, OP_LOCKT);
4218 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004219 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 return status;
4221}
4222
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004223static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225 int status;
4226
4227 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004228 if (status != -EIO)
4229 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004230 if (status == 0)
4231 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 return status;
4233}
4234
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004235static int decode_release_lockowner(struct xdr_stream *xdr)
4236{
4237 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4238}
4239
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240static int decode_lookup(struct xdr_stream *xdr)
4241{
4242 return decode_op_hdr(xdr, OP_LOOKUP);
4243}
4244
4245/* This is too sick! */
4246static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4247{
Andy Adamson05d564f2008-12-23 16:06:15 -05004248 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 uint32_t limit_type, nblocks, blocksize;
4250
Benny Halevyc0eae662009-08-14 17:20:14 +03004251 p = xdr_inline_decode(xdr, 12);
4252 if (unlikely(!p))
4253 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004254 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004255 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004256 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004257 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004258 break;
4259 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004260 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004261 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004262 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 }
4264 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004265out_overflow:
4266 print_overflow_msg(__func__, xdr);
4267 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268}
4269
4270static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4271{
Andy Adamson05d564f2008-12-23 16:06:15 -05004272 __be32 *p;
4273 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004274 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275
Benny Halevyc0eae662009-08-14 17:20:14 +03004276 p = xdr_inline_decode(xdr, 4);
4277 if (unlikely(!p))
4278 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004279 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4281 res->delegation_type = 0;
4282 return 0;
4283 }
Benny Halevy07d30432009-08-14 17:19:52 +03004284 status = decode_stateid(xdr, &res->delegation);
4285 if (unlikely(status))
4286 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004287 p = xdr_inline_decode(xdr, 4);
4288 if (unlikely(!p))
4289 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004290 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004291
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004293 case NFS4_OPEN_DELEGATE_READ:
4294 res->delegation_type = FMODE_READ;
4295 break;
4296 case NFS4_OPEN_DELEGATE_WRITE:
4297 res->delegation_type = FMODE_WRITE|FMODE_READ;
4298 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299 return -EIO;
4300 }
David Howells7539bba2006-08-22 20:06:09 -04004301 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004302out_overflow:
4303 print_overflow_msg(__func__, xdr);
4304 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305}
4306
4307static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4308{
Andy Adamson05d564f2008-12-23 16:06:15 -05004309 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004310 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004311 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312
Andy Adamson05d564f2008-12-23 16:06:15 -05004313 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004314 if (status != -EIO)
4315 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004316 if (!status)
4317 status = decode_stateid(xdr, &res->stateid);
4318 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004319 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320
Andy Adamson05d564f2008-12-23 16:06:15 -05004321 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322
Benny Halevyc0eae662009-08-14 17:20:14 +03004323 p = xdr_inline_decode(xdr, 8);
4324 if (unlikely(!p))
4325 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004326 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004327 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004328 if (bmlen > 10)
4329 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330
Benny Halevyc0eae662009-08-14 17:20:14 +03004331 p = xdr_inline_decode(xdr, bmlen << 2);
4332 if (unlikely(!p))
4333 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004334 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4335 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004336 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004337 for (; i < NFS4_BITMAP_SIZE; i++)
4338 res->attrset[i] = 0;
4339
Linus Torvalds1da177e2005-04-16 15:20:36 -07004340 return decode_delegation(xdr, res);
4341xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004342 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004344out_overflow:
4345 print_overflow_msg(__func__, xdr);
4346 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347}
4348
4349static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4350{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004351 int status;
4352
Andy Adamson05d564f2008-12-23 16:06:15 -05004353 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004354 if (status != -EIO)
4355 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004356 if (!status)
4357 status = decode_stateid(xdr, &res->stateid);
4358 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359}
4360
4361static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4362{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363 int status;
4364
4365 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004366 if (status != -EIO)
4367 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004368 if (!status)
4369 status = decode_stateid(xdr, &res->stateid);
4370 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371}
4372
4373static int decode_putfh(struct xdr_stream *xdr)
4374{
4375 return decode_op_hdr(xdr, OP_PUTFH);
4376}
4377
4378static int decode_putrootfh(struct xdr_stream *xdr)
4379{
4380 return decode_op_hdr(xdr, OP_PUTROOTFH);
4381}
4382
4383static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4384{
4385 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004386 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387 uint32_t count, eof, recvd, hdrlen;
4388 int status;
4389
4390 status = decode_op_hdr(xdr, OP_READ);
4391 if (status)
4392 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004393 p = xdr_inline_decode(xdr, 8);
4394 if (unlikely(!p))
4395 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004396 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004397 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004398 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 recvd = req->rq_rcv_buf.len - hdrlen;
4400 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004401 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402 "count %u > recvd %u\n", count, recvd);
4403 count = recvd;
4404 eof = 0;
4405 }
4406 xdr_read_pages(xdr, count);
4407 res->eof = eof;
4408 res->count = count;
4409 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004410out_overflow:
4411 print_overflow_msg(__func__, xdr);
4412 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413}
4414
4415static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4416{
4417 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004419 size_t hdrlen;
4420 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004421 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422
4423 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004424 if (!status)
4425 status = decode_verifier(xdr, readdir->verifier.data);
4426 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004428 dprintk("%s: verifier = %08x:%08x\n",
4429 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004430 ((u32 *)readdir->verifier.data)[0],
4431 ((u32 *)readdir->verifier.data)[1]);
4432
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433
Benny Halevydb942bb2009-08-14 17:19:56 +03004434 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 recvd = rcvbuf->len - hdrlen;
4436 if (pglen > recvd)
4437 pglen = recvd;
4438 xdr_read_pages(xdr, pglen);
4439
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004440
Trond Myklebustac396122010-11-15 20:26:22 -05004441 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442}
4443
4444static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4445{
4446 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4447 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004448 size_t hdrlen;
4449 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004450 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004451 int status;
4452
4453 status = decode_op_hdr(xdr, OP_READLINK);
4454 if (status)
4455 return status;
4456
4457 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004458 p = xdr_inline_decode(xdr, 4);
4459 if (unlikely(!p))
4460 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004461 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004463 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 return -ENAMETOOLONG;
4465 }
4466 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4467 recvd = req->rq_rcv_buf.len - hdrlen;
4468 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004469 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 "count %u > recvd %u\n", len, recvd);
4471 return -EIO;
4472 }
4473 xdr_read_pages(xdr, len);
4474 /*
4475 * The XDR encode routine has set things up so that
4476 * the link text will be copied directly into the
4477 * buffer. We just have to do overflow-checking,
4478 * and and null-terminate the text (the VFS expects
4479 * null-termination).
4480 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004481 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004483out_overflow:
4484 print_overflow_msg(__func__, xdr);
4485 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486}
4487
4488static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4489{
4490 int status;
4491
4492 status = decode_op_hdr(xdr, OP_REMOVE);
4493 if (status)
4494 goto out;
4495 status = decode_change_info(xdr, cinfo);
4496out:
4497 return status;
4498}
4499
4500static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4501 struct nfs4_change_info *new_cinfo)
4502{
4503 int status;
4504
4505 status = decode_op_hdr(xdr, OP_RENAME);
4506 if (status)
4507 goto out;
4508 if ((status = decode_change_info(xdr, old_cinfo)))
4509 goto out;
4510 status = decode_change_info(xdr, new_cinfo);
4511out:
4512 return status;
4513}
4514
4515static int decode_renew(struct xdr_stream *xdr)
4516{
4517 return decode_op_hdr(xdr, OP_RENEW);
4518}
4519
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004520static int
4521decode_restorefh(struct xdr_stream *xdr)
4522{
4523 return decode_op_hdr(xdr, OP_RESTOREFH);
4524}
4525
J. Bruce Fields029d1052005-06-22 17:16:22 +00004526static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4527 size_t *acl_len)
4528{
Al Viro8687b632006-10-19 23:28:48 -07004529 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004530 uint32_t attrlen,
4531 bitmap[2] = {0};
4532 struct kvec *iov = req->rq_rcv_buf.head;
4533 int status;
4534
4535 *acl_len = 0;
4536 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4537 goto out;
4538 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4539 goto out;
4540 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4541 goto out;
4542
4543 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4544 return -EIO;
4545 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004546 size_t hdrlen;
4547 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004548
4549 /* We ignore &savep and don't do consistency checks on
4550 * the attr length. Let userspace figure it out.... */
4551 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4552 recvd = req->rq_rcv_buf.len - hdrlen;
4553 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004554 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004555 " acl reply: attrlen %u > recvd %u\n",
4556 attrlen, recvd);
4557 return -EINVAL;
4558 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004559 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004560 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004561 } else
4562 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004563
4564out:
4565 return status;
4566}
4567
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568static int
4569decode_savefh(struct xdr_stream *xdr)
4570{
4571 return decode_op_hdr(xdr, OP_SAVEFH);
4572}
4573
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004574static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575{
Al Viro8687b632006-10-19 23:28:48 -07004576 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577 uint32_t bmlen;
4578 int status;
4579
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580 status = decode_op_hdr(xdr, OP_SETATTR);
4581 if (status)
4582 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004583 p = xdr_inline_decode(xdr, 4);
4584 if (unlikely(!p))
4585 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004586 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004587 p = xdr_inline_decode(xdr, bmlen << 2);
4588 if (likely(p))
4589 return 0;
4590out_overflow:
4591 print_overflow_msg(__func__, xdr);
4592 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593}
4594
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004595static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596{
Al Viro8687b632006-10-19 23:28:48 -07004597 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598 uint32_t opnum;
4599 int32_t nfserr;
4600
Benny Halevyc0eae662009-08-14 17:20:14 +03004601 p = xdr_inline_decode(xdr, 8);
4602 if (unlikely(!p))
4603 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004604 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004606 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004607 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 return -EIO;
4609 }
Benny Halevycccddf42009-08-14 17:20:19 +03004610 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004612 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4613 if (unlikely(!p))
4614 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004615 p = xdr_decode_hyper(p, &res->clientid);
4616 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617 } else if (nfserr == NFSERR_CLID_INUSE) {
4618 uint32_t len;
4619
4620 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004621 p = xdr_inline_decode(xdr, 4);
4622 if (unlikely(!p))
4623 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004624 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004625 p = xdr_inline_decode(xdr, len);
4626 if (unlikely(!p))
4627 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628
4629 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004630 p = xdr_inline_decode(xdr, 4);
4631 if (unlikely(!p))
4632 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004633 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004634 p = xdr_inline_decode(xdr, len);
4635 if (unlikely(!p))
4636 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637 return -NFSERR_CLID_INUSE;
4638 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004639 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640
4641 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004642out_overflow:
4643 print_overflow_msg(__func__, xdr);
4644 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645}
4646
4647static int decode_setclientid_confirm(struct xdr_stream *xdr)
4648{
4649 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4650}
4651
4652static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4653{
Al Viro8687b632006-10-19 23:28:48 -07004654 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 int status;
4656
4657 status = decode_op_hdr(xdr, OP_WRITE);
4658 if (status)
4659 return status;
4660
Benny Halevyc0eae662009-08-14 17:20:14 +03004661 p = xdr_inline_decode(xdr, 16);
4662 if (unlikely(!p))
4663 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004664 res->count = be32_to_cpup(p++);
4665 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004666 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004667 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004668out_overflow:
4669 print_overflow_msg(__func__, xdr);
4670 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671}
4672
4673static int decode_delegreturn(struct xdr_stream *xdr)
4674{
4675 return decode_op_hdr(xdr, OP_DELEGRETURN);
4676}
4677
Benny Halevy99fe60d2009-04-01 09:22:29 -04004678#if defined(CONFIG_NFS_V4_1)
4679static int decode_exchange_id(struct xdr_stream *xdr,
4680 struct nfs41_exchange_id_res *res)
4681{
4682 __be32 *p;
4683 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004684 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004685 int status;
4686 struct nfs_client *clp = res->client;
4687
4688 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4689 if (status)
4690 return status;
4691
Benny Halevyc0eae662009-08-14 17:20:14 +03004692 p = xdr_inline_decode(xdr, 8);
4693 if (unlikely(!p))
4694 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004695 xdr_decode_hyper(p, &clp->cl_ex_clid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004696 p = xdr_inline_decode(xdr, 12);
4697 if (unlikely(!p))
4698 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004699 clp->cl_seqid = be32_to_cpup(p++);
4700 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004701
4702 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004703 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004704 if (dummy != SP4_NONE)
4705 return -EIO;
4706
4707 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004708 p = xdr_inline_decode(xdr, 8);
4709 if (unlikely(!p))
4710 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004711
4712 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004713 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4714 if (unlikely(status))
4715 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004716
4717 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004718 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4719 if (unlikely(status))
4720 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004721
4722 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004723 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4724 if (unlikely(status))
4725 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004726
4727 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004728out_overflow:
4729 print_overflow_msg(__func__, xdr);
4730 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004731}
Andy Adamsonfc931582009-04-01 09:22:31 -04004732
4733static int decode_chan_attrs(struct xdr_stream *xdr,
4734 struct nfs4_channel_attrs *attrs)
4735{
4736 __be32 *p;
4737 u32 nr_attrs;
4738
Benny Halevyc0eae662009-08-14 17:20:14 +03004739 p = xdr_inline_decode(xdr, 28);
4740 if (unlikely(!p))
4741 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004742 attrs->headerpadsz = be32_to_cpup(p++);
4743 attrs->max_rqst_sz = be32_to_cpup(p++);
4744 attrs->max_resp_sz = be32_to_cpup(p++);
4745 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4746 attrs->max_ops = be32_to_cpup(p++);
4747 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004748 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004749 if (unlikely(nr_attrs > 1)) {
4750 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4751 __func__, nr_attrs);
4752 return -EINVAL;
4753 }
Benny Halevyc0eae662009-08-14 17:20:14 +03004754 if (nr_attrs == 1) {
4755 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
4756 if (unlikely(!p))
4757 goto out_overflow;
4758 }
Andy Adamsonfc931582009-04-01 09:22:31 -04004759 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004760out_overflow:
4761 print_overflow_msg(__func__, xdr);
4762 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004763}
4764
Benny Halevye78291e2009-08-14 17:20:00 +03004765static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
4766{
4767 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04004768}
4769
4770static int decode_create_session(struct xdr_stream *xdr,
4771 struct nfs41_create_session_res *res)
4772{
4773 __be32 *p;
4774 int status;
4775 struct nfs_client *clp = res->client;
4776 struct nfs4_session *session = clp->cl_session;
4777
4778 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03004779 if (!status)
4780 status = decode_sessionid(xdr, &session->sess_id);
4781 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04004782 return status;
4783
Andy Adamsonfc931582009-04-01 09:22:31 -04004784 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03004785 p = xdr_inline_decode(xdr, 8);
4786 if (unlikely(!p))
4787 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004788 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004789 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004790
4791 /* Channel attributes */
4792 status = decode_chan_attrs(xdr, &session->fc_attrs);
4793 if (!status)
4794 status = decode_chan_attrs(xdr, &session->bc_attrs);
4795 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004796out_overflow:
4797 print_overflow_msg(__func__, xdr);
4798 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04004799}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04004800
4801static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
4802{
4803 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
4804}
Ricardo Labiaga18019752009-12-05 16:08:40 -05004805
4806static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
4807{
4808 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
4809}
Benny Halevy99fe60d2009-04-01 09:22:29 -04004810#endif /* CONFIG_NFS_V4_1 */
4811
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004812static int decode_sequence(struct xdr_stream *xdr,
4813 struct nfs4_sequence_res *res,
4814 struct rpc_rqst *rqstp)
4815{
4816#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004817 struct nfs4_sessionid id;
4818 u32 dummy;
4819 int status;
4820 __be32 *p;
4821
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004822 if (!res->sr_session)
4823 return 0;
4824
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004825 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03004826 if (!status)
4827 status = decode_sessionid(xdr, &id);
4828 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004829 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004830
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004831 /*
4832 * If the server returns different values for sessionID, slotID or
4833 * sequence number, the server is looney tunes.
4834 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05004835 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004836
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004837 if (memcmp(id.data, res->sr_session->sess_id.data,
4838 NFS4_MAX_SESSIONID_LEN)) {
4839 dprintk("%s Invalid session id\n", __func__);
4840 goto out_err;
4841 }
Benny Halevye78291e2009-08-14 17:20:00 +03004842
Benny Halevyc0eae662009-08-14 17:20:14 +03004843 p = xdr_inline_decode(xdr, 20);
4844 if (unlikely(!p))
4845 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03004846
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004847 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03004848 dummy = be32_to_cpup(p++);
Benny Halevydfb4f302010-09-24 09:17:01 -04004849 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004850 dprintk("%s Invalid sequence number\n", __func__);
4851 goto out_err;
4852 }
4853 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03004854 dummy = be32_to_cpup(p++);
Benny Halevydfb4f302010-09-24 09:17:01 -04004855 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004856 dprintk("%s Invalid slot id\n", __func__);
4857 goto out_err;
4858 }
4859 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004860 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004861 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03004862 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05004863 /* result flags */
4864 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004865 status = 0;
4866out_err:
4867 res->sr_status = status;
4868 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004869out_overflow:
4870 print_overflow_msg(__func__, xdr);
4871 status = -EIO;
4872 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004873#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004874 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04004875#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04004876}
4877
Andy Adamsonb1f69b72010-10-20 00:18:03 -04004878#if defined(CONFIG_NFS_V4_1)
4879
4880static int decode_getdeviceinfo(struct xdr_stream *xdr,
4881 struct pnfs_device *pdev)
4882{
4883 __be32 *p;
4884 uint32_t len, type;
4885 int status;
4886
4887 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
4888 if (status) {
4889 if (status == -ETOOSMALL) {
4890 p = xdr_inline_decode(xdr, 4);
4891 if (unlikely(!p))
4892 goto out_overflow;
4893 pdev->mincount = be32_to_cpup(p);
4894 dprintk("%s: Min count too small. mincnt = %u\n",
4895 __func__, pdev->mincount);
4896 }
4897 return status;
4898 }
4899
4900 p = xdr_inline_decode(xdr, 8);
4901 if (unlikely(!p))
4902 goto out_overflow;
4903 type = be32_to_cpup(p++);
4904 if (type != pdev->layout_type) {
4905 dprintk("%s: layout mismatch req: %u pdev: %u\n",
4906 __func__, pdev->layout_type, type);
4907 return -EINVAL;
4908 }
4909 /*
4910 * Get the length of the opaque device_addr4. xdr_read_pages places
4911 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
4912 * and places the remaining xdr data in xdr_buf->tail
4913 */
4914 pdev->mincount = be32_to_cpup(p);
4915 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
4916
4917 /* Parse notification bitmap, verifying that it is zero. */
4918 p = xdr_inline_decode(xdr, 4);
4919 if (unlikely(!p))
4920 goto out_overflow;
4921 len = be32_to_cpup(p);
4922 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00004923 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04004924
4925 p = xdr_inline_decode(xdr, 4 * len);
4926 if (unlikely(!p))
4927 goto out_overflow;
4928 for (i = 0; i < len; i++, p++) {
4929 if (be32_to_cpup(p)) {
4930 dprintk("%s: notifications not supported\n",
4931 __func__);
4932 return -EIO;
4933 }
4934 }
4935 }
4936 return 0;
4937out_overflow:
4938 print_overflow_msg(__func__, xdr);
4939 return -EIO;
4940}
4941
4942static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
4943 struct nfs4_layoutget_res *res)
4944{
4945 __be32 *p;
4946 int status;
4947 u32 layout_count;
4948
4949 status = decode_op_hdr(xdr, OP_LAYOUTGET);
4950 if (status)
4951 return status;
4952 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
4953 if (unlikely(!p))
4954 goto out_overflow;
4955 res->return_on_close = be32_to_cpup(p++);
4956 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
4957 layout_count = be32_to_cpup(p);
4958 if (!layout_count) {
4959 dprintk("%s: server responded with empty layout array\n",
4960 __func__);
4961 return -EINVAL;
4962 }
4963
4964 p = xdr_inline_decode(xdr, 24);
4965 if (unlikely(!p))
4966 goto out_overflow;
4967 p = xdr_decode_hyper(p, &res->range.offset);
4968 p = xdr_decode_hyper(p, &res->range.length);
4969 res->range.iomode = be32_to_cpup(p++);
4970 res->type = be32_to_cpup(p++);
4971
4972 status = decode_opaque_inline(xdr, &res->layout.len, (char **)&p);
4973 if (unlikely(status))
4974 return status;
4975
4976 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
4977 __func__,
4978 (unsigned long)res->range.offset,
4979 (unsigned long)res->range.length,
4980 res->range.iomode,
4981 res->type,
4982 res->layout.len);
4983
4984 /* nfs4_proc_layoutget allocated a single page */
4985 if (res->layout.len > PAGE_SIZE)
4986 return -ENOMEM;
4987 memcpy(res->layout.buf, p, res->layout.len);
4988
4989 if (layout_count > 1) {
4990 /* We only handle a length one array at the moment. Any
4991 * further entries are just ignored. Note that this means
4992 * the client may see a response that is less than the
4993 * minimum it requested.
4994 */
4995 dprintk("%s: server responded with %d layouts, dropping tail\n",
4996 __func__, layout_count);
4997 }
4998
4999 return 0;
5000out_overflow:
5001 print_overflow_msg(__func__, xdr);
5002 return -EIO;
5003}
5004#endif /* CONFIG_NFS_V4_1 */
5005
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006/*
Benny Halevy49c25592008-12-23 16:06:16 -05005007 * END OF "GENERIC" DECODE ROUTINES.
5008 */
5009
5010/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011 * Decode OPEN_DOWNGRADE response
5012 */
Chuck Leverbf269552010-12-14 14:59:29 +00005013static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5014 struct xdr_stream *xdr,
5015 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016{
Andy Adamson05d564f2008-12-23 16:06:15 -05005017 struct compound_hdr hdr;
5018 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019
Chuck Leverbf269552010-12-14 14:59:29 +00005020 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005021 if (status)
5022 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005023 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005024 if (status)
5025 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005026 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005027 if (status)
5028 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005029 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005030 if (status != 0)
5031 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005032 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005033 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005035 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036}
5037
5038/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005039 * Decode ACCESS response
5040 */
Chuck Leverbf269552010-12-14 14:59:29 +00005041static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5042 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044 struct compound_hdr hdr;
5045 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005046
Chuck Leverbf269552010-12-14 14:59:29 +00005047 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005048 if (status)
5049 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005050 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005051 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005053 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005054 if (status != 0)
5055 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005056 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005057 if (status != 0)
5058 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005059 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005060 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061out:
5062 return status;
5063}
5064
5065/*
5066 * Decode LOOKUP response
5067 */
Chuck Leverbf269552010-12-14 14:59:29 +00005068static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5069 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005070{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 struct compound_hdr hdr;
5072 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005073
Chuck Leverbf269552010-12-14 14:59:29 +00005074 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005075 if (status)
5076 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005077 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005078 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005080 status = decode_putfh(xdr);
5081 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005083 status = decode_lookup(xdr);
5084 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005086 status = decode_getfh(xdr, res->fh);
5087 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005089 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005090 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091out:
5092 return status;
5093}
5094
5095/*
5096 * Decode LOOKUP_ROOT response
5097 */
Chuck Leverbf269552010-12-14 14:59:29 +00005098static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5099 struct xdr_stream *xdr,
5100 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102 struct compound_hdr hdr;
5103 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005104
Chuck Leverbf269552010-12-14 14:59:29 +00005105 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005106 if (status)
5107 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005108 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005109 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005110 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005111 status = decode_putrootfh(xdr);
5112 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005114 status = decode_getfh(xdr, res->fh);
5115 if (status == 0)
5116 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005117 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118out:
5119 return status;
5120}
5121
5122/*
5123 * Decode REMOVE response
5124 */
Chuck Leverbf269552010-12-14 14:59:29 +00005125static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5126 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128 struct compound_hdr hdr;
5129 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005130
Chuck Leverbf269552010-12-14 14:59:29 +00005131 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005132 if (status)
5133 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005134 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005135 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005137 status = decode_putfh(xdr);
5138 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005139 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005140 status = decode_remove(xdr, &res->cinfo);
5141 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005142 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005143 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005144 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145out:
5146 return status;
5147}
5148
5149/*
5150 * Decode RENAME response
5151 */
Chuck Leverbf269552010-12-14 14:59:29 +00005152static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5153 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005154{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 struct compound_hdr hdr;
5156 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005157
Chuck Leverbf269552010-12-14 14:59:29 +00005158 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005159 if (status)
5160 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005161 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005162 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005164 status = decode_putfh(xdr);
5165 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005167 status = decode_savefh(xdr);
5168 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005170 status = decode_putfh(xdr);
5171 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005173 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5174 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005175 goto out;
5176 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005177 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005178 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005179 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005180 status = decode_restorefh(xdr);
5181 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005182 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005183 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005184 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185out:
5186 return status;
5187}
5188
5189/*
5190 * Decode LINK response
5191 */
Chuck Leverbf269552010-12-14 14:59:29 +00005192static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5193 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195 struct compound_hdr hdr;
5196 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005197
Chuck Leverbf269552010-12-14 14:59:29 +00005198 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005199 if (status)
5200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005201 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005202 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005203 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005204 status = decode_putfh(xdr);
5205 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005207 status = decode_savefh(xdr);
5208 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005210 status = decode_putfh(xdr);
5211 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005212 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005213 status = decode_link(xdr, &res->cinfo);
5214 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005215 goto out;
5216 /*
5217 * Note order: OP_LINK leaves the directory as the current
5218 * filehandle.
5219 */
Chuck Leverbf269552010-12-14 14:59:29 +00005220 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005221 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005222 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005223 status = decode_restorefh(xdr);
5224 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005225 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005226 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005227 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228out:
5229 return status;
5230}
5231
5232/*
5233 * Decode CREATE response
5234 */
Chuck Leverbf269552010-12-14 14:59:29 +00005235static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5236 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005237{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238 struct compound_hdr hdr;
5239 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005240
Chuck Leverbf269552010-12-14 14:59:29 +00005241 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005242 if (status)
5243 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005244 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005245 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005247 status = decode_putfh(xdr);
5248 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005250 status = decode_savefh(xdr);
5251 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005252 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005253 status = decode_create(xdr, &res->dir_cinfo);
5254 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005256 status = decode_getfh(xdr, res->fh);
5257 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005259 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005260 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005261 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005262 status = decode_restorefh(xdr);
5263 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005264 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005265 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005266 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267out:
5268 return status;
5269}
5270
5271/*
5272 * Decode SYMLINK response
5273 */
Chuck Leverbf269552010-12-14 14:59:29 +00005274static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5275 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276{
Chuck Leverbf269552010-12-14 14:59:29 +00005277 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005278}
5279
5280/*
5281 * Decode GETATTR response
5282 */
Chuck Leverbf269552010-12-14 14:59:29 +00005283static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5284 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286 struct compound_hdr hdr;
5287 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005288
Chuck Leverbf269552010-12-14 14:59:29 +00005289 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290 if (status)
5291 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005292 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005293 if (status)
5294 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005295 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296 if (status)
5297 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005298 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005299 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300out:
5301 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302}
5303
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005304/*
5305 * Encode an SETACL request
5306 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005307static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5308 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005309{
Andy Adamson05d564f2008-12-23 16:06:15 -05005310 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005311 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005312 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005313
Chuck Lever9f06c712010-12-14 14:59:18 +00005314 encode_compound_hdr(xdr, req, &hdr);
5315 encode_sequence(xdr, &args->seq_args, &hdr);
5316 encode_putfh(xdr, args->fh, &hdr);
5317 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005318 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005319}
Andy Adamson05d564f2008-12-23 16:06:15 -05005320
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005321/*
5322 * Decode SETACL response
5323 */
5324static int
Chuck Leverbf269552010-12-14 14:59:29 +00005325nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005326 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005327{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005328 struct compound_hdr hdr;
5329 int status;
5330
Chuck Leverbf269552010-12-14 14:59:29 +00005331 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005332 if (status)
5333 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005334 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005335 if (status)
5336 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005337 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005338 if (status)
5339 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005340 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005341out:
5342 return status;
5343}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344
5345/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005346 * Decode GETACL response
5347 */
5348static int
Chuck Leverbf269552010-12-14 14:59:29 +00005349nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005350 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005351{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005352 struct compound_hdr hdr;
5353 int status;
5354
Chuck Leverbf269552010-12-14 14:59:29 +00005355 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005356 if (status)
5357 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005358 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005359 if (status)
5360 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005361 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005362 if (status)
5363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005364 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005365
5366out:
5367 return status;
5368}
5369
5370/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005371 * Decode CLOSE response
5372 */
Chuck Leverbf269552010-12-14 14:59:29 +00005373static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5374 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005375{
Andy Adamson05d564f2008-12-23 16:06:15 -05005376 struct compound_hdr hdr;
5377 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378
Chuck Leverbf269552010-12-14 14:59:29 +00005379 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005380 if (status)
5381 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005382 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005383 if (status)
5384 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005385 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005386 if (status)
5387 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005388 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005389 if (status != 0)
5390 goto out;
5391 /*
5392 * Note: Server may do delete on close for this file
5393 * in which case the getattr call will fail with
5394 * an ESTALE error. Shouldn't be a problem,
5395 * though, since fattr->valid will remain unset.
5396 */
Chuck Leverbf269552010-12-14 14:59:29 +00005397 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005398 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005399out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005400 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005401}
5402
5403/*
5404 * Decode OPEN response
5405 */
Chuck Leverbf269552010-12-14 14:59:29 +00005406static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5407 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408{
Andy Adamson05d564f2008-12-23 16:06:15 -05005409 struct compound_hdr hdr;
5410 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005411
Chuck Leverbf269552010-12-14 14:59:29 +00005412 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005413 if (status)
5414 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005415 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005416 if (status)
5417 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005418 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005419 if (status)
5420 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005421 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005422 if (status)
5423 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005424 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005425 if (status)
5426 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005427 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005428 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005429 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005430 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005431 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005432 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005433 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005434 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005435 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005436out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005437 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438}
5439
5440/*
5441 * Decode OPEN_CONFIRM response
5442 */
Chuck Leverbf269552010-12-14 14:59:29 +00005443static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5444 struct xdr_stream *xdr,
5445 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005446{
Andy Adamson05d564f2008-12-23 16:06:15 -05005447 struct compound_hdr hdr;
5448 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005449
Chuck Leverbf269552010-12-14 14:59:29 +00005450 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005451 if (status)
5452 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005453 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005454 if (status)
5455 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005456 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005457out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005458 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459}
5460
5461/*
5462 * Decode OPEN response
5463 */
Chuck Leverbf269552010-12-14 14:59:29 +00005464static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5465 struct xdr_stream *xdr,
5466 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005467{
Andy Adamson05d564f2008-12-23 16:06:15 -05005468 struct compound_hdr hdr;
5469 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005470
Chuck Leverbf269552010-12-14 14:59:29 +00005471 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005472 if (status)
5473 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005474 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005475 if (status)
5476 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005477 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005478 if (status)
5479 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005480 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005481 if (status)
5482 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005483 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005484 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005485out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005486 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487}
5488
5489/*
5490 * Decode SETATTR response
5491 */
Chuck Leverbf269552010-12-14 14:59:29 +00005492static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5493 struct xdr_stream *xdr,
5494 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005495{
Andy Adamson05d564f2008-12-23 16:06:15 -05005496 struct compound_hdr hdr;
5497 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005498
Chuck Leverbf269552010-12-14 14:59:29 +00005499 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005500 if (status)
5501 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005502 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005503 if (status)
5504 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005505 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005506 if (status)
5507 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005508 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005509 if (status)
5510 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005511 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005512 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005513out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005514 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005515}
5516
5517/*
5518 * Decode LOCK response
5519 */
Chuck Leverbf269552010-12-14 14:59:29 +00005520static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5521 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005523 struct compound_hdr hdr;
5524 int status;
5525
Chuck Leverbf269552010-12-14 14:59:29 +00005526 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005527 if (status)
5528 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005529 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005530 if (status)
5531 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005532 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005533 if (status)
5534 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005535 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005536out:
5537 return status;
5538}
5539
5540/*
5541 * Decode LOCKT response
5542 */
Chuck Leverbf269552010-12-14 14:59:29 +00005543static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5544 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005545{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546 struct compound_hdr hdr;
5547 int status;
5548
Chuck Leverbf269552010-12-14 14:59:29 +00005549 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005550 if (status)
5551 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005552 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005553 if (status)
5554 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005555 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005556 if (status)
5557 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005558 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559out:
5560 return status;
5561}
5562
5563/*
5564 * Decode LOCKU response
5565 */
Chuck Leverbf269552010-12-14 14:59:29 +00005566static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5567 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005568{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005569 struct compound_hdr hdr;
5570 int status;
5571
Chuck Leverbf269552010-12-14 14:59:29 +00005572 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005573 if (status)
5574 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005575 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005576 if (status)
5577 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005578 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005579 if (status)
5580 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005581 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005582out:
5583 return status;
5584}
5585
Chuck Leverbf269552010-12-14 14:59:29 +00005586static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5587 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005588{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005589 struct compound_hdr hdr;
5590 int status;
5591
Chuck Leverbf269552010-12-14 14:59:29 +00005592 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005593 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005594 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005595 return status;
5596}
5597
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598/*
5599 * Decode READLINK response
5600 */
Chuck Leverbf269552010-12-14 14:59:29 +00005601static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5602 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04005603 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005604{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605 struct compound_hdr hdr;
5606 int status;
5607
Chuck Leverbf269552010-12-14 14:59:29 +00005608 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005609 if (status)
5610 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005611 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005612 if (status)
5613 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005614 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005615 if (status)
5616 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005617 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005618out:
5619 return status;
5620}
5621
5622/*
5623 * Decode READDIR response
5624 */
Chuck Leverbf269552010-12-14 14:59:29 +00005625static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5626 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005627{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005628 struct compound_hdr hdr;
5629 int status;
5630
Chuck Leverbf269552010-12-14 14:59:29 +00005631 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005632 if (status)
5633 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005634 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005635 if (status)
5636 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005637 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005638 if (status)
5639 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005640 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005641out:
5642 return status;
5643}
5644
5645/*
5646 * Decode Read response
5647 */
Chuck Leverbf269552010-12-14 14:59:29 +00005648static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5649 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005650{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005651 struct compound_hdr hdr;
5652 int status;
5653
Chuck Leverbf269552010-12-14 14:59:29 +00005654 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005655 if (status)
5656 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005657 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005658 if (status)
5659 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005660 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005661 if (status)
5662 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005663 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005664 if (!status)
5665 status = res->count;
5666out:
5667 return status;
5668}
5669
5670/*
5671 * Decode WRITE response
5672 */
Chuck Leverbf269552010-12-14 14:59:29 +00005673static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5674 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005675{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005676 struct compound_hdr hdr;
5677 int status;
5678
Chuck Leverbf269552010-12-14 14:59:29 +00005679 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005680 if (status)
5681 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005682 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005683 if (status)
5684 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005685 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686 if (status)
5687 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005688 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005689 if (status)
5690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005691 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005692 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005693 if (!status)
5694 status = res->count;
5695out:
5696 return status;
5697}
5698
5699/*
5700 * Decode COMMIT response
5701 */
Chuck Leverbf269552010-12-14 14:59:29 +00005702static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5703 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005704{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005705 struct compound_hdr hdr;
5706 int status;
5707
Chuck Leverbf269552010-12-14 14:59:29 +00005708 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005709 if (status)
5710 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005711 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005712 if (status)
5713 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005714 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005715 if (status)
5716 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005717 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005718 if (status)
5719 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005720 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005721 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005722out:
5723 return status;
5724}
5725
5726/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005727 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005728 */
Chuck Leverbf269552010-12-14 14:59:29 +00005729static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04005730 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005731{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005732 struct compound_hdr hdr;
5733 int status;
5734
Chuck Leverbf269552010-12-14 14:59:29 +00005735 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005736 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005737 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005738 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005739 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005741 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005742 return status;
5743}
5744
5745/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005746 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005747 */
Chuck Leverbf269552010-12-14 14:59:29 +00005748static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04005749 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005751 struct compound_hdr hdr;
5752 int status;
5753
Chuck Leverbf269552010-12-14 14:59:29 +00005754 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005756 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005757 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005758 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005760 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005761 return status;
5762}
5763
5764/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005765 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005766 */
Chuck Leverbf269552010-12-14 14:59:29 +00005767static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04005768 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005769{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005770 struct compound_hdr hdr;
5771 int status;
5772
Chuck Leverbf269552010-12-14 14:59:29 +00005773 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005774 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005775 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005776 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005777 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005778 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005779 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780 return status;
5781}
5782
5783/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005784 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005785 */
Chuck Leverbf269552010-12-14 14:59:29 +00005786static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
5787 struct xdr_stream *xdr,
5788 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005789{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005790 struct compound_hdr hdr;
5791 int status;
5792
Chuck Leverbf269552010-12-14 14:59:29 +00005793 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005794 if (status)
5795 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005796 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005797 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005798 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005799 status = decode_putfh(xdr);
5800 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005801 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005802 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005803out:
5804 return status;
5805}
5806
5807/*
5808 * Decode RENEW response
5809 */
Chuck Leverbf269552010-12-14 14:59:29 +00005810static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5811 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005812{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005813 struct compound_hdr hdr;
5814 int status;
5815
Chuck Leverbf269552010-12-14 14:59:29 +00005816 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005817 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005818 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005819 return status;
5820}
5821
5822/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005823 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824 */
Chuck Leverbf269552010-12-14 14:59:29 +00005825static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
5826 struct xdr_stream *xdr,
5827 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005828{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829 struct compound_hdr hdr;
5830 int status;
5831
Chuck Leverbf269552010-12-14 14:59:29 +00005832 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005833 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005834 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835 return status;
5836}
5837
5838/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005839 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005840 */
Chuck Leverbf269552010-12-14 14:59:29 +00005841static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
5842 struct xdr_stream *xdr,
5843 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005844{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845 struct compound_hdr hdr;
5846 int status;
5847
Chuck Leverbf269552010-12-14 14:59:29 +00005848 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005849 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005850 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005851 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005852 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005854 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855 return status;
5856}
5857
5858/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005859 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07005860 */
Chuck Leverbf269552010-12-14 14:59:29 +00005861static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
5862 struct xdr_stream *xdr,
5863 struct nfs4_delegreturnres *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);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005869 if (status)
5870 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005871 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005872 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01005873 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005874 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01005875 if (status != 0)
5876 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005877 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04005878 if (status != 0)
5879 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005880 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005881 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01005882out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005883 return status;
5884}
5885
Trond Myklebust683b57b2006-06-09 09:34:22 -04005886/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005887 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04005888 */
Chuck Leverbf269552010-12-14 14:59:29 +00005889static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
5890 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04005891 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005892{
Trond Myklebust683b57b2006-06-09 09:34:22 -04005893 struct compound_hdr hdr;
5894 int status;
5895
Chuck Leverbf269552010-12-14 14:59:29 +00005896 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005897 if (status)
5898 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005899 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005900 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005901 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005902 status = decode_putfh(xdr);
5903 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005904 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005905 status = decode_lookup(xdr);
5906 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04005907 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005908 xdr_enter_page(xdr, PAGE_SIZE);
5909 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005910 res->fs_locations->server,
5911 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04005912out:
5913 return status;
5914}
5915
Benny Halevy99fe60d2009-04-01 09:22:29 -04005916#if defined(CONFIG_NFS_V4_1)
5917/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005918 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04005919 */
Chuck Leverbf269552010-12-14 14:59:29 +00005920static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
5921 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04005922 void *res)
5923{
Benny Halevy99fe60d2009-04-01 09:22:29 -04005924 struct compound_hdr hdr;
5925 int status;
5926
Chuck Leverbf269552010-12-14 14:59:29 +00005927 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005928 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005929 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005930 return status;
5931}
Andy Adamson2050f0c2009-04-01 09:22:30 -04005932
5933/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005934 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04005935 */
Chuck Leverbf269552010-12-14 14:59:29 +00005936static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
5937 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04005938 struct nfs41_create_session_res *res)
5939{
Andy Adamsonfc931582009-04-01 09:22:31 -04005940 struct compound_hdr hdr;
5941 int status;
5942
Chuck Leverbf269552010-12-14 14:59:29 +00005943 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04005944 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005945 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04005946 return status;
5947}
5948
5949/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005950 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005951 */
Chuck Leverbf269552010-12-14 14:59:29 +00005952static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
5953 struct xdr_stream *xdr,
5954 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005955{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005956 struct compound_hdr hdr;
5957 int status;
5958
Chuck Leverbf269552010-12-14 14:59:29 +00005959 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005960 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005961 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005962 return status;
5963}
5964
5965/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005966 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005967 */
Chuck Leverbf269552010-12-14 14:59:29 +00005968static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
5969 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005970 struct nfs4_sequence_res *res)
5971{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005972 struct compound_hdr hdr;
5973 int status;
5974
Chuck Leverbf269552010-12-14 14:59:29 +00005975 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005976 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005977 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005978 return status;
5979}
5980
5981/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05005982 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04005983 */
Chuck Leverbf269552010-12-14 14:59:29 +00005984static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
5985 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04005986 struct nfs4_get_lease_time_res *res)
5987{
Andy Adamson2050f0c2009-04-01 09:22:30 -04005988 struct compound_hdr hdr;
5989 int status;
5990
Chuck Leverbf269552010-12-14 14:59:29 +00005991 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04005992 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005993 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04005994 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005995 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04005996 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005997 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04005998 return status;
5999}
Ricardo Labiaga18019752009-12-05 16:08:40 -05006000
6001/*
6002 * Decode RECLAIM_COMPLETE response
6003 */
Chuck Leverbf269552010-12-14 14:59:29 +00006004static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6005 struct xdr_stream *xdr,
Ricardo Labiaga18019752009-12-05 16:08:40 -05006006 struct nfs41_reclaim_complete_res *res)
6007{
Ricardo Labiaga18019752009-12-05 16:08:40 -05006008 struct compound_hdr hdr;
6009 int status;
6010
Chuck Leverbf269552010-12-14 14:59:29 +00006011 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006012 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006013 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006014 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006015 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006016 return status;
6017}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006018
6019/*
6020 * Decode GETDEVINFO response
6021 */
Chuck Leverbf269552010-12-14 14:59:29 +00006022static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6023 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006024 struct nfs4_getdeviceinfo_res *res)
6025{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006026 struct compound_hdr hdr;
6027 int status;
6028
Chuck Leverbf269552010-12-14 14:59:29 +00006029 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006030 if (status != 0)
6031 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006032 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006033 if (status != 0)
6034 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006035 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006036out:
6037 return status;
6038}
6039
6040/*
6041 * Decode LAYOUTGET response
6042 */
Chuck Leverbf269552010-12-14 14:59:29 +00006043static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6044 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006045 struct nfs4_layoutget_res *res)
6046{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006047 struct compound_hdr hdr;
6048 int status;
6049
Chuck Leverbf269552010-12-14 14:59:29 +00006050 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006051 if (status)
6052 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006053 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006054 if (status)
6055 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006056 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006057 if (status)
6058 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006059 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006060out:
6061 return status;
6062}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006063#endif /* CONFIG_NFS_V4_1 */
6064
Chuck Lever573c4e12010-12-14 14:58:11 +00006065/**
6066 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6067 * the local page cache.
6068 * @xdr: XDR stream where entry resides
6069 * @entry: buffer to fill in with entry data
6070 * @plus: boolean indicating whether this should be a readdirplus entry
6071 *
6072 * Returns zero if successful, otherwise a negative errno value is
6073 * returned.
6074 *
6075 * This function is not invoked during READDIR reply decoding, but
6076 * rather whenever an application invokes the getdents(2) system call
6077 * on a directory already in our cache.
6078 */
6079int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6080 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081{
6082 uint32_t bitmap[2] = {0};
6083 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006084 __be32 *p = xdr_inline_decode(xdr, 4);
6085 if (unlikely(!p))
6086 goto out_overflow;
6087 if (!ntohl(*p++)) {
6088 p = xdr_inline_decode(xdr, 4);
6089 if (unlikely(!p))
6090 goto out_overflow;
6091 if (!ntohl(*p++))
Chuck Lever573c4e12010-12-14 14:58:11 +00006092 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006093 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006094 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095 }
6096
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006097 p = xdr_inline_decode(xdr, 12);
6098 if (unlikely(!p))
6099 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100 entry->prev_cookie = entry->cookie;
6101 p = xdr_decode_hyper(p, &entry->cookie);
6102 entry->len = ntohl(*p++);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006103
Trond Myklebust9af8c222010-10-24 11:52:55 -04006104 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006105 if (unlikely(!p))
6106 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108
6109 /*
6110 * In case the server doesn't return an inode number,
6111 * we fake one here. (We don't use inode number 0,
6112 * since glibc seems to choke on it...)
6113 */
6114 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006115 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006116
Trond Myklebust9af8c222010-10-24 11:52:55 -04006117 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006118 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006119
6120 if (decode_attr_length(xdr, &len, &p) < 0)
6121 goto out_overflow;
6122
Chuck Lever573c4e12010-12-14 14:58:11 +00006123 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6124 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006125 goto out_overflow;
6126 if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
6127 entry->ino = entry->fattr->fileid;
6128
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006129 entry->d_type = DT_UNKNOWN;
6130 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6131 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6132
Trond Myklebust9af8c222010-10-24 11:52:55 -04006133 if (verify_attr_len(xdr, p, len) < 0)
6134 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006136 p = xdr_inline_peek(xdr, 8);
6137 if (p != NULL)
6138 entry->eof = !p[0] && p[1];
6139 else
6140 entry->eof = 0;
6141
Chuck Lever573c4e12010-12-14 14:58:11 +00006142 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006143
6144out_overflow:
6145 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006146 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006147}
6148
6149/*
6150 * We need to translate between nfs status return values and
6151 * the local errno values which may not be the same.
6152 */
6153static struct {
6154 int stat;
6155 int errno;
6156} nfs_errtbl[] = {
6157 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006158 { NFS4ERR_PERM, -EPERM },
6159 { NFS4ERR_NOENT, -ENOENT },
6160 { NFS4ERR_IO, -errno_NFSERR_IO},
6161 { NFS4ERR_NXIO, -ENXIO },
6162 { NFS4ERR_ACCESS, -EACCES },
6163 { NFS4ERR_EXIST, -EEXIST },
6164 { NFS4ERR_XDEV, -EXDEV },
6165 { NFS4ERR_NOTDIR, -ENOTDIR },
6166 { NFS4ERR_ISDIR, -EISDIR },
6167 { NFS4ERR_INVAL, -EINVAL },
6168 { NFS4ERR_FBIG, -EFBIG },
6169 { NFS4ERR_NOSPC, -ENOSPC },
6170 { NFS4ERR_ROFS, -EROFS },
6171 { NFS4ERR_MLINK, -EMLINK },
6172 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6173 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6174 { NFS4ERR_DQUOT, -EDQUOT },
6175 { NFS4ERR_STALE, -ESTALE },
6176 { NFS4ERR_BADHANDLE, -EBADHANDLE },
6177 { NFS4ERR_BADOWNER, -EINVAL },
6178 { NFS4ERR_BADNAME, -EINVAL },
6179 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6180 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6181 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006182 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006183 { NFS4ERR_BADTYPE, -EBADTYPE },
6184 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006185 { NFS4ERR_SYMLINK, -ELOOP },
6186 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6187 { NFS4ERR_DEADLOCK, -EDEADLK },
6188 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189 * to be handled by a
6190 * middle-layer.
6191 */
Benny Halevy856dff32008-03-31 17:39:06 +03006192 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193};
6194
6195/*
6196 * Convert an NFS error code to a local one.
6197 * This one is used jointly by NFSv2 and NFSv3.
6198 */
6199static int
David Howells0a8ea432006-08-22 20:06:08 -04006200nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201{
6202 int i;
6203 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6204 if (nfs_errtbl[i].stat == stat)
6205 return nfs_errtbl[i].errno;
6206 }
6207 if (stat <= 10000 || stat > 10100) {
6208 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006209 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210 }
6211 /* If we cannot translate the error, the recovery routines should
6212 * handle it.
6213 * Note: remaining NFSv4 error codes have values > 10000, so should
6214 * not conflict with native Linux error codes.
6215 */
Benny Halevy856dff32008-03-31 17:39:06 +03006216 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217}
6218
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219#define PROC(proc, argtype, restype) \
6220[NFSPROC4_CLNT_##proc] = { \
6221 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006222 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006223 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006224 .p_arglen = NFS4_##argtype##_sz, \
6225 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006226 .p_statidx = NFSPROC4_CLNT_##proc, \
6227 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006228}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229
6230struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006231 PROC(READ, enc_read, dec_read),
6232 PROC(WRITE, enc_write, dec_write),
6233 PROC(COMMIT, enc_commit, dec_commit),
6234 PROC(OPEN, enc_open, dec_open),
6235 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6236 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6237 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6238 PROC(CLOSE, enc_close, dec_close),
6239 PROC(SETATTR, enc_setattr, dec_setattr),
6240 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6241 PROC(RENEW, enc_renew, dec_renew),
6242 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6243 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6244 PROC(LOCK, enc_lock, dec_lock),
6245 PROC(LOCKT, enc_lockt, dec_lockt),
6246 PROC(LOCKU, enc_locku, dec_locku),
6247 PROC(ACCESS, enc_access, dec_access),
6248 PROC(GETATTR, enc_getattr, dec_getattr),
6249 PROC(LOOKUP, enc_lookup, dec_lookup),
6250 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6251 PROC(REMOVE, enc_remove, dec_remove),
6252 PROC(RENAME, enc_rename, dec_rename),
6253 PROC(LINK, enc_link, dec_link),
6254 PROC(SYMLINK, enc_symlink, dec_symlink),
6255 PROC(CREATE, enc_create, dec_create),
6256 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6257 PROC(STATFS, enc_statfs, dec_statfs),
6258 PROC(READLINK, enc_readlink, dec_readlink),
6259 PROC(READDIR, enc_readdir, dec_readdir),
6260 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6261 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6262 PROC(GETACL, enc_getacl, dec_getacl),
6263 PROC(SETACL, enc_setacl, dec_setacl),
6264 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6265 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006266#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006267 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6268 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6269 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6270 PROC(SEQUENCE, enc_sequence, dec_sequence),
6271 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6272 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6273 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6274 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006275#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276};
6277
6278struct rpc_version nfs_version4 = {
6279 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006280 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281 .procs = nfs4_procedures
6282};
6283
6284/*
6285 * Local variables:
6286 * c-basic-offset: 8
6287 * End:
6288 */