blob: f2421206435697b0459caf328d4554204f5edfe1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
47#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050048#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000049#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/nfs.h>
51#include <linux/nfs4.h>
52#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000054#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050055#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040056#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#define NFSDBG_FACILITY NFSDBG_XDR
59
60/* Mapping from NFS error code to "errno" error code. */
61#define errno_NFSERR_IO EIO
62
David Howells0a8ea432006-08-22 20:06:08 -040063static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
66#ifdef DEBUG
67#define NFS4_MAXTAGLEN 20
68#else
69#define NFS4_MAXTAGLEN 0
70#endif
71
Andy Adamson6c0195a2008-12-23 16:06:15 -050072/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 */
Trond Myklebustd035c362010-12-21 10:45:27 -050075#define open_owner_id_maxsz (1 + 1 + 4)
76#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040077#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
80#define op_encode_hdr_maxsz (1)
81#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
84#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
85#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
87 (NFS4_FHSIZE >> 2))
88#define decode_putfh_maxsz (op_decode_hdr_maxsz)
89#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
90#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
91#define encode_getfh_maxsz (op_encode_hdr_maxsz)
92#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
93 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000094#define nfs4_fattr_bitmap_maxsz 3
95#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
97#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040098#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
99#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000100/* This is based on getfattr, which uses the most attributes: */
101#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400102 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000103#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
104 nfs4_fattr_value_maxsz)
105#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400106#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
107 1 + 2 + 1 + \
108 nfs4_owner_maxsz + \
109 nfs4_group_maxsz + \
110 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define encode_savefh_maxsz (op_encode_hdr_maxsz)
112#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400113#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
114#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200115#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Bryan Schumaker7ebb9312011-03-24 17:12:30 +0000116#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
118#define decode_renew_maxsz (op_decode_hdr_maxsz)
119#define encode_setclientid_maxsz \
120 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500121 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
122 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
123 1 /* sc_prog */ + \
124 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
125 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
126 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define decode_setclientid_maxsz \
128 (op_decode_hdr_maxsz + \
129 2 + \
130 1024) /* large value for CLID_INUSE */
131#define encode_setclientid_confirm_maxsz \
132 (op_encode_hdr_maxsz + \
133 3 + (NFS4_VERIFIER_SIZE >> 2))
134#define decode_setclientid_confirm_maxsz \
135 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400136#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
137#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400138#define encode_share_access_maxsz \
139 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500140#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400141#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
142#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
143#define encode_open_maxsz (op_encode_hdr_maxsz + \
144 2 + encode_share_access_maxsz + 2 + \
145 open_owner_id_maxsz + \
146 encode_opentype_maxsz + \
147 encode_claim_null_maxsz)
148#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400149#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400150 decode_ace_maxsz)
151#define decode_change_info_maxsz (5)
152#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400153 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400154 decode_change_info_maxsz + 1 + \
155 nfs4_fattr_bitmap_maxsz + \
156 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400157#define encode_open_confirm_maxsz \
158 (op_encode_hdr_maxsz + \
159 encode_stateid_maxsz + 1)
160#define decode_open_confirm_maxsz \
161 (op_decode_hdr_maxsz + \
162 decode_stateid_maxsz)
163#define encode_open_downgrade_maxsz \
164 (op_encode_hdr_maxsz + \
165 encode_stateid_maxsz + 1 + \
166 encode_share_access_maxsz)
167#define decode_open_downgrade_maxsz \
168 (op_decode_hdr_maxsz + \
169 decode_stateid_maxsz)
170#define encode_close_maxsz (op_encode_hdr_maxsz + \
171 1 + encode_stateid_maxsz)
172#define decode_close_maxsz (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
175 encode_stateid_maxsz + \
176 encode_attrs_maxsz)
177#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
178 nfs4_fattr_bitmap_maxsz)
179#define encode_read_maxsz (op_encode_hdr_maxsz + \
180 encode_stateid_maxsz + 3)
181#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
182#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
183 2 + encode_verifier_maxsz + 5)
184#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
185 decode_verifier_maxsz)
186#define encode_readlink_maxsz (op_encode_hdr_maxsz)
187#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
188#define encode_write_maxsz (op_encode_hdr_maxsz + \
189 encode_stateid_maxsz + 4)
190#define decode_write_maxsz (op_decode_hdr_maxsz + \
191 2 + decode_verifier_maxsz)
192#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
193#define decode_commit_maxsz (op_decode_hdr_maxsz + \
194 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#define encode_remove_maxsz (op_encode_hdr_maxsz + \
196 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400197#define decode_remove_maxsz (op_decode_hdr_maxsz + \
198 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199#define encode_rename_maxsz (op_encode_hdr_maxsz + \
200 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400201#define decode_rename_maxsz (op_decode_hdr_maxsz + \
202 decode_change_info_maxsz + \
203 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#define encode_link_maxsz (op_encode_hdr_maxsz + \
205 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400206#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400207#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400208#define encode_lock_maxsz (op_encode_hdr_maxsz + \
209 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400210 1 + encode_stateid_maxsz + 1 + \
211 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400212#define decode_lock_denied_maxsz \
213 (8 + decode_lockowner_maxsz)
214#define decode_lock_maxsz (op_decode_hdr_maxsz + \
215 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400216#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
217 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400218#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
219 decode_lock_denied_maxsz)
220#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
221 encode_stateid_maxsz + \
222 4)
223#define decode_locku_maxsz (op_decode_hdr_maxsz + \
224 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400225#define encode_release_lockowner_maxsz \
226 (op_encode_hdr_maxsz + \
227 encode_lockowner_maxsz)
228#define decode_release_lockowner_maxsz \
229 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400230#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
231#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
233 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400234 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000235 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
237#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400238 1 + 2 + nfs4_name_maxsz + \
239 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400240#define decode_create_maxsz (op_decode_hdr_maxsz + \
241 decode_change_info_maxsz + \
242 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400243#define encode_statfs_maxsz (encode_getattr_maxsz)
244#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
246#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400247#define encode_getacl_maxsz (encode_getattr_maxsz)
248#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
249 nfs4_fattr_bitmap_maxsz + 1)
250#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
251 encode_stateid_maxsz + 3)
252#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400253#define encode_fs_locations_maxsz \
254 (encode_getattr_maxsz)
255#define decode_fs_locations_maxsz \
256 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000257#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
258#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 4 + (NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400259
260#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400261#define NFS4_MAX_MACHINE_NAME_LEN (64)
262
Benny Halevy99fe60d2009-04-01 09:22:29 -0400263#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
264 encode_verifier_maxsz + \
265 1 /* co_ownerid.len */ + \
266 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
267 1 /* flags */ + \
268 1 /* spa_how */ + \
269 0 /* SP4_NONE (for now) */ + \
270 1 /* zero implemetation id array */)
271#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
272 2 /* eir_clientid */ + \
273 1 /* eir_sequenceid */ + \
274 1 /* eir_flags */ + \
275 1 /* spr_how */ + \
276 0 /* SP4_NONE (for now) */ + \
277 2 /* eir_server_owner.so_minor_id */ + \
278 /* eir_server_owner.so_major_id<> */ \
279 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
280 /* eir_server_scope<> */ \
281 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
282 1 /* eir_server_impl_id array length */ + \
283 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400284#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
285#define decode_channel_attrs_maxsz (6 + \
286 1 /* ca_rdma_ird.len */ + \
287 1 /* ca_rdma_ird */)
288#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
289 2 /* csa_clientid */ + \
290 1 /* csa_sequence */ + \
291 1 /* csa_flags */ + \
292 encode_channel_attrs_maxsz + \
293 encode_channel_attrs_maxsz + \
294 1 /* csa_cb_program */ + \
295 1 /* csa_sec_parms.len (1) */ + \
296 1 /* cb_secflavor (AUTH_SYS) */ + \
297 1 /* stamp */ + \
298 1 /* machinename.len */ + \
299 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
300 1 /* uid */ + \
301 1 /* gid */ + \
302 1 /* gids.len (0) */)
303#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
304 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
305 1 /* csr_sequence */ + \
306 1 /* csr_flags */ + \
307 decode_channel_attrs_maxsz + \
308 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400309#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
310#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400311#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
312 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
313#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
314 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500315#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
316#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400317#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
318 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
319#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
320 1 /* layout type */ + \
321 1 /* opaque devaddr4 length */ + \
322 /* devaddr4 payload is read into page */ \
323 1 /* notification bitmap length */ + \
324 1 /* notification bitmap */)
325#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
326 encode_stateid_maxsz)
327#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
328 decode_stateid_maxsz + \
329 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy 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)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400346#else /* CONFIG_NFS_V4_1 */
347#define encode_sequence_maxsz 0
348#define decode_sequence_maxsz 0
349#endif /* CONFIG_NFS_V4_1 */
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
352#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
353#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400354 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400356 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400358 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400360 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400362 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400364 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400366 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400368 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400370 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400372 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400374 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400376 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400378 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400380 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400381 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400383 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400385 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400386 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400388 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400390 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400391 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400393 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400395 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400396 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400398 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400399 encode_putfh_maxsz + \
400 encode_savefh_maxsz + \
401 encode_open_maxsz + \
402 encode_getfh_maxsz + \
403 encode_getattr_maxsz + \
404 encode_restorefh_maxsz + \
405 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400407 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400408 decode_putfh_maxsz + \
409 decode_savefh_maxsz + \
410 decode_open_maxsz + \
411 decode_getfh_maxsz + \
412 decode_getattr_maxsz + \
413 decode_restorefh_maxsz + \
414 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400415#define NFS4_enc_open_confirm_sz \
416 (compound_encode_hdr_maxsz + \
417 encode_putfh_maxsz + \
418 encode_open_confirm_maxsz)
419#define NFS4_dec_open_confirm_sz \
420 (compound_decode_hdr_maxsz + \
421 decode_putfh_maxsz + \
422 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400424 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400426 encode_open_maxsz + \
427 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400429 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400431 decode_open_maxsz + \
432 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_enc_open_downgrade_sz \
434 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400435 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 encode_putfh_maxsz + \
437 encode_open_downgrade_maxsz + \
438 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#define NFS4_dec_open_downgrade_sz \
440 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400441 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400442 decode_putfh_maxsz + \
443 decode_open_downgrade_maxsz + \
444 decode_getattr_maxsz)
445#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400447 encode_putfh_maxsz + \
448 encode_close_maxsz + \
449 encode_getattr_maxsz)
450#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400451 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400452 decode_putfh_maxsz + \
453 decode_close_maxsz + \
454 decode_getattr_maxsz)
455#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400457 encode_putfh_maxsz + \
458 encode_setattr_maxsz + \
459 encode_getattr_maxsz)
460#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400461 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400462 decode_putfh_maxsz + \
463 decode_setattr_maxsz + \
464 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 encode_putfh_maxsz + \
468 encode_fsinfo_maxsz)
469#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400470 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 decode_putfh_maxsz + \
472 decode_fsinfo_maxsz)
473#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
474 encode_renew_maxsz)
475#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
476 decode_renew_maxsz)
477#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
478 encode_setclientid_maxsz)
479#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
480 decode_setclientid_maxsz)
481#define NFS4_enc_setclientid_confirm_sz \
482 (compound_encode_hdr_maxsz + \
483 encode_setclientid_confirm_maxsz + \
484 encode_putrootfh_maxsz + \
485 encode_fsinfo_maxsz)
486#define NFS4_dec_setclientid_confirm_sz \
487 (compound_decode_hdr_maxsz + \
488 decode_setclientid_confirm_maxsz + \
489 decode_putrootfh_maxsz + \
490 decode_fsinfo_maxsz)
491#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400494 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400496 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400498 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400502 encode_lockt_maxsz)
503#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400504 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400505 decode_putfh_maxsz + \
506 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400508 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400510 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400512 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400514 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400515#define NFS4_enc_release_lockowner_sz \
516 (compound_encode_hdr_maxsz + \
517 encode_lockowner_maxsz)
518#define NFS4_dec_release_lockowner_sz \
519 (compound_decode_hdr_maxsz + \
520 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400522 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400524 encode_access_maxsz + \
525 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400527 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400529 decode_access_maxsz + \
530 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 encode_putfh_maxsz + \
534 encode_getattr_maxsz)
535#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400536 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 decode_putfh_maxsz + \
538 decode_getattr_maxsz)
539#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400540 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 encode_putfh_maxsz + \
542 encode_lookup_maxsz + \
543 encode_getattr_maxsz + \
544 encode_getfh_maxsz)
545#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400546 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400548 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 decode_getattr_maxsz + \
550 decode_getfh_maxsz)
551#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400552 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 encode_putrootfh_maxsz + \
554 encode_getattr_maxsz + \
555 encode_getfh_maxsz)
556#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400557 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 decode_putrootfh_maxsz + \
559 decode_getattr_maxsz + \
560 decode_getfh_maxsz)
561#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400564 encode_remove_maxsz + \
565 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400567 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400569 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400570 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 encode_putfh_maxsz + \
574 encode_savefh_maxsz + \
575 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400576 encode_rename_maxsz + \
577 encode_getattr_maxsz + \
578 encode_restorefh_maxsz + \
579 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400581 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 decode_putfh_maxsz + \
583 decode_savefh_maxsz + \
584 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400585 decode_rename_maxsz + \
586 decode_getattr_maxsz + \
587 decode_restorefh_maxsz + \
588 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
592 encode_savefh_maxsz + \
593 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400594 encode_link_maxsz + \
595 decode_getattr_maxsz + \
596 encode_restorefh_maxsz + \
597 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400599 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 decode_putfh_maxsz + \
601 decode_savefh_maxsz + \
602 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400603 decode_link_maxsz + \
604 decode_getattr_maxsz + \
605 decode_restorefh_maxsz + \
606 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400608 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 encode_putfh_maxsz + \
610 encode_symlink_maxsz + \
611 encode_getattr_maxsz + \
612 encode_getfh_maxsz)
613#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400614 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 decode_putfh_maxsz + \
616 decode_symlink_maxsz + \
617 decode_getattr_maxsz + \
618 decode_getfh_maxsz)
619#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400620 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400622 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400624 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400626 encode_restorefh_maxsz + \
627 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400629 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400631 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400633 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400635 decode_restorefh_maxsz + \
636 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400638 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 encode_putfh_maxsz + \
640 encode_getattr_maxsz)
641#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400642 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 decode_putfh_maxsz + \
644 decode_getattr_maxsz)
645#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400648 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400652 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800655 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 encode_getattr_maxsz)
657#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400658 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800659 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 decode_getattr_maxsz)
661#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400662 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100664 encode_delegreturn_maxsz + \
665 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400667 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100668 decode_delegreturn_maxsz + \
669 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000670#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400671 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000672 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400673 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000674#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400675 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000676 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400677 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000678#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400679 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000680 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400681 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000682#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400683 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000684 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400685 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400686#define NFS4_enc_fs_locations_sz \
687 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400689 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400690 encode_lookup_maxsz + \
691 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400692#define NFS4_dec_fs_locations_sz \
693 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400695 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400696 decode_lookup_maxsz + \
697 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000698#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
699 encode_sequence_maxsz + \
700 encode_putfh_maxsz + \
701 encode_secinfo_maxsz)
702#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
703 decode_sequence_maxsz + \
704 decode_putfh_maxsz + \
705 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400706#if defined(CONFIG_NFS_V4_1)
707#define NFS4_enc_exchange_id_sz \
708 (compound_encode_hdr_maxsz + \
709 encode_exchange_id_maxsz)
710#define NFS4_dec_exchange_id_sz \
711 (compound_decode_hdr_maxsz + \
712 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400713#define NFS4_enc_create_session_sz \
714 (compound_encode_hdr_maxsz + \
715 encode_create_session_maxsz)
716#define NFS4_dec_create_session_sz \
717 (compound_decode_hdr_maxsz + \
718 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400719#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
720 encode_destroy_session_maxsz)
721#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
722 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400723#define NFS4_enc_sequence_sz \
724 (compound_decode_hdr_maxsz + \
725 encode_sequence_maxsz)
726#define NFS4_dec_sequence_sz \
727 (compound_decode_hdr_maxsz + \
728 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400729#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
730 encode_sequence_maxsz + \
731 encode_putrootfh_maxsz + \
732 encode_fsinfo_maxsz)
733#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
734 decode_sequence_maxsz + \
735 decode_putrootfh_maxsz + \
736 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500737#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
738 encode_sequence_maxsz + \
739 encode_reclaim_complete_maxsz)
740#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
741 decode_sequence_maxsz + \
742 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400743#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
744 encode_sequence_maxsz +\
745 encode_getdeviceinfo_maxsz)
746#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
747 decode_sequence_maxsz + \
748 decode_getdeviceinfo_maxsz)
749#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
750 encode_sequence_maxsz + \
751 encode_putfh_maxsz + \
752 encode_layoutget_maxsz)
753#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
754 decode_sequence_maxsz + \
755 decode_putfh_maxsz + \
756 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000757#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
758 encode_sequence_maxsz +\
759 encode_putfh_maxsz + \
760 encode_layoutcommit_maxsz + \
761 encode_getattr_maxsz)
762#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
763 decode_sequence_maxsz + \
764 decode_putfh_maxsz + \
765 decode_layoutcommit_maxsz + \
766 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300767#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
768 encode_sequence_maxsz + \
769 encode_putfh_maxsz + \
770 encode_layoutreturn_maxsz)
771#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
772 decode_sequence_maxsz + \
773 decode_putfh_maxsz + \
774 decode_layoutreturn_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500775
776const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
777 compound_encode_hdr_maxsz +
778 encode_sequence_maxsz +
779 encode_putfh_maxsz +
780 encode_getattr_maxsz) *
781 XDR_UNIT);
782
783const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
784 compound_decode_hdr_maxsz +
785 decode_sequence_maxsz +
786 decode_putfh_maxsz) *
787 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400788#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Trond Myklebustbca79472009-03-11 14:10:26 -0400790static const umode_t nfs_type2fmt[] = {
791 [NF4BAD] = 0,
792 [NF4REG] = S_IFREG,
793 [NF4DIR] = S_IFDIR,
794 [NF4BLK] = S_IFBLK,
795 [NF4CHR] = S_IFCHR,
796 [NF4LNK] = S_IFLNK,
797 [NF4SOCK] = S_IFSOCK,
798 [NF4FIFO] = S_IFIFO,
799 [NF4ATTRDIR] = 0,
800 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801};
802
803struct compound_hdr {
804 int32_t status;
805 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500806 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 uint32_t taglen;
808 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400809 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400810 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811};
812
Benny Halevy13c65ce2009-08-14 17:19:25 +0300813static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
814{
815 __be32 *p = xdr_reserve_space(xdr, nbytes);
816 BUG_ON(!p);
817 return p;
818}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
821{
Al Viro8687b632006-10-19 23:28:48 -0700822 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824 p = xdr_reserve_space(xdr, 4 + len);
825 BUG_ON(p == NULL);
826 xdr_encode_opaque(p, str, len);
827}
828
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400829static void encode_compound_hdr(struct xdr_stream *xdr,
830 struct rpc_rqst *req,
831 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
Al Viro8687b632006-10-19 23:28:48 -0700833 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400834 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400835
836 /* initialize running count of expected bytes in reply.
837 * NOTE: the replied tag SHOULD be the same is the one sent,
838 * but this is not required as a MUST for the server to do so. */
839 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
842 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300843 p = reserve_space(xdr, 4 + hdr->taglen + 8);
844 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300845 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500846 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300847 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500848}
849
850static void encode_nops(struct compound_hdr *hdr)
851{
Andy Adamsonfc931582009-04-01 09:22:31 -0400852 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500853 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854}
855
856static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
857{
Al Viro8687b632006-10-19 23:28:48 -0700858 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
860 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
861 BUG_ON(p == NULL);
862 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
863}
864
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500865static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
867 char owner_name[IDMAP_NAMESZ];
868 char owner_group[IDMAP_NAMESZ];
869 int owner_namelen = 0;
870 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700871 __be32 *p;
872 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 int len;
874 uint32_t bmval0 = 0;
875 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 /*
878 * We reserve enough space to write the entire attribute buffer at once.
879 * In the worst-case, this would be
880 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
881 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000882 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 */
884 len = 16;
885
886 /* Sigh */
887 if (iap->ia_valid & ATTR_SIZE)
888 len += 8;
889 if (iap->ia_valid & ATTR_MODE)
890 len += 4;
891 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800892 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400894 dprintk("nfs: couldn't resolve uid %d to string\n",
895 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 /* XXX */
897 strcpy(owner_name, "nobody");
898 owner_namelen = sizeof("nobody") - 1;
899 /* goto out; */
900 }
901 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
902 }
903 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800904 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400906 dprintk("nfs: couldn't resolve gid %d to string\n",
907 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 strcpy(owner_group, "nobody");
909 owner_grouplen = sizeof("nobody") - 1;
910 /* goto out; */
911 }
912 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
913 }
914 if (iap->ia_valid & ATTR_ATIME_SET)
915 len += 16;
916 else if (iap->ia_valid & ATTR_ATIME)
917 len += 4;
918 if (iap->ia_valid & ATTR_MTIME_SET)
919 len += 16;
920 else if (iap->ia_valid & ATTR_MTIME)
921 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300922 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 /*
925 * We write the bitmap length now, but leave the bitmap and the attribute
926 * buffer length to be backfilled at the end of this routine.
927 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300928 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 q = p;
930 p += 3;
931
932 if (iap->ia_valid & ATTR_SIZE) {
933 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300934 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 }
936 if (iap->ia_valid & ATTR_MODE) {
937 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300938 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 }
940 if (iap->ia_valid & ATTR_UID) {
941 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300942 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 }
944 if (iap->ia_valid & ATTR_GID) {
945 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300946 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
948 if (iap->ia_valid & ATTR_ATIME_SET) {
949 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300950 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
951 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -0400952 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
953 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 }
955 else if (iap->ia_valid & ATTR_ATIME) {
956 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300957 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 }
959 if (iap->ia_valid & ATTR_MTIME_SET) {
960 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300961 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
962 *p++ = cpu_to_be32(0);
963 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
964 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 }
966 else if (iap->ia_valid & ATTR_MTIME) {
967 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300968 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500970
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 /*
972 * Now we backfill the bitmap and the attribute buffer length.
973 */
974 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400975 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 len, ((char *)p - (char *)q) + 4);
977 BUG();
978 }
979 len = (char *)p - (char *)q - 12;
980 *q++ = htonl(bmval0);
981 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +0300982 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985}
986
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500987static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988{
Al Viro8687b632006-10-19 23:28:48 -0700989 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Benny Halevy13c65ce2009-08-14 17:19:25 +0300991 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300992 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +0300993 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500994 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -0400995 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996}
997
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500998static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999{
Al Viro8687b632006-10-19 23:28:48 -07001000 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Benny Halevy13c65ce2009-08-14 17:19:25 +03001002 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001003 *p++ = cpu_to_be32(OP_CLOSE);
1004 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001005 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001006 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001007 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008}
1009
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001010static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011{
Al Viro8687b632006-10-19 23:28:48 -07001012 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001013
Benny Halevy13c65ce2009-08-14 17:19:25 +03001014 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001015 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001016 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001017 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001018 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001019 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020}
1021
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001022static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023{
Al Viro8687b632006-10-19 23:28:48 -07001024 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001025
Benny Halevy13c65ce2009-08-14 17:19:25 +03001026 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001027 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001028 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 switch (create->ftype) {
1031 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001032 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001033 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001034 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 break;
1036
1037 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001038 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001039 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001040 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 break;
1042
1043 default:
1044 break;
1045 }
1046
Benny Halevy811652b2009-08-14 17:19:34 +03001047 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001048 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001049 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001051 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052}
1053
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001054static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055{
Andy Adamson05d564f2008-12-23 16:06:15 -05001056 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Benny Halevy13c65ce2009-08-14 17:19:25 +03001058 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001059 *p++ = cpu_to_be32(OP_GETATTR);
1060 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001061 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001062 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001063 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064}
1065
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001066static 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 -07001067{
Andy Adamson05d564f2008-12-23 16:06:15 -05001068 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
Benny Halevy13c65ce2009-08-14 17:19:25 +03001070 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001071 *p++ = cpu_to_be32(OP_GETATTR);
1072 *p++ = cpu_to_be32(2);
1073 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001074 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001075 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001076 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077}
1078
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001079static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001081 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1082 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001085static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001087 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
1088 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089}
1090
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001091static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001092{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001093 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1094 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001095}
1096
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001097static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
Al Viro8687b632006-10-19 23:28:48 -07001099 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Benny Halevy13c65ce2009-08-14 17:19:25 +03001101 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001102 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001103 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001104 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105}
1106
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001107static void encode_link(struct xdr_stream *xdr, const struct qstr *name, 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, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001112 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001113 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001114 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001115 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001118static inline int nfs4_lock_type(struct file_lock *fl, int block)
1119{
1120 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1121 return block ? NFS4_READW_LT : NFS4_READ_LT;
1122 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1123}
1124
1125static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1126{
1127 if (fl->fl_end == OFFSET_MAX)
1128 return ~(uint64_t)0;
1129 return fl->fl_end - fl->fl_start + 1;
1130}
1131
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001132static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1133{
1134 __be32 *p;
1135
Trond Myklebustd035c362010-12-21 10:45:27 -05001136 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001137 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001138 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001139 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001140 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001141 xdr_encode_hyper(p, lowner->id);
1142}
1143
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144/*
1145 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1146 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1147 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001148static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Al Viro8687b632006-10-19 23:28:48 -07001150 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Benny Halevy13c65ce2009-08-14 17:19:25 +03001152 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001153 *p++ = cpu_to_be32(OP_LOCK);
1154 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1155 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001156 p = xdr_encode_hyper(p, args->fl->fl_start);
1157 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001158 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001159 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001160 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001161 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001162 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001163 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001164 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
1166 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001167 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001168 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001169 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 }
Andy Adamsond0179312008-12-23 16:06:17 -05001171 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001172 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001175static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
Al Viro8687b632006-10-19 23:28:48 -07001177 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001179 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001180 *p++ = cpu_to_be32(OP_LOCKT);
1181 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001182 p = xdr_encode_hyper(p, args->fl->fl_start);
1183 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001184 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001185 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001186 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187}
1188
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001189static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190{
Al Viro8687b632006-10-19 23:28:48 -07001191 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Benny Halevy13c65ce2009-08-14 17:19:25 +03001193 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001194 *p++ = cpu_to_be32(OP_LOCKU);
1195 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1196 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001197 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001198 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001199 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001200 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001201 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202}
1203
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001204static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1205{
1206 __be32 *p;
1207
1208 p = reserve_space(xdr, 4);
1209 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1210 encode_lockowner(xdr, lowner);
1211 hdr->nops++;
1212 hdr->replen += decode_release_lockowner_maxsz;
1213}
1214
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001215static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216{
1217 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -07001218 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
Benny Halevy13c65ce2009-08-14 17:19:25 +03001220 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001221 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001222 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001223 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001224 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225}
1226
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001227static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228{
Al Viro8687b632006-10-19 23:28:48 -07001229 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Benny Halevy13c65ce2009-08-14 17:19:25 +03001231 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001232 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001233 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001234 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001235 break;
1236 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001237 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001238 break;
1239 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001240 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001241 break;
1242 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001243 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 }
Benny Halevy34558512009-08-14 17:19:30 +03001245 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246}
1247
1248static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1249{
Al Viro8687b632006-10-19 23:28:48 -07001250 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 /*
1252 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1253 * owner 4 = 32
1254 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001255 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001256 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001257 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001258 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001259 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001260 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001261 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001262 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001263 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001264 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
1267static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1268{
Al Viro8687b632006-10-19 23:28:48 -07001269 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001270 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Benny Halevy13c65ce2009-08-14 17:19:25 +03001272 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001274 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001275 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001276 encode_attrs(xdr, arg->u.attrs, arg->server);
1277 break;
1278 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001279 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001280 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001281 if (nfs4_has_persistent_session(clp)) {
1282 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1283 encode_attrs(xdr, arg->u.attrs, arg->server);
1284 } else {
1285 struct iattr dummy;
1286
1287 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1288 encode_nfs4_verifier(xdr, &arg->u.verifier);
1289 dummy.ia_valid = 0;
1290 encode_attrs(xdr, &dummy, arg->server);
1291 }
1292 } else {
1293 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1294 encode_nfs4_verifier(xdr, &arg->u.verifier);
1295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 }
1297}
1298
1299static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1300{
Al Viro8687b632006-10-19 23:28:48 -07001301 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Benny Halevy13c65ce2009-08-14 17:19:25 +03001303 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001305 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001306 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001307 break;
1308 default:
1309 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001310 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001311 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 }
1313}
1314
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001315static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
Al Viro8687b632006-10-19 23:28:48 -07001317 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Benny Halevy13c65ce2009-08-14 17:19:25 +03001319 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001321 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001322 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001323 break;
1324 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001325 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001326 break;
1327 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001328 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001329 break;
1330 default:
1331 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
1333}
1334
1335static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1336{
Al Viro8687b632006-10-19 23:28:48 -07001337 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Benny Halevy13c65ce2009-08-14 17:19:25 +03001339 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001340 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 encode_string(xdr, name->len, name->name);
1342}
1343
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001344static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345{
Al Viro8687b632006-10-19 23:28:48 -07001346 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Benny Halevy13c65ce2009-08-14 17:19:25 +03001348 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001349 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 encode_delegation_type(xdr, type);
1351}
1352
1353static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1354{
Al Viro8687b632006-10-19 23:28:48 -07001355 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
Benny Halevy13c65ce2009-08-14 17:19:25 +03001357 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001358 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Benny Halevy34558512009-08-14 17:19:30 +03001359 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 encode_string(xdr, name->len, name->name);
1361}
1362
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001363static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364{
1365 encode_openhdr(xdr, arg);
1366 encode_opentype(xdr, arg);
1367 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001368 case NFS4_OPEN_CLAIM_NULL:
1369 encode_claim_null(xdr, arg->name);
1370 break;
1371 case NFS4_OPEN_CLAIM_PREVIOUS:
1372 encode_claim_previous(xdr, arg->u.delegation_type);
1373 break;
1374 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1375 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1376 break;
1377 default:
1378 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
Andy Adamsond0179312008-12-23 16:06:17 -05001380 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001381 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001384static 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 -07001385{
Al Viro8687b632006-10-19 23:28:48 -07001386 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Benny Halevy13c65ce2009-08-14 17:19:25 +03001388 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001389 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001390 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001391 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001392 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001393 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394}
1395
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001396static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397{
Al Viro8687b632006-10-19 23:28:48 -07001398 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Benny Halevy13c65ce2009-08-14 17:19:25 +03001400 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001401 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001402 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001403 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001404 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001405 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001406 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407}
1408
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001409static void
Andy Adamsond0179312008-12-23 16:06:17 -05001410encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411{
1412 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001413 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Benny Halevy13c65ce2009-08-14 17:19:25 +03001415 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001416 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001417 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001418 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001419 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420}
1421
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001422static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423{
Andy Adamson05d564f2008-12-23 16:06:15 -05001424 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001425
Benny Halevy13c65ce2009-08-14 17:19:25 +03001426 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001427 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001428 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001429 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430}
1431
Andy Adamson89d1ea62011-03-01 01:34:09 +00001432static 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 -07001433{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001435 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Benny Halevy13c65ce2009-08-14 17:19:25 +03001437 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001439 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001440 if (zero_seqid)
1441 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001442 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 } else
Benny Halevy34558512009-08-14 17:19:30 +03001444 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445}
1446
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001447static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448{
Al Viro8687b632006-10-19 23:28:48 -07001449 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Benny Halevy13c65ce2009-08-14 17:19:25 +03001451 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001452 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Andy Adamson89d1ea62011-03-01 01:34:09 +00001454 encode_stateid(xdr, args->context, args->lock_context,
1455 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Benny Halevy13c65ce2009-08-14 17:19:25 +03001457 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001458 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001459 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001460 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001461 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462}
1463
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001464static 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 -07001465{
Trond Myklebust28331a42011-04-27 13:47:52 -04001466 uint32_t attrs[2] = {
1467 FATTR4_WORD0_RDATTR_ERROR,
1468 FATTR4_WORD1_MOUNTED_ON_FILEID,
1469 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001470 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001471 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001473 if (readdir->plus) {
1474 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001475 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001476 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1477 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1478 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1479 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001480 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001481 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001482 /* Use mounted_on_fileid only if the server supports it */
1483 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1484 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001485
Benny Halevy13c65ce2009-08-14 17:19:25 +03001486 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001487 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001488 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001489 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001490 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001491 *p++ = cpu_to_be32(readdir->count);
1492 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001493
Benny Halevye75bc1c2009-08-14 17:18:54 +03001494 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001495 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001496 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001497 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001498 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1499 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001500 (unsigned long long)readdir->cookie,
1501 ((u32 *)readdir->verifier.data)[0],
1502 ((u32 *)readdir->verifier.data)[1],
1503 attrs[0] & readdir->bitmask[0],
1504 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505}
1506
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001507static 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 -07001508{
Al Viro8687b632006-10-19 23:28:48 -07001509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Benny Halevy13c65ce2009-08-14 17:19:25 +03001511 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001512 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001513 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001514 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515}
1516
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001517static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, 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, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001522 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001523 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001524 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001525 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526}
1527
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001528static 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 -07001529{
Al Viro8687b632006-10-19 23:28:48 -07001530 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Benny Halevy811652b2009-08-14 17:19:34 +03001532 p = reserve_space(xdr, 4);
1533 *p = cpu_to_be32(OP_RENAME);
1534 encode_string(xdr, oldname->len, oldname->name);
1535 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001536 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001537 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538}
1539
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001540static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
Al Viro8687b632006-10-19 23:28:48 -07001542 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
Benny Halevy13c65ce2009-08-14 17:19:25 +03001544 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001545 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001546 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001547 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001548 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549}
1550
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001551static void
Andy Adamsond0179312008-12-23 16:06:17 -05001552encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001553{
Al Viro8687b632006-10-19 23:28:48 -07001554 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001555
Benny Halevy13c65ce2009-08-14 17:19:25 +03001556 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001557 *p = cpu_to_be32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001558 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001559 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001560}
1561
Chuck Lever9f06c712010-12-14 14:59:18 +00001562static void
Andy Adamsond0179312008-12-23 16:06:17 -05001563encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001564{
Al Viro8687b632006-10-19 23:28:48 -07001565 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001566
Benny Halevy13c65ce2009-08-14 17:19:25 +03001567 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001568 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001569 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001570 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001571 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001572 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001573 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001574 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001575 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001576 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001577 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001578 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001579}
1580
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001581static void
Andy Adamsond0179312008-12-23 16:06:17 -05001582encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583{
Al Viro8687b632006-10-19 23:28:48 -07001584 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Benny Halevy13c65ce2009-08-14 17:19:25 +03001586 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001587 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001588 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001589 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590}
1591
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001592static 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 -07001593{
Al Viro8687b632006-10-19 23:28:48 -07001594 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001595
Benny Halevy13c65ce2009-08-14 17:19:25 +03001596 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001597 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001598 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001599 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001600 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001601 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602}
1603
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001604static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605{
Al Viro8687b632006-10-19 23:28:48 -07001606 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
Benny Halevy13c65ce2009-08-14 17:19:25 +03001608 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001609 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001610 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001613 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001614 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1616 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001617 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001618 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001619 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001620 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001623static 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 -07001624{
Andy Adamson05d564f2008-12-23 16:06:15 -05001625 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Benny Halevy13c65ce2009-08-14 17:19:25 +03001627 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001628 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001629 p = xdr_encode_hyper(p, arg->clientid);
1630 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001631 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001632 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633}
1634
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001635static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636{
Al Viro8687b632006-10-19 23:28:48 -07001637 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
Benny Halevy13c65ce2009-08-14 17:19:25 +03001639 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001640 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
Andy Adamson89d1ea62011-03-01 01:34:09 +00001642 encode_stateid(xdr, args->context, args->lock_context,
1643 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
Benny Halevy13c65ce2009-08-14 17:19:25 +03001645 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001646 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001647 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001648 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
1650 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001651 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001652 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
1654
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001655static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
Al Viro8687b632006-10-19 23:28:48 -07001657 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
Benny Halevy13c65ce2009-08-14 17:19:25 +03001659 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
Benny Halevye75bc1c2009-08-14 17:18:54 +03001661 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001662 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001663 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001664 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001666
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001667static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1668{
1669 int len = name->len;
1670 __be32 *p;
1671
1672 p = reserve_space(xdr, 8 + len);
1673 *p++ = cpu_to_be32(OP_SECINFO);
1674 xdr_encode_opaque(p, name->name, len);
1675 hdr->nops++;
1676 hdr->replen += decode_secinfo_maxsz;
1677}
1678
Benny Halevy99fe60d2009-04-01 09:22:29 -04001679#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001680/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001681static void encode_exchange_id(struct xdr_stream *xdr,
1682 struct nfs41_exchange_id_args *args,
1683 struct compound_hdr *hdr)
1684{
1685 __be32 *p;
1686
Benny Halevy13c65ce2009-08-14 17:19:25 +03001687 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001688 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001689 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001690
1691 encode_string(xdr, args->id_len, args->id);
1692
Benny Halevy13c65ce2009-08-14 17:19:25 +03001693 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001694 *p++ = cpu_to_be32(args->flags);
1695 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001696 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001697 hdr->nops++;
1698 hdr->replen += decode_exchange_id_maxsz;
1699}
Andy Adamsonfc931582009-04-01 09:22:31 -04001700
1701static void encode_create_session(struct xdr_stream *xdr,
1702 struct nfs41_create_session_args *args,
1703 struct compound_hdr *hdr)
1704{
1705 __be32 *p;
1706 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1707 uint32_t len;
1708 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001709 u32 max_resp_sz_cached;
1710
1711 /*
1712 * Assumes OPEN is the biggest non-idempotent compound.
1713 * 2 is the verifier.
1714 */
1715 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1716 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001717
Andy Adamsonfc931582009-04-01 09:22:31 -04001718 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1719 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001720
Benny Halevy13c65ce2009-08-14 17:19:25 +03001721 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001722 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001723 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001724 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1725 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001726
Andy Adamsonfc931582009-04-01 09:22:31 -04001727 /* Fore Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001728 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1729 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1730 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001731 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001732 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1733 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1734 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001735
1736 /* Back Channel */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001737 *p++ = cpu_to_be32(args->fc_attrs.headerpadsz); /* header padding size */
1738 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1739 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1740 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1741 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1742 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1743 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001744
Benny Halevye75bc1c2009-08-14 17:18:54 +03001745 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001746 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001747 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001748
1749 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001750 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001751 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001752 *p++ = cpu_to_be32(0); /* UID */
1753 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001754 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001755 hdr->nops++;
1756 hdr->replen += decode_create_session_maxsz;
1757}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001758
1759static void encode_destroy_session(struct xdr_stream *xdr,
1760 struct nfs4_session *session,
1761 struct compound_hdr *hdr)
1762{
1763 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001764 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001765 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001766 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001767 hdr->nops++;
1768 hdr->replen += decode_destroy_session_maxsz;
1769}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001770
1771static void encode_reclaim_complete(struct xdr_stream *xdr,
1772 struct nfs41_reclaim_complete_args *args,
1773 struct compound_hdr *hdr)
1774{
1775 __be32 *p;
1776
1777 p = reserve_space(xdr, 8);
1778 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1779 *p++ = cpu_to_be32(args->one_fs);
1780 hdr->nops++;
1781 hdr->replen += decode_reclaim_complete_maxsz;
1782}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001783#endif /* CONFIG_NFS_V4_1 */
1784
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001785static void encode_sequence(struct xdr_stream *xdr,
1786 const struct nfs4_sequence_args *args,
1787 struct compound_hdr *hdr)
1788{
1789#if defined(CONFIG_NFS_V4_1)
1790 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001791 struct nfs4_slot_table *tp;
1792 struct nfs4_slot *slot;
1793 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001794
1795 if (!session)
1796 return;
1797
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001798 tp = &session->fc_slot_table;
1799
1800 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1801 slot = tp->slots + args->sa_slotid;
1802
Benny Halevy13c65ce2009-08-14 17:19:25 +03001803 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001804 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001805
1806 /*
1807 * Sessionid + seqid + slotid + max slotid + cache_this
1808 */
1809 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1810 "max_slotid=%d cache_this=%d\n",
1811 __func__,
1812 ((u32 *)session->sess_id.data)[0],
1813 ((u32 *)session->sess_id.data)[1],
1814 ((u32 *)session->sess_id.data)[2],
1815 ((u32 *)session->sess_id.data)[3],
1816 slot->seq_nr, args->sa_slotid,
1817 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001818 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001819 *p++ = cpu_to_be32(slot->seq_nr);
1820 *p++ = cpu_to_be32(args->sa_slotid);
1821 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001822 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001823 hdr->nops++;
1824 hdr->replen += decode_sequence_maxsz;
1825#endif /* CONFIG_NFS_V4_1 */
1826}
1827
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001828#ifdef CONFIG_NFS_V4_1
1829static void
1830encode_getdeviceinfo(struct xdr_stream *xdr,
1831 const struct nfs4_getdeviceinfo_args *args,
1832 struct compound_hdr *hdr)
1833{
1834 __be32 *p;
1835
1836 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1837 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1838 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1839 NFS4_DEVICEID4_SIZE);
1840 *p++ = cpu_to_be32(args->pdev->layout_type);
1841 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1842 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1843 hdr->nops++;
1844 hdr->replen += decode_getdeviceinfo_maxsz;
1845}
1846
1847static void
1848encode_layoutget(struct xdr_stream *xdr,
1849 const struct nfs4_layoutget_args *args,
1850 struct compound_hdr *hdr)
1851{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001852 __be32 *p;
1853
1854 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1855 *p++ = cpu_to_be32(OP_LAYOUTGET);
1856 *p++ = cpu_to_be32(0); /* Signal layout available */
1857 *p++ = cpu_to_be32(args->type);
1858 *p++ = cpu_to_be32(args->range.iomode);
1859 p = xdr_encode_hyper(p, args->range.offset);
1860 p = xdr_encode_hyper(p, args->range.length);
1861 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001862 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001863 *p = cpu_to_be32(args->maxcount);
1864
1865 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1866 __func__,
1867 args->type,
1868 args->range.iomode,
1869 (unsigned long)args->range.offset,
1870 (unsigned long)args->range.length,
1871 args->maxcount);
1872 hdr->nops++;
1873 hdr->replen += decode_layoutget_maxsz;
1874}
Andy Adamson863a3c62011-03-23 13:27:54 +00001875
1876static int
1877encode_layoutcommit(struct xdr_stream *xdr,
1878 const struct nfs4_layoutcommit_args *args,
1879 struct compound_hdr *hdr)
1880{
1881 __be32 *p;
1882
1883 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1884 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1885
1886 p = reserve_space(xdr, 48 + NFS4_STATEID_SIZE);
1887 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1888 /* Only whole file layouts */
1889 p = xdr_encode_hyper(p, 0); /* offset */
1890 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); /* length */
1891 *p++ = cpu_to_be32(0); /* reclaim */
1892 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1893 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1894 p = xdr_encode_hyper(p, args->lastbytewritten);
1895 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1896 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
1897 *p++ = cpu_to_be32(0); /* no file layout payload */
1898
1899 hdr->nops++;
1900 hdr->replen += decode_layoutcommit_maxsz;
1901 return 0;
1902}
Benny Halevycbe82602011-05-22 19:52:37 +03001903
1904static void
1905encode_layoutreturn(struct xdr_stream *xdr,
1906 const struct nfs4_layoutreturn_args *args,
1907 struct compound_hdr *hdr)
1908{
1909 __be32 *p;
1910
1911 p = reserve_space(xdr, 20);
1912 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
1913 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
1914 *p++ = cpu_to_be32(args->layout_type);
1915 *p++ = cpu_to_be32(IOMODE_ANY);
1916 *p = cpu_to_be32(RETURN_FILE);
1917 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
1918 p = xdr_encode_hyper(p, 0);
1919 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
1920 spin_lock(&args->inode->i_lock);
1921 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
1922 spin_unlock(&args->inode->i_lock);
1923 p = reserve_space(xdr, 4);
1924 *p = cpu_to_be32(0);
1925 hdr->nops++;
1926 hdr->replen += decode_layoutreturn_maxsz;
1927}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001928#endif /* CONFIG_NFS_V4_1 */
1929
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930/*
1931 * END OF "GENERIC" ENCODE ROUTINES.
1932 */
1933
Benny Halevy66cc0422009-04-01 09:22:10 -04001934static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
1935{
1936#if defined(CONFIG_NFS_V4_1)
1937 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04001938 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04001939#endif /* CONFIG_NFS_V4_1 */
1940 return 0;
1941}
1942
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943/*
1944 * Encode an ACCESS request
1945 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001946static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
1947 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001950 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
Chuck Lever9f06c712010-12-14 14:59:18 +00001953 encode_compound_hdr(xdr, req, &hdr);
1954 encode_sequence(xdr, &args->seq_args, &hdr);
1955 encode_putfh(xdr, args->fh, &hdr);
1956 encode_access(xdr, args->access, &hdr);
1957 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001958 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959}
1960
1961/*
1962 * Encode LOOKUP request
1963 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001964static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
1965 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001968 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970
Chuck Lever9f06c712010-12-14 14:59:18 +00001971 encode_compound_hdr(xdr, req, &hdr);
1972 encode_sequence(xdr, &args->seq_args, &hdr);
1973 encode_putfh(xdr, args->dir_fh, &hdr);
1974 encode_lookup(xdr, args->name, &hdr);
1975 encode_getfh(xdr, &hdr);
1976 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001977 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978}
1979
1980/*
1981 * Encode LOOKUP_ROOT request
1982 */
Chuck Lever9f06c712010-12-14 14:59:18 +00001983static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
1984 struct xdr_stream *xdr,
1985 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04001988 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
Chuck Lever9f06c712010-12-14 14:59:18 +00001991 encode_compound_hdr(xdr, req, &hdr);
1992 encode_sequence(xdr, &args->seq_args, &hdr);
1993 encode_putrootfh(xdr, &hdr);
1994 encode_getfh(xdr, &hdr);
1995 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001996 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997}
1998
1999/*
2000 * Encode REMOVE request
2001 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002002static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2003 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002006 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008
Chuck Lever9f06c712010-12-14 14:59:18 +00002009 encode_compound_hdr(xdr, req, &hdr);
2010 encode_sequence(xdr, &args->seq_args, &hdr);
2011 encode_putfh(xdr, args->fh, &hdr);
2012 encode_remove(xdr, &args->name, &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 RENAME request
2019 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002020static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2021 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002024 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
Chuck Lever9f06c712010-12-14 14:59:18 +00002027 encode_compound_hdr(xdr, req, &hdr);
2028 encode_sequence(xdr, &args->seq_args, &hdr);
2029 encode_putfh(xdr, args->old_dir, &hdr);
2030 encode_savefh(xdr, &hdr);
2031 encode_putfh(xdr, args->new_dir, &hdr);
2032 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2033 encode_getfattr(xdr, args->bitmask, &hdr);
2034 encode_restorefh(xdr, &hdr);
2035 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002036 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037}
2038
2039/*
2040 * Encode LINK request
2041 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002042static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2043 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002046 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
Chuck Lever9f06c712010-12-14 14:59:18 +00002049 encode_compound_hdr(xdr, req, &hdr);
2050 encode_sequence(xdr, &args->seq_args, &hdr);
2051 encode_putfh(xdr, args->fh, &hdr);
2052 encode_savefh(xdr, &hdr);
2053 encode_putfh(xdr, args->dir_fh, &hdr);
2054 encode_link(xdr, args->name, &hdr);
2055 encode_getfattr(xdr, args->bitmask, &hdr);
2056 encode_restorefh(xdr, &hdr);
2057 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002058 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059}
2060
2061/*
2062 * Encode CREATE request
2063 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002064static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2065 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002068 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070
Chuck Lever9f06c712010-12-14 14:59:18 +00002071 encode_compound_hdr(xdr, req, &hdr);
2072 encode_sequence(xdr, &args->seq_args, &hdr);
2073 encode_putfh(xdr, args->dir_fh, &hdr);
2074 encode_savefh(xdr, &hdr);
2075 encode_create(xdr, args, &hdr);
2076 encode_getfh(xdr, &hdr);
2077 encode_getfattr(xdr, args->bitmask, &hdr);
2078 encode_restorefh(xdr, &hdr);
2079 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002080 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081}
2082
2083/*
2084 * Encode SYMLINK request
2085 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002086static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2087 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088{
Chuck Lever9f06c712010-12-14 14:59:18 +00002089 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090}
2091
2092/*
2093 * Encode GETATTR request
2094 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002095static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2096 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002099 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Chuck Lever9f06c712010-12-14 14:59:18 +00002102 encode_compound_hdr(xdr, req, &hdr);
2103 encode_sequence(xdr, &args->seq_args, &hdr);
2104 encode_putfh(xdr, args->fh, &hdr);
2105 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002106 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107}
2108
2109/*
2110 * Encode a CLOSE request
2111 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002112static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2113 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114{
Andy Adamson05d564f2008-12-23 16:06:15 -05002115 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002116 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002117 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Chuck Lever9f06c712010-12-14 14:59:18 +00002119 encode_compound_hdr(xdr, req, &hdr);
2120 encode_sequence(xdr, &args->seq_args, &hdr);
2121 encode_putfh(xdr, args->fh, &hdr);
2122 encode_close(xdr, args, &hdr);
2123 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002124 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125}
2126
2127/*
2128 * Encode an OPEN request
2129 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002130static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2131 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002134 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
Chuck Lever9f06c712010-12-14 14:59:18 +00002137 encode_compound_hdr(xdr, req, &hdr);
2138 encode_sequence(xdr, &args->seq_args, &hdr);
2139 encode_putfh(xdr, args->fh, &hdr);
2140 encode_savefh(xdr, &hdr);
2141 encode_open(xdr, args, &hdr);
2142 encode_getfh(xdr, &hdr);
2143 encode_getfattr(xdr, args->bitmask, &hdr);
2144 encode_restorefh(xdr, &hdr);
2145 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002146 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147}
2148
2149/*
2150 * Encode an OPEN_CONFIRM request
2151 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002152static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2153 struct xdr_stream *xdr,
2154 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002157 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159
Chuck Lever9f06c712010-12-14 14:59:18 +00002160 encode_compound_hdr(xdr, req, &hdr);
2161 encode_putfh(xdr, args->fh, &hdr);
2162 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002163 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164}
2165
2166/*
2167 * Encode an OPEN request with no attributes.
2168 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002169static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2170 struct xdr_stream *xdr,
2171 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002174 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
Chuck Lever9f06c712010-12-14 14:59:18 +00002177 encode_compound_hdr(xdr, req, &hdr);
2178 encode_sequence(xdr, &args->seq_args, &hdr);
2179 encode_putfh(xdr, args->fh, &hdr);
2180 encode_open(xdr, args, &hdr);
2181 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002182 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183}
2184
2185/*
2186 * Encode an OPEN_DOWNGRADE request
2187 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002188static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2189 struct xdr_stream *xdr,
2190 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002193 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
Chuck Lever9f06c712010-12-14 14:59:18 +00002196 encode_compound_hdr(xdr, req, &hdr);
2197 encode_sequence(xdr, &args->seq_args, &hdr);
2198 encode_putfh(xdr, args->fh, &hdr);
2199 encode_open_downgrade(xdr, args, &hdr);
2200 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002201 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202}
2203
2204/*
2205 * Encode a LOCK request
2206 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002207static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2208 struct nfs_lock_args *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_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002218 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219}
2220
2221/*
2222 * Encode a LOCKT request
2223 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002224static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2225 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002228 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
Chuck Lever9f06c712010-12-14 14:59:18 +00002231 encode_compound_hdr(xdr, req, &hdr);
2232 encode_sequence(xdr, &args->seq_args, &hdr);
2233 encode_putfh(xdr, args->fh, &hdr);
2234 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002235 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236}
2237
2238/*
2239 * Encode a LOCKU request
2240 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002241static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2242 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002245 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
Chuck Lever9f06c712010-12-14 14:59:18 +00002248 encode_compound_hdr(xdr, req, &hdr);
2249 encode_sequence(xdr, &args->seq_args, &hdr);
2250 encode_putfh(xdr, args->fh, &hdr);
2251 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002252 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253}
2254
Chuck Lever9f06c712010-12-14 14:59:18 +00002255static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2256 struct xdr_stream *xdr,
2257 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002258{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002259 struct compound_hdr hdr = {
2260 .minorversion = 0,
2261 };
2262
Chuck Lever9f06c712010-12-14 14:59:18 +00002263 encode_compound_hdr(xdr, req, &hdr);
2264 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002265 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002266}
2267
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268/*
2269 * Encode a READLINK request
2270 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002271static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2272 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002275 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
Chuck Lever9f06c712010-12-14 14:59:18 +00002278 encode_compound_hdr(xdr, req, &hdr);
2279 encode_sequence(xdr, &args->seq_args, &hdr);
2280 encode_putfh(xdr, args->fh, &hdr);
2281 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002282
Benny Halevy28f56692009-04-01 09:22:09 -04002283 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002284 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002285 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286}
2287
2288/*
2289 * Encode a READDIR request
2290 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002291static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2292 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002295 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297
Chuck Lever9f06c712010-12-14 14:59:18 +00002298 encode_compound_hdr(xdr, req, &hdr);
2299 encode_sequence(xdr, &args->seq_args, &hdr);
2300 encode_putfh(xdr, args->fh, &hdr);
2301 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002302
Benny Halevy28f56692009-04-01 09:22:09 -04002303 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002304 args->pgbase, args->count);
2305 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002306 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002307 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002308 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309}
2310
2311/*
2312 * Encode a READ request
2313 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002314static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2315 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002318 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Chuck Lever9f06c712010-12-14 14:59:18 +00002321 encode_compound_hdr(xdr, req, &hdr);
2322 encode_sequence(xdr, &args->seq_args, &hdr);
2323 encode_putfh(xdr, args->fh, &hdr);
2324 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
Benny Halevy28f56692009-04-01 09:22:09 -04002326 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002328 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002329 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330}
2331
2332/*
2333 * Encode an SETATTR request
2334 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002335static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2336 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337{
Andy Adamson05d564f2008-12-23 16:06:15 -05002338 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002339 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002340 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Chuck Lever9f06c712010-12-14 14:59:18 +00002342 encode_compound_hdr(xdr, req, &hdr);
2343 encode_sequence(xdr, &args->seq_args, &hdr);
2344 encode_putfh(xdr, args->fh, &hdr);
2345 encode_setattr(xdr, args, args->server, &hdr);
2346 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002347 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348}
2349
2350/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002351 * Encode a GETACL request
2352 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002353static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2354 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002355{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002356 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002357 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002358 };
Benny Halevy28f56692009-04-01 09:22:09 -04002359 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002360
Chuck Lever9f06c712010-12-14 14:59:18 +00002361 encode_compound_hdr(xdr, req, &hdr);
2362 encode_sequence(xdr, &args->seq_args, &hdr);
2363 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fieldsd327cf72009-12-03 08:10:17 -05002364 replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002365 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002366
Benny Halevy28f56692009-04-01 09:22:09 -04002367 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002368 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05002369 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002370}
2371
2372/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 * Encode a WRITE request
2374 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002375static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2376 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002379 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
Chuck Lever9f06c712010-12-14 14:59:18 +00002382 encode_compound_hdr(xdr, req, &hdr);
2383 encode_sequence(xdr, &args->seq_args, &hdr);
2384 encode_putfh(xdr, args->fh, &hdr);
2385 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002386 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002387 if (args->bitmask)
2388 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002389 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390}
2391
2392/*
2393 * a COMMIT request
2394 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002395static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2396 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002399 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Chuck Lever9f06c712010-12-14 14:59:18 +00002402 encode_compound_hdr(xdr, req, &hdr);
2403 encode_sequence(xdr, &args->seq_args, &hdr);
2404 encode_putfh(xdr, args->fh, &hdr);
2405 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002406 if (args->bitmask)
2407 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002408 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409}
2410
2411/*
2412 * FSINFO request
2413 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002414static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2415 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002418 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
Chuck Lever9f06c712010-12-14 14:59:18 +00002421 encode_compound_hdr(xdr, req, &hdr);
2422 encode_sequence(xdr, &args->seq_args, &hdr);
2423 encode_putfh(xdr, args->fh, &hdr);
2424 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002425 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426}
2427
2428/*
2429 * a PATHCONF request
2430 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002431static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2432 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002435 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437
Chuck Lever9f06c712010-12-14 14:59:18 +00002438 encode_compound_hdr(xdr, req, &hdr);
2439 encode_sequence(xdr, &args->seq_args, &hdr);
2440 encode_putfh(xdr, args->fh, &hdr);
2441 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002442 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002443 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444}
2445
2446/*
2447 * a STATFS request
2448 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002449static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2450 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002453 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455
Chuck Lever9f06c712010-12-14 14:59:18 +00002456 encode_compound_hdr(xdr, req, &hdr);
2457 encode_sequence(xdr, &args->seq_args, &hdr);
2458 encode_putfh(xdr, args->fh, &hdr);
2459 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002460 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002461 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462}
2463
2464/*
2465 * GETATTR_BITMAP request
2466 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002467static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2468 struct xdr_stream *xdr,
2469 struct nfs4_server_caps_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->fhandle, &hdr);
2478 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002479 FATTR4_WORD0_LINK_SUPPORT|
2480 FATTR4_WORD0_SYMLINK_SUPPORT|
2481 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002482 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483}
2484
2485/*
2486 * a RENEW request
2487 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002488static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2489 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002492 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 };
2494
Chuck Lever9f06c712010-12-14 14:59:18 +00002495 encode_compound_hdr(xdr, req, &hdr);
2496 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002497 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498}
2499
2500/*
2501 * a SETCLIENTID request
2502 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002503static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2504 struct xdr_stream *xdr,
2505 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002508 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 };
2510
Chuck Lever9f06c712010-12-14 14:59:18 +00002511 encode_compound_hdr(xdr, req, &hdr);
2512 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002513 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514}
2515
2516/*
2517 * a SETCLIENTID_CONFIRM request
2518 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002519static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2520 struct xdr_stream *xdr,
2521 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002524 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 };
2526 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527
Chuck Lever9f06c712010-12-14 14:59:18 +00002528 encode_compound_hdr(xdr, req, &hdr);
2529 encode_setclientid_confirm(xdr, arg, &hdr);
2530 encode_putrootfh(xdr, &hdr);
2531 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002532 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533}
2534
2535/*
2536 * DELEGRETURN request
2537 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002538static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2539 struct xdr_stream *xdr,
2540 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002543 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545
Chuck Lever9f06c712010-12-14 14:59:18 +00002546 encode_compound_hdr(xdr, req, &hdr);
2547 encode_sequence(xdr, &args->seq_args, &hdr);
2548 encode_putfh(xdr, args->fhandle, &hdr);
2549 encode_delegreturn(xdr, args->stateid, &hdr);
2550 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002551 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552}
2553
2554/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002555 * Encode FS_LOCATIONS request
2556 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002557static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2558 struct xdr_stream *xdr,
2559 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002560{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002561 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002562 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002563 };
Benny Halevy28f56692009-04-01 09:22:09 -04002564 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002565
Chuck Lever9f06c712010-12-14 14:59:18 +00002566 encode_compound_hdr(xdr, req, &hdr);
2567 encode_sequence(xdr, &args->seq_args, &hdr);
2568 encode_putfh(xdr, args->dir_fh, &hdr);
2569 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002570 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002571 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002572
Benny Halevy28f56692009-04-01 09:22:09 -04002573 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002574 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002575 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002576}
2577
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002578/*
2579 * Encode SECINFO request
2580 */
2581static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2582 struct xdr_stream *xdr,
2583 struct nfs4_secinfo_arg *args)
2584{
2585 struct compound_hdr hdr = {
2586 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2587 };
2588
2589 encode_compound_hdr(xdr, req, &hdr);
2590 encode_sequence(xdr, &args->seq_args, &hdr);
2591 encode_putfh(xdr, args->dir_fh, &hdr);
2592 encode_secinfo(xdr, args->name, &hdr);
2593 encode_nops(&hdr);
2594}
2595
Benny Halevy99fe60d2009-04-01 09:22:29 -04002596#if defined(CONFIG_NFS_V4_1)
2597/*
2598 * EXCHANGE_ID request
2599 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002600static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2601 struct xdr_stream *xdr,
2602 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002603{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002604 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002605 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002606 };
2607
Chuck Lever9f06c712010-12-14 14:59:18 +00002608 encode_compound_hdr(xdr, req, &hdr);
2609 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002610 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002611}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002612
2613/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002614 * a CREATE_SESSION request
2615 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002616static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2617 struct xdr_stream *xdr,
2618 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002619{
Andy Adamsonfc931582009-04-01 09:22:31 -04002620 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002621 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002622 };
2623
Chuck Lever9f06c712010-12-14 14:59:18 +00002624 encode_compound_hdr(xdr, req, &hdr);
2625 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002626 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002627}
2628
2629/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002630 * a DESTROY_SESSION request
2631 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002632static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2633 struct xdr_stream *xdr,
2634 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002635{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002636 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002637 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002638 };
2639
Chuck Lever9f06c712010-12-14 14:59:18 +00002640 encode_compound_hdr(xdr, req, &hdr);
2641 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002642 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002643}
2644
2645/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002646 * a SEQUENCE request
2647 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002648static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2649 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002650{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002651 struct compound_hdr hdr = {
2652 .minorversion = nfs4_xdr_minorversion(args),
2653 };
2654
Chuck Lever9f06c712010-12-14 14:59:18 +00002655 encode_compound_hdr(xdr, req, &hdr);
2656 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002657 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002658}
2659
2660/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002661 * a GET_LEASE_TIME request
2662 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002663static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2664 struct xdr_stream *xdr,
2665 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002666{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002667 struct compound_hdr hdr = {
2668 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2669 };
2670 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
2671
Chuck Lever9f06c712010-12-14 14:59:18 +00002672 encode_compound_hdr(xdr, req, &hdr);
2673 encode_sequence(xdr, &args->la_seq_args, &hdr);
2674 encode_putrootfh(xdr, &hdr);
2675 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002676 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002677}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002678
2679/*
2680 * a RECLAIM_COMPLETE request
2681 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002682static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2683 struct xdr_stream *xdr,
2684 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002685{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002686 struct compound_hdr hdr = {
2687 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2688 };
2689
Chuck Lever9f06c712010-12-14 14:59:18 +00002690 encode_compound_hdr(xdr, req, &hdr);
2691 encode_sequence(xdr, &args->seq_args, &hdr);
2692 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002693 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002694}
2695
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002696/*
2697 * Encode GETDEVICEINFO request
2698 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002699static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2700 struct xdr_stream *xdr,
2701 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002702{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002703 struct compound_hdr hdr = {
2704 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2705 };
2706
Chuck Lever9f06c712010-12-14 14:59:18 +00002707 encode_compound_hdr(xdr, req, &hdr);
2708 encode_sequence(xdr, &args->seq_args, &hdr);
2709 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002710
2711 /* set up reply kvec. Subtract notification bitmap max size (2)
2712 * so that notification bitmap is put in xdr_buf tail */
2713 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2714 args->pdev->pages, args->pdev->pgbase,
2715 args->pdev->pglen);
2716
2717 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002718}
2719
2720/*
2721 * Encode LAYOUTGET request
2722 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002723static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2724 struct xdr_stream *xdr,
2725 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002726{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002727 struct compound_hdr hdr = {
2728 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2729 };
2730
Chuck Lever9f06c712010-12-14 14:59:18 +00002731 encode_compound_hdr(xdr, req, &hdr);
2732 encode_sequence(xdr, &args->seq_args, &hdr);
2733 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2734 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002735
2736 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2737 args->layout.pages, 0, args->layout.pglen);
2738
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002739 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002740}
Andy Adamson863a3c62011-03-23 13:27:54 +00002741
2742/*
2743 * Encode LAYOUTCOMMIT request
2744 */
Benny Halevycbe82602011-05-22 19:52:37 +03002745static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2746 struct xdr_stream *xdr,
2747 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002748{
2749 struct compound_hdr hdr = {
2750 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2751 };
2752
2753 encode_compound_hdr(xdr, req, &hdr);
2754 encode_sequence(xdr, &args->seq_args, &hdr);
2755 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2756 encode_layoutcommit(xdr, args, &hdr);
2757 encode_getfattr(xdr, args->bitmask, &hdr);
2758 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002759}
2760
2761/*
2762 * Encode LAYOUTRETURN request
2763 */
2764static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2765 struct xdr_stream *xdr,
2766 struct nfs4_layoutreturn_args *args)
2767{
2768 struct compound_hdr hdr = {
2769 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2770 };
2771
2772 encode_compound_hdr(xdr, req, &hdr);
2773 encode_sequence(xdr, &args->seq_args, &hdr);
2774 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2775 encode_layoutreturn(xdr, args, &hdr);
2776 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002777}
Benny Halevy99fe60d2009-04-01 09:22:29 -04002778#endif /* CONFIG_NFS_V4_1 */
2779
Benny Halevy686841b2009-08-14 17:19:48 +03002780static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
2781{
2782 dprintk("nfs: %s: prematurely hit end of receive buffer. "
2783 "Remaining buffer length is %tu words.\n",
2784 func, xdr->end - xdr->p);
2785}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786
Trond Myklebust683b57b2006-06-09 09:34:22 -04002787static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788{
Al Viro8687b632006-10-19 23:28:48 -07002789 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790
Benny Halevyc0eae662009-08-14 17:20:14 +03002791 p = xdr_inline_decode(xdr, 4);
2792 if (unlikely(!p))
2793 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002794 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03002795 p = xdr_inline_decode(xdr, *len);
2796 if (unlikely(!p))
2797 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 *string = (char *)p;
2799 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002800out_overflow:
2801 print_overflow_msg(__func__, xdr);
2802 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803}
2804
2805static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2806{
Al Viro8687b632006-10-19 23:28:48 -07002807 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808
Benny Halevyc0eae662009-08-14 17:20:14 +03002809 p = xdr_inline_decode(xdr, 8);
2810 if (unlikely(!p))
2811 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002812 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03002813 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002814
Benny Halevyc0eae662009-08-14 17:20:14 +03002815 p = xdr_inline_decode(xdr, hdr->taglen + 4);
2816 if (unlikely(!p))
2817 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 hdr->tag = (char *)p;
2819 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03002820 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05002821 if (unlikely(hdr->nops < 1))
2822 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002824out_overflow:
2825 print_overflow_msg(__func__, xdr);
2826 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827}
2828
2829static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2830{
Al Viro8687b632006-10-19 23:28:48 -07002831 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 uint32_t opnum;
2833 int32_t nfserr;
2834
Benny Halevyc0eae662009-08-14 17:20:14 +03002835 p = xdr_inline_decode(xdr, 8);
2836 if (unlikely(!p))
2837 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03002838 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002840 dprintk("nfs: Server returned operation"
2841 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 opnum, expected);
2843 return -EIO;
2844 }
Benny Halevycccddf42009-08-14 17:20:19 +03002845 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002847 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002849out_overflow:
2850 print_overflow_msg(__func__, xdr);
2851 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852}
2853
2854/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002855static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856{
Al Viro8687b632006-10-19 23:28:48 -07002857 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002858 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 char *str;
2860
Benny Halevyc0eae662009-08-14 17:20:14 +03002861 p = xdr_inline_decode(xdr, 12);
2862 if (likely(p))
2863 return decode_opaque_inline(xdr, &strlen, &str);
2864 print_overflow_msg(__func__, xdr);
2865 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866}
2867
2868static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2869{
Al Viro8687b632006-10-19 23:28:48 -07002870 uint32_t bmlen;
2871 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872
Benny Halevyc0eae662009-08-14 17:20:14 +03002873 p = xdr_inline_decode(xdr, 4);
2874 if (unlikely(!p))
2875 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002876 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877
2878 bitmap[0] = bitmap[1] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002879 p = xdr_inline_decode(xdr, (bmlen << 2));
2880 if (unlikely(!p))
2881 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03002883 bitmap[0] = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 if (bmlen > 1)
Benny Halevycccddf42009-08-14 17:20:19 +03002885 bitmap[1] = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 }
2887 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002888out_overflow:
2889 print_overflow_msg(__func__, xdr);
2890 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891}
2892
Al Viro8687b632006-10-19 23:28:48 -07002893static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894{
Al Viro8687b632006-10-19 23:28:48 -07002895 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
Benny Halevyc0eae662009-08-14 17:20:14 +03002897 p = xdr_inline_decode(xdr, 4);
2898 if (unlikely(!p))
2899 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002900 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 *savep = xdr->p;
2902 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03002903out_overflow:
2904 print_overflow_msg(__func__, xdr);
2905 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906}
2907
2908static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2909{
2910 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04002911 int ret;
2912 ret = decode_attr_bitmap(xdr, bitmask);
2913 if (unlikely(ret < 0))
2914 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2916 } else
2917 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002918 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 return 0;
2920}
2921
2922static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2923{
Al Viro8687b632006-10-19 23:28:48 -07002924 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002925 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926
2927 *type = 0;
2928 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2929 return -EIO;
2930 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
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 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002936 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 return -EIO;
2938 }
2939 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002940 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002942 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002943 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002944out_overflow:
2945 print_overflow_msg(__func__, xdr);
2946 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947}
2948
2949static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2950{
Al Viro8687b632006-10-19 23:28:48 -07002951 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002952 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953
2954 *change = 0;
2955 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2956 return -EIO;
2957 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002958 p = xdr_inline_decode(xdr, 8);
2959 if (unlikely(!p))
2960 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002961 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002963 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002965 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002967 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002968out_overflow:
2969 print_overflow_msg(__func__, xdr);
2970 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971}
2972
2973static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2974{
Al Viro8687b632006-10-19 23:28:48 -07002975 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002976 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977
2978 *size = 0;
2979 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2980 return -EIO;
2981 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03002982 p = xdr_inline_decode(xdr, 8);
2983 if (unlikely(!p))
2984 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03002985 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002987 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002989 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002990 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03002991out_overflow:
2992 print_overflow_msg(__func__, xdr);
2993 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994}
2995
2996static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2997{
Al Viro8687b632006-10-19 23:28:48 -07002998 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999
3000 *res = 0;
3001 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3002 return -EIO;
3003 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003004 p = xdr_inline_decode(xdr, 4);
3005 if (unlikely(!p))
3006 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003007 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3009 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003010 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003012out_overflow:
3013 print_overflow_msg(__func__, xdr);
3014 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015}
3016
3017static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3018{
Al Viro8687b632006-10-19 23:28:48 -07003019 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020
3021 *res = 0;
3022 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3023 return -EIO;
3024 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003025 p = xdr_inline_decode(xdr, 4);
3026 if (unlikely(!p))
3027 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003028 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3030 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003031 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003033out_overflow:
3034 print_overflow_msg(__func__, xdr);
3035 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036}
3037
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003038static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039{
Al Viro8687b632006-10-19 23:28:48 -07003040 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003041 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042
3043 fsid->major = 0;
3044 fsid->minor = 0;
3045 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3046 return -EIO;
3047 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003048 p = xdr_inline_decode(xdr, 16);
3049 if (unlikely(!p))
3050 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003051 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003052 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003054 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003056 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 (unsigned long long)fsid->major,
3058 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003059 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003060out_overflow:
3061 print_overflow_msg(__func__, xdr);
3062 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063}
3064
3065static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3066{
Al Viro8687b632006-10-19 23:28:48 -07003067 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068
3069 *res = 60;
3070 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3071 return -EIO;
3072 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003073 p = xdr_inline_decode(xdr, 4);
3074 if (unlikely(!p))
3075 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003076 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3078 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003079 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003081out_overflow:
3082 print_overflow_msg(__func__, xdr);
3083 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084}
3085
Bryan Schumakerae42c702010-10-21 16:33:17 -04003086static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap)
3087{
3088 __be32 *p;
3089
3090 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3091 return -EIO;
3092 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3093 p = xdr_inline_decode(xdr, 4);
3094 if (unlikely(!p))
3095 goto out_overflow;
3096 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Bryan Schumaker7ebb9312011-03-24 17:12:30 +00003097 return -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003098 }
3099 return 0;
3100out_overflow:
3101 print_overflow_msg(__func__, xdr);
3102 return -EIO;
3103}
3104
3105static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3106{
3107 __be32 *p;
3108 int len;
3109
Trond Myklebust7ad07352010-10-23 15:34:20 -04003110 if (fh != NULL)
3111 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003112
3113 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3114 return -EIO;
3115 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3116 p = xdr_inline_decode(xdr, 4);
3117 if (unlikely(!p))
3118 goto out_overflow;
3119 len = be32_to_cpup(p);
3120 if (len > NFS4_FHSIZE)
3121 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003122 p = xdr_inline_decode(xdr, len);
3123 if (unlikely(!p))
3124 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003125 if (fh != NULL) {
3126 memcpy(fh->data, p, len);
3127 fh->size = len;
3128 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003129 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3130 }
3131 return 0;
3132out_overflow:
3133 print_overflow_msg(__func__, xdr);
3134 return -EIO;
3135}
3136
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3138{
Al Viro8687b632006-10-19 23:28:48 -07003139 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140
3141 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3142 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3143 return -EIO;
3144 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003145 p = xdr_inline_decode(xdr, 4);
3146 if (unlikely(!p))
3147 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003148 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3150 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003151 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003153out_overflow:
3154 print_overflow_msg(__func__, xdr);
3155 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156}
3157
3158static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3159{
Al Viro8687b632006-10-19 23:28:48 -07003160 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003161 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162
3163 *fileid = 0;
3164 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3165 return -EIO;
3166 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003167 p = xdr_inline_decode(xdr, 8);
3168 if (unlikely(!p))
3169 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003170 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003172 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003174 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003175 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003176out_overflow:
3177 print_overflow_msg(__func__, xdr);
3178 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179}
3180
Manoj Naik99baf622006-06-09 09:34:24 -04003181static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3182{
Al Viro8687b632006-10-19 23:28:48 -07003183 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003184 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003185
3186 *fileid = 0;
3187 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3188 return -EIO;
3189 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003190 p = xdr_inline_decode(xdr, 8);
3191 if (unlikely(!p))
3192 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003193 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003194 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003195 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003196 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003197 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003198 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003199out_overflow:
3200 print_overflow_msg(__func__, xdr);
3201 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003202}
3203
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3205{
Al Viro8687b632006-10-19 23:28:48 -07003206 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 int status = 0;
3208
3209 *res = 0;
3210 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3211 return -EIO;
3212 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003213 p = xdr_inline_decode(xdr, 8);
3214 if (unlikely(!p))
3215 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003216 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3218 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003219 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003221out_overflow:
3222 print_overflow_msg(__func__, xdr);
3223 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224}
3225
3226static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3227{
Al Viro8687b632006-10-19 23:28:48 -07003228 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 int status = 0;
3230
3231 *res = 0;
3232 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3233 return -EIO;
3234 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003235 p = xdr_inline_decode(xdr, 8);
3236 if (unlikely(!p))
3237 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003238 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3240 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003241 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003243out_overflow:
3244 print_overflow_msg(__func__, xdr);
3245 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246}
3247
3248static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3249{
Al Viro8687b632006-10-19 23:28:48 -07003250 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 int status = 0;
3252
3253 *res = 0;
3254 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3255 return -EIO;
3256 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003257 p = xdr_inline_decode(xdr, 8);
3258 if (unlikely(!p))
3259 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003260 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3262 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003263 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003265out_overflow:
3266 print_overflow_msg(__func__, xdr);
3267 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268}
3269
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003270static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3271{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003272 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003273 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003274 int status = 0;
3275
Benny Halevyc0eae662009-08-14 17:20:14 +03003276 p = xdr_inline_decode(xdr, 4);
3277 if (unlikely(!p))
3278 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003279 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003280 if (n == 0)
3281 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003282 dprintk("path ");
3283 path->ncomponents = 0;
3284 while (path->ncomponents < n) {
3285 struct nfs4_string *component = &path->components[path->ncomponents];
3286 status = decode_opaque_inline(xdr, &component->len, &component->data);
3287 if (unlikely(status != 0))
3288 goto out_eio;
3289 if (path->ncomponents != n)
3290 dprintk("/");
3291 dprintk("%s", component->data);
3292 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3293 path->ncomponents++;
3294 else {
3295 dprintk("cannot parse %d components in path\n", n);
3296 goto out_eio;
3297 }
3298 }
3299out:
3300 dprintk("\n");
3301 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003302root_path:
3303/* a root pathname is sent as a zero component4 */
3304 path->ncomponents = 1;
3305 path->components[0].len=0;
3306 path->components[0].data=NULL;
3307 dprintk("path /\n");
3308 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003309out_eio:
3310 dprintk(" status %d", status);
3311 status = -EIO;
3312 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003313out_overflow:
3314 print_overflow_msg(__func__, xdr);
3315 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003316}
3317
3318static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003319{
3320 int n;
Al Viro8687b632006-10-19 23:28:48 -07003321 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003322 int status = -EIO;
3323
3324 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3325 goto out;
3326 status = 0;
3327 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3328 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003329 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003330 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003331 if (unlikely(status != 0))
3332 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003333 p = xdr_inline_decode(xdr, 4);
3334 if (unlikely(!p))
3335 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003336 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003337 if (n <= 0)
3338 goto out_eio;
3339 res->nlocations = 0;
3340 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003341 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003342 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003343
Benny Halevyc0eae662009-08-14 17:20:14 +03003344 p = xdr_inline_decode(xdr, 4);
3345 if (unlikely(!p))
3346 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003347 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003348
3349 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003350 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003351 while (loc->nservers < m) {
3352 struct nfs4_string *server = &loc->servers[loc->nservers];
3353 status = decode_opaque_inline(xdr, &server->len, &server->data);
3354 if (unlikely(status != 0))
3355 goto out_eio;
3356 dprintk("%s ", server->data);
3357 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3358 loc->nservers++;
3359 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003360 unsigned int i;
3361 dprintk("%s: using first %u of %u servers "
3362 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003363 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003364 NFS4_FS_LOCATION_MAXSERVERS,
3365 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003366 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003367 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003368 char *data;
3369 status = decode_opaque_inline(xdr, &len, &data);
3370 if (unlikely(status != 0))
3371 goto out_eio;
3372 }
3373 }
3374 }
3375 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003376 if (unlikely(status != 0))
3377 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003378 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003379 res->nlocations++;
3380 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003381 if (res->nlocations != 0)
3382 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003383out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003384 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003385 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003386out_overflow:
3387 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003388out_eio:
3389 status = -EIO;
3390 goto out;
3391}
3392
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3394{
Al Viro8687b632006-10-19 23:28:48 -07003395 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 int status = 0;
3397
3398 *res = 0;
3399 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3400 return -EIO;
3401 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003402 p = xdr_inline_decode(xdr, 8);
3403 if (unlikely(!p))
3404 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003405 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3407 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003408 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003410out_overflow:
3411 print_overflow_msg(__func__, xdr);
3412 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413}
3414
3415static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3416{
Al Viro8687b632006-10-19 23:28:48 -07003417 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 int status = 0;
3419
3420 *maxlink = 1;
3421 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3422 return -EIO;
3423 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003424 p = xdr_inline_decode(xdr, 4);
3425 if (unlikely(!p))
3426 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003427 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3429 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003430 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003432out_overflow:
3433 print_overflow_msg(__func__, xdr);
3434 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435}
3436
3437static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3438{
Al Viro8687b632006-10-19 23:28:48 -07003439 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 int status = 0;
3441
3442 *maxname = 1024;
3443 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3444 return -EIO;
3445 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003446 p = xdr_inline_decode(xdr, 4);
3447 if (unlikely(!p))
3448 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003449 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3451 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003452 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003454out_overflow:
3455 print_overflow_msg(__func__, xdr);
3456 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457}
3458
3459static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3460{
Al Viro8687b632006-10-19 23:28:48 -07003461 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 int status = 0;
3463
3464 *res = 1024;
3465 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3466 return -EIO;
3467 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3468 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003469 p = xdr_inline_decode(xdr, 8);
3470 if (unlikely(!p))
3471 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003472 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 if (maxread > 0x7FFFFFFF)
3474 maxread = 0x7FFFFFFF;
3475 *res = (uint32_t)maxread;
3476 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3477 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003478 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003480out_overflow:
3481 print_overflow_msg(__func__, xdr);
3482 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483}
3484
3485static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3486{
Al Viro8687b632006-10-19 23:28:48 -07003487 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 int status = 0;
3489
3490 *res = 1024;
3491 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3492 return -EIO;
3493 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3494 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003495 p = xdr_inline_decode(xdr, 8);
3496 if (unlikely(!p))
3497 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003498 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 if (maxwrite > 0x7FFFFFFF)
3500 maxwrite = 0x7FFFFFFF;
3501 *res = (uint32_t)maxwrite;
3502 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3503 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003504 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003506out_overflow:
3507 print_overflow_msg(__func__, xdr);
3508 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509}
3510
Trond Myklebustbca79472009-03-11 14:10:26 -04003511static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512{
Trond Myklebustbca79472009-03-11 14:10:26 -04003513 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003514 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003515 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516
3517 *mode = 0;
3518 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3519 return -EIO;
3520 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003521 p = xdr_inline_decode(xdr, 4);
3522 if (unlikely(!p))
3523 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003524 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003525 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003527 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003529 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003530 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003531out_overflow:
3532 print_overflow_msg(__func__, xdr);
3533 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534}
3535
3536static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3537{
Al Viro8687b632006-10-19 23:28:48 -07003538 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003539 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540
3541 *nlink = 1;
3542 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3543 return -EIO;
3544 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003545 p = xdr_inline_decode(xdr, 4);
3546 if (unlikely(!p))
3547 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003548 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003550 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003552 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003553 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003554out_overflow:
3555 print_overflow_msg(__func__, xdr);
3556 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557}
3558
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003559static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003560 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561{
Al Viro8687b632006-10-19 23:28:48 -07003562 uint32_t len;
3563 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003564 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565
3566 *uid = -2;
3567 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3568 return -EIO;
3569 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003570 p = xdr_inline_decode(xdr, 4);
3571 if (unlikely(!p))
3572 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003573 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003574 p = xdr_inline_decode(xdr, len);
3575 if (unlikely(!p))
3576 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003577 if (!may_sleep) {
3578 /* do nothing */
3579 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003580 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003581 ret = NFS_ATTR_FATTR_OWNER;
3582 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003584 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003586 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003587 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3589 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003590 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003591 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003592out_overflow:
3593 print_overflow_msg(__func__, xdr);
3594 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595}
3596
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003597static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003598 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599{
Al Viro8687b632006-10-19 23:28:48 -07003600 uint32_t len;
3601 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003602 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603
3604 *gid = -2;
3605 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3606 return -EIO;
3607 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003608 p = xdr_inline_decode(xdr, 4);
3609 if (unlikely(!p))
3610 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003611 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003612 p = xdr_inline_decode(xdr, len);
3613 if (unlikely(!p))
3614 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003615 if (!may_sleep) {
3616 /* do nothing */
3617 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003618 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003619 ret = NFS_ATTR_FATTR_GROUP;
3620 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003622 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003624 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003625 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3627 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003628 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003629 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003630out_overflow:
3631 print_overflow_msg(__func__, xdr);
3632 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633}
3634
3635static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3636{
Al Viro8687b632006-10-19 23:28:48 -07003637 uint32_t major = 0, minor = 0;
3638 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003639 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640
3641 *rdev = MKDEV(0,0);
3642 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3643 return -EIO;
3644 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3645 dev_t tmp;
3646
Benny Halevyc0eae662009-08-14 17:20:14 +03003647 p = xdr_inline_decode(xdr, 8);
3648 if (unlikely(!p))
3649 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003650 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003651 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 tmp = MKDEV(major, minor);
3653 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3654 *rdev = tmp;
3655 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003656 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003658 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003659 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003660out_overflow:
3661 print_overflow_msg(__func__, xdr);
3662 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663}
3664
3665static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3666{
Al Viro8687b632006-10-19 23:28:48 -07003667 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 int status = 0;
3669
3670 *res = 0;
3671 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3672 return -EIO;
3673 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003674 p = xdr_inline_decode(xdr, 8);
3675 if (unlikely(!p))
3676 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003677 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3679 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003680 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003682out_overflow:
3683 print_overflow_msg(__func__, xdr);
3684 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685}
3686
3687static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3688{
Al Viro8687b632006-10-19 23:28:48 -07003689 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 int status = 0;
3691
3692 *res = 0;
3693 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3694 return -EIO;
3695 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003696 p = xdr_inline_decode(xdr, 8);
3697 if (unlikely(!p))
3698 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003699 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3701 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003702 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003704out_overflow:
3705 print_overflow_msg(__func__, xdr);
3706 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707}
3708
3709static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3710{
Al Viro8687b632006-10-19 23:28:48 -07003711 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 int status = 0;
3713
3714 *res = 0;
3715 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3716 return -EIO;
3717 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003718 p = xdr_inline_decode(xdr, 8);
3719 if (unlikely(!p))
3720 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003721 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3723 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003724 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003726out_overflow:
3727 print_overflow_msg(__func__, xdr);
3728 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729}
3730
3731static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3732{
Al Viro8687b632006-10-19 23:28:48 -07003733 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003734 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735
3736 *used = 0;
3737 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3738 return -EIO;
3739 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003740 p = xdr_inline_decode(xdr, 8);
3741 if (unlikely(!p))
3742 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003743 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003745 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003747 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003749 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003750out_overflow:
3751 print_overflow_msg(__func__, xdr);
3752 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753}
3754
3755static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3756{
Al Viro8687b632006-10-19 23:28:48 -07003757 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 uint64_t sec;
3759 uint32_t nsec;
3760
Benny Halevyc0eae662009-08-14 17:20:14 +03003761 p = xdr_inline_decode(xdr, 12);
3762 if (unlikely(!p))
3763 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003764 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03003765 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 time->tv_sec = (time_t)sec;
3767 time->tv_nsec = (long)nsec;
3768 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003769out_overflow:
3770 print_overflow_msg(__func__, xdr);
3771 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772}
3773
3774static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3775{
3776 int status = 0;
3777
3778 time->tv_sec = 0;
3779 time->tv_nsec = 0;
3780 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
3781 return -EIO;
3782 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
3783 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003784 if (status == 0)
3785 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
3787 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003788 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 return status;
3790}
3791
3792static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3793{
3794 int status = 0;
3795
3796 time->tv_sec = 0;
3797 time->tv_nsec = 0;
3798 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
3799 return -EIO;
3800 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
3801 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003802 if (status == 0)
3803 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
3805 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003806 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 return status;
3808}
3809
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07003810static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
3811 struct timespec *time)
3812{
3813 int status = 0;
3814
3815 time->tv_sec = 0;
3816 time->tv_nsec = 0;
3817 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
3818 return -EIO;
3819 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
3820 status = decode_attr_time(xdr, time);
3821 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
3822 }
3823 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
3824 (long)time->tv_nsec);
3825 return status;
3826}
3827
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
3829{
3830 int status = 0;
3831
3832 time->tv_sec = 0;
3833 time->tv_nsec = 0;
3834 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
3835 return -EIO;
3836 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
3837 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04003838 if (status == 0)
3839 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
3841 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003842 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 return status;
3844}
3845
Al Viro8687b632006-10-19 23:28:48 -07003846static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847{
3848 unsigned int attrwords = XDR_QUADLEN(attrlen);
3849 unsigned int nwords = xdr->p - savep;
3850
3851 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003852 dprintk("%s: server returned incorrect attribute length: "
3853 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003854 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 attrwords << 2,
3856 (attrwords < nwords) ? '<' : '>',
3857 nwords << 2);
3858 return -EIO;
3859 }
3860 return 0;
3861}
3862
3863static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3864{
Al Viro8687b632006-10-19 23:28:48 -07003865 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866
Benny Halevyc0eae662009-08-14 17:20:14 +03003867 p = xdr_inline_decode(xdr, 20);
3868 if (unlikely(!p))
3869 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003870 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003871 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03003872 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003874out_overflow:
3875 print_overflow_msg(__func__, xdr);
3876 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877}
3878
3879static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
3880{
Al Viro8687b632006-10-19 23:28:48 -07003881 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 uint32_t supp, acc;
3883 int status;
3884
3885 status = decode_op_hdr(xdr, OP_ACCESS);
3886 if (status)
3887 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003888 p = xdr_inline_decode(xdr, 8);
3889 if (unlikely(!p))
3890 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003891 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003892 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 access->supported = supp;
3894 access->access = acc;
3895 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003896out_overflow:
3897 print_overflow_msg(__func__, xdr);
3898 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899}
3900
Benny Halevy07d30432009-08-14 17:19:52 +03003901static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902{
Al Viro8687b632006-10-19 23:28:48 -07003903 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03003904
3905 p = xdr_inline_decode(xdr, len);
3906 if (likely(p)) {
3907 memcpy(buf, p, len);
3908 return 0;
3909 }
3910 print_overflow_msg(__func__, xdr);
3911 return -EIO;
3912}
3913
3914static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
3915{
3916 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917}
3918
3919static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3920{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 int status;
3922
3923 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003924 if (status != -EIO)
3925 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03003926 if (!status)
3927 status = decode_stateid(xdr, &res->stateid);
3928 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929}
3930
Benny Halevydb942bb2009-08-14 17:19:56 +03003931static int decode_verifier(struct xdr_stream *xdr, void *verifier)
3932{
3933 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934}
3935
3936static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
3937{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 int status;
3939
3940 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03003941 if (!status)
3942 status = decode_verifier(xdr, res->verf->verifier);
3943 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944}
3945
3946static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3947{
Al Viro8687b632006-10-19 23:28:48 -07003948 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 uint32_t bmlen;
3950 int status;
3951
3952 status = decode_op_hdr(xdr, OP_CREATE);
3953 if (status)
3954 return status;
3955 if ((status = decode_change_info(xdr, cinfo)))
3956 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003957 p = xdr_inline_decode(xdr, 4);
3958 if (unlikely(!p))
3959 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003960 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003961 p = xdr_inline_decode(xdr, bmlen << 2);
3962 if (likely(p))
3963 return 0;
3964out_overflow:
3965 print_overflow_msg(__func__, xdr);
3966 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967}
3968
3969static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
3970{
Al Viro8687b632006-10-19 23:28:48 -07003971 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003972 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 int status;
3974
3975 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3976 goto xdr_error;
3977 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3978 goto xdr_error;
3979 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3980 goto xdr_error;
3981 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
3982 goto xdr_error;
3983 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
3984 goto xdr_error;
3985 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
3986 goto xdr_error;
3987 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
3988 goto xdr_error;
3989 status = verify_attr_len(xdr, savep, attrlen);
3990xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003991 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 return status;
3993}
Andy Adamson6c0195a2008-12-23 16:06:15 -05003994
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
3996{
Al Viro8687b632006-10-19 23:28:48 -07003997 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003998 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004000
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4002 goto xdr_error;
4003 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4004 goto xdr_error;
4005 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4006 goto xdr_error;
4007
4008 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4009 goto xdr_error;
4010 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4011 goto xdr_error;
4012 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4013 goto xdr_error;
4014 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4015 goto xdr_error;
4016 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4017 goto xdr_error;
4018 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4019 goto xdr_error;
4020
4021 status = verify_attr_len(xdr, savep, attrlen);
4022xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004023 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 return status;
4025}
4026
4027static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
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;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004032
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 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
4040 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4041 goto xdr_error;
4042 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4043 goto xdr_error;
4044
4045 status = verify_attr_len(xdr, savep, attrlen);
4046xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004047 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 return status;
4049}
4050
Bryan Schumakerae42c702010-10-21 16:33:17 -04004051static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4052 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004053 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054{
Trond Myklebustbca79472009-03-11 14:10:26 -04004055 int status;
4056 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004057 uint32_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004059 status = decode_attr_type(xdr, bitmap, &type);
4060 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004062 fattr->mode = 0;
4063 if (status != 0) {
4064 fattr->mode |= nfs_type2fmt[type];
4065 fattr->valid |= status;
4066 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004068 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4069 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004071 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004072
4073 status = decode_attr_size(xdr, bitmap, &fattr->size);
4074 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004076 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004077
4078 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4079 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004081 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004082
Bryan Schumakerae42c702010-10-21 16:33:17 -04004083 status = decode_attr_error(xdr, bitmap);
Bryan Schumaker7ebb9312011-03-24 17:12:30 +00004084 if (status == -NFS4ERR_WRONGSEC) {
4085 nfs_fixup_secinfo_attributes(fattr, fh);
4086 status = 0;
4087 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04004088 if (status < 0)
4089 goto xdr_error;
4090
4091 status = decode_attr_filehandle(xdr, bitmap, fh);
4092 if (status < 0)
4093 goto xdr_error;
4094
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004095 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4096 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004098 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004099
4100 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04004101 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004102 fattr));
4103 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004104 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004105 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004106
4107 status = decode_attr_mode(xdr, bitmap, &fmode);
4108 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004110 if (status != 0) {
4111 fattr->mode |= fmode;
4112 fattr->valid |= status;
4113 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004114
4115 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4116 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004118 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004119
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004120 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004121 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004123 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004124
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004125 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004126 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004128 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004129
4130 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4131 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004133 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004134
4135 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4136 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004138 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004139
4140 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4141 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004143 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004144
4145 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4146 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004148 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004149
4150 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4151 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004153 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004154
Trond Myklebust28331a42011-04-27 13:47:52 -04004155 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004156 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004157 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004158 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004159
Bryan Schumakerae42c702010-10-21 16:33:17 -04004160xdr_error:
4161 dprintk("%s: xdr returned %d\n", __func__, -status);
4162 return status;
4163}
4164
4165static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4166 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4167{
4168 __be32 *savep;
4169 uint32_t attrlen,
4170 bitmap[2] = {0};
4171 int status;
4172
4173 status = decode_op_hdr(xdr, OP_GETATTR);
4174 if (status < 0)
4175 goto xdr_error;
4176
4177 status = decode_attr_bitmap(xdr, bitmap);
4178 if (status < 0)
4179 goto xdr_error;
4180
4181 status = decode_attr_length(xdr, &attrlen, &savep);
4182 if (status < 0)
4183 goto xdr_error;
4184
4185 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4186 if (status < 0)
4187 goto xdr_error;
4188
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004189 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004191 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 return status;
4193}
4194
Bryan Schumakerae42c702010-10-21 16:33:17 -04004195static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4196 const struct nfs_server *server, int may_sleep)
4197{
4198 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4199}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200
Andy Adamson504913f2010-10-20 00:17:57 -04004201/*
4202 * Decode potentially multiple layout types. Currently we only support
4203 * one layout driver per file system.
4204 */
4205static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4206 uint32_t *layouttype)
4207{
4208 uint32_t *p;
4209 int num;
4210
4211 p = xdr_inline_decode(xdr, 4);
4212 if (unlikely(!p))
4213 goto out_overflow;
4214 num = be32_to_cpup(p);
4215
4216 /* pNFS is not supported by the underlying file system */
4217 if (num == 0) {
4218 *layouttype = 0;
4219 return 0;
4220 }
4221 if (num > 1)
4222 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4223 "per filesystem not supported\n", __func__);
4224
4225 /* Decode and set first layout type, move xdr->p past unused types */
4226 p = xdr_inline_decode(xdr, num * 4);
4227 if (unlikely(!p))
4228 goto out_overflow;
4229 *layouttype = be32_to_cpup(p);
4230 return 0;
4231out_overflow:
4232 print_overflow_msg(__func__, xdr);
4233 return -EIO;
4234}
4235
4236/*
4237 * The type of file system exported.
4238 * Note we must ensure that layouttype is set in any non-error case.
4239 */
4240static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4241 uint32_t *layouttype)
4242{
4243 int status = 0;
4244
4245 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4246 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4247 return -EIO;
4248 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4249 status = decode_first_pnfs_layout_type(xdr, layouttype);
4250 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4251 } else
4252 *layouttype = 0;
4253 return status;
4254}
4255
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4257{
Al Viro8687b632006-10-19 23:28:48 -07004258 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259 uint32_t attrlen, bitmap[2];
4260 int status;
4261
4262 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4263 goto xdr_error;
4264 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4265 goto xdr_error;
4266 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4267 goto xdr_error;
4268
4269 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4270
4271 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4272 goto xdr_error;
4273 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4274 goto xdr_error;
4275 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4276 goto xdr_error;
4277 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4278 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4279 goto xdr_error;
4280 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004281 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4282 if (status != 0)
4283 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004284 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4285 if (status != 0)
4286 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287
4288 status = verify_attr_len(xdr, savep, attrlen);
4289xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004290 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291 return status;
4292}
4293
4294static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4295{
Al Viro8687b632006-10-19 23:28:48 -07004296 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 uint32_t len;
4298 int status;
4299
Trond Myklebust99367812007-07-17 21:52:41 -04004300 /* Zero handle first to allow comparisons */
4301 memset(fh, 0, sizeof(*fh));
4302
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303 status = decode_op_hdr(xdr, OP_GETFH);
4304 if (status)
4305 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306
Benny Halevyc0eae662009-08-14 17:20:14 +03004307 p = xdr_inline_decode(xdr, 4);
4308 if (unlikely(!p))
4309 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004310 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311 if (len > NFS4_FHSIZE)
4312 return -EIO;
4313 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004314 p = xdr_inline_decode(xdr, len);
4315 if (unlikely(!p))
4316 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004317 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004319out_overflow:
4320 print_overflow_msg(__func__, xdr);
4321 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322}
4323
4324static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4325{
4326 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004327
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 status = decode_op_hdr(xdr, OP_LINK);
4329 if (status)
4330 return status;
4331 return decode_change_info(xdr, cinfo);
4332}
4333
4334/*
4335 * We create the owner, so we know a proper owner.id length is 4.
4336 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004337static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004339 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004340 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004341 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004343 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004344 if (unlikely(!p))
4345 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004346 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004347 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004348 type = be32_to_cpup(p++); /* 4 byte read */
4349 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004350 fl->fl_start = (loff_t)offset;
4351 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4352 if (length == ~(uint64_t)0)
4353 fl->fl_end = OFFSET_MAX;
4354 fl->fl_type = F_WRLCK;
4355 if (type & 1)
4356 fl->fl_type = F_RDLCK;
4357 fl->fl_pid = 0;
4358 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004359 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4360 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4361 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004362 if (likely(p))
4363 return -NFS4ERR_DENIED;
4364out_overflow:
4365 print_overflow_msg(__func__, xdr);
4366 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367}
4368
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004369static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 int status;
4372
4373 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004374 if (status == -EIO)
4375 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004377 status = decode_stateid(xdr, &res->stateid);
4378 if (unlikely(status))
4379 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004381 status = decode_lock_denied(xdr, NULL);
4382 if (res->open_seqid != NULL)
4383 nfs_increment_open_seqid(status, res->open_seqid);
4384 nfs_increment_lock_seqid(status, res->lock_seqid);
4385out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 return status;
4387}
4388
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004389static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390{
4391 int status;
4392 status = decode_op_hdr(xdr, OP_LOCKT);
4393 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004394 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 return status;
4396}
4397
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004398static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400 int status;
4401
4402 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004403 if (status != -EIO)
4404 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004405 if (status == 0)
4406 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 return status;
4408}
4409
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004410static int decode_release_lockowner(struct xdr_stream *xdr)
4411{
4412 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4413}
4414
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415static int decode_lookup(struct xdr_stream *xdr)
4416{
4417 return decode_op_hdr(xdr, OP_LOOKUP);
4418}
4419
4420/* This is too sick! */
4421static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4422{
Andy Adamson05d564f2008-12-23 16:06:15 -05004423 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424 uint32_t limit_type, nblocks, blocksize;
4425
Benny Halevyc0eae662009-08-14 17:20:14 +03004426 p = xdr_inline_decode(xdr, 12);
4427 if (unlikely(!p))
4428 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004429 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004431 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004432 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004433 break;
4434 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004435 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004436 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004437 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 }
4439 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004440out_overflow:
4441 print_overflow_msg(__func__, xdr);
4442 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443}
4444
4445static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4446{
Andy Adamson05d564f2008-12-23 16:06:15 -05004447 __be32 *p;
4448 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004449 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450
Benny Halevyc0eae662009-08-14 17:20:14 +03004451 p = xdr_inline_decode(xdr, 4);
4452 if (unlikely(!p))
4453 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004454 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4456 res->delegation_type = 0;
4457 return 0;
4458 }
Benny Halevy07d30432009-08-14 17:19:52 +03004459 status = decode_stateid(xdr, &res->delegation);
4460 if (unlikely(status))
4461 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004462 p = xdr_inline_decode(xdr, 4);
4463 if (unlikely(!p))
4464 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004465 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004466
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004468 case NFS4_OPEN_DELEGATE_READ:
4469 res->delegation_type = FMODE_READ;
4470 break;
4471 case NFS4_OPEN_DELEGATE_WRITE:
4472 res->delegation_type = FMODE_WRITE|FMODE_READ;
4473 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474 return -EIO;
4475 }
David Howells7539bba2006-08-22 20:06:09 -04004476 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004477out_overflow:
4478 print_overflow_msg(__func__, xdr);
4479 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480}
4481
4482static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4483{
Andy Adamson05d564f2008-12-23 16:06:15 -05004484 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004485 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004486 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487
Andy Adamson05d564f2008-12-23 16:06:15 -05004488 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004489 if (status != -EIO)
4490 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004491 if (!status)
4492 status = decode_stateid(xdr, &res->stateid);
4493 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004494 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495
Andy Adamson05d564f2008-12-23 16:06:15 -05004496 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497
Benny Halevyc0eae662009-08-14 17:20:14 +03004498 p = xdr_inline_decode(xdr, 8);
4499 if (unlikely(!p))
4500 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004501 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004502 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004503 if (bmlen > 10)
4504 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505
Benny Halevyc0eae662009-08-14 17:20:14 +03004506 p = xdr_inline_decode(xdr, bmlen << 2);
4507 if (unlikely(!p))
4508 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004509 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4510 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004511 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004512 for (; i < NFS4_BITMAP_SIZE; i++)
4513 res->attrset[i] = 0;
4514
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515 return decode_delegation(xdr, res);
4516xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004517 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004519out_overflow:
4520 print_overflow_msg(__func__, xdr);
4521 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004522}
4523
4524static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4525{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004526 int status;
4527
Andy Adamson05d564f2008-12-23 16:06:15 -05004528 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004529 if (status != -EIO)
4530 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004531 if (!status)
4532 status = decode_stateid(xdr, &res->stateid);
4533 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534}
4535
4536static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4537{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 int status;
4539
4540 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004541 if (status != -EIO)
4542 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004543 if (!status)
4544 status = decode_stateid(xdr, &res->stateid);
4545 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004546}
4547
4548static int decode_putfh(struct xdr_stream *xdr)
4549{
4550 return decode_op_hdr(xdr, OP_PUTFH);
4551}
4552
4553static int decode_putrootfh(struct xdr_stream *xdr)
4554{
4555 return decode_op_hdr(xdr, OP_PUTROOTFH);
4556}
4557
4558static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4559{
4560 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004561 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 uint32_t count, eof, recvd, hdrlen;
4563 int status;
4564
4565 status = decode_op_hdr(xdr, OP_READ);
4566 if (status)
4567 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004568 p = xdr_inline_decode(xdr, 8);
4569 if (unlikely(!p))
4570 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004571 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004572 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004573 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574 recvd = req->rq_rcv_buf.len - hdrlen;
4575 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004576 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577 "count %u > recvd %u\n", count, recvd);
4578 count = recvd;
4579 eof = 0;
4580 }
4581 xdr_read_pages(xdr, count);
4582 res->eof = eof;
4583 res->count = count;
4584 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004585out_overflow:
4586 print_overflow_msg(__func__, xdr);
4587 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588}
4589
4590static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4591{
4592 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004593 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004594 size_t hdrlen;
4595 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004596 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597
4598 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004599 if (!status)
4600 status = decode_verifier(xdr, readdir->verifier.data);
4601 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004603 dprintk("%s: verifier = %08x:%08x\n",
4604 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004605 ((u32 *)readdir->verifier.data)[0],
4606 ((u32 *)readdir->verifier.data)[1]);
4607
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608
Benny Halevydb942bb2009-08-14 17:19:56 +03004609 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 recvd = rcvbuf->len - hdrlen;
4611 if (pglen > recvd)
4612 pglen = recvd;
4613 xdr_read_pages(xdr, pglen);
4614
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004615
Trond Myklebustac396122010-11-15 20:26:22 -05004616 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617}
4618
4619static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4620{
4621 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4622 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004623 size_t hdrlen;
4624 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004625 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626 int status;
4627
4628 status = decode_op_hdr(xdr, OP_READLINK);
4629 if (status)
4630 return status;
4631
4632 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004633 p = xdr_inline_decode(xdr, 4);
4634 if (unlikely(!p))
4635 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004636 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004638 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 return -ENAMETOOLONG;
4640 }
4641 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4642 recvd = req->rq_rcv_buf.len - hdrlen;
4643 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004644 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 "count %u > recvd %u\n", len, recvd);
4646 return -EIO;
4647 }
4648 xdr_read_pages(xdr, len);
4649 /*
4650 * The XDR encode routine has set things up so that
4651 * the link text will be copied directly into the
4652 * buffer. We just have to do overflow-checking,
4653 * and and null-terminate the text (the VFS expects
4654 * null-termination).
4655 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004656 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004658out_overflow:
4659 print_overflow_msg(__func__, xdr);
4660 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661}
4662
4663static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4664{
4665 int status;
4666
4667 status = decode_op_hdr(xdr, OP_REMOVE);
4668 if (status)
4669 goto out;
4670 status = decode_change_info(xdr, cinfo);
4671out:
4672 return status;
4673}
4674
4675static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4676 struct nfs4_change_info *new_cinfo)
4677{
4678 int status;
4679
4680 status = decode_op_hdr(xdr, OP_RENAME);
4681 if (status)
4682 goto out;
4683 if ((status = decode_change_info(xdr, old_cinfo)))
4684 goto out;
4685 status = decode_change_info(xdr, new_cinfo);
4686out:
4687 return status;
4688}
4689
4690static int decode_renew(struct xdr_stream *xdr)
4691{
4692 return decode_op_hdr(xdr, OP_RENEW);
4693}
4694
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004695static int
4696decode_restorefh(struct xdr_stream *xdr)
4697{
4698 return decode_op_hdr(xdr, OP_RESTOREFH);
4699}
4700
J. Bruce Fields029d1052005-06-22 17:16:22 +00004701static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
4702 size_t *acl_len)
4703{
Al Viro8687b632006-10-19 23:28:48 -07004704 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004705 uint32_t attrlen,
4706 bitmap[2] = {0};
4707 struct kvec *iov = req->rq_rcv_buf.head;
4708 int status;
4709
4710 *acl_len = 0;
4711 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4712 goto out;
4713 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4714 goto out;
4715 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4716 goto out;
4717
4718 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4719 return -EIO;
4720 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004721 size_t hdrlen;
4722 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004723
4724 /* We ignore &savep and don't do consistency checks on
4725 * the attr length. Let userspace figure it out.... */
4726 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
4727 recvd = req->rq_rcv_buf.len - hdrlen;
4728 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004729 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00004730 " acl reply: attrlen %u > recvd %u\n",
4731 attrlen, recvd);
4732 return -EINVAL;
4733 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04004734 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004735 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04004736 } else
4737 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004738
4739out:
4740 return status;
4741}
4742
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743static int
4744decode_savefh(struct xdr_stream *xdr)
4745{
4746 return decode_op_hdr(xdr, OP_SAVEFH);
4747}
4748
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004749static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750{
Al Viro8687b632006-10-19 23:28:48 -07004751 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752 uint32_t bmlen;
4753 int status;
4754
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755 status = decode_op_hdr(xdr, OP_SETATTR);
4756 if (status)
4757 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004758 p = xdr_inline_decode(xdr, 4);
4759 if (unlikely(!p))
4760 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004761 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004762 p = xdr_inline_decode(xdr, bmlen << 2);
4763 if (likely(p))
4764 return 0;
4765out_overflow:
4766 print_overflow_msg(__func__, xdr);
4767 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768}
4769
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004770static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771{
Al Viro8687b632006-10-19 23:28:48 -07004772 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773 uint32_t opnum;
4774 int32_t nfserr;
4775
Benny Halevyc0eae662009-08-14 17:20:14 +03004776 p = xdr_inline_decode(xdr, 8);
4777 if (unlikely(!p))
4778 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004779 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004780 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004781 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05004782 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 return -EIO;
4784 }
Benny Halevycccddf42009-08-14 17:20:19 +03004785 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004787 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
4788 if (unlikely(!p))
4789 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04004790 p = xdr_decode_hyper(p, &res->clientid);
4791 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792 } else if (nfserr == NFSERR_CLID_INUSE) {
4793 uint32_t len;
4794
4795 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004796 p = xdr_inline_decode(xdr, 4);
4797 if (unlikely(!p))
4798 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004799 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004800 p = xdr_inline_decode(xdr, len);
4801 if (unlikely(!p))
4802 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004803
4804 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03004805 p = xdr_inline_decode(xdr, 4);
4806 if (unlikely(!p))
4807 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004808 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004809 p = xdr_inline_decode(xdr, len);
4810 if (unlikely(!p))
4811 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812 return -NFSERR_CLID_INUSE;
4813 } else
Benny Halevy856dff32008-03-31 17:39:06 +03004814 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815
4816 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004817out_overflow:
4818 print_overflow_msg(__func__, xdr);
4819 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004820}
4821
4822static int decode_setclientid_confirm(struct xdr_stream *xdr)
4823{
4824 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
4825}
4826
4827static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
4828{
Al Viro8687b632006-10-19 23:28:48 -07004829 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830 int status;
4831
4832 status = decode_op_hdr(xdr, OP_WRITE);
4833 if (status)
4834 return status;
4835
Benny Halevyc0eae662009-08-14 17:20:14 +03004836 p = xdr_inline_decode(xdr, 16);
4837 if (unlikely(!p))
4838 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004839 res->count = be32_to_cpup(p++);
4840 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03004841 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004843out_overflow:
4844 print_overflow_msg(__func__, xdr);
4845 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846}
4847
4848static int decode_delegreturn(struct xdr_stream *xdr)
4849{
4850 return decode_op_hdr(xdr, OP_DELEGRETURN);
4851}
4852
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004853static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
4854{
4855 __be32 *p;
4856
4857 p = xdr_inline_decode(xdr, 4);
4858 if (unlikely(!p))
4859 goto out_overflow;
4860 flavor->gss.sec_oid4.len = be32_to_cpup(p);
4861 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
4862 goto out_err;
4863
4864 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
4865 if (unlikely(!p))
4866 goto out_overflow;
4867 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
4868
4869 p = xdr_inline_decode(xdr, 8);
4870 if (unlikely(!p))
4871 goto out_overflow;
4872 flavor->gss.qop4 = be32_to_cpup(p++);
4873 flavor->gss.service = be32_to_cpup(p);
4874
4875 return 0;
4876
4877out_overflow:
4878 print_overflow_msg(__func__, xdr);
4879 return -EIO;
4880out_err:
4881 return -EINVAL;
4882}
4883
4884static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
4885{
4886 struct nfs4_secinfo_flavor *sec_flavor;
4887 int status;
4888 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004889 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004890
4891 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04004892 if (status)
4893 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004894 p = xdr_inline_decode(xdr, 4);
4895 if (unlikely(!p))
4896 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004897
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004898 res->flavors->num_flavors = 0;
4899 num_flavors = be32_to_cpup(p);
4900
4901 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004902 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004903 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004904 break;
4905
4906 p = xdr_inline_decode(xdr, 4);
4907 if (unlikely(!p))
4908 goto out_overflow;
4909 sec_flavor->flavor = be32_to_cpup(p);
4910
4911 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04004912 status = decode_secinfo_gss(xdr, sec_flavor);
4913 if (status)
4914 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004915 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04004916 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004917 }
4918
Bryan Schumaker613e9012011-04-27 15:28:44 -04004919out:
4920 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00004921out_overflow:
4922 print_overflow_msg(__func__, xdr);
4923 return -EIO;
4924}
4925
Benny Halevy99fe60d2009-04-01 09:22:29 -04004926#if defined(CONFIG_NFS_V4_1)
4927static int decode_exchange_id(struct xdr_stream *xdr,
4928 struct nfs41_exchange_id_res *res)
4929{
4930 __be32 *p;
4931 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03004932 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004933 int status;
4934 struct nfs_client *clp = res->client;
4935
4936 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
4937 if (status)
4938 return status;
4939
Benny Halevyc0eae662009-08-14 17:20:14 +03004940 p = xdr_inline_decode(xdr, 8);
4941 if (unlikely(!p))
4942 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05004943 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03004944 p = xdr_inline_decode(xdr, 12);
4945 if (unlikely(!p))
4946 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004947 clp->cl_seqid = be32_to_cpup(p++);
4948 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004949
4950 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03004951 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04004952 if (dummy != SP4_NONE)
4953 return -EIO;
4954
4955 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03004956 p = xdr_inline_decode(xdr, 8);
4957 if (unlikely(!p))
4958 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004959
4960 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03004961 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4962 if (unlikely(status))
4963 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004964
4965 /* Throw away server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03004966 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4967 if (unlikely(status))
4968 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004969
4970 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03004971 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
4972 if (unlikely(status))
4973 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004974
4975 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004976out_overflow:
4977 print_overflow_msg(__func__, xdr);
4978 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04004979}
Andy Adamsonfc931582009-04-01 09:22:31 -04004980
4981static int decode_chan_attrs(struct xdr_stream *xdr,
4982 struct nfs4_channel_attrs *attrs)
4983{
4984 __be32 *p;
4985 u32 nr_attrs;
4986
Benny Halevyc0eae662009-08-14 17:20:14 +03004987 p = xdr_inline_decode(xdr, 28);
4988 if (unlikely(!p))
4989 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004990 attrs->headerpadsz = be32_to_cpup(p++);
4991 attrs->max_rqst_sz = be32_to_cpup(p++);
4992 attrs->max_resp_sz = be32_to_cpup(p++);
4993 attrs->max_resp_sz_cached = be32_to_cpup(p++);
4994 attrs->max_ops = be32_to_cpup(p++);
4995 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004996 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04004997 if (unlikely(nr_attrs > 1)) {
4998 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
4999 __func__, nr_attrs);
5000 return -EINVAL;
5001 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005002 if (nr_attrs == 1) {
5003 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5004 if (unlikely(!p))
5005 goto out_overflow;
5006 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005007 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005008out_overflow:
5009 print_overflow_msg(__func__, xdr);
5010 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005011}
5012
Benny Halevye78291e2009-08-14 17:20:00 +03005013static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5014{
5015 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005016}
5017
5018static int decode_create_session(struct xdr_stream *xdr,
5019 struct nfs41_create_session_res *res)
5020{
5021 __be32 *p;
5022 int status;
5023 struct nfs_client *clp = res->client;
5024 struct nfs4_session *session = clp->cl_session;
5025
5026 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005027 if (!status)
5028 status = decode_sessionid(xdr, &session->sess_id);
5029 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005030 return status;
5031
Andy Adamsonfc931582009-04-01 09:22:31 -04005032 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005033 p = xdr_inline_decode(xdr, 8);
5034 if (unlikely(!p))
5035 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005036 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005037 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005038
5039 /* Channel attributes */
5040 status = decode_chan_attrs(xdr, &session->fc_attrs);
5041 if (!status)
5042 status = decode_chan_attrs(xdr, &session->bc_attrs);
5043 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005044out_overflow:
5045 print_overflow_msg(__func__, xdr);
5046 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005047}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005048
5049static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5050{
5051 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5052}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005053
5054static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5055{
5056 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5057}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005058#endif /* CONFIG_NFS_V4_1 */
5059
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005060static int decode_sequence(struct xdr_stream *xdr,
5061 struct nfs4_sequence_res *res,
5062 struct rpc_rqst *rqstp)
5063{
5064#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005065 struct nfs4_sessionid id;
5066 u32 dummy;
5067 int status;
5068 __be32 *p;
5069
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005070 if (!res->sr_session)
5071 return 0;
5072
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005073 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005074 if (!status)
5075 status = decode_sessionid(xdr, &id);
5076 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005077 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005078
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005079 /*
5080 * If the server returns different values for sessionID, slotID or
5081 * sequence number, the server is looney tunes.
5082 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005083 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005084
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005085 if (memcmp(id.data, res->sr_session->sess_id.data,
5086 NFS4_MAX_SESSIONID_LEN)) {
5087 dprintk("%s Invalid session id\n", __func__);
5088 goto out_err;
5089 }
Benny Halevye78291e2009-08-14 17:20:00 +03005090
Benny Halevyc0eae662009-08-14 17:20:14 +03005091 p = xdr_inline_decode(xdr, 20);
5092 if (unlikely(!p))
5093 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005094
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005095 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005096 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005097 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005098 dprintk("%s Invalid sequence number\n", __func__);
5099 goto out_err;
5100 }
5101 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005102 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005103 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005104 dprintk("%s Invalid slot id\n", __func__);
5105 goto out_err;
5106 }
5107 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005108 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005109 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005110 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005111 /* result flags */
5112 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005113 status = 0;
5114out_err:
5115 res->sr_status = status;
5116 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005117out_overflow:
5118 print_overflow_msg(__func__, xdr);
5119 status = -EIO;
5120 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005121#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005122 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005123#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005124}
5125
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005126#if defined(CONFIG_NFS_V4_1)
5127
5128static int decode_getdeviceinfo(struct xdr_stream *xdr,
5129 struct pnfs_device *pdev)
5130{
5131 __be32 *p;
5132 uint32_t len, type;
5133 int status;
5134
5135 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5136 if (status) {
5137 if (status == -ETOOSMALL) {
5138 p = xdr_inline_decode(xdr, 4);
5139 if (unlikely(!p))
5140 goto out_overflow;
5141 pdev->mincount = be32_to_cpup(p);
5142 dprintk("%s: Min count too small. mincnt = %u\n",
5143 __func__, pdev->mincount);
5144 }
5145 return status;
5146 }
5147
5148 p = xdr_inline_decode(xdr, 8);
5149 if (unlikely(!p))
5150 goto out_overflow;
5151 type = be32_to_cpup(p++);
5152 if (type != pdev->layout_type) {
5153 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5154 __func__, pdev->layout_type, type);
5155 return -EINVAL;
5156 }
5157 /*
5158 * Get the length of the opaque device_addr4. xdr_read_pages places
5159 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5160 * and places the remaining xdr data in xdr_buf->tail
5161 */
5162 pdev->mincount = be32_to_cpup(p);
5163 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5164
5165 /* Parse notification bitmap, verifying that it is zero. */
5166 p = xdr_inline_decode(xdr, 4);
5167 if (unlikely(!p))
5168 goto out_overflow;
5169 len = be32_to_cpup(p);
5170 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005171 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005172
5173 p = xdr_inline_decode(xdr, 4 * len);
5174 if (unlikely(!p))
5175 goto out_overflow;
5176 for (i = 0; i < len; i++, p++) {
5177 if (be32_to_cpup(p)) {
5178 dprintk("%s: notifications not supported\n",
5179 __func__);
5180 return -EIO;
5181 }
5182 }
5183 }
5184 return 0;
5185out_overflow:
5186 print_overflow_msg(__func__, xdr);
5187 return -EIO;
5188}
5189
5190static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5191 struct nfs4_layoutget_res *res)
5192{
5193 __be32 *p;
5194 int status;
5195 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005196 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5197 struct kvec *iov = rcvbuf->head;
5198 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005199
5200 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5201 if (status)
5202 return status;
5203 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5204 if (unlikely(!p))
5205 goto out_overflow;
5206 res->return_on_close = be32_to_cpup(p++);
5207 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5208 layout_count = be32_to_cpup(p);
5209 if (!layout_count) {
5210 dprintk("%s: server responded with empty layout array\n",
5211 __func__);
5212 return -EINVAL;
5213 }
5214
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005215 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005216 if (unlikely(!p))
5217 goto out_overflow;
5218 p = xdr_decode_hyper(p, &res->range.offset);
5219 p = xdr_decode_hyper(p, &res->range.length);
5220 res->range.iomode = be32_to_cpup(p++);
5221 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005222 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005223
5224 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5225 __func__,
5226 (unsigned long)res->range.offset,
5227 (unsigned long)res->range.length,
5228 res->range.iomode,
5229 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005230 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005231
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005232 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5233 recvd = req->rq_rcv_buf.len - hdrlen;
5234 if (res->layoutp->len > recvd) {
5235 dprintk("NFS: server cheating in layoutget reply: "
5236 "layout len %u > recvd %u\n",
5237 res->layoutp->len, recvd);
5238 return -EINVAL;
5239 }
5240
5241 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005242
5243 if (layout_count > 1) {
5244 /* We only handle a length one array at the moment. Any
5245 * further entries are just ignored. Note that this means
5246 * the client may see a response that is less than the
5247 * minimum it requested.
5248 */
5249 dprintk("%s: server responded with %d layouts, dropping tail\n",
5250 __func__, layout_count);
5251 }
5252
5253 return 0;
5254out_overflow:
5255 print_overflow_msg(__func__, xdr);
5256 return -EIO;
5257}
Andy Adamson863a3c62011-03-23 13:27:54 +00005258
Benny Halevycbe82602011-05-22 19:52:37 +03005259static int decode_layoutreturn(struct xdr_stream *xdr,
5260 struct nfs4_layoutreturn_res *res)
5261{
5262 __be32 *p;
5263 int status;
5264
5265 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5266 if (status)
5267 return status;
5268 p = xdr_inline_decode(xdr, 4);
5269 if (unlikely(!p))
5270 goto out_overflow;
5271 res->lrs_present = be32_to_cpup(p);
5272 if (res->lrs_present)
5273 status = decode_stateid(xdr, &res->stateid);
5274 return status;
5275out_overflow:
5276 print_overflow_msg(__func__, xdr);
5277 return -EIO;
5278}
5279
Andy Adamson863a3c62011-03-23 13:27:54 +00005280static int decode_layoutcommit(struct xdr_stream *xdr,
5281 struct rpc_rqst *req,
5282 struct nfs4_layoutcommit_res *res)
5283{
5284 __be32 *p;
5285 __u32 sizechanged;
5286 int status;
5287
5288 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
5289 if (status)
5290 return status;
5291
5292 p = xdr_inline_decode(xdr, 4);
5293 if (unlikely(!p))
5294 goto out_overflow;
5295 sizechanged = be32_to_cpup(p);
5296
5297 if (sizechanged) {
5298 /* throw away new size */
5299 p = xdr_inline_decode(xdr, 8);
5300 if (unlikely(!p))
5301 goto out_overflow;
5302 }
5303 return 0;
5304out_overflow:
5305 print_overflow_msg(__func__, xdr);
5306 return -EIO;
5307}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005308#endif /* CONFIG_NFS_V4_1 */
5309
Linus Torvalds1da177e2005-04-16 15:20:36 -07005310/*
Benny Halevy49c25592008-12-23 16:06:16 -05005311 * END OF "GENERIC" DECODE ROUTINES.
5312 */
5313
5314/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315 * Decode OPEN_DOWNGRADE response
5316 */
Chuck Leverbf269552010-12-14 14:59:29 +00005317static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5318 struct xdr_stream *xdr,
5319 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005320{
Andy Adamson05d564f2008-12-23 16:06:15 -05005321 struct compound_hdr hdr;
5322 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323
Chuck Leverbf269552010-12-14 14:59:29 +00005324 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005325 if (status)
5326 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005327 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005328 if (status)
5329 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005330 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005331 if (status)
5332 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005333 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005334 if (status != 0)
5335 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005336 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005337 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005338out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005339 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340}
5341
5342/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343 * Decode ACCESS response
5344 */
Chuck Leverbf269552010-12-14 14:59:29 +00005345static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5346 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005347{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348 struct compound_hdr hdr;
5349 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005350
Chuck Leverbf269552010-12-14 14:59:29 +00005351 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005352 if (status)
5353 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005354 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005355 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005356 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005357 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005358 if (status != 0)
5359 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005360 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005361 if (status != 0)
5362 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005363 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005364 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005365out:
5366 return status;
5367}
5368
5369/*
5370 * Decode LOOKUP response
5371 */
Chuck Leverbf269552010-12-14 14:59:29 +00005372static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5373 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005374{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005375 struct compound_hdr hdr;
5376 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005377
Chuck Leverbf269552010-12-14 14:59:29 +00005378 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005379 if (status)
5380 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005381 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005382 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005384 status = decode_putfh(xdr);
5385 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005386 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005387 status = decode_lookup(xdr);
5388 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005390 status = decode_getfh(xdr, res->fh);
5391 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005392 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005393 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005394 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005395out:
5396 return status;
5397}
5398
5399/*
5400 * Decode LOOKUP_ROOT response
5401 */
Chuck Leverbf269552010-12-14 14:59:29 +00005402static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5403 struct xdr_stream *xdr,
5404 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005405{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406 struct compound_hdr hdr;
5407 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005408
Chuck Leverbf269552010-12-14 14:59:29 +00005409 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005410 if (status)
5411 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005412 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005413 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005415 status = decode_putrootfh(xdr);
5416 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005417 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005418 status = decode_getfh(xdr, res->fh);
5419 if (status == 0)
5420 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005421 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005422out:
5423 return status;
5424}
5425
5426/*
5427 * Decode REMOVE response
5428 */
Chuck Leverbf269552010-12-14 14:59:29 +00005429static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5430 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005431{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005432 struct compound_hdr hdr;
5433 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005434
Chuck Leverbf269552010-12-14 14:59:29 +00005435 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005436 if (status)
5437 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005438 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005439 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005440 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005441 status = decode_putfh(xdr);
5442 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005443 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005444 status = decode_remove(xdr, &res->cinfo);
5445 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005446 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005447 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005448 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005449out:
5450 return status;
5451}
5452
5453/*
5454 * Decode RENAME response
5455 */
Chuck Leverbf269552010-12-14 14:59:29 +00005456static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5457 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005458{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459 struct compound_hdr hdr;
5460 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005461
Chuck Leverbf269552010-12-14 14:59:29 +00005462 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005463 if (status)
5464 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005465 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005466 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005467 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005468 status = decode_putfh(xdr);
5469 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005470 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005471 status = decode_savefh(xdr);
5472 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005473 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005474 status = decode_putfh(xdr);
5475 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005476 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005477 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5478 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005479 goto out;
5480 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005481 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005482 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005483 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005484 status = decode_restorefh(xdr);
5485 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005486 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005487 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005488 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005489out:
5490 return status;
5491}
5492
5493/*
5494 * Decode LINK response
5495 */
Chuck Leverbf269552010-12-14 14:59:29 +00005496static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5497 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005498{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005499 struct compound_hdr hdr;
5500 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005501
Chuck Leverbf269552010-12-14 14:59:29 +00005502 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005503 if (status)
5504 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005505 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005506 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005507 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005508 status = decode_putfh(xdr);
5509 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005510 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005511 status = decode_savefh(xdr);
5512 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005513 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005514 status = decode_putfh(xdr);
5515 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005517 status = decode_link(xdr, &res->cinfo);
5518 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005519 goto out;
5520 /*
5521 * Note order: OP_LINK leaves the directory as the current
5522 * filehandle.
5523 */
Chuck Leverbf269552010-12-14 14:59:29 +00005524 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005525 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005526 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005527 status = decode_restorefh(xdr);
5528 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005529 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005530 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005531 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532out:
5533 return status;
5534}
5535
5536/*
5537 * Decode CREATE response
5538 */
Chuck Leverbf269552010-12-14 14:59:29 +00005539static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5540 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005541{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005542 struct compound_hdr hdr;
5543 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005544
Chuck Leverbf269552010-12-14 14:59:29 +00005545 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005546 if (status)
5547 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005548 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005549 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005550 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005551 status = decode_putfh(xdr);
5552 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005553 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005554 status = decode_savefh(xdr);
5555 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005556 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005557 status = decode_create(xdr, &res->dir_cinfo);
5558 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005560 status = decode_getfh(xdr, res->fh);
5561 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005562 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005563 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005564 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005565 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005566 status = decode_restorefh(xdr);
5567 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005568 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005569 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005570 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005571out:
5572 return status;
5573}
5574
5575/*
5576 * Decode SYMLINK response
5577 */
Chuck Leverbf269552010-12-14 14:59:29 +00005578static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5579 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005580{
Chuck Leverbf269552010-12-14 14:59:29 +00005581 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005582}
5583
5584/*
5585 * Decode GETATTR response
5586 */
Chuck Leverbf269552010-12-14 14:59:29 +00005587static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5588 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005589{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005590 struct compound_hdr hdr;
5591 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005592
Chuck Leverbf269552010-12-14 14:59:29 +00005593 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005594 if (status)
5595 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005596 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005597 if (status)
5598 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005599 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005600 if (status)
5601 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005602 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005603 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005604out:
5605 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005606}
5607
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005608/*
5609 * Encode an SETACL request
5610 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005611static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5612 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005613{
Andy Adamson05d564f2008-12-23 16:06:15 -05005614 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005615 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005616 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005617
Chuck Lever9f06c712010-12-14 14:59:18 +00005618 encode_compound_hdr(xdr, req, &hdr);
5619 encode_sequence(xdr, &args->seq_args, &hdr);
5620 encode_putfh(xdr, args->fh, &hdr);
5621 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05005622 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005623}
Andy Adamson05d564f2008-12-23 16:06:15 -05005624
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005625/*
5626 * Decode SETACL response
5627 */
5628static int
Chuck Leverbf269552010-12-14 14:59:29 +00005629nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04005630 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005631{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005632 struct compound_hdr hdr;
5633 int status;
5634
Chuck Leverbf269552010-12-14 14:59:29 +00005635 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005636 if (status)
5637 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005638 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005639 if (status)
5640 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005641 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005642 if (status)
5643 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005644 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005645out:
5646 return status;
5647}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648
5649/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00005650 * Decode GETACL response
5651 */
5652static int
Chuck Leverbf269552010-12-14 14:59:29 +00005653nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04005654 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005655{
J. Bruce Fields029d1052005-06-22 17:16:22 +00005656 struct compound_hdr hdr;
5657 int status;
5658
Chuck Leverbf269552010-12-14 14:59:29 +00005659 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005660 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);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005666 if (status)
5667 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005668 status = decode_getacl(xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005669
5670out:
5671 return status;
5672}
5673
5674/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005675 * Decode CLOSE response
5676 */
Chuck Leverbf269552010-12-14 14:59:29 +00005677static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5678 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005679{
Andy Adamson05d564f2008-12-23 16:06:15 -05005680 struct compound_hdr hdr;
5681 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005682
Chuck Leverbf269552010-12-14 14:59:29 +00005683 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005684 if (status)
5685 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005686 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005687 if (status)
5688 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005689 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005690 if (status)
5691 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005692 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005693 if (status != 0)
5694 goto out;
5695 /*
5696 * Note: Server may do delete on close for this file
5697 * in which case the getattr call will fail with
5698 * an ESTALE error. Shouldn't be a problem,
5699 * though, since fattr->valid will remain unset.
5700 */
Chuck Leverbf269552010-12-14 14:59:29 +00005701 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005702 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005703out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005704 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005705}
5706
5707/*
5708 * Decode OPEN response
5709 */
Chuck Leverbf269552010-12-14 14:59:29 +00005710static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5711 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005712{
Andy Adamson05d564f2008-12-23 16:06:15 -05005713 struct compound_hdr hdr;
5714 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005715
Chuck Leverbf269552010-12-14 14:59:29 +00005716 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005717 if (status)
5718 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005719 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005720 if (status)
5721 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005722 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005723 if (status)
5724 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005725 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005726 if (status)
5727 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005728 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005729 if (status)
5730 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005731 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005732 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005733 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005734 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005735 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005736 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005738 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005739 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005741 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005742}
5743
5744/*
5745 * Decode OPEN_CONFIRM response
5746 */
Chuck Leverbf269552010-12-14 14:59:29 +00005747static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
5748 struct xdr_stream *xdr,
5749 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750{
Andy Adamson05d564f2008-12-23 16:06:15 -05005751 struct compound_hdr hdr;
5752 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753
Chuck Leverbf269552010-12-14 14:59:29 +00005754 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005755 if (status)
5756 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005757 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005758 if (status)
5759 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005760 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005761out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005762 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763}
5764
5765/*
5766 * Decode OPEN response
5767 */
Chuck Leverbf269552010-12-14 14:59:29 +00005768static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
5769 struct xdr_stream *xdr,
5770 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005771{
Andy Adamson05d564f2008-12-23 16:06:15 -05005772 struct compound_hdr hdr;
5773 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005774
Chuck Leverbf269552010-12-14 14:59:29 +00005775 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005776 if (status)
5777 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005778 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005779 if (status)
5780 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005781 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005782 if (status)
5783 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005784 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05005785 if (status)
5786 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005787 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005788 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005789out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005790 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005791}
5792
5793/*
5794 * Decode SETATTR response
5795 */
Chuck Leverbf269552010-12-14 14:59:29 +00005796static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
5797 struct xdr_stream *xdr,
5798 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799{
Andy Adamson05d564f2008-12-23 16:06:15 -05005800 struct compound_hdr hdr;
5801 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005802
Chuck Leverbf269552010-12-14 14:59:29 +00005803 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005804 if (status)
5805 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005806 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005807 if (status)
5808 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005809 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005810 if (status)
5811 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005812 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005813 if (status)
5814 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005815 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005816 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005817out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005818 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005819}
5820
5821/*
5822 * Decode LOCK response
5823 */
Chuck Leverbf269552010-12-14 14:59:29 +00005824static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5825 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005826{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005827 struct compound_hdr hdr;
5828 int status;
5829
Chuck Leverbf269552010-12-14 14:59:29 +00005830 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005831 if (status)
5832 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005833 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005834 if (status)
5835 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005836 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005837 if (status)
5838 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005839 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005840out:
5841 return status;
5842}
5843
5844/*
5845 * Decode LOCKT response
5846 */
Chuck Leverbf269552010-12-14 14:59:29 +00005847static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5848 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005849{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 struct compound_hdr hdr;
5851 int status;
5852
Chuck Leverbf269552010-12-14 14:59:29 +00005853 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854 if (status)
5855 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005856 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005857 if (status)
5858 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005859 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005860 if (status)
5861 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005862 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005863out:
5864 return status;
5865}
5866
5867/*
5868 * Decode LOCKU response
5869 */
Chuck Leverbf269552010-12-14 14:59:29 +00005870static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5871 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005872{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005873 struct compound_hdr hdr;
5874 int status;
5875
Chuck Leverbf269552010-12-14 14:59:29 +00005876 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 if (status)
5878 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005879 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005880 if (status)
5881 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005882 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005883 if (status)
5884 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005885 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005886out:
5887 return status;
5888}
5889
Chuck Leverbf269552010-12-14 14:59:29 +00005890static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
5891 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005892{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005893 struct compound_hdr hdr;
5894 int status;
5895
Chuck Leverbf269552010-12-14 14:59:29 +00005896 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005897 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00005898 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005899 return status;
5900}
5901
Linus Torvalds1da177e2005-04-16 15:20:36 -07005902/*
5903 * Decode READLINK response
5904 */
Chuck Leverbf269552010-12-14 14:59:29 +00005905static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
5906 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04005907 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005908{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909 struct compound_hdr hdr;
5910 int status;
5911
Chuck Leverbf269552010-12-14 14:59:29 +00005912 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005913 if (status)
5914 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005915 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005916 if (status)
5917 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005918 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005919 if (status)
5920 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005921 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005922out:
5923 return status;
5924}
5925
5926/*
5927 * Decode READDIR response
5928 */
Chuck Leverbf269552010-12-14 14:59:29 +00005929static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5930 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005932 struct compound_hdr hdr;
5933 int status;
5934
Chuck Leverbf269552010-12-14 14:59:29 +00005935 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005936 if (status)
5937 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005938 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005939 if (status)
5940 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005941 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005942 if (status)
5943 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005944 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945out:
5946 return status;
5947}
5948
5949/*
5950 * Decode Read response
5951 */
Chuck Leverbf269552010-12-14 14:59:29 +00005952static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5953 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005955 struct compound_hdr hdr;
5956 int status;
5957
Chuck Leverbf269552010-12-14 14:59:29 +00005958 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005959 if (status)
5960 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005961 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005962 if (status)
5963 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005964 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005965 if (status)
5966 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005967 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005968 if (!status)
5969 status = res->count;
5970out:
5971 return status;
5972}
5973
5974/*
5975 * Decode WRITE response
5976 */
Chuck Leverbf269552010-12-14 14:59:29 +00005977static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5978 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005980 struct compound_hdr hdr;
5981 int status;
5982
Chuck Leverbf269552010-12-14 14:59:29 +00005983 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984 if (status)
5985 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005986 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005987 if (status)
5988 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005989 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005990 if (status)
5991 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005992 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04005993 if (status)
5994 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00005995 if (res->fattr)
5996 decode_getfattr(xdr, res->fattr, res->server,
5997 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005998 if (!status)
5999 status = res->count;
6000out:
6001 return status;
6002}
6003
6004/*
6005 * Decode COMMIT response
6006 */
Chuck Leverbf269552010-12-14 14:59:29 +00006007static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6008 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006009{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006010 struct compound_hdr hdr;
6011 int status;
6012
Chuck Leverbf269552010-12-14 14:59:29 +00006013 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006014 if (status)
6015 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006016 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006017 if (status)
6018 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006019 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006020 if (status)
6021 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006022 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006023 if (status)
6024 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006025 if (res->fattr)
6026 decode_getfattr(xdr, res->fattr, res->server,
6027 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006028out:
6029 return status;
6030}
6031
6032/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006033 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034 */
Chuck Leverbf269552010-12-14 14:59:29 +00006035static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006036 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006038 struct compound_hdr hdr;
6039 int status;
6040
Chuck Leverbf269552010-12-14 14:59:29 +00006041 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006043 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006044 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006045 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006047 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006048 return status;
6049}
6050
6051/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006052 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053 */
Chuck Leverbf269552010-12-14 14:59:29 +00006054static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006055 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006056{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006057 struct compound_hdr hdr;
6058 int status;
6059
Chuck Leverbf269552010-12-14 14:59:29 +00006060 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006062 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006063 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006064 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006065 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006066 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006067 return status;
6068}
6069
6070/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006071 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006072 */
Chuck Leverbf269552010-12-14 14:59:29 +00006073static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006074 struct nfs4_statfs_res *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)
Chuck Leverbf269552010-12-14 14:59:29 +00006081 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006082 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006083 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006084 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006085 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086 return status;
6087}
6088
6089/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006090 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006091 */
Chuck Leverbf269552010-12-14 14:59:29 +00006092static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6093 struct xdr_stream *xdr,
6094 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006095{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006096 struct compound_hdr hdr;
6097 int status;
6098
Chuck Leverbf269552010-12-14 14:59:29 +00006099 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006100 if (status)
6101 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006102 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006103 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006105 status = decode_putfh(xdr);
6106 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006107 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006108 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109out:
6110 return status;
6111}
6112
6113/*
6114 * Decode RENEW response
6115 */
Chuck Leverbf269552010-12-14 14:59:29 +00006116static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6117 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006119 struct compound_hdr hdr;
6120 int status;
6121
Chuck Leverbf269552010-12-14 14:59:29 +00006122 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006124 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125 return status;
6126}
6127
6128/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006129 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006130 */
Chuck Leverbf269552010-12-14 14:59:29 +00006131static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6132 struct xdr_stream *xdr,
6133 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006134{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006135 struct compound_hdr hdr;
6136 int status;
6137
Chuck Leverbf269552010-12-14 14:59:29 +00006138 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006140 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141 return status;
6142}
6143
6144/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006145 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146 */
Chuck Leverbf269552010-12-14 14:59:29 +00006147static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6148 struct xdr_stream *xdr,
6149 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006150{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006151 struct compound_hdr hdr;
6152 int status;
6153
Chuck Leverbf269552010-12-14 14:59:29 +00006154 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006157 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006158 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006159 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006160 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006161 return status;
6162}
6163
6164/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006165 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006166 */
Chuck Leverbf269552010-12-14 14:59:29 +00006167static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6168 struct xdr_stream *xdr,
6169 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006171 struct compound_hdr hdr;
6172 int status;
6173
Chuck Leverbf269552010-12-14 14:59:29 +00006174 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006175 if (status)
6176 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006177 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006178 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006179 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006180 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006181 if (status != 0)
6182 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006183 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006184 if (status != 0)
6185 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006186 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006187 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01006188out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006189 return status;
6190}
6191
Trond Myklebust683b57b2006-06-09 09:34:22 -04006192/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006193 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006194 */
Chuck Leverbf269552010-12-14 14:59:29 +00006195static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6196 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006197 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006198{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006199 struct compound_hdr hdr;
6200 int status;
6201
Chuck Leverbf269552010-12-14 14:59:29 +00006202 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006203 if (status)
6204 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006205 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006206 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006207 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006208 status = decode_putfh(xdr);
6209 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006210 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006211 status = decode_lookup(xdr);
6212 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006213 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006214 xdr_enter_page(xdr, PAGE_SIZE);
6215 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006216 res->fs_locations->server,
6217 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006218out:
6219 return status;
6220}
6221
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006222/*
6223 * Decode SECINFO response
6224 */
6225static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6226 struct xdr_stream *xdr,
6227 struct nfs4_secinfo_res *res)
6228{
6229 struct compound_hdr hdr;
6230 int status;
6231
6232 status = decode_compound_hdr(xdr, &hdr);
6233 if (status)
6234 goto out;
6235 status = decode_sequence(xdr, &res->seq_res, rqstp);
6236 if (status)
6237 goto out;
6238 status = decode_putfh(xdr);
6239 if (status)
6240 goto out;
6241 status = decode_secinfo(xdr, res);
6242 if (status)
6243 goto out;
6244out:
6245 return status;
6246}
6247
Benny Halevy99fe60d2009-04-01 09:22:29 -04006248#if defined(CONFIG_NFS_V4_1)
6249/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006250 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006251 */
Chuck Leverbf269552010-12-14 14:59:29 +00006252static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6253 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006254 void *res)
6255{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006256 struct compound_hdr hdr;
6257 int status;
6258
Chuck Leverbf269552010-12-14 14:59:29 +00006259 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006260 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006262 return status;
6263}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006264
6265/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006266 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006267 */
Chuck Leverbf269552010-12-14 14:59:29 +00006268static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6269 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006270 struct nfs41_create_session_res *res)
6271{
Andy Adamsonfc931582009-04-01 09:22:31 -04006272 struct compound_hdr hdr;
6273 int status;
6274
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006276 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006278 return status;
6279}
6280
6281/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006282 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006283 */
Chuck Leverbf269552010-12-14 14:59:29 +00006284static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6285 struct xdr_stream *xdr,
6286 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006287{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006288 struct compound_hdr hdr;
6289 int status;
6290
Chuck Leverbf269552010-12-14 14:59:29 +00006291 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006292 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006293 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006294 return status;
6295}
6296
6297/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006298 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006299 */
Chuck Leverbf269552010-12-14 14:59:29 +00006300static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6301 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006302 struct nfs4_sequence_res *res)
6303{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006304 struct compound_hdr hdr;
6305 int status;
6306
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006308 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006309 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006310 return status;
6311}
6312
6313/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006314 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006315 */
Chuck Leverbf269552010-12-14 14:59:29 +00006316static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6317 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006318 struct nfs4_get_lease_time_res *res)
6319{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006320 struct compound_hdr hdr;
6321 int status;
6322
Chuck Leverbf269552010-12-14 14:59:29 +00006323 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006324 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006325 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006326 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006327 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006328 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006329 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006330 return status;
6331}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006332
6333/*
6334 * Decode RECLAIM_COMPLETE response
6335 */
Chuck Leverbf269552010-12-14 14:59:29 +00006336static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6337 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006338 struct nfs41_reclaim_complete_res *res)
6339{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006340 struct compound_hdr hdr;
6341 int status;
6342
Chuck Leverbf269552010-12-14 14:59:29 +00006343 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006344 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006345 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006346 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006347 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006348 return status;
6349}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006350
6351/*
6352 * Decode GETDEVINFO response
6353 */
Chuck Leverbf269552010-12-14 14:59:29 +00006354static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6355 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006356 struct nfs4_getdeviceinfo_res *res)
6357{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006358 struct compound_hdr hdr;
6359 int status;
6360
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006362 if (status != 0)
6363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006365 if (status != 0)
6366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006368out:
6369 return status;
6370}
6371
6372/*
6373 * Decode LAYOUTGET response
6374 */
Chuck Leverbf269552010-12-14 14:59:29 +00006375static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6376 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006377 struct nfs4_layoutget_res *res)
6378{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006379 struct compound_hdr hdr;
6380 int status;
6381
Chuck Leverbf269552010-12-14 14:59:29 +00006382 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006383 if (status)
6384 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006385 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006386 if (status)
6387 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006388 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006389 if (status)
6390 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006391 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006392out:
6393 return status;
6394}
Andy Adamson863a3c62011-03-23 13:27:54 +00006395
6396/*
Benny Halevycbe82602011-05-22 19:52:37 +03006397 * Decode LAYOUTRETURN response
6398 */
6399static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6400 struct xdr_stream *xdr,
6401 struct nfs4_layoutreturn_res *res)
6402{
6403 struct compound_hdr hdr;
6404 int status;
6405
6406 status = decode_compound_hdr(xdr, &hdr);
6407 if (status)
6408 goto out;
6409 status = decode_sequence(xdr, &res->seq_res, rqstp);
6410 if (status)
6411 goto out;
6412 status = decode_putfh(xdr);
6413 if (status)
6414 goto out;
6415 status = decode_layoutreturn(xdr, res);
6416out:
6417 return status;
6418}
6419
6420/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006421 * Decode LAYOUTCOMMIT response
6422 */
6423static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6424 struct xdr_stream *xdr,
6425 struct nfs4_layoutcommit_res *res)
6426{
6427 struct compound_hdr hdr;
6428 int status;
6429
6430 status = decode_compound_hdr(xdr, &hdr);
6431 if (status)
6432 goto out;
6433 status = decode_sequence(xdr, &res->seq_res, rqstp);
6434 if (status)
6435 goto out;
6436 status = decode_putfh(xdr);
6437 if (status)
6438 goto out;
6439 status = decode_layoutcommit(xdr, rqstp, res);
6440 if (status)
6441 goto out;
6442 decode_getfattr(xdr, res->fattr, res->server,
6443 !RPC_IS_ASYNC(rqstp->rq_task));
6444out:
6445 return status;
6446}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006447#endif /* CONFIG_NFS_V4_1 */
6448
Chuck Lever573c4e12010-12-14 14:58:11 +00006449/**
6450 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6451 * the local page cache.
6452 * @xdr: XDR stream where entry resides
6453 * @entry: buffer to fill in with entry data
6454 * @plus: boolean indicating whether this should be a readdirplus entry
6455 *
6456 * Returns zero if successful, otherwise a negative errno value is
6457 * returned.
6458 *
6459 * This function is not invoked during READDIR reply decoding, but
6460 * rather whenever an application invokes the getdents(2) system call
6461 * on a directory already in our cache.
6462 */
6463int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6464 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006465{
6466 uint32_t bitmap[2] = {0};
6467 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006468 __be32 *p = xdr_inline_decode(xdr, 4);
6469 if (unlikely(!p))
6470 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006471 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006472 p = xdr_inline_decode(xdr, 4);
6473 if (unlikely(!p))
6474 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006475 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006476 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006478 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006479 }
6480
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006481 p = xdr_inline_decode(xdr, 12);
6482 if (unlikely(!p))
6483 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006484 entry->prev_cookie = entry->cookie;
6485 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006486 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006487
Trond Myklebust9af8c222010-10-24 11:52:55 -04006488 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006489 if (unlikely(!p))
6490 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006492
6493 /*
6494 * In case the server doesn't return an inode number,
6495 * we fake one here. (We don't use inode number 0,
6496 * since glibc seems to choke on it...)
6497 */
6498 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006499 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006500
Trond Myklebust9af8c222010-10-24 11:52:55 -04006501 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006502 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006503
6504 if (decode_attr_length(xdr, &len, &p) < 0)
6505 goto out_overflow;
6506
Chuck Lever573c4e12010-12-14 14:58:11 +00006507 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6508 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006509 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006510 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6511 entry->ino = entry->fattr->mounted_on_fileid;
6512 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006513 entry->ino = entry->fattr->fileid;
6514
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006515 entry->d_type = DT_UNKNOWN;
6516 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6517 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6518
Chuck Lever573c4e12010-12-14 14:58:11 +00006519 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006520
6521out_overflow:
6522 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006523 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524}
6525
6526/*
6527 * We need to translate between nfs status return values and
6528 * the local errno values which may not be the same.
6529 */
6530static struct {
6531 int stat;
6532 int errno;
6533} nfs_errtbl[] = {
6534 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03006535 { NFS4ERR_PERM, -EPERM },
6536 { NFS4ERR_NOENT, -ENOENT },
6537 { NFS4ERR_IO, -errno_NFSERR_IO},
6538 { NFS4ERR_NXIO, -ENXIO },
6539 { NFS4ERR_ACCESS, -EACCES },
6540 { NFS4ERR_EXIST, -EEXIST },
6541 { NFS4ERR_XDEV, -EXDEV },
6542 { NFS4ERR_NOTDIR, -ENOTDIR },
6543 { NFS4ERR_ISDIR, -EISDIR },
6544 { NFS4ERR_INVAL, -EINVAL },
6545 { NFS4ERR_FBIG, -EFBIG },
6546 { NFS4ERR_NOSPC, -ENOSPC },
6547 { NFS4ERR_ROFS, -EROFS },
6548 { NFS4ERR_MLINK, -EMLINK },
6549 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
6550 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
6551 { NFS4ERR_DQUOT, -EDQUOT },
6552 { NFS4ERR_STALE, -ESTALE },
6553 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03006554 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
6555 { NFS4ERR_NOTSUPP, -ENOTSUPP },
6556 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006557 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03006558 { NFS4ERR_BADTYPE, -EBADTYPE },
6559 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03006560 { NFS4ERR_SYMLINK, -ELOOP },
6561 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
6562 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03006563 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006564};
6565
6566/*
6567 * Convert an NFS error code to a local one.
6568 * This one is used jointly by NFSv2 and NFSv3.
6569 */
6570static int
David Howells0a8ea432006-08-22 20:06:08 -04006571nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006572{
6573 int i;
6574 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
6575 if (nfs_errtbl[i].stat == stat)
6576 return nfs_errtbl[i].errno;
6577 }
6578 if (stat <= 10000 || stat > 10100) {
6579 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05006580 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006581 }
6582 /* If we cannot translate the error, the recovery routines should
6583 * handle it.
6584 * Note: remaining NFSv4 error codes have values > 10000, so should
6585 * not conflict with native Linux error codes.
6586 */
Benny Halevy856dff32008-03-31 17:39:06 +03006587 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006588}
6589
Linus Torvalds1da177e2005-04-16 15:20:36 -07006590#define PROC(proc, argtype, restype) \
6591[NFSPROC4_CLNT_##proc] = { \
6592 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00006593 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00006594 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04006595 .p_arglen = NFS4_##argtype##_sz, \
6596 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05006597 .p_statidx = NFSPROC4_CLNT_##proc, \
6598 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05006599}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006600
6601struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00006602 PROC(READ, enc_read, dec_read),
6603 PROC(WRITE, enc_write, dec_write),
6604 PROC(COMMIT, enc_commit, dec_commit),
6605 PROC(OPEN, enc_open, dec_open),
6606 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
6607 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
6608 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
6609 PROC(CLOSE, enc_close, dec_close),
6610 PROC(SETATTR, enc_setattr, dec_setattr),
6611 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
6612 PROC(RENEW, enc_renew, dec_renew),
6613 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
6614 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
6615 PROC(LOCK, enc_lock, dec_lock),
6616 PROC(LOCKT, enc_lockt, dec_lockt),
6617 PROC(LOCKU, enc_locku, dec_locku),
6618 PROC(ACCESS, enc_access, dec_access),
6619 PROC(GETATTR, enc_getattr, dec_getattr),
6620 PROC(LOOKUP, enc_lookup, dec_lookup),
6621 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
6622 PROC(REMOVE, enc_remove, dec_remove),
6623 PROC(RENAME, enc_rename, dec_rename),
6624 PROC(LINK, enc_link, dec_link),
6625 PROC(SYMLINK, enc_symlink, dec_symlink),
6626 PROC(CREATE, enc_create, dec_create),
6627 PROC(PATHCONF, enc_pathconf, dec_pathconf),
6628 PROC(STATFS, enc_statfs, dec_statfs),
6629 PROC(READLINK, enc_readlink, dec_readlink),
6630 PROC(READDIR, enc_readdir, dec_readdir),
6631 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
6632 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
6633 PROC(GETACL, enc_getacl, dec_getacl),
6634 PROC(SETACL, enc_setacl, dec_setacl),
6635 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
6636 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006637 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006638#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00006639 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
6640 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
6641 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
6642 PROC(SEQUENCE, enc_sequence, dec_sequence),
6643 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
6644 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
6645 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
6646 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00006647 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03006648 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Benny Halevy99fe60d2009-04-01 09:22:29 -04006649#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650};
6651
6652struct rpc_version nfs_version4 = {
6653 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08006654 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655 .procs = nfs4_procedures
6656};
6657
6658/*
6659 * Local variables:
6660 * c-basic-offset: 8
6661 * End:
6662 */