blob: 7d914d9e7584d593eac7cea963df027bc8c62daa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
47#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050048#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000049#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/nfs.h>
51#include <linux/nfs4.h>
52#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000054#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050055#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040056#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#define NFSDBG_FACILITY NFSDBG_XDR
59
60/* Mapping from NFS error code to "errno" error code. */
61#define errno_NFSERR_IO EIO
62
David Howells0a8ea432006-08-22 20:06:08 -040063static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
66#ifdef DEBUG
67#define NFS4_MAXTAGLEN 20
68#else
69#define NFS4_MAXTAGLEN 0
70#endif
71
Andy Adamson6c0195a2008-12-23 16:06:15 -050072/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 */
Trond Myklebustd035c362010-12-21 10:45:27 -050075#define open_owner_id_maxsz (1 + 1 + 4)
76#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040077#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
80#define op_encode_hdr_maxsz (1)
81#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
84#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
85#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
87 (NFS4_FHSIZE >> 2))
88#define decode_putfh_maxsz (op_decode_hdr_maxsz)
89#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
90#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
91#define encode_getfh_maxsz (op_encode_hdr_maxsz)
92#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
93 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040094#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000095#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
97#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040098#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
99#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000100/* This is based on getfattr, which uses the most attributes: */
101#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400102 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000103#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
104 nfs4_fattr_value_maxsz)
105#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400106#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
107 1 + 2 + 1 + \
108 nfs4_owner_maxsz + \
109 nfs4_group_maxsz + \
110 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define encode_savefh_maxsz (op_encode_hdr_maxsz)
112#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400113#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
114#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200115#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Bryan Schumaker7ebb9312011-03-24 17:12:30 +0000116#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
118#define decode_renew_maxsz (op_decode_hdr_maxsz)
119#define encode_setclientid_maxsz \
120 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500121 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
122 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
123 1 /* sc_prog */ + \
124 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
125 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
126 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define decode_setclientid_maxsz \
128 (op_decode_hdr_maxsz + \
129 2 + \
130 1024) /* large value for CLID_INUSE */
131#define encode_setclientid_confirm_maxsz \
132 (op_encode_hdr_maxsz + \
133 3 + (NFS4_VERIFIER_SIZE >> 2))
134#define decode_setclientid_confirm_maxsz \
135 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400136#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
137#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400138#define encode_share_access_maxsz \
139 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500140#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400141#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
142#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
143#define encode_open_maxsz (op_encode_hdr_maxsz + \
144 2 + encode_share_access_maxsz + 2 + \
145 open_owner_id_maxsz + \
146 encode_opentype_maxsz + \
147 encode_claim_null_maxsz)
148#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400149#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400150 decode_ace_maxsz)
151#define decode_change_info_maxsz (5)
152#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400153 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400154 decode_change_info_maxsz + 1 + \
155 nfs4_fattr_bitmap_maxsz + \
156 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400157#define encode_open_confirm_maxsz \
158 (op_encode_hdr_maxsz + \
159 encode_stateid_maxsz + 1)
160#define decode_open_confirm_maxsz \
161 (op_decode_hdr_maxsz + \
162 decode_stateid_maxsz)
163#define encode_open_downgrade_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1 + \
166 encode_share_access_maxsz)
167#define decode_open_downgrade_maxsz \
168 (op_decode_hdr_maxsz + \
169 decode_stateid_maxsz)
170#define encode_close_maxsz (op_encode_hdr_maxsz + \
171 1 + encode_stateid_maxsz)
172#define decode_close_maxsz (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
175 encode_stateid_maxsz + \
176 encode_attrs_maxsz)
177#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
178 nfs4_fattr_bitmap_maxsz)
179#define encode_read_maxsz (op_encode_hdr_maxsz + \
180 encode_stateid_maxsz + 3)
181#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
182#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
183 2 + encode_verifier_maxsz + 5)
184#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
185 decode_verifier_maxsz)
186#define encode_readlink_maxsz (op_encode_hdr_maxsz)
187#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
188#define encode_write_maxsz (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 4)
190#define decode_write_maxsz (op_decode_hdr_maxsz + \
191 2 + decode_verifier_maxsz)
192#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
193#define decode_commit_maxsz (op_decode_hdr_maxsz + \
194 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#define encode_remove_maxsz (op_encode_hdr_maxsz + \
196 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400197#define decode_remove_maxsz (op_decode_hdr_maxsz + \
198 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199#define encode_rename_maxsz (op_encode_hdr_maxsz + \
200 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400201#define decode_rename_maxsz (op_decode_hdr_maxsz + \
202 decode_change_info_maxsz + \
203 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#define encode_link_maxsz (op_encode_hdr_maxsz + \
205 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400206#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400207#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400208#define encode_lock_maxsz (op_encode_hdr_maxsz + \
209 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400210 1 + encode_stateid_maxsz + 1 + \
211 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400212#define decode_lock_denied_maxsz \
213 (8 + decode_lockowner_maxsz)
214#define decode_lock_maxsz (op_decode_hdr_maxsz + \
215 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
219 decode_lock_denied_maxsz)
220#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
221 encode_stateid_maxsz + \
222 4)
223#define decode_locku_maxsz (op_decode_hdr_maxsz + \
224 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400225#define encode_release_lockowner_maxsz \
226 (op_encode_hdr_maxsz + \
227 encode_lockowner_maxsz)
228#define decode_release_lockowner_maxsz \
229 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400230#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
231#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
233 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400234 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000235 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
237#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400238 1 + 2 + nfs4_name_maxsz + \
239 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400240#define decode_create_maxsz (op_decode_hdr_maxsz + \
241 decode_change_info_maxsz + \
242 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400243#define encode_statfs_maxsz (encode_getattr_maxsz)
244#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
246#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400247#define encode_getacl_maxsz (encode_getattr_maxsz)
248#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
249 nfs4_fattr_bitmap_maxsz + 1)
250#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
251 encode_stateid_maxsz + 3)
252#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400253#define encode_fs_locations_maxsz \
254 (encode_getattr_maxsz)
255#define decode_fs_locations_maxsz \
256 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000257#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400258#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400259
260#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400261#define NFS4_MAX_MACHINE_NAME_LEN (64)
262
Benny Halevy99fe60d2009-04-01 09:22:29 -0400263#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
264 encode_verifier_maxsz + \
265 1 /* co_ownerid.len */ + \
266 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
267 1 /* flags */ + \
268 1 /* spa_how */ + \
269 0 /* SP4_NONE (for now) */ + \
270 1 /* zero implemetation id array */)
271#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
272 2 /* eir_clientid */ + \
273 1 /* eir_sequenceid */ + \
274 1 /* eir_flags */ + \
275 1 /* spr_how */ + \
276 0 /* SP4_NONE (for now) */ + \
277 2 /* eir_server_owner.so_minor_id */ + \
278 /* eir_server_owner.so_major_id<> */ \
279 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
280 /* eir_server_scope<> */ \
281 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
282 1 /* eir_server_impl_id array length */ + \
283 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400284#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
285#define decode_channel_attrs_maxsz (6 + \
286 1 /* ca_rdma_ird.len */ + \
287 1 /* ca_rdma_ird */)
288#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
289 2 /* csa_clientid */ + \
290 1 /* csa_sequence */ + \
291 1 /* csa_flags */ + \
292 encode_channel_attrs_maxsz + \
293 encode_channel_attrs_maxsz + \
294 1 /* csa_cb_program */ + \
295 1 /* csa_sec_parms.len (1) */ + \
296 1 /* cb_secflavor (AUTH_SYS) */ + \
297 1 /* stamp */ + \
298 1 /* machinename.len */ + \
299 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
300 1 /* uid */ + \
301 1 /* gid */ + \
302 1 /* gids.len (0) */)
303#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
304 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
305 1 /* csr_sequence */ + \
306 1 /* csr_flags */ + \
307 decode_channel_attrs_maxsz + \
308 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400309#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
310#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400311#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
312 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
313#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
314 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500315#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
316#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400317#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
318 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
319#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
320 1 /* layout type */ + \
321 1 /* opaque devaddr4 length */ + \
322 /* devaddr4 payload is read into page */ \
323 1 /* notification bitmap length */ + \
324 1 /* notification bitmap */)
325#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
326 encode_stateid_maxsz)
327#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
328 decode_stateid_maxsz + \
329 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000330#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
331 2 /* offset */ + \
332 2 /* length */ + \
333 1 /* reclaim */ + \
334 encode_stateid_maxsz + \
335 1 /* new offset (true) */ + \
336 2 /* last byte written */ + \
337 1 /* nt_timechanged (false) */ + \
338 1 /* layoutupdate4 layout type */ + \
339 1 /* NULL filelayout layoutupdate4 payload */)
340#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300341#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
342 encode_stateid_maxsz + \
343 1 /* FIXME: opaque lrf_body always empty at the moment */)
344#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
345 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400346#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
347#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400348#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
349 XDR_QUADLEN(NFS4_STATEID_SIZE))
350#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400351#else /* CONFIG_NFS_V4_1 */
352#define encode_sequence_maxsz 0
353#define decode_sequence_maxsz 0
354#endif /* CONFIG_NFS_V4_1 */
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
357#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
358#define NFS4_enc_read_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_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400363 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400365 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400367 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400369 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400371 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400373 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400375 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400377 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400379 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400381 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400383 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400385 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400386 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400390 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400391 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400393 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400395 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400396 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400398 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400400 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400401 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400403 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400404 encode_putfh_maxsz + \
405 encode_savefh_maxsz + \
406 encode_open_maxsz + \
407 encode_getfh_maxsz + \
408 encode_getattr_maxsz + \
409 encode_restorefh_maxsz + \
410 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400412 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400413 decode_putfh_maxsz + \
414 decode_savefh_maxsz + \
415 decode_open_maxsz + \
416 decode_getfh_maxsz + \
417 decode_getattr_maxsz + \
418 decode_restorefh_maxsz + \
419 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400420#define NFS4_enc_open_confirm_sz \
421 (compound_encode_hdr_maxsz + \
422 encode_putfh_maxsz + \
423 encode_open_confirm_maxsz)
424#define NFS4_dec_open_confirm_sz \
425 (compound_decode_hdr_maxsz + \
426 decode_putfh_maxsz + \
427 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400429 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400431 encode_open_maxsz + \
432 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400436 decode_open_maxsz + \
437 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438#define NFS4_enc_open_downgrade_sz \
439 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400440 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400441 encode_putfh_maxsz + \
442 encode_open_downgrade_maxsz + \
443 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444#define NFS4_dec_open_downgrade_sz \
445 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400447 decode_putfh_maxsz + \
448 decode_open_downgrade_maxsz + \
449 decode_getattr_maxsz)
450#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400452 encode_putfh_maxsz + \
453 encode_close_maxsz + \
454 encode_getattr_maxsz)
455#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400457 decode_putfh_maxsz + \
458 decode_close_maxsz + \
459 decode_getattr_maxsz)
460#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400461 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400462 encode_putfh_maxsz + \
463 encode_setattr_maxsz + \
464 encode_getattr_maxsz)
465#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400467 decode_putfh_maxsz + \
468 decode_setattr_maxsz + \
469 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400471 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 encode_putfh_maxsz + \
473 encode_fsinfo_maxsz)
474#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400475 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 decode_putfh_maxsz + \
477 decode_fsinfo_maxsz)
478#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
479 encode_renew_maxsz)
480#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
481 decode_renew_maxsz)
482#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
483 encode_setclientid_maxsz)
484#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
485 decode_setclientid_maxsz)
486#define NFS4_enc_setclientid_confirm_sz \
487 (compound_encode_hdr_maxsz + \
488 encode_setclientid_confirm_maxsz + \
489 encode_putrootfh_maxsz + \
490 encode_fsinfo_maxsz)
491#define NFS4_dec_setclientid_confirm_sz \
492 (compound_decode_hdr_maxsz + \
493 decode_setclientid_confirm_maxsz + \
494 decode_putrootfh_maxsz + \
495 decode_fsinfo_maxsz)
496#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400497 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400499 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400501 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400503 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400505 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400507 encode_lockt_maxsz)
508#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400509 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400510 decode_putfh_maxsz + \
511 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512#define NFS4_enc_locku_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 + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400515 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516#define NFS4_dec_locku_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 + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400519 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400520#define NFS4_enc_release_lockowner_sz \
521 (compound_encode_hdr_maxsz + \
522 encode_lockowner_maxsz)
523#define NFS4_dec_release_lockowner_sz \
524 (compound_decode_hdr_maxsz + \
525 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400527 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400529 encode_access_maxsz + \
530 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400534 decode_access_maxsz + \
535 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400537 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 encode_putfh_maxsz + \
539 encode_getattr_maxsz)
540#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400541 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 decode_putfh_maxsz + \
543 decode_getattr_maxsz)
544#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400545 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 encode_putfh_maxsz + \
547 encode_lookup_maxsz + \
548 encode_getattr_maxsz + \
549 encode_getfh_maxsz)
550#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400551 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400553 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 decode_getattr_maxsz + \
555 decode_getfh_maxsz)
556#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400557 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 encode_putrootfh_maxsz + \
559 encode_getattr_maxsz + \
560 encode_getfh_maxsz)
561#define NFS4_dec_lookup_root_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_putrootfh_maxsz + \
564 decode_getattr_maxsz + \
565 decode_getfh_maxsz)
566#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400567 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400569 encode_remove_maxsz + \
570 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400574 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400575 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400577 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 encode_putfh_maxsz + \
579 encode_savefh_maxsz + \
580 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400581 encode_rename_maxsz + \
582 encode_getattr_maxsz + \
583 encode_restorefh_maxsz + \
584 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400586 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 decode_putfh_maxsz + \
588 decode_savefh_maxsz + \
589 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400590 decode_rename_maxsz + \
591 decode_getattr_maxsz + \
592 decode_restorefh_maxsz + \
593 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 encode_putfh_maxsz + \
597 encode_savefh_maxsz + \
598 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400599 encode_link_maxsz + \
600 decode_getattr_maxsz + \
601 encode_restorefh_maxsz + \
602 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400604 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 decode_putfh_maxsz + \
606 decode_savefh_maxsz + \
607 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400608 decode_link_maxsz + \
609 decode_getattr_maxsz + \
610 decode_restorefh_maxsz + \
611 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400613 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 encode_putfh_maxsz + \
615 encode_symlink_maxsz + \
616 encode_getattr_maxsz + \
617 encode_getfh_maxsz)
618#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400619 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 decode_putfh_maxsz + \
621 decode_symlink_maxsz + \
622 decode_getattr_maxsz + \
623 decode_getfh_maxsz)
624#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400625 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400627 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400629 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400631 encode_restorefh_maxsz + \
632 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400634 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400636 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400638 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400640 decode_restorefh_maxsz + \
641 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642#define NFS4_enc_pathconf_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 + \
645 encode_getattr_maxsz)
646#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400647 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 decode_putfh_maxsz + \
649 decode_getattr_maxsz)
650#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400651 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400653 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400655 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400657 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400659 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800660 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 encode_getattr_maxsz)
662#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400663 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800664 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 decode_getattr_maxsz)
666#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400667 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100669 encode_delegreturn_maxsz + \
670 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400672 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100673 decode_delegreturn_maxsz + \
674 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000675#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400676 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000677 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400678 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000679#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000681 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400682 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000683#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400684 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000685 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400686 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000687#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000689 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400690 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400691#define NFS4_enc_fs_locations_sz \
692 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400693 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400694 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400695 encode_lookup_maxsz + \
696 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400697#define NFS4_dec_fs_locations_sz \
698 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400699 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400700 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400701 decode_lookup_maxsz + \
702 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000703#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
704 encode_sequence_maxsz + \
705 encode_putfh_maxsz + \
706 encode_secinfo_maxsz)
707#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
708 decode_sequence_maxsz + \
709 decode_putfh_maxsz + \
710 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400711#if defined(CONFIG_NFS_V4_1)
712#define NFS4_enc_exchange_id_sz \
713 (compound_encode_hdr_maxsz + \
714 encode_exchange_id_maxsz)
715#define NFS4_dec_exchange_id_sz \
716 (compound_decode_hdr_maxsz + \
717 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400718#define NFS4_enc_create_session_sz \
719 (compound_encode_hdr_maxsz + \
720 encode_create_session_maxsz)
721#define NFS4_dec_create_session_sz \
722 (compound_decode_hdr_maxsz + \
723 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400724#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
725 encode_destroy_session_maxsz)
726#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
727 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400728#define NFS4_enc_sequence_sz \
729 (compound_decode_hdr_maxsz + \
730 encode_sequence_maxsz)
731#define NFS4_dec_sequence_sz \
732 (compound_decode_hdr_maxsz + \
733 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400734#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
735 encode_sequence_maxsz + \
736 encode_putrootfh_maxsz + \
737 encode_fsinfo_maxsz)
738#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
739 decode_sequence_maxsz + \
740 decode_putrootfh_maxsz + \
741 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500742#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
743 encode_sequence_maxsz + \
744 encode_reclaim_complete_maxsz)
745#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
746 decode_sequence_maxsz + \
747 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400748#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
749 encode_sequence_maxsz +\
750 encode_getdeviceinfo_maxsz)
751#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
752 decode_sequence_maxsz + \
753 decode_getdeviceinfo_maxsz)
754#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
755 encode_sequence_maxsz + \
756 encode_putfh_maxsz + \
757 encode_layoutget_maxsz)
758#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
759 decode_sequence_maxsz + \
760 decode_putfh_maxsz + \
761 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000762#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
763 encode_sequence_maxsz +\
764 encode_putfh_maxsz + \
765 encode_layoutcommit_maxsz + \
766 encode_getattr_maxsz)
767#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
768 decode_sequence_maxsz + \
769 decode_putfh_maxsz + \
770 decode_layoutcommit_maxsz + \
771 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300772#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
773 encode_sequence_maxsz + \
774 encode_putfh_maxsz + \
775 encode_layoutreturn_maxsz)
776#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
777 decode_sequence_maxsz + \
778 decode_putfh_maxsz + \
779 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400780#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
781 encode_sequence_maxsz + \
782 encode_putrootfh_maxsz +\
783 encode_secinfo_no_name_maxsz)
784#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
785 decode_sequence_maxsz + \
786 decode_putrootfh_maxsz + \
787 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400788#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
789 encode_sequence_maxsz + \
790 encode_test_stateid_maxsz)
791#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
792 decode_sequence_maxsz + \
793 decode_test_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500794
795const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
796 compound_encode_hdr_maxsz +
797 encode_sequence_maxsz +
798 encode_putfh_maxsz +
799 encode_getattr_maxsz) *
800 XDR_UNIT);
801
802const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
803 compound_decode_hdr_maxsz +
804 decode_sequence_maxsz +
805 decode_putfh_maxsz) *
806 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400807#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Trond Myklebustbca79472009-03-11 14:10:26 -0400809static const umode_t nfs_type2fmt[] = {
810 [NF4BAD] = 0,
811 [NF4REG] = S_IFREG,
812 [NF4DIR] = S_IFDIR,
813 [NF4BLK] = S_IFBLK,
814 [NF4CHR] = S_IFCHR,
815 [NF4LNK] = S_IFLNK,
816 [NF4SOCK] = S_IFSOCK,
817 [NF4FIFO] = S_IFIFO,
818 [NF4ATTRDIR] = 0,
819 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820};
821
822struct compound_hdr {
823 int32_t status;
824 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500825 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 uint32_t taglen;
827 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400828 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400829 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830};
831
Benny Halevy13c65ce2009-08-14 17:19:25 +0300832static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
833{
834 __be32 *p = xdr_reserve_space(xdr, nbytes);
835 BUG_ON(!p);
836 return p;
837}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
839static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
840{
Al Viro8687b632006-10-19 23:28:48 -0700841 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 p = xdr_reserve_space(xdr, 4 + len);
844 BUG_ON(p == NULL);
845 xdr_encode_opaque(p, str, len);
846}
847
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400848static void encode_compound_hdr(struct xdr_stream *xdr,
849 struct rpc_rqst *req,
850 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
Al Viro8687b632006-10-19 23:28:48 -0700852 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400853 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400854
855 /* initialize running count of expected bytes in reply.
856 * NOTE: the replied tag SHOULD be the same is the one sent,
857 * but this is not required as a MUST for the server to do so. */
858 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
861 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300862 p = reserve_space(xdr, 4 + hdr->taglen + 8);
863 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300864 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500865 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300866 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500867}
868
869static void encode_nops(struct compound_hdr *hdr)
870{
Andy Adamsonfc931582009-04-01 09:22:31 -0400871 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500872 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873}
874
875static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
876{
Al Viro8687b632006-10-19 23:28:48 -0700877 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
879 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
880 BUG_ON(p == NULL);
881 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
882}
883
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500884static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
886 char owner_name[IDMAP_NAMESZ];
887 char owner_group[IDMAP_NAMESZ];
888 int owner_namelen = 0;
889 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700890 __be32 *p;
891 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 int len;
893 uint32_t bmval0 = 0;
894 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 /*
897 * We reserve enough space to write the entire attribute buffer at once.
898 * In the worst-case, this would be
899 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
900 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000901 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 */
903 len = 16;
904
905 /* Sigh */
906 if (iap->ia_valid & ATTR_SIZE)
907 len += 8;
908 if (iap->ia_valid & ATTR_MODE)
909 len += 4;
910 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800911 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400913 dprintk("nfs: couldn't resolve uid %d to string\n",
914 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 /* XXX */
916 strcpy(owner_name, "nobody");
917 owner_namelen = sizeof("nobody") - 1;
918 /* goto out; */
919 }
920 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
921 }
922 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800923 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400925 dprintk("nfs: couldn't resolve gid %d to string\n",
926 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 strcpy(owner_group, "nobody");
928 owner_grouplen = sizeof("nobody") - 1;
929 /* goto out; */
930 }
931 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
932 }
933 if (iap->ia_valid & ATTR_ATIME_SET)
934 len += 16;
935 else if (iap->ia_valid & ATTR_ATIME)
936 len += 4;
937 if (iap->ia_valid & ATTR_MTIME_SET)
938 len += 16;
939 else if (iap->ia_valid & ATTR_MTIME)
940 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300941 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943 /*
944 * We write the bitmap length now, but leave the bitmap and the attribute
945 * buffer length to be backfilled at the end of this routine.
946 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300947 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 q = p;
949 p += 3;
950
951 if (iap->ia_valid & ATTR_SIZE) {
952 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300953 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 }
955 if (iap->ia_valid & ATTR_MODE) {
956 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300957 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 }
959 if (iap->ia_valid & ATTR_UID) {
960 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300961 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 }
963 if (iap->ia_valid & ATTR_GID) {
964 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300965 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 }
967 if (iap->ia_valid & ATTR_ATIME_SET) {
968 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300969 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
970 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400971 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
972 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 }
974 else if (iap->ia_valid & ATTR_ATIME) {
975 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300976 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 }
978 if (iap->ia_valid & ATTR_MTIME_SET) {
979 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300980 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
981 *p++ = cpu_to_be32(0);
982 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
983 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 }
985 else if (iap->ia_valid & ATTR_MTIME) {
986 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300987 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 /*
991 * Now we backfill the bitmap and the attribute buffer length.
992 */
993 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400994 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 len, ((char *)p - (char *)q) + 4);
996 BUG();
997 }
998 len = (char *)p - (char *)q - 12;
999 *q++ = htonl(bmval0);
1000 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001001 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004}
1005
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001006static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007{
Al Viro8687b632006-10-19 23:28:48 -07001008 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Benny Halevy13c65ce2009-08-14 17:19:25 +03001010 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001011 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001012 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001013 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001014 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015}
1016
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001017static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
Al Viro8687b632006-10-19 23:28:48 -07001019 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Benny Halevy13c65ce2009-08-14 17:19:25 +03001021 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001022 *p++ = cpu_to_be32(OP_CLOSE);
1023 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001024 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001025 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001026 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027}
1028
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001029static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030{
Al Viro8687b632006-10-19 23:28:48 -07001031 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001032
Benny Halevy13c65ce2009-08-14 17:19:25 +03001033 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001034 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001035 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001036 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001037 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001038 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039}
1040
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001041static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042{
Al Viro8687b632006-10-19 23:28:48 -07001043 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001044
Benny Halevy13c65ce2009-08-14 17:19:25 +03001045 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001046 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001047 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
1049 switch (create->ftype) {
1050 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001051 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001052 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001053 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 break;
1055
1056 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001057 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001058 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001059 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 break;
1061
1062 default:
1063 break;
1064 }
1065
Benny Halevy811652b2009-08-14 17:19:34 +03001066 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001067 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001068 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001070 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001073static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
Andy Adamson05d564f2008-12-23 16:06:15 -05001075 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Benny Halevy13c65ce2009-08-14 17:19:25 +03001077 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001078 *p++ = cpu_to_be32(OP_GETATTR);
1079 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001080 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001081 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001082 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001085static 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 -07001086{
Andy Adamson05d564f2008-12-23 16:06:15 -05001087 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Benny Halevy13c65ce2009-08-14 17:19:25 +03001089 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001090 *p++ = cpu_to_be32(OP_GETATTR);
1091 *p++ = cpu_to_be32(2);
1092 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001093 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001094 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001095 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096}
1097
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001098static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001100 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1101 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102}
1103
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001104static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001106 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1107 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108}
1109
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001110static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001111{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001112 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1113 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001114}
1115
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001116static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
Al Viro8687b632006-10-19 23:28:48 -07001118 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Benny Halevy13c65ce2009-08-14 17:19:25 +03001120 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001121 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001122 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001123 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124}
1125
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001126static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127{
Al Viro8687b632006-10-19 23:28:48 -07001128 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Benny Halevy13c65ce2009-08-14 17:19:25 +03001130 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001131 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001132 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001133 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001134 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135}
1136
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001137static inline int nfs4_lock_type(struct file_lock *fl, int block)
1138{
1139 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1140 return block ? NFS4_READW_LT : NFS4_READ_LT;
1141 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1142}
1143
1144static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1145{
1146 if (fl->fl_end == OFFSET_MAX)
1147 return ~(uint64_t)0;
1148 return fl->fl_end - fl->fl_start + 1;
1149}
1150
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001151static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1152{
1153 __be32 *p;
1154
Trond Myklebustd035c362010-12-21 10:45:27 -05001155 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001156 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001157 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001158 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001159 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001160 xdr_encode_hyper(p, lowner->id);
1161}
1162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163/*
1164 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1165 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1166 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001167static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Al Viro8687b632006-10-19 23:28:48 -07001169 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Benny Halevy13c65ce2009-08-14 17:19:25 +03001171 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001172 *p++ = cpu_to_be32(OP_LOCK);
1173 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1174 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001175 p = xdr_encode_hyper(p, args->fl->fl_start);
1176 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001177 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001178 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001179 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001180 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001181 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001182 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001183 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 }
1185 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001186 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001187 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001188 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
Andy Adamsond0179312008-12-23 16:06:17 -05001190 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001191 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192}
1193
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001194static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195{
Al Viro8687b632006-10-19 23:28:48 -07001196 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001198 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001199 *p++ = cpu_to_be32(OP_LOCKT);
1200 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001201 p = xdr_encode_hyper(p, args->fl->fl_start);
1202 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001203 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001204 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001205 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206}
1207
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001208static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209{
Al Viro8687b632006-10-19 23:28:48 -07001210 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
Benny Halevy13c65ce2009-08-14 17:19:25 +03001212 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001213 *p++ = cpu_to_be32(OP_LOCKU);
1214 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1215 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001216 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001217 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001218 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001219 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001220 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221}
1222
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001223static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1224{
1225 __be32 *p;
1226
1227 p = reserve_space(xdr, 4);
1228 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1229 encode_lockowner(xdr, lowner);
1230 hdr->nops++;
1231 hdr->replen += decode_release_lockowner_maxsz;
1232}
1233
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001234static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235{
1236 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001237 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
Benny Halevy13c65ce2009-08-14 17:19:25 +03001239 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001240 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001241 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001242 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001243 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244}
1245
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001246static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247{
Al Viro8687b632006-10-19 23:28:48 -07001248 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
Benny Halevy13c65ce2009-08-14 17:19:25 +03001250 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001251 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001252 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001253 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001254 break;
1255 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001256 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001257 break;
1258 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001259 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001260 break;
1261 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001262 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 }
Benny Halevy34558512009-08-14 17:19:30 +03001264 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
1267static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1268{
Al Viro8687b632006-10-19 23:28:48 -07001269 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 /*
1271 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1272 * owner 4 = 32
1273 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001274 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001275 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001276 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001277 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001278 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001279 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001280 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001281 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001282 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001283 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284}
1285
1286static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1287{
Al Viro8687b632006-10-19 23:28:48 -07001288 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001289 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Benny Halevy13c65ce2009-08-14 17:19:25 +03001291 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001293 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001294 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001295 encode_attrs(xdr, arg->u.attrs, arg->server);
1296 break;
1297 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001298 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001299 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001300 if (nfs4_has_persistent_session(clp)) {
1301 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1302 encode_attrs(xdr, arg->u.attrs, arg->server);
1303 } else {
1304 struct iattr dummy;
1305
1306 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1307 encode_nfs4_verifier(xdr, &arg->u.verifier);
1308 dummy.ia_valid = 0;
1309 encode_attrs(xdr, &dummy, arg->server);
1310 }
1311 } else {
1312 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1313 encode_nfs4_verifier(xdr, &arg->u.verifier);
1314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 }
1316}
1317
1318static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1319{
Al Viro8687b632006-10-19 23:28:48 -07001320 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
Benny Halevy13c65ce2009-08-14 17:19:25 +03001322 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001324 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001325 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001326 break;
1327 default:
1328 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001329 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001330 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 }
1332}
1333
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001334static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335{
Al Viro8687b632006-10-19 23:28:48 -07001336 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
Benny Halevy13c65ce2009-08-14 17:19:25 +03001338 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001340 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001341 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001342 break;
1343 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001344 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001345 break;
1346 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001347 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001348 break;
1349 default:
1350 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 }
1352}
1353
1354static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1355{
Al Viro8687b632006-10-19 23:28:48 -07001356 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Benny Halevy13c65ce2009-08-14 17:19:25 +03001358 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001359 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 encode_string(xdr, name->len, name->name);
1361}
1362
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001363static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364{
Al Viro8687b632006-10-19 23:28:48 -07001365 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
Benny Halevy13c65ce2009-08-14 17:19:25 +03001367 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001368 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 encode_delegation_type(xdr, type);
1370}
1371
1372static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1373{
Al Viro8687b632006-10-19 23:28:48 -07001374 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
Benny Halevy13c65ce2009-08-14 17:19:25 +03001376 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001377 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001378 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 encode_string(xdr, name->len, name->name);
1380}
1381
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001382static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383{
1384 encode_openhdr(xdr, arg);
1385 encode_opentype(xdr, arg);
1386 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001387 case NFS4_OPEN_CLAIM_NULL:
1388 encode_claim_null(xdr, arg->name);
1389 break;
1390 case NFS4_OPEN_CLAIM_PREVIOUS:
1391 encode_claim_previous(xdr, arg->u.delegation_type);
1392 break;
1393 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1394 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1395 break;
1396 default:
1397 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 }
Andy Adamsond0179312008-12-23 16:06:17 -05001399 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001400 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401}
1402
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001403static 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 -07001404{
Al Viro8687b632006-10-19 23:28:48 -07001405 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Benny Halevy13c65ce2009-08-14 17:19:25 +03001407 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001408 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001409 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001410 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001411 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001412 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413}
1414
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001415static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416{
Al Viro8687b632006-10-19 23:28:48 -07001417 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Benny Halevy13c65ce2009-08-14 17:19:25 +03001419 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001420 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001421 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001422 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001423 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001424 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001425 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426}
1427
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001428static void
Andy Adamsond0179312008-12-23 16:06:17 -05001429encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430{
1431 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001432 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
Benny Halevy13c65ce2009-08-14 17:19:25 +03001434 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001435 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001436 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001437 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001438 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439}
1440
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001441static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442{
Andy Adamson05d564f2008-12-23 16:06:15 -05001443 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001444
Benny Halevy13c65ce2009-08-14 17:19:25 +03001445 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001446 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001447 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001448 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449}
1450
Andy Adamson89d1ea62011-03-01 01:34:09 +00001451static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001454 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Benny Halevy13c65ce2009-08-14 17:19:25 +03001456 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001458 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001459 if (zero_seqid)
1460 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001461 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 } else
Benny Halevy34558512009-08-14 17:19:30 +03001463 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464}
1465
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001466static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
Al Viro8687b632006-10-19 23:28:48 -07001468 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Benny Halevy13c65ce2009-08-14 17:19:25 +03001470 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001471 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Andy Adamson89d1ea62011-03-01 01:34:09 +00001473 encode_stateid(xdr, args->context, args->lock_context,
1474 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Benny Halevy13c65ce2009-08-14 17:19:25 +03001476 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001477 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001478 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001479 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001480 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481}
1482
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001483static 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 -07001484{
Trond Myklebust28331a42011-04-27 13:47:52 -04001485 uint32_t attrs[2] = {
1486 FATTR4_WORD0_RDATTR_ERROR,
1487 FATTR4_WORD1_MOUNTED_ON_FILEID,
1488 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001489 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001490 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001492 if (readdir->plus) {
1493 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001494 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001495 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1496 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1497 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1498 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001499 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001500 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001501 /* Use mounted_on_fileid only if the server supports it */
1502 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1503 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001504
Benny Halevy13c65ce2009-08-14 17:19:25 +03001505 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001506 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001507 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001508 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001509 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001510 *p++ = cpu_to_be32(readdir->count);
1511 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001512
Benny Halevye75bc1c2009-08-14 17:18:54 +03001513 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001514 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001515 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001516 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001517 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1518 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001519 (unsigned long long)readdir->cookie,
1520 ((u32 *)readdir->verifier.data)[0],
1521 ((u32 *)readdir->verifier.data)[1],
1522 attrs[0] & readdir->bitmask[0],
1523 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524}
1525
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001526static 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 -07001527{
Al Viro8687b632006-10-19 23:28:48 -07001528 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Benny Halevy13c65ce2009-08-14 17:19:25 +03001530 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001531 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001532 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001533 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534}
1535
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001536static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537{
Al Viro8687b632006-10-19 23:28:48 -07001538 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
Benny Halevy13c65ce2009-08-14 17:19:25 +03001540 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001541 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001542 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001543 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001544 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545}
1546
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001547static 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 -07001548{
Al Viro8687b632006-10-19 23:28:48 -07001549 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Benny Halevy811652b2009-08-14 17:19:34 +03001551 p = reserve_space(xdr, 4);
1552 *p = cpu_to_be32(OP_RENAME);
1553 encode_string(xdr, oldname->len, oldname->name);
1554 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001555 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001556 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557}
1558
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001559static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560{
Al Viro8687b632006-10-19 23:28:48 -07001561 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Benny Halevy13c65ce2009-08-14 17:19:25 +03001563 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001564 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001565 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001566 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001567 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568}
1569
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001570static void
Andy Adamsond0179312008-12-23 16:06:17 -05001571encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001572{
Al Viro8687b632006-10-19 23:28:48 -07001573 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001574
Benny Halevy13c65ce2009-08-14 17:19:25 +03001575 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001576 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001577 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001578 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001579}
1580
Chuck Lever9f06c712010-12-14 14:59:18 +00001581static void
Andy Adamsond0179312008-12-23 16:06:17 -05001582encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001583{
Al Viro8687b632006-10-19 23:28:48 -07001584 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001585
Benny Halevy13c65ce2009-08-14 17:19:25 +03001586 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001587 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001588 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001589 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001590 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001591 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001592 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001593 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001594 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001595 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001596 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001597 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001598}
1599
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001600static void
Andy Adamsond0179312008-12-23 16:06:17 -05001601encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602{
Al Viro8687b632006-10-19 23:28:48 -07001603 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
Benny Halevy13c65ce2009-08-14 17:19:25 +03001605 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001606 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001607 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001608 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609}
1610
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001611static 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 -07001612{
Al Viro8687b632006-10-19 23:28:48 -07001613 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001614
Benny Halevy13c65ce2009-08-14 17:19:25 +03001615 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001616 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001617 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001618 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001619 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001620 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001623static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
Al Viro8687b632006-10-19 23:28:48 -07001625 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Benny Halevy13c65ce2009-08-14 17:19:25 +03001627 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001628 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001629 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
1631 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001632 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001633 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1635 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001636 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001637 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001638 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001639 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640}
1641
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001642static 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 -07001643{
Andy Adamson05d564f2008-12-23 16:06:15 -05001644 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
Benny Halevy13c65ce2009-08-14 17:19:25 +03001646 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001647 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001648 p = xdr_encode_hyper(p, arg->clientid);
1649 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001650 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001651 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652}
1653
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001654static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655{
Al Viro8687b632006-10-19 23:28:48 -07001656 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
Benny Halevy13c65ce2009-08-14 17:19:25 +03001658 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001659 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
Andy Adamson89d1ea62011-03-01 01:34:09 +00001661 encode_stateid(xdr, args->context, args->lock_context,
1662 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
Benny Halevy13c65ce2009-08-14 17:19:25 +03001664 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001665 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001666 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001667 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
1669 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001670 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001671 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672}
1673
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001674static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
Al Viro8687b632006-10-19 23:28:48 -07001676 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
Benny Halevy13c65ce2009-08-14 17:19:25 +03001678 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Benny Halevye75bc1c2009-08-14 17:18:54 +03001680 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001681 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001682 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001683 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001685
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001686static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1687{
1688 int len = name->len;
1689 __be32 *p;
1690
1691 p = reserve_space(xdr, 8 + len);
1692 *p++ = cpu_to_be32(OP_SECINFO);
1693 xdr_encode_opaque(p, name->name, len);
1694 hdr->nops++;
1695 hdr->replen += decode_secinfo_maxsz;
1696}
1697
Benny Halevy99fe60d2009-04-01 09:22:29 -04001698#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001699/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001700static void encode_exchange_id(struct xdr_stream *xdr,
1701 struct nfs41_exchange_id_args *args,
1702 struct compound_hdr *hdr)
1703{
1704 __be32 *p;
1705
Benny Halevy13c65ce2009-08-14 17:19:25 +03001706 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001707 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001708 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001709
1710 encode_string(xdr, args->id_len, args->id);
1711
Benny Halevy13c65ce2009-08-14 17:19:25 +03001712 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001713 *p++ = cpu_to_be32(args->flags);
1714 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001715 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001716 hdr->nops++;
1717 hdr->replen += decode_exchange_id_maxsz;
1718}
Andy Adamsonfc931582009-04-01 09:22:31 -04001719
1720static void encode_create_session(struct xdr_stream *xdr,
1721 struct nfs41_create_session_args *args,
1722 struct compound_hdr *hdr)
1723{
1724 __be32 *p;
1725 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1726 uint32_t len;
1727 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001728 u32 max_resp_sz_cached;
1729
1730 /*
1731 * Assumes OPEN is the biggest non-idempotent compound.
1732 * 2 is the verifier.
1733 */
1734 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1735 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001736
Andy Adamsonfc931582009-04-01 09:22:31 -04001737 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1738 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001739
Benny Halevy13c65ce2009-08-14 17:19:25 +03001740 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001741 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001742 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001743 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1744 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001745
Andy Adamsonfc931582009-04-01 09:22:31 -04001746 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001747 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001748 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1749 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001750 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001751 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1752 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1753 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001754
1755 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001756 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001757 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1758 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1759 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1760 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1761 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1762 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001763
Benny Halevye75bc1c2009-08-14 17:18:54 +03001764 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001765 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001766 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001767
1768 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001769 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001770 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001771 *p++ = cpu_to_be32(0); /* UID */
1772 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001773 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001774 hdr->nops++;
1775 hdr->replen += decode_create_session_maxsz;
1776}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001777
1778static void encode_destroy_session(struct xdr_stream *xdr,
1779 struct nfs4_session *session,
1780 struct compound_hdr *hdr)
1781{
1782 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001783 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001784 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001785 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001786 hdr->nops++;
1787 hdr->replen += decode_destroy_session_maxsz;
1788}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001789
1790static void encode_reclaim_complete(struct xdr_stream *xdr,
1791 struct nfs41_reclaim_complete_args *args,
1792 struct compound_hdr *hdr)
1793{
1794 __be32 *p;
1795
1796 p = reserve_space(xdr, 8);
1797 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1798 *p++ = cpu_to_be32(args->one_fs);
1799 hdr->nops++;
1800 hdr->replen += decode_reclaim_complete_maxsz;
1801}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001802#endif /* CONFIG_NFS_V4_1 */
1803
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001804static void encode_sequence(struct xdr_stream *xdr,
1805 const struct nfs4_sequence_args *args,
1806 struct compound_hdr *hdr)
1807{
1808#if defined(CONFIG_NFS_V4_1)
1809 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001810 struct nfs4_slot_table *tp;
1811 struct nfs4_slot *slot;
1812 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001813
1814 if (!session)
1815 return;
1816
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001817 tp = &session->fc_slot_table;
1818
1819 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1820 slot = tp->slots + args->sa_slotid;
1821
Benny Halevy13c65ce2009-08-14 17:19:25 +03001822 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001823 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001824
1825 /*
1826 * Sessionid + seqid + slotid + max slotid + cache_this
1827 */
1828 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1829 "max_slotid=%d cache_this=%d\n",
1830 __func__,
1831 ((u32 *)session->sess_id.data)[0],
1832 ((u32 *)session->sess_id.data)[1],
1833 ((u32 *)session->sess_id.data)[2],
1834 ((u32 *)session->sess_id.data)[3],
1835 slot->seq_nr, args->sa_slotid,
1836 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001837 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001838 *p++ = cpu_to_be32(slot->seq_nr);
1839 *p++ = cpu_to_be32(args->sa_slotid);
1840 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001841 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001842 hdr->nops++;
1843 hdr->replen += decode_sequence_maxsz;
1844#endif /* CONFIG_NFS_V4_1 */
1845}
1846
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001847#ifdef CONFIG_NFS_V4_1
1848static void
1849encode_getdeviceinfo(struct xdr_stream *xdr,
1850 const struct nfs4_getdeviceinfo_args *args,
1851 struct compound_hdr *hdr)
1852{
1853 __be32 *p;
1854
1855 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1856 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1857 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1858 NFS4_DEVICEID4_SIZE);
1859 *p++ = cpu_to_be32(args->pdev->layout_type);
1860 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1861 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1862 hdr->nops++;
1863 hdr->replen += decode_getdeviceinfo_maxsz;
1864}
1865
1866static void
1867encode_layoutget(struct xdr_stream *xdr,
1868 const struct nfs4_layoutget_args *args,
1869 struct compound_hdr *hdr)
1870{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001871 __be32 *p;
1872
1873 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1874 *p++ = cpu_to_be32(OP_LAYOUTGET);
1875 *p++ = cpu_to_be32(0); /* Signal layout available */
1876 *p++ = cpu_to_be32(args->type);
1877 *p++ = cpu_to_be32(args->range.iomode);
1878 p = xdr_encode_hyper(p, args->range.offset);
1879 p = xdr_encode_hyper(p, args->range.length);
1880 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001881 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001882 *p = cpu_to_be32(args->maxcount);
1883
1884 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1885 __func__,
1886 args->type,
1887 args->range.iomode,
1888 (unsigned long)args->range.offset,
1889 (unsigned long)args->range.length,
1890 args->maxcount);
1891 hdr->nops++;
1892 hdr->replen += decode_layoutget_maxsz;
1893}
Andy Adamson863a3c62011-03-23 13:27:54 +00001894
1895static int
1896encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001897 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001898 const struct nfs4_layoutcommit_args *args,
1899 struct compound_hdr *hdr)
1900{
1901 __be32 *p;
1902
1903 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1904 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1905
Benny Halevyac7db722011-05-22 19:53:48 +03001906 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
Andy Adamson863a3c62011-03-23 13:27:54 +00001907 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1908 /* Only whole file layouts */
1909 p = xdr_encode_hyper(p, 0); /* offset */
1910 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); /* length */
1911 *p++ = cpu_to_be32(0); /* reclaim */
1912 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1913 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1914 p = xdr_encode_hyper(p, args->lastbytewritten);
1915 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1916 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001917
1918 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1919 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1920 NFS_I(inode)->layout, xdr, args);
1921 else {
1922 p = reserve_space(xdr, 4);
1923 *p = cpu_to_be32(0); /* no layout-type payload */
1924 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001925
1926 hdr->nops++;
1927 hdr->replen += decode_layoutcommit_maxsz;
1928 return 0;
1929}
Benny Halevycbe82602011-05-22 19:52:37 +03001930
1931static void
1932encode_layoutreturn(struct xdr_stream *xdr,
1933 const struct nfs4_layoutreturn_args *args,
1934 struct compound_hdr *hdr)
1935{
1936 __be32 *p;
1937
1938 p = reserve_space(xdr, 20);
1939 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
1940 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1941 *p++ = cpu_to_be32(args->layout_type);
1942 *p++ = cpu_to_be32(IOMODE_ANY);
1943 *p = cpu_to_be32(RETURN_FILE);
1944 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
1945 p = xdr_encode_hyper(p, 0);
1946 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1947 spin_lock(&args->inode->i_lock);
1948 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1949 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001950 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1951 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1952 NFS_I(args->inode)->layout, xdr, args);
1953 } else {
1954 p = reserve_space(xdr, 4);
1955 *p = cpu_to_be32(0);
1956 }
Benny Halevycbe82602011-05-22 19:52:37 +03001957 hdr->nops++;
1958 hdr->replen += decode_layoutreturn_maxsz;
1959}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001960
1961static int
1962encode_secinfo_no_name(struct xdr_stream *xdr,
1963 const struct nfs41_secinfo_no_name_args *args,
1964 struct compound_hdr *hdr)
1965{
1966 __be32 *p;
1967 p = reserve_space(xdr, 8);
1968 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
1969 *p++ = cpu_to_be32(args->style);
1970 hdr->nops++;
1971 hdr->replen += decode_secinfo_no_name_maxsz;
1972 return 0;
1973}
Bryan Schumaker7d974792011-06-02 14:59:08 -04001974
1975static void encode_test_stateid(struct xdr_stream *xdr,
1976 struct nfs41_test_stateid_args *args,
1977 struct compound_hdr *hdr)
1978{
1979 __be32 *p;
1980
1981 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
1982 *p++ = cpu_to_be32(OP_TEST_STATEID);
1983 *p++ = cpu_to_be32(1);
1984 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
1985 hdr->nops++;
1986 hdr->replen += decode_test_stateid_maxsz;
1987}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001988#endif /* CONFIG_NFS_V4_1 */
1989
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990/*
1991 * END OF "GENERIC" ENCODE ROUTINES.
1992 */
1993
Benny Halevy66cc0422009-04-01 09:22:10 -04001994static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1995{
1996#if defined(CONFIG_NFS_V4_1)
1997 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001998 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001999#endif /* CONFIG_NFS_V4_1 */
2000 return 0;
2001}
2002
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003/*
2004 * Encode an ACCESS request
2005 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002006static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2007 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
Chuck Lever9f06c712010-12-14 14:59:18 +00002013 encode_compound_hdr(xdr, req, &hdr);
2014 encode_sequence(xdr, &args->seq_args, &hdr);
2015 encode_putfh(xdr, args->fh, &hdr);
2016 encode_access(xdr, args->access, &hdr);
2017 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002018 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019}
2020
2021/*
2022 * Encode LOOKUP request
2023 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002024static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2025 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002028 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030
Chuck Lever9f06c712010-12-14 14:59:18 +00002031 encode_compound_hdr(xdr, req, &hdr);
2032 encode_sequence(xdr, &args->seq_args, &hdr);
2033 encode_putfh(xdr, args->dir_fh, &hdr);
2034 encode_lookup(xdr, args->name, &hdr);
2035 encode_getfh(xdr, &hdr);
2036 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002037 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038}
2039
2040/*
2041 * Encode LOOKUP_ROOT request
2042 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002043static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2044 struct xdr_stream *xdr,
2045 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002048 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
Chuck Lever9f06c712010-12-14 14:59:18 +00002051 encode_compound_hdr(xdr, req, &hdr);
2052 encode_sequence(xdr, &args->seq_args, &hdr);
2053 encode_putrootfh(xdr, &hdr);
2054 encode_getfh(xdr, &hdr);
2055 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002056 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057}
2058
2059/*
2060 * Encode REMOVE request
2061 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002062static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2063 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002066 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
Chuck Lever9f06c712010-12-14 14:59:18 +00002069 encode_compound_hdr(xdr, req, &hdr);
2070 encode_sequence(xdr, &args->seq_args, &hdr);
2071 encode_putfh(xdr, args->fh, &hdr);
2072 encode_remove(xdr, &args->name, &hdr);
2073 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002074 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075}
2076
2077/*
2078 * Encode RENAME request
2079 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002080static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2081 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002084 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
Chuck Lever9f06c712010-12-14 14:59:18 +00002087 encode_compound_hdr(xdr, req, &hdr);
2088 encode_sequence(xdr, &args->seq_args, &hdr);
2089 encode_putfh(xdr, args->old_dir, &hdr);
2090 encode_savefh(xdr, &hdr);
2091 encode_putfh(xdr, args->new_dir, &hdr);
2092 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2093 encode_getfattr(xdr, args->bitmask, &hdr);
2094 encode_restorefh(xdr, &hdr);
2095 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002096 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097}
2098
2099/*
2100 * Encode LINK request
2101 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002102static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2103 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002106 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
Chuck Lever9f06c712010-12-14 14:59:18 +00002109 encode_compound_hdr(xdr, req, &hdr);
2110 encode_sequence(xdr, &args->seq_args, &hdr);
2111 encode_putfh(xdr, args->fh, &hdr);
2112 encode_savefh(xdr, &hdr);
2113 encode_putfh(xdr, args->dir_fh, &hdr);
2114 encode_link(xdr, args->name, &hdr);
2115 encode_getfattr(xdr, args->bitmask, &hdr);
2116 encode_restorefh(xdr, &hdr);
2117 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002118 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119}
2120
2121/*
2122 * Encode CREATE request
2123 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002124static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2125 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002128 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
Chuck Lever9f06c712010-12-14 14:59:18 +00002131 encode_compound_hdr(xdr, req, &hdr);
2132 encode_sequence(xdr, &args->seq_args, &hdr);
2133 encode_putfh(xdr, args->dir_fh, &hdr);
2134 encode_savefh(xdr, &hdr);
2135 encode_create(xdr, args, &hdr);
2136 encode_getfh(xdr, &hdr);
2137 encode_getfattr(xdr, args->bitmask, &hdr);
2138 encode_restorefh(xdr, &hdr);
2139 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002140 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141}
2142
2143/*
2144 * Encode SYMLINK request
2145 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002146static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2147 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148{
Chuck Lever9f06c712010-12-14 14:59:18 +00002149 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150}
2151
2152/*
2153 * Encode GETATTR request
2154 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002155static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2156 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002159 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
Chuck Lever9f06c712010-12-14 14:59:18 +00002162 encode_compound_hdr(xdr, req, &hdr);
2163 encode_sequence(xdr, &args->seq_args, &hdr);
2164 encode_putfh(xdr, args->fh, &hdr);
2165 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002166 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167}
2168
2169/*
2170 * Encode a CLOSE request
2171 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002172static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2173 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174{
Andy Adamson05d564f2008-12-23 16:06:15 -05002175 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002176 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002177 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Chuck Lever9f06c712010-12-14 14:59:18 +00002179 encode_compound_hdr(xdr, req, &hdr);
2180 encode_sequence(xdr, &args->seq_args, &hdr);
2181 encode_putfh(xdr, args->fh, &hdr);
2182 encode_close(xdr, args, &hdr);
2183 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002184 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185}
2186
2187/*
2188 * Encode an OPEN request
2189 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002190static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2191 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002194 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
Chuck Lever9f06c712010-12-14 14:59:18 +00002197 encode_compound_hdr(xdr, req, &hdr);
2198 encode_sequence(xdr, &args->seq_args, &hdr);
2199 encode_putfh(xdr, args->fh, &hdr);
2200 encode_savefh(xdr, &hdr);
2201 encode_open(xdr, args, &hdr);
2202 encode_getfh(xdr, &hdr);
2203 encode_getfattr(xdr, args->bitmask, &hdr);
2204 encode_restorefh(xdr, &hdr);
2205 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002206 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207}
2208
2209/*
2210 * Encode an OPEN_CONFIRM request
2211 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002212static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2213 struct xdr_stream *xdr,
2214 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002217 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
Chuck Lever9f06c712010-12-14 14:59:18 +00002220 encode_compound_hdr(xdr, req, &hdr);
2221 encode_putfh(xdr, args->fh, &hdr);
2222 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002223 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224}
2225
2226/*
2227 * Encode an OPEN request with no attributes.
2228 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002229static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2230 struct xdr_stream *xdr,
2231 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002234 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
Chuck Lever9f06c712010-12-14 14:59:18 +00002237 encode_compound_hdr(xdr, req, &hdr);
2238 encode_sequence(xdr, &args->seq_args, &hdr);
2239 encode_putfh(xdr, args->fh, &hdr);
2240 encode_open(xdr, args, &hdr);
2241 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002242 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243}
2244
2245/*
2246 * Encode an OPEN_DOWNGRADE request
2247 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002248static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2249 struct xdr_stream *xdr,
2250 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002253 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Chuck Lever9f06c712010-12-14 14:59:18 +00002256 encode_compound_hdr(xdr, req, &hdr);
2257 encode_sequence(xdr, &args->seq_args, &hdr);
2258 encode_putfh(xdr, args->fh, &hdr);
2259 encode_open_downgrade(xdr, args, &hdr);
2260 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002261 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262}
2263
2264/*
2265 * Encode a LOCK request
2266 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002267static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2268 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002271 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273
Chuck Lever9f06c712010-12-14 14:59:18 +00002274 encode_compound_hdr(xdr, req, &hdr);
2275 encode_sequence(xdr, &args->seq_args, &hdr);
2276 encode_putfh(xdr, args->fh, &hdr);
2277 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002278 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279}
2280
2281/*
2282 * Encode a LOCKT request
2283 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002284static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2285 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002288 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
Chuck Lever9f06c712010-12-14 14:59:18 +00002291 encode_compound_hdr(xdr, req, &hdr);
2292 encode_sequence(xdr, &args->seq_args, &hdr);
2293 encode_putfh(xdr, args->fh, &hdr);
2294 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002295 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296}
2297
2298/*
2299 * Encode a LOCKU request
2300 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002301static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2302 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002305 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
Chuck Lever9f06c712010-12-14 14:59:18 +00002308 encode_compound_hdr(xdr, req, &hdr);
2309 encode_sequence(xdr, &args->seq_args, &hdr);
2310 encode_putfh(xdr, args->fh, &hdr);
2311 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002312 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313}
2314
Chuck Lever9f06c712010-12-14 14:59:18 +00002315static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2316 struct xdr_stream *xdr,
2317 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002318{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002319 struct compound_hdr hdr = {
2320 .minorversion = 0,
2321 };
2322
Chuck Lever9f06c712010-12-14 14:59:18 +00002323 encode_compound_hdr(xdr, req, &hdr);
2324 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002325 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002326}
2327
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328/*
2329 * Encode a READLINK request
2330 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002331static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2332 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002335 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
Chuck Lever9f06c712010-12-14 14:59:18 +00002338 encode_compound_hdr(xdr, req, &hdr);
2339 encode_sequence(xdr, &args->seq_args, &hdr);
2340 encode_putfh(xdr, args->fh, &hdr);
2341 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002342
Benny Halevy28f56692009-04-01 09:22:09 -04002343 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002344 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002345 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346}
2347
2348/*
2349 * Encode a READDIR request
2350 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002351static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2352 const struct nfs4_readdir_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->fh, &hdr);
2361 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002362
Benny Halevy28f56692009-04-01 09:22:09 -04002363 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002364 args->pgbase, args->count);
2365 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002366 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002367 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002368 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369}
2370
2371/*
2372 * Encode a READ request
2373 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002374static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2375 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002378 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380
Chuck Lever9f06c712010-12-14 14:59:18 +00002381 encode_compound_hdr(xdr, req, &hdr);
2382 encode_sequence(xdr, &args->seq_args, &hdr);
2383 encode_putfh(xdr, args->fh, &hdr);
2384 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
Benny Halevy28f56692009-04-01 09:22:09 -04002386 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002388 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002389 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390}
2391
2392/*
2393 * Encode an SETATTR request
2394 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002395static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2396 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397{
Andy Adamson05d564f2008-12-23 16:06:15 -05002398 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002399 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002400 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Chuck Lever9f06c712010-12-14 14:59:18 +00002402 encode_compound_hdr(xdr, req, &hdr);
2403 encode_sequence(xdr, &args->seq_args, &hdr);
2404 encode_putfh(xdr, args->fh, &hdr);
2405 encode_setattr(xdr, args, args->server, &hdr);
2406 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002407 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408}
2409
2410/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002411 * Encode a GETACL request
2412 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002413static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2414 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002415{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002416 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002417 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002418 };
Benny Halevy28f56692009-04-01 09:22:09 -04002419 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002420
Chuck Lever9f06c712010-12-14 14:59:18 +00002421 encode_compound_hdr(xdr, req, &hdr);
2422 encode_sequence(xdr, &args->seq_args, &hdr);
2423 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002424 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002425 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002426
Benny Halevy28f56692009-04-01 09:22:09 -04002427 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002428 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002429 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002430}
2431
2432/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 * Encode a WRITE request
2434 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002435static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2436 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002439 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
Chuck Lever9f06c712010-12-14 14:59:18 +00002442 encode_compound_hdr(xdr, req, &hdr);
2443 encode_sequence(xdr, &args->seq_args, &hdr);
2444 encode_putfh(xdr, args->fh, &hdr);
2445 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002446 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002447 if (args->bitmask)
2448 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002449 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450}
2451
2452/*
2453 * a COMMIT request
2454 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002455static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2456 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002459 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461
Chuck Lever9f06c712010-12-14 14:59:18 +00002462 encode_compound_hdr(xdr, req, &hdr);
2463 encode_sequence(xdr, &args->seq_args, &hdr);
2464 encode_putfh(xdr, args->fh, &hdr);
2465 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002466 if (args->bitmask)
2467 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002468 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469}
2470
2471/*
2472 * FSINFO request
2473 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002474static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2475 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002478 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480
Chuck Lever9f06c712010-12-14 14:59:18 +00002481 encode_compound_hdr(xdr, req, &hdr);
2482 encode_sequence(xdr, &args->seq_args, &hdr);
2483 encode_putfh(xdr, args->fh, &hdr);
2484 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002485 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486}
2487
2488/*
2489 * a PATHCONF request
2490 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002491static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2492 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
Chuck Lever9f06c712010-12-14 14:59:18 +00002498 encode_compound_hdr(xdr, req, &hdr);
2499 encode_sequence(xdr, &args->seq_args, &hdr);
2500 encode_putfh(xdr, args->fh, &hdr);
2501 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002502 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002503 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504}
2505
2506/*
2507 * a STATFS request
2508 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002509static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2510 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002513 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515
Chuck Lever9f06c712010-12-14 14:59:18 +00002516 encode_compound_hdr(xdr, req, &hdr);
2517 encode_sequence(xdr, &args->seq_args, &hdr);
2518 encode_putfh(xdr, args->fh, &hdr);
2519 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002520 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002521 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522}
2523
2524/*
2525 * GETATTR_BITMAP request
2526 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002527static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2528 struct xdr_stream *xdr,
2529 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002532 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
Chuck Lever9f06c712010-12-14 14:59:18 +00002535 encode_compound_hdr(xdr, req, &hdr);
2536 encode_sequence(xdr, &args->seq_args, &hdr);
2537 encode_putfh(xdr, args->fhandle, &hdr);
2538 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002539 FATTR4_WORD0_LINK_SUPPORT|
2540 FATTR4_WORD0_SYMLINK_SUPPORT|
2541 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002542 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543}
2544
2545/*
2546 * a RENEW request
2547 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002548static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2549 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002552 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 };
2554
Chuck Lever9f06c712010-12-14 14:59:18 +00002555 encode_compound_hdr(xdr, req, &hdr);
2556 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002557 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558}
2559
2560/*
2561 * a SETCLIENTID request
2562 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002563static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2564 struct xdr_stream *xdr,
2565 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002568 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 };
2570
Chuck Lever9f06c712010-12-14 14:59:18 +00002571 encode_compound_hdr(xdr, req, &hdr);
2572 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002573 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574}
2575
2576/*
2577 * a SETCLIENTID_CONFIRM request
2578 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002579static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2580 struct xdr_stream *xdr,
2581 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002584 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 };
2586 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587
Chuck Lever9f06c712010-12-14 14:59:18 +00002588 encode_compound_hdr(xdr, req, &hdr);
2589 encode_setclientid_confirm(xdr, arg, &hdr);
2590 encode_putrootfh(xdr, &hdr);
2591 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002592 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593}
2594
2595/*
2596 * DELEGRETURN request
2597 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002598static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2599 struct xdr_stream *xdr,
2600 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002603 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605
Chuck Lever9f06c712010-12-14 14:59:18 +00002606 encode_compound_hdr(xdr, req, &hdr);
2607 encode_sequence(xdr, &args->seq_args, &hdr);
2608 encode_putfh(xdr, args->fhandle, &hdr);
2609 encode_delegreturn(xdr, args->stateid, &hdr);
2610 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002611 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612}
2613
2614/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002615 * Encode FS_LOCATIONS request
2616 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002617static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2618 struct xdr_stream *xdr,
2619 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002620{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002621 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002622 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002623 };
Benny Halevy28f56692009-04-01 09:22:09 -04002624 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002625
Chuck Lever9f06c712010-12-14 14:59:18 +00002626 encode_compound_hdr(xdr, req, &hdr);
2627 encode_sequence(xdr, &args->seq_args, &hdr);
2628 encode_putfh(xdr, args->dir_fh, &hdr);
2629 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002630 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002631 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002632
Benny Halevy28f56692009-04-01 09:22:09 -04002633 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002634 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002635 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002636}
2637
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002638/*
2639 * Encode SECINFO request
2640 */
2641static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2642 struct xdr_stream *xdr,
2643 struct nfs4_secinfo_arg *args)
2644{
2645 struct compound_hdr hdr = {
2646 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2647 };
2648
2649 encode_compound_hdr(xdr, req, &hdr);
2650 encode_sequence(xdr, &args->seq_args, &hdr);
2651 encode_putfh(xdr, args->dir_fh, &hdr);
2652 encode_secinfo(xdr, args->name, &hdr);
2653 encode_nops(&hdr);
2654}
2655
Benny Halevy99fe60d2009-04-01 09:22:29 -04002656#if defined(CONFIG_NFS_V4_1)
2657/*
2658 * EXCHANGE_ID request
2659 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002660static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2661 struct xdr_stream *xdr,
2662 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002663{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002664 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002665 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002666 };
2667
Chuck Lever9f06c712010-12-14 14:59:18 +00002668 encode_compound_hdr(xdr, req, &hdr);
2669 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002670 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002671}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002672
2673/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002674 * a CREATE_SESSION request
2675 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002676static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2677 struct xdr_stream *xdr,
2678 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002679{
Andy Adamsonfc931582009-04-01 09:22:31 -04002680 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002681 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002682 };
2683
Chuck Lever9f06c712010-12-14 14:59:18 +00002684 encode_compound_hdr(xdr, req, &hdr);
2685 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002686 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002687}
2688
2689/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002690 * a DESTROY_SESSION request
2691 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002692static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2693 struct xdr_stream *xdr,
2694 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002695{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002696 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002697 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002698 };
2699
Chuck Lever9f06c712010-12-14 14:59:18 +00002700 encode_compound_hdr(xdr, req, &hdr);
2701 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002702 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002703}
2704
2705/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002706 * a SEQUENCE request
2707 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002708static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2709 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002710{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002711 struct compound_hdr hdr = {
2712 .minorversion = nfs4_xdr_minorversion(args),
2713 };
2714
Chuck Lever9f06c712010-12-14 14:59:18 +00002715 encode_compound_hdr(xdr, req, &hdr);
2716 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002717 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002718}
2719
2720/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002721 * a GET_LEASE_TIME request
2722 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002723static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2724 struct xdr_stream *xdr,
2725 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002726{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002727 struct compound_hdr hdr = {
2728 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2729 };
2730 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2731
Chuck Lever9f06c712010-12-14 14:59:18 +00002732 encode_compound_hdr(xdr, req, &hdr);
2733 encode_sequence(xdr, &args->la_seq_args, &hdr);
2734 encode_putrootfh(xdr, &hdr);
2735 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002736 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002737}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002738
2739/*
2740 * a RECLAIM_COMPLETE request
2741 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002742static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2743 struct xdr_stream *xdr,
2744 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002745{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002746 struct compound_hdr hdr = {
2747 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2748 };
2749
Chuck Lever9f06c712010-12-14 14:59:18 +00002750 encode_compound_hdr(xdr, req, &hdr);
2751 encode_sequence(xdr, &args->seq_args, &hdr);
2752 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002753 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002754}
2755
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002756/*
2757 * Encode GETDEVICEINFO request
2758 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002759static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2760 struct xdr_stream *xdr,
2761 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002762{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002763 struct compound_hdr hdr = {
2764 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2765 };
2766
Chuck Lever9f06c712010-12-14 14:59:18 +00002767 encode_compound_hdr(xdr, req, &hdr);
2768 encode_sequence(xdr, &args->seq_args, &hdr);
2769 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002770
2771 /* set up reply kvec. Subtract notification bitmap max size (2)
2772 * so that notification bitmap is put in xdr_buf tail */
2773 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2774 args->pdev->pages, args->pdev->pgbase,
2775 args->pdev->pglen);
2776
2777 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002778}
2779
2780/*
2781 * Encode LAYOUTGET request
2782 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002783static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2784 struct xdr_stream *xdr,
2785 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002786{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002787 struct compound_hdr hdr = {
2788 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2789 };
2790
Chuck Lever9f06c712010-12-14 14:59:18 +00002791 encode_compound_hdr(xdr, req, &hdr);
2792 encode_sequence(xdr, &args->seq_args, &hdr);
2793 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2794 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002795
2796 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2797 args->layout.pages, 0, args->layout.pglen);
2798
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002799 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002800}
Andy Adamson863a3c62011-03-23 13:27:54 +00002801
2802/*
2803 * Encode LAYOUTCOMMIT request
2804 */
Benny Halevycbe82602011-05-22 19:52:37 +03002805static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2806 struct xdr_stream *xdr,
2807 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002808{
Benny Halevyac7db722011-05-22 19:53:48 +03002809 struct nfs4_layoutcommit_data *data =
2810 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002811 struct compound_hdr hdr = {
2812 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2813 };
2814
2815 encode_compound_hdr(xdr, req, &hdr);
2816 encode_sequence(xdr, &args->seq_args, &hdr);
2817 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002818 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002819 encode_getfattr(xdr, args->bitmask, &hdr);
2820 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002821}
2822
2823/*
2824 * Encode LAYOUTRETURN request
2825 */
2826static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2827 struct xdr_stream *xdr,
2828 struct nfs4_layoutreturn_args *args)
2829{
2830 struct compound_hdr hdr = {
2831 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2832 };
2833
2834 encode_compound_hdr(xdr, req, &hdr);
2835 encode_sequence(xdr, &args->seq_args, &hdr);
2836 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2837 encode_layoutreturn(xdr, args, &hdr);
2838 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002839}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002840
2841/*
2842 * Encode SECINFO_NO_NAME request
2843 */
2844static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2845 struct xdr_stream *xdr,
2846 struct nfs41_secinfo_no_name_args *args)
2847{
2848 struct compound_hdr hdr = {
2849 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2850 };
2851
2852 encode_compound_hdr(xdr, req, &hdr);
2853 encode_sequence(xdr, &args->seq_args, &hdr);
2854 encode_putrootfh(xdr, &hdr);
2855 encode_secinfo_no_name(xdr, args, &hdr);
2856 encode_nops(&hdr);
2857 return 0;
2858}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002859
2860/*
2861 * Encode TEST_STATEID request
2862 */
2863static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2864 struct xdr_stream *xdr,
2865 struct nfs41_test_stateid_args *args)
2866{
2867 struct compound_hdr hdr = {
2868 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2869 };
2870
2871 encode_compound_hdr(xdr, req, &hdr);
2872 encode_sequence(xdr, &args->seq_args, &hdr);
2873 encode_test_stateid(xdr, args, &hdr);
2874 encode_nops(&hdr);
2875}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002876#endif /* CONFIG_NFS_V4_1 */
2877
Benny Halevy686841b2009-08-14 17:19:48 +03002878static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2879{
2880 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2881 "Remaining buffer length is %tu words.\n",
2882 func, xdr->end - xdr->p);
2883}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884
Trond Myklebust683b57b2006-06-09 09:34:22 -04002885static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886{
Al Viro8687b632006-10-19 23:28:48 -07002887 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888
Benny Halevyc0eae662009-08-14 17:20:14 +03002889 p = xdr_inline_decode(xdr, 4);
2890 if (unlikely(!p))
2891 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002892 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002893 p = xdr_inline_decode(xdr, *len);
2894 if (unlikely(!p))
2895 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 *string = (char *)p;
2897 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002898out_overflow:
2899 print_overflow_msg(__func__, xdr);
2900 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901}
2902
2903static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2904{
Al Viro8687b632006-10-19 23:28:48 -07002905 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906
Benny Halevyc0eae662009-08-14 17:20:14 +03002907 p = xdr_inline_decode(xdr, 8);
2908 if (unlikely(!p))
2909 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002910 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002911 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002912
Benny Halevyc0eae662009-08-14 17:20:14 +03002913 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2914 if (unlikely(!p))
2915 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 hdr->tag = (char *)p;
2917 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002918 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002919 if (unlikely(hdr->nops < 1))
2920 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002922out_overflow:
2923 print_overflow_msg(__func__, xdr);
2924 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925}
2926
2927static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2928{
Al Viro8687b632006-10-19 23:28:48 -07002929 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 uint32_t opnum;
2931 int32_t nfserr;
2932
Benny Halevyc0eae662009-08-14 17:20:14 +03002933 p = xdr_inline_decode(xdr, 8);
2934 if (unlikely(!p))
2935 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002936 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002938 dprintk("nfs: Server returned operation"
2939 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 opnum, expected);
2941 return -EIO;
2942 }
Benny Halevycccddf42009-08-14 17:20:19 +03002943 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002945 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002947out_overflow:
2948 print_overflow_msg(__func__, xdr);
2949 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950}
2951
2952/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002953static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954{
Al Viro8687b632006-10-19 23:28:48 -07002955 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002956 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 char *str;
2958
Benny Halevyc0eae662009-08-14 17:20:14 +03002959 p = xdr_inline_decode(xdr, 12);
2960 if (likely(p))
2961 return decode_opaque_inline(xdr, &strlen, &str);
2962 print_overflow_msg(__func__, xdr);
2963 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964}
2965
2966static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2967{
Al Viro8687b632006-10-19 23:28:48 -07002968 uint32_t bmlen;
2969 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970
Benny Halevyc0eae662009-08-14 17:20:14 +03002971 p = xdr_inline_decode(xdr, 4);
2972 if (unlikely(!p))
2973 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002974 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
2976 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002977 p = xdr_inline_decode(xdr, (bmlen << 2));
2978 if (unlikely(!p))
2979 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002981 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002983 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 }
2985 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002986out_overflow:
2987 print_overflow_msg(__func__, xdr);
2988 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989}
2990
Al Viro8687b632006-10-19 23:28:48 -07002991static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992{
Al Viro8687b632006-10-19 23:28:48 -07002993 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994
Benny Halevyc0eae662009-08-14 17:20:14 +03002995 p = xdr_inline_decode(xdr, 4);
2996 if (unlikely(!p))
2997 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002998 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 *savep = xdr->p;
3000 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003001out_overflow:
3002 print_overflow_msg(__func__, xdr);
3003 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004}
3005
3006static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3007{
3008 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003009 int ret;
3010 ret = decode_attr_bitmap(xdr, bitmask);
3011 if (unlikely(ret < 0))
3012 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3014 } else
3015 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03003016 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 return 0;
3018}
3019
3020static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3021{
Al Viro8687b632006-10-19 23:28:48 -07003022 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003023 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024
3025 *type = 0;
3026 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3027 return -EIO;
3028 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003029 p = xdr_inline_decode(xdr, 4);
3030 if (unlikely(!p))
3031 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003032 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003034 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 return -EIO;
3036 }
3037 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003038 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003040 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003041 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003042out_overflow:
3043 print_overflow_msg(__func__, xdr);
3044 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045}
3046
3047static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3048{
Al Viro8687b632006-10-19 23:28:48 -07003049 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003050 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051
3052 *change = 0;
3053 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3054 return -EIO;
3055 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003056 p = xdr_inline_decode(xdr, 8);
3057 if (unlikely(!p))
3058 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003059 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003061 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003063 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003065 return ret;
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_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3072{
Al Viro8687b632006-10-19 23:28:48 -07003073 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003074 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075
3076 *size = 0;
3077 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3078 return -EIO;
3079 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
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, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003085 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003087 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003088 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003089out_overflow:
3090 print_overflow_msg(__func__, xdr);
3091 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092}
3093
3094static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3095{
Al Viro8687b632006-10-19 23:28:48 -07003096 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097
3098 *res = 0;
3099 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3100 return -EIO;
3101 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003102 p = xdr_inline_decode(xdr, 4);
3103 if (unlikely(!p))
3104 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003105 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3107 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003108 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003110out_overflow:
3111 print_overflow_msg(__func__, xdr);
3112 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113}
3114
3115static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3116{
Al Viro8687b632006-10-19 23:28:48 -07003117 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118
3119 *res = 0;
3120 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3121 return -EIO;
3122 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003123 p = xdr_inline_decode(xdr, 4);
3124 if (unlikely(!p))
3125 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003126 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3128 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003129 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003131out_overflow:
3132 print_overflow_msg(__func__, xdr);
3133 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134}
3135
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003136static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137{
Al Viro8687b632006-10-19 23:28:48 -07003138 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003139 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140
3141 fsid->major = 0;
3142 fsid->minor = 0;
3143 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3144 return -EIO;
3145 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003146 p = xdr_inline_decode(xdr, 16);
3147 if (unlikely(!p))
3148 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003149 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003150 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003152 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003154 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 (unsigned long long)fsid->major,
3156 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003157 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003158out_overflow:
3159 print_overflow_msg(__func__, xdr);
3160 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161}
3162
3163static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3164{
Al Viro8687b632006-10-19 23:28:48 -07003165 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166
3167 *res = 60;
3168 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3169 return -EIO;
3170 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003171 p = xdr_inline_decode(xdr, 4);
3172 if (unlikely(!p))
3173 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003174 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3176 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003177 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003179out_overflow:
3180 print_overflow_msg(__func__, xdr);
3181 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182}
3183
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003184static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003185{
3186 __be32 *p;
3187
3188 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3189 return -EIO;
3190 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3191 p = xdr_inline_decode(xdr, 4);
3192 if (unlikely(!p))
3193 goto out_overflow;
3194 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003195 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003196 }
3197 return 0;
3198out_overflow:
3199 print_overflow_msg(__func__, xdr);
3200 return -EIO;
3201}
3202
3203static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3204{
3205 __be32 *p;
3206 int len;
3207
Trond Myklebust7ad07352010-10-23 15:34:20 -04003208 if (fh != NULL)
3209 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003210
3211 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3212 return -EIO;
3213 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3214 p = xdr_inline_decode(xdr, 4);
3215 if (unlikely(!p))
3216 goto out_overflow;
3217 len = be32_to_cpup(p);
3218 if (len > NFS4_FHSIZE)
3219 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003220 p = xdr_inline_decode(xdr, len);
3221 if (unlikely(!p))
3222 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003223 if (fh != NULL) {
3224 memcpy(fh->data, p, len);
3225 fh->size = len;
3226 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003227 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3228 }
3229 return 0;
3230out_overflow:
3231 print_overflow_msg(__func__, xdr);
3232 return -EIO;
3233}
3234
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3236{
Al Viro8687b632006-10-19 23:28:48 -07003237 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
3239 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3240 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3241 return -EIO;
3242 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003243 p = xdr_inline_decode(xdr, 4);
3244 if (unlikely(!p))
3245 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003246 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3248 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003249 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003251out_overflow:
3252 print_overflow_msg(__func__, xdr);
3253 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254}
3255
3256static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3257{
Al Viro8687b632006-10-19 23:28:48 -07003258 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003259 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260
3261 *fileid = 0;
3262 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3263 return -EIO;
3264 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003265 p = xdr_inline_decode(xdr, 8);
3266 if (unlikely(!p))
3267 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003268 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003270 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003272 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003273 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003274out_overflow:
3275 print_overflow_msg(__func__, xdr);
3276 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277}
3278
Manoj Naik99baf622006-06-09 09:34:24 -04003279static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3280{
Al Viro8687b632006-10-19 23:28:48 -07003281 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003282 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003283
3284 *fileid = 0;
3285 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3286 return -EIO;
3287 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003288 p = xdr_inline_decode(xdr, 8);
3289 if (unlikely(!p))
3290 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003291 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003292 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003293 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003294 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003295 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003296 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003297out_overflow:
3298 print_overflow_msg(__func__, xdr);
3299 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003300}
3301
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3303{
Al Viro8687b632006-10-19 23:28:48 -07003304 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 int status = 0;
3306
3307 *res = 0;
3308 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3309 return -EIO;
3310 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003311 p = xdr_inline_decode(xdr, 8);
3312 if (unlikely(!p))
3313 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003314 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3316 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003317 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003319out_overflow:
3320 print_overflow_msg(__func__, xdr);
3321 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322}
3323
3324static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3325{
Al Viro8687b632006-10-19 23:28:48 -07003326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 int status = 0;
3328
3329 *res = 0;
3330 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3331 return -EIO;
3332 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003333 p = xdr_inline_decode(xdr, 8);
3334 if (unlikely(!p))
3335 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003336 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3338 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003339 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003341out_overflow:
3342 print_overflow_msg(__func__, xdr);
3343 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344}
3345
3346static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3347{
Al Viro8687b632006-10-19 23:28:48 -07003348 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 int status = 0;
3350
3351 *res = 0;
3352 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3353 return -EIO;
3354 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003355 p = xdr_inline_decode(xdr, 8);
3356 if (unlikely(!p))
3357 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003358 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3360 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003361 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003363out_overflow:
3364 print_overflow_msg(__func__, xdr);
3365 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366}
3367
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003368static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3369{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003370 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003371 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003372 int status = 0;
3373
Benny Halevyc0eae662009-08-14 17:20:14 +03003374 p = xdr_inline_decode(xdr, 4);
3375 if (unlikely(!p))
3376 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003377 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003378 if (n == 0)
3379 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003380 dprintk("path ");
3381 path->ncomponents = 0;
3382 while (path->ncomponents < n) {
3383 struct nfs4_string *component = &path->components[path->ncomponents];
3384 status = decode_opaque_inline(xdr, &component->len, &component->data);
3385 if (unlikely(status != 0))
3386 goto out_eio;
3387 if (path->ncomponents != n)
3388 dprintk("/");
3389 dprintk("%s", component->data);
3390 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3391 path->ncomponents++;
3392 else {
3393 dprintk("cannot parse %d components in path\n", n);
3394 goto out_eio;
3395 }
3396 }
3397out:
3398 dprintk("\n");
3399 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003400root_path:
3401/* a root pathname is sent as a zero component4 */
3402 path->ncomponents = 1;
3403 path->components[0].len=0;
3404 path->components[0].data=NULL;
3405 dprintk("path /\n");
3406 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003407out_eio:
3408 dprintk(" status %d", status);
3409 status = -EIO;
3410 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003411out_overflow:
3412 print_overflow_msg(__func__, xdr);
3413 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003414}
3415
3416static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003417{
3418 int n;
Al Viro8687b632006-10-19 23:28:48 -07003419 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003420 int status = -EIO;
3421
3422 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3423 goto out;
3424 status = 0;
3425 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3426 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003427 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003428 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003429 if (unlikely(status != 0))
3430 goto out;
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 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003435 if (n <= 0)
3436 goto out_eio;
3437 res->nlocations = 0;
3438 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003439 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003440 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003441
Benny Halevyc0eae662009-08-14 17:20:14 +03003442 p = xdr_inline_decode(xdr, 4);
3443 if (unlikely(!p))
3444 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003445 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003446
3447 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003448 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003449 while (loc->nservers < m) {
3450 struct nfs4_string *server = &loc->servers[loc->nservers];
3451 status = decode_opaque_inline(xdr, &server->len, &server->data);
3452 if (unlikely(status != 0))
3453 goto out_eio;
3454 dprintk("%s ", server->data);
3455 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3456 loc->nservers++;
3457 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003458 unsigned int i;
3459 dprintk("%s: using first %u of %u servers "
3460 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003461 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003462 NFS4_FS_LOCATION_MAXSERVERS,
3463 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003464 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003465 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003466 char *data;
3467 status = decode_opaque_inline(xdr, &len, &data);
3468 if (unlikely(status != 0))
3469 goto out_eio;
3470 }
3471 }
3472 }
3473 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003474 if (unlikely(status != 0))
3475 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003476 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003477 res->nlocations++;
3478 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003479 if (res->nlocations != 0)
3480 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003481out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003482 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003483 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003484out_overflow:
3485 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003486out_eio:
3487 status = -EIO;
3488 goto out;
3489}
3490
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3492{
Al Viro8687b632006-10-19 23:28:48 -07003493 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 int status = 0;
3495
3496 *res = 0;
3497 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3498 return -EIO;
3499 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003500 p = xdr_inline_decode(xdr, 8);
3501 if (unlikely(!p))
3502 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003503 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3505 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003506 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003508out_overflow:
3509 print_overflow_msg(__func__, xdr);
3510 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511}
3512
3513static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3514{
Al Viro8687b632006-10-19 23:28:48 -07003515 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 int status = 0;
3517
3518 *maxlink = 1;
3519 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3520 return -EIO;
3521 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003522 p = xdr_inline_decode(xdr, 4);
3523 if (unlikely(!p))
3524 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003525 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3527 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003528 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003530out_overflow:
3531 print_overflow_msg(__func__, xdr);
3532 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533}
3534
3535static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3536{
Al Viro8687b632006-10-19 23:28:48 -07003537 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538 int status = 0;
3539
3540 *maxname = 1024;
3541 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3542 return -EIO;
3543 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003544 p = xdr_inline_decode(xdr, 4);
3545 if (unlikely(!p))
3546 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003547 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3549 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003550 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003552out_overflow:
3553 print_overflow_msg(__func__, xdr);
3554 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555}
3556
3557static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3558{
Al Viro8687b632006-10-19 23:28:48 -07003559 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 int status = 0;
3561
3562 *res = 1024;
3563 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3564 return -EIO;
3565 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3566 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003567 p = xdr_inline_decode(xdr, 8);
3568 if (unlikely(!p))
3569 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003570 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 if (maxread > 0x7FFFFFFF)
3572 maxread = 0x7FFFFFFF;
3573 *res = (uint32_t)maxread;
3574 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3575 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003576 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003578out_overflow:
3579 print_overflow_msg(__func__, xdr);
3580 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581}
3582
3583static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3584{
Al Viro8687b632006-10-19 23:28:48 -07003585 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 int status = 0;
3587
3588 *res = 1024;
3589 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3590 return -EIO;
3591 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3592 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003593 p = xdr_inline_decode(xdr, 8);
3594 if (unlikely(!p))
3595 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003596 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 if (maxwrite > 0x7FFFFFFF)
3598 maxwrite = 0x7FFFFFFF;
3599 *res = (uint32_t)maxwrite;
3600 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3601 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003602 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003604out_overflow:
3605 print_overflow_msg(__func__, xdr);
3606 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607}
3608
Trond Myklebustbca79472009-03-11 14:10:26 -04003609static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610{
Trond Myklebustbca79472009-03-11 14:10:26 -04003611 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003612 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003613 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614
3615 *mode = 0;
3616 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3617 return -EIO;
3618 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003619 p = xdr_inline_decode(xdr, 4);
3620 if (unlikely(!p))
3621 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003622 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003623 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003625 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003627 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003628 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003629out_overflow:
3630 print_overflow_msg(__func__, xdr);
3631 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632}
3633
3634static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3635{
Al Viro8687b632006-10-19 23:28:48 -07003636 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003637 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638
3639 *nlink = 1;
3640 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3641 return -EIO;
3642 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003643 p = xdr_inline_decode(xdr, 4);
3644 if (unlikely(!p))
3645 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003646 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003648 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003650 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003651 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003652out_overflow:
3653 print_overflow_msg(__func__, xdr);
3654 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655}
3656
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003657static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003658 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659{
Al Viro8687b632006-10-19 23:28:48 -07003660 uint32_t len;
3661 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003662 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663
3664 *uid = -2;
3665 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3666 return -EIO;
3667 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003668 p = xdr_inline_decode(xdr, 4);
3669 if (unlikely(!p))
3670 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003671 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003672 p = xdr_inline_decode(xdr, len);
3673 if (unlikely(!p))
3674 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003675 if (!may_sleep) {
3676 /* do nothing */
3677 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003678 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003679 ret = NFS_ATTR_FATTR_OWNER;
3680 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003682 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003684 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003685 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3687 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003688 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003689 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003690out_overflow:
3691 print_overflow_msg(__func__, xdr);
3692 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693}
3694
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003695static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003696 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697{
Al Viro8687b632006-10-19 23:28:48 -07003698 uint32_t len;
3699 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003700 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701
3702 *gid = -2;
3703 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3704 return -EIO;
3705 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003706 p = xdr_inline_decode(xdr, 4);
3707 if (unlikely(!p))
3708 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003709 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003710 p = xdr_inline_decode(xdr, len);
3711 if (unlikely(!p))
3712 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003713 if (!may_sleep) {
3714 /* do nothing */
3715 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003716 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003717 ret = NFS_ATTR_FATTR_GROUP;
3718 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003720 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003722 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003723 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3725 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003726 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003727 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003728out_overflow:
3729 print_overflow_msg(__func__, xdr);
3730 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731}
3732
3733static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3734{
Al Viro8687b632006-10-19 23:28:48 -07003735 uint32_t major = 0, minor = 0;
3736 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003737 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738
3739 *rdev = MKDEV(0,0);
3740 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3741 return -EIO;
3742 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3743 dev_t tmp;
3744
Benny Halevyc0eae662009-08-14 17:20:14 +03003745 p = xdr_inline_decode(xdr, 8);
3746 if (unlikely(!p))
3747 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003748 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003749 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 tmp = MKDEV(major, minor);
3751 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3752 *rdev = tmp;
3753 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003754 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003756 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003757 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003758out_overflow:
3759 print_overflow_msg(__func__, xdr);
3760 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761}
3762
3763static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3764{
Al Viro8687b632006-10-19 23:28:48 -07003765 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 int status = 0;
3767
3768 *res = 0;
3769 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3770 return -EIO;
3771 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003772 p = xdr_inline_decode(xdr, 8);
3773 if (unlikely(!p))
3774 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003775 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3777 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003778 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003780out_overflow:
3781 print_overflow_msg(__func__, xdr);
3782 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783}
3784
3785static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3786{
Al Viro8687b632006-10-19 23:28:48 -07003787 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 int status = 0;
3789
3790 *res = 0;
3791 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3792 return -EIO;
3793 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003794 p = xdr_inline_decode(xdr, 8);
3795 if (unlikely(!p))
3796 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003797 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3799 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003800 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003802out_overflow:
3803 print_overflow_msg(__func__, xdr);
3804 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805}
3806
3807static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3808{
Al Viro8687b632006-10-19 23:28:48 -07003809 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 int status = 0;
3811
3812 *res = 0;
3813 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3814 return -EIO;
3815 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003816 p = xdr_inline_decode(xdr, 8);
3817 if (unlikely(!p))
3818 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003819 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3821 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003822 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003824out_overflow:
3825 print_overflow_msg(__func__, xdr);
3826 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827}
3828
3829static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3830{
Al Viro8687b632006-10-19 23:28:48 -07003831 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003832 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833
3834 *used = 0;
3835 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3836 return -EIO;
3837 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003838 p = xdr_inline_decode(xdr, 8);
3839 if (unlikely(!p))
3840 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003841 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003843 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003845 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003847 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003848out_overflow:
3849 print_overflow_msg(__func__, xdr);
3850 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851}
3852
3853static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3854{
Al Viro8687b632006-10-19 23:28:48 -07003855 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 uint64_t sec;
3857 uint32_t nsec;
3858
Benny Halevyc0eae662009-08-14 17:20:14 +03003859 p = xdr_inline_decode(xdr, 12);
3860 if (unlikely(!p))
3861 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003862 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003863 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 time->tv_sec = (time_t)sec;
3865 time->tv_nsec = (long)nsec;
3866 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003867out_overflow:
3868 print_overflow_msg(__func__, xdr);
3869 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870}
3871
3872static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3873{
3874 int status = 0;
3875
3876 time->tv_sec = 0;
3877 time->tv_nsec = 0;
3878 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3879 return -EIO;
3880 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3881 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003882 if (status == 0)
3883 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3885 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003886 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 return status;
3888}
3889
3890static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3891{
3892 int status = 0;
3893
3894 time->tv_sec = 0;
3895 time->tv_nsec = 0;
3896 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3897 return -EIO;
3898 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3899 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003900 if (status == 0)
3901 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3903 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003904 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 return status;
3906}
3907
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003908static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3909 struct timespec *time)
3910{
3911 int status = 0;
3912
3913 time->tv_sec = 0;
3914 time->tv_nsec = 0;
3915 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3916 return -EIO;
3917 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3918 status = decode_attr_time(xdr, time);
3919 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3920 }
3921 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3922 (long)time->tv_nsec);
3923 return status;
3924}
3925
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3927{
3928 int status = 0;
3929
3930 time->tv_sec = 0;
3931 time->tv_nsec = 0;
3932 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3933 return -EIO;
3934 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3935 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003936 if (status == 0)
3937 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3939 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003940 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941 return status;
3942}
3943
Al Viro8687b632006-10-19 23:28:48 -07003944static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945{
3946 unsigned int attrwords = XDR_QUADLEN(attrlen);
3947 unsigned int nwords = xdr->p - savep;
3948
3949 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003950 dprintk("%s: server returned incorrect attribute length: "
3951 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003952 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 attrwords << 2,
3954 (attrwords < nwords) ? '<' : '>',
3955 nwords << 2);
3956 return -EIO;
3957 }
3958 return 0;
3959}
3960
3961static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3962{
Al Viro8687b632006-10-19 23:28:48 -07003963 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964
Benny Halevyc0eae662009-08-14 17:20:14 +03003965 p = xdr_inline_decode(xdr, 20);
3966 if (unlikely(!p))
3967 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003968 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003969 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003970 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003972out_overflow:
3973 print_overflow_msg(__func__, xdr);
3974 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975}
3976
3977static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3978{
Al Viro8687b632006-10-19 23:28:48 -07003979 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 uint32_t supp, acc;
3981 int status;
3982
3983 status = decode_op_hdr(xdr, OP_ACCESS);
3984 if (status)
3985 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003986 p = xdr_inline_decode(xdr, 8);
3987 if (unlikely(!p))
3988 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003989 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003990 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 access->supported = supp;
3992 access->access = acc;
3993 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003994out_overflow:
3995 print_overflow_msg(__func__, xdr);
3996 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997}
3998
Benny Halevy07d30432009-08-14 17:19:52 +03003999static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000{
Al Viro8687b632006-10-19 23:28:48 -07004001 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004002
4003 p = xdr_inline_decode(xdr, len);
4004 if (likely(p)) {
4005 memcpy(buf, p, len);
4006 return 0;
4007 }
4008 print_overflow_msg(__func__, xdr);
4009 return -EIO;
4010}
4011
4012static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4013{
4014 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015}
4016
4017static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4018{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 int status;
4020
4021 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004022 if (status != -EIO)
4023 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004024 if (!status)
4025 status = decode_stateid(xdr, &res->stateid);
4026 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027}
4028
Benny Halevydb942bb2009-08-14 17:19:56 +03004029static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4030{
4031 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032}
4033
4034static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4035{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 int status;
4037
4038 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004039 if (!status)
4040 status = decode_verifier(xdr, res->verf->verifier);
4041 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042}
4043
4044static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4045{
Al Viro8687b632006-10-19 23:28:48 -07004046 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 uint32_t bmlen;
4048 int status;
4049
4050 status = decode_op_hdr(xdr, OP_CREATE);
4051 if (status)
4052 return status;
4053 if ((status = decode_change_info(xdr, cinfo)))
4054 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004055 p = xdr_inline_decode(xdr, 4);
4056 if (unlikely(!p))
4057 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004058 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004059 p = xdr_inline_decode(xdr, bmlen << 2);
4060 if (likely(p))
4061 return 0;
4062out_overflow:
4063 print_overflow_msg(__func__, xdr);
4064 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065}
4066
4067static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4068{
Al Viro8687b632006-10-19 23:28:48 -07004069 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004070 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 int status;
4072
4073 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4074 goto xdr_error;
4075 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4076 goto xdr_error;
4077 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4078 goto xdr_error;
4079 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4080 goto xdr_error;
4081 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4082 goto xdr_error;
4083 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4084 goto xdr_error;
4085 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4086 goto xdr_error;
4087 status = verify_attr_len(xdr, savep, attrlen);
4088xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004089 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 return status;
4091}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004092
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4094{
Al Viro8687b632006-10-19 23:28:48 -07004095 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004096 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004098
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4100 goto xdr_error;
4101 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4102 goto xdr_error;
4103 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4104 goto xdr_error;
4105
4106 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4107 goto xdr_error;
4108 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4109 goto xdr_error;
4110 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4111 goto xdr_error;
4112 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4113 goto xdr_error;
4114 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4115 goto xdr_error;
4116 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4117 goto xdr_error;
4118
4119 status = verify_attr_len(xdr, savep, attrlen);
4120xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004121 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 return status;
4123}
4124
4125static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4126{
Al Viro8687b632006-10-19 23:28:48 -07004127 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004128 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004130
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4132 goto xdr_error;
4133 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4134 goto xdr_error;
4135 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4136 goto xdr_error;
4137
4138 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4139 goto xdr_error;
4140 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4141 goto xdr_error;
4142
4143 status = verify_attr_len(xdr, savep, attrlen);
4144xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004145 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 return status;
4147}
4148
Bryan Schumakerae42c702010-10-21 16:33:17 -04004149static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4150 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004151 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152{
Trond Myklebustbca79472009-03-11 14:10:26 -04004153 int status;
4154 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004155 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004156 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004158 status = decode_attr_type(xdr, bitmap, &type);
4159 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004161 fattr->mode = 0;
4162 if (status != 0) {
4163 fattr->mode |= nfs_type2fmt[type];
4164 fattr->valid |= status;
4165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004167 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4168 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004170 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004171
4172 status = decode_attr_size(xdr, bitmap, &fattr->size);
4173 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004175 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004176
4177 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4178 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004180 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004181
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004182 err = 0;
4183 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004184 if (status < 0)
4185 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004186 if (err == -NFS4ERR_WRONGSEC)
4187 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004188
4189 status = decode_attr_filehandle(xdr, bitmap, fh);
4190 if (status < 0)
4191 goto xdr_error;
4192
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004193 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4194 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004196 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004197
4198 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04004199 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004200 fattr));
4201 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004202 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004203 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004204
4205 status = decode_attr_mode(xdr, bitmap, &fmode);
4206 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004208 if (status != 0) {
4209 fattr->mode |= fmode;
4210 fattr->valid |= status;
4211 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004212
4213 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4214 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004216 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004217
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004218 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004219 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004221 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004222
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004223 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004224 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004226 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004227
4228 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4229 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004231 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004232
4233 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4234 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004236 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004237
4238 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4239 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004241 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004242
4243 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4244 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004246 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004247
4248 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4249 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004251 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004252
Trond Myklebust28331a42011-04-27 13:47:52 -04004253 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004254 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004255 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004256 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004257
Bryan Schumakerae42c702010-10-21 16:33:17 -04004258xdr_error:
4259 dprintk("%s: xdr returned %d\n", __func__, -status);
4260 return status;
4261}
4262
4263static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4264 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4265{
4266 __be32 *savep;
4267 uint32_t attrlen,
4268 bitmap[2] = {0};
4269 int status;
4270
4271 status = decode_op_hdr(xdr, OP_GETATTR);
4272 if (status < 0)
4273 goto xdr_error;
4274
4275 status = decode_attr_bitmap(xdr, bitmap);
4276 if (status < 0)
4277 goto xdr_error;
4278
4279 status = decode_attr_length(xdr, &attrlen, &savep);
4280 if (status < 0)
4281 goto xdr_error;
4282
4283 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4284 if (status < 0)
4285 goto xdr_error;
4286
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004287 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004289 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290 return status;
4291}
4292
Bryan Schumakerae42c702010-10-21 16:33:17 -04004293static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4294 const struct nfs_server *server, int may_sleep)
4295{
4296 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4297}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298
Andy Adamson504913f2010-10-20 00:17:57 -04004299/*
4300 * Decode potentially multiple layout types. Currently we only support
4301 * one layout driver per file system.
4302 */
4303static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4304 uint32_t *layouttype)
4305{
4306 uint32_t *p;
4307 int num;
4308
4309 p = xdr_inline_decode(xdr, 4);
4310 if (unlikely(!p))
4311 goto out_overflow;
4312 num = be32_to_cpup(p);
4313
4314 /* pNFS is not supported by the underlying file system */
4315 if (num == 0) {
4316 *layouttype = 0;
4317 return 0;
4318 }
4319 if (num > 1)
4320 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4321 "per filesystem not supported\n", __func__);
4322
4323 /* Decode and set first layout type, move xdr->p past unused types */
4324 p = xdr_inline_decode(xdr, num * 4);
4325 if (unlikely(!p))
4326 goto out_overflow;
4327 *layouttype = be32_to_cpup(p);
4328 return 0;
4329out_overflow:
4330 print_overflow_msg(__func__, xdr);
4331 return -EIO;
4332}
4333
4334/*
4335 * The type of file system exported.
4336 * Note we must ensure that layouttype is set in any non-error case.
4337 */
4338static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4339 uint32_t *layouttype)
4340{
4341 int status = 0;
4342
4343 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4344 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4345 return -EIO;
4346 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4347 status = decode_first_pnfs_layout_type(xdr, layouttype);
4348 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4349 } else
4350 *layouttype = 0;
4351 return status;
4352}
4353
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4355{
Al Viro8687b632006-10-19 23:28:48 -07004356 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 uint32_t attrlen, bitmap[2];
4358 int status;
4359
4360 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4361 goto xdr_error;
4362 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4363 goto xdr_error;
4364 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4365 goto xdr_error;
4366
4367 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4368
4369 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4370 goto xdr_error;
4371 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4372 goto xdr_error;
4373 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4374 goto xdr_error;
4375 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4376 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4377 goto xdr_error;
4378 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004379 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4380 if (status != 0)
4381 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004382 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4383 if (status != 0)
4384 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385
4386 status = verify_attr_len(xdr, savep, attrlen);
4387xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004388 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 return status;
4390}
4391
4392static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4393{
Al Viro8687b632006-10-19 23:28:48 -07004394 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 uint32_t len;
4396 int status;
4397
Trond Myklebust99367812007-07-17 21:52:41 -04004398 /* Zero handle first to allow comparisons */
4399 memset(fh, 0, sizeof(*fh));
4400
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 status = decode_op_hdr(xdr, OP_GETFH);
4402 if (status)
4403 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404
Benny Halevyc0eae662009-08-14 17:20:14 +03004405 p = xdr_inline_decode(xdr, 4);
4406 if (unlikely(!p))
4407 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004408 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409 if (len > NFS4_FHSIZE)
4410 return -EIO;
4411 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004412 p = xdr_inline_decode(xdr, len);
4413 if (unlikely(!p))
4414 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004415 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004417out_overflow:
4418 print_overflow_msg(__func__, xdr);
4419 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420}
4421
4422static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4423{
4424 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004425
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 status = decode_op_hdr(xdr, OP_LINK);
4427 if (status)
4428 return status;
4429 return decode_change_info(xdr, cinfo);
4430}
4431
4432/*
4433 * We create the owner, so we know a proper owner.id length is 4.
4434 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004435static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004437 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004438 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004439 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004441 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004442 if (unlikely(!p))
4443 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004444 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004445 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004446 type = be32_to_cpup(p++); /* 4 byte read */
4447 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004448 fl->fl_start = (loff_t)offset;
4449 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4450 if (length == ~(uint64_t)0)
4451 fl->fl_end = OFFSET_MAX;
4452 fl->fl_type = F_WRLCK;
4453 if (type & 1)
4454 fl->fl_type = F_RDLCK;
4455 fl->fl_pid = 0;
4456 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004457 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4458 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4459 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004460 if (likely(p))
4461 return -NFS4ERR_DENIED;
4462out_overflow:
4463 print_overflow_msg(__func__, xdr);
4464 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465}
4466
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004467static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 int status;
4470
4471 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004472 if (status == -EIO)
4473 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004475 status = decode_stateid(xdr, &res->stateid);
4476 if (unlikely(status))
4477 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004479 status = decode_lock_denied(xdr, NULL);
4480 if (res->open_seqid != NULL)
4481 nfs_increment_open_seqid(status, res->open_seqid);
4482 nfs_increment_lock_seqid(status, res->lock_seqid);
4483out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484 return status;
4485}
4486
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004487static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488{
4489 int status;
4490 status = decode_op_hdr(xdr, OP_LOCKT);
4491 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004492 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493 return status;
4494}
4495
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004496static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004498 int status;
4499
4500 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004501 if (status != -EIO)
4502 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004503 if (status == 0)
4504 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505 return status;
4506}
4507
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004508static int decode_release_lockowner(struct xdr_stream *xdr)
4509{
4510 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4511}
4512
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513static int decode_lookup(struct xdr_stream *xdr)
4514{
4515 return decode_op_hdr(xdr, OP_LOOKUP);
4516}
4517
4518/* This is too sick! */
4519static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4520{
Andy Adamson05d564f2008-12-23 16:06:15 -05004521 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522 uint32_t limit_type, nblocks, blocksize;
4523
Benny Halevyc0eae662009-08-14 17:20:14 +03004524 p = xdr_inline_decode(xdr, 12);
4525 if (unlikely(!p))
4526 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004527 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004529 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004530 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004531 break;
4532 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004533 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004534 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004535 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536 }
4537 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004538out_overflow:
4539 print_overflow_msg(__func__, xdr);
4540 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541}
4542
4543static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4544{
Andy Adamson05d564f2008-12-23 16:06:15 -05004545 __be32 *p;
4546 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004547 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548
Benny Halevyc0eae662009-08-14 17:20:14 +03004549 p = xdr_inline_decode(xdr, 4);
4550 if (unlikely(!p))
4551 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004552 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4554 res->delegation_type = 0;
4555 return 0;
4556 }
Benny Halevy07d30432009-08-14 17:19:52 +03004557 status = decode_stateid(xdr, &res->delegation);
4558 if (unlikely(status))
4559 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004560 p = xdr_inline_decode(xdr, 4);
4561 if (unlikely(!p))
4562 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004563 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004564
Linus Torvalds1da177e2005-04-16 15:20:36 -07004565 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004566 case NFS4_OPEN_DELEGATE_READ:
4567 res->delegation_type = FMODE_READ;
4568 break;
4569 case NFS4_OPEN_DELEGATE_WRITE:
4570 res->delegation_type = FMODE_WRITE|FMODE_READ;
4571 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 return -EIO;
4573 }
David Howells7539bba2006-08-22 20:06:09 -04004574 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004575out_overflow:
4576 print_overflow_msg(__func__, xdr);
4577 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004578}
4579
4580static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4581{
Andy Adamson05d564f2008-12-23 16:06:15 -05004582 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004583 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004584 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585
Andy Adamson05d564f2008-12-23 16:06:15 -05004586 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004587 if (status != -EIO)
4588 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004589 if (!status)
4590 status = decode_stateid(xdr, &res->stateid);
4591 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004592 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593
Andy Adamson05d564f2008-12-23 16:06:15 -05004594 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595
Benny Halevyc0eae662009-08-14 17:20:14 +03004596 p = xdr_inline_decode(xdr, 8);
4597 if (unlikely(!p))
4598 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004599 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004600 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004601 if (bmlen > 10)
4602 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603
Benny Halevyc0eae662009-08-14 17:20:14 +03004604 p = xdr_inline_decode(xdr, bmlen << 2);
4605 if (unlikely(!p))
4606 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004607 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4608 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004609 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004610 for (; i < NFS4_BITMAP_SIZE; i++)
4611 res->attrset[i] = 0;
4612
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 return decode_delegation(xdr, res);
4614xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004615 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004617out_overflow:
4618 print_overflow_msg(__func__, xdr);
4619 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620}
4621
4622static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4623{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 int status;
4625
Andy Adamson05d564f2008-12-23 16:06:15 -05004626 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004627 if (status != -EIO)
4628 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004629 if (!status)
4630 status = decode_stateid(xdr, &res->stateid);
4631 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632}
4633
4634static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4635{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636 int status;
4637
4638 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004639 if (status != -EIO)
4640 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004641 if (!status)
4642 status = decode_stateid(xdr, &res->stateid);
4643 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644}
4645
4646static int decode_putfh(struct xdr_stream *xdr)
4647{
4648 return decode_op_hdr(xdr, OP_PUTFH);
4649}
4650
4651static int decode_putrootfh(struct xdr_stream *xdr)
4652{
4653 return decode_op_hdr(xdr, OP_PUTROOTFH);
4654}
4655
4656static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4657{
4658 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004659 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 uint32_t count, eof, recvd, hdrlen;
4661 int status;
4662
4663 status = decode_op_hdr(xdr, OP_READ);
4664 if (status)
4665 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004666 p = xdr_inline_decode(xdr, 8);
4667 if (unlikely(!p))
4668 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004669 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004670 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004671 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672 recvd = req->rq_rcv_buf.len - hdrlen;
4673 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004674 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675 "count %u > recvd %u\n", count, recvd);
4676 count = recvd;
4677 eof = 0;
4678 }
4679 xdr_read_pages(xdr, count);
4680 res->eof = eof;
4681 res->count = count;
4682 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004683out_overflow:
4684 print_overflow_msg(__func__, xdr);
4685 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686}
4687
4688static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4689{
4690 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004692 size_t hdrlen;
4693 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004694 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695
4696 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004697 if (!status)
4698 status = decode_verifier(xdr, readdir->verifier.data);
4699 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004700 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004701 dprintk("%s: verifier = %08x:%08x\n",
4702 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004703 ((u32 *)readdir->verifier.data)[0],
4704 ((u32 *)readdir->verifier.data)[1]);
4705
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706
Benny Halevydb942bb2009-08-14 17:19:56 +03004707 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708 recvd = rcvbuf->len - hdrlen;
4709 if (pglen > recvd)
4710 pglen = recvd;
4711 xdr_read_pages(xdr, pglen);
4712
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004713
Trond Myklebustac396122010-11-15 20:26:22 -05004714 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715}
4716
4717static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4718{
4719 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4720 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004721 size_t hdrlen;
4722 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004723 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724 int status;
4725
4726 status = decode_op_hdr(xdr, OP_READLINK);
4727 if (status)
4728 return status;
4729
4730 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004731 p = xdr_inline_decode(xdr, 4);
4732 if (unlikely(!p))
4733 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004734 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004736 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 return -ENAMETOOLONG;
4738 }
4739 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4740 recvd = req->rq_rcv_buf.len - hdrlen;
4741 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004742 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743 "count %u > recvd %u\n", len, recvd);
4744 return -EIO;
4745 }
4746 xdr_read_pages(xdr, len);
4747 /*
4748 * The XDR encode routine has set things up so that
4749 * the link text will be copied directly into the
4750 * buffer. We just have to do overflow-checking,
4751 * and and null-terminate the text (the VFS expects
4752 * null-termination).
4753 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004754 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004756out_overflow:
4757 print_overflow_msg(__func__, xdr);
4758 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759}
4760
4761static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4762{
4763 int status;
4764
4765 status = decode_op_hdr(xdr, OP_REMOVE);
4766 if (status)
4767 goto out;
4768 status = decode_change_info(xdr, cinfo);
4769out:
4770 return status;
4771}
4772
4773static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4774 struct nfs4_change_info *new_cinfo)
4775{
4776 int status;
4777
4778 status = decode_op_hdr(xdr, OP_RENAME);
4779 if (status)
4780 goto out;
4781 if ((status = decode_change_info(xdr, old_cinfo)))
4782 goto out;
4783 status = decode_change_info(xdr, new_cinfo);
4784out:
4785 return status;
4786}
4787
4788static int decode_renew(struct xdr_stream *xdr)
4789{
4790 return decode_op_hdr(xdr, OP_RENEW);
4791}
4792
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004793static int
4794decode_restorefh(struct xdr_stream *xdr)
4795{
4796 return decode_op_hdr(xdr, OP_RESTOREFH);
4797}
4798
J. Bruce Fields029d1052005-06-22 17:16:22 +00004799static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4800 size_t *acl_len)
4801{
Al Viro8687b632006-10-19 23:28:48 -07004802 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004803 uint32_t attrlen,
4804 bitmap[2] = {0};
4805 struct kvec *iov = req->rq_rcv_buf.head;
4806 int status;
4807
4808 *acl_len = 0;
4809 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4810 goto out;
4811 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4812 goto out;
4813 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4814 goto out;
4815
4816 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4817 return -EIO;
4818 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004819 size_t hdrlen;
4820 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004821
4822 /* We ignore &savep and don't do consistency checks on
4823 * the attr length. Let userspace figure it out.... */
4824 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4825 recvd = req->rq_rcv_buf.len - hdrlen;
4826 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004827 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004828 " acl reply: attrlen %u > recvd %u\n",
4829 attrlen, recvd);
4830 return -EINVAL;
4831 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004832 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004833 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004834 } else
4835 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004836
4837out:
4838 return status;
4839}
4840
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841static int
4842decode_savefh(struct xdr_stream *xdr)
4843{
4844 return decode_op_hdr(xdr, OP_SAVEFH);
4845}
4846
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004847static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848{
Al Viro8687b632006-10-19 23:28:48 -07004849 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850 uint32_t bmlen;
4851 int status;
4852
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853 status = decode_op_hdr(xdr, OP_SETATTR);
4854 if (status)
4855 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004856 p = xdr_inline_decode(xdr, 4);
4857 if (unlikely(!p))
4858 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004859 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004860 p = xdr_inline_decode(xdr, bmlen << 2);
4861 if (likely(p))
4862 return 0;
4863out_overflow:
4864 print_overflow_msg(__func__, xdr);
4865 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866}
4867
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004868static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869{
Al Viro8687b632006-10-19 23:28:48 -07004870 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871 uint32_t opnum;
4872 int32_t nfserr;
4873
Benny Halevyc0eae662009-08-14 17:20:14 +03004874 p = xdr_inline_decode(xdr, 8);
4875 if (unlikely(!p))
4876 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004877 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004879 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004880 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 return -EIO;
4882 }
Benny Halevycccddf42009-08-14 17:20:19 +03004883 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004885 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4886 if (unlikely(!p))
4887 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004888 p = xdr_decode_hyper(p, &res->clientid);
4889 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 } else if (nfserr == NFSERR_CLID_INUSE) {
4891 uint32_t len;
4892
4893 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004894 p = xdr_inline_decode(xdr, 4);
4895 if (unlikely(!p))
4896 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004897 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004898 p = xdr_inline_decode(xdr, len);
4899 if (unlikely(!p))
4900 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901
4902 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004903 p = xdr_inline_decode(xdr, 4);
4904 if (unlikely(!p))
4905 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004906 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004907 p = xdr_inline_decode(xdr, len);
4908 if (unlikely(!p))
4909 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910 return -NFSERR_CLID_INUSE;
4911 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004912 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913
4914 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004915out_overflow:
4916 print_overflow_msg(__func__, xdr);
4917 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918}
4919
4920static int decode_setclientid_confirm(struct xdr_stream *xdr)
4921{
4922 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4923}
4924
4925static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4926{
Al Viro8687b632006-10-19 23:28:48 -07004927 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928 int status;
4929
4930 status = decode_op_hdr(xdr, OP_WRITE);
4931 if (status)
4932 return status;
4933
Benny Halevyc0eae662009-08-14 17:20:14 +03004934 p = xdr_inline_decode(xdr, 16);
4935 if (unlikely(!p))
4936 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004937 res->count = be32_to_cpup(p++);
4938 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004939 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004940 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004941out_overflow:
4942 print_overflow_msg(__func__, xdr);
4943 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944}
4945
4946static int decode_delegreturn(struct xdr_stream *xdr)
4947{
4948 return decode_op_hdr(xdr, OP_DELEGRETURN);
4949}
4950
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004951static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
4952{
4953 __be32 *p;
4954
4955 p = xdr_inline_decode(xdr, 4);
4956 if (unlikely(!p))
4957 goto out_overflow;
4958 flavor->gss.sec_oid4.len = be32_to_cpup(p);
4959 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
4960 goto out_err;
4961
4962 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
4963 if (unlikely(!p))
4964 goto out_overflow;
4965 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
4966
4967 p = xdr_inline_decode(xdr, 8);
4968 if (unlikely(!p))
4969 goto out_overflow;
4970 flavor->gss.qop4 = be32_to_cpup(p++);
4971 flavor->gss.service = be32_to_cpup(p);
4972
4973 return 0;
4974
4975out_overflow:
4976 print_overflow_msg(__func__, xdr);
4977 return -EIO;
4978out_err:
4979 return -EINVAL;
4980}
4981
4982static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
4983{
4984 struct nfs4_secinfo_flavor *sec_flavor;
4985 int status;
4986 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004987 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004988
4989 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04004990 if (status)
4991 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004992 p = xdr_inline_decode(xdr, 4);
4993 if (unlikely(!p))
4994 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004995
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004996 res->flavors->num_flavors = 0;
4997 num_flavors = be32_to_cpup(p);
4998
4999 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005000 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005001 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005002 break;
5003
5004 p = xdr_inline_decode(xdr, 4);
5005 if (unlikely(!p))
5006 goto out_overflow;
5007 sec_flavor->flavor = be32_to_cpup(p);
5008
5009 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005010 status = decode_secinfo_gss(xdr, sec_flavor);
5011 if (status)
5012 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005013 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005014 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005015 }
5016
Bryan Schumaker613e9012011-04-27 15:28:44 -04005017out:
5018 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005019out_overflow:
5020 print_overflow_msg(__func__, xdr);
5021 return -EIO;
5022}
5023
Benny Halevy99fe60d2009-04-01 09:22:29 -04005024#if defined(CONFIG_NFS_V4_1)
5025static int decode_exchange_id(struct xdr_stream *xdr,
5026 struct nfs41_exchange_id_res *res)
5027{
5028 __be32 *p;
5029 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005030 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005031 int status;
5032 struct nfs_client *clp = res->client;
5033
5034 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5035 if (status)
5036 return status;
5037
Benny Halevyc0eae662009-08-14 17:20:14 +03005038 p = xdr_inline_decode(xdr, 8);
5039 if (unlikely(!p))
5040 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005041 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005042 p = xdr_inline_decode(xdr, 12);
5043 if (unlikely(!p))
5044 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005045 clp->cl_seqid = be32_to_cpup(p++);
5046 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005047
5048 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005049 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005050 if (dummy != SP4_NONE)
5051 return -EIO;
5052
5053 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005054 p = xdr_inline_decode(xdr, 8);
5055 if (unlikely(!p))
5056 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005057
5058 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005059 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5060 if (unlikely(status))
5061 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005062
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005063 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005064 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5065 if (unlikely(status))
5066 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005067
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005068 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5069 return -EIO;
5070
5071 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5072 res->server_scope->server_scope_sz = dummy;
5073
Benny Halevy99fe60d2009-04-01 09:22:29 -04005074 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03005075 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5076 if (unlikely(status))
5077 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005078
5079 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005080out_overflow:
5081 print_overflow_msg(__func__, xdr);
5082 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005083}
Andy Adamsonfc931582009-04-01 09:22:31 -04005084
5085static int decode_chan_attrs(struct xdr_stream *xdr,
5086 struct nfs4_channel_attrs *attrs)
5087{
5088 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005089 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005090
Benny Halevyc0eae662009-08-14 17:20:14 +03005091 p = xdr_inline_decode(xdr, 28);
5092 if (unlikely(!p))
5093 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005094 val = be32_to_cpup(p++); /* headerpadsz */
5095 if (val)
5096 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005097 attrs->max_rqst_sz = be32_to_cpup(p++);
5098 attrs->max_resp_sz = be32_to_cpup(p++);
5099 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5100 attrs->max_ops = be32_to_cpup(p++);
5101 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005102 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005103 if (unlikely(nr_attrs > 1)) {
5104 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
5105 __func__, nr_attrs);
5106 return -EINVAL;
5107 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005108 if (nr_attrs == 1) {
5109 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5110 if (unlikely(!p))
5111 goto out_overflow;
5112 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005113 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005114out_overflow:
5115 print_overflow_msg(__func__, xdr);
5116 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005117}
5118
Benny Halevye78291e2009-08-14 17:20:00 +03005119static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5120{
5121 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005122}
5123
5124static int decode_create_session(struct xdr_stream *xdr,
5125 struct nfs41_create_session_res *res)
5126{
5127 __be32 *p;
5128 int status;
5129 struct nfs_client *clp = res->client;
5130 struct nfs4_session *session = clp->cl_session;
5131
5132 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005133 if (!status)
5134 status = decode_sessionid(xdr, &session->sess_id);
5135 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005136 return status;
5137
Andy Adamsonfc931582009-04-01 09:22:31 -04005138 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005139 p = xdr_inline_decode(xdr, 8);
5140 if (unlikely(!p))
5141 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005142 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005143 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005144
5145 /* Channel attributes */
5146 status = decode_chan_attrs(xdr, &session->fc_attrs);
5147 if (!status)
5148 status = decode_chan_attrs(xdr, &session->bc_attrs);
5149 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005150out_overflow:
5151 print_overflow_msg(__func__, xdr);
5152 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005153}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005154
5155static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5156{
5157 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5158}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005159
5160static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5161{
5162 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5163}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005164#endif /* CONFIG_NFS_V4_1 */
5165
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005166static int decode_sequence(struct xdr_stream *xdr,
5167 struct nfs4_sequence_res *res,
5168 struct rpc_rqst *rqstp)
5169{
5170#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005171 struct nfs4_sessionid id;
5172 u32 dummy;
5173 int status;
5174 __be32 *p;
5175
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005176 if (!res->sr_session)
5177 return 0;
5178
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005179 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005180 if (!status)
5181 status = decode_sessionid(xdr, &id);
5182 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005183 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005184
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005185 /*
5186 * If the server returns different values for sessionID, slotID or
5187 * sequence number, the server is looney tunes.
5188 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005189 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005190
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005191 if (memcmp(id.data, res->sr_session->sess_id.data,
5192 NFS4_MAX_SESSIONID_LEN)) {
5193 dprintk("%s Invalid session id\n", __func__);
5194 goto out_err;
5195 }
Benny Halevye78291e2009-08-14 17:20:00 +03005196
Benny Halevyc0eae662009-08-14 17:20:14 +03005197 p = xdr_inline_decode(xdr, 20);
5198 if (unlikely(!p))
5199 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005200
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005201 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005202 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005203 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005204 dprintk("%s Invalid sequence number\n", __func__);
5205 goto out_err;
5206 }
5207 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005208 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005209 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005210 dprintk("%s Invalid slot id\n", __func__);
5211 goto out_err;
5212 }
5213 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005214 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005215 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005216 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005217 /* result flags */
5218 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005219 status = 0;
5220out_err:
5221 res->sr_status = status;
5222 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005223out_overflow:
5224 print_overflow_msg(__func__, xdr);
5225 status = -EIO;
5226 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005227#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005228 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005229#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005230}
5231
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005232#if defined(CONFIG_NFS_V4_1)
5233
5234static int decode_getdeviceinfo(struct xdr_stream *xdr,
5235 struct pnfs_device *pdev)
5236{
5237 __be32 *p;
5238 uint32_t len, type;
5239 int status;
5240
5241 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5242 if (status) {
5243 if (status == -ETOOSMALL) {
5244 p = xdr_inline_decode(xdr, 4);
5245 if (unlikely(!p))
5246 goto out_overflow;
5247 pdev->mincount = be32_to_cpup(p);
5248 dprintk("%s: Min count too small. mincnt = %u\n",
5249 __func__, pdev->mincount);
5250 }
5251 return status;
5252 }
5253
5254 p = xdr_inline_decode(xdr, 8);
5255 if (unlikely(!p))
5256 goto out_overflow;
5257 type = be32_to_cpup(p++);
5258 if (type != pdev->layout_type) {
5259 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5260 __func__, pdev->layout_type, type);
5261 return -EINVAL;
5262 }
5263 /*
5264 * Get the length of the opaque device_addr4. xdr_read_pages places
5265 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5266 * and places the remaining xdr data in xdr_buf->tail
5267 */
5268 pdev->mincount = be32_to_cpup(p);
5269 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5270
5271 /* Parse notification bitmap, verifying that it is zero. */
5272 p = xdr_inline_decode(xdr, 4);
5273 if (unlikely(!p))
5274 goto out_overflow;
5275 len = be32_to_cpup(p);
5276 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005277 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005278
5279 p = xdr_inline_decode(xdr, 4 * len);
5280 if (unlikely(!p))
5281 goto out_overflow;
5282 for (i = 0; i < len; i++, p++) {
5283 if (be32_to_cpup(p)) {
5284 dprintk("%s: notifications not supported\n",
5285 __func__);
5286 return -EIO;
5287 }
5288 }
5289 }
5290 return 0;
5291out_overflow:
5292 print_overflow_msg(__func__, xdr);
5293 return -EIO;
5294}
5295
5296static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5297 struct nfs4_layoutget_res *res)
5298{
5299 __be32 *p;
5300 int status;
5301 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005302 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5303 struct kvec *iov = rcvbuf->head;
5304 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005305
5306 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5307 if (status)
5308 return status;
5309 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5310 if (unlikely(!p))
5311 goto out_overflow;
5312 res->return_on_close = be32_to_cpup(p++);
5313 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5314 layout_count = be32_to_cpup(p);
5315 if (!layout_count) {
5316 dprintk("%s: server responded with empty layout array\n",
5317 __func__);
5318 return -EINVAL;
5319 }
5320
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005321 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005322 if (unlikely(!p))
5323 goto out_overflow;
5324 p = xdr_decode_hyper(p, &res->range.offset);
5325 p = xdr_decode_hyper(p, &res->range.length);
5326 res->range.iomode = be32_to_cpup(p++);
5327 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005328 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005329
5330 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5331 __func__,
5332 (unsigned long)res->range.offset,
5333 (unsigned long)res->range.length,
5334 res->range.iomode,
5335 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005336 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005337
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005338 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5339 recvd = req->rq_rcv_buf.len - hdrlen;
5340 if (res->layoutp->len > recvd) {
5341 dprintk("NFS: server cheating in layoutget reply: "
5342 "layout len %u > recvd %u\n",
5343 res->layoutp->len, recvd);
5344 return -EINVAL;
5345 }
5346
5347 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005348
5349 if (layout_count > 1) {
5350 /* We only handle a length one array at the moment. Any
5351 * further entries are just ignored. Note that this means
5352 * the client may see a response that is less than the
5353 * minimum it requested.
5354 */
5355 dprintk("%s: server responded with %d layouts, dropping tail\n",
5356 __func__, layout_count);
5357 }
5358
5359 return 0;
5360out_overflow:
5361 print_overflow_msg(__func__, xdr);
5362 return -EIO;
5363}
Andy Adamson863a3c62011-03-23 13:27:54 +00005364
Benny Halevycbe82602011-05-22 19:52:37 +03005365static int decode_layoutreturn(struct xdr_stream *xdr,
5366 struct nfs4_layoutreturn_res *res)
5367{
5368 __be32 *p;
5369 int status;
5370
5371 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5372 if (status)
5373 return status;
5374 p = xdr_inline_decode(xdr, 4);
5375 if (unlikely(!p))
5376 goto out_overflow;
5377 res->lrs_present = be32_to_cpup(p);
5378 if (res->lrs_present)
5379 status = decode_stateid(xdr, &res->stateid);
5380 return status;
5381out_overflow:
5382 print_overflow_msg(__func__, xdr);
5383 return -EIO;
5384}
5385
Andy Adamson863a3c62011-03-23 13:27:54 +00005386static int decode_layoutcommit(struct xdr_stream *xdr,
5387 struct rpc_rqst *req,
5388 struct nfs4_layoutcommit_res *res)
5389{
5390 __be32 *p;
5391 __u32 sizechanged;
5392 int status;
5393
5394 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5395 if (status)
5396 return status;
5397
5398 p = xdr_inline_decode(xdr, 4);
5399 if (unlikely(!p))
5400 goto out_overflow;
5401 sizechanged = be32_to_cpup(p);
5402
5403 if (sizechanged) {
5404 /* throw away new size */
5405 p = xdr_inline_decode(xdr, 8);
5406 if (unlikely(!p))
5407 goto out_overflow;
5408 }
5409 return 0;
5410out_overflow:
5411 print_overflow_msg(__func__, xdr);
5412 return -EIO;
5413}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005414
5415static int decode_test_stateid(struct xdr_stream *xdr,
5416 struct nfs41_test_stateid_res *res)
5417{
5418 __be32 *p;
5419 int status;
5420 int num_res;
5421
5422 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5423 if (status)
5424 return status;
5425
5426 p = xdr_inline_decode(xdr, 4);
5427 if (unlikely(!p))
5428 goto out_overflow;
5429 num_res = be32_to_cpup(p++);
5430 if (num_res != 1)
5431 goto out;
5432
5433 p = xdr_inline_decode(xdr, 4);
5434 if (unlikely(!p))
5435 goto out_overflow;
5436 res->status = be32_to_cpup(p++);
5437 return res->status;
5438out_overflow:
5439 print_overflow_msg(__func__, xdr);
5440out:
5441 return -EIO;
5442}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005443#endif /* CONFIG_NFS_V4_1 */
5444
Linus Torvalds1da177e2005-04-16 15:20:36 -07005445/*
Benny Halevy49c25592008-12-23 16:06:16 -05005446 * END OF "GENERIC" DECODE ROUTINES.
5447 */
5448
5449/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005450 * Decode OPEN_DOWNGRADE response
5451 */
Chuck Leverbf269552010-12-14 14:59:29 +00005452static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5453 struct xdr_stream *xdr,
5454 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005455{
Andy Adamson05d564f2008-12-23 16:06:15 -05005456 struct compound_hdr hdr;
5457 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005458
Chuck Leverbf269552010-12-14 14:59:29 +00005459 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005460 if (status)
5461 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005462 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005463 if (status)
5464 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005465 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005466 if (status)
5467 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005468 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005469 if (status != 0)
5470 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005471 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005472 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005473out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005474 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005475}
5476
5477/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005478 * Decode ACCESS response
5479 */
Chuck Leverbf269552010-12-14 14:59:29 +00005480static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5481 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005482{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005483 struct compound_hdr hdr;
5484 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005485
Chuck Leverbf269552010-12-14 14:59:29 +00005486 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005487 if (status)
5488 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005489 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005490 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005491 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005492 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005493 if (status != 0)
5494 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005495 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005496 if (status != 0)
5497 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005498 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005499 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005500out:
5501 return status;
5502}
5503
5504/*
5505 * Decode LOOKUP response
5506 */
Chuck Leverbf269552010-12-14 14:59:29 +00005507static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5508 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005509{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005510 struct compound_hdr hdr;
5511 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005512
Chuck Leverbf269552010-12-14 14:59:29 +00005513 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005514 if (status)
5515 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005516 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005517 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005519 status = decode_putfh(xdr);
5520 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005521 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005522 status = decode_lookup(xdr);
5523 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005525 status = decode_getfh(xdr, res->fh);
5526 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005527 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005528 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005529 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005530out:
5531 return status;
5532}
5533
5534/*
5535 * Decode LOOKUP_ROOT response
5536 */
Chuck Leverbf269552010-12-14 14:59:29 +00005537static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5538 struct xdr_stream *xdr,
5539 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005541 struct compound_hdr hdr;
5542 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005543
Chuck Leverbf269552010-12-14 14:59:29 +00005544 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005545 if (status)
5546 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005547 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005548 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005549 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005550 status = decode_putrootfh(xdr);
5551 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005552 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005553 status = decode_getfh(xdr, res->fh);
5554 if (status == 0)
5555 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005556 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005557out:
5558 return status;
5559}
5560
5561/*
5562 * Decode REMOVE response
5563 */
Chuck Leverbf269552010-12-14 14:59:29 +00005564static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5565 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005566{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567 struct compound_hdr hdr;
5568 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005569
Chuck Leverbf269552010-12-14 14:59:29 +00005570 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005571 if (status)
5572 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005573 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005574 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005575 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005576 status = decode_putfh(xdr);
5577 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005578 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005579 status = decode_remove(xdr, &res->cinfo);
5580 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005581 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005582 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005583 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005584out:
5585 return status;
5586}
5587
5588/*
5589 * Decode RENAME response
5590 */
Chuck Leverbf269552010-12-14 14:59:29 +00005591static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5592 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005593{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005594 struct compound_hdr hdr;
5595 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005596
Chuck Leverbf269552010-12-14 14:59:29 +00005597 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005598 if (status)
5599 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005600 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005601 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005602 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005603 status = decode_putfh(xdr);
5604 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005606 status = decode_savefh(xdr);
5607 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005608 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005609 status = decode_putfh(xdr);
5610 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005612 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5613 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005614 goto out;
5615 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005616 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005617 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005618 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005619 status = decode_restorefh(xdr);
5620 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005621 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005622 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005623 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005624out:
5625 return status;
5626}
5627
5628/*
5629 * Decode LINK response
5630 */
Chuck Leverbf269552010-12-14 14:59:29 +00005631static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5632 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005633{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005634 struct compound_hdr hdr;
5635 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005636
Chuck Leverbf269552010-12-14 14:59:29 +00005637 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005638 if (status)
5639 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005640 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005641 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005642 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005643 status = decode_putfh(xdr);
5644 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005645 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005646 status = decode_savefh(xdr);
5647 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005649 status = decode_putfh(xdr);
5650 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005651 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005652 status = decode_link(xdr, &res->cinfo);
5653 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005654 goto out;
5655 /*
5656 * Note order: OP_LINK leaves the directory as the current
5657 * filehandle.
5658 */
Chuck Leverbf269552010-12-14 14:59:29 +00005659 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005660 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005661 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005662 status = decode_restorefh(xdr);
5663 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005664 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005665 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005666 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005667out:
5668 return status;
5669}
5670
5671/*
5672 * Decode CREATE response
5673 */
Chuck Leverbf269552010-12-14 14:59:29 +00005674static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5675 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005676{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005677 struct compound_hdr hdr;
5678 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005679
Chuck Leverbf269552010-12-14 14:59:29 +00005680 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005681 if (status)
5682 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005683 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005684 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005685 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005686 status = decode_putfh(xdr);
5687 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005688 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005689 status = decode_savefh(xdr);
5690 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005691 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005692 status = decode_create(xdr, &res->dir_cinfo);
5693 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005694 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005695 status = decode_getfh(xdr, res->fh);
5696 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005697 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005698 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005699 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005700 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005701 status = decode_restorefh(xdr);
5702 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005703 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005704 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005705 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005706out:
5707 return status;
5708}
5709
5710/*
5711 * Decode SYMLINK response
5712 */
Chuck Leverbf269552010-12-14 14:59:29 +00005713static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5714 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005715{
Chuck Leverbf269552010-12-14 14:59:29 +00005716 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005717}
5718
5719/*
5720 * Decode GETATTR response
5721 */
Chuck Leverbf269552010-12-14 14:59:29 +00005722static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5723 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005724{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005725 struct compound_hdr hdr;
5726 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005727
Chuck Leverbf269552010-12-14 14:59:29 +00005728 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005729 if (status)
5730 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005731 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005732 if (status)
5733 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005734 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005735 if (status)
5736 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005737 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005738 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005739out:
5740 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005741}
5742
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005743/*
5744 * Encode an SETACL request
5745 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005746static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5747 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005748{
Andy Adamson05d564f2008-12-23 16:06:15 -05005749 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005750 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005751 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005752
Chuck Lever9f06c712010-12-14 14:59:18 +00005753 encode_compound_hdr(xdr, req, &hdr);
5754 encode_sequence(xdr, &args->seq_args, &hdr);
5755 encode_putfh(xdr, args->fh, &hdr);
5756 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005757 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005758}
Andy Adamson05d564f2008-12-23 16:06:15 -05005759
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005760/*
5761 * Decode SETACL response
5762 */
5763static int
Chuck Leverbf269552010-12-14 14:59:29 +00005764nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005765 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005766{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005767 struct compound_hdr hdr;
5768 int status;
5769
Chuck Leverbf269552010-12-14 14:59:29 +00005770 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005771 if (status)
5772 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005773 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005774 if (status)
5775 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005776 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005777 if (status)
5778 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005779 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005780out:
5781 return status;
5782}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005783
5784/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005785 * Decode GETACL response
5786 */
5787static int
Chuck Leverbf269552010-12-14 14:59:29 +00005788nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005789 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005790{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005791 struct compound_hdr hdr;
5792 int status;
5793
Chuck Leverbf269552010-12-14 14:59:29 +00005794 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005795 if (status)
5796 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005797 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005798 if (status)
5799 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005800 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005801 if (status)
5802 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005803 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005804
5805out:
5806 return status;
5807}
5808
5809/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005810 * Decode CLOSE response
5811 */
Chuck Leverbf269552010-12-14 14:59:29 +00005812static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5813 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005814{
Andy Adamson05d564f2008-12-23 16:06:15 -05005815 struct compound_hdr hdr;
5816 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005817
Chuck Leverbf269552010-12-14 14:59:29 +00005818 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005819 if (status)
5820 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005821 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005822 if (status)
5823 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005824 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005825 if (status)
5826 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005827 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005828 if (status != 0)
5829 goto out;
5830 /*
5831 * Note: Server may do delete on close for this file
5832 * in which case the getattr call will fail with
5833 * an ESTALE error. Shouldn't be a problem,
5834 * though, since fattr->valid will remain unset.
5835 */
Chuck Leverbf269552010-12-14 14:59:29 +00005836 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005837 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005838out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005839 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005840}
5841
5842/*
5843 * Decode OPEN response
5844 */
Chuck Leverbf269552010-12-14 14:59:29 +00005845static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5846 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005847{
Andy Adamson05d564f2008-12-23 16:06:15 -05005848 struct compound_hdr hdr;
5849 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850
Chuck Leverbf269552010-12-14 14:59:29 +00005851 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005852 if (status)
5853 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005854 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005855 if (status)
5856 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005857 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005858 if (status)
5859 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005860 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005861 if (status)
5862 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005863 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005864 if (status)
5865 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005866 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005868 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005869 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005870 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005871 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005872 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005873 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005874 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005875out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005876 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877}
5878
5879/*
5880 * Decode OPEN_CONFIRM response
5881 */
Chuck Leverbf269552010-12-14 14:59:29 +00005882static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5883 struct xdr_stream *xdr,
5884 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885{
Andy Adamson05d564f2008-12-23 16:06:15 -05005886 struct compound_hdr hdr;
5887 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888
Chuck Leverbf269552010-12-14 14:59:29 +00005889 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005890 if (status)
5891 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005892 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005893 if (status)
5894 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005895 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005896out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005897 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005898}
5899
5900/*
5901 * Decode OPEN response
5902 */
Chuck Leverbf269552010-12-14 14:59:29 +00005903static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5904 struct xdr_stream *xdr,
5905 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005906{
Andy Adamson05d564f2008-12-23 16:06:15 -05005907 struct compound_hdr hdr;
5908 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909
Chuck Leverbf269552010-12-14 14:59:29 +00005910 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005911 if (status)
5912 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005913 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005914 if (status)
5915 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005916 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005917 if (status)
5918 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005919 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005920 if (status)
5921 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005922 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005923 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005925 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926}
5927
5928/*
5929 * Decode SETATTR response
5930 */
Chuck Leverbf269552010-12-14 14:59:29 +00005931static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5932 struct xdr_stream *xdr,
5933 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005934{
Andy Adamson05d564f2008-12-23 16:06:15 -05005935 struct compound_hdr hdr;
5936 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937
Chuck Leverbf269552010-12-14 14:59:29 +00005938 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005939 if (status)
5940 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005941 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005942 if (status)
5943 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005944 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005945 if (status)
5946 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005947 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005948 if (status)
5949 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005950 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005951 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005952out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005953 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954}
5955
5956/*
5957 * Decode LOCK response
5958 */
Chuck Leverbf269552010-12-14 14:59:29 +00005959static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5960 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005961{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005962 struct compound_hdr hdr;
5963 int status;
5964
Chuck Leverbf269552010-12-14 14:59:29 +00005965 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966 if (status)
5967 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005968 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005969 if (status)
5970 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005971 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972 if (status)
5973 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005974 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005975out:
5976 return status;
5977}
5978
5979/*
5980 * Decode LOCKT response
5981 */
Chuck Leverbf269552010-12-14 14:59:29 +00005982static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5983 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985 struct compound_hdr hdr;
5986 int status;
5987
Chuck Leverbf269552010-12-14 14:59:29 +00005988 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989 if (status)
5990 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005991 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005992 if (status)
5993 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005994 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995 if (status)
5996 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005997 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005998out:
5999 return status;
6000}
6001
6002/*
6003 * Decode LOCKU response
6004 */
Chuck Leverbf269552010-12-14 14:59:29 +00006005static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6006 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008 struct compound_hdr hdr;
6009 int status;
6010
Chuck Leverbf269552010-12-14 14:59:29 +00006011 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006012 if (status)
6013 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006014 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006015 if (status)
6016 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006017 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006018 if (status)
6019 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006020 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021out:
6022 return status;
6023}
6024
Chuck Leverbf269552010-12-14 14:59:29 +00006025static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6026 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006027{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006028 struct compound_hdr hdr;
6029 int status;
6030
Chuck Leverbf269552010-12-14 14:59:29 +00006031 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006032 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006033 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006034 return status;
6035}
6036
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037/*
6038 * Decode READLINK response
6039 */
Chuck Leverbf269552010-12-14 14:59:29 +00006040static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6041 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006042 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006044 struct compound_hdr hdr;
6045 int status;
6046
Chuck Leverbf269552010-12-14 14:59:29 +00006047 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006048 if (status)
6049 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006050 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006051 if (status)
6052 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006053 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006054 if (status)
6055 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006056 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006057out:
6058 return status;
6059}
6060
6061/*
6062 * Decode READDIR response
6063 */
Chuck Leverbf269552010-12-14 14:59:29 +00006064static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6065 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006066{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067 struct compound_hdr hdr;
6068 int status;
6069
Chuck Leverbf269552010-12-14 14:59:29 +00006070 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006071 if (status)
6072 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006073 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006074 if (status)
6075 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006076 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077 if (status)
6078 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006079 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006080out:
6081 return status;
6082}
6083
6084/*
6085 * Decode Read response
6086 */
Chuck Leverbf269552010-12-14 14:59:29 +00006087static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6088 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090 struct compound_hdr hdr;
6091 int status;
6092
Chuck Leverbf269552010-12-14 14:59:29 +00006093 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094 if (status)
6095 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006096 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006097 if (status)
6098 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006099 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100 if (status)
6101 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006102 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103 if (!status)
6104 status = res->count;
6105out:
6106 return status;
6107}
6108
6109/*
6110 * Decode WRITE response
6111 */
Chuck Leverbf269552010-12-14 14:59:29 +00006112static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6113 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006115 struct compound_hdr hdr;
6116 int status;
6117
Chuck Leverbf269552010-12-14 14:59:29 +00006118 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006119 if (status)
6120 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006121 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006122 if (status)
6123 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006124 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125 if (status)
6126 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006127 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006128 if (status)
6129 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006130 if (res->fattr)
6131 decode_getfattr(xdr, res->fattr, res->server,
6132 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133 if (!status)
6134 status = res->count;
6135out:
6136 return status;
6137}
6138
6139/*
6140 * Decode COMMIT response
6141 */
Chuck Leverbf269552010-12-14 14:59:29 +00006142static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6143 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006144{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145 struct compound_hdr hdr;
6146 int status;
6147
Chuck Leverbf269552010-12-14 14:59:29 +00006148 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006149 if (status)
6150 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006151 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006152 if (status)
6153 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006154 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155 if (status)
6156 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006157 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006158 if (status)
6159 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006160 if (res->fattr)
6161 decode_getfattr(xdr, res->fattr, res->server,
6162 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163out:
6164 return status;
6165}
6166
6167/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006168 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169 */
Chuck Leverbf269552010-12-14 14:59:29 +00006170static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006171 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173 struct compound_hdr hdr;
6174 int status;
6175
Chuck Leverbf269552010-12-14 14:59:29 +00006176 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006177 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006178 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006179 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006180 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183 return status;
6184}
6185
6186/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006187 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188 */
Chuck Leverbf269552010-12-14 14:59:29 +00006189static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006190 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 struct compound_hdr hdr;
6193 int status;
6194
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006197 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006198 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006199 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202 return status;
6203}
6204
6205/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006206 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207 */
Chuck Leverbf269552010-12-14 14:59:29 +00006208static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006209 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211 struct compound_hdr hdr;
6212 int status;
6213
Chuck Leverbf269552010-12-14 14:59:29 +00006214 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006216 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006217 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006218 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006220 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221 return status;
6222}
6223
6224/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006225 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226 */
Chuck Leverbf269552010-12-14 14:59:29 +00006227static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6228 struct xdr_stream *xdr,
6229 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006231 struct compound_hdr hdr;
6232 int status;
6233
Chuck Leverbf269552010-12-14 14:59:29 +00006234 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006235 if (status)
6236 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006237 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006238 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006240 status = decode_putfh(xdr);
6241 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006243 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006244out:
6245 return status;
6246}
6247
6248/*
6249 * Decode RENEW response
6250 */
Chuck Leverbf269552010-12-14 14:59:29 +00006251static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6252 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006254 struct compound_hdr hdr;
6255 int status;
6256
Chuck Leverbf269552010-12-14 14:59:29 +00006257 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006259 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260 return status;
6261}
6262
6263/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006264 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265 */
Chuck Leverbf269552010-12-14 14:59:29 +00006266static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6267 struct xdr_stream *xdr,
6268 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 struct compound_hdr hdr;
6271 int status;
6272
Chuck Leverbf269552010-12-14 14:59:29 +00006273 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006274 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006276 return status;
6277}
6278
6279/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006280 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006281 */
Chuck Leverbf269552010-12-14 14:59:29 +00006282static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6283 struct xdr_stream *xdr,
6284 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006286 struct compound_hdr hdr;
6287 int status;
6288
Chuck Leverbf269552010-12-14 14:59:29 +00006289 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006291 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006292 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006293 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006294 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006295 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006296 return status;
6297}
6298
6299/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006300 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006301 */
Chuck Leverbf269552010-12-14 14:59:29 +00006302static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6303 struct xdr_stream *xdr,
6304 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306 struct compound_hdr hdr;
6307 int status;
6308
Chuck Leverbf269552010-12-14 14:59:29 +00006309 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006310 if (status)
6311 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006312 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006313 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006314 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006315 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006316 if (status != 0)
6317 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006318 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006319 if (status != 0)
6320 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006321 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006322 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01006323out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 return status;
6325}
6326
Trond Myklebust683b57b2006-06-09 09:34:22 -04006327/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006328 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006329 */
Chuck Leverbf269552010-12-14 14:59:29 +00006330static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6331 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006332 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006333{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006334 struct compound_hdr hdr;
6335 int status;
6336
Chuck Leverbf269552010-12-14 14:59:29 +00006337 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006338 if (status)
6339 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006340 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006341 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006342 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006343 status = decode_putfh(xdr);
6344 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006345 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006346 status = decode_lookup(xdr);
6347 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006348 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006349 xdr_enter_page(xdr, PAGE_SIZE);
6350 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006351 res->fs_locations->server,
6352 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006353out:
6354 return status;
6355}
6356
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006357/*
6358 * Decode SECINFO response
6359 */
6360static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6361 struct xdr_stream *xdr,
6362 struct nfs4_secinfo_res *res)
6363{
6364 struct compound_hdr hdr;
6365 int status;
6366
6367 status = decode_compound_hdr(xdr, &hdr);
6368 if (status)
6369 goto out;
6370 status = decode_sequence(xdr, &res->seq_res, rqstp);
6371 if (status)
6372 goto out;
6373 status = decode_putfh(xdr);
6374 if (status)
6375 goto out;
6376 status = decode_secinfo(xdr, res);
6377 if (status)
6378 goto out;
6379out:
6380 return status;
6381}
6382
Benny Halevy99fe60d2009-04-01 09:22:29 -04006383#if defined(CONFIG_NFS_V4_1)
6384/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006385 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006386 */
Chuck Leverbf269552010-12-14 14:59:29 +00006387static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6388 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006389 void *res)
6390{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006391 struct compound_hdr hdr;
6392 int status;
6393
Chuck Leverbf269552010-12-14 14:59:29 +00006394 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006395 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006396 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006397 return status;
6398}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006399
6400/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006401 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006402 */
Chuck Leverbf269552010-12-14 14:59:29 +00006403static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6404 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006405 struct nfs41_create_session_res *res)
6406{
Andy Adamsonfc931582009-04-01 09:22:31 -04006407 struct compound_hdr hdr;
6408 int status;
6409
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006411 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006412 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006413 return status;
6414}
6415
6416/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006417 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006418 */
Chuck Leverbf269552010-12-14 14:59:29 +00006419static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6420 struct xdr_stream *xdr,
6421 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006422{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006423 struct compound_hdr hdr;
6424 int status;
6425
Chuck Leverbf269552010-12-14 14:59:29 +00006426 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006427 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006428 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006429 return status;
6430}
6431
6432/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006433 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006434 */
Chuck Leverbf269552010-12-14 14:59:29 +00006435static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6436 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006437 struct nfs4_sequence_res *res)
6438{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006439 struct compound_hdr hdr;
6440 int status;
6441
Chuck Leverbf269552010-12-14 14:59:29 +00006442 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006443 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006444 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006445 return status;
6446}
6447
6448/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006449 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006450 */
Chuck Leverbf269552010-12-14 14:59:29 +00006451static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6452 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006453 struct nfs4_get_lease_time_res *res)
6454{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006455 struct compound_hdr hdr;
6456 int status;
6457
Chuck Leverbf269552010-12-14 14:59:29 +00006458 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006459 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006460 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006461 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006462 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006463 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006464 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006465 return status;
6466}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006467
6468/*
6469 * Decode RECLAIM_COMPLETE response
6470 */
Chuck Leverbf269552010-12-14 14:59:29 +00006471static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6472 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006473 struct nfs41_reclaim_complete_res *res)
6474{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006475 struct compound_hdr hdr;
6476 int status;
6477
Chuck Leverbf269552010-12-14 14:59:29 +00006478 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006479 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006480 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006481 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006482 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006483 return status;
6484}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006485
6486/*
6487 * Decode GETDEVINFO response
6488 */
Chuck Leverbf269552010-12-14 14:59:29 +00006489static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6490 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006491 struct nfs4_getdeviceinfo_res *res)
6492{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006493 struct compound_hdr hdr;
6494 int status;
6495
Chuck Leverbf269552010-12-14 14:59:29 +00006496 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006497 if (status != 0)
6498 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006499 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006500 if (status != 0)
6501 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006502 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006503out:
6504 return status;
6505}
6506
6507/*
6508 * Decode LAYOUTGET response
6509 */
Chuck Leverbf269552010-12-14 14:59:29 +00006510static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6511 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006512 struct nfs4_layoutget_res *res)
6513{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006514 struct compound_hdr hdr;
6515 int status;
6516
Chuck Leverbf269552010-12-14 14:59:29 +00006517 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006518 if (status)
6519 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006520 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006521 if (status)
6522 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006523 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006524 if (status)
6525 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006526 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006527out:
6528 return status;
6529}
Andy Adamson863a3c62011-03-23 13:27:54 +00006530
6531/*
Benny Halevycbe82602011-05-22 19:52:37 +03006532 * Decode LAYOUTRETURN response
6533 */
6534static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6535 struct xdr_stream *xdr,
6536 struct nfs4_layoutreturn_res *res)
6537{
6538 struct compound_hdr hdr;
6539 int status;
6540
6541 status = decode_compound_hdr(xdr, &hdr);
6542 if (status)
6543 goto out;
6544 status = decode_sequence(xdr, &res->seq_res, rqstp);
6545 if (status)
6546 goto out;
6547 status = decode_putfh(xdr);
6548 if (status)
6549 goto out;
6550 status = decode_layoutreturn(xdr, res);
6551out:
6552 return status;
6553}
6554
6555/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006556 * Decode LAYOUTCOMMIT response
6557 */
6558static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6559 struct xdr_stream *xdr,
6560 struct nfs4_layoutcommit_res *res)
6561{
6562 struct compound_hdr hdr;
6563 int status;
6564
6565 status = decode_compound_hdr(xdr, &hdr);
6566 if (status)
6567 goto out;
6568 status = decode_sequence(xdr, &res->seq_res, rqstp);
6569 if (status)
6570 goto out;
6571 status = decode_putfh(xdr);
6572 if (status)
6573 goto out;
6574 status = decode_layoutcommit(xdr, rqstp, res);
6575 if (status)
6576 goto out;
6577 decode_getfattr(xdr, res->fattr, res->server,
6578 !RPC_IS_ASYNC(rqstp->rq_task));
6579out:
6580 return status;
6581}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006582
6583/*
6584 * Decode SECINFO_NO_NAME response
6585 */
6586static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6587 struct xdr_stream *xdr,
6588 struct nfs4_secinfo_res *res)
6589{
6590 struct compound_hdr hdr;
6591 int status;
6592
6593 status = decode_compound_hdr(xdr, &hdr);
6594 if (status)
6595 goto out;
6596 status = decode_sequence(xdr, &res->seq_res, rqstp);
6597 if (status)
6598 goto out;
6599 status = decode_putrootfh(xdr);
6600 if (status)
6601 goto out;
6602 status = decode_secinfo(xdr, res);
6603out:
6604 return status;
6605}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006606
6607/*
6608 * Decode TEST_STATEID response
6609 */
6610static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6611 struct xdr_stream *xdr,
6612 struct nfs41_test_stateid_res *res)
6613{
6614 struct compound_hdr hdr;
6615 int status;
6616
6617 status = decode_compound_hdr(xdr, &hdr);
6618 if (status)
6619 goto out;
6620 status = decode_sequence(xdr, &res->seq_res, rqstp);
6621 if (status)
6622 goto out;
6623 status = decode_test_stateid(xdr, res);
6624out:
6625 return status;
6626}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006627#endif /* CONFIG_NFS_V4_1 */
6628
Chuck Lever573c4e12010-12-14 14:58:11 +00006629/**
6630 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6631 * the local page cache.
6632 * @xdr: XDR stream where entry resides
6633 * @entry: buffer to fill in with entry data
6634 * @plus: boolean indicating whether this should be a readdirplus entry
6635 *
6636 * Returns zero if successful, otherwise a negative errno value is
6637 * returned.
6638 *
6639 * This function is not invoked during READDIR reply decoding, but
6640 * rather whenever an application invokes the getdents(2) system call
6641 * on a directory already in our cache.
6642 */
6643int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6644 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006645{
6646 uint32_t bitmap[2] = {0};
6647 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006648 __be32 *p = xdr_inline_decode(xdr, 4);
6649 if (unlikely(!p))
6650 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006651 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006652 p = xdr_inline_decode(xdr, 4);
6653 if (unlikely(!p))
6654 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006655 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006656 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006657 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006658 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659 }
6660
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006661 p = xdr_inline_decode(xdr, 12);
6662 if (unlikely(!p))
6663 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664 entry->prev_cookie = entry->cookie;
6665 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006666 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006667
Trond Myklebust9af8c222010-10-24 11:52:55 -04006668 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006669 if (unlikely(!p))
6670 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006671 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672
6673 /*
6674 * In case the server doesn't return an inode number,
6675 * we fake one here. (We don't use inode number 0,
6676 * since glibc seems to choke on it...)
6677 */
6678 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006679 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680
Trond Myklebust9af8c222010-10-24 11:52:55 -04006681 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006682 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006683
6684 if (decode_attr_length(xdr, &len, &p) < 0)
6685 goto out_overflow;
6686
Chuck Lever573c4e12010-12-14 14:58:11 +00006687 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6688 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006689 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006690 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6691 entry->ino = entry->fattr->mounted_on_fileid;
6692 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006693 entry->ino = entry->fattr->fileid;
6694
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006695 entry->d_type = DT_UNKNOWN;
6696 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6697 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6698
Chuck Lever573c4e12010-12-14 14:58:11 +00006699 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006700
6701out_overflow:
6702 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006703 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006704}
6705
6706/*
6707 * We need to translate between nfs status return values and
6708 * the local errno values which may not be the same.
6709 */
6710static struct {
6711 int stat;
6712 int errno;
6713} nfs_errtbl[] = {
6714 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006715 { NFS4ERR_PERM, -EPERM },
6716 { NFS4ERR_NOENT, -ENOENT },
6717 { NFS4ERR_IO, -errno_NFSERR_IO},
6718 { NFS4ERR_NXIO, -ENXIO },
6719 { NFS4ERR_ACCESS, -EACCES },
6720 { NFS4ERR_EXIST, -EEXIST },
6721 { NFS4ERR_XDEV, -EXDEV },
6722 { NFS4ERR_NOTDIR, -ENOTDIR },
6723 { NFS4ERR_ISDIR, -EISDIR },
6724 { NFS4ERR_INVAL, -EINVAL },
6725 { NFS4ERR_FBIG, -EFBIG },
6726 { NFS4ERR_NOSPC, -ENOSPC },
6727 { NFS4ERR_ROFS, -EROFS },
6728 { NFS4ERR_MLINK, -EMLINK },
6729 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6730 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6731 { NFS4ERR_DQUOT, -EDQUOT },
6732 { NFS4ERR_STALE, -ESTALE },
6733 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006734 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6735 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6736 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006737 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006738 { NFS4ERR_BADTYPE, -EBADTYPE },
6739 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006740 { NFS4ERR_SYMLINK, -ELOOP },
6741 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6742 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006743 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006744};
6745
6746/*
6747 * Convert an NFS error code to a local one.
6748 * This one is used jointly by NFSv2 and NFSv3.
6749 */
6750static int
David Howells0a8ea432006-08-22 20:06:08 -04006751nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006752{
6753 int i;
6754 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6755 if (nfs_errtbl[i].stat == stat)
6756 return nfs_errtbl[i].errno;
6757 }
6758 if (stat <= 10000 || stat > 10100) {
6759 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006760 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006761 }
6762 /* If we cannot translate the error, the recovery routines should
6763 * handle it.
6764 * Note: remaining NFSv4 error codes have values > 10000, so should
6765 * not conflict with native Linux error codes.
6766 */
Benny Halevy856dff32008-03-31 17:39:06 +03006767 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768}
6769
Linus Torvalds1da177e2005-04-16 15:20:36 -07006770#define PROC(proc, argtype, restype) \
6771[NFSPROC4_CLNT_##proc] = { \
6772 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006773 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006774 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006775 .p_arglen = NFS4_##argtype##_sz, \
6776 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006777 .p_statidx = NFSPROC4_CLNT_##proc, \
6778 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006779}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006780
6781struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006782 PROC(READ, enc_read, dec_read),
6783 PROC(WRITE, enc_write, dec_write),
6784 PROC(COMMIT, enc_commit, dec_commit),
6785 PROC(OPEN, enc_open, dec_open),
6786 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6787 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6788 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6789 PROC(CLOSE, enc_close, dec_close),
6790 PROC(SETATTR, enc_setattr, dec_setattr),
6791 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6792 PROC(RENEW, enc_renew, dec_renew),
6793 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6794 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6795 PROC(LOCK, enc_lock, dec_lock),
6796 PROC(LOCKT, enc_lockt, dec_lockt),
6797 PROC(LOCKU, enc_locku, dec_locku),
6798 PROC(ACCESS, enc_access, dec_access),
6799 PROC(GETATTR, enc_getattr, dec_getattr),
6800 PROC(LOOKUP, enc_lookup, dec_lookup),
6801 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6802 PROC(REMOVE, enc_remove, dec_remove),
6803 PROC(RENAME, enc_rename, dec_rename),
6804 PROC(LINK, enc_link, dec_link),
6805 PROC(SYMLINK, enc_symlink, dec_symlink),
6806 PROC(CREATE, enc_create, dec_create),
6807 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6808 PROC(STATFS, enc_statfs, dec_statfs),
6809 PROC(READLINK, enc_readlink, dec_readlink),
6810 PROC(READDIR, enc_readdir, dec_readdir),
6811 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6812 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6813 PROC(GETACL, enc_getacl, dec_getacl),
6814 PROC(SETACL, enc_setacl, dec_setacl),
6815 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6816 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006817 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006818#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006819 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6820 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6821 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6822 PROC(SEQUENCE, enc_sequence, dec_sequence),
6823 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6824 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6825 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6826 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00006827 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03006828 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006829 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04006830 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006831#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006832};
6833
6834struct rpc_version nfs_version4 = {
6835 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006836 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006837 .procs = nfs4_procedures
6838};
6839
6840/*
6841 * Local variables:
6842 * c-basic-offset: 8
6843 * End:
6844 */