blob: c8c069a6319be26b149360f58390e53c2a6d52ae [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 Labiaga18019752009-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
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400348#else /* CONFIG_NFS_V4_1 */
349#define encode_sequence_maxsz 0
350#define decode_sequence_maxsz 0
351#endif /* CONFIG_NFS_V4_1 */
352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
354#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
355#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400356 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400358 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400360 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400362 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400364 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400366 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400368 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400370 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400372 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400374 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400376 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400378 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400380 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400382 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400383 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400385 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400387 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400388 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400390 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400392 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400393 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400395 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400397 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400398 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400400 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400401 encode_putfh_maxsz + \
402 encode_savefh_maxsz + \
403 encode_open_maxsz + \
404 encode_getfh_maxsz + \
405 encode_getattr_maxsz + \
406 encode_restorefh_maxsz + \
407 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400409 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400410 decode_putfh_maxsz + \
411 decode_savefh_maxsz + \
412 decode_open_maxsz + \
413 decode_getfh_maxsz + \
414 decode_getattr_maxsz + \
415 decode_restorefh_maxsz + \
416 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400417#define NFS4_enc_open_confirm_sz \
418 (compound_encode_hdr_maxsz + \
419 encode_putfh_maxsz + \
420 encode_open_confirm_maxsz)
421#define NFS4_dec_open_confirm_sz \
422 (compound_decode_hdr_maxsz + \
423 decode_putfh_maxsz + \
424 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400426 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400428 encode_open_maxsz + \
429 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400431 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400433 decode_open_maxsz + \
434 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#define NFS4_enc_open_downgrade_sz \
436 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400437 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400438 encode_putfh_maxsz + \
439 encode_open_downgrade_maxsz + \
440 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_dec_open_downgrade_sz \
442 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400443 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400444 decode_putfh_maxsz + \
445 decode_open_downgrade_maxsz + \
446 decode_getattr_maxsz)
447#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400448 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400449 encode_putfh_maxsz + \
450 encode_close_maxsz + \
451 encode_getattr_maxsz)
452#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400453 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400454 decode_putfh_maxsz + \
455 decode_close_maxsz + \
456 decode_getattr_maxsz)
457#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400459 encode_putfh_maxsz + \
460 encode_setattr_maxsz + \
461 encode_getattr_maxsz)
462#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400463 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400464 decode_putfh_maxsz + \
465 decode_setattr_maxsz + \
466 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400468 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 encode_putfh_maxsz + \
470 encode_fsinfo_maxsz)
471#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400472 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 decode_putfh_maxsz + \
474 decode_fsinfo_maxsz)
475#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
476 encode_renew_maxsz)
477#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
478 decode_renew_maxsz)
479#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
480 encode_setclientid_maxsz)
481#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
482 decode_setclientid_maxsz)
483#define NFS4_enc_setclientid_confirm_sz \
484 (compound_encode_hdr_maxsz + \
485 encode_setclientid_confirm_maxsz + \
486 encode_putrootfh_maxsz + \
487 encode_fsinfo_maxsz)
488#define NFS4_dec_setclientid_confirm_sz \
489 (compound_decode_hdr_maxsz + \
490 decode_setclientid_confirm_maxsz + \
491 decode_putrootfh_maxsz + \
492 decode_fsinfo_maxsz)
493#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400494 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400496 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400498 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400500 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400502 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400504 encode_lockt_maxsz)
505#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400506 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400507 decode_putfh_maxsz + \
508 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400510 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400512 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400514 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400516 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400517#define NFS4_enc_release_lockowner_sz \
518 (compound_encode_hdr_maxsz + \
519 encode_lockowner_maxsz)
520#define NFS4_dec_release_lockowner_sz \
521 (compound_decode_hdr_maxsz + \
522 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400526 encode_access_maxsz + \
527 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400529 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400531 decode_access_maxsz + \
532 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400534 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 encode_putfh_maxsz + \
536 encode_getattr_maxsz)
537#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 decode_putfh_maxsz + \
540 decode_getattr_maxsz)
541#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 encode_putfh_maxsz + \
544 encode_lookup_maxsz + \
545 encode_getattr_maxsz + \
546 encode_getfh_maxsz)
547#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400548 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400550 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 decode_getattr_maxsz + \
552 decode_getfh_maxsz)
553#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400554 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 encode_putrootfh_maxsz + \
556 encode_getattr_maxsz + \
557 encode_getfh_maxsz)
558#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400559 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 decode_putrootfh_maxsz + \
561 decode_getattr_maxsz + \
562 decode_getfh_maxsz)
563#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400566 encode_remove_maxsz + \
567 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400569 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400571 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400572 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 encode_putfh_maxsz + \
576 encode_savefh_maxsz + \
577 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400578 encode_rename_maxsz + \
579 encode_getattr_maxsz + \
580 encode_restorefh_maxsz + \
581 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400583 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 decode_putfh_maxsz + \
585 decode_savefh_maxsz + \
586 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400587 decode_rename_maxsz + \
588 decode_getattr_maxsz + \
589 decode_restorefh_maxsz + \
590 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 encode_putfh_maxsz + \
594 encode_savefh_maxsz + \
595 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400596 encode_link_maxsz + \
597 decode_getattr_maxsz + \
598 encode_restorefh_maxsz + \
599 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400601 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 decode_putfh_maxsz + \
603 decode_savefh_maxsz + \
604 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400605 decode_link_maxsz + \
606 decode_getattr_maxsz + \
607 decode_restorefh_maxsz + \
608 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 encode_putfh_maxsz + \
612 encode_symlink_maxsz + \
613 encode_getattr_maxsz + \
614 encode_getfh_maxsz)
615#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 decode_putfh_maxsz + \
618 decode_symlink_maxsz + \
619 decode_getattr_maxsz + \
620 decode_getfh_maxsz)
621#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400624 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400626 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400628 encode_restorefh_maxsz + \
629 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400631 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400633 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400635 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400637 decode_restorefh_maxsz + \
638 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400640 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 encode_putfh_maxsz + \
642 encode_getattr_maxsz)
643#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400644 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 decode_putfh_maxsz + \
646 decode_getattr_maxsz)
647#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400648 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400650 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400652 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400654 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400656 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800657 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 encode_getattr_maxsz)
659#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800661 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 decode_getattr_maxsz)
663#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100666 encode_delegreturn_maxsz + \
667 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400669 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100670 decode_delegreturn_maxsz + \
671 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000672#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400673 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000674 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400675 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000676#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400677 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000678 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400679 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000680#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400681 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000682 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400683 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000684#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400685 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000686 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400687 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400688#define NFS4_enc_fs_locations_sz \
689 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400691 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400692 encode_lookup_maxsz + \
693 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400694#define NFS4_dec_fs_locations_sz \
695 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400697 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400698 decode_lookup_maxsz + \
699 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000700#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
701 encode_sequence_maxsz + \
702 encode_putfh_maxsz + \
703 encode_secinfo_maxsz)
704#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
705 decode_sequence_maxsz + \
706 decode_putfh_maxsz + \
707 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400708#if defined(CONFIG_NFS_V4_1)
709#define NFS4_enc_exchange_id_sz \
710 (compound_encode_hdr_maxsz + \
711 encode_exchange_id_maxsz)
712#define NFS4_dec_exchange_id_sz \
713 (compound_decode_hdr_maxsz + \
714 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400715#define NFS4_enc_create_session_sz \
716 (compound_encode_hdr_maxsz + \
717 encode_create_session_maxsz)
718#define NFS4_dec_create_session_sz \
719 (compound_decode_hdr_maxsz + \
720 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400721#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
722 encode_destroy_session_maxsz)
723#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
724 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400725#define NFS4_enc_sequence_sz \
726 (compound_decode_hdr_maxsz + \
727 encode_sequence_maxsz)
728#define NFS4_dec_sequence_sz \
729 (compound_decode_hdr_maxsz + \
730 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400731#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
732 encode_sequence_maxsz + \
733 encode_putrootfh_maxsz + \
734 encode_fsinfo_maxsz)
735#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
736 decode_sequence_maxsz + \
737 decode_putrootfh_maxsz + \
738 decode_fsinfo_maxsz)
Ricardo Labiaga18019752009-12-05 16:08:40 -0500739#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
740 encode_sequence_maxsz + \
741 encode_reclaim_complete_maxsz)
742#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
743 decode_sequence_maxsz + \
744 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400745#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
746 encode_sequence_maxsz +\
747 encode_getdeviceinfo_maxsz)
748#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
749 decode_sequence_maxsz + \
750 decode_getdeviceinfo_maxsz)
751#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
752 encode_sequence_maxsz + \
753 encode_putfh_maxsz + \
754 encode_layoutget_maxsz)
755#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
756 decode_sequence_maxsz + \
757 decode_putfh_maxsz + \
758 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000759#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
760 encode_sequence_maxsz +\
761 encode_putfh_maxsz + \
762 encode_layoutcommit_maxsz + \
763 encode_getattr_maxsz)
764#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
765 decode_sequence_maxsz + \
766 decode_putfh_maxsz + \
767 decode_layoutcommit_maxsz + \
768 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300769#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
770 encode_sequence_maxsz + \
771 encode_putfh_maxsz + \
772 encode_layoutreturn_maxsz)
773#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
774 decode_sequence_maxsz + \
775 decode_putfh_maxsz + \
776 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400777#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
778 encode_sequence_maxsz + \
779 encode_putrootfh_maxsz +\
780 encode_secinfo_no_name_maxsz)
781#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
782 decode_sequence_maxsz + \
783 decode_putrootfh_maxsz + \
784 decode_secinfo_no_name_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500785
786const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
787 compound_encode_hdr_maxsz +
788 encode_sequence_maxsz +
789 encode_putfh_maxsz +
790 encode_getattr_maxsz) *
791 XDR_UNIT);
792
793const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
794 compound_decode_hdr_maxsz +
795 decode_sequence_maxsz +
796 decode_putfh_maxsz) *
797 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400798#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Trond Myklebustbca79472009-03-11 14:10:26 -0400800static const umode_t nfs_type2fmt[] = {
801 [NF4BAD] = 0,
802 [NF4REG] = S_IFREG,
803 [NF4DIR] = S_IFDIR,
804 [NF4BLK] = S_IFBLK,
805 [NF4CHR] = S_IFCHR,
806 [NF4LNK] = S_IFLNK,
807 [NF4SOCK] = S_IFSOCK,
808 [NF4FIFO] = S_IFIFO,
809 [NF4ATTRDIR] = 0,
810 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811};
812
813struct compound_hdr {
814 int32_t status;
815 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500816 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 uint32_t taglen;
818 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400819 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400820 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821};
822
Benny Halevy13c65ce2009-08-14 17:19:25 +0300823static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
824{
825 __be32 *p = xdr_reserve_space(xdr, nbytes);
826 BUG_ON(!p);
827 return p;
828}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
831{
Al Viro8687b632006-10-19 23:28:48 -0700832 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
834 p = xdr_reserve_space(xdr, 4 + len);
835 BUG_ON(p == NULL);
836 xdr_encode_opaque(p, str, len);
837}
838
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400839static void encode_compound_hdr(struct xdr_stream *xdr,
840 struct rpc_rqst *req,
841 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842{
Al Viro8687b632006-10-19 23:28:48 -0700843 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400844 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400845
846 /* initialize running count of expected bytes in reply.
847 * NOTE: the replied tag SHOULD be the same is the one sent,
848 * but this is not required as a MUST for the server to do so. */
849 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
852 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300853 p = reserve_space(xdr, 4 + hdr->taglen + 8);
854 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300855 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500856 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300857 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500858}
859
860static void encode_nops(struct compound_hdr *hdr)
861{
Andy Adamsonfc931582009-04-01 09:22:31 -0400862 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500863 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864}
865
866static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
867{
Al Viro8687b632006-10-19 23:28:48 -0700868 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
870 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
871 BUG_ON(p == NULL);
872 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
873}
874
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500875static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
877 char owner_name[IDMAP_NAMESZ];
878 char owner_group[IDMAP_NAMESZ];
879 int owner_namelen = 0;
880 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700881 __be32 *p;
882 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 int len;
884 uint32_t bmval0 = 0;
885 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 /*
888 * We reserve enough space to write the entire attribute buffer at once.
889 * In the worst-case, this would be
890 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
891 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000892 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 */
894 len = 16;
895
896 /* Sigh */
897 if (iap->ia_valid & ATTR_SIZE)
898 len += 8;
899 if (iap->ia_valid & ATTR_MODE)
900 len += 4;
901 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800902 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400904 dprintk("nfs: couldn't resolve uid %d to string\n",
905 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 /* XXX */
907 strcpy(owner_name, "nobody");
908 owner_namelen = sizeof("nobody") - 1;
909 /* goto out; */
910 }
911 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
912 }
913 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800914 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400916 dprintk("nfs: couldn't resolve gid %d to string\n",
917 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 strcpy(owner_group, "nobody");
919 owner_grouplen = sizeof("nobody") - 1;
920 /* goto out; */
921 }
922 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
923 }
924 if (iap->ia_valid & ATTR_ATIME_SET)
925 len += 16;
926 else if (iap->ia_valid & ATTR_ATIME)
927 len += 4;
928 if (iap->ia_valid & ATTR_MTIME_SET)
929 len += 16;
930 else if (iap->ia_valid & ATTR_MTIME)
931 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300932 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934 /*
935 * We write the bitmap length now, but leave the bitmap and the attribute
936 * buffer length to be backfilled at the end of this routine.
937 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300938 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 q = p;
940 p += 3;
941
942 if (iap->ia_valid & ATTR_SIZE) {
943 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300944 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 }
946 if (iap->ia_valid & ATTR_MODE) {
947 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300948 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 }
950 if (iap->ia_valid & ATTR_UID) {
951 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300952 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 }
954 if (iap->ia_valid & ATTR_GID) {
955 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300956 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 }
958 if (iap->ia_valid & ATTR_ATIME_SET) {
959 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300960 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
961 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400962 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
963 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 }
965 else if (iap->ia_valid & ATTR_ATIME) {
966 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300967 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 }
969 if (iap->ia_valid & ATTR_MTIME_SET) {
970 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300971 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
972 *p++ = cpu_to_be32(0);
973 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
974 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 }
976 else if (iap->ia_valid & ATTR_MTIME) {
977 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300978 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 /*
982 * Now we backfill the bitmap and the attribute buffer length.
983 */
984 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400985 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 len, ((char *)p - (char *)q) + 4);
987 BUG();
988 }
989 len = (char *)p - (char *)q - 12;
990 *q++ = htonl(bmval0);
991 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300992 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995}
996
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500997static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998{
Al Viro8687b632006-10-19 23:28:48 -0700999 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
Benny Halevy13c65ce2009-08-14 17:19:25 +03001001 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001002 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001003 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001004 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001005 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006}
1007
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001008static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009{
Al Viro8687b632006-10-19 23:28:48 -07001010 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Benny Halevy13c65ce2009-08-14 17:19:25 +03001012 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001013 *p++ = cpu_to_be32(OP_CLOSE);
1014 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001015 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001016 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001017 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018}
1019
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001020static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021{
Al Viro8687b632006-10-19 23:28:48 -07001022 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001023
Benny Halevy13c65ce2009-08-14 17:19:25 +03001024 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001025 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001026 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001027 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001028 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001029 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001032static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033{
Al Viro8687b632006-10-19 23:28:48 -07001034 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001035
Benny Halevy13c65ce2009-08-14 17:19:25 +03001036 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001037 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001038 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
1040 switch (create->ftype) {
1041 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001042 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001043 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001044 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 break;
1046
1047 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001048 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001049 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001050 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 break;
1052
1053 default:
1054 break;
1055 }
1056
Benny Halevy811652b2009-08-14 17:19:34 +03001057 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001058 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001059 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001061 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062}
1063
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001064static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065{
Andy Adamson05d564f2008-12-23 16:06:15 -05001066 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
Benny Halevy13c65ce2009-08-14 17:19:25 +03001068 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001069 *p++ = cpu_to_be32(OP_GETATTR);
1070 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001071 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001072 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001073 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074}
1075
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001076static 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 -07001077{
Andy Adamson05d564f2008-12-23 16:06:15 -05001078 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Benny Halevy13c65ce2009-08-14 17:19:25 +03001080 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001081 *p++ = cpu_to_be32(OP_GETATTR);
1082 *p++ = cpu_to_be32(2);
1083 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001084 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001085 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001086 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087}
1088
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001089static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001091 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1092 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093}
1094
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001095static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001097 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1098 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099}
1100
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001101static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001102{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001103 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1104 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001105}
1106
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001107static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108{
Al Viro8687b632006-10-19 23:28:48 -07001109 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
Benny Halevy13c65ce2009-08-14 17:19:25 +03001111 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001112 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001113 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001114 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115}
1116
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001117static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118{
Al Viro8687b632006-10-19 23:28:48 -07001119 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
Benny Halevy13c65ce2009-08-14 17:19:25 +03001121 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001122 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001123 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001124 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001125 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126}
1127
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001128static inline int nfs4_lock_type(struct file_lock *fl, int block)
1129{
1130 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1131 return block ? NFS4_READW_LT : NFS4_READ_LT;
1132 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1133}
1134
1135static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1136{
1137 if (fl->fl_end == OFFSET_MAX)
1138 return ~(uint64_t)0;
1139 return fl->fl_end - fl->fl_start + 1;
1140}
1141
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001142static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1143{
1144 __be32 *p;
1145
Trond Myklebustd035c362010-12-21 10:45:27 -05001146 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001147 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001148 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001149 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001150 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001151 xdr_encode_hyper(p, lowner->id);
1152}
1153
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154/*
1155 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1156 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1157 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001158static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159{
Al Viro8687b632006-10-19 23:28:48 -07001160 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Benny Halevy13c65ce2009-08-14 17:19:25 +03001162 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001163 *p++ = cpu_to_be32(OP_LOCK);
1164 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1165 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001166 p = xdr_encode_hyper(p, args->fl->fl_start);
1167 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001168 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001169 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001170 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001171 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001172 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001173 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001174 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 }
1176 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001177 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001178 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001179 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 }
Andy Adamsond0179312008-12-23 16:06:17 -05001181 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001182 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183}
1184
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001185static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186{
Al Viro8687b632006-10-19 23:28:48 -07001187 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001189 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001190 *p++ = cpu_to_be32(OP_LOCKT);
1191 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001192 p = xdr_encode_hyper(p, args->fl->fl_start);
1193 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001194 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001195 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001196 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197}
1198
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001199static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200{
Al Viro8687b632006-10-19 23:28:48 -07001201 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
Benny Halevy13c65ce2009-08-14 17:19:25 +03001203 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001204 *p++ = cpu_to_be32(OP_LOCKU);
1205 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1206 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001207 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001208 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001209 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001210 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001211 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212}
1213
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001214static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1215{
1216 __be32 *p;
1217
1218 p = reserve_space(xdr, 4);
1219 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1220 encode_lockowner(xdr, lowner);
1221 hdr->nops++;
1222 hdr->replen += decode_release_lockowner_maxsz;
1223}
1224
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001225static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
1227 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001228 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
Benny Halevy13c65ce2009-08-14 17:19:25 +03001230 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001231 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001232 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001233 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001234 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235}
1236
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001237static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238{
Al Viro8687b632006-10-19 23:28:48 -07001239 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Benny Halevy13c65ce2009-08-14 17:19:25 +03001241 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001242 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001243 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001244 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001245 break;
1246 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001247 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001248 break;
1249 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001250 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001251 break;
1252 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001253 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 }
Benny Halevy34558512009-08-14 17:19:30 +03001255 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256}
1257
1258static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1259{
Al Viro8687b632006-10-19 23:28:48 -07001260 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 /*
1262 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1263 * owner 4 = 32
1264 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001265 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001266 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001267 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001268 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001269 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001270 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001271 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001272 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001273 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001274 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275}
1276
1277static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1278{
Al Viro8687b632006-10-19 23:28:48 -07001279 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001280 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Benny Halevy13c65ce2009-08-14 17:19:25 +03001282 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001284 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001285 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001286 encode_attrs(xdr, arg->u.attrs, arg->server);
1287 break;
1288 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001289 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001290 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001291 if (nfs4_has_persistent_session(clp)) {
1292 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1293 encode_attrs(xdr, arg->u.attrs, arg->server);
1294 } else {
1295 struct iattr dummy;
1296
1297 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1298 encode_nfs4_verifier(xdr, &arg->u.verifier);
1299 dummy.ia_valid = 0;
1300 encode_attrs(xdr, &dummy, arg->server);
1301 }
1302 } else {
1303 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1304 encode_nfs4_verifier(xdr, &arg->u.verifier);
1305 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 }
1307}
1308
1309static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1310{
Al Viro8687b632006-10-19 23:28:48 -07001311 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312
Benny Halevy13c65ce2009-08-14 17:19:25 +03001313 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001315 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001316 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001317 break;
1318 default:
1319 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001320 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001321 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 }
1323}
1324
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001325static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
Al Viro8687b632006-10-19 23:28:48 -07001327 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
Benny Halevy13c65ce2009-08-14 17:19:25 +03001329 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001331 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001332 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001333 break;
1334 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001335 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001336 break;
1337 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001338 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001339 break;
1340 default:
1341 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 }
1343}
1344
1345static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1346{
Al Viro8687b632006-10-19 23:28:48 -07001347 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Benny Halevy13c65ce2009-08-14 17:19:25 +03001349 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001350 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 encode_string(xdr, name->len, name->name);
1352}
1353
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001354static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355{
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_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 encode_delegation_type(xdr, type);
1361}
1362
1363static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1364{
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+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001368 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001369 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 encode_string(xdr, name->len, name->name);
1371}
1372
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001373static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374{
1375 encode_openhdr(xdr, arg);
1376 encode_opentype(xdr, arg);
1377 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001378 case NFS4_OPEN_CLAIM_NULL:
1379 encode_claim_null(xdr, arg->name);
1380 break;
1381 case NFS4_OPEN_CLAIM_PREVIOUS:
1382 encode_claim_previous(xdr, arg->u.delegation_type);
1383 break;
1384 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1385 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1386 break;
1387 default:
1388 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 }
Andy Adamsond0179312008-12-23 16:06:17 -05001390 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001391 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392}
1393
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001394static 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 -07001395{
Al Viro8687b632006-10-19 23:28:48 -07001396 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Benny Halevy13c65ce2009-08-14 17:19:25 +03001398 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001399 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001400 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001401 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001402 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001403 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404}
1405
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001406static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407{
Al Viro8687b632006-10-19 23:28:48 -07001408 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Benny Halevy13c65ce2009-08-14 17:19:25 +03001410 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001411 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001412 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001413 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001414 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001415 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001416 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417}
1418
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001419static void
Andy Adamsond0179312008-12-23 16:06:17 -05001420encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421{
1422 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001423 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Benny Halevy13c65ce2009-08-14 17:19:25 +03001425 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001426 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001427 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001428 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001429 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430}
1431
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001432static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433{
Andy Adamson05d564f2008-12-23 16:06:15 -05001434 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001435
Benny Halevy13c65ce2009-08-14 17:19:25 +03001436 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001437 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001438 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001439 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440}
1441
Andy Adamson89d1ea62011-03-01 01:34:09 +00001442static 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 -07001443{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001445 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Benny Halevy13c65ce2009-08-14 17:19:25 +03001447 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001449 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001450 if (zero_seqid)
1451 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001452 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 } else
Benny Halevy34558512009-08-14 17:19:30 +03001454 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455}
1456
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001457static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458{
Al Viro8687b632006-10-19 23:28:48 -07001459 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
Benny Halevy13c65ce2009-08-14 17:19:25 +03001461 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001462 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Andy Adamson89d1ea62011-03-01 01:34:09 +00001464 encode_stateid(xdr, args->context, args->lock_context,
1465 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Benny Halevy13c65ce2009-08-14 17:19:25 +03001467 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001468 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001469 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001470 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001471 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472}
1473
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001474static 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 -07001475{
Trond Myklebust28331a42011-04-27 13:47:52 -04001476 uint32_t attrs[2] = {
1477 FATTR4_WORD0_RDATTR_ERROR,
1478 FATTR4_WORD1_MOUNTED_ON_FILEID,
1479 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001480 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001481 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001483 if (readdir->plus) {
1484 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001485 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001486 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1487 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1488 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1489 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001490 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001491 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001492 /* Use mounted_on_fileid only if the server supports it */
1493 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1494 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001495
Benny Halevy13c65ce2009-08-14 17:19:25 +03001496 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001497 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001498 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001499 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001500 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001501 *p++ = cpu_to_be32(readdir->count);
1502 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001503
Benny Halevye75bc1c2009-08-14 17:18:54 +03001504 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001505 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001506 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001507 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001508 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1509 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001510 (unsigned long long)readdir->cookie,
1511 ((u32 *)readdir->verifier.data)[0],
1512 ((u32 *)readdir->verifier.data)[1],
1513 attrs[0] & readdir->bitmask[0],
1514 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515}
1516
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001517static 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 -07001518{
Al Viro8687b632006-10-19 23:28:48 -07001519 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Benny Halevy13c65ce2009-08-14 17:19:25 +03001521 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001522 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001523 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001524 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
1526
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001527static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
Al Viro8687b632006-10-19 23:28:48 -07001529 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
Benny Halevy13c65ce2009-08-14 17:19:25 +03001531 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001532 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001533 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001534 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001535 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536}
1537
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001538static 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 -07001539{
Al Viro8687b632006-10-19 23:28:48 -07001540 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Benny Halevy811652b2009-08-14 17:19:34 +03001542 p = reserve_space(xdr, 4);
1543 *p = cpu_to_be32(OP_RENAME);
1544 encode_string(xdr, oldname->len, oldname->name);
1545 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001546 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001547 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548}
1549
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001550static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
Al Viro8687b632006-10-19 23:28:48 -07001552 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Benny Halevy13c65ce2009-08-14 17:19:25 +03001554 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001555 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001556 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001557 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001558 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559}
1560
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001561static void
Andy Adamsond0179312008-12-23 16:06:17 -05001562encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001563{
Al Viro8687b632006-10-19 23:28:48 -07001564 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001565
Benny Halevy13c65ce2009-08-14 17:19:25 +03001566 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001567 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001568 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001569 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001570}
1571
Chuck Lever9f06c712010-12-14 14:59:18 +00001572static void
Andy Adamsond0179312008-12-23 16:06:17 -05001573encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001574{
Al Viro8687b632006-10-19 23:28:48 -07001575 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001576
Benny Halevy13c65ce2009-08-14 17:19:25 +03001577 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001578 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001579 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001580 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001581 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001582 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001583 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001584 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001585 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001586 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001587 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001588 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001589}
1590
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001591static void
Andy Adamsond0179312008-12-23 16:06:17 -05001592encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593{
Al Viro8687b632006-10-19 23:28:48 -07001594 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
Benny Halevy13c65ce2009-08-14 17:19:25 +03001596 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001597 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001598 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001599 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001602static 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 -07001603{
Al Viro8687b632006-10-19 23:28:48 -07001604 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001605
Benny Halevy13c65ce2009-08-14 17:19:25 +03001606 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001607 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001608 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001609 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001610 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001611 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612}
1613
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615{
Al Viro8687b632006-10-19 23:28:48 -07001616 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
Benny Halevy13c65ce2009-08-14 17:19:25 +03001618 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001619 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001620 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
1622 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001623 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001624 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1626 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001627 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001628 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001629 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001630 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001633static 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 -07001634{
Andy Adamson05d564f2008-12-23 16:06:15 -05001635 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
Benny Halevy13c65ce2009-08-14 17:19:25 +03001637 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001638 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001639 p = xdr_encode_hyper(p, arg->clientid);
1640 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001641 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001642 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643}
1644
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001645static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
Al Viro8687b632006-10-19 23:28:48 -07001647 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
Benny Halevy13c65ce2009-08-14 17:19:25 +03001649 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001650 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
Andy Adamson89d1ea62011-03-01 01:34:09 +00001652 encode_stateid(xdr, args->context, args->lock_context,
1653 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
Benny Halevy13c65ce2009-08-14 17:19:25 +03001655 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001656 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001657 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001658 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
1660 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001661 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001662 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663}
1664
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001665static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666{
Al Viro8687b632006-10-19 23:28:48 -07001667 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
Benny Halevy13c65ce2009-08-14 17:19:25 +03001669 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
Benny Halevye75bc1c2009-08-14 17:18:54 +03001671 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001672 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001673 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001674 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001676
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001677static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1678{
1679 int len = name->len;
1680 __be32 *p;
1681
1682 p = reserve_space(xdr, 8 + len);
1683 *p++ = cpu_to_be32(OP_SECINFO);
1684 xdr_encode_opaque(p, name->name, len);
1685 hdr->nops++;
1686 hdr->replen += decode_secinfo_maxsz;
1687}
1688
Benny Halevy99fe60d2009-04-01 09:22:29 -04001689#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001690/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001691static void encode_exchange_id(struct xdr_stream *xdr,
1692 struct nfs41_exchange_id_args *args,
1693 struct compound_hdr *hdr)
1694{
1695 __be32 *p;
1696
Benny Halevy13c65ce2009-08-14 17:19:25 +03001697 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001698 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001699 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001700
1701 encode_string(xdr, args->id_len, args->id);
1702
Benny Halevy13c65ce2009-08-14 17:19:25 +03001703 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001704 *p++ = cpu_to_be32(args->flags);
1705 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001706 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001707 hdr->nops++;
1708 hdr->replen += decode_exchange_id_maxsz;
1709}
Andy Adamsonfc931582009-04-01 09:22:31 -04001710
1711static void encode_create_session(struct xdr_stream *xdr,
1712 struct nfs41_create_session_args *args,
1713 struct compound_hdr *hdr)
1714{
1715 __be32 *p;
1716 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1717 uint32_t len;
1718 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001719 u32 max_resp_sz_cached;
1720
1721 /*
1722 * Assumes OPEN is the biggest non-idempotent compound.
1723 * 2 is the verifier.
1724 */
1725 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1726 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001727
Andy Adamsonfc931582009-04-01 09:22:31 -04001728 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1729 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001730
Benny Halevy13c65ce2009-08-14 17:19:25 +03001731 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001732 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001733 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001734 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1735 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001736
Andy Adamsonfc931582009-04-01 09:22:31 -04001737 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001738 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001739 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1740 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001741 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001742 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1743 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1744 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001745
1746 /* Back 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->bc_attrs.max_rqst_sz); /* max req size */
1749 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1750 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1751 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1752 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1753 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001754
Benny Halevye75bc1c2009-08-14 17:18:54 +03001755 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001756 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001757 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001758
1759 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001760 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001761 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001762 *p++ = cpu_to_be32(0); /* UID */
1763 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001764 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001765 hdr->nops++;
1766 hdr->replen += decode_create_session_maxsz;
1767}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001768
1769static void encode_destroy_session(struct xdr_stream *xdr,
1770 struct nfs4_session *session,
1771 struct compound_hdr *hdr)
1772{
1773 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001774 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001775 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001776 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001777 hdr->nops++;
1778 hdr->replen += decode_destroy_session_maxsz;
1779}
Ricardo Labiaga18019752009-12-05 16:08:40 -05001780
1781static void encode_reclaim_complete(struct xdr_stream *xdr,
1782 struct nfs41_reclaim_complete_args *args,
1783 struct compound_hdr *hdr)
1784{
1785 __be32 *p;
1786
1787 p = reserve_space(xdr, 8);
1788 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1789 *p++ = cpu_to_be32(args->one_fs);
1790 hdr->nops++;
1791 hdr->replen += decode_reclaim_complete_maxsz;
1792}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001793#endif /* CONFIG_NFS_V4_1 */
1794
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001795static void encode_sequence(struct xdr_stream *xdr,
1796 const struct nfs4_sequence_args *args,
1797 struct compound_hdr *hdr)
1798{
1799#if defined(CONFIG_NFS_V4_1)
1800 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001801 struct nfs4_slot_table *tp;
1802 struct nfs4_slot *slot;
1803 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001804
1805 if (!session)
1806 return;
1807
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001808 tp = &session->fc_slot_table;
1809
1810 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1811 slot = tp->slots + args->sa_slotid;
1812
Benny Halevy13c65ce2009-08-14 17:19:25 +03001813 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001814 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001815
1816 /*
1817 * Sessionid + seqid + slotid + max slotid + cache_this
1818 */
1819 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1820 "max_slotid=%d cache_this=%d\n",
1821 __func__,
1822 ((u32 *)session->sess_id.data)[0],
1823 ((u32 *)session->sess_id.data)[1],
1824 ((u32 *)session->sess_id.data)[2],
1825 ((u32 *)session->sess_id.data)[3],
1826 slot->seq_nr, args->sa_slotid,
1827 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001828 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001829 *p++ = cpu_to_be32(slot->seq_nr);
1830 *p++ = cpu_to_be32(args->sa_slotid);
1831 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001832 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001833 hdr->nops++;
1834 hdr->replen += decode_sequence_maxsz;
1835#endif /* CONFIG_NFS_V4_1 */
1836}
1837
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001838#ifdef CONFIG_NFS_V4_1
1839static void
1840encode_getdeviceinfo(struct xdr_stream *xdr,
1841 const struct nfs4_getdeviceinfo_args *args,
1842 struct compound_hdr *hdr)
1843{
1844 __be32 *p;
1845
1846 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1847 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1848 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1849 NFS4_DEVICEID4_SIZE);
1850 *p++ = cpu_to_be32(args->pdev->layout_type);
1851 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1852 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1853 hdr->nops++;
1854 hdr->replen += decode_getdeviceinfo_maxsz;
1855}
1856
1857static void
1858encode_layoutget(struct xdr_stream *xdr,
1859 const struct nfs4_layoutget_args *args,
1860 struct compound_hdr *hdr)
1861{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001862 __be32 *p;
1863
1864 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1865 *p++ = cpu_to_be32(OP_LAYOUTGET);
1866 *p++ = cpu_to_be32(0); /* Signal layout available */
1867 *p++ = cpu_to_be32(args->type);
1868 *p++ = cpu_to_be32(args->range.iomode);
1869 p = xdr_encode_hyper(p, args->range.offset);
1870 p = xdr_encode_hyper(p, args->range.length);
1871 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001872 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001873 *p = cpu_to_be32(args->maxcount);
1874
1875 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1876 __func__,
1877 args->type,
1878 args->range.iomode,
1879 (unsigned long)args->range.offset,
1880 (unsigned long)args->range.length,
1881 args->maxcount);
1882 hdr->nops++;
1883 hdr->replen += decode_layoutget_maxsz;
1884}
Andy Adamson863a3c62011-03-23 13:27:54 +00001885
1886static int
1887encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001888 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001889 const struct nfs4_layoutcommit_args *args,
1890 struct compound_hdr *hdr)
1891{
1892 __be32 *p;
1893
1894 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1895 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1896
Benny Halevyac7db722011-05-22 19:53:48 +03001897 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
Andy Adamson863a3c62011-03-23 13:27:54 +00001898 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1899 /* Only whole file layouts */
1900 p = xdr_encode_hyper(p, 0); /* offset */
1901 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); /* length */
1902 *p++ = cpu_to_be32(0); /* reclaim */
1903 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1904 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1905 p = xdr_encode_hyper(p, args->lastbytewritten);
1906 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1907 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001908
1909 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
1910 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
1911 NFS_I(inode)->layout, xdr, args);
1912 else {
1913 p = reserve_space(xdr, 4);
1914 *p = cpu_to_be32(0); /* no layout-type payload */
1915 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001916
1917 hdr->nops++;
1918 hdr->replen += decode_layoutcommit_maxsz;
1919 return 0;
1920}
Benny Halevycbe82602011-05-22 19:52:37 +03001921
1922static void
1923encode_layoutreturn(struct xdr_stream *xdr,
1924 const struct nfs4_layoutreturn_args *args,
1925 struct compound_hdr *hdr)
1926{
1927 __be32 *p;
1928
1929 p = reserve_space(xdr, 20);
1930 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
1931 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1932 *p++ = cpu_to_be32(args->layout_type);
1933 *p++ = cpu_to_be32(IOMODE_ANY);
1934 *p = cpu_to_be32(RETURN_FILE);
1935 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
1936 p = xdr_encode_hyper(p, 0);
1937 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1938 spin_lock(&args->inode->i_lock);
1939 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1940 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03001941 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
1942 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
1943 NFS_I(args->inode)->layout, xdr, args);
1944 } else {
1945 p = reserve_space(xdr, 4);
1946 *p = cpu_to_be32(0);
1947 }
Benny Halevycbe82602011-05-22 19:52:37 +03001948 hdr->nops++;
1949 hdr->replen += decode_layoutreturn_maxsz;
1950}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04001951
1952static int
1953encode_secinfo_no_name(struct xdr_stream *xdr,
1954 const struct nfs41_secinfo_no_name_args *args,
1955 struct compound_hdr *hdr)
1956{
1957 __be32 *p;
1958 p = reserve_space(xdr, 8);
1959 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
1960 *p++ = cpu_to_be32(args->style);
1961 hdr->nops++;
1962 hdr->replen += decode_secinfo_no_name_maxsz;
1963 return 0;
1964}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001965#endif /* CONFIG_NFS_V4_1 */
1966
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967/*
1968 * END OF "GENERIC" ENCODE ROUTINES.
1969 */
1970
Benny Halevy66cc0422009-04-01 09:22:10 -04001971static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1972{
1973#if defined(CONFIG_NFS_V4_1)
1974 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001975 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001976#endif /* CONFIG_NFS_V4_1 */
1977 return 0;
1978}
1979
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980/*
1981 * Encode an ACCESS request
1982 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001983static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1984 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001987 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
Chuck Lever9f06c712010-12-14 14:59:18 +00001990 encode_compound_hdr(xdr, req, &hdr);
1991 encode_sequence(xdr, &args->seq_args, &hdr);
1992 encode_putfh(xdr, args->fh, &hdr);
1993 encode_access(xdr, args->access, &hdr);
1994 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001995 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996}
1997
1998/*
1999 * Encode LOOKUP request
2000 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002001static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2002 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002005 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007
Chuck Lever9f06c712010-12-14 14:59:18 +00002008 encode_compound_hdr(xdr, req, &hdr);
2009 encode_sequence(xdr, &args->seq_args, &hdr);
2010 encode_putfh(xdr, args->dir_fh, &hdr);
2011 encode_lookup(xdr, args->name, &hdr);
2012 encode_getfh(xdr, &hdr);
2013 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002014 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015}
2016
2017/*
2018 * Encode LOOKUP_ROOT request
2019 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002020static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2021 struct xdr_stream *xdr,
2022 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002025 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027
Chuck Lever9f06c712010-12-14 14:59:18 +00002028 encode_compound_hdr(xdr, req, &hdr);
2029 encode_sequence(xdr, &args->seq_args, &hdr);
2030 encode_putrootfh(xdr, &hdr);
2031 encode_getfh(xdr, &hdr);
2032 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002033 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034}
2035
2036/*
2037 * Encode REMOVE request
2038 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002039static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2040 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002043 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
Chuck Lever9f06c712010-12-14 14:59:18 +00002046 encode_compound_hdr(xdr, req, &hdr);
2047 encode_sequence(xdr, &args->seq_args, &hdr);
2048 encode_putfh(xdr, args->fh, &hdr);
2049 encode_remove(xdr, &args->name, &hdr);
2050 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002051 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052}
2053
2054/*
2055 * Encode RENAME request
2056 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002057static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2058 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002061 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
Chuck Lever9f06c712010-12-14 14:59:18 +00002064 encode_compound_hdr(xdr, req, &hdr);
2065 encode_sequence(xdr, &args->seq_args, &hdr);
2066 encode_putfh(xdr, args->old_dir, &hdr);
2067 encode_savefh(xdr, &hdr);
2068 encode_putfh(xdr, args->new_dir, &hdr);
2069 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2070 encode_getfattr(xdr, args->bitmask, &hdr);
2071 encode_restorefh(xdr, &hdr);
2072 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002073 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074}
2075
2076/*
2077 * Encode LINK request
2078 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002079static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2080 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002083 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
Chuck Lever9f06c712010-12-14 14:59:18 +00002086 encode_compound_hdr(xdr, req, &hdr);
2087 encode_sequence(xdr, &args->seq_args, &hdr);
2088 encode_putfh(xdr, args->fh, &hdr);
2089 encode_savefh(xdr, &hdr);
2090 encode_putfh(xdr, args->dir_fh, &hdr);
2091 encode_link(xdr, args->name, &hdr);
2092 encode_getfattr(xdr, args->bitmask, &hdr);
2093 encode_restorefh(xdr, &hdr);
2094 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002095 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096}
2097
2098/*
2099 * Encode CREATE request
2100 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002101static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2102 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002105 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
Chuck Lever9f06c712010-12-14 14:59:18 +00002108 encode_compound_hdr(xdr, req, &hdr);
2109 encode_sequence(xdr, &args->seq_args, &hdr);
2110 encode_putfh(xdr, args->dir_fh, &hdr);
2111 encode_savefh(xdr, &hdr);
2112 encode_create(xdr, args, &hdr);
2113 encode_getfh(xdr, &hdr);
2114 encode_getfattr(xdr, args->bitmask, &hdr);
2115 encode_restorefh(xdr, &hdr);
2116 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002117 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118}
2119
2120/*
2121 * Encode SYMLINK request
2122 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002123static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2124 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125{
Chuck Lever9f06c712010-12-14 14:59:18 +00002126 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127}
2128
2129/*
2130 * Encode GETATTR request
2131 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002132static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2133 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002136 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
Chuck Lever9f06c712010-12-14 14:59:18 +00002139 encode_compound_hdr(xdr, req, &hdr);
2140 encode_sequence(xdr, &args->seq_args, &hdr);
2141 encode_putfh(xdr, args->fh, &hdr);
2142 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002143 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144}
2145
2146/*
2147 * Encode a CLOSE request
2148 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002149static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2150 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151{
Andy Adamson05d564f2008-12-23 16:06:15 -05002152 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002153 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002154 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
Chuck Lever9f06c712010-12-14 14:59:18 +00002156 encode_compound_hdr(xdr, req, &hdr);
2157 encode_sequence(xdr, &args->seq_args, &hdr);
2158 encode_putfh(xdr, args->fh, &hdr);
2159 encode_close(xdr, args, &hdr);
2160 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002161 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162}
2163
2164/*
2165 * Encode an OPEN request
2166 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002167static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2168 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002171 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
Chuck Lever9f06c712010-12-14 14:59:18 +00002174 encode_compound_hdr(xdr, req, &hdr);
2175 encode_sequence(xdr, &args->seq_args, &hdr);
2176 encode_putfh(xdr, args->fh, &hdr);
2177 encode_savefh(xdr, &hdr);
2178 encode_open(xdr, args, &hdr);
2179 encode_getfh(xdr, &hdr);
2180 encode_getfattr(xdr, args->bitmask, &hdr);
2181 encode_restorefh(xdr, &hdr);
2182 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002183 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184}
2185
2186/*
2187 * Encode an OPEN_CONFIRM request
2188 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002189static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2190 struct xdr_stream *xdr,
2191 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002194 .nops = 0,
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_putfh(xdr, args->fh, &hdr);
2199 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002200 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201}
2202
2203/*
2204 * Encode an OPEN request with no attributes.
2205 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002206static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2207 struct xdr_stream *xdr,
2208 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002211 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Chuck Lever9f06c712010-12-14 14:59:18 +00002214 encode_compound_hdr(xdr, req, &hdr);
2215 encode_sequence(xdr, &args->seq_args, &hdr);
2216 encode_putfh(xdr, args->fh, &hdr);
2217 encode_open(xdr, args, &hdr);
2218 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002219 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220}
2221
2222/*
2223 * Encode an OPEN_DOWNGRADE request
2224 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002225static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2226 struct xdr_stream *xdr,
2227 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002230 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
Chuck Lever9f06c712010-12-14 14:59:18 +00002233 encode_compound_hdr(xdr, req, &hdr);
2234 encode_sequence(xdr, &args->seq_args, &hdr);
2235 encode_putfh(xdr, args->fh, &hdr);
2236 encode_open_downgrade(xdr, args, &hdr);
2237 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002238 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239}
2240
2241/*
2242 * Encode a LOCK request
2243 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002244static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2245 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002248 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
Chuck Lever9f06c712010-12-14 14:59:18 +00002251 encode_compound_hdr(xdr, req, &hdr);
2252 encode_sequence(xdr, &args->seq_args, &hdr);
2253 encode_putfh(xdr, args->fh, &hdr);
2254 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002255 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256}
2257
2258/*
2259 * Encode a LOCKT request
2260 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002261static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2262 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002265 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
Chuck Lever9f06c712010-12-14 14:59:18 +00002268 encode_compound_hdr(xdr, req, &hdr);
2269 encode_sequence(xdr, &args->seq_args, &hdr);
2270 encode_putfh(xdr, args->fh, &hdr);
2271 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002272 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273}
2274
2275/*
2276 * Encode a LOCKU request
2277 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002278static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2279 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002282 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
Chuck Lever9f06c712010-12-14 14:59:18 +00002285 encode_compound_hdr(xdr, req, &hdr);
2286 encode_sequence(xdr, &args->seq_args, &hdr);
2287 encode_putfh(xdr, args->fh, &hdr);
2288 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002289 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290}
2291
Chuck Lever9f06c712010-12-14 14:59:18 +00002292static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2293 struct xdr_stream *xdr,
2294 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002295{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002296 struct compound_hdr hdr = {
2297 .minorversion = 0,
2298 };
2299
Chuck Lever9f06c712010-12-14 14:59:18 +00002300 encode_compound_hdr(xdr, req, &hdr);
2301 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002302 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002303}
2304
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305/*
2306 * Encode a READLINK request
2307 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002308static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2309 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002312 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
Chuck Lever9f06c712010-12-14 14:59:18 +00002315 encode_compound_hdr(xdr, req, &hdr);
2316 encode_sequence(xdr, &args->seq_args, &hdr);
2317 encode_putfh(xdr, args->fh, &hdr);
2318 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002319
Benny Halevy28f56692009-04-01 09:22:09 -04002320 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002321 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002322 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323}
2324
2325/*
2326 * Encode a READDIR request
2327 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002328static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2329 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002332 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334
Chuck Lever9f06c712010-12-14 14:59:18 +00002335 encode_compound_hdr(xdr, req, &hdr);
2336 encode_sequence(xdr, &args->seq_args, &hdr);
2337 encode_putfh(xdr, args->fh, &hdr);
2338 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002339
Benny Halevy28f56692009-04-01 09:22:09 -04002340 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002341 args->pgbase, args->count);
2342 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002343 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002344 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002345 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346}
2347
2348/*
2349 * Encode a READ request
2350 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002351static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2352 struct nfs_readargs *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_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Benny Halevy28f56692009-04-01 09:22:09 -04002363 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002365 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002366 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367}
2368
2369/*
2370 * Encode an SETATTR request
2371 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002372static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2373 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374{
Andy Adamson05d564f2008-12-23 16:06:15 -05002375 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002376 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002377 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378
Chuck Lever9f06c712010-12-14 14:59:18 +00002379 encode_compound_hdr(xdr, req, &hdr);
2380 encode_sequence(xdr, &args->seq_args, &hdr);
2381 encode_putfh(xdr, args->fh, &hdr);
2382 encode_setattr(xdr, args, args->server, &hdr);
2383 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002384 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385}
2386
2387/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002388 * Encode a GETACL request
2389 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002390static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2391 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002392{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002393 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002394 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002395 };
Benny Halevy28f56692009-04-01 09:22:09 -04002396 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002397
Chuck Lever9f06c712010-12-14 14:59:18 +00002398 encode_compound_hdr(xdr, req, &hdr);
2399 encode_sequence(xdr, &args->seq_args, &hdr);
2400 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002401 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002402 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002403
Benny Halevy28f56692009-04-01 09:22:09 -04002404 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002405 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002406 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002407}
2408
2409/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 * Encode a WRITE request
2411 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002412static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2413 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002416 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
Chuck Lever9f06c712010-12-14 14:59:18 +00002419 encode_compound_hdr(xdr, req, &hdr);
2420 encode_sequence(xdr, &args->seq_args, &hdr);
2421 encode_putfh(xdr, args->fh, &hdr);
2422 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002423 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002424 if (args->bitmask)
2425 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002426 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427}
2428
2429/*
2430 * a COMMIT request
2431 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002432static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2433 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002436 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438
Chuck Lever9f06c712010-12-14 14:59:18 +00002439 encode_compound_hdr(xdr, req, &hdr);
2440 encode_sequence(xdr, &args->seq_args, &hdr);
2441 encode_putfh(xdr, args->fh, &hdr);
2442 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002443 if (args->bitmask)
2444 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002445 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446}
2447
2448/*
2449 * FSINFO request
2450 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002451static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2452 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002455 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457
Chuck Lever9f06c712010-12-14 14:59:18 +00002458 encode_compound_hdr(xdr, req, &hdr);
2459 encode_sequence(xdr, &args->seq_args, &hdr);
2460 encode_putfh(xdr, args->fh, &hdr);
2461 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002462 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463}
2464
2465/*
2466 * a PATHCONF request
2467 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002468static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2469 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002472 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
Chuck Lever9f06c712010-12-14 14:59:18 +00002475 encode_compound_hdr(xdr, req, &hdr);
2476 encode_sequence(xdr, &args->seq_args, &hdr);
2477 encode_putfh(xdr, args->fh, &hdr);
2478 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002479 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002480 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481}
2482
2483/*
2484 * a STATFS request
2485 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002486static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2487 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002490 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
Chuck Lever9f06c712010-12-14 14:59:18 +00002493 encode_compound_hdr(xdr, req, &hdr);
2494 encode_sequence(xdr, &args->seq_args, &hdr);
2495 encode_putfh(xdr, args->fh, &hdr);
2496 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002497 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002498 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499}
2500
2501/*
2502 * GETATTR_BITMAP request
2503 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002504static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2505 struct xdr_stream *xdr,
2506 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002509 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
Chuck Lever9f06c712010-12-14 14:59:18 +00002512 encode_compound_hdr(xdr, req, &hdr);
2513 encode_sequence(xdr, &args->seq_args, &hdr);
2514 encode_putfh(xdr, args->fhandle, &hdr);
2515 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002516 FATTR4_WORD0_LINK_SUPPORT|
2517 FATTR4_WORD0_SYMLINK_SUPPORT|
2518 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002519 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520}
2521
2522/*
2523 * a RENEW request
2524 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002525static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2526 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002529 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 };
2531
Chuck Lever9f06c712010-12-14 14:59:18 +00002532 encode_compound_hdr(xdr, req, &hdr);
2533 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002534 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535}
2536
2537/*
2538 * a SETCLIENTID request
2539 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002540static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2541 struct xdr_stream *xdr,
2542 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002545 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 };
2547
Chuck Lever9f06c712010-12-14 14:59:18 +00002548 encode_compound_hdr(xdr, req, &hdr);
2549 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002550 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551}
2552
2553/*
2554 * a SETCLIENTID_CONFIRM request
2555 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002556static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2557 struct xdr_stream *xdr,
2558 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002561 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 };
2563 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
Chuck Lever9f06c712010-12-14 14:59:18 +00002565 encode_compound_hdr(xdr, req, &hdr);
2566 encode_setclientid_confirm(xdr, arg, &hdr);
2567 encode_putrootfh(xdr, &hdr);
2568 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002569 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570}
2571
2572/*
2573 * DELEGRETURN request
2574 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002575static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2576 struct xdr_stream *xdr,
2577 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002580 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582
Chuck Lever9f06c712010-12-14 14:59:18 +00002583 encode_compound_hdr(xdr, req, &hdr);
2584 encode_sequence(xdr, &args->seq_args, &hdr);
2585 encode_putfh(xdr, args->fhandle, &hdr);
2586 encode_delegreturn(xdr, args->stateid, &hdr);
2587 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002588 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589}
2590
2591/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002592 * Encode FS_LOCATIONS request
2593 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002594static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2595 struct xdr_stream *xdr,
2596 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002597{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002598 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002599 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002600 };
Benny Halevy28f56692009-04-01 09:22:09 -04002601 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002602
Chuck Lever9f06c712010-12-14 14:59:18 +00002603 encode_compound_hdr(xdr, req, &hdr);
2604 encode_sequence(xdr, &args->seq_args, &hdr);
2605 encode_putfh(xdr, args->dir_fh, &hdr);
2606 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002607 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002608 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002609
Benny Halevy28f56692009-04-01 09:22:09 -04002610 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002611 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002612 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002613}
2614
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002615/*
2616 * Encode SECINFO request
2617 */
2618static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2619 struct xdr_stream *xdr,
2620 struct nfs4_secinfo_arg *args)
2621{
2622 struct compound_hdr hdr = {
2623 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2624 };
2625
2626 encode_compound_hdr(xdr, req, &hdr);
2627 encode_sequence(xdr, &args->seq_args, &hdr);
2628 encode_putfh(xdr, args->dir_fh, &hdr);
2629 encode_secinfo(xdr, args->name, &hdr);
2630 encode_nops(&hdr);
2631}
2632
Benny Halevy99fe60d2009-04-01 09:22:29 -04002633#if defined(CONFIG_NFS_V4_1)
2634/*
2635 * EXCHANGE_ID request
2636 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002637static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2638 struct xdr_stream *xdr,
2639 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002640{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002641 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002642 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002643 };
2644
Chuck Lever9f06c712010-12-14 14:59:18 +00002645 encode_compound_hdr(xdr, req, &hdr);
2646 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002647 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002648}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002649
2650/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002651 * a CREATE_SESSION request
2652 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002653static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2654 struct xdr_stream *xdr,
2655 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002656{
Andy Adamsonfc931582009-04-01 09:22:31 -04002657 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002658 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002659 };
2660
Chuck Lever9f06c712010-12-14 14:59:18 +00002661 encode_compound_hdr(xdr, req, &hdr);
2662 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002663 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002664}
2665
2666/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002667 * a DESTROY_SESSION request
2668 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002669static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2670 struct xdr_stream *xdr,
2671 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002672{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002673 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002674 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002675 };
2676
Chuck Lever9f06c712010-12-14 14:59:18 +00002677 encode_compound_hdr(xdr, req, &hdr);
2678 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002679 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002680}
2681
2682/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002683 * a SEQUENCE request
2684 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002685static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2686 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002687{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002688 struct compound_hdr hdr = {
2689 .minorversion = nfs4_xdr_minorversion(args),
2690 };
2691
Chuck Lever9f06c712010-12-14 14:59:18 +00002692 encode_compound_hdr(xdr, req, &hdr);
2693 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002694 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002695}
2696
2697/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002698 * a GET_LEASE_TIME request
2699 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002700static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2701 struct xdr_stream *xdr,
2702 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002703{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002704 struct compound_hdr hdr = {
2705 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2706 };
2707 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2708
Chuck Lever9f06c712010-12-14 14:59:18 +00002709 encode_compound_hdr(xdr, req, &hdr);
2710 encode_sequence(xdr, &args->la_seq_args, &hdr);
2711 encode_putrootfh(xdr, &hdr);
2712 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002713 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002714}
Ricardo Labiaga18019752009-12-05 16:08:40 -05002715
2716/*
2717 * a RECLAIM_COMPLETE request
2718 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002719static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2720 struct xdr_stream *xdr,
2721 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga18019752009-12-05 16:08:40 -05002722{
Ricardo Labiaga18019752009-12-05 16:08:40 -05002723 struct compound_hdr hdr = {
2724 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2725 };
2726
Chuck Lever9f06c712010-12-14 14:59:18 +00002727 encode_compound_hdr(xdr, req, &hdr);
2728 encode_sequence(xdr, &args->seq_args, &hdr);
2729 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002730 encode_nops(&hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05002731}
2732
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002733/*
2734 * Encode GETDEVICEINFO request
2735 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002736static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2737 struct xdr_stream *xdr,
2738 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002739{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002740 struct compound_hdr hdr = {
2741 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2742 };
2743
Chuck Lever9f06c712010-12-14 14:59:18 +00002744 encode_compound_hdr(xdr, req, &hdr);
2745 encode_sequence(xdr, &args->seq_args, &hdr);
2746 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002747
2748 /* set up reply kvec. Subtract notification bitmap max size (2)
2749 * so that notification bitmap is put in xdr_buf tail */
2750 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2751 args->pdev->pages, args->pdev->pgbase,
2752 args->pdev->pglen);
2753
2754 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002755}
2756
2757/*
2758 * Encode LAYOUTGET request
2759 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002760static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2761 struct xdr_stream *xdr,
2762 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002763{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002764 struct compound_hdr hdr = {
2765 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2766 };
2767
Chuck Lever9f06c712010-12-14 14:59:18 +00002768 encode_compound_hdr(xdr, req, &hdr);
2769 encode_sequence(xdr, &args->seq_args, &hdr);
2770 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2771 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002772
2773 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2774 args->layout.pages, 0, args->layout.pglen);
2775
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002776 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002777}
Andy Adamson863a3c62011-03-23 13:27:54 +00002778
2779/*
2780 * Encode LAYOUTCOMMIT request
2781 */
Benny Halevycbe82602011-05-22 19:52:37 +03002782static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2783 struct xdr_stream *xdr,
2784 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002785{
Benny Halevyac7db722011-05-22 19:53:48 +03002786 struct nfs4_layoutcommit_data *data =
2787 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002788 struct compound_hdr hdr = {
2789 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2790 };
2791
2792 encode_compound_hdr(xdr, req, &hdr);
2793 encode_sequence(xdr, &args->seq_args, &hdr);
2794 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002795 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002796 encode_getfattr(xdr, args->bitmask, &hdr);
2797 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002798}
2799
2800/*
2801 * Encode LAYOUTRETURN request
2802 */
2803static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2804 struct xdr_stream *xdr,
2805 struct nfs4_layoutreturn_args *args)
2806{
2807 struct compound_hdr hdr = {
2808 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2809 };
2810
2811 encode_compound_hdr(xdr, req, &hdr);
2812 encode_sequence(xdr, &args->seq_args, &hdr);
2813 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2814 encode_layoutreturn(xdr, args, &hdr);
2815 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002816}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002817
2818/*
2819 * Encode SECINFO_NO_NAME request
2820 */
2821static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2822 struct xdr_stream *xdr,
2823 struct nfs41_secinfo_no_name_args *args)
2824{
2825 struct compound_hdr hdr = {
2826 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2827 };
2828
2829 encode_compound_hdr(xdr, req, &hdr);
2830 encode_sequence(xdr, &args->seq_args, &hdr);
2831 encode_putrootfh(xdr, &hdr);
2832 encode_secinfo_no_name(xdr, args, &hdr);
2833 encode_nops(&hdr);
2834 return 0;
2835}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002836#endif /* CONFIG_NFS_V4_1 */
2837
Benny Halevy686841b2009-08-14 17:19:48 +03002838static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2839{
2840 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2841 "Remaining buffer length is %tu words.\n",
2842 func, xdr->end - xdr->p);
2843}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
Trond Myklebust683b57b2006-06-09 09:34:22 -04002845static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846{
Al Viro8687b632006-10-19 23:28:48 -07002847 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848
Benny Halevyc0eae662009-08-14 17:20:14 +03002849 p = xdr_inline_decode(xdr, 4);
2850 if (unlikely(!p))
2851 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002852 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002853 p = xdr_inline_decode(xdr, *len);
2854 if (unlikely(!p))
2855 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 *string = (char *)p;
2857 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002858out_overflow:
2859 print_overflow_msg(__func__, xdr);
2860 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861}
2862
2863static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2864{
Al Viro8687b632006-10-19 23:28:48 -07002865 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866
Benny Halevyc0eae662009-08-14 17:20:14 +03002867 p = xdr_inline_decode(xdr, 8);
2868 if (unlikely(!p))
2869 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002870 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002871 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002872
Benny Halevyc0eae662009-08-14 17:20:14 +03002873 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2874 if (unlikely(!p))
2875 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 hdr->tag = (char *)p;
2877 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002878 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002879 if (unlikely(hdr->nops < 1))
2880 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002882out_overflow:
2883 print_overflow_msg(__func__, xdr);
2884 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885}
2886
2887static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2888{
Al Viro8687b632006-10-19 23:28:48 -07002889 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 uint32_t opnum;
2891 int32_t nfserr;
2892
Benny Halevyc0eae662009-08-14 17:20:14 +03002893 p = xdr_inline_decode(xdr, 8);
2894 if (unlikely(!p))
2895 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002896 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002898 dprintk("nfs: Server returned operation"
2899 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 opnum, expected);
2901 return -EIO;
2902 }
Benny Halevycccddf42009-08-14 17:20:19 +03002903 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002905 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002907out_overflow:
2908 print_overflow_msg(__func__, xdr);
2909 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910}
2911
2912/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002913static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914{
Al Viro8687b632006-10-19 23:28:48 -07002915 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002916 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 char *str;
2918
Benny Halevyc0eae662009-08-14 17:20:14 +03002919 p = xdr_inline_decode(xdr, 12);
2920 if (likely(p))
2921 return decode_opaque_inline(xdr, &strlen, &str);
2922 print_overflow_msg(__func__, xdr);
2923 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924}
2925
2926static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2927{
Al Viro8687b632006-10-19 23:28:48 -07002928 uint32_t bmlen;
2929 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930
Benny Halevyc0eae662009-08-14 17:20:14 +03002931 p = xdr_inline_decode(xdr, 4);
2932 if (unlikely(!p))
2933 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002934 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935
2936 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002937 p = xdr_inline_decode(xdr, (bmlen << 2));
2938 if (unlikely(!p))
2939 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002941 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002943 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 }
2945 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002946out_overflow:
2947 print_overflow_msg(__func__, xdr);
2948 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949}
2950
Al Viro8687b632006-10-19 23:28:48 -07002951static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952{
Al Viro8687b632006-10-19 23:28:48 -07002953 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954
Benny Halevyc0eae662009-08-14 17:20:14 +03002955 p = xdr_inline_decode(xdr, 4);
2956 if (unlikely(!p))
2957 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002958 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 *savep = xdr->p;
2960 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002961out_overflow:
2962 print_overflow_msg(__func__, xdr);
2963 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964}
2965
2966static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2967{
2968 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04002969 int ret;
2970 ret = decode_attr_bitmap(xdr, bitmask);
2971 if (unlikely(ret < 0))
2972 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2974 } else
2975 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002976 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 return 0;
2978}
2979
2980static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2981{
Al Viro8687b632006-10-19 23:28:48 -07002982 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002983 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984
2985 *type = 0;
2986 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2987 return -EIO;
2988 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002989 p = xdr_inline_decode(xdr, 4);
2990 if (unlikely(!p))
2991 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002992 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002994 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 return -EIO;
2996 }
2997 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002998 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003000 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003001 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003002out_overflow:
3003 print_overflow_msg(__func__, xdr);
3004 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005}
3006
3007static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3008{
Al Viro8687b632006-10-19 23:28:48 -07003009 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003010 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011
3012 *change = 0;
3013 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3014 return -EIO;
3015 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003016 p = xdr_inline_decode(xdr, 8);
3017 if (unlikely(!p))
3018 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003019 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003021 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003023 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003025 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003026out_overflow:
3027 print_overflow_msg(__func__, xdr);
3028 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029}
3030
3031static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3032{
Al Viro8687b632006-10-19 23:28:48 -07003033 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003034 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035
3036 *size = 0;
3037 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3038 return -EIO;
3039 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003040 p = xdr_inline_decode(xdr, 8);
3041 if (unlikely(!p))
3042 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003043 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003045 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003047 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003048 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003049out_overflow:
3050 print_overflow_msg(__func__, xdr);
3051 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052}
3053
3054static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3055{
Al Viro8687b632006-10-19 23:28:48 -07003056 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
3058 *res = 0;
3059 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3060 return -EIO;
3061 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003062 p = xdr_inline_decode(xdr, 4);
3063 if (unlikely(!p))
3064 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003065 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3067 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003068 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003070out_overflow:
3071 print_overflow_msg(__func__, xdr);
3072 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073}
3074
3075static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3076{
Al Viro8687b632006-10-19 23:28:48 -07003077 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078
3079 *res = 0;
3080 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3081 return -EIO;
3082 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003083 p = xdr_inline_decode(xdr, 4);
3084 if (unlikely(!p))
3085 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003086 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3088 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003089 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003091out_overflow:
3092 print_overflow_msg(__func__, xdr);
3093 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094}
3095
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003096static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097{
Al Viro8687b632006-10-19 23:28:48 -07003098 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003099 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100
3101 fsid->major = 0;
3102 fsid->minor = 0;
3103 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3104 return -EIO;
3105 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003106 p = xdr_inline_decode(xdr, 16);
3107 if (unlikely(!p))
3108 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003109 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003110 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003112 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003114 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 (unsigned long long)fsid->major,
3116 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003117 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003118out_overflow:
3119 print_overflow_msg(__func__, xdr);
3120 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121}
3122
3123static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3124{
Al Viro8687b632006-10-19 23:28:48 -07003125 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126
3127 *res = 60;
3128 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3129 return -EIO;
3130 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003131 p = xdr_inline_decode(xdr, 4);
3132 if (unlikely(!p))
3133 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003134 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3136 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003137 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003139out_overflow:
3140 print_overflow_msg(__func__, xdr);
3141 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142}
3143
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003144static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003145{
3146 __be32 *p;
3147
3148 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3149 return -EIO;
3150 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3151 p = xdr_inline_decode(xdr, 4);
3152 if (unlikely(!p))
3153 goto out_overflow;
3154 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003155 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003156 }
3157 return 0;
3158out_overflow:
3159 print_overflow_msg(__func__, xdr);
3160 return -EIO;
3161}
3162
3163static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3164{
3165 __be32 *p;
3166 int len;
3167
Trond Myklebust7ad07352010-10-23 15:34:20 -04003168 if (fh != NULL)
3169 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003170
3171 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3172 return -EIO;
3173 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3174 p = xdr_inline_decode(xdr, 4);
3175 if (unlikely(!p))
3176 goto out_overflow;
3177 len = be32_to_cpup(p);
3178 if (len > NFS4_FHSIZE)
3179 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003180 p = xdr_inline_decode(xdr, len);
3181 if (unlikely(!p))
3182 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003183 if (fh != NULL) {
3184 memcpy(fh->data, p, len);
3185 fh->size = len;
3186 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003187 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3188 }
3189 return 0;
3190out_overflow:
3191 print_overflow_msg(__func__, xdr);
3192 return -EIO;
3193}
3194
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3196{
Al Viro8687b632006-10-19 23:28:48 -07003197 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198
3199 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3200 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3201 return -EIO;
3202 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003203 p = xdr_inline_decode(xdr, 4);
3204 if (unlikely(!p))
3205 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003206 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3208 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003209 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003211out_overflow:
3212 print_overflow_msg(__func__, xdr);
3213 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214}
3215
3216static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3217{
Al Viro8687b632006-10-19 23:28:48 -07003218 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003219 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220
3221 *fileid = 0;
3222 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3223 return -EIO;
3224 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003225 p = xdr_inline_decode(xdr, 8);
3226 if (unlikely(!p))
3227 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003228 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003230 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003232 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003233 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003234out_overflow:
3235 print_overflow_msg(__func__, xdr);
3236 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237}
3238
Manoj Naik99baf622006-06-09 09:34:24 -04003239static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3240{
Al Viro8687b632006-10-19 23:28:48 -07003241 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003242 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003243
3244 *fileid = 0;
3245 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3246 return -EIO;
3247 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003248 p = xdr_inline_decode(xdr, 8);
3249 if (unlikely(!p))
3250 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003251 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003252 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003253 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003254 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003255 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003256 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003257out_overflow:
3258 print_overflow_msg(__func__, xdr);
3259 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003260}
3261
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3263{
Al Viro8687b632006-10-19 23:28:48 -07003264 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 int status = 0;
3266
3267 *res = 0;
3268 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3269 return -EIO;
3270 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003271 p = xdr_inline_decode(xdr, 8);
3272 if (unlikely(!p))
3273 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003274 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3276 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003277 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003279out_overflow:
3280 print_overflow_msg(__func__, xdr);
3281 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282}
3283
3284static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3285{
Al Viro8687b632006-10-19 23:28:48 -07003286 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 int status = 0;
3288
3289 *res = 0;
3290 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3291 return -EIO;
3292 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003293 p = xdr_inline_decode(xdr, 8);
3294 if (unlikely(!p))
3295 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003296 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3298 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003299 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003301out_overflow:
3302 print_overflow_msg(__func__, xdr);
3303 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304}
3305
3306static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3307{
Al Viro8687b632006-10-19 23:28:48 -07003308 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 int status = 0;
3310
3311 *res = 0;
3312 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3313 return -EIO;
3314 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003315 p = xdr_inline_decode(xdr, 8);
3316 if (unlikely(!p))
3317 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003318 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3320 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003321 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003323out_overflow:
3324 print_overflow_msg(__func__, xdr);
3325 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326}
3327
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003328static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3329{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003330 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003331 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003332 int status = 0;
3333
Benny Halevyc0eae662009-08-14 17:20:14 +03003334 p = xdr_inline_decode(xdr, 4);
3335 if (unlikely(!p))
3336 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003337 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003338 if (n == 0)
3339 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003340 dprintk("path ");
3341 path->ncomponents = 0;
3342 while (path->ncomponents < n) {
3343 struct nfs4_string *component = &path->components[path->ncomponents];
3344 status = decode_opaque_inline(xdr, &component->len, &component->data);
3345 if (unlikely(status != 0))
3346 goto out_eio;
3347 if (path->ncomponents != n)
3348 dprintk("/");
3349 dprintk("%s", component->data);
3350 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3351 path->ncomponents++;
3352 else {
3353 dprintk("cannot parse %d components in path\n", n);
3354 goto out_eio;
3355 }
3356 }
3357out:
3358 dprintk("\n");
3359 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003360root_path:
3361/* a root pathname is sent as a zero component4 */
3362 path->ncomponents = 1;
3363 path->components[0].len=0;
3364 path->components[0].data=NULL;
3365 dprintk("path /\n");
3366 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003367out_eio:
3368 dprintk(" status %d", status);
3369 status = -EIO;
3370 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003371out_overflow:
3372 print_overflow_msg(__func__, xdr);
3373 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003374}
3375
3376static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003377{
3378 int n;
Al Viro8687b632006-10-19 23:28:48 -07003379 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003380 int status = -EIO;
3381
3382 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3383 goto out;
3384 status = 0;
3385 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3386 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003387 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003388 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003389 if (unlikely(status != 0))
3390 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003391 p = xdr_inline_decode(xdr, 4);
3392 if (unlikely(!p))
3393 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003394 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003395 if (n <= 0)
3396 goto out_eio;
3397 res->nlocations = 0;
3398 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003399 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003400 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003401
Benny Halevyc0eae662009-08-14 17:20:14 +03003402 p = xdr_inline_decode(xdr, 4);
3403 if (unlikely(!p))
3404 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003405 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003406
3407 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003408 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003409 while (loc->nservers < m) {
3410 struct nfs4_string *server = &loc->servers[loc->nservers];
3411 status = decode_opaque_inline(xdr, &server->len, &server->data);
3412 if (unlikely(status != 0))
3413 goto out_eio;
3414 dprintk("%s ", server->data);
3415 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3416 loc->nservers++;
3417 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003418 unsigned int i;
3419 dprintk("%s: using first %u of %u servers "
3420 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003421 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003422 NFS4_FS_LOCATION_MAXSERVERS,
3423 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003424 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003425 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003426 char *data;
3427 status = decode_opaque_inline(xdr, &len, &data);
3428 if (unlikely(status != 0))
3429 goto out_eio;
3430 }
3431 }
3432 }
3433 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003434 if (unlikely(status != 0))
3435 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003436 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003437 res->nlocations++;
3438 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003439 if (res->nlocations != 0)
3440 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003441out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003442 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003443 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003444out_overflow:
3445 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003446out_eio:
3447 status = -EIO;
3448 goto out;
3449}
3450
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3452{
Al Viro8687b632006-10-19 23:28:48 -07003453 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 int status = 0;
3455
3456 *res = 0;
3457 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3458 return -EIO;
3459 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003460 p = xdr_inline_decode(xdr, 8);
3461 if (unlikely(!p))
3462 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003463 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3465 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003466 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003468out_overflow:
3469 print_overflow_msg(__func__, xdr);
3470 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471}
3472
3473static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3474{
Al Viro8687b632006-10-19 23:28:48 -07003475 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 int status = 0;
3477
3478 *maxlink = 1;
3479 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3480 return -EIO;
3481 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003482 p = xdr_inline_decode(xdr, 4);
3483 if (unlikely(!p))
3484 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003485 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3487 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003488 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003490out_overflow:
3491 print_overflow_msg(__func__, xdr);
3492 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493}
3494
3495static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3496{
Al Viro8687b632006-10-19 23:28:48 -07003497 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 int status = 0;
3499
3500 *maxname = 1024;
3501 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3502 return -EIO;
3503 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003504 p = xdr_inline_decode(xdr, 4);
3505 if (unlikely(!p))
3506 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003507 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3509 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003510 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003512out_overflow:
3513 print_overflow_msg(__func__, xdr);
3514 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515}
3516
3517static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3518{
Al Viro8687b632006-10-19 23:28:48 -07003519 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 int status = 0;
3521
3522 *res = 1024;
3523 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3524 return -EIO;
3525 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3526 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003527 p = xdr_inline_decode(xdr, 8);
3528 if (unlikely(!p))
3529 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003530 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531 if (maxread > 0x7FFFFFFF)
3532 maxread = 0x7FFFFFFF;
3533 *res = (uint32_t)maxread;
3534 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3535 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003536 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003538out_overflow:
3539 print_overflow_msg(__func__, xdr);
3540 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541}
3542
3543static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3544{
Al Viro8687b632006-10-19 23:28:48 -07003545 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 int status = 0;
3547
3548 *res = 1024;
3549 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3550 return -EIO;
3551 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3552 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003553 p = xdr_inline_decode(xdr, 8);
3554 if (unlikely(!p))
3555 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003556 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 if (maxwrite > 0x7FFFFFFF)
3558 maxwrite = 0x7FFFFFFF;
3559 *res = (uint32_t)maxwrite;
3560 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3561 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003562 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003564out_overflow:
3565 print_overflow_msg(__func__, xdr);
3566 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567}
3568
Trond Myklebustbca79472009-03-11 14:10:26 -04003569static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570{
Trond Myklebustbca79472009-03-11 14:10:26 -04003571 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003572 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003573 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574
3575 *mode = 0;
3576 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3577 return -EIO;
3578 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003579 p = xdr_inline_decode(xdr, 4);
3580 if (unlikely(!p))
3581 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003582 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003583 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003585 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003587 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003588 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003589out_overflow:
3590 print_overflow_msg(__func__, xdr);
3591 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592}
3593
3594static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3595{
Al Viro8687b632006-10-19 23:28:48 -07003596 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003597 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598
3599 *nlink = 1;
3600 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3601 return -EIO;
3602 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003603 p = xdr_inline_decode(xdr, 4);
3604 if (unlikely(!p))
3605 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003606 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003608 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003610 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003611 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003612out_overflow:
3613 print_overflow_msg(__func__, xdr);
3614 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615}
3616
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003617static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003618 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619{
Al Viro8687b632006-10-19 23:28:48 -07003620 uint32_t len;
3621 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003622 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623
3624 *uid = -2;
3625 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3626 return -EIO;
3627 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003628 p = xdr_inline_decode(xdr, 4);
3629 if (unlikely(!p))
3630 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003631 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003632 p = xdr_inline_decode(xdr, len);
3633 if (unlikely(!p))
3634 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003635 if (!may_sleep) {
3636 /* do nothing */
3637 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003638 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003639 ret = NFS_ATTR_FATTR_OWNER;
3640 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003642 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003644 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003645 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3647 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003648 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003649 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003650out_overflow:
3651 print_overflow_msg(__func__, xdr);
3652 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653}
3654
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003655static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003656 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657{
Al Viro8687b632006-10-19 23:28:48 -07003658 uint32_t len;
3659 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003660 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661
3662 *gid = -2;
3663 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3664 return -EIO;
3665 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003666 p = xdr_inline_decode(xdr, 4);
3667 if (unlikely(!p))
3668 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003669 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003670 p = xdr_inline_decode(xdr, len);
3671 if (unlikely(!p))
3672 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003673 if (!may_sleep) {
3674 /* do nothing */
3675 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003676 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003677 ret = NFS_ATTR_FATTR_GROUP;
3678 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003680 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003682 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003683 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3685 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003686 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003687 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003688out_overflow:
3689 print_overflow_msg(__func__, xdr);
3690 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691}
3692
3693static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3694{
Al Viro8687b632006-10-19 23:28:48 -07003695 uint32_t major = 0, minor = 0;
3696 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003697 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698
3699 *rdev = MKDEV(0,0);
3700 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3701 return -EIO;
3702 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3703 dev_t tmp;
3704
Benny Halevyc0eae662009-08-14 17:20:14 +03003705 p = xdr_inline_decode(xdr, 8);
3706 if (unlikely(!p))
3707 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003708 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003709 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710 tmp = MKDEV(major, minor);
3711 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3712 *rdev = tmp;
3713 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003714 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003716 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003717 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003718out_overflow:
3719 print_overflow_msg(__func__, xdr);
3720 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721}
3722
3723static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3724{
Al Viro8687b632006-10-19 23:28:48 -07003725 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726 int status = 0;
3727
3728 *res = 0;
3729 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3730 return -EIO;
3731 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003732 p = xdr_inline_decode(xdr, 8);
3733 if (unlikely(!p))
3734 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003735 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3737 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003738 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003740out_overflow:
3741 print_overflow_msg(__func__, xdr);
3742 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743}
3744
3745static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3746{
Al Viro8687b632006-10-19 23:28:48 -07003747 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 int status = 0;
3749
3750 *res = 0;
3751 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3752 return -EIO;
3753 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003754 p = xdr_inline_decode(xdr, 8);
3755 if (unlikely(!p))
3756 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003757 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3759 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003760 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003762out_overflow:
3763 print_overflow_msg(__func__, xdr);
3764 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765}
3766
3767static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3768{
Al Viro8687b632006-10-19 23:28:48 -07003769 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003770 int status = 0;
3771
3772 *res = 0;
3773 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3774 return -EIO;
3775 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003776 p = xdr_inline_decode(xdr, 8);
3777 if (unlikely(!p))
3778 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003779 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3781 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003782 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003784out_overflow:
3785 print_overflow_msg(__func__, xdr);
3786 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787}
3788
3789static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3790{
Al Viro8687b632006-10-19 23:28:48 -07003791 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003792 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793
3794 *used = 0;
3795 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3796 return -EIO;
3797 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003798 p = xdr_inline_decode(xdr, 8);
3799 if (unlikely(!p))
3800 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003801 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003803 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003805 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003807 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003808out_overflow:
3809 print_overflow_msg(__func__, xdr);
3810 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811}
3812
3813static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3814{
Al Viro8687b632006-10-19 23:28:48 -07003815 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 uint64_t sec;
3817 uint32_t nsec;
3818
Benny Halevyc0eae662009-08-14 17:20:14 +03003819 p = xdr_inline_decode(xdr, 12);
3820 if (unlikely(!p))
3821 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003822 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003823 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 time->tv_sec = (time_t)sec;
3825 time->tv_nsec = (long)nsec;
3826 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003827out_overflow:
3828 print_overflow_msg(__func__, xdr);
3829 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830}
3831
3832static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3833{
3834 int status = 0;
3835
3836 time->tv_sec = 0;
3837 time->tv_nsec = 0;
3838 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3839 return -EIO;
3840 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3841 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003842 if (status == 0)
3843 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3845 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003846 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 return status;
3848}
3849
3850static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3851{
3852 int status = 0;
3853
3854 time->tv_sec = 0;
3855 time->tv_nsec = 0;
3856 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3857 return -EIO;
3858 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3859 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003860 if (status == 0)
3861 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3863 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003864 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 return status;
3866}
3867
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003868static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3869 struct timespec *time)
3870{
3871 int status = 0;
3872
3873 time->tv_sec = 0;
3874 time->tv_nsec = 0;
3875 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3876 return -EIO;
3877 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3878 status = decode_attr_time(xdr, time);
3879 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3880 }
3881 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3882 (long)time->tv_nsec);
3883 return status;
3884}
3885
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3887{
3888 int status = 0;
3889
3890 time->tv_sec = 0;
3891 time->tv_nsec = 0;
3892 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3893 return -EIO;
3894 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3895 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003896 if (status == 0)
3897 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3899 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003900 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 return status;
3902}
3903
Al Viro8687b632006-10-19 23:28:48 -07003904static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905{
3906 unsigned int attrwords = XDR_QUADLEN(attrlen);
3907 unsigned int nwords = xdr->p - savep;
3908
3909 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003910 dprintk("%s: server returned incorrect attribute length: "
3911 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003912 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 attrwords << 2,
3914 (attrwords < nwords) ? '<' : '>',
3915 nwords << 2);
3916 return -EIO;
3917 }
3918 return 0;
3919}
3920
3921static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3922{
Al Viro8687b632006-10-19 23:28:48 -07003923 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924
Benny Halevyc0eae662009-08-14 17:20:14 +03003925 p = xdr_inline_decode(xdr, 20);
3926 if (unlikely(!p))
3927 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003928 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003929 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003930 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003932out_overflow:
3933 print_overflow_msg(__func__, xdr);
3934 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935}
3936
3937static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3938{
Al Viro8687b632006-10-19 23:28:48 -07003939 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940 uint32_t supp, acc;
3941 int status;
3942
3943 status = decode_op_hdr(xdr, OP_ACCESS);
3944 if (status)
3945 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003946 p = xdr_inline_decode(xdr, 8);
3947 if (unlikely(!p))
3948 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003949 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003950 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 access->supported = supp;
3952 access->access = acc;
3953 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003954out_overflow:
3955 print_overflow_msg(__func__, xdr);
3956 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957}
3958
Benny Halevy07d30432009-08-14 17:19:52 +03003959static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960{
Al Viro8687b632006-10-19 23:28:48 -07003961 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003962
3963 p = xdr_inline_decode(xdr, len);
3964 if (likely(p)) {
3965 memcpy(buf, p, len);
3966 return 0;
3967 }
3968 print_overflow_msg(__func__, xdr);
3969 return -EIO;
3970}
3971
3972static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3973{
3974 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975}
3976
3977static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3978{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 int status;
3980
3981 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003982 if (status != -EIO)
3983 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003984 if (!status)
3985 status = decode_stateid(xdr, &res->stateid);
3986 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987}
3988
Benny Halevydb942bb2009-08-14 17:19:56 +03003989static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3990{
3991 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992}
3993
3994static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3995{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 int status;
3997
3998 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003999 if (!status)
4000 status = decode_verifier(xdr, res->verf->verifier);
4001 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002}
4003
4004static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4005{
Al Viro8687b632006-10-19 23:28:48 -07004006 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 uint32_t bmlen;
4008 int status;
4009
4010 status = decode_op_hdr(xdr, OP_CREATE);
4011 if (status)
4012 return status;
4013 if ((status = decode_change_info(xdr, cinfo)))
4014 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004015 p = xdr_inline_decode(xdr, 4);
4016 if (unlikely(!p))
4017 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004018 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004019 p = xdr_inline_decode(xdr, bmlen << 2);
4020 if (likely(p))
4021 return 0;
4022out_overflow:
4023 print_overflow_msg(__func__, xdr);
4024 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025}
4026
4027static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4028{
Al Viro8687b632006-10-19 23:28:48 -07004029 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004030 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031 int status;
4032
4033 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4034 goto xdr_error;
4035 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4036 goto xdr_error;
4037 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4038 goto xdr_error;
4039 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4040 goto xdr_error;
4041 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4042 goto xdr_error;
4043 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4044 goto xdr_error;
4045 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4046 goto xdr_error;
4047 status = verify_attr_len(xdr, savep, attrlen);
4048xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004049 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 return status;
4051}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004052
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4054{
Al Viro8687b632006-10-19 23:28:48 -07004055 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004056 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004058
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4060 goto xdr_error;
4061 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4062 goto xdr_error;
4063 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4064 goto xdr_error;
4065
4066 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4067 goto xdr_error;
4068 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4069 goto xdr_error;
4070 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4071 goto xdr_error;
4072 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4073 goto xdr_error;
4074 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4075 goto xdr_error;
4076 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4077 goto xdr_error;
4078
4079 status = verify_attr_len(xdr, savep, attrlen);
4080xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004081 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 return status;
4083}
4084
4085static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4086{
Al Viro8687b632006-10-19 23:28:48 -07004087 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004088 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004090
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4092 goto xdr_error;
4093 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4094 goto xdr_error;
4095 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4096 goto xdr_error;
4097
4098 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4099 goto xdr_error;
4100 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4101 goto xdr_error;
4102
4103 status = verify_attr_len(xdr, savep, attrlen);
4104xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004105 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 return status;
4107}
4108
Bryan Schumakerae42c702010-10-21 16:33:17 -04004109static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4110 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004111 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112{
Trond Myklebustbca79472009-03-11 14:10:26 -04004113 int status;
4114 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004115 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004116 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004118 status = decode_attr_type(xdr, bitmap, &type);
4119 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004121 fattr->mode = 0;
4122 if (status != 0) {
4123 fattr->mode |= nfs_type2fmt[type];
4124 fattr->valid |= status;
4125 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004127 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4128 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004130 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004131
4132 status = decode_attr_size(xdr, bitmap, &fattr->size);
4133 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004135 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004136
4137 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4138 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004140 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004141
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004142 err = 0;
4143 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004144 if (status < 0)
4145 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004146 if (err == -NFS4ERR_WRONGSEC)
4147 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004148
4149 status = decode_attr_filehandle(xdr, bitmap, fh);
4150 if (status < 0)
4151 goto xdr_error;
4152
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004153 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4154 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004156 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004157
4158 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04004159 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004160 fattr));
4161 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004162 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004163 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004164
4165 status = decode_attr_mode(xdr, bitmap, &fmode);
4166 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004168 if (status != 0) {
4169 fattr->mode |= fmode;
4170 fattr->valid |= status;
4171 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004172
4173 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4174 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004176 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004177
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004178 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004179 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004181 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004182
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004183 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004184 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004186 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004187
4188 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4189 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004191 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004192
4193 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
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_time_access(xdr, bitmap, &fattr->atime);
4199 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004201 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004202
4203 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4204 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004206 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004207
4208 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4209 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004211 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004212
Trond Myklebust28331a42011-04-27 13:47:52 -04004213 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004214 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004215 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004216 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004217
Bryan Schumakerae42c702010-10-21 16:33:17 -04004218xdr_error:
4219 dprintk("%s: xdr returned %d\n", __func__, -status);
4220 return status;
4221}
4222
4223static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4224 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4225{
4226 __be32 *savep;
4227 uint32_t attrlen,
4228 bitmap[2] = {0};
4229 int status;
4230
4231 status = decode_op_hdr(xdr, OP_GETATTR);
4232 if (status < 0)
4233 goto xdr_error;
4234
4235 status = decode_attr_bitmap(xdr, bitmap);
4236 if (status < 0)
4237 goto xdr_error;
4238
4239 status = decode_attr_length(xdr, &attrlen, &savep);
4240 if (status < 0)
4241 goto xdr_error;
4242
4243 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4244 if (status < 0)
4245 goto xdr_error;
4246
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004247 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004249 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 return status;
4251}
4252
Bryan Schumakerae42c702010-10-21 16:33:17 -04004253static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4254 const struct nfs_server *server, int may_sleep)
4255{
4256 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4257}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258
Andy Adamson504913f2010-10-20 00:17:57 -04004259/*
4260 * Decode potentially multiple layout types. Currently we only support
4261 * one layout driver per file system.
4262 */
4263static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4264 uint32_t *layouttype)
4265{
4266 uint32_t *p;
4267 int num;
4268
4269 p = xdr_inline_decode(xdr, 4);
4270 if (unlikely(!p))
4271 goto out_overflow;
4272 num = be32_to_cpup(p);
4273
4274 /* pNFS is not supported by the underlying file system */
4275 if (num == 0) {
4276 *layouttype = 0;
4277 return 0;
4278 }
4279 if (num > 1)
4280 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4281 "per filesystem not supported\n", __func__);
4282
4283 /* Decode and set first layout type, move xdr->p past unused types */
4284 p = xdr_inline_decode(xdr, num * 4);
4285 if (unlikely(!p))
4286 goto out_overflow;
4287 *layouttype = be32_to_cpup(p);
4288 return 0;
4289out_overflow:
4290 print_overflow_msg(__func__, xdr);
4291 return -EIO;
4292}
4293
4294/*
4295 * The type of file system exported.
4296 * Note we must ensure that layouttype is set in any non-error case.
4297 */
4298static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4299 uint32_t *layouttype)
4300{
4301 int status = 0;
4302
4303 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4304 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4305 return -EIO;
4306 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4307 status = decode_first_pnfs_layout_type(xdr, layouttype);
4308 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4309 } else
4310 *layouttype = 0;
4311 return status;
4312}
4313
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4315{
Al Viro8687b632006-10-19 23:28:48 -07004316 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317 uint32_t attrlen, bitmap[2];
4318 int status;
4319
4320 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4321 goto xdr_error;
4322 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4323 goto xdr_error;
4324 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4325 goto xdr_error;
4326
4327 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4328
4329 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4330 goto xdr_error;
4331 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4332 goto xdr_error;
4333 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4334 goto xdr_error;
4335 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4336 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4337 goto xdr_error;
4338 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004339 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4340 if (status != 0)
4341 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004342 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4343 if (status != 0)
4344 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345
4346 status = verify_attr_len(xdr, savep, attrlen);
4347xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004348 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 return status;
4350}
4351
4352static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4353{
Al Viro8687b632006-10-19 23:28:48 -07004354 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 uint32_t len;
4356 int status;
4357
Trond Myklebust99367812007-07-17 21:52:41 -04004358 /* Zero handle first to allow comparisons */
4359 memset(fh, 0, sizeof(*fh));
4360
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361 status = decode_op_hdr(xdr, OP_GETFH);
4362 if (status)
4363 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364
Benny Halevyc0eae662009-08-14 17:20:14 +03004365 p = xdr_inline_decode(xdr, 4);
4366 if (unlikely(!p))
4367 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004368 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369 if (len > NFS4_FHSIZE)
4370 return -EIO;
4371 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004372 p = xdr_inline_decode(xdr, len);
4373 if (unlikely(!p))
4374 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004375 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004377out_overflow:
4378 print_overflow_msg(__func__, xdr);
4379 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380}
4381
4382static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4383{
4384 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004385
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 status = decode_op_hdr(xdr, OP_LINK);
4387 if (status)
4388 return status;
4389 return decode_change_info(xdr, cinfo);
4390}
4391
4392/*
4393 * We create the owner, so we know a proper owner.id length is 4.
4394 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004395static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004397 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004398 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004399 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004401 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004402 if (unlikely(!p))
4403 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004404 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004405 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004406 type = be32_to_cpup(p++); /* 4 byte read */
4407 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004408 fl->fl_start = (loff_t)offset;
4409 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4410 if (length == ~(uint64_t)0)
4411 fl->fl_end = OFFSET_MAX;
4412 fl->fl_type = F_WRLCK;
4413 if (type & 1)
4414 fl->fl_type = F_RDLCK;
4415 fl->fl_pid = 0;
4416 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004417 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4418 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4419 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004420 if (likely(p))
4421 return -NFS4ERR_DENIED;
4422out_overflow:
4423 print_overflow_msg(__func__, xdr);
4424 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425}
4426
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004427static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429 int status;
4430
4431 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004432 if (status == -EIO)
4433 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004434 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004435 status = decode_stateid(xdr, &res->stateid);
4436 if (unlikely(status))
4437 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004439 status = decode_lock_denied(xdr, NULL);
4440 if (res->open_seqid != NULL)
4441 nfs_increment_open_seqid(status, res->open_seqid);
4442 nfs_increment_lock_seqid(status, res->lock_seqid);
4443out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444 return status;
4445}
4446
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004447static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448{
4449 int status;
4450 status = decode_op_hdr(xdr, OP_LOCKT);
4451 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004452 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 return status;
4454}
4455
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004456static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 int status;
4459
4460 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004461 if (status != -EIO)
4462 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004463 if (status == 0)
4464 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 return status;
4466}
4467
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004468static int decode_release_lockowner(struct xdr_stream *xdr)
4469{
4470 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4471}
4472
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473static int decode_lookup(struct xdr_stream *xdr)
4474{
4475 return decode_op_hdr(xdr, OP_LOOKUP);
4476}
4477
4478/* This is too sick! */
4479static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4480{
Andy Adamson05d564f2008-12-23 16:06:15 -05004481 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004482 uint32_t limit_type, nblocks, blocksize;
4483
Benny Halevyc0eae662009-08-14 17:20:14 +03004484 p = xdr_inline_decode(xdr, 12);
4485 if (unlikely(!p))
4486 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004487 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004489 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004490 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004491 break;
4492 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004493 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004494 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004495 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 }
4497 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004498out_overflow:
4499 print_overflow_msg(__func__, xdr);
4500 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004501}
4502
4503static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4504{
Andy Adamson05d564f2008-12-23 16:06:15 -05004505 __be32 *p;
4506 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004507 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508
Benny Halevyc0eae662009-08-14 17:20:14 +03004509 p = xdr_inline_decode(xdr, 4);
4510 if (unlikely(!p))
4511 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004512 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4514 res->delegation_type = 0;
4515 return 0;
4516 }
Benny Halevy07d30432009-08-14 17:19:52 +03004517 status = decode_stateid(xdr, &res->delegation);
4518 if (unlikely(status))
4519 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004520 p = xdr_inline_decode(xdr, 4);
4521 if (unlikely(!p))
4522 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004523 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004524
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004526 case NFS4_OPEN_DELEGATE_READ:
4527 res->delegation_type = FMODE_READ;
4528 break;
4529 case NFS4_OPEN_DELEGATE_WRITE:
4530 res->delegation_type = FMODE_WRITE|FMODE_READ;
4531 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532 return -EIO;
4533 }
David Howells7539bba2006-08-22 20:06:09 -04004534 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004535out_overflow:
4536 print_overflow_msg(__func__, xdr);
4537 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538}
4539
4540static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4541{
Andy Adamson05d564f2008-12-23 16:06:15 -05004542 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004543 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004544 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545
Andy Adamson05d564f2008-12-23 16:06:15 -05004546 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004547 if (status != -EIO)
4548 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004549 if (!status)
4550 status = decode_stateid(xdr, &res->stateid);
4551 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004552 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553
Andy Adamson05d564f2008-12-23 16:06:15 -05004554 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004555
Benny Halevyc0eae662009-08-14 17:20:14 +03004556 p = xdr_inline_decode(xdr, 8);
4557 if (unlikely(!p))
4558 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004559 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004560 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004561 if (bmlen > 10)
4562 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563
Benny Halevyc0eae662009-08-14 17:20:14 +03004564 p = xdr_inline_decode(xdr, bmlen << 2);
4565 if (unlikely(!p))
4566 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004567 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4568 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004569 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004570 for (; i < NFS4_BITMAP_SIZE; i++)
4571 res->attrset[i] = 0;
4572
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 return decode_delegation(xdr, res);
4574xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004575 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004577out_overflow:
4578 print_overflow_msg(__func__, xdr);
4579 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004580}
4581
4582static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4583{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 int status;
4585
Andy Adamson05d564f2008-12-23 16:06:15 -05004586 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
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 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592}
4593
4594static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4595{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596 int status;
4597
4598 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004599 if (status != -EIO)
4600 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004601 if (!status)
4602 status = decode_stateid(xdr, &res->stateid);
4603 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004604}
4605
4606static int decode_putfh(struct xdr_stream *xdr)
4607{
4608 return decode_op_hdr(xdr, OP_PUTFH);
4609}
4610
4611static int decode_putrootfh(struct xdr_stream *xdr)
4612{
4613 return decode_op_hdr(xdr, OP_PUTROOTFH);
4614}
4615
4616static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4617{
4618 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004619 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620 uint32_t count, eof, recvd, hdrlen;
4621 int status;
4622
4623 status = decode_op_hdr(xdr, OP_READ);
4624 if (status)
4625 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004626 p = xdr_inline_decode(xdr, 8);
4627 if (unlikely(!p))
4628 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004629 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004630 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004631 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632 recvd = req->rq_rcv_buf.len - hdrlen;
4633 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004634 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635 "count %u > recvd %u\n", count, recvd);
4636 count = recvd;
4637 eof = 0;
4638 }
4639 xdr_read_pages(xdr, count);
4640 res->eof = eof;
4641 res->count = count;
4642 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004643out_overflow:
4644 print_overflow_msg(__func__, xdr);
4645 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646}
4647
4648static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4649{
4650 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004652 size_t hdrlen;
4653 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004654 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655
4656 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004657 if (!status)
4658 status = decode_verifier(xdr, readdir->verifier.data);
4659 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004661 dprintk("%s: verifier = %08x:%08x\n",
4662 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004663 ((u32 *)readdir->verifier.data)[0],
4664 ((u32 *)readdir->verifier.data)[1]);
4665
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666
Benny Halevydb942bb2009-08-14 17:19:56 +03004667 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004668 recvd = rcvbuf->len - hdrlen;
4669 if (pglen > recvd)
4670 pglen = recvd;
4671 xdr_read_pages(xdr, pglen);
4672
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004673
Trond Myklebustac396122010-11-15 20:26:22 -05004674 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675}
4676
4677static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4678{
4679 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4680 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004681 size_t hdrlen;
4682 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004683 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 int status;
4685
4686 status = decode_op_hdr(xdr, OP_READLINK);
4687 if (status)
4688 return status;
4689
4690 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004691 p = xdr_inline_decode(xdr, 4);
4692 if (unlikely(!p))
4693 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004694 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004696 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004697 return -ENAMETOOLONG;
4698 }
4699 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4700 recvd = req->rq_rcv_buf.len - hdrlen;
4701 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004702 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703 "count %u > recvd %u\n", len, recvd);
4704 return -EIO;
4705 }
4706 xdr_read_pages(xdr, len);
4707 /*
4708 * The XDR encode routine has set things up so that
4709 * the link text will be copied directly into the
4710 * buffer. We just have to do overflow-checking,
4711 * and and null-terminate the text (the VFS expects
4712 * null-termination).
4713 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004714 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004716out_overflow:
4717 print_overflow_msg(__func__, xdr);
4718 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719}
4720
4721static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4722{
4723 int status;
4724
4725 status = decode_op_hdr(xdr, OP_REMOVE);
4726 if (status)
4727 goto out;
4728 status = decode_change_info(xdr, cinfo);
4729out:
4730 return status;
4731}
4732
4733static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4734 struct nfs4_change_info *new_cinfo)
4735{
4736 int status;
4737
4738 status = decode_op_hdr(xdr, OP_RENAME);
4739 if (status)
4740 goto out;
4741 if ((status = decode_change_info(xdr, old_cinfo)))
4742 goto out;
4743 status = decode_change_info(xdr, new_cinfo);
4744out:
4745 return status;
4746}
4747
4748static int decode_renew(struct xdr_stream *xdr)
4749{
4750 return decode_op_hdr(xdr, OP_RENEW);
4751}
4752
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004753static int
4754decode_restorefh(struct xdr_stream *xdr)
4755{
4756 return decode_op_hdr(xdr, OP_RESTOREFH);
4757}
4758
J. Bruce Fields029d1052005-06-22 17:16:22 +00004759static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4760 size_t *acl_len)
4761{
Al Viro8687b632006-10-19 23:28:48 -07004762 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004763 uint32_t attrlen,
4764 bitmap[2] = {0};
4765 struct kvec *iov = req->rq_rcv_buf.head;
4766 int status;
4767
4768 *acl_len = 0;
4769 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4770 goto out;
4771 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4772 goto out;
4773 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4774 goto out;
4775
4776 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4777 return -EIO;
4778 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004779 size_t hdrlen;
4780 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004781
4782 /* We ignore &savep and don't do consistency checks on
4783 * the attr length. Let userspace figure it out.... */
4784 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4785 recvd = req->rq_rcv_buf.len - hdrlen;
4786 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004787 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004788 " acl reply: attrlen %u > recvd %u\n",
4789 attrlen, recvd);
4790 return -EINVAL;
4791 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004792 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004793 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004794 } else
4795 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004796
4797out:
4798 return status;
4799}
4800
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801static int
4802decode_savefh(struct xdr_stream *xdr)
4803{
4804 return decode_op_hdr(xdr, OP_SAVEFH);
4805}
4806
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004807static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808{
Al Viro8687b632006-10-19 23:28:48 -07004809 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810 uint32_t bmlen;
4811 int status;
4812
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 status = decode_op_hdr(xdr, OP_SETATTR);
4814 if (status)
4815 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004816 p = xdr_inline_decode(xdr, 4);
4817 if (unlikely(!p))
4818 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004819 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004820 p = xdr_inline_decode(xdr, bmlen << 2);
4821 if (likely(p))
4822 return 0;
4823out_overflow:
4824 print_overflow_msg(__func__, xdr);
4825 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826}
4827
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004828static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829{
Al Viro8687b632006-10-19 23:28:48 -07004830 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831 uint32_t opnum;
4832 int32_t nfserr;
4833
Benny Halevyc0eae662009-08-14 17:20:14 +03004834 p = xdr_inline_decode(xdr, 8);
4835 if (unlikely(!p))
4836 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004837 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004839 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004840 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 return -EIO;
4842 }
Benny Halevycccddf42009-08-14 17:20:19 +03004843 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004845 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4846 if (unlikely(!p))
4847 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004848 p = xdr_decode_hyper(p, &res->clientid);
4849 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850 } else if (nfserr == NFSERR_CLID_INUSE) {
4851 uint32_t len;
4852
4853 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004854 p = xdr_inline_decode(xdr, 4);
4855 if (unlikely(!p))
4856 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004857 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004858 p = xdr_inline_decode(xdr, len);
4859 if (unlikely(!p))
4860 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861
4862 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004863 p = xdr_inline_decode(xdr, 4);
4864 if (unlikely(!p))
4865 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004866 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004867 p = xdr_inline_decode(xdr, len);
4868 if (unlikely(!p))
4869 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870 return -NFSERR_CLID_INUSE;
4871 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004872 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873
4874 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004875out_overflow:
4876 print_overflow_msg(__func__, xdr);
4877 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004878}
4879
4880static int decode_setclientid_confirm(struct xdr_stream *xdr)
4881{
4882 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4883}
4884
4885static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4886{
Al Viro8687b632006-10-19 23:28:48 -07004887 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888 int status;
4889
4890 status = decode_op_hdr(xdr, OP_WRITE);
4891 if (status)
4892 return status;
4893
Benny Halevyc0eae662009-08-14 17:20:14 +03004894 p = xdr_inline_decode(xdr, 16);
4895 if (unlikely(!p))
4896 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004897 res->count = be32_to_cpup(p++);
4898 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004899 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004901out_overflow:
4902 print_overflow_msg(__func__, xdr);
4903 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904}
4905
4906static int decode_delegreturn(struct xdr_stream *xdr)
4907{
4908 return decode_op_hdr(xdr, OP_DELEGRETURN);
4909}
4910
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004911static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
4912{
4913 __be32 *p;
4914
4915 p = xdr_inline_decode(xdr, 4);
4916 if (unlikely(!p))
4917 goto out_overflow;
4918 flavor->gss.sec_oid4.len = be32_to_cpup(p);
4919 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
4920 goto out_err;
4921
4922 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
4923 if (unlikely(!p))
4924 goto out_overflow;
4925 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
4926
4927 p = xdr_inline_decode(xdr, 8);
4928 if (unlikely(!p))
4929 goto out_overflow;
4930 flavor->gss.qop4 = be32_to_cpup(p++);
4931 flavor->gss.service = be32_to_cpup(p);
4932
4933 return 0;
4934
4935out_overflow:
4936 print_overflow_msg(__func__, xdr);
4937 return -EIO;
4938out_err:
4939 return -EINVAL;
4940}
4941
4942static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
4943{
4944 struct nfs4_secinfo_flavor *sec_flavor;
4945 int status;
4946 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004947 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004948
4949 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04004950 if (status)
4951 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004952 p = xdr_inline_decode(xdr, 4);
4953 if (unlikely(!p))
4954 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004955
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004956 res->flavors->num_flavors = 0;
4957 num_flavors = be32_to_cpup(p);
4958
4959 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004960 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004961 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004962 break;
4963
4964 p = xdr_inline_decode(xdr, 4);
4965 if (unlikely(!p))
4966 goto out_overflow;
4967 sec_flavor->flavor = be32_to_cpup(p);
4968
4969 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04004970 status = decode_secinfo_gss(xdr, sec_flavor);
4971 if (status)
4972 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004973 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004974 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004975 }
4976
Bryan Schumaker613e9012011-04-27 15:28:44 -04004977out:
4978 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004979out_overflow:
4980 print_overflow_msg(__func__, xdr);
4981 return -EIO;
4982}
4983
Benny Halevy99fe60d2009-04-01 09:22:29 -04004984#if defined(CONFIG_NFS_V4_1)
4985static int decode_exchange_id(struct xdr_stream *xdr,
4986 struct nfs41_exchange_id_res *res)
4987{
4988 __be32 *p;
4989 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004990 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004991 int status;
4992 struct nfs_client *clp = res->client;
4993
4994 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4995 if (status)
4996 return status;
4997
Benny Halevyc0eae662009-08-14 17:20:14 +03004998 p = xdr_inline_decode(xdr, 8);
4999 if (unlikely(!p))
5000 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005001 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005002 p = xdr_inline_decode(xdr, 12);
5003 if (unlikely(!p))
5004 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005005 clp->cl_seqid = be32_to_cpup(p++);
5006 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005007
5008 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005009 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005010 if (dummy != SP4_NONE)
5011 return -EIO;
5012
5013 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005014 p = xdr_inline_decode(xdr, 8);
5015 if (unlikely(!p))
5016 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005017
5018 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005019 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5020 if (unlikely(status))
5021 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005022
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005023 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005024 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5025 if (unlikely(status))
5026 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005027
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005028 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5029 return -EIO;
5030
5031 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5032 res->server_scope->server_scope_sz = dummy;
5033
Benny Halevy99fe60d2009-04-01 09:22:29 -04005034 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03005035 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5036 if (unlikely(status))
5037 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005038
5039 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005040out_overflow:
5041 print_overflow_msg(__func__, xdr);
5042 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005043}
Andy Adamsonfc931582009-04-01 09:22:31 -04005044
5045static int decode_chan_attrs(struct xdr_stream *xdr,
5046 struct nfs4_channel_attrs *attrs)
5047{
5048 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005049 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005050
Benny Halevyc0eae662009-08-14 17:20:14 +03005051 p = xdr_inline_decode(xdr, 28);
5052 if (unlikely(!p))
5053 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005054 val = be32_to_cpup(p++); /* headerpadsz */
5055 if (val)
5056 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005057 attrs->max_rqst_sz = be32_to_cpup(p++);
5058 attrs->max_resp_sz = be32_to_cpup(p++);
5059 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5060 attrs->max_ops = be32_to_cpup(p++);
5061 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005062 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005063 if (unlikely(nr_attrs > 1)) {
5064 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
5065 __func__, nr_attrs);
5066 return -EINVAL;
5067 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005068 if (nr_attrs == 1) {
5069 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5070 if (unlikely(!p))
5071 goto out_overflow;
5072 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005073 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005074out_overflow:
5075 print_overflow_msg(__func__, xdr);
5076 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005077}
5078
Benny Halevye78291e2009-08-14 17:20:00 +03005079static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5080{
5081 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005082}
5083
5084static int decode_create_session(struct xdr_stream *xdr,
5085 struct nfs41_create_session_res *res)
5086{
5087 __be32 *p;
5088 int status;
5089 struct nfs_client *clp = res->client;
5090 struct nfs4_session *session = clp->cl_session;
5091
5092 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005093 if (!status)
5094 status = decode_sessionid(xdr, &session->sess_id);
5095 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005096 return status;
5097
Andy Adamsonfc931582009-04-01 09:22:31 -04005098 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005099 p = xdr_inline_decode(xdr, 8);
5100 if (unlikely(!p))
5101 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005102 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005103 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005104
5105 /* Channel attributes */
5106 status = decode_chan_attrs(xdr, &session->fc_attrs);
5107 if (!status)
5108 status = decode_chan_attrs(xdr, &session->bc_attrs);
5109 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005110out_overflow:
5111 print_overflow_msg(__func__, xdr);
5112 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005113}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005114
5115static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5116{
5117 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5118}
Ricardo Labiaga18019752009-12-05 16:08:40 -05005119
5120static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5121{
5122 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5123}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005124#endif /* CONFIG_NFS_V4_1 */
5125
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005126static int decode_sequence(struct xdr_stream *xdr,
5127 struct nfs4_sequence_res *res,
5128 struct rpc_rqst *rqstp)
5129{
5130#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005131 struct nfs4_sessionid id;
5132 u32 dummy;
5133 int status;
5134 __be32 *p;
5135
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005136 if (!res->sr_session)
5137 return 0;
5138
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005139 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005140 if (!status)
5141 status = decode_sessionid(xdr, &id);
5142 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005143 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005144
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005145 /*
5146 * If the server returns different values for sessionID, slotID or
5147 * sequence number, the server is looney tunes.
5148 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005149 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005150
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005151 if (memcmp(id.data, res->sr_session->sess_id.data,
5152 NFS4_MAX_SESSIONID_LEN)) {
5153 dprintk("%s Invalid session id\n", __func__);
5154 goto out_err;
5155 }
Benny Halevye78291e2009-08-14 17:20:00 +03005156
Benny Halevyc0eae662009-08-14 17:20:14 +03005157 p = xdr_inline_decode(xdr, 20);
5158 if (unlikely(!p))
5159 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005160
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005161 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005162 dummy = be32_to_cpup(p++);
Benny Halevydfb4f302010-09-24 09:17:01 -04005163 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005164 dprintk("%s Invalid sequence number\n", __func__);
5165 goto out_err;
5166 }
5167 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005168 dummy = be32_to_cpup(p++);
Benny Halevydfb4f302010-09-24 09:17:01 -04005169 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005170 dprintk("%s Invalid slot id\n", __func__);
5171 goto out_err;
5172 }
5173 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005174 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005175 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005176 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005177 /* result flags */
5178 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005179 status = 0;
5180out_err:
5181 res->sr_status = status;
5182 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005183out_overflow:
5184 print_overflow_msg(__func__, xdr);
5185 status = -EIO;
5186 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005187#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005188 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005189#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005190}
5191
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005192#if defined(CONFIG_NFS_V4_1)
5193
5194static int decode_getdeviceinfo(struct xdr_stream *xdr,
5195 struct pnfs_device *pdev)
5196{
5197 __be32 *p;
5198 uint32_t len, type;
5199 int status;
5200
5201 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5202 if (status) {
5203 if (status == -ETOOSMALL) {
5204 p = xdr_inline_decode(xdr, 4);
5205 if (unlikely(!p))
5206 goto out_overflow;
5207 pdev->mincount = be32_to_cpup(p);
5208 dprintk("%s: Min count too small. mincnt = %u\n",
5209 __func__, pdev->mincount);
5210 }
5211 return status;
5212 }
5213
5214 p = xdr_inline_decode(xdr, 8);
5215 if (unlikely(!p))
5216 goto out_overflow;
5217 type = be32_to_cpup(p++);
5218 if (type != pdev->layout_type) {
5219 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5220 __func__, pdev->layout_type, type);
5221 return -EINVAL;
5222 }
5223 /*
5224 * Get the length of the opaque device_addr4. xdr_read_pages places
5225 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5226 * and places the remaining xdr data in xdr_buf->tail
5227 */
5228 pdev->mincount = be32_to_cpup(p);
5229 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5230
5231 /* Parse notification bitmap, verifying that it is zero. */
5232 p = xdr_inline_decode(xdr, 4);
5233 if (unlikely(!p))
5234 goto out_overflow;
5235 len = be32_to_cpup(p);
5236 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005237 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005238
5239 p = xdr_inline_decode(xdr, 4 * len);
5240 if (unlikely(!p))
5241 goto out_overflow;
5242 for (i = 0; i < len; i++, p++) {
5243 if (be32_to_cpup(p)) {
5244 dprintk("%s: notifications not supported\n",
5245 __func__);
5246 return -EIO;
5247 }
5248 }
5249 }
5250 return 0;
5251out_overflow:
5252 print_overflow_msg(__func__, xdr);
5253 return -EIO;
5254}
5255
5256static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5257 struct nfs4_layoutget_res *res)
5258{
5259 __be32 *p;
5260 int status;
5261 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005262 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5263 struct kvec *iov = rcvbuf->head;
5264 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005265
5266 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5267 if (status)
5268 return status;
5269 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5270 if (unlikely(!p))
5271 goto out_overflow;
5272 res->return_on_close = be32_to_cpup(p++);
5273 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5274 layout_count = be32_to_cpup(p);
5275 if (!layout_count) {
5276 dprintk("%s: server responded with empty layout array\n",
5277 __func__);
5278 return -EINVAL;
5279 }
5280
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005281 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005282 if (unlikely(!p))
5283 goto out_overflow;
5284 p = xdr_decode_hyper(p, &res->range.offset);
5285 p = xdr_decode_hyper(p, &res->range.length);
5286 res->range.iomode = be32_to_cpup(p++);
5287 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005288 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005289
5290 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5291 __func__,
5292 (unsigned long)res->range.offset,
5293 (unsigned long)res->range.length,
5294 res->range.iomode,
5295 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005296 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005297
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005298 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5299 recvd = req->rq_rcv_buf.len - hdrlen;
5300 if (res->layoutp->len > recvd) {
5301 dprintk("NFS: server cheating in layoutget reply: "
5302 "layout len %u > recvd %u\n",
5303 res->layoutp->len, recvd);
5304 return -EINVAL;
5305 }
5306
5307 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005308
5309 if (layout_count > 1) {
5310 /* We only handle a length one array at the moment. Any
5311 * further entries are just ignored. Note that this means
5312 * the client may see a response that is less than the
5313 * minimum it requested.
5314 */
5315 dprintk("%s: server responded with %d layouts, dropping tail\n",
5316 __func__, layout_count);
5317 }
5318
5319 return 0;
5320out_overflow:
5321 print_overflow_msg(__func__, xdr);
5322 return -EIO;
5323}
Andy Adamson863a3c62011-03-23 13:27:54 +00005324
Benny Halevycbe82602011-05-22 19:52:37 +03005325static int decode_layoutreturn(struct xdr_stream *xdr,
5326 struct nfs4_layoutreturn_res *res)
5327{
5328 __be32 *p;
5329 int status;
5330
5331 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5332 if (status)
5333 return status;
5334 p = xdr_inline_decode(xdr, 4);
5335 if (unlikely(!p))
5336 goto out_overflow;
5337 res->lrs_present = be32_to_cpup(p);
5338 if (res->lrs_present)
5339 status = decode_stateid(xdr, &res->stateid);
5340 return status;
5341out_overflow:
5342 print_overflow_msg(__func__, xdr);
5343 return -EIO;
5344}
5345
Andy Adamson863a3c62011-03-23 13:27:54 +00005346static int decode_layoutcommit(struct xdr_stream *xdr,
5347 struct rpc_rqst *req,
5348 struct nfs4_layoutcommit_res *res)
5349{
5350 __be32 *p;
5351 __u32 sizechanged;
5352 int status;
5353
5354 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5355 if (status)
5356 return status;
5357
5358 p = xdr_inline_decode(xdr, 4);
5359 if (unlikely(!p))
5360 goto out_overflow;
5361 sizechanged = be32_to_cpup(p);
5362
5363 if (sizechanged) {
5364 /* throw away new size */
5365 p = xdr_inline_decode(xdr, 8);
5366 if (unlikely(!p))
5367 goto out_overflow;
5368 }
5369 return 0;
5370out_overflow:
5371 print_overflow_msg(__func__, xdr);
5372 return -EIO;
5373}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005374#endif /* CONFIG_NFS_V4_1 */
5375
Linus Torvalds1da177e2005-04-16 15:20:36 -07005376/*
Benny Halevy49c25592008-12-23 16:06:16 -05005377 * END OF "GENERIC" DECODE ROUTINES.
5378 */
5379
5380/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005381 * Decode OPEN_DOWNGRADE response
5382 */
Chuck Leverbf269552010-12-14 14:59:29 +00005383static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5384 struct xdr_stream *xdr,
5385 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005386{
Andy Adamson05d564f2008-12-23 16:06:15 -05005387 struct compound_hdr hdr;
5388 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389
Chuck Leverbf269552010-12-14 14:59:29 +00005390 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005391 if (status)
5392 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005393 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005394 if (status)
5395 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005396 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005397 if (status)
5398 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005399 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005400 if (status != 0)
5401 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005402 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005403 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005405 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406}
5407
5408/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005409 * Decode ACCESS response
5410 */
Chuck Leverbf269552010-12-14 14:59:29 +00005411static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5412 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414 struct compound_hdr hdr;
5415 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005416
Chuck Leverbf269552010-12-14 14:59:29 +00005417 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005418 if (status)
5419 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005420 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005421 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005422 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005423 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005424 if (status != 0)
5425 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005426 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005427 if (status != 0)
5428 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005429 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005430 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005431out:
5432 return status;
5433}
5434
5435/*
5436 * Decode LOOKUP response
5437 */
Chuck Leverbf269552010-12-14 14:59:29 +00005438static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5439 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005440{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005441 struct compound_hdr hdr;
5442 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005443
Chuck Leverbf269552010-12-14 14:59:29 +00005444 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005445 if (status)
5446 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005447 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005448 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005449 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005450 status = decode_putfh(xdr);
5451 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005452 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005453 status = decode_lookup(xdr);
5454 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005455 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005456 status = decode_getfh(xdr, res->fh);
5457 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005458 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005459 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005460 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005461out:
5462 return status;
5463}
5464
5465/*
5466 * Decode LOOKUP_ROOT response
5467 */
Chuck Leverbf269552010-12-14 14:59:29 +00005468static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5469 struct xdr_stream *xdr,
5470 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005471{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005472 struct compound_hdr hdr;
5473 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005474
Chuck Leverbf269552010-12-14 14:59:29 +00005475 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005476 if (status)
5477 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005478 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005479 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005480 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005481 status = decode_putrootfh(xdr);
5482 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005483 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005484 status = decode_getfh(xdr, res->fh);
5485 if (status == 0)
5486 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005487 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005488out:
5489 return status;
5490}
5491
5492/*
5493 * Decode REMOVE response
5494 */
Chuck Leverbf269552010-12-14 14:59:29 +00005495static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5496 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005497{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005498 struct compound_hdr hdr;
5499 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005500
Chuck Leverbf269552010-12-14 14:59:29 +00005501 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005502 if (status)
5503 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005504 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005505 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005506 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005507 status = decode_putfh(xdr);
5508 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005509 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005510 status = decode_remove(xdr, &res->cinfo);
5511 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005512 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005513 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005514 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005515out:
5516 return status;
5517}
5518
5519/*
5520 * Decode RENAME response
5521 */
Chuck Leverbf269552010-12-14 14:59:29 +00005522static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5523 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005525 struct compound_hdr hdr;
5526 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005527
Chuck Leverbf269552010-12-14 14:59:29 +00005528 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005529 if (status)
5530 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005531 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005532 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005533 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005534 status = decode_putfh(xdr);
5535 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005536 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005537 status = decode_savefh(xdr);
5538 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005539 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005540 status = decode_putfh(xdr);
5541 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005542 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005543 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5544 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005545 goto out;
5546 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005547 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005548 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005549 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005550 status = decode_restorefh(xdr);
5551 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005552 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005553 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005554 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005555out:
5556 return status;
5557}
5558
5559/*
5560 * Decode LINK response
5561 */
Chuck Leverbf269552010-12-14 14:59:29 +00005562static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5563 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005564{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005565 struct compound_hdr hdr;
5566 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005567
Chuck Leverbf269552010-12-14 14:59:29 +00005568 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005569 if (status)
5570 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005571 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005572 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005573 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005574 status = decode_putfh(xdr);
5575 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005577 status = decode_savefh(xdr);
5578 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005579 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005580 status = decode_putfh(xdr);
5581 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005582 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005583 status = decode_link(xdr, &res->cinfo);
5584 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005585 goto out;
5586 /*
5587 * Note order: OP_LINK leaves the directory as the current
5588 * filehandle.
5589 */
Chuck Leverbf269552010-12-14 14:59:29 +00005590 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005591 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005592 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005593 status = decode_restorefh(xdr);
5594 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005595 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005596 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005597 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598out:
5599 return status;
5600}
5601
5602/*
5603 * Decode CREATE response
5604 */
Chuck Leverbf269552010-12-14 14:59:29 +00005605static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5606 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005607{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005608 struct compound_hdr hdr;
5609 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005610
Chuck Leverbf269552010-12-14 14:59:29 +00005611 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005612 if (status)
5613 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005614 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005615 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005616 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005617 status = decode_putfh(xdr);
5618 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005619 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005620 status = decode_savefh(xdr);
5621 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005622 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005623 status = decode_create(xdr, &res->dir_cinfo);
5624 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005625 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005626 status = decode_getfh(xdr, res->fh);
5627 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005628 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005629 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005630 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005631 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005632 status = decode_restorefh(xdr);
5633 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005634 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005635 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005636 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005637out:
5638 return status;
5639}
5640
5641/*
5642 * Decode SYMLINK response
5643 */
Chuck Leverbf269552010-12-14 14:59:29 +00005644static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5645 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005646{
Chuck Leverbf269552010-12-14 14:59:29 +00005647 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648}
5649
5650/*
5651 * Decode GETATTR response
5652 */
Chuck Leverbf269552010-12-14 14:59:29 +00005653static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5654 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005655{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005656 struct compound_hdr hdr;
5657 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005658
Chuck Leverbf269552010-12-14 14:59:29 +00005659 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005660 if (status)
5661 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005662 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005663 if (status)
5664 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005665 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005666 if (status)
5667 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005668 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005669 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005670out:
5671 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005672}
5673
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005674/*
5675 * Encode an SETACL request
5676 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005677static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5678 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005679{
Andy Adamson05d564f2008-12-23 16:06:15 -05005680 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005681 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005682 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005683
Chuck Lever9f06c712010-12-14 14:59:18 +00005684 encode_compound_hdr(xdr, req, &hdr);
5685 encode_sequence(xdr, &args->seq_args, &hdr);
5686 encode_putfh(xdr, args->fh, &hdr);
5687 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005688 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005689}
Andy Adamson05d564f2008-12-23 16:06:15 -05005690
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005691/*
5692 * Decode SETACL response
5693 */
5694static int
Chuck Leverbf269552010-12-14 14:59:29 +00005695nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005696 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005697{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005698 struct compound_hdr hdr;
5699 int status;
5700
Chuck Leverbf269552010-12-14 14:59:29 +00005701 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005702 if (status)
5703 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005704 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005705 if (status)
5706 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005707 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005708 if (status)
5709 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005710 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005711out:
5712 return status;
5713}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005714
5715/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005716 * Decode GETACL response
5717 */
5718static int
Chuck Leverbf269552010-12-14 14:59:29 +00005719nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005720 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005721{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005722 struct compound_hdr hdr;
5723 int status;
5724
Chuck Leverbf269552010-12-14 14:59:29 +00005725 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005726 if (status)
5727 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005728 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005729 if (status)
5730 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005731 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005732 if (status)
5733 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005734 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005735
5736out:
5737 return status;
5738}
5739
5740/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005741 * Decode CLOSE response
5742 */
Chuck Leverbf269552010-12-14 14:59:29 +00005743static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5744 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745{
Andy Adamson05d564f2008-12-23 16:06:15 -05005746 struct compound_hdr hdr;
5747 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005748
Chuck Leverbf269552010-12-14 14:59:29 +00005749 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005750 if (status)
5751 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005752 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005753 if (status)
5754 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005755 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005756 if (status)
5757 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005758 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005759 if (status != 0)
5760 goto out;
5761 /*
5762 * Note: Server may do delete on close for this file
5763 * in which case the getattr call will fail with
5764 * an ESTALE error. Shouldn't be a problem,
5765 * though, since fattr->valid will remain unset.
5766 */
Chuck Leverbf269552010-12-14 14:59:29 +00005767 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005768 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005769out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005770 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005771}
5772
5773/*
5774 * Decode OPEN response
5775 */
Chuck Leverbf269552010-12-14 14:59:29 +00005776static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5777 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005778{
Andy Adamson05d564f2008-12-23 16:06:15 -05005779 struct compound_hdr hdr;
5780 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005781
Chuck Leverbf269552010-12-14 14:59:29 +00005782 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005783 if (status)
5784 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005785 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005786 if (status)
5787 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005788 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005789 if (status)
5790 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005791 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005792 if (status)
5793 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005794 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005795 if (status)
5796 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005797 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005798 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005799 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005800 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005801 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005802 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005803 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005804 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005805 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005806out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005807 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005808}
5809
5810/*
5811 * Decode OPEN_CONFIRM response
5812 */
Chuck Leverbf269552010-12-14 14:59:29 +00005813static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5814 struct xdr_stream *xdr,
5815 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005816{
Andy Adamson05d564f2008-12-23 16:06:15 -05005817 struct compound_hdr hdr;
5818 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005819
Chuck Leverbf269552010-12-14 14:59:29 +00005820 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005821 if (status)
5822 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005823 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005824 if (status)
5825 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005826 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005827out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005828 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829}
5830
5831/*
5832 * Decode OPEN response
5833 */
Chuck Leverbf269552010-12-14 14:59:29 +00005834static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5835 struct xdr_stream *xdr,
5836 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005837{
Andy Adamson05d564f2008-12-23 16:06:15 -05005838 struct compound_hdr hdr;
5839 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005840
Chuck Leverbf269552010-12-14 14:59:29 +00005841 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005842 if (status)
5843 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005844 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005845 if (status)
5846 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005847 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005848 if (status)
5849 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005850 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005851 if (status)
5852 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005853 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005854 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005856 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857}
5858
5859/*
5860 * Decode SETATTR response
5861 */
Chuck Leverbf269552010-12-14 14:59:29 +00005862static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5863 struct xdr_stream *xdr,
5864 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005865{
Andy Adamson05d564f2008-12-23 16:06:15 -05005866 struct compound_hdr hdr;
5867 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868
Chuck Leverbf269552010-12-14 14:59:29 +00005869 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005870 if (status)
5871 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005872 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005873 if (status)
5874 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005875 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005876 if (status)
5877 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005878 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005879 if (status)
5880 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005881 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005882 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005883out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005884 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885}
5886
5887/*
5888 * Decode LOCK response
5889 */
Chuck Leverbf269552010-12-14 14:59:29 +00005890static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5891 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005892{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005893 struct compound_hdr hdr;
5894 int status;
5895
Chuck Leverbf269552010-12-14 14:59:29 +00005896 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005897 if (status)
5898 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005899 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005900 if (status)
5901 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005902 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903 if (status)
5904 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005905 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005906out:
5907 return status;
5908}
5909
5910/*
5911 * Decode LOCKT response
5912 */
Chuck Leverbf269552010-12-14 14:59:29 +00005913static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5914 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005915{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005916 struct compound_hdr hdr;
5917 int status;
5918
Chuck Leverbf269552010-12-14 14:59:29 +00005919 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005920 if (status)
5921 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005922 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005923 if (status)
5924 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005925 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926 if (status)
5927 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005928 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005929out:
5930 return status;
5931}
5932
5933/*
5934 * Decode LOCKU response
5935 */
Chuck Leverbf269552010-12-14 14:59:29 +00005936static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5937 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005938{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005939 struct compound_hdr hdr;
5940 int status;
5941
Chuck Leverbf269552010-12-14 14:59:29 +00005942 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005943 if (status)
5944 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005945 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005946 if (status)
5947 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005948 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949 if (status)
5950 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005951 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005952out:
5953 return status;
5954}
5955
Chuck Leverbf269552010-12-14 14:59:29 +00005956static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5957 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005958{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005959 struct compound_hdr hdr;
5960 int status;
5961
Chuck Leverbf269552010-12-14 14:59:29 +00005962 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005963 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005964 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005965 return status;
5966}
5967
Linus Torvalds1da177e2005-04-16 15:20:36 -07005968/*
5969 * Decode READLINK response
5970 */
Chuck Leverbf269552010-12-14 14:59:29 +00005971static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5972 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04005973 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005975 struct compound_hdr hdr;
5976 int status;
5977
Chuck Leverbf269552010-12-14 14:59:29 +00005978 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979 if (status)
5980 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005981 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005982 if (status)
5983 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005984 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005985 if (status)
5986 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005987 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005988out:
5989 return status;
5990}
5991
5992/*
5993 * Decode READDIR response
5994 */
Chuck Leverbf269552010-12-14 14:59:29 +00005995static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5996 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005998 struct compound_hdr hdr;
5999 int status;
6000
Chuck Leverbf269552010-12-14 14:59:29 +00006001 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002 if (status)
6003 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006004 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006005 if (status)
6006 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006007 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006008 if (status)
6009 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006010 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011out:
6012 return status;
6013}
6014
6015/*
6016 * Decode Read response
6017 */
Chuck Leverbf269552010-12-14 14:59:29 +00006018static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6019 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021 struct compound_hdr hdr;
6022 int status;
6023
Chuck Leverbf269552010-12-14 14:59:29 +00006024 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006025 if (status)
6026 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006027 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006028 if (status)
6029 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006030 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006031 if (status)
6032 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006033 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034 if (!status)
6035 status = res->count;
6036out:
6037 return status;
6038}
6039
6040/*
6041 * Decode WRITE response
6042 */
Chuck Leverbf269552010-12-14 14:59:29 +00006043static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6044 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006045{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046 struct compound_hdr hdr;
6047 int status;
6048
Chuck Leverbf269552010-12-14 14:59:29 +00006049 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006050 if (status)
6051 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006052 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006053 if (status)
6054 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006055 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056 if (status)
6057 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006058 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006059 if (status)
6060 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006061 if (res->fattr)
6062 decode_getfattr(xdr, res->fattr, res->server,
6063 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006064 if (!status)
6065 status = res->count;
6066out:
6067 return status;
6068}
6069
6070/*
6071 * Decode COMMIT response
6072 */
Chuck Leverbf269552010-12-14 14:59:29 +00006073static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6074 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006075{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006076 struct compound_hdr hdr;
6077 int status;
6078
Chuck Leverbf269552010-12-14 14:59:29 +00006079 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006080 if (status)
6081 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006082 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006083 if (status)
6084 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006085 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086 if (status)
6087 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006088 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006089 if (status)
6090 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006091 if (res->fattr)
6092 decode_getfattr(xdr, res->fattr, res->server,
6093 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006094out:
6095 return status;
6096}
6097
6098/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006099 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006100 */
Chuck Leverbf269552010-12-14 14:59:29 +00006101static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006102 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104 struct compound_hdr hdr;
6105 int status;
6106
Chuck Leverbf269552010-12-14 14:59:29 +00006107 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006109 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006110 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006111 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006112 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006113 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114 return status;
6115}
6116
6117/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006118 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006119 */
Chuck Leverbf269552010-12-14 14:59:29 +00006120static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006121 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123 struct compound_hdr hdr;
6124 int status;
6125
Chuck Leverbf269552010-12-14 14:59:29 +00006126 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006128 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006129 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006130 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006131 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006132 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133 return status;
6134}
6135
6136/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006137 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006138 */
Chuck Leverbf269552010-12-14 14:59:29 +00006139static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006140 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006142 struct compound_hdr hdr;
6143 int status;
6144
Chuck Leverbf269552010-12-14 14:59:29 +00006145 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006147 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006148 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006149 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006151 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152 return status;
6153}
6154
6155/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006156 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006157 */
Chuck Leverbf269552010-12-14 14:59:29 +00006158static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6159 struct xdr_stream *xdr,
6160 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006162 struct compound_hdr hdr;
6163 int status;
6164
Chuck Leverbf269552010-12-14 14:59:29 +00006165 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006166 if (status)
6167 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006168 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006169 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006171 status = decode_putfh(xdr);
6172 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006173 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006174 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175out:
6176 return status;
6177}
6178
6179/*
6180 * Decode RENEW response
6181 */
Chuck Leverbf269552010-12-14 14:59:29 +00006182static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6183 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006184{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185 struct compound_hdr hdr;
6186 int status;
6187
Chuck Leverbf269552010-12-14 14:59:29 +00006188 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006190 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191 return status;
6192}
6193
6194/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006195 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196 */
Chuck Leverbf269552010-12-14 14:59:29 +00006197static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6198 struct xdr_stream *xdr,
6199 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201 struct compound_hdr hdr;
6202 int status;
6203
Chuck Leverbf269552010-12-14 14:59:29 +00006204 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006206 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207 return status;
6208}
6209
6210/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006211 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212 */
Chuck Leverbf269552010-12-14 14:59:29 +00006213static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6214 struct xdr_stream *xdr,
6215 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217 struct compound_hdr hdr;
6218 int status;
6219
Chuck Leverbf269552010-12-14 14:59:29 +00006220 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006221 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006222 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006223 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006224 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006226 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227 return status;
6228}
6229
6230/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006231 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232 */
Chuck Leverbf269552010-12-14 14:59:29 +00006233static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6234 struct xdr_stream *xdr,
6235 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237 struct compound_hdr hdr;
6238 int status;
6239
Chuck Leverbf269552010-12-14 14:59:29 +00006240 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006241 if (status)
6242 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006243 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006244 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006245 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006246 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006247 if (status != 0)
6248 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006250 if (status != 0)
6251 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006252 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006253 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01006254out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006255 return status;
6256}
6257
Trond Myklebust683b57b2006-06-09 09:34:22 -04006258/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006259 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006260 */
Chuck Leverbf269552010-12-14 14:59:29 +00006261static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6262 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006263 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006264{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006265 struct compound_hdr hdr;
6266 int status;
6267
Chuck Leverbf269552010-12-14 14:59:29 +00006268 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006269 if (status)
6270 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006271 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006272 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006273 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_putfh(xdr);
6275 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006276 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_lookup(xdr);
6278 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006280 xdr_enter_page(xdr, PAGE_SIZE);
6281 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006282 res->fs_locations->server,
6283 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006284out:
6285 return status;
6286}
6287
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006288/*
6289 * Decode SECINFO response
6290 */
6291static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6292 struct xdr_stream *xdr,
6293 struct nfs4_secinfo_res *res)
6294{
6295 struct compound_hdr hdr;
6296 int status;
6297
6298 status = decode_compound_hdr(xdr, &hdr);
6299 if (status)
6300 goto out;
6301 status = decode_sequence(xdr, &res->seq_res, rqstp);
6302 if (status)
6303 goto out;
6304 status = decode_putfh(xdr);
6305 if (status)
6306 goto out;
6307 status = decode_secinfo(xdr, res);
6308 if (status)
6309 goto out;
6310out:
6311 return status;
6312}
6313
Benny Halevy99fe60d2009-04-01 09:22:29 -04006314#if defined(CONFIG_NFS_V4_1)
6315/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006316 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006317 */
Chuck Leverbf269552010-12-14 14:59:29 +00006318static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6319 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006320 void *res)
6321{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006322 struct compound_hdr hdr;
6323 int status;
6324
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006326 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006327 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006328 return status;
6329}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006330
6331/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006332 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006333 */
Chuck Leverbf269552010-12-14 14:59:29 +00006334static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6335 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006336 struct nfs41_create_session_res *res)
6337{
Andy Adamsonfc931582009-04-01 09:22:31 -04006338 struct compound_hdr hdr;
6339 int status;
6340
Chuck Leverbf269552010-12-14 14:59:29 +00006341 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006342 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006343 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006344 return status;
6345}
6346
6347/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006348 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006349 */
Chuck Leverbf269552010-12-14 14:59:29 +00006350static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6351 struct xdr_stream *xdr,
6352 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006353{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006354 struct compound_hdr hdr;
6355 int status;
6356
Chuck Leverbf269552010-12-14 14:59:29 +00006357 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006358 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006359 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006360 return status;
6361}
6362
6363/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006364 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006365 */
Chuck Leverbf269552010-12-14 14:59:29 +00006366static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6367 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006368 struct nfs4_sequence_res *res)
6369{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006370 struct compound_hdr hdr;
6371 int status;
6372
Chuck Leverbf269552010-12-14 14:59:29 +00006373 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006374 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006375 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006376 return status;
6377}
6378
6379/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006380 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006381 */
Chuck Leverbf269552010-12-14 14:59:29 +00006382static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6383 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006384 struct nfs4_get_lease_time_res *res)
6385{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006386 struct compound_hdr hdr;
6387 int status;
6388
Chuck Leverbf269552010-12-14 14:59:29 +00006389 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006390 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006391 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006392 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006394 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006395 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006396 return status;
6397}
Ricardo Labiaga18019752009-12-05 16:08:40 -05006398
6399/*
6400 * Decode RECLAIM_COMPLETE response
6401 */
Chuck Leverbf269552010-12-14 14:59:29 +00006402static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6403 struct xdr_stream *xdr,
Ricardo Labiaga18019752009-12-05 16:08:40 -05006404 struct nfs41_reclaim_complete_res *res)
6405{
Ricardo Labiaga18019752009-12-05 16:08:40 -05006406 struct compound_hdr hdr;
6407 int status;
6408
Chuck Leverbf269552010-12-14 14:59:29 +00006409 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006410 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006411 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006412 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga18019752009-12-05 16:08:40 -05006414 return status;
6415}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006416
6417/*
6418 * Decode GETDEVINFO response
6419 */
Chuck Leverbf269552010-12-14 14:59:29 +00006420static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6421 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006422 struct nfs4_getdeviceinfo_res *res)
6423{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006424 struct compound_hdr hdr;
6425 int status;
6426
Chuck Leverbf269552010-12-14 14:59:29 +00006427 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006428 if (status != 0)
6429 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006430 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006431 if (status != 0)
6432 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006434out:
6435 return status;
6436}
6437
6438/*
6439 * Decode LAYOUTGET response
6440 */
Chuck Leverbf269552010-12-14 14:59:29 +00006441static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6442 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006443 struct nfs4_layoutget_res *res)
6444{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006445 struct compound_hdr hdr;
6446 int status;
6447
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006449 if (status)
6450 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006451 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006452 if (status)
6453 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006454 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006455 if (status)
6456 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006457 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006458out:
6459 return status;
6460}
Andy Adamson863a3c62011-03-23 13:27:54 +00006461
6462/*
Benny Halevycbe82602011-05-22 19:52:37 +03006463 * Decode LAYOUTRETURN response
6464 */
6465static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6466 struct xdr_stream *xdr,
6467 struct nfs4_layoutreturn_res *res)
6468{
6469 struct compound_hdr hdr;
6470 int status;
6471
6472 status = decode_compound_hdr(xdr, &hdr);
6473 if (status)
6474 goto out;
6475 status = decode_sequence(xdr, &res->seq_res, rqstp);
6476 if (status)
6477 goto out;
6478 status = decode_putfh(xdr);
6479 if (status)
6480 goto out;
6481 status = decode_layoutreturn(xdr, res);
6482out:
6483 return status;
6484}
6485
6486/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006487 * Decode LAYOUTCOMMIT response
6488 */
6489static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6490 struct xdr_stream *xdr,
6491 struct nfs4_layoutcommit_res *res)
6492{
6493 struct compound_hdr hdr;
6494 int status;
6495
6496 status = decode_compound_hdr(xdr, &hdr);
6497 if (status)
6498 goto out;
6499 status = decode_sequence(xdr, &res->seq_res, rqstp);
6500 if (status)
6501 goto out;
6502 status = decode_putfh(xdr);
6503 if (status)
6504 goto out;
6505 status = decode_layoutcommit(xdr, rqstp, res);
6506 if (status)
6507 goto out;
6508 decode_getfattr(xdr, res->fattr, res->server,
6509 !RPC_IS_ASYNC(rqstp->rq_task));
6510out:
6511 return status;
6512}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006513
6514/*
6515 * Decode SECINFO_NO_NAME response
6516 */
6517static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6518 struct xdr_stream *xdr,
6519 struct nfs4_secinfo_res *res)
6520{
6521 struct compound_hdr hdr;
6522 int status;
6523
6524 status = decode_compound_hdr(xdr, &hdr);
6525 if (status)
6526 goto out;
6527 status = decode_sequence(xdr, &res->seq_res, rqstp);
6528 if (status)
6529 goto out;
6530 status = decode_putrootfh(xdr);
6531 if (status)
6532 goto out;
6533 status = decode_secinfo(xdr, res);
6534out:
6535 return status;
6536}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006537#endif /* CONFIG_NFS_V4_1 */
6538
Chuck Lever573c4e12010-12-14 14:58:11 +00006539/**
6540 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6541 * the local page cache.
6542 * @xdr: XDR stream where entry resides
6543 * @entry: buffer to fill in with entry data
6544 * @plus: boolean indicating whether this should be a readdirplus entry
6545 *
6546 * Returns zero if successful, otherwise a negative errno value is
6547 * returned.
6548 *
6549 * This function is not invoked during READDIR reply decoding, but
6550 * rather whenever an application invokes the getdents(2) system call
6551 * on a directory already in our cache.
6552 */
6553int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6554 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006555{
6556 uint32_t bitmap[2] = {0};
6557 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006558 __be32 *p = xdr_inline_decode(xdr, 4);
6559 if (unlikely(!p))
6560 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006561 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006562 p = xdr_inline_decode(xdr, 4);
6563 if (unlikely(!p))
6564 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006565 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006566 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006568 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569 }
6570
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006571 p = xdr_inline_decode(xdr, 12);
6572 if (unlikely(!p))
6573 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574 entry->prev_cookie = entry->cookie;
6575 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006576 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006577
Trond Myklebust9af8c222010-10-24 11:52:55 -04006578 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006579 if (unlikely(!p))
6580 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006581 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006582
6583 /*
6584 * In case the server doesn't return an inode number,
6585 * we fake one here. (We don't use inode number 0,
6586 * since glibc seems to choke on it...)
6587 */
6588 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006589 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590
Trond Myklebust9af8c222010-10-24 11:52:55 -04006591 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006592 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006593
6594 if (decode_attr_length(xdr, &len, &p) < 0)
6595 goto out_overflow;
6596
Chuck Lever573c4e12010-12-14 14:58:11 +00006597 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6598 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006599 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006600 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6601 entry->ino = entry->fattr->mounted_on_fileid;
6602 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006603 entry->ino = entry->fattr->fileid;
6604
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006605 entry->d_type = DT_UNKNOWN;
6606 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6607 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6608
Chuck Lever573c4e12010-12-14 14:58:11 +00006609 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006610
6611out_overflow:
6612 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006613 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006614}
6615
6616/*
6617 * We need to translate between nfs status return values and
6618 * the local errno values which may not be the same.
6619 */
6620static struct {
6621 int stat;
6622 int errno;
6623} nfs_errtbl[] = {
6624 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006625 { NFS4ERR_PERM, -EPERM },
6626 { NFS4ERR_NOENT, -ENOENT },
6627 { NFS4ERR_IO, -errno_NFSERR_IO},
6628 { NFS4ERR_NXIO, -ENXIO },
6629 { NFS4ERR_ACCESS, -EACCES },
6630 { NFS4ERR_EXIST, -EEXIST },
6631 { NFS4ERR_XDEV, -EXDEV },
6632 { NFS4ERR_NOTDIR, -ENOTDIR },
6633 { NFS4ERR_ISDIR, -EISDIR },
6634 { NFS4ERR_INVAL, -EINVAL },
6635 { NFS4ERR_FBIG, -EFBIG },
6636 { NFS4ERR_NOSPC, -ENOSPC },
6637 { NFS4ERR_ROFS, -EROFS },
6638 { NFS4ERR_MLINK, -EMLINK },
6639 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6640 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6641 { NFS4ERR_DQUOT, -EDQUOT },
6642 { NFS4ERR_STALE, -ESTALE },
6643 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006644 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6645 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6646 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006647 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006648 { NFS4ERR_BADTYPE, -EBADTYPE },
6649 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006650 { NFS4ERR_SYMLINK, -ELOOP },
6651 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6652 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006653 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006654};
6655
6656/*
6657 * Convert an NFS error code to a local one.
6658 * This one is used jointly by NFSv2 and NFSv3.
6659 */
6660static int
David Howells0a8ea432006-08-22 20:06:08 -04006661nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006662{
6663 int i;
6664 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6665 if (nfs_errtbl[i].stat == stat)
6666 return nfs_errtbl[i].errno;
6667 }
6668 if (stat <= 10000 || stat > 10100) {
6669 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006670 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006671 }
6672 /* If we cannot translate the error, the recovery routines should
6673 * handle it.
6674 * Note: remaining NFSv4 error codes have values > 10000, so should
6675 * not conflict with native Linux error codes.
6676 */
Benny Halevy856dff32008-03-31 17:39:06 +03006677 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006678}
6679
Linus Torvalds1da177e2005-04-16 15:20:36 -07006680#define PROC(proc, argtype, restype) \
6681[NFSPROC4_CLNT_##proc] = { \
6682 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006683 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006684 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006685 .p_arglen = NFS4_##argtype##_sz, \
6686 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006687 .p_statidx = NFSPROC4_CLNT_##proc, \
6688 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006689}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006690
6691struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006692 PROC(READ, enc_read, dec_read),
6693 PROC(WRITE, enc_write, dec_write),
6694 PROC(COMMIT, enc_commit, dec_commit),
6695 PROC(OPEN, enc_open, dec_open),
6696 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6697 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6698 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6699 PROC(CLOSE, enc_close, dec_close),
6700 PROC(SETATTR, enc_setattr, dec_setattr),
6701 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6702 PROC(RENEW, enc_renew, dec_renew),
6703 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6704 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6705 PROC(LOCK, enc_lock, dec_lock),
6706 PROC(LOCKT, enc_lockt, dec_lockt),
6707 PROC(LOCKU, enc_locku, dec_locku),
6708 PROC(ACCESS, enc_access, dec_access),
6709 PROC(GETATTR, enc_getattr, dec_getattr),
6710 PROC(LOOKUP, enc_lookup, dec_lookup),
6711 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6712 PROC(REMOVE, enc_remove, dec_remove),
6713 PROC(RENAME, enc_rename, dec_rename),
6714 PROC(LINK, enc_link, dec_link),
6715 PROC(SYMLINK, enc_symlink, dec_symlink),
6716 PROC(CREATE, enc_create, dec_create),
6717 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6718 PROC(STATFS, enc_statfs, dec_statfs),
6719 PROC(READLINK, enc_readlink, dec_readlink),
6720 PROC(READDIR, enc_readdir, dec_readdir),
6721 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6722 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6723 PROC(GETACL, enc_getacl, dec_getacl),
6724 PROC(SETACL, enc_setacl, dec_setacl),
6725 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6726 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006727 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006728#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006729 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6730 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6731 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6732 PROC(SEQUENCE, enc_sequence, dec_sequence),
6733 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6734 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6735 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6736 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00006737 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03006738 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006739 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006740#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006741};
6742
6743struct rpc_version nfs_version4 = {
6744 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006745 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006746 .procs = nfs4_procedures
6747};
6748
6749/*
6750 * Local variables:
6751 * c-basic-offset: 8
6752 * End:
6753 */