blob: dcaf69309d8eea153166084f2895c9a77a81564e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
47#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050048#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000049#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/nfs.h>
51#include <linux/nfs4.h>
52#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000054#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050055#include "internal.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040056#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#define NFSDBG_FACILITY NFSDBG_XDR
59
60/* Mapping from NFS error code to "errno" error code. */
61#define errno_NFSERR_IO EIO
62
David Howells0a8ea432006-08-22 20:06:08 -040063static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
66#ifdef DEBUG
67#define NFS4_MAXTAGLEN 20
68#else
69#define NFS4_MAXTAGLEN 0
70#endif
71
Andy Adamson6c0195a2008-12-23 16:06:15 -050072/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 */
Trond Myklebustd035c362010-12-21 10:45:27 -050075#define open_owner_id_maxsz (1 + 1 + 4)
76#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040077#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
79#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
80#define op_encode_hdr_maxsz (1)
81#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040082#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
83#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
84#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
85#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
87 (NFS4_FHSIZE >> 2))
88#define decode_putfh_maxsz (op_decode_hdr_maxsz)
89#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
90#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
91#define encode_getfh_maxsz (op_encode_hdr_maxsz)
92#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
93 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -040094#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +000095#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
97#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040098#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
99#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +0000100/* This is based on getfattr, which uses the most attributes: */
101#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400102 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000103#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
104 nfs4_fattr_value_maxsz)
105#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400106#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
107 1 + 2 + 1 + \
108 nfs4_owner_maxsz + \
109 nfs4_group_maxsz + \
110 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define encode_savefh_maxsz (op_encode_hdr_maxsz)
112#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400113#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
114#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200115#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400116/* The 5 accounts for the PNFS attributes, and assumes that at most three
117 * layout types will be returned.
118 */
119#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
120 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
122#define decode_renew_maxsz (op_decode_hdr_maxsz)
123#define encode_setclientid_maxsz \
124 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500125 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
126 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
127 1 /* sc_prog */ + \
128 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
129 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
130 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#define decode_setclientid_maxsz \
132 (op_decode_hdr_maxsz + \
133 2 + \
134 1024) /* large value for CLID_INUSE */
135#define encode_setclientid_confirm_maxsz \
136 (op_encode_hdr_maxsz + \
137 3 + (NFS4_VERIFIER_SIZE >> 2))
138#define decode_setclientid_confirm_maxsz \
139 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400140#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
141#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400142#define encode_share_access_maxsz \
143 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500144#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400145#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
146#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
147#define encode_open_maxsz (op_encode_hdr_maxsz + \
148 2 + encode_share_access_maxsz + 2 + \
149 open_owner_id_maxsz + \
150 encode_opentype_maxsz + \
151 encode_claim_null_maxsz)
152#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400153#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400154 decode_ace_maxsz)
155#define decode_change_info_maxsz (5)
156#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400157 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400158 decode_change_info_maxsz + 1 + \
159 nfs4_fattr_bitmap_maxsz + \
160 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400161#define encode_open_confirm_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1)
164#define decode_open_confirm_maxsz \
165 (op_decode_hdr_maxsz + \
166 decode_stateid_maxsz)
167#define encode_open_downgrade_maxsz \
168 (op_encode_hdr_maxsz + \
169 encode_stateid_maxsz + 1 + \
170 encode_share_access_maxsz)
171#define decode_open_downgrade_maxsz \
172 (op_decode_hdr_maxsz + \
173 decode_stateid_maxsz)
174#define encode_close_maxsz (op_encode_hdr_maxsz + \
175 1 + encode_stateid_maxsz)
176#define decode_close_maxsz (op_decode_hdr_maxsz + \
177 decode_stateid_maxsz)
178#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
179 encode_stateid_maxsz + \
180 encode_attrs_maxsz)
181#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
182 nfs4_fattr_bitmap_maxsz)
183#define encode_read_maxsz (op_encode_hdr_maxsz + \
184 encode_stateid_maxsz + 3)
185#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
186#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
187 2 + encode_verifier_maxsz + 5)
188#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
189 decode_verifier_maxsz)
190#define encode_readlink_maxsz (op_encode_hdr_maxsz)
191#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
192#define encode_write_maxsz (op_encode_hdr_maxsz + \
193 encode_stateid_maxsz + 4)
194#define decode_write_maxsz (op_decode_hdr_maxsz + \
195 2 + decode_verifier_maxsz)
196#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
197#define decode_commit_maxsz (op_decode_hdr_maxsz + \
198 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199#define encode_remove_maxsz (op_encode_hdr_maxsz + \
200 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400201#define decode_remove_maxsz (op_decode_hdr_maxsz + \
202 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#define encode_rename_maxsz (op_encode_hdr_maxsz + \
204 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400205#define decode_rename_maxsz (op_decode_hdr_maxsz + \
206 decode_change_info_maxsz + \
207 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208#define encode_link_maxsz (op_encode_hdr_maxsz + \
209 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400210#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400211#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400212#define encode_lock_maxsz (op_encode_hdr_maxsz + \
213 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400214 1 + encode_stateid_maxsz + 1 + \
215 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400216#define decode_lock_denied_maxsz \
217 (8 + decode_lockowner_maxsz)
218#define decode_lock_maxsz (op_decode_hdr_maxsz + \
219 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400220#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
221 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400222#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
223 decode_lock_denied_maxsz)
224#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
225 encode_stateid_maxsz + \
226 4)
227#define decode_locku_maxsz (op_decode_hdr_maxsz + \
228 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400229#define encode_release_lockowner_maxsz \
230 (op_encode_hdr_maxsz + \
231 encode_lockowner_maxsz)
232#define decode_release_lockowner_maxsz \
233 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400234#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
235#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
237 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400238 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000239 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
241#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400242 1 + 2 + nfs4_name_maxsz + \
243 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400244#define decode_create_maxsz (op_decode_hdr_maxsz + \
245 decode_change_info_maxsz + \
246 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400247#define encode_statfs_maxsz (encode_getattr_maxsz)
248#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
250#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400251#define encode_getacl_maxsz (encode_getattr_maxsz)
252#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
253 nfs4_fattr_bitmap_maxsz + 1)
254#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
255 encode_stateid_maxsz + 3)
256#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400257#define encode_fs_locations_maxsz \
258 (encode_getattr_maxsz)
259#define decode_fs_locations_maxsz \
260 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000261#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400262#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400263
264#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400265#define NFS4_MAX_MACHINE_NAME_LEN (64)
266
Benny Halevy99fe60d2009-04-01 09:22:29 -0400267#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
268 encode_verifier_maxsz + \
269 1 /* co_ownerid.len */ + \
270 XDR_QUADLEN(NFS4_EXCHANGE_ID_LEN) + \
271 1 /* flags */ + \
272 1 /* spa_how */ + \
273 0 /* SP4_NONE (for now) */ + \
274 1 /* zero implemetation id array */)
275#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
276 2 /* eir_clientid */ + \
277 1 /* eir_sequenceid */ + \
278 1 /* eir_flags */ + \
279 1 /* spr_how */ + \
280 0 /* SP4_NONE (for now) */ + \
281 2 /* eir_server_owner.so_minor_id */ + \
282 /* eir_server_owner.so_major_id<> */ \
283 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
284 /* eir_server_scope<> */ \
285 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
286 1 /* eir_server_impl_id array length */ + \
287 0 /* ignored eir_server_impl_id contents */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400288#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
289#define decode_channel_attrs_maxsz (6 + \
290 1 /* ca_rdma_ird.len */ + \
291 1 /* ca_rdma_ird */)
292#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
293 2 /* csa_clientid */ + \
294 1 /* csa_sequence */ + \
295 1 /* csa_flags */ + \
296 encode_channel_attrs_maxsz + \
297 encode_channel_attrs_maxsz + \
298 1 /* csa_cb_program */ + \
299 1 /* csa_sec_parms.len (1) */ + \
300 1 /* cb_secflavor (AUTH_SYS) */ + \
301 1 /* stamp */ + \
302 1 /* machinename.len */ + \
303 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
304 1 /* uid */ + \
305 1 /* gid */ + \
306 1 /* gids.len (0) */)
307#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
308 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
309 1 /* csr_sequence */ + \
310 1 /* csr_flags */ + \
311 decode_channel_attrs_maxsz + \
312 decode_channel_attrs_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400313#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
314#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400315#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
316 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
317#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
318 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500319#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
320#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400321#define encode_getdevicelist_maxsz (op_encode_hdr_maxsz + 4 + \
322 encode_verifier_maxsz)
323#define decode_getdevicelist_maxsz (op_decode_hdr_maxsz + \
324 2 /* nfs_cookie4 gdlr_cookie */ + \
325 decode_verifier_maxsz \
326 /* verifier4 gdlr_verifier */ + \
327 1 /* gdlr_deviceid_list count */ + \
328 XDR_QUADLEN(NFS4_PNFS_GETDEVLIST_MAXNUM * \
329 NFS4_DEVICEID4_SIZE) \
330 /* gdlr_deviceid_list */ + \
331 1 /* bool gdlr_eof */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400332#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + 4 + \
333 XDR_QUADLEN(NFS4_DEVICEID4_SIZE))
334#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
335 1 /* layout type */ + \
336 1 /* opaque devaddr4 length */ + \
337 /* devaddr4 payload is read into page */ \
338 1 /* notification bitmap length */ + \
339 1 /* notification bitmap */)
340#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
341 encode_stateid_maxsz)
342#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
343 decode_stateid_maxsz + \
344 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000345#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
346 2 /* offset */ + \
347 2 /* length */ + \
348 1 /* reclaim */ + \
349 encode_stateid_maxsz + \
350 1 /* new offset (true) */ + \
351 2 /* last byte written */ + \
352 1 /* nt_timechanged (false) */ + \
353 1 /* layoutupdate4 layout type */ + \
354 1 /* NULL filelayout layoutupdate4 payload */)
355#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300356#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
357 encode_stateid_maxsz + \
358 1 /* FIXME: opaque lrf_body always empty at the moment */)
359#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
360 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400361#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
362#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400363#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
364 XDR_QUADLEN(NFS4_STATEID_SIZE))
365#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400366#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
367 XDR_QUADLEN(NFS4_STATEID_SIZE))
368#define decode_free_stateid_maxsz (op_decode_hdr_maxsz + 1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400369#else /* CONFIG_NFS_V4_1 */
370#define encode_sequence_maxsz 0
371#define decode_sequence_maxsz 0
372#endif /* CONFIG_NFS_V4_1 */
373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
375#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
376#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400377 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400379 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400381 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400383 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400385 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400387 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400389 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400391 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400393 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400395 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400397 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400399 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400401 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400403 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400404 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400406 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400408 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400409 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400411 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400413 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400414 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400416 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400418 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400419 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400421 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400422 encode_putfh_maxsz + \
423 encode_savefh_maxsz + \
424 encode_open_maxsz + \
425 encode_getfh_maxsz + \
426 encode_getattr_maxsz + \
427 encode_restorefh_maxsz + \
428 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400431 decode_putfh_maxsz + \
432 decode_savefh_maxsz + \
433 decode_open_maxsz + \
434 decode_getfh_maxsz + \
435 decode_getattr_maxsz + \
436 decode_restorefh_maxsz + \
437 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400438#define NFS4_enc_open_confirm_sz \
439 (compound_encode_hdr_maxsz + \
440 encode_putfh_maxsz + \
441 encode_open_confirm_maxsz)
442#define NFS4_dec_open_confirm_sz \
443 (compound_decode_hdr_maxsz + \
444 decode_putfh_maxsz + \
445 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400447 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400449 encode_open_maxsz + \
450 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400454 decode_open_maxsz + \
455 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define NFS4_enc_open_downgrade_sz \
457 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400458 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400459 encode_putfh_maxsz + \
460 encode_open_downgrade_maxsz + \
461 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#define NFS4_dec_open_downgrade_sz \
463 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400465 decode_putfh_maxsz + \
466 decode_open_downgrade_maxsz + \
467 decode_getattr_maxsz)
468#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400470 encode_putfh_maxsz + \
471 encode_close_maxsz + \
472 encode_getattr_maxsz)
473#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400474 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400475 decode_putfh_maxsz + \
476 decode_close_maxsz + \
477 decode_getattr_maxsz)
478#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400479 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400480 encode_putfh_maxsz + \
481 encode_setattr_maxsz + \
482 encode_getattr_maxsz)
483#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400484 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400485 decode_putfh_maxsz + \
486 decode_setattr_maxsz + \
487 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400489 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 encode_putfh_maxsz + \
491 encode_fsinfo_maxsz)
492#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400493 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 decode_putfh_maxsz + \
495 decode_fsinfo_maxsz)
496#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
497 encode_renew_maxsz)
498#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
499 decode_renew_maxsz)
500#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
501 encode_setclientid_maxsz)
502#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
503 decode_setclientid_maxsz)
504#define NFS4_enc_setclientid_confirm_sz \
505 (compound_encode_hdr_maxsz + \
506 encode_setclientid_confirm_maxsz + \
507 encode_putrootfh_maxsz + \
508 encode_fsinfo_maxsz)
509#define NFS4_dec_setclientid_confirm_sz \
510 (compound_decode_hdr_maxsz + \
511 decode_setclientid_confirm_maxsz + \
512 decode_putrootfh_maxsz + \
513 decode_fsinfo_maxsz)
514#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400515 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400517 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400519 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400521 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400523 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400525 encode_lockt_maxsz)
526#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400527 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400528 decode_putfh_maxsz + \
529 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400531 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400533 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400535 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400537 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400538#define NFS4_enc_release_lockowner_sz \
539 (compound_encode_hdr_maxsz + \
540 encode_lockowner_maxsz)
541#define NFS4_dec_release_lockowner_sz \
542 (compound_decode_hdr_maxsz + \
543 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400545 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400547 encode_access_maxsz + \
548 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400550 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400552 decode_access_maxsz + \
553 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400555 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 encode_putfh_maxsz + \
557 encode_getattr_maxsz)
558#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400559 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 decode_putfh_maxsz + \
561 decode_getattr_maxsz)
562#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400563 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 encode_putfh_maxsz + \
565 encode_lookup_maxsz + \
566 encode_getattr_maxsz + \
567 encode_getfh_maxsz)
568#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400569 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400571 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 decode_getattr_maxsz + \
573 decode_getfh_maxsz)
574#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400575 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 encode_putrootfh_maxsz + \
577 encode_getattr_maxsz + \
578 encode_getfh_maxsz)
579#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putrootfh_maxsz + \
582 decode_getattr_maxsz + \
583 decode_getfh_maxsz)
584#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400585 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400587 encode_remove_maxsz + \
588 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400592 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400593 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 encode_putfh_maxsz + \
597 encode_savefh_maxsz + \
598 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400599 encode_rename_maxsz + \
600 encode_getattr_maxsz + \
601 encode_restorefh_maxsz + \
602 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400604 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 decode_putfh_maxsz + \
606 decode_savefh_maxsz + \
607 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400608 decode_rename_maxsz + \
609 decode_getattr_maxsz + \
610 decode_restorefh_maxsz + \
611 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400613 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 encode_putfh_maxsz + \
615 encode_savefh_maxsz + \
616 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400617 encode_link_maxsz + \
618 decode_getattr_maxsz + \
619 encode_restorefh_maxsz + \
620 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 decode_putfh_maxsz + \
624 decode_savefh_maxsz + \
625 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400626 decode_link_maxsz + \
627 decode_getattr_maxsz + \
628 decode_restorefh_maxsz + \
629 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400631 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 encode_putfh_maxsz + \
633 encode_symlink_maxsz + \
634 encode_getattr_maxsz + \
635 encode_getfh_maxsz)
636#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400637 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 decode_putfh_maxsz + \
639 decode_symlink_maxsz + \
640 decode_getattr_maxsz + \
641 decode_getfh_maxsz)
642#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400643 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400645 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400647 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400649 encode_restorefh_maxsz + \
650 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400652 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400654 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400656 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400658 decode_restorefh_maxsz + \
659 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400661 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 encode_putfh_maxsz + \
663 encode_getattr_maxsz)
664#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400665 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 decode_putfh_maxsz + \
667 decode_getattr_maxsz)
668#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400669 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400671 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400673 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400675 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400677 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800678 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 encode_getattr_maxsz)
680#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400681 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800682 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 decode_getattr_maxsz)
684#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400685 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100687 encode_delegreturn_maxsz + \
688 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400690 decode_sequence_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100691 decode_delegreturn_maxsz + \
692 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000693#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000695 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400696 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000697#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400698 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000699 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400700 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000701#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000703 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400704 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000705#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000707 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400708 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400709#define NFS4_enc_fs_locations_sz \
710 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400711 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400712 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400713 encode_lookup_maxsz + \
714 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400715#define NFS4_dec_fs_locations_sz \
716 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400717 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400718 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400719 decode_lookup_maxsz + \
720 decode_fs_locations_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000721#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
722 encode_sequence_maxsz + \
723 encode_putfh_maxsz + \
724 encode_secinfo_maxsz)
725#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
726 decode_sequence_maxsz + \
727 decode_putfh_maxsz + \
728 decode_secinfo_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400729#if defined(CONFIG_NFS_V4_1)
730#define NFS4_enc_exchange_id_sz \
731 (compound_encode_hdr_maxsz + \
732 encode_exchange_id_maxsz)
733#define NFS4_dec_exchange_id_sz \
734 (compound_decode_hdr_maxsz + \
735 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400736#define NFS4_enc_create_session_sz \
737 (compound_encode_hdr_maxsz + \
738 encode_create_session_maxsz)
739#define NFS4_dec_create_session_sz \
740 (compound_decode_hdr_maxsz + \
741 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400742#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
743 encode_destroy_session_maxsz)
744#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
745 decode_destroy_session_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400746#define NFS4_enc_sequence_sz \
747 (compound_decode_hdr_maxsz + \
748 encode_sequence_maxsz)
749#define NFS4_dec_sequence_sz \
750 (compound_decode_hdr_maxsz + \
751 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400752#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
753 encode_sequence_maxsz + \
754 encode_putrootfh_maxsz + \
755 encode_fsinfo_maxsz)
756#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
757 decode_sequence_maxsz + \
758 decode_putrootfh_maxsz + \
759 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500760#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
761 encode_sequence_maxsz + \
762 encode_reclaim_complete_maxsz)
763#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
764 decode_sequence_maxsz + \
765 decode_reclaim_complete_maxsz)
Andy Adamson7f11d8d2011-07-30 20:52:35 -0400766#define NFS4_enc_getdevicelist_sz (compound_encode_hdr_maxsz + \
767 encode_sequence_maxsz + \
768 encode_putfh_maxsz + \
769 encode_getdevicelist_maxsz)
770#define NFS4_dec_getdevicelist_sz (compound_decode_hdr_maxsz + \
771 decode_sequence_maxsz + \
772 decode_putfh_maxsz + \
773 decode_getdevicelist_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400774#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
775 encode_sequence_maxsz +\
776 encode_getdeviceinfo_maxsz)
777#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
778 decode_sequence_maxsz + \
779 decode_getdeviceinfo_maxsz)
780#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
781 encode_sequence_maxsz + \
782 encode_putfh_maxsz + \
783 encode_layoutget_maxsz)
784#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
785 decode_sequence_maxsz + \
786 decode_putfh_maxsz + \
787 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000788#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
789 encode_sequence_maxsz +\
790 encode_putfh_maxsz + \
791 encode_layoutcommit_maxsz + \
792 encode_getattr_maxsz)
793#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
794 decode_sequence_maxsz + \
795 decode_putfh_maxsz + \
796 decode_layoutcommit_maxsz + \
797 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300798#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
799 encode_sequence_maxsz + \
800 encode_putfh_maxsz + \
801 encode_layoutreturn_maxsz)
802#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
803 decode_sequence_maxsz + \
804 decode_putfh_maxsz + \
805 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400806#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
807 encode_sequence_maxsz + \
808 encode_putrootfh_maxsz +\
809 encode_secinfo_no_name_maxsz)
810#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
811 decode_sequence_maxsz + \
812 decode_putrootfh_maxsz + \
813 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400814#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
815 encode_sequence_maxsz + \
816 encode_test_stateid_maxsz)
817#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
818 decode_sequence_maxsz + \
819 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400820#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
821 encode_sequence_maxsz + \
822 encode_free_stateid_maxsz)
823#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
824 decode_sequence_maxsz + \
825 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500826
827const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
828 compound_encode_hdr_maxsz +
829 encode_sequence_maxsz +
830 encode_putfh_maxsz +
831 encode_getattr_maxsz) *
832 XDR_UNIT);
833
834const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
835 compound_decode_hdr_maxsz +
836 decode_sequence_maxsz +
837 decode_putfh_maxsz) *
838 XDR_UNIT);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400839#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Trond Myklebustbca79472009-03-11 14:10:26 -0400841static const umode_t nfs_type2fmt[] = {
842 [NF4BAD] = 0,
843 [NF4REG] = S_IFREG,
844 [NF4DIR] = S_IFDIR,
845 [NF4BLK] = S_IFBLK,
846 [NF4CHR] = S_IFCHR,
847 [NF4LNK] = S_IFLNK,
848 [NF4SOCK] = S_IFSOCK,
849 [NF4FIFO] = S_IFIFO,
850 [NF4ATTRDIR] = 0,
851 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852};
853
854struct compound_hdr {
855 int32_t status;
856 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500857 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 uint32_t taglen;
859 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400860 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400861 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862};
863
Benny Halevy13c65ce2009-08-14 17:19:25 +0300864static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
865{
866 __be32 *p = xdr_reserve_space(xdr, nbytes);
867 BUG_ON(!p);
868 return p;
869}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
872{
Al Viro8687b632006-10-19 23:28:48 -0700873 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875 p = xdr_reserve_space(xdr, 4 + len);
876 BUG_ON(p == NULL);
877 xdr_encode_opaque(p, str, len);
878}
879
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400880static void encode_compound_hdr(struct xdr_stream *xdr,
881 struct rpc_rqst *req,
882 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883{
Al Viro8687b632006-10-19 23:28:48 -0700884 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400885 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400886
887 /* initialize running count of expected bytes in reply.
888 * NOTE: the replied tag SHOULD be the same is the one sent,
889 * but this is not required as a MUST for the server to do so. */
890 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
892 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
893 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
Benny Halevy811652b2009-08-14 17:19:34 +0300894 p = reserve_space(xdr, 4 + hdr->taglen + 8);
895 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300896 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500897 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300898 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500899}
900
901static void encode_nops(struct compound_hdr *hdr)
902{
Andy Adamsonfc931582009-04-01 09:22:31 -0400903 BUG_ON(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500904 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905}
906
907static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
908{
Al Viro8687b632006-10-19 23:28:48 -0700909 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
911 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
912 BUG_ON(p == NULL);
913 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
914}
915
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500916static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
918 char owner_name[IDMAP_NAMESZ];
919 char owner_group[IDMAP_NAMESZ];
920 int owner_namelen = 0;
921 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700922 __be32 *p;
923 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 int len;
925 uint32_t bmval0 = 0;
926 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 /*
929 * We reserve enough space to write the entire attribute buffer at once.
930 * In the worst-case, this would be
931 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
932 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000933 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 */
935 len = 16;
936
937 /* Sigh */
938 if (iap->ia_valid & ATTR_SIZE)
939 len += 8;
940 if (iap->ia_valid & ATTR_MODE)
941 len += 4;
942 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800943 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400945 dprintk("nfs: couldn't resolve uid %d to string\n",
946 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 /* XXX */
948 strcpy(owner_name, "nobody");
949 owner_namelen = sizeof("nobody") - 1;
950 /* goto out; */
951 }
952 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
953 }
954 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -0800955 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400957 dprintk("nfs: couldn't resolve gid %d to string\n",
958 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 strcpy(owner_group, "nobody");
960 owner_grouplen = sizeof("nobody") - 1;
961 /* goto out; */
962 }
963 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
964 }
965 if (iap->ia_valid & ATTR_ATIME_SET)
966 len += 16;
967 else if (iap->ia_valid & ATTR_ATIME)
968 len += 4;
969 if (iap->ia_valid & ATTR_MTIME_SET)
970 len += 16;
971 else if (iap->ia_valid & ATTR_MTIME)
972 len += 4;
Benny Halevy13c65ce2009-08-14 17:19:25 +0300973 p = reserve_space(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 /*
976 * We write the bitmap length now, but leave the bitmap and the attribute
977 * buffer length to be backfilled at the end of this routine.
978 */
Benny Halevye75bc1c2009-08-14 17:18:54 +0300979 *p++ = cpu_to_be32(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 q = p;
981 p += 3;
982
983 if (iap->ia_valid & ATTR_SIZE) {
984 bmval0 |= FATTR4_WORD0_SIZE;
Benny Halevyb95be5a2009-08-14 17:19:01 +0300985 p = xdr_encode_hyper(p, iap->ia_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 }
987 if (iap->ia_valid & ATTR_MODE) {
988 bmval1 |= FATTR4_WORD1_MODE;
Benny Halevye75bc1c2009-08-14 17:18:54 +0300989 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 }
991 if (iap->ia_valid & ATTR_UID) {
992 bmval1 |= FATTR4_WORD1_OWNER;
Benny Halevy811652b2009-08-14 17:19:34 +0300993 p = xdr_encode_opaque(p, owner_name, owner_namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 }
995 if (iap->ia_valid & ATTR_GID) {
996 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
Benny Halevy811652b2009-08-14 17:19:34 +0300997 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 }
999 if (iap->ia_valid & ATTR_ATIME_SET) {
1000 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001001 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1002 *p++ = cpu_to_be32(0);
Trond Myklebustd3f6baa2010-06-22 08:52:39 -04001003 *p++ = cpu_to_be32(iap->ia_atime.tv_sec);
1004 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 }
1006 else if (iap->ia_valid & ATTR_ATIME) {
1007 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001008 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 }
1010 if (iap->ia_valid & ATTR_MTIME_SET) {
1011 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001012 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1013 *p++ = cpu_to_be32(0);
1014 *p++ = cpu_to_be32(iap->ia_mtime.tv_sec);
1015 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 }
1017 else if (iap->ia_valid & ATTR_MTIME) {
1018 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
Benny Halevye75bc1c2009-08-14 17:18:54 +03001019 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 /*
1023 * Now we backfill the bitmap and the attribute buffer length.
1024 */
1025 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001026 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 len, ((char *)p - (char *)q) + 4);
1028 BUG();
1029 }
1030 len = (char *)p - (char *)q - 12;
1031 *q++ = htonl(bmval0);
1032 *q++ = htonl(bmval1);
Benny Halevy34558512009-08-14 17:19:30 +03001033 *q = htonl(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036}
1037
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001038static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039{
Al Viro8687b632006-10-19 23:28:48 -07001040 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
Benny Halevy13c65ce2009-08-14 17:19:25 +03001042 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001043 *p++ = cpu_to_be32(OP_ACCESS);
Benny Halevy34558512009-08-14 17:19:30 +03001044 *p = cpu_to_be32(access);
Andy Adamsond0179312008-12-23 16:06:17 -05001045 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001046 hdr->replen += decode_access_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047}
1048
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001049static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050{
Al Viro8687b632006-10-19 23:28:48 -07001051 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Benny Halevy13c65ce2009-08-14 17:19:25 +03001053 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001054 *p++ = cpu_to_be32(OP_CLOSE);
1055 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
Benny Halevy34558512009-08-14 17:19:30 +03001056 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001057 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001058 hdr->replen += decode_close_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059}
1060
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001061static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062{
Al Viro8687b632006-10-19 23:28:48 -07001063 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001064
Benny Halevy13c65ce2009-08-14 17:19:25 +03001065 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001066 *p++ = cpu_to_be32(OP_COMMIT);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001067 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001068 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001069 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001070 hdr->replen += decode_commit_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001073static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
Al Viro8687b632006-10-19 23:28:48 -07001075 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001076
Benny Halevy13c65ce2009-08-14 17:19:25 +03001077 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001078 *p++ = cpu_to_be32(OP_CREATE);
Benny Halevy34558512009-08-14 17:19:30 +03001079 *p = cpu_to_be32(create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081 switch (create->ftype) {
1082 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001083 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001084 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever94a6d752006-08-22 20:06:23 -04001085 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 break;
1087
1088 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001089 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001090 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001091 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 break;
1093
1094 default:
1095 break;
1096 }
1097
Benny Halevy811652b2009-08-14 17:19:34 +03001098 encode_string(xdr, create->name->len, create->name->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001099 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001100 hdr->replen += decode_create_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001102 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103}
1104
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001105static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106{
Andy Adamson05d564f2008-12-23 16:06:15 -05001107 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Benny Halevy13c65ce2009-08-14 17:19:25 +03001109 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001110 *p++ = cpu_to_be32(OP_GETATTR);
1111 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001112 *p = cpu_to_be32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -05001113 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001114 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115}
1116
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001117static 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 -07001118{
Andy Adamson05d564f2008-12-23 16:06:15 -05001119 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
Benny Halevy13c65ce2009-08-14 17:19:25 +03001121 p = reserve_space(xdr, 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001122 *p++ = cpu_to_be32(OP_GETATTR);
1123 *p++ = cpu_to_be32(2);
1124 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001125 *p = cpu_to_be32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -05001126 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001127 hdr->replen += decode_getattr_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Fred Isamandae100c2011-07-30 20:52:37 -04001130static void
1131encode_getattr_three(struct xdr_stream *xdr,
1132 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1133 struct compound_hdr *hdr)
1134{
1135 __be32 *p;
1136
1137 p = reserve_space(xdr, 4);
1138 *p = cpu_to_be32(OP_GETATTR);
1139 if (bm2) {
1140 p = reserve_space(xdr, 16);
1141 *p++ = cpu_to_be32(3);
1142 *p++ = cpu_to_be32(bm0);
1143 *p++ = cpu_to_be32(bm1);
1144 *p = cpu_to_be32(bm2);
1145 } else if (bm1) {
1146 p = reserve_space(xdr, 12);
1147 *p++ = cpu_to_be32(2);
1148 *p++ = cpu_to_be32(bm0);
1149 *p = cpu_to_be32(bm1);
1150 } else {
1151 p = reserve_space(xdr, 8);
1152 *p++ = cpu_to_be32(1);
1153 *p = cpu_to_be32(bm0);
1154 }
1155 hdr->nops++;
1156 hdr->replen += decode_getattr_maxsz;
1157}
1158
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001159static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001161 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1162 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001165static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166{
Fred Isamandae100c2011-07-30 20:52:37 -04001167 encode_getattr_three(xdr,
1168 bitmask[0] & nfs4_fsinfo_bitmap[0],
1169 bitmask[1] & nfs4_fsinfo_bitmap[1],
1170 bitmask[2] & nfs4_fsinfo_bitmap[2],
1171 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172}
1173
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001174static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001175{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001176 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1177 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001178}
1179
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001180static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181{
Al Viro8687b632006-10-19 23:28:48 -07001182 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Benny Halevy13c65ce2009-08-14 17:19:25 +03001184 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001185 *p = cpu_to_be32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001186 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001187 hdr->replen += decode_getfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188}
1189
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001190static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191{
Al Viro8687b632006-10-19 23:28:48 -07001192 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
Benny Halevy13c65ce2009-08-14 17:19:25 +03001194 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001195 *p++ = cpu_to_be32(OP_LINK);
Benny Halevy811652b2009-08-14 17:19:34 +03001196 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001197 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001198 hdr->replen += decode_link_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199}
1200
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001201static inline int nfs4_lock_type(struct file_lock *fl, int block)
1202{
1203 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
1204 return block ? NFS4_READW_LT : NFS4_READ_LT;
1205 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1206}
1207
1208static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1209{
1210 if (fl->fl_end == OFFSET_MAX)
1211 return ~(uint64_t)0;
1212 return fl->fl_end - fl->fl_start + 1;
1213}
1214
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001215static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1216{
1217 __be32 *p;
1218
Trond Myklebustd035c362010-12-21 10:45:27 -05001219 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001220 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001221 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001222 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001223 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001224 xdr_encode_hyper(p, lowner->id);
1225}
1226
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227/*
1228 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1229 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1230 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001231static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232{
Al Viro8687b632006-10-19 23:28:48 -07001233 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
Benny Halevy13c65ce2009-08-14 17:19:25 +03001235 p = reserve_space(xdr, 32);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001236 *p++ = cpu_to_be32(OP_LOCK);
1237 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1238 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001239 p = xdr_encode_hyper(p, args->fl->fl_start);
1240 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001241 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001242 if (args->new_lock_owner){
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001243 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001244 *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001245 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001246 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001247 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 }
1249 else {
Benny Halevy13c65ce2009-08-14 17:19:25 +03001250 p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001251 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001252 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 }
Andy Adamsond0179312008-12-23 16:06:17 -05001254 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001255 hdr->replen += decode_lock_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256}
1257
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001258static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259{
Al Viro8687b632006-10-19 23:28:48 -07001260 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001262 p = reserve_space(xdr, 24);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001263 *p++ = cpu_to_be32(OP_LOCKT);
1264 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001265 p = xdr_encode_hyper(p, args->fl->fl_start);
1266 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001267 encode_lockowner(xdr, &args->lock_owner);
Andy Adamsond0179312008-12-23 16:06:17 -05001268 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001269 hdr->replen += decode_lockt_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270}
1271
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001272static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273{
Al Viro8687b632006-10-19 23:28:48 -07001274 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Benny Halevy13c65ce2009-08-14 17:19:25 +03001276 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001277 *p++ = cpu_to_be32(OP_LOCKU);
1278 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1279 *p++ = cpu_to_be32(args->seqid->sequence->counter);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001280 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001281 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001282 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -05001283 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001284 hdr->replen += decode_locku_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285}
1286
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001287static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1288{
1289 __be32 *p;
1290
1291 p = reserve_space(xdr, 4);
1292 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1293 encode_lockowner(xdr, lowner);
1294 hdr->nops++;
1295 hdr->replen += decode_release_lockowner_maxsz;
1296}
1297
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001298static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299{
1300 int len = name->len;
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, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001304 *p++ = cpu_to_be32(OP_LOOKUP);
Benny Halevy811652b2009-08-14 17:19:34 +03001305 xdr_encode_opaque(p, name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001306 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001307 hdr->replen += decode_lookup_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308}
1309
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001310static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311{
Al Viro8687b632006-10-19 23:28:48 -07001312 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Benny Halevy13c65ce2009-08-14 17:19:25 +03001314 p = reserve_space(xdr, 8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001315 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001316 case FMODE_READ:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001317 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001318 break;
1319 case FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001320 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001321 break;
1322 case FMODE_READ|FMODE_WRITE:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001323 *p++ = cpu_to_be32(NFS4_SHARE_ACCESS_BOTH);
Andy Adamson05d564f2008-12-23 16:06:15 -05001324 break;
1325 default:
Benny Halevye75bc1c2009-08-14 17:18:54 +03001326 *p++ = cpu_to_be32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 }
Benny Halevy34558512009-08-14 17:19:30 +03001328 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329}
1330
1331static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1332{
Al Viro8687b632006-10-19 23:28:48 -07001333 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 /*
1335 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1336 * owner 4 = 32
1337 */
Benny Halevy13c65ce2009-08-14 17:19:25 +03001338 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001339 *p++ = cpu_to_be32(OP_OPEN);
Benny Halevy34558512009-08-14 17:19:30 +03001340 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001341 encode_share_access(xdr, arg->fmode);
Trond Myklebustd035c362010-12-21 10:45:27 -05001342 p = reserve_space(xdr, 32);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001343 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001344 *p++ = cpu_to_be32(20);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001345 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001346 *p++ = cpu_to_be32(arg->server->s_dev);
Benny Halevy34558512009-08-14 17:19:30 +03001347 xdr_encode_hyper(p, arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348}
1349
1350static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1351{
Al Viro8687b632006-10-19 23:28:48 -07001352 __be32 *p;
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001353 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Benny Halevy13c65ce2009-08-14 17:19:25 +03001355 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001357 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001358 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andy Adamson05d564f2008-12-23 16:06:15 -05001359 encode_attrs(xdr, arg->u.attrs, arg->server);
1360 break;
1361 default:
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001362 clp = arg->server->nfs_client;
Trond Myklebusta4432342010-06-16 09:52:27 -04001363 if (clp->cl_mvops->minor_version > 0) {
Alexandros Batsakis4882ef72009-12-05 13:30:21 -05001364 if (nfs4_has_persistent_session(clp)) {
1365 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
1366 encode_attrs(xdr, arg->u.attrs, arg->server);
1367 } else {
1368 struct iattr dummy;
1369
1370 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1371 encode_nfs4_verifier(xdr, &arg->u.verifier);
1372 dummy.ia_valid = 0;
1373 encode_attrs(xdr, &dummy, arg->server);
1374 }
1375 } else {
1376 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1377 encode_nfs4_verifier(xdr, &arg->u.verifier);
1378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
1380}
1381
1382static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1383{
Al Viro8687b632006-10-19 23:28:48 -07001384 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Benny Halevy13c65ce2009-08-14 17:19:25 +03001386 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001388 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001389 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001390 break;
1391 default:
1392 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
Benny Halevy34558512009-08-14 17:19:30 +03001393 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001394 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 }
1396}
1397
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001398static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399{
Al Viro8687b632006-10-19 23:28:48 -07001400 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
Benny Halevy13c65ce2009-08-14 17:19:25 +03001402 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001404 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001405 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001406 break;
1407 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001408 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001409 break;
1410 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001411 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001412 break;
1413 default:
1414 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 }
1416}
1417
1418static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1419{
Al Viro8687b632006-10-19 23:28:48 -07001420 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Benny Halevy13c65ce2009-08-14 17:19:25 +03001422 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001423 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 encode_string(xdr, name->len, name->name);
1425}
1426
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001427static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428{
Al Viro8687b632006-10-19 23:28:48 -07001429 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Benny Halevy13c65ce2009-08-14 17:19:25 +03001431 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001432 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 encode_delegation_type(xdr, type);
1434}
1435
1436static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1437{
Al Viro8687b632006-10-19 23:28:48 -07001438 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Benny Halevy13c65ce2009-08-14 17:19:25 +03001440 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001441 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
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 encode_string(xdr, name->len, name->name);
1444}
1445
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001446static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447{
1448 encode_openhdr(xdr, arg);
1449 encode_opentype(xdr, arg);
1450 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001451 case NFS4_OPEN_CLAIM_NULL:
1452 encode_claim_null(xdr, arg->name);
1453 break;
1454 case NFS4_OPEN_CLAIM_PREVIOUS:
1455 encode_claim_previous(xdr, arg->u.delegation_type);
1456 break;
1457 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1458 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1459 break;
1460 default:
1461 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 }
Andy Adamsond0179312008-12-23 16:06:17 -05001463 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001464 hdr->replen += decode_open_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465}
1466
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001467static 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 -07001468{
Al Viro8687b632006-10-19 23:28:48 -07001469 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
Benny Halevy13c65ce2009-08-14 17:19:25 +03001471 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001472 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001473 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001474 *p = cpu_to_be32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001475 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001476 hdr->replen += decode_open_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477}
1478
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001479static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480{
Al Viro8687b632006-10-19 23:28:48 -07001481 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Benny Halevy13c65ce2009-08-14 17:19:25 +03001483 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001484 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001485 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
Benny Halevy34558512009-08-14 17:19:30 +03001486 *p = cpu_to_be32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001487 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001488 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001489 hdr->replen += decode_open_downgrade_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490}
1491
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001492static void
Andy Adamsond0179312008-12-23 16:06:17 -05001493encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494{
1495 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001496 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
Benny Halevy13c65ce2009-08-14 17:19:25 +03001498 p = reserve_space(xdr, 8 + len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001499 *p++ = cpu_to_be32(OP_PUTFH);
Benny Halevy811652b2009-08-14 17:19:34 +03001500 xdr_encode_opaque(p, fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001501 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001502 hdr->replen += decode_putfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503}
1504
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001505static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506{
Andy Adamson05d564f2008-12-23 16:06:15 -05001507 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001508
Benny Halevy13c65ce2009-08-14 17:19:25 +03001509 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001510 *p = cpu_to_be32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001511 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001512 hdr->replen += decode_putrootfh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513}
1514
Andy Adamson89d1ea62011-03-01 01:34:09 +00001515static 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 -07001516{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001518 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Benny Halevy13c65ce2009-08-14 17:19:25 +03001520 p = reserve_space(xdr, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 if (ctx->state != NULL) {
Trond Myklebust77041ed2010-07-01 12:49:11 -04001522 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
Andy Adamson89d1ea62011-03-01 01:34:09 +00001523 if (zero_seqid)
1524 stateid.stateid.seqid = 0;
Benny Halevy34558512009-08-14 17:19:30 +03001525 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 } else
Benny Halevy34558512009-08-14 17:19:30 +03001527 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528}
1529
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001530static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
Al Viro8687b632006-10-19 23:28:48 -07001532 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Benny Halevy13c65ce2009-08-14 17:19:25 +03001534 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001535 *p = cpu_to_be32(OP_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Andy Adamson89d1ea62011-03-01 01:34:09 +00001537 encode_stateid(xdr, args->context, args->lock_context,
1538 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
Benny Halevy13c65ce2009-08-14 17:19:25 +03001540 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001541 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001542 *p = cpu_to_be32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001543 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001544 hdr->replen += decode_read_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545}
1546
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001547static 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 -07001548{
Trond Myklebust28331a42011-04-27 13:47:52 -04001549 uint32_t attrs[2] = {
1550 FATTR4_WORD0_RDATTR_ERROR,
1551 FATTR4_WORD1_MOUNTED_ON_FILEID,
1552 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001553 uint32_t dircount = readdir->count >> 1;
Al Viro8687b632006-10-19 23:28:48 -07001554 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001556 if (readdir->plus) {
1557 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001558 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001559 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1560 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1561 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1562 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001563 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001564 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001565 /* Use mounted_on_fileid only if the server supports it */
1566 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1567 attrs[0] |= FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001568
Benny Halevy13c65ce2009-08-14 17:19:25 +03001569 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001570 *p++ = cpu_to_be32(OP_READDIR);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001571 p = xdr_encode_hyper(p, readdir->cookie);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001572 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001573 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001574 *p++ = cpu_to_be32(readdir->count);
1575 *p++ = cpu_to_be32(2);
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001576
Benny Halevye75bc1c2009-08-14 17:18:54 +03001577 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
Benny Halevy34558512009-08-14 17:19:30 +03001578 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001579 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001580 hdr->replen += decode_readdir_maxsz;
Fred Isaman44109242008-04-02 15:21:15 +03001581 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1582 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001583 (unsigned long long)readdir->cookie,
1584 ((u32 *)readdir->verifier.data)[0],
1585 ((u32 *)readdir->verifier.data)[1],
1586 attrs[0] & readdir->bitmask[0],
1587 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588}
1589
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001590static 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 -07001591{
Al Viro8687b632006-10-19 23:28:48 -07001592 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
Benny Halevy13c65ce2009-08-14 17:19:25 +03001594 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001595 *p = cpu_to_be32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001596 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001597 hdr->replen += decode_readlink_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598}
1599
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001600static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601{
Al Viro8687b632006-10-19 23:28:48 -07001602 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
Benny Halevy13c65ce2009-08-14 17:19:25 +03001604 p = reserve_space(xdr, 8 + name->len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001605 *p++ = cpu_to_be32(OP_REMOVE);
Benny Halevy811652b2009-08-14 17:19:34 +03001606 xdr_encode_opaque(p, name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001607 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001608 hdr->replen += decode_remove_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609}
1610
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001611static 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 -07001612{
Al Viro8687b632006-10-19 23:28:48 -07001613 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
Benny Halevy811652b2009-08-14 17:19:34 +03001615 p = reserve_space(xdr, 4);
1616 *p = cpu_to_be32(OP_RENAME);
1617 encode_string(xdr, oldname->len, oldname->name);
1618 encode_string(xdr, newname->len, newname->name);
Andy Adamsond0179312008-12-23 16:06:17 -05001619 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001620 hdr->replen += decode_rename_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001623static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
Al Viro8687b632006-10-19 23:28:48 -07001625 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Benny Halevy13c65ce2009-08-14 17:19:25 +03001627 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001628 *p++ = cpu_to_be32(OP_RENEW);
Benny Halevy34558512009-08-14 17:19:30 +03001629 xdr_encode_hyper(p, client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001630 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001631 hdr->replen += decode_renew_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001634static void
Andy Adamsond0179312008-12-23 16:06:17 -05001635encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001636{
Al Viro8687b632006-10-19 23:28:48 -07001637 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001638
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_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001641 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001642 hdr->replen += decode_restorefh_maxsz;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001643}
1644
Chuck Lever9f06c712010-12-14 14:59:18 +00001645static void
Andy Adamsond0179312008-12-23 16:06:17 -05001646encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001647{
Al Viro8687b632006-10-19 23:28:48 -07001648 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001649
Benny Halevy13c65ce2009-08-14 17:19:25 +03001650 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001651 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001652 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001653 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001654 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001655 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Chuck Lever9f06c712010-12-14 14:59:18 +00001656 BUG_ON(arg->acl_len % 4);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001657 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001658 *p = cpu_to_be32(arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001659 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001660 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001661 hdr->replen += decode_setacl_maxsz;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001662}
1663
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001664static void
Andy Adamsond0179312008-12-23 16:06:17 -05001665encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666{
Al Viro8687b632006-10-19 23:28:48 -07001667 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
Benny Halevy13c65ce2009-08-14 17:19:25 +03001669 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001670 *p = cpu_to_be32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001671 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001672 hdr->replen += decode_savefh_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673}
1674
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001675static 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 -07001676{
Al Viro8687b632006-10-19 23:28:48 -07001677 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001678
Benny Halevy13c65ce2009-08-14 17:19:25 +03001679 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001680 *p++ = cpu_to_be32(OP_SETATTR);
Benny Halevy34558512009-08-14 17:19:30 +03001681 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001682 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001683 hdr->replen += decode_setattr_maxsz;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001684 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685}
1686
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001687static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688{
Al Viro8687b632006-10-19 23:28:48 -07001689 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690
Benny Halevy13c65ce2009-08-14 17:19:25 +03001691 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001692 *p++ = cpu_to_be32(OP_SETCLIENTID);
Benny Halevy34558512009-08-14 17:19:30 +03001693 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
1695 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001696 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001697 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1699 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001700 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001701 *p = cpu_to_be32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001702 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001703 hdr->replen += decode_setclientid_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704}
1705
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001706static 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 -07001707{
Andy Adamson05d564f2008-12-23 16:06:15 -05001708 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Benny Halevy13c65ce2009-08-14 17:19:25 +03001710 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001711 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001712 p = xdr_encode_hyper(p, arg->clientid);
1713 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001714 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001715 hdr->replen += decode_setclientid_confirm_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
1717
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001718static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719{
Al Viro8687b632006-10-19 23:28:48 -07001720 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Benny Halevy13c65ce2009-08-14 17:19:25 +03001722 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001723 *p = cpu_to_be32(OP_WRITE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
Andy Adamson89d1ea62011-03-01 01:34:09 +00001725 encode_stateid(xdr, args->context, args->lock_context,
1726 hdr->minorversion);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Benny Halevy13c65ce2009-08-14 17:19:25 +03001728 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001729 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001730 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001731 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
1733 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001734 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001735 hdr->replen += decode_write_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736}
1737
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001738static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739{
Al Viro8687b632006-10-19 23:28:48 -07001740 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
Benny Halevy13c65ce2009-08-14 17:19:25 +03001742 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
Benny Halevye75bc1c2009-08-14 17:18:54 +03001744 *p++ = cpu_to_be32(OP_DELEGRETURN);
Benny Halevy34558512009-08-14 17:19:30 +03001745 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001746 hdr->nops++;
Benny Halevydadf0c22009-04-01 09:22:08 -04001747 hdr->replen += decode_delegreturn_maxsz;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001749
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001750static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1751{
1752 int len = name->len;
1753 __be32 *p;
1754
1755 p = reserve_space(xdr, 8 + len);
1756 *p++ = cpu_to_be32(OP_SECINFO);
1757 xdr_encode_opaque(p, name->name, len);
1758 hdr->nops++;
1759 hdr->replen += decode_secinfo_maxsz;
1760}
1761
Benny Halevy99fe60d2009-04-01 09:22:29 -04001762#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001763/* NFSv4.1 operations */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001764static void encode_exchange_id(struct xdr_stream *xdr,
1765 struct nfs41_exchange_id_args *args,
1766 struct compound_hdr *hdr)
1767{
1768 __be32 *p;
1769
Benny Halevy13c65ce2009-08-14 17:19:25 +03001770 p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
Benny Halevye75bc1c2009-08-14 17:18:54 +03001771 *p++ = cpu_to_be32(OP_EXCHANGE_ID);
Benny Halevy34558512009-08-14 17:19:30 +03001772 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
Benny Halevy99fe60d2009-04-01 09:22:29 -04001773
1774 encode_string(xdr, args->id_len, args->id);
1775
Benny Halevy13c65ce2009-08-14 17:19:25 +03001776 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001777 *p++ = cpu_to_be32(args->flags);
1778 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
Benny Halevy34558512009-08-14 17:19:30 +03001779 *p = cpu_to_be32(0); /* zero length implementation id array */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001780 hdr->nops++;
1781 hdr->replen += decode_exchange_id_maxsz;
1782}
Andy Adamsonfc931582009-04-01 09:22:31 -04001783
1784static void encode_create_session(struct xdr_stream *xdr,
1785 struct nfs41_create_session_args *args,
1786 struct compound_hdr *hdr)
1787{
1788 __be32 *p;
1789 char machine_name[NFS4_MAX_MACHINE_NAME_LEN];
1790 uint32_t len;
1791 struct nfs_client *clp = args->client;
Mike Sager8e0d46e2009-12-17 12:06:26 -05001792 u32 max_resp_sz_cached;
1793
1794 /*
1795 * Assumes OPEN is the biggest non-idempotent compound.
1796 * 2 is the verifier.
1797 */
1798 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1799 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001800
Andy Adamsonfc931582009-04-01 09:22:31 -04001801 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1802 clp->cl_ipaddr);
Benny Halevy42edd692009-08-14 17:19:13 +03001803
Benny Halevy13c65ce2009-08-14 17:19:25 +03001804 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001805 *p++ = cpu_to_be32(OP_CREATE_SESSION);
Andy Adamson114f64b2011-03-09 13:13:45 -05001806 p = xdr_encode_hyper(p, clp->cl_clientid);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001807 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1808 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001809
Andy Adamsonfc931582009-04-01 09:22:31 -04001810 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001811 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001812 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1813 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001814 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001815 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1816 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1817 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001818
1819 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001820 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001821 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1822 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1823 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1824 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1825 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1826 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001827
Benny Halevye75bc1c2009-08-14 17:18:54 +03001828 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001829 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001830 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001831
1832 /* authsys_parms rfc1831 */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001833 *p++ = cpu_to_be32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
Benny Halevy811652b2009-08-14 17:19:34 +03001834 p = xdr_encode_opaque(p, machine_name, len);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001835 *p++ = cpu_to_be32(0); /* UID */
1836 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001837 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001838 hdr->nops++;
1839 hdr->replen += decode_create_session_maxsz;
1840}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001841
1842static void encode_destroy_session(struct xdr_stream *xdr,
1843 struct nfs4_session *session,
1844 struct compound_hdr *hdr)
1845{
1846 __be32 *p;
Benny Halevy13c65ce2009-08-14 17:19:25 +03001847 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001848 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
Benny Halevy34558512009-08-14 17:19:30 +03001849 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001850 hdr->nops++;
1851 hdr->replen += decode_destroy_session_maxsz;
1852}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001853
1854static void encode_reclaim_complete(struct xdr_stream *xdr,
1855 struct nfs41_reclaim_complete_args *args,
1856 struct compound_hdr *hdr)
1857{
1858 __be32 *p;
1859
1860 p = reserve_space(xdr, 8);
1861 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1862 *p++ = cpu_to_be32(args->one_fs);
1863 hdr->nops++;
1864 hdr->replen += decode_reclaim_complete_maxsz;
1865}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001866#endif /* CONFIG_NFS_V4_1 */
1867
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001868static void encode_sequence(struct xdr_stream *xdr,
1869 const struct nfs4_sequence_args *args,
1870 struct compound_hdr *hdr)
1871{
1872#if defined(CONFIG_NFS_V4_1)
1873 struct nfs4_session *session = args->sa_session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001874 struct nfs4_slot_table *tp;
1875 struct nfs4_slot *slot;
1876 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001877
1878 if (!session)
1879 return;
1880
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001881 tp = &session->fc_slot_table;
1882
1883 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1884 slot = tp->slots + args->sa_slotid;
1885
Benny Halevy13c65ce2009-08-14 17:19:25 +03001886 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001887 *p++ = cpu_to_be32(OP_SEQUENCE);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001888
1889 /*
1890 * Sessionid + seqid + slotid + max slotid + cache_this
1891 */
1892 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1893 "max_slotid=%d cache_this=%d\n",
1894 __func__,
1895 ((u32 *)session->sess_id.data)[0],
1896 ((u32 *)session->sess_id.data)[1],
1897 ((u32 *)session->sess_id.data)[2],
1898 ((u32 *)session->sess_id.data)[3],
1899 slot->seq_nr, args->sa_slotid,
1900 tp->highest_used_slotid, args->sa_cache_this);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001901 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001902 *p++ = cpu_to_be32(slot->seq_nr);
1903 *p++ = cpu_to_be32(args->sa_slotid);
1904 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001905 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001906 hdr->nops++;
1907 hdr->replen += decode_sequence_maxsz;
1908#endif /* CONFIG_NFS_V4_1 */
1909}
1910
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001911#ifdef CONFIG_NFS_V4_1
1912static void
Andy Adamson7f11d8d2011-07-30 20:52:35 -04001913encode_getdevicelist(struct xdr_stream *xdr,
1914 const struct nfs4_getdevicelist_args *args,
1915 struct compound_hdr *hdr)
1916{
1917 __be32 *p;
1918 nfs4_verifier dummy = {
1919 .data = "dummmmmy",
1920 };
1921
1922 p = reserve_space(xdr, 20);
1923 *p++ = cpu_to_be32(OP_GETDEVICELIST);
1924 *p++ = cpu_to_be32(args->layoutclass);
1925 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1926 xdr_encode_hyper(p, 0ULL); /* cookie */
1927 encode_nfs4_verifier(xdr, &dummy);
1928 hdr->nops++;
1929 hdr->replen += decode_getdevicelist_maxsz;
1930}
1931
1932static void
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001933encode_getdeviceinfo(struct xdr_stream *xdr,
1934 const struct nfs4_getdeviceinfo_args *args,
1935 struct compound_hdr *hdr)
1936{
1937 __be32 *p;
1938
1939 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE);
1940 *p++ = cpu_to_be32(OP_GETDEVICEINFO);
1941 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1942 NFS4_DEVICEID4_SIZE);
1943 *p++ = cpu_to_be32(args->pdev->layout_type);
1944 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1945 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1946 hdr->nops++;
1947 hdr->replen += decode_getdeviceinfo_maxsz;
1948}
1949
1950static void
1951encode_layoutget(struct xdr_stream *xdr,
1952 const struct nfs4_layoutget_args *args,
1953 struct compound_hdr *hdr)
1954{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001955 __be32 *p;
1956
1957 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
1958 *p++ = cpu_to_be32(OP_LAYOUTGET);
1959 *p++ = cpu_to_be32(0); /* Signal layout available */
1960 *p++ = cpu_to_be32(args->type);
1961 *p++ = cpu_to_be32(args->range.iomode);
1962 p = xdr_encode_hyper(p, args->range.offset);
1963 p = xdr_encode_hyper(p, args->range.length);
1964 p = xdr_encode_hyper(p, args->minlength);
Fred Isamancf7d63f2011-01-06 11:36:25 +00001965 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001966 *p = cpu_to_be32(args->maxcount);
1967
1968 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1969 __func__,
1970 args->type,
1971 args->range.iomode,
1972 (unsigned long)args->range.offset,
1973 (unsigned long)args->range.length,
1974 args->maxcount);
1975 hdr->nops++;
1976 hdr->replen += decode_layoutget_maxsz;
1977}
Andy Adamson863a3c62011-03-23 13:27:54 +00001978
1979static int
1980encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001981 struct inode *inode,
Andy Adamson863a3c62011-03-23 13:27:54 +00001982 const struct nfs4_layoutcommit_args *args,
1983 struct compound_hdr *hdr)
1984{
1985 __be32 *p;
1986
1987 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1988 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1989
Benny Halevyac7db722011-05-22 19:53:48 +03001990 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
Andy Adamson863a3c62011-03-23 13:27:54 +00001991 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
1992 /* Only whole file layouts */
1993 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001994 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Andy Adamson863a3c62011-03-23 13:27:54 +00001995 *p++ = cpu_to_be32(0); /* reclaim */
1996 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
1997 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1998 p = xdr_encode_hyper(p, args->lastbytewritten);
1999 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2000 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002001
2002 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2003 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2004 NFS_I(inode)->layout, xdr, args);
2005 else {
2006 p = reserve_space(xdr, 4);
2007 *p = cpu_to_be32(0); /* no layout-type payload */
2008 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002009
2010 hdr->nops++;
2011 hdr->replen += decode_layoutcommit_maxsz;
2012 return 0;
2013}
Benny Halevycbe82602011-05-22 19:52:37 +03002014
2015static void
2016encode_layoutreturn(struct xdr_stream *xdr,
2017 const struct nfs4_layoutreturn_args *args,
2018 struct compound_hdr *hdr)
2019{
2020 __be32 *p;
2021
2022 p = reserve_space(xdr, 20);
2023 *p++ = cpu_to_be32(OP_LAYOUTRETURN);
2024 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2025 *p++ = cpu_to_be32(args->layout_type);
2026 *p++ = cpu_to_be32(IOMODE_ANY);
2027 *p = cpu_to_be32(RETURN_FILE);
2028 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
2029 p = xdr_encode_hyper(p, 0);
2030 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2031 spin_lock(&args->inode->i_lock);
2032 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
2033 spin_unlock(&args->inode->i_lock);
Andy Adamson04a55542011-05-22 19:53:10 +03002034 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2035 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2036 NFS_I(args->inode)->layout, xdr, args);
2037 } else {
2038 p = reserve_space(xdr, 4);
2039 *p = cpu_to_be32(0);
2040 }
Benny Halevycbe82602011-05-22 19:52:37 +03002041 hdr->nops++;
2042 hdr->replen += decode_layoutreturn_maxsz;
2043}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002044
2045static int
2046encode_secinfo_no_name(struct xdr_stream *xdr,
2047 const struct nfs41_secinfo_no_name_args *args,
2048 struct compound_hdr *hdr)
2049{
2050 __be32 *p;
2051 p = reserve_space(xdr, 8);
2052 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2053 *p++ = cpu_to_be32(args->style);
2054 hdr->nops++;
2055 hdr->replen += decode_secinfo_no_name_maxsz;
2056 return 0;
2057}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002058
2059static void encode_test_stateid(struct xdr_stream *xdr,
2060 struct nfs41_test_stateid_args *args,
2061 struct compound_hdr *hdr)
2062{
2063 __be32 *p;
2064
2065 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
2066 *p++ = cpu_to_be32(OP_TEST_STATEID);
2067 *p++ = cpu_to_be32(1);
2068 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2069 hdr->nops++;
2070 hdr->replen += decode_test_stateid_maxsz;
2071}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002072
2073static void encode_free_stateid(struct xdr_stream *xdr,
2074 struct nfs41_free_stateid_args *args,
2075 struct compound_hdr *hdr)
2076{
2077 __be32 *p;
2078 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
2079 *p++ = cpu_to_be32(OP_FREE_STATEID);
2080 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2081 hdr->nops++;
2082 hdr->replen += decode_free_stateid_maxsz;
2083}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002084#endif /* CONFIG_NFS_V4_1 */
2085
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086/*
2087 * END OF "GENERIC" ENCODE ROUTINES.
2088 */
2089
Benny Halevy66cc0422009-04-01 09:22:10 -04002090static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2091{
2092#if defined(CONFIG_NFS_V4_1)
2093 if (args->sa_session)
Trond Myklebusta4432342010-06-16 09:52:27 -04002094 return args->sa_session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002095#endif /* CONFIG_NFS_V4_1 */
2096 return 0;
2097}
2098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099/*
2100 * Encode an ACCESS request
2101 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002102static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2103 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002106 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
Chuck Lever9f06c712010-12-14 14:59:18 +00002109 encode_compound_hdr(xdr, req, &hdr);
2110 encode_sequence(xdr, &args->seq_args, &hdr);
2111 encode_putfh(xdr, args->fh, &hdr);
2112 encode_access(xdr, args->access, &hdr);
2113 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002114 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115}
2116
2117/*
2118 * Encode LOOKUP request
2119 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002120static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2121 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002124 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
Chuck Lever9f06c712010-12-14 14:59:18 +00002127 encode_compound_hdr(xdr, req, &hdr);
2128 encode_sequence(xdr, &args->seq_args, &hdr);
2129 encode_putfh(xdr, args->dir_fh, &hdr);
2130 encode_lookup(xdr, args->name, &hdr);
2131 encode_getfh(xdr, &hdr);
2132 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002133 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134}
2135
2136/*
2137 * Encode LOOKUP_ROOT request
2138 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002139static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2140 struct xdr_stream *xdr,
2141 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002144 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
Chuck Lever9f06c712010-12-14 14:59:18 +00002147 encode_compound_hdr(xdr, req, &hdr);
2148 encode_sequence(xdr, &args->seq_args, &hdr);
2149 encode_putrootfh(xdr, &hdr);
2150 encode_getfh(xdr, &hdr);
2151 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002152 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153}
2154
2155/*
2156 * Encode REMOVE request
2157 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002158static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2159 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002162 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164
Chuck Lever9f06c712010-12-14 14:59:18 +00002165 encode_compound_hdr(xdr, req, &hdr);
2166 encode_sequence(xdr, &args->seq_args, &hdr);
2167 encode_putfh(xdr, args->fh, &hdr);
2168 encode_remove(xdr, &args->name, &hdr);
2169 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002170 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171}
2172
2173/*
2174 * Encode RENAME request
2175 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002176static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2177 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002180 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
Chuck Lever9f06c712010-12-14 14:59:18 +00002183 encode_compound_hdr(xdr, req, &hdr);
2184 encode_sequence(xdr, &args->seq_args, &hdr);
2185 encode_putfh(xdr, args->old_dir, &hdr);
2186 encode_savefh(xdr, &hdr);
2187 encode_putfh(xdr, args->new_dir, &hdr);
2188 encode_rename(xdr, args->old_name, args->new_name, &hdr);
2189 encode_getfattr(xdr, args->bitmask, &hdr);
2190 encode_restorefh(xdr, &hdr);
2191 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002192 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193}
2194
2195/*
2196 * Encode LINK request
2197 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002198static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2199 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002202 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
Chuck Lever9f06c712010-12-14 14:59:18 +00002205 encode_compound_hdr(xdr, req, &hdr);
2206 encode_sequence(xdr, &args->seq_args, &hdr);
2207 encode_putfh(xdr, args->fh, &hdr);
2208 encode_savefh(xdr, &hdr);
2209 encode_putfh(xdr, args->dir_fh, &hdr);
2210 encode_link(xdr, args->name, &hdr);
2211 encode_getfattr(xdr, args->bitmask, &hdr);
2212 encode_restorefh(xdr, &hdr);
2213 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002214 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215}
2216
2217/*
2218 * Encode CREATE request
2219 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002220static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2221 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002224 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
Chuck Lever9f06c712010-12-14 14:59:18 +00002227 encode_compound_hdr(xdr, req, &hdr);
2228 encode_sequence(xdr, &args->seq_args, &hdr);
2229 encode_putfh(xdr, args->dir_fh, &hdr);
2230 encode_savefh(xdr, &hdr);
2231 encode_create(xdr, args, &hdr);
2232 encode_getfh(xdr, &hdr);
2233 encode_getfattr(xdr, args->bitmask, &hdr);
2234 encode_restorefh(xdr, &hdr);
2235 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002236 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237}
2238
2239/*
2240 * Encode SYMLINK request
2241 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002242static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2243 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244{
Chuck Lever9f06c712010-12-14 14:59:18 +00002245 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246}
2247
2248/*
2249 * Encode GETATTR request
2250 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002251static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2252 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002255 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
Chuck Lever9f06c712010-12-14 14:59:18 +00002258 encode_compound_hdr(xdr, req, &hdr);
2259 encode_sequence(xdr, &args->seq_args, &hdr);
2260 encode_putfh(xdr, args->fh, &hdr);
2261 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002262 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263}
2264
2265/*
2266 * Encode a CLOSE request
2267 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002268static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2269 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270{
Andy Adamson05d564f2008-12-23 16:06:15 -05002271 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002272 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002273 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274
Chuck Lever9f06c712010-12-14 14:59:18 +00002275 encode_compound_hdr(xdr, req, &hdr);
2276 encode_sequence(xdr, &args->seq_args, &hdr);
2277 encode_putfh(xdr, args->fh, &hdr);
2278 encode_close(xdr, args, &hdr);
2279 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002280 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281}
2282
2283/*
2284 * Encode an OPEN request
2285 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002286static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2287 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002290 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
Chuck Lever9f06c712010-12-14 14:59:18 +00002293 encode_compound_hdr(xdr, req, &hdr);
2294 encode_sequence(xdr, &args->seq_args, &hdr);
2295 encode_putfh(xdr, args->fh, &hdr);
2296 encode_savefh(xdr, &hdr);
2297 encode_open(xdr, args, &hdr);
2298 encode_getfh(xdr, &hdr);
2299 encode_getfattr(xdr, args->bitmask, &hdr);
2300 encode_restorefh(xdr, &hdr);
2301 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002302 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303}
2304
2305/*
2306 * Encode an OPEN_CONFIRM request
2307 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002308static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2309 struct xdr_stream *xdr,
2310 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002313 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Chuck Lever9f06c712010-12-14 14:59:18 +00002316 encode_compound_hdr(xdr, req, &hdr);
2317 encode_putfh(xdr, args->fh, &hdr);
2318 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002319 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320}
2321
2322/*
2323 * Encode an OPEN request with no attributes.
2324 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002325static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2326 struct xdr_stream *xdr,
2327 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002330 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
Chuck Lever9f06c712010-12-14 14:59:18 +00002333 encode_compound_hdr(xdr, req, &hdr);
2334 encode_sequence(xdr, &args->seq_args, &hdr);
2335 encode_putfh(xdr, args->fh, &hdr);
2336 encode_open(xdr, args, &hdr);
2337 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002338 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339}
2340
2341/*
2342 * Encode an OPEN_DOWNGRADE request
2343 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002344static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2345 struct xdr_stream *xdr,
2346 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002349 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351
Chuck Lever9f06c712010-12-14 14:59:18 +00002352 encode_compound_hdr(xdr, req, &hdr);
2353 encode_sequence(xdr, &args->seq_args, &hdr);
2354 encode_putfh(xdr, args->fh, &hdr);
2355 encode_open_downgrade(xdr, args, &hdr);
2356 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002357 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358}
2359
2360/*
2361 * Encode a LOCK request
2362 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002363static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2364 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002367 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369
Chuck Lever9f06c712010-12-14 14:59:18 +00002370 encode_compound_hdr(xdr, req, &hdr);
2371 encode_sequence(xdr, &args->seq_args, &hdr);
2372 encode_putfh(xdr, args->fh, &hdr);
2373 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002374 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375}
2376
2377/*
2378 * Encode a LOCKT request
2379 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002380static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2381 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002384 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
Chuck Lever9f06c712010-12-14 14:59:18 +00002387 encode_compound_hdr(xdr, req, &hdr);
2388 encode_sequence(xdr, &args->seq_args, &hdr);
2389 encode_putfh(xdr, args->fh, &hdr);
2390 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002391 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392}
2393
2394/*
2395 * Encode a LOCKU request
2396 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002397static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2398 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002401 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403
Chuck Lever9f06c712010-12-14 14:59:18 +00002404 encode_compound_hdr(xdr, req, &hdr);
2405 encode_sequence(xdr, &args->seq_args, &hdr);
2406 encode_putfh(xdr, args->fh, &hdr);
2407 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002408 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409}
2410
Chuck Lever9f06c712010-12-14 14:59:18 +00002411static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2412 struct xdr_stream *xdr,
2413 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002414{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002415 struct compound_hdr hdr = {
2416 .minorversion = 0,
2417 };
2418
Chuck Lever9f06c712010-12-14 14:59:18 +00002419 encode_compound_hdr(xdr, req, &hdr);
2420 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002421 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002422}
2423
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424/*
2425 * Encode a READLINK request
2426 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002427static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2428 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002431 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433
Chuck Lever9f06c712010-12-14 14:59:18 +00002434 encode_compound_hdr(xdr, req, &hdr);
2435 encode_sequence(xdr, &args->seq_args, &hdr);
2436 encode_putfh(xdr, args->fh, &hdr);
2437 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002438
Benny Halevy28f56692009-04-01 09:22:09 -04002439 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002440 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002441 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442}
2443
2444/*
2445 * Encode a READDIR request
2446 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002447static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2448 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002451 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453
Chuck Lever9f06c712010-12-14 14:59:18 +00002454 encode_compound_hdr(xdr, req, &hdr);
2455 encode_sequence(xdr, &args->seq_args, &hdr);
2456 encode_putfh(xdr, args->fh, &hdr);
2457 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002458
Benny Halevy28f56692009-04-01 09:22:09 -04002459 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002460 args->pgbase, args->count);
2461 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002462 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002463 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002464 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465}
2466
2467/*
2468 * Encode a READ request
2469 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002470static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2471 struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002474 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476
Chuck Lever9f06c712010-12-14 14:59:18 +00002477 encode_compound_hdr(xdr, req, &hdr);
2478 encode_sequence(xdr, &args->seq_args, &hdr);
2479 encode_putfh(xdr, args->fh, &hdr);
2480 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481
Benny Halevy28f56692009-04-01 09:22:09 -04002482 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002484 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002485 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486}
2487
2488/*
2489 * Encode an SETATTR request
2490 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002491static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2492 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493{
Andy Adamson05d564f2008-12-23 16:06:15 -05002494 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002496 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
Chuck Lever9f06c712010-12-14 14:59:18 +00002498 encode_compound_hdr(xdr, req, &hdr);
2499 encode_sequence(xdr, &args->seq_args, &hdr);
2500 encode_putfh(xdr, args->fh, &hdr);
2501 encode_setattr(xdr, args, args->server, &hdr);
2502 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002503 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504}
2505
2506/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002507 * Encode a GETACL request
2508 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002509static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2510 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002511{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002512 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002513 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002514 };
Benny Halevy28f56692009-04-01 09:22:09 -04002515 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002516
Chuck Lever9f06c712010-12-14 14:59:18 +00002517 encode_compound_hdr(xdr, req, &hdr);
2518 encode_sequence(xdr, &args->seq_args, &hdr);
2519 encode_putfh(xdr, args->fh, &hdr);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002520 replen = hdr.replen + op_decode_hdr_maxsz + 1;
Chuck Lever9f06c712010-12-14 14:59:18 +00002521 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002522
Benny Halevy28f56692009-04-01 09:22:09 -04002523 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
J. Bruce Fields029d1052005-06-22 17:16:22 +00002524 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002525 xdr_set_scratch_buffer(xdr, page_address(args->acl_scratch), PAGE_SIZE);
2526
Andy Adamsond0179312008-12-23 16:06:17 -05002527 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002528}
2529
2530/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 * Encode a WRITE request
2532 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002533static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2534 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002537 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
Chuck Lever9f06c712010-12-14 14:59:18 +00002540 encode_compound_hdr(xdr, req, &hdr);
2541 encode_sequence(xdr, &args->seq_args, &hdr);
2542 encode_putfh(xdr, args->fh, &hdr);
2543 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002544 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002545 if (args->bitmask)
2546 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002547 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548}
2549
2550/*
2551 * a COMMIT request
2552 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002553static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2554 struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002557 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
Chuck Lever9f06c712010-12-14 14:59:18 +00002560 encode_compound_hdr(xdr, req, &hdr);
2561 encode_sequence(xdr, &args->seq_args, &hdr);
2562 encode_putfh(xdr, args->fh, &hdr);
2563 encode_commit(xdr, args, &hdr);
Fred Isaman988b6dc2011-03-23 13:27:52 +00002564 if (args->bitmask)
2565 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002566 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567}
2568
2569/*
2570 * FSINFO request
2571 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002572static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2573 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002576 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578
Chuck Lever9f06c712010-12-14 14:59:18 +00002579 encode_compound_hdr(xdr, req, &hdr);
2580 encode_sequence(xdr, &args->seq_args, &hdr);
2581 encode_putfh(xdr, args->fh, &hdr);
2582 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002583 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584}
2585
2586/*
2587 * a PATHCONF request
2588 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002589static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2590 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002593 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Chuck Lever9f06c712010-12-14 14:59:18 +00002596 encode_compound_hdr(xdr, req, &hdr);
2597 encode_sequence(xdr, &args->seq_args, &hdr);
2598 encode_putfh(xdr, args->fh, &hdr);
2599 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002600 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002601 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602}
2603
2604/*
2605 * a STATFS request
2606 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002607static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2608 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002611 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613
Chuck Lever9f06c712010-12-14 14:59:18 +00002614 encode_compound_hdr(xdr, req, &hdr);
2615 encode_sequence(xdr, &args->seq_args, &hdr);
2616 encode_putfh(xdr, args->fh, &hdr);
2617 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002618 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002619 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620}
2621
2622/*
2623 * GETATTR_BITMAP request
2624 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002625static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2626 struct xdr_stream *xdr,
2627 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002630 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
Chuck Lever9f06c712010-12-14 14:59:18 +00002633 encode_compound_hdr(xdr, req, &hdr);
2634 encode_sequence(xdr, &args->seq_args, &hdr);
2635 encode_putfh(xdr, args->fhandle, &hdr);
2636 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002637 FATTR4_WORD0_LINK_SUPPORT|
2638 FATTR4_WORD0_SYMLINK_SUPPORT|
2639 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002640 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641}
2642
2643/*
2644 * a RENEW request
2645 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002646static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2647 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002650 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 };
2652
Chuck Lever9f06c712010-12-14 14:59:18 +00002653 encode_compound_hdr(xdr, req, &hdr);
2654 encode_renew(xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002655 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656}
2657
2658/*
2659 * a SETCLIENTID request
2660 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002661static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2662 struct xdr_stream *xdr,
2663 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002666 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 };
2668
Chuck Lever9f06c712010-12-14 14:59:18 +00002669 encode_compound_hdr(xdr, req, &hdr);
2670 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002671 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672}
2673
2674/*
2675 * a SETCLIENTID_CONFIRM request
2676 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002677static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2678 struct xdr_stream *xdr,
2679 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002682 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 };
Fred Isamandae100c2011-07-30 20:52:37 -04002684 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685
Chuck Lever9f06c712010-12-14 14:59:18 +00002686 encode_compound_hdr(xdr, req, &hdr);
2687 encode_setclientid_confirm(xdr, arg, &hdr);
2688 encode_putrootfh(xdr, &hdr);
2689 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002690 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691}
2692
2693/*
2694 * DELEGRETURN request
2695 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002696static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2697 struct xdr_stream *xdr,
2698 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002701 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703
Chuck Lever9f06c712010-12-14 14:59:18 +00002704 encode_compound_hdr(xdr, req, &hdr);
2705 encode_sequence(xdr, &args->seq_args, &hdr);
2706 encode_putfh(xdr, args->fhandle, &hdr);
2707 encode_delegreturn(xdr, args->stateid, &hdr);
2708 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002709 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710}
2711
2712/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002713 * Encode FS_LOCATIONS request
2714 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002715static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2716 struct xdr_stream *xdr,
2717 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002718{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002719 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002720 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002721 };
Benny Halevy28f56692009-04-01 09:22:09 -04002722 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002723
Chuck Lever9f06c712010-12-14 14:59:18 +00002724 encode_compound_hdr(xdr, req, &hdr);
2725 encode_sequence(xdr, &args->seq_args, &hdr);
2726 encode_putfh(xdr, args->dir_fh, &hdr);
2727 encode_lookup(xdr, args->name, &hdr);
Benny Halevy28f56692009-04-01 09:22:09 -04002728 replen = hdr.replen; /* get the attribute into args->page */
Chuck Lever9f06c712010-12-14 14:59:18 +00002729 encode_fs_locations(xdr, args->bitmask, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002730
Benny Halevy28f56692009-04-01 09:22:09 -04002731 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002732 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002733 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002734}
2735
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002736/*
2737 * Encode SECINFO request
2738 */
2739static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2740 struct xdr_stream *xdr,
2741 struct nfs4_secinfo_arg *args)
2742{
2743 struct compound_hdr hdr = {
2744 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2745 };
2746
2747 encode_compound_hdr(xdr, req, &hdr);
2748 encode_sequence(xdr, &args->seq_args, &hdr);
2749 encode_putfh(xdr, args->dir_fh, &hdr);
2750 encode_secinfo(xdr, args->name, &hdr);
2751 encode_nops(&hdr);
2752}
2753
Benny Halevy99fe60d2009-04-01 09:22:29 -04002754#if defined(CONFIG_NFS_V4_1)
2755/*
2756 * EXCHANGE_ID request
2757 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002758static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2759 struct xdr_stream *xdr,
2760 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002761{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002762 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002763 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002764 };
2765
Chuck Lever9f06c712010-12-14 14:59:18 +00002766 encode_compound_hdr(xdr, req, &hdr);
2767 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002768 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002769}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002770
2771/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002772 * a CREATE_SESSION request
2773 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002774static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2775 struct xdr_stream *xdr,
2776 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002777{
Andy Adamsonfc931582009-04-01 09:22:31 -04002778 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002779 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002780 };
2781
Chuck Lever9f06c712010-12-14 14:59:18 +00002782 encode_compound_hdr(xdr, req, &hdr);
2783 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002784 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002785}
2786
2787/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002788 * a DESTROY_SESSION request
2789 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002790static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2791 struct xdr_stream *xdr,
2792 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002793{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002794 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002795 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002796 };
2797
Chuck Lever9f06c712010-12-14 14:59:18 +00002798 encode_compound_hdr(xdr, req, &hdr);
2799 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002800 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002801}
2802
2803/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002804 * a SEQUENCE request
2805 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002806static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2807 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002808{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002809 struct compound_hdr hdr = {
2810 .minorversion = nfs4_xdr_minorversion(args),
2811 };
2812
Chuck Lever9f06c712010-12-14 14:59:18 +00002813 encode_compound_hdr(xdr, req, &hdr);
2814 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002815 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002816}
2817
2818/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002819 * a GET_LEASE_TIME request
2820 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002821static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2822 struct xdr_stream *xdr,
2823 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002824{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002825 struct compound_hdr hdr = {
2826 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2827 };
Fred Isamandae100c2011-07-30 20:52:37 -04002828 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002829
Chuck Lever9f06c712010-12-14 14:59:18 +00002830 encode_compound_hdr(xdr, req, &hdr);
2831 encode_sequence(xdr, &args->la_seq_args, &hdr);
2832 encode_putrootfh(xdr, &hdr);
2833 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002834 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002835}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002836
2837/*
2838 * a RECLAIM_COMPLETE request
2839 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002840static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2841 struct xdr_stream *xdr,
2842 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002843{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002844 struct compound_hdr hdr = {
2845 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2846 };
2847
Chuck Lever9f06c712010-12-14 14:59:18 +00002848 encode_compound_hdr(xdr, req, &hdr);
2849 encode_sequence(xdr, &args->seq_args, &hdr);
2850 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002851 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002852}
2853
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002854/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04002855 * Encode GETDEVICELIST request
2856 */
2857static void nfs4_xdr_enc_getdevicelist(struct rpc_rqst *req,
2858 struct xdr_stream *xdr,
2859 struct nfs4_getdevicelist_args *args)
2860{
2861 struct compound_hdr hdr = {
2862 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2863 };
2864
2865 encode_compound_hdr(xdr, req, &hdr);
2866 encode_sequence(xdr, &args->seq_args, &hdr);
2867 encode_putfh(xdr, args->fh, &hdr);
2868 encode_getdevicelist(xdr, args, &hdr);
2869 encode_nops(&hdr);
2870}
2871
2872/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002873 * Encode GETDEVICEINFO request
2874 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002875static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2876 struct xdr_stream *xdr,
2877 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002878{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002879 struct compound_hdr hdr = {
2880 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2881 };
2882
Chuck Lever9f06c712010-12-14 14:59:18 +00002883 encode_compound_hdr(xdr, req, &hdr);
2884 encode_sequence(xdr, &args->seq_args, &hdr);
2885 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002886
2887 /* set up reply kvec. Subtract notification bitmap max size (2)
2888 * so that notification bitmap is put in xdr_buf tail */
2889 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2890 args->pdev->pages, args->pdev->pgbase,
2891 args->pdev->pglen);
2892
2893 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002894}
2895
2896/*
2897 * Encode LAYOUTGET request
2898 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002899static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2900 struct xdr_stream *xdr,
2901 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002902{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002903 struct compound_hdr hdr = {
2904 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2905 };
2906
Chuck Lever9f06c712010-12-14 14:59:18 +00002907 encode_compound_hdr(xdr, req, &hdr);
2908 encode_sequence(xdr, &args->seq_args, &hdr);
2909 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2910 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002911
2912 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2913 args->layout.pages, 0, args->layout.pglen);
2914
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002915 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002916}
Andy Adamson863a3c62011-03-23 13:27:54 +00002917
2918/*
2919 * Encode LAYOUTCOMMIT request
2920 */
Benny Halevycbe82602011-05-22 19:52:37 +03002921static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2922 struct xdr_stream *xdr,
2923 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002924{
Benny Halevyac7db722011-05-22 19:53:48 +03002925 struct nfs4_layoutcommit_data *data =
2926 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002927 struct compound_hdr hdr = {
2928 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2929 };
2930
2931 encode_compound_hdr(xdr, req, &hdr);
2932 encode_sequence(xdr, &args->seq_args, &hdr);
2933 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002934 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002935 encode_getfattr(xdr, args->bitmask, &hdr);
2936 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002937}
2938
2939/*
2940 * Encode LAYOUTRETURN request
2941 */
2942static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2943 struct xdr_stream *xdr,
2944 struct nfs4_layoutreturn_args *args)
2945{
2946 struct compound_hdr hdr = {
2947 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2948 };
2949
2950 encode_compound_hdr(xdr, req, &hdr);
2951 encode_sequence(xdr, &args->seq_args, &hdr);
2952 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2953 encode_layoutreturn(xdr, args, &hdr);
2954 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002955}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002956
2957/*
2958 * Encode SECINFO_NO_NAME request
2959 */
2960static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2961 struct xdr_stream *xdr,
2962 struct nfs41_secinfo_no_name_args *args)
2963{
2964 struct compound_hdr hdr = {
2965 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2966 };
2967
2968 encode_compound_hdr(xdr, req, &hdr);
2969 encode_sequence(xdr, &args->seq_args, &hdr);
2970 encode_putrootfh(xdr, &hdr);
2971 encode_secinfo_no_name(xdr, args, &hdr);
2972 encode_nops(&hdr);
2973 return 0;
2974}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002975
2976/*
2977 * Encode TEST_STATEID request
2978 */
2979static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
2980 struct xdr_stream *xdr,
2981 struct nfs41_test_stateid_args *args)
2982{
2983 struct compound_hdr hdr = {
2984 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2985 };
2986
2987 encode_compound_hdr(xdr, req, &hdr);
2988 encode_sequence(xdr, &args->seq_args, &hdr);
2989 encode_test_stateid(xdr, args, &hdr);
2990 encode_nops(&hdr);
2991}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002992
2993/*
2994 * Encode FREE_STATEID request
2995 */
2996static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
2997 struct xdr_stream *xdr,
2998 struct nfs41_free_stateid_args *args)
2999{
3000 struct compound_hdr hdr = {
3001 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3002 };
3003
3004 encode_compound_hdr(xdr, req, &hdr);
3005 encode_sequence(xdr, &args->seq_args, &hdr);
3006 encode_free_stateid(xdr, args, &hdr);
3007 encode_nops(&hdr);
3008}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003009#endif /* CONFIG_NFS_V4_1 */
3010
Benny Halevy686841b2009-08-14 17:19:48 +03003011static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3012{
3013 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3014 "Remaining buffer length is %tu words.\n",
3015 func, xdr->end - xdr->p);
3016}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017
Trond Myklebust683b57b2006-06-09 09:34:22 -04003018static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019{
Al Viro8687b632006-10-19 23:28:48 -07003020 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021
Benny Halevyc0eae662009-08-14 17:20:14 +03003022 p = xdr_inline_decode(xdr, 4);
3023 if (unlikely(!p))
3024 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003025 *len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003026 p = xdr_inline_decode(xdr, *len);
3027 if (unlikely(!p))
3028 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 *string = (char *)p;
3030 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003031out_overflow:
3032 print_overflow_msg(__func__, xdr);
3033 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034}
3035
3036static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3037{
Al Viro8687b632006-10-19 23:28:48 -07003038 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039
Benny Halevyc0eae662009-08-14 17:20:14 +03003040 p = xdr_inline_decode(xdr, 8);
3041 if (unlikely(!p))
3042 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003043 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003044 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003045
Benny Halevyc0eae662009-08-14 17:20:14 +03003046 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3047 if (unlikely(!p))
3048 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 hdr->tag = (char *)p;
3050 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003051 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003052 if (unlikely(hdr->nops < 1))
3053 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003055out_overflow:
3056 print_overflow_msg(__func__, xdr);
3057 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058}
3059
3060static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3061{
Al Viro8687b632006-10-19 23:28:48 -07003062 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 uint32_t opnum;
3064 int32_t nfserr;
3065
Benny Halevyc0eae662009-08-14 17:20:14 +03003066 p = xdr_inline_decode(xdr, 8);
3067 if (unlikely(!p))
3068 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003069 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003071 dprintk("nfs: Server returned operation"
3072 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 opnum, expected);
3074 return -EIO;
3075 }
Benny Halevycccddf42009-08-14 17:20:19 +03003076 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03003078 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003080out_overflow:
3081 print_overflow_msg(__func__, xdr);
3082 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083}
3084
3085/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04003086static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087{
Al Viro8687b632006-10-19 23:28:48 -07003088 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003089 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 char *str;
3091
Benny Halevyc0eae662009-08-14 17:20:14 +03003092 p = xdr_inline_decode(xdr, 12);
3093 if (likely(p))
3094 return decode_opaque_inline(xdr, &strlen, &str);
3095 print_overflow_msg(__func__, xdr);
3096 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097}
3098
3099static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3100{
Al Viro8687b632006-10-19 23:28:48 -07003101 uint32_t bmlen;
3102 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103
Benny Halevyc0eae662009-08-14 17:20:14 +03003104 p = xdr_inline_decode(xdr, 4);
3105 if (unlikely(!p))
3106 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003107 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108
Fred Isamandae100c2011-07-30 20:52:37 -04003109 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003110 p = xdr_inline_decode(xdr, (bmlen << 2));
3111 if (unlikely(!p))
3112 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003114 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003115 if (bmlen > 1) {
3116 bitmap[1] = be32_to_cpup(p++);
3117 if (bmlen > 2)
3118 bitmap[2] = be32_to_cpup(p);
3119 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 }
3121 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003122out_overflow:
3123 print_overflow_msg(__func__, xdr);
3124 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125}
3126
Al Viro8687b632006-10-19 23:28:48 -07003127static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128{
Al Viro8687b632006-10-19 23:28:48 -07003129 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130
Benny Halevyc0eae662009-08-14 17:20:14 +03003131 p = xdr_inline_decode(xdr, 4);
3132 if (unlikely(!p))
3133 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003134 *attrlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 *savep = xdr->p;
3136 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003137out_overflow:
3138 print_overflow_msg(__func__, xdr);
3139 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140}
3141
3142static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3143{
3144 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003145 int ret;
3146 ret = decode_attr_bitmap(xdr, bitmask);
3147 if (unlikely(ret < 0))
3148 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3150 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003151 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3152 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3153 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 return 0;
3155}
3156
3157static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3158{
Al Viro8687b632006-10-19 23:28:48 -07003159 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003160 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161
3162 *type = 0;
3163 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3164 return -EIO;
3165 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003166 p = xdr_inline_decode(xdr, 4);
3167 if (unlikely(!p))
3168 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003169 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003171 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 return -EIO;
3173 }
3174 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003175 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003177 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003178 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003179out_overflow:
3180 print_overflow_msg(__func__, xdr);
3181 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182}
3183
3184static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3185{
Al Viro8687b632006-10-19 23:28:48 -07003186 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003187 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188
3189 *change = 0;
3190 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3191 return -EIO;
3192 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003193 p = xdr_inline_decode(xdr, 8);
3194 if (unlikely(!p))
3195 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003196 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003198 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003200 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003202 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003203out_overflow:
3204 print_overflow_msg(__func__, xdr);
3205 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206}
3207
3208static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3209{
Al Viro8687b632006-10-19 23:28:48 -07003210 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003211 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212
3213 *size = 0;
3214 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3215 return -EIO;
3216 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003217 p = xdr_inline_decode(xdr, 8);
3218 if (unlikely(!p))
3219 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003220 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003222 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003224 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003225 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003226out_overflow:
3227 print_overflow_msg(__func__, xdr);
3228 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229}
3230
3231static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3232{
Al Viro8687b632006-10-19 23:28:48 -07003233 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234
3235 *res = 0;
3236 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3237 return -EIO;
3238 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003239 p = xdr_inline_decode(xdr, 4);
3240 if (unlikely(!p))
3241 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003242 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3244 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003245 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003247out_overflow:
3248 print_overflow_msg(__func__, xdr);
3249 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250}
3251
3252static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3253{
Al Viro8687b632006-10-19 23:28:48 -07003254 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255
3256 *res = 0;
3257 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3258 return -EIO;
3259 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003260 p = xdr_inline_decode(xdr, 4);
3261 if (unlikely(!p))
3262 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003263 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3265 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003266 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003268out_overflow:
3269 print_overflow_msg(__func__, xdr);
3270 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271}
3272
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003273static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274{
Al Viro8687b632006-10-19 23:28:48 -07003275 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003276 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277
3278 fsid->major = 0;
3279 fsid->minor = 0;
3280 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3281 return -EIO;
3282 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003283 p = xdr_inline_decode(xdr, 16);
3284 if (unlikely(!p))
3285 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003286 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003287 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003289 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003291 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 (unsigned long long)fsid->major,
3293 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003294 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003295out_overflow:
3296 print_overflow_msg(__func__, xdr);
3297 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298}
3299
3300static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3301{
Al Viro8687b632006-10-19 23:28:48 -07003302 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303
3304 *res = 60;
3305 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3306 return -EIO;
3307 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003308 p = xdr_inline_decode(xdr, 4);
3309 if (unlikely(!p))
3310 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003311 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3313 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003314 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003316out_overflow:
3317 print_overflow_msg(__func__, xdr);
3318 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319}
3320
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003321static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003322{
3323 __be32 *p;
3324
3325 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3326 return -EIO;
3327 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3328 p = xdr_inline_decode(xdr, 4);
3329 if (unlikely(!p))
3330 goto out_overflow;
3331 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003332 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003333 }
3334 return 0;
3335out_overflow:
3336 print_overflow_msg(__func__, xdr);
3337 return -EIO;
3338}
3339
3340static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3341{
3342 __be32 *p;
3343 int len;
3344
Trond Myklebust7ad07352010-10-23 15:34:20 -04003345 if (fh != NULL)
3346 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003347
3348 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3349 return -EIO;
3350 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3351 p = xdr_inline_decode(xdr, 4);
3352 if (unlikely(!p))
3353 goto out_overflow;
3354 len = be32_to_cpup(p);
3355 if (len > NFS4_FHSIZE)
3356 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003357 p = xdr_inline_decode(xdr, len);
3358 if (unlikely(!p))
3359 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003360 if (fh != NULL) {
3361 memcpy(fh->data, p, len);
3362 fh->size = len;
3363 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003364 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3365 }
3366 return 0;
3367out_overflow:
3368 print_overflow_msg(__func__, xdr);
3369 return -EIO;
3370}
3371
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3373{
Al Viro8687b632006-10-19 23:28:48 -07003374 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375
3376 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
3377 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3378 return -EIO;
3379 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003380 p = xdr_inline_decode(xdr, 4);
3381 if (unlikely(!p))
3382 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003383 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3385 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003386 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003388out_overflow:
3389 print_overflow_msg(__func__, xdr);
3390 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391}
3392
3393static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3394{
Al Viro8687b632006-10-19 23:28:48 -07003395 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003396 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397
3398 *fileid = 0;
3399 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3400 return -EIO;
3401 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
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, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003407 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003409 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003410 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003411out_overflow:
3412 print_overflow_msg(__func__, xdr);
3413 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414}
3415
Manoj Naik99baf622006-06-09 09:34:24 -04003416static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3417{
Al Viro8687b632006-10-19 23:28:48 -07003418 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003419 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003420
3421 *fileid = 0;
3422 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3423 return -EIO;
3424 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003425 p = xdr_inline_decode(xdr, 8);
3426 if (unlikely(!p))
3427 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003428 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003429 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003430 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003431 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003432 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003433 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003434out_overflow:
3435 print_overflow_msg(__func__, xdr);
3436 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003437}
3438
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3440{
Al Viro8687b632006-10-19 23:28:48 -07003441 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 int status = 0;
3443
3444 *res = 0;
3445 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3446 return -EIO;
3447 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003448 p = xdr_inline_decode(xdr, 8);
3449 if (unlikely(!p))
3450 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003451 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3453 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003454 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003456out_overflow:
3457 print_overflow_msg(__func__, xdr);
3458 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459}
3460
3461static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3462{
Al Viro8687b632006-10-19 23:28:48 -07003463 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 int status = 0;
3465
3466 *res = 0;
3467 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3468 return -EIO;
3469 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003470 p = xdr_inline_decode(xdr, 8);
3471 if (unlikely(!p))
3472 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003473 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3475 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003476 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003478out_overflow:
3479 print_overflow_msg(__func__, xdr);
3480 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481}
3482
3483static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3484{
Al Viro8687b632006-10-19 23:28:48 -07003485 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 int status = 0;
3487
3488 *res = 0;
3489 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3490 return -EIO;
3491 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003492 p = xdr_inline_decode(xdr, 8);
3493 if (unlikely(!p))
3494 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003495 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3497 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003498 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003500out_overflow:
3501 print_overflow_msg(__func__, xdr);
3502 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503}
3504
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003505static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3506{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003507 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003508 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003509 int status = 0;
3510
Benny Halevyc0eae662009-08-14 17:20:14 +03003511 p = xdr_inline_decode(xdr, 4);
3512 if (unlikely(!p))
3513 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003514 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003515 if (n == 0)
3516 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003517 dprintk("path ");
3518 path->ncomponents = 0;
3519 while (path->ncomponents < n) {
3520 struct nfs4_string *component = &path->components[path->ncomponents];
3521 status = decode_opaque_inline(xdr, &component->len, &component->data);
3522 if (unlikely(status != 0))
3523 goto out_eio;
3524 if (path->ncomponents != n)
3525 dprintk("/");
3526 dprintk("%s", component->data);
3527 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3528 path->ncomponents++;
3529 else {
3530 dprintk("cannot parse %d components in path\n", n);
3531 goto out_eio;
3532 }
3533 }
3534out:
3535 dprintk("\n");
3536 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003537root_path:
3538/* a root pathname is sent as a zero component4 */
3539 path->ncomponents = 1;
3540 path->components[0].len=0;
3541 path->components[0].data=NULL;
3542 dprintk("path /\n");
3543 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003544out_eio:
3545 dprintk(" status %d", status);
3546 status = -EIO;
3547 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003548out_overflow:
3549 print_overflow_msg(__func__, xdr);
3550 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003551}
3552
3553static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003554{
3555 int n;
Al Viro8687b632006-10-19 23:28:48 -07003556 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003557 int status = -EIO;
3558
3559 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3560 goto out;
3561 status = 0;
3562 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3563 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003564 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003565 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003566 if (unlikely(status != 0))
3567 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003568 p = xdr_inline_decode(xdr, 4);
3569 if (unlikely(!p))
3570 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003571 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003572 if (n <= 0)
3573 goto out_eio;
3574 res->nlocations = 0;
3575 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003576 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003577 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04003578
Benny Halevyc0eae662009-08-14 17:20:14 +03003579 p = xdr_inline_decode(xdr, 4);
3580 if (unlikely(!p))
3581 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003582 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003583
3584 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07003585 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003586 while (loc->nservers < m) {
3587 struct nfs4_string *server = &loc->servers[loc->nservers];
3588 status = decode_opaque_inline(xdr, &server->len, &server->data);
3589 if (unlikely(status != 0))
3590 goto out_eio;
3591 dprintk("%s ", server->data);
3592 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
3593 loc->nservers++;
3594 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003595 unsigned int i;
3596 dprintk("%s: using first %u of %u servers "
3597 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003598 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003599 NFS4_FS_LOCATION_MAXSERVERS,
3600 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003601 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003602 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003603 char *data;
3604 status = decode_opaque_inline(xdr, &len, &data);
3605 if (unlikely(status != 0))
3606 goto out_eio;
3607 }
3608 }
3609 }
3610 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003611 if (unlikely(status != 0))
3612 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003613 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003614 res->nlocations++;
3615 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003616 if (res->nlocations != 0)
3617 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003618out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003619 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003620 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003621out_overflow:
3622 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003623out_eio:
3624 status = -EIO;
3625 goto out;
3626}
3627
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3629{
Al Viro8687b632006-10-19 23:28:48 -07003630 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 int status = 0;
3632
3633 *res = 0;
3634 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3635 return -EIO;
3636 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003637 p = xdr_inline_decode(xdr, 8);
3638 if (unlikely(!p))
3639 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003640 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3642 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003643 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003645out_overflow:
3646 print_overflow_msg(__func__, xdr);
3647 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648}
3649
3650static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3651{
Al Viro8687b632006-10-19 23:28:48 -07003652 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 int status = 0;
3654
3655 *maxlink = 1;
3656 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3657 return -EIO;
3658 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003659 p = xdr_inline_decode(xdr, 4);
3660 if (unlikely(!p))
3661 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003662 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3664 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003665 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003667out_overflow:
3668 print_overflow_msg(__func__, xdr);
3669 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670}
3671
3672static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3673{
Al Viro8687b632006-10-19 23:28:48 -07003674 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 int status = 0;
3676
3677 *maxname = 1024;
3678 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3679 return -EIO;
3680 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003681 p = xdr_inline_decode(xdr, 4);
3682 if (unlikely(!p))
3683 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003684 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3686 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003687 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003689out_overflow:
3690 print_overflow_msg(__func__, xdr);
3691 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692}
3693
3694static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3695{
Al Viro8687b632006-10-19 23:28:48 -07003696 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 int status = 0;
3698
3699 *res = 1024;
3700 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3701 return -EIO;
3702 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3703 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003704 p = xdr_inline_decode(xdr, 8);
3705 if (unlikely(!p))
3706 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003707 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 if (maxread > 0x7FFFFFFF)
3709 maxread = 0x7FFFFFFF;
3710 *res = (uint32_t)maxread;
3711 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3712 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003713 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003715out_overflow:
3716 print_overflow_msg(__func__, xdr);
3717 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718}
3719
3720static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3721{
Al Viro8687b632006-10-19 23:28:48 -07003722 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 int status = 0;
3724
3725 *res = 1024;
3726 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3727 return -EIO;
3728 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3729 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003730 p = xdr_inline_decode(xdr, 8);
3731 if (unlikely(!p))
3732 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003733 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 if (maxwrite > 0x7FFFFFFF)
3735 maxwrite = 0x7FFFFFFF;
3736 *res = (uint32_t)maxwrite;
3737 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3738 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003739 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003741out_overflow:
3742 print_overflow_msg(__func__, xdr);
3743 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744}
3745
Trond Myklebustbca79472009-03-11 14:10:26 -04003746static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747{
Trond Myklebustbca79472009-03-11 14:10:26 -04003748 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003749 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003750 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751
3752 *mode = 0;
3753 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3754 return -EIO;
3755 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003756 p = xdr_inline_decode(xdr, 4);
3757 if (unlikely(!p))
3758 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003759 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003760 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003762 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003764 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003765 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003766out_overflow:
3767 print_overflow_msg(__func__, xdr);
3768 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769}
3770
3771static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3772{
Al Viro8687b632006-10-19 23:28:48 -07003773 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003774 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775
3776 *nlink = 1;
3777 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3778 return -EIO;
3779 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003780 p = xdr_inline_decode(xdr, 4);
3781 if (unlikely(!p))
3782 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003783 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003785 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003787 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003788 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003789out_overflow:
3790 print_overflow_msg(__func__, xdr);
3791 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792}
3793
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003794static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003795 const struct nfs_server *server, uint32_t *uid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796{
Al Viro8687b632006-10-19 23:28:48 -07003797 uint32_t len;
3798 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003799 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800
3801 *uid = -2;
3802 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3803 return -EIO;
3804 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003805 p = xdr_inline_decode(xdr, 4);
3806 if (unlikely(!p))
3807 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003808 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003809 p = xdr_inline_decode(xdr, len);
3810 if (unlikely(!p))
3811 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003812 if (!may_sleep) {
3813 /* do nothing */
3814 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003815 if (nfs_map_name_to_uid(server, (char *)p, len, uid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003816 ret = NFS_ATTR_FATTR_OWNER;
3817 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003819 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003821 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003822 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3824 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003825 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003826 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003827out_overflow:
3828 print_overflow_msg(__func__, xdr);
3829 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830}
3831
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003832static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003833 const struct nfs_server *server, uint32_t *gid, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834{
Al Viro8687b632006-10-19 23:28:48 -07003835 uint32_t len;
3836 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003837 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838
3839 *gid = -2;
3840 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3841 return -EIO;
3842 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003843 p = xdr_inline_decode(xdr, 4);
3844 if (unlikely(!p))
3845 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003846 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03003847 p = xdr_inline_decode(xdr, len);
3848 if (unlikely(!p))
3849 goto out_overflow;
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003850 if (!may_sleep) {
3851 /* do nothing */
3852 } else if (len < XDR_MAX_NETOBJ) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08003853 if (nfs_map_group_to_gid(server, (char *)p, len, gid) == 0)
Trond Myklebust409924e2009-03-11 14:10:27 -04003854 ret = NFS_ATTR_FATTR_GROUP;
3855 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003857 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04003859 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003860 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3862 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003863 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003864 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003865out_overflow:
3866 print_overflow_msg(__func__, xdr);
3867 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868}
3869
3870static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3871{
Al Viro8687b632006-10-19 23:28:48 -07003872 uint32_t major = 0, minor = 0;
3873 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003874 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875
3876 *rdev = MKDEV(0,0);
3877 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3878 return -EIO;
3879 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3880 dev_t tmp;
3881
Benny Halevyc0eae662009-08-14 17:20:14 +03003882 p = xdr_inline_decode(xdr, 8);
3883 if (unlikely(!p))
3884 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003885 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003886 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 tmp = MKDEV(major, minor);
3888 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3889 *rdev = tmp;
3890 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003891 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003893 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003894 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003895out_overflow:
3896 print_overflow_msg(__func__, xdr);
3897 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898}
3899
3900static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3901{
Al Viro8687b632006-10-19 23:28:48 -07003902 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 int status = 0;
3904
3905 *res = 0;
3906 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3907 return -EIO;
3908 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003909 p = xdr_inline_decode(xdr, 8);
3910 if (unlikely(!p))
3911 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003912 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3914 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003915 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003917out_overflow:
3918 print_overflow_msg(__func__, xdr);
3919 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920}
3921
3922static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3923{
Al Viro8687b632006-10-19 23:28:48 -07003924 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 int status = 0;
3926
3927 *res = 0;
3928 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
3929 return -EIO;
3930 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003931 p = xdr_inline_decode(xdr, 8);
3932 if (unlikely(!p))
3933 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003934 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
3936 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003937 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003939out_overflow:
3940 print_overflow_msg(__func__, xdr);
3941 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942}
3943
3944static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3945{
Al Viro8687b632006-10-19 23:28:48 -07003946 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 int status = 0;
3948
3949 *res = 0;
3950 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
3951 return -EIO;
3952 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003953 p = xdr_inline_decode(xdr, 8);
3954 if (unlikely(!p))
3955 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003956 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
3958 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003959 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003961out_overflow:
3962 print_overflow_msg(__func__, xdr);
3963 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964}
3965
3966static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
3967{
Al Viro8687b632006-10-19 23:28:48 -07003968 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003969 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970
3971 *used = 0;
3972 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
3973 return -EIO;
3974 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003975 p = xdr_inline_decode(xdr, 8);
3976 if (unlikely(!p))
3977 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003978 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04003980 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003982 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04003984 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003985out_overflow:
3986 print_overflow_msg(__func__, xdr);
3987 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988}
3989
3990static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
3991{
Al Viro8687b632006-10-19 23:28:48 -07003992 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 uint64_t sec;
3994 uint32_t nsec;
3995
Benny Halevyc0eae662009-08-14 17:20:14 +03003996 p = xdr_inline_decode(xdr, 12);
3997 if (unlikely(!p))
3998 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003999 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004000 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 time->tv_sec = (time_t)sec;
4002 time->tv_nsec = (long)nsec;
4003 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004004out_overflow:
4005 print_overflow_msg(__func__, xdr);
4006 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007}
4008
4009static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4010{
4011 int status = 0;
4012
4013 time->tv_sec = 0;
4014 time->tv_nsec = 0;
4015 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4016 return -EIO;
4017 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4018 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004019 if (status == 0)
4020 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4022 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004023 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 return status;
4025}
4026
4027static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4028{
4029 int status = 0;
4030
4031 time->tv_sec = 0;
4032 time->tv_nsec = 0;
4033 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4034 return -EIO;
4035 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4036 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004037 if (status == 0)
4038 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4040 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004041 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 return status;
4043}
4044
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004045static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4046 struct timespec *time)
4047{
4048 int status = 0;
4049
4050 time->tv_sec = 0;
4051 time->tv_nsec = 0;
4052 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4053 return -EIO;
4054 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4055 status = decode_attr_time(xdr, time);
4056 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4057 }
4058 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4059 (long)time->tv_nsec);
4060 return status;
4061}
4062
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4064{
4065 int status = 0;
4066
4067 time->tv_sec = 0;
4068 time->tv_nsec = 0;
4069 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4070 return -EIO;
4071 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4072 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004073 if (status == 0)
4074 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4076 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004077 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078 return status;
4079}
4080
Al Viro8687b632006-10-19 23:28:48 -07004081static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082{
4083 unsigned int attrwords = XDR_QUADLEN(attrlen);
4084 unsigned int nwords = xdr->p - savep;
4085
4086 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004087 dprintk("%s: server returned incorrect attribute length: "
4088 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004089 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 attrwords << 2,
4091 (attrwords < nwords) ? '<' : '>',
4092 nwords << 2);
4093 return -EIO;
4094 }
4095 return 0;
4096}
4097
4098static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4099{
Al Viro8687b632006-10-19 23:28:48 -07004100 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101
Benny Halevyc0eae662009-08-14 17:20:14 +03004102 p = xdr_inline_decode(xdr, 20);
4103 if (unlikely(!p))
4104 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004105 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004106 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004107 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004109out_overflow:
4110 print_overflow_msg(__func__, xdr);
4111 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112}
4113
4114static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
4115{
Al Viro8687b632006-10-19 23:28:48 -07004116 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117 uint32_t supp, acc;
4118 int status;
4119
4120 status = decode_op_hdr(xdr, OP_ACCESS);
4121 if (status)
4122 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004123 p = xdr_inline_decode(xdr, 8);
4124 if (unlikely(!p))
4125 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004126 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004127 acc = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 access->supported = supp;
4129 access->access = acc;
4130 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004131out_overflow:
4132 print_overflow_msg(__func__, xdr);
4133 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134}
4135
Benny Halevy07d30432009-08-14 17:19:52 +03004136static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137{
Al Viro8687b632006-10-19 23:28:48 -07004138 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03004139
4140 p = xdr_inline_decode(xdr, len);
4141 if (likely(p)) {
4142 memcpy(buf, p, len);
4143 return 0;
4144 }
4145 print_overflow_msg(__func__, xdr);
4146 return -EIO;
4147}
4148
4149static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4150{
4151 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152}
4153
4154static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4155{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 int status;
4157
4158 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004159 if (status != -EIO)
4160 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004161 if (!status)
4162 status = decode_stateid(xdr, &res->stateid);
4163 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164}
4165
Benny Halevydb942bb2009-08-14 17:19:56 +03004166static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4167{
4168 return decode_opaque_fixed(xdr, verifier, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169}
4170
4171static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
4172{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 int status;
4174
4175 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004176 if (!status)
4177 status = decode_verifier(xdr, res->verf->verifier);
4178 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179}
4180
4181static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4182{
Al Viro8687b632006-10-19 23:28:48 -07004183 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 uint32_t bmlen;
4185 int status;
4186
4187 status = decode_op_hdr(xdr, OP_CREATE);
4188 if (status)
4189 return status;
4190 if ((status = decode_change_info(xdr, cinfo)))
4191 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004192 p = xdr_inline_decode(xdr, 4);
4193 if (unlikely(!p))
4194 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004195 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004196 p = xdr_inline_decode(xdr, bmlen << 2);
4197 if (likely(p))
4198 return 0;
4199out_overflow:
4200 print_overflow_msg(__func__, xdr);
4201 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202}
4203
4204static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4205{
Al Viro8687b632006-10-19 23:28:48 -07004206 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004207 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 int status;
4209
4210 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4211 goto xdr_error;
4212 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4213 goto xdr_error;
4214 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4215 goto xdr_error;
4216 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4217 goto xdr_error;
4218 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4219 goto xdr_error;
4220 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4221 goto xdr_error;
4222 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4223 goto xdr_error;
4224 status = verify_attr_len(xdr, savep, attrlen);
4225xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004226 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227 return status;
4228}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004229
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4231{
Al Viro8687b632006-10-19 23:28:48 -07004232 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004233 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004235
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4237 goto xdr_error;
4238 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4239 goto xdr_error;
4240 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4241 goto xdr_error;
4242
4243 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4244 goto xdr_error;
4245 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4246 goto xdr_error;
4247 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4248 goto xdr_error;
4249 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4250 goto xdr_error;
4251 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4252 goto xdr_error;
4253 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4254 goto xdr_error;
4255
4256 status = verify_attr_len(xdr, savep, attrlen);
4257xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004258 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259 return status;
4260}
4261
4262static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4263{
Al Viro8687b632006-10-19 23:28:48 -07004264 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004265 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004266 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004267
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4269 goto xdr_error;
4270 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4271 goto xdr_error;
4272 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4273 goto xdr_error;
4274
4275 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4276 goto xdr_error;
4277 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4278 goto xdr_error;
4279
4280 status = verify_attr_len(xdr, savep, attrlen);
4281xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004282 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 return status;
4284}
4285
Bryan Schumakerae42c702010-10-21 16:33:17 -04004286static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4287 struct nfs_fattr *fattr, struct nfs_fh *fh,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004288 const struct nfs_server *server, int may_sleep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289{
Trond Myklebustbca79472009-03-11 14:10:26 -04004290 int status;
4291 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004292 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004293 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004295 status = decode_attr_type(xdr, bitmap, &type);
4296 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004298 fattr->mode = 0;
4299 if (status != 0) {
4300 fattr->mode |= nfs_type2fmt[type];
4301 fattr->valid |= status;
4302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004304 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4305 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004307 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004308
4309 status = decode_attr_size(xdr, bitmap, &fattr->size);
4310 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004312 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004313
4314 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4315 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004317 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004318
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004319 err = 0;
4320 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004321 if (status < 0)
4322 goto xdr_error;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004323 if (err == -NFS4ERR_WRONGSEC)
4324 nfs_fixup_secinfo_attributes(fattr, fh);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004325
4326 status = decode_attr_filehandle(xdr, bitmap, fh);
4327 if (status < 0)
4328 goto xdr_error;
4329
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004330 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4331 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004333 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004334
4335 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04004336 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004337 fattr));
4338 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004339 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004340 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004341
4342 status = decode_attr_mode(xdr, bitmap, &fmode);
4343 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004345 if (status != 0) {
4346 fattr->mode |= fmode;
4347 fattr->valid |= status;
4348 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004349
4350 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4351 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004353 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004354
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004355 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004356 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004358 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004359
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08004360 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, may_sleep);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004361 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004362 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004363 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004364
4365 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4366 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004368 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004369
4370 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4371 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004373 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004374
4375 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4376 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004378 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004379
4380 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4381 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004383 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004384
4385 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4386 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004388 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004389
Trond Myklebust28331a42011-04-27 13:47:52 -04004390 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004391 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004392 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004393 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004394
Bryan Schumakerae42c702010-10-21 16:33:17 -04004395xdr_error:
4396 dprintk("%s: xdr returned %d\n", __func__, -status);
4397 return status;
4398}
4399
4400static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4401 struct nfs_fh *fh, const struct nfs_server *server, int may_sleep)
4402{
4403 __be32 *savep;
4404 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004405 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004406 int status;
4407
4408 status = decode_op_hdr(xdr, OP_GETATTR);
4409 if (status < 0)
4410 goto xdr_error;
4411
4412 status = decode_attr_bitmap(xdr, bitmap);
4413 if (status < 0)
4414 goto xdr_error;
4415
4416 status = decode_attr_length(xdr, &attrlen, &savep);
4417 if (status < 0)
4418 goto xdr_error;
4419
4420 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server, may_sleep);
4421 if (status < 0)
4422 goto xdr_error;
4423
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004424 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004426 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427 return status;
4428}
4429
Bryan Schumakerae42c702010-10-21 16:33:17 -04004430static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4431 const struct nfs_server *server, int may_sleep)
4432{
4433 return decode_getfattr_generic(xdr, fattr, NULL, server, may_sleep);
4434}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435
Andy Adamson504913f2010-10-20 00:17:57 -04004436/*
4437 * Decode potentially multiple layout types. Currently we only support
4438 * one layout driver per file system.
4439 */
4440static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4441 uint32_t *layouttype)
4442{
4443 uint32_t *p;
4444 int num;
4445
4446 p = xdr_inline_decode(xdr, 4);
4447 if (unlikely(!p))
4448 goto out_overflow;
4449 num = be32_to_cpup(p);
4450
4451 /* pNFS is not supported by the underlying file system */
4452 if (num == 0) {
4453 *layouttype = 0;
4454 return 0;
4455 }
4456 if (num > 1)
4457 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers "
4458 "per filesystem not supported\n", __func__);
4459
4460 /* Decode and set first layout type, move xdr->p past unused types */
4461 p = xdr_inline_decode(xdr, num * 4);
4462 if (unlikely(!p))
4463 goto out_overflow;
4464 *layouttype = be32_to_cpup(p);
4465 return 0;
4466out_overflow:
4467 print_overflow_msg(__func__, xdr);
4468 return -EIO;
4469}
4470
4471/*
4472 * The type of file system exported.
4473 * Note we must ensure that layouttype is set in any non-error case.
4474 */
4475static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4476 uint32_t *layouttype)
4477{
4478 int status = 0;
4479
4480 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4481 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4482 return -EIO;
4483 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4484 status = decode_first_pnfs_layout_type(xdr, layouttype);
4485 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
4486 } else
4487 *layouttype = 0;
4488 return status;
4489}
4490
Fred Isamandae100c2011-07-30 20:52:37 -04004491/*
4492 * The prefered block size for layout directed io
4493 */
4494static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4495 uint32_t *res)
4496{
4497 __be32 *p;
4498
4499 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4500 *res = 0;
4501 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4502 p = xdr_inline_decode(xdr, 4);
4503 if (unlikely(!p)) {
4504 print_overflow_msg(__func__, xdr);
4505 return -EIO;
4506 }
4507 *res = be32_to_cpup(p);
4508 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4509 }
4510 return 0;
4511}
4512
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4514{
Al Viro8687b632006-10-19 23:28:48 -07004515 __be32 *savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004516 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 int status;
4518
4519 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4520 goto xdr_error;
4521 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4522 goto xdr_error;
4523 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4524 goto xdr_error;
4525
4526 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4527
4528 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4529 goto xdr_error;
4530 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4531 goto xdr_error;
4532 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4533 goto xdr_error;
4534 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4535 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4536 goto xdr_error;
4537 fsinfo->wtpref = fsinfo->wtmax;
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004538 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4539 if (status != 0)
4540 goto xdr_error;
Andy Adamson504913f2010-10-20 00:17:57 -04004541 status = decode_attr_pnfstype(xdr, bitmap, &fsinfo->layouttype);
4542 if (status != 0)
4543 goto xdr_error;
Fred Isamandae100c2011-07-30 20:52:37 -04004544 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4545 if (status)
4546 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547
4548 status = verify_attr_len(xdr, savep, attrlen);
4549xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004550 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551 return status;
4552}
4553
4554static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4555{
Al Viro8687b632006-10-19 23:28:48 -07004556 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 uint32_t len;
4558 int status;
4559
Trond Myklebust99367812007-07-17 21:52:41 -04004560 /* Zero handle first to allow comparisons */
4561 memset(fh, 0, sizeof(*fh));
4562
Linus Torvalds1da177e2005-04-16 15:20:36 -07004563 status = decode_op_hdr(xdr, OP_GETFH);
4564 if (status)
4565 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566
Benny Halevyc0eae662009-08-14 17:20:14 +03004567 p = xdr_inline_decode(xdr, 4);
4568 if (unlikely(!p))
4569 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004570 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571 if (len > NFS4_FHSIZE)
4572 return -EIO;
4573 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004574 p = xdr_inline_decode(xdr, len);
4575 if (unlikely(!p))
4576 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004577 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004578 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004579out_overflow:
4580 print_overflow_msg(__func__, xdr);
4581 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582}
4583
4584static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4585{
4586 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004587
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588 status = decode_op_hdr(xdr, OP_LINK);
4589 if (status)
4590 return status;
4591 return decode_change_info(xdr, cinfo);
4592}
4593
4594/*
4595 * We create the owner, so we know a proper owner.id length is 4.
4596 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004597static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004599 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004600 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004601 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004603 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004604 if (unlikely(!p))
4605 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004606 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004607 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004608 type = be32_to_cpup(p++); /* 4 byte read */
4609 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004610 fl->fl_start = (loff_t)offset;
4611 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4612 if (length == ~(uint64_t)0)
4613 fl->fl_end = OFFSET_MAX;
4614 fl->fl_type = F_WRLCK;
4615 if (type & 1)
4616 fl->fl_type = F_RDLCK;
4617 fl->fl_pid = 0;
4618 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004619 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4620 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4621 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004622 if (likely(p))
4623 return -NFS4ERR_DENIED;
4624out_overflow:
4625 print_overflow_msg(__func__, xdr);
4626 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627}
4628
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004629static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 int status;
4632
4633 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004634 if (status == -EIO)
4635 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636 if (status == 0) {
Benny Halevy07d30432009-08-14 17:19:52 +03004637 status = decode_stateid(xdr, &res->stateid);
4638 if (unlikely(status))
4639 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004641 status = decode_lock_denied(xdr, NULL);
4642 if (res->open_seqid != NULL)
4643 nfs_increment_open_seqid(status, res->open_seqid);
4644 nfs_increment_lock_seqid(status, res->lock_seqid);
4645out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646 return status;
4647}
4648
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004649static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650{
4651 int status;
4652 status = decode_op_hdr(xdr, OP_LOCKT);
4653 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004654 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 return status;
4656}
4657
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004658static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 int status;
4661
4662 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004663 if (status != -EIO)
4664 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004665 if (status == 0)
4666 status = decode_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004667 return status;
4668}
4669
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04004670static int decode_release_lockowner(struct xdr_stream *xdr)
4671{
4672 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
4673}
4674
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675static int decode_lookup(struct xdr_stream *xdr)
4676{
4677 return decode_op_hdr(xdr, OP_LOOKUP);
4678}
4679
4680/* This is too sick! */
4681static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
4682{
Andy Adamson05d564f2008-12-23 16:06:15 -05004683 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 uint32_t limit_type, nblocks, blocksize;
4685
Benny Halevyc0eae662009-08-14 17:20:14 +03004686 p = xdr_inline_decode(xdr, 12);
4687 if (unlikely(!p))
4688 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004689 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004691 case 1:
Benny Halevycccddf42009-08-14 17:20:19 +03004692 xdr_decode_hyper(p, maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05004693 break;
4694 case 2:
Benny Halevy6f723f72009-08-14 17:19:37 +03004695 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004696 blocksize = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004697 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 }
4699 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004700out_overflow:
4701 print_overflow_msg(__func__, xdr);
4702 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703}
4704
4705static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
4706{
Andy Adamson05d564f2008-12-23 16:06:15 -05004707 __be32 *p;
4708 uint32_t delegation_type;
Benny Halevy07d30432009-08-14 17:19:52 +03004709 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004710
Benny Halevyc0eae662009-08-14 17:20:14 +03004711 p = xdr_inline_decode(xdr, 4);
4712 if (unlikely(!p))
4713 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004714 delegation_type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
4716 res->delegation_type = 0;
4717 return 0;
4718 }
Benny Halevy07d30432009-08-14 17:19:52 +03004719 status = decode_stateid(xdr, &res->delegation);
4720 if (unlikely(status))
4721 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004722 p = xdr_inline_decode(xdr, 4);
4723 if (unlikely(!p))
4724 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004725 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004726
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05004728 case NFS4_OPEN_DELEGATE_READ:
4729 res->delegation_type = FMODE_READ;
4730 break;
4731 case NFS4_OPEN_DELEGATE_WRITE:
4732 res->delegation_type = FMODE_WRITE|FMODE_READ;
4733 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734 return -EIO;
4735 }
David Howells7539bba2006-08-22 20:06:09 -04004736 return decode_ace(xdr, NULL, res->server->nfs_client);
Benny Halevyc0eae662009-08-14 17:20:14 +03004737out_overflow:
4738 print_overflow_msg(__func__, xdr);
4739 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740}
4741
4742static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
4743{
Andy Adamson05d564f2008-12-23 16:06:15 -05004744 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004745 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05004746 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747
Andy Adamson05d564f2008-12-23 16:06:15 -05004748 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004749 if (status != -EIO)
4750 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004751 if (!status)
4752 status = decode_stateid(xdr, &res->stateid);
4753 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05004754 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755
Andy Adamson05d564f2008-12-23 16:06:15 -05004756 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757
Benny Halevyc0eae662009-08-14 17:20:14 +03004758 p = xdr_inline_decode(xdr, 8);
4759 if (unlikely(!p))
4760 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004761 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004762 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05004763 if (bmlen > 10)
4764 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765
Benny Halevyc0eae662009-08-14 17:20:14 +03004766 p = xdr_inline_decode(xdr, bmlen << 2);
4767 if (unlikely(!p))
4768 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004769 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
4770 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03004771 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04004772 for (; i < NFS4_BITMAP_SIZE; i++)
4773 res->attrset[i] = 0;
4774
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775 return decode_delegation(xdr, res);
4776xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004777 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03004779out_overflow:
4780 print_overflow_msg(__func__, xdr);
4781 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782}
4783
4784static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
4785{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 int status;
4787
Andy Adamson05d564f2008-12-23 16:06:15 -05004788 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004789 if (status != -EIO)
4790 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004791 if (!status)
4792 status = decode_stateid(xdr, &res->stateid);
4793 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794}
4795
4796static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
4797{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 int status;
4799
4800 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004801 if (status != -EIO)
4802 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004803 if (!status)
4804 status = decode_stateid(xdr, &res->stateid);
4805 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004806}
4807
4808static int decode_putfh(struct xdr_stream *xdr)
4809{
4810 return decode_op_hdr(xdr, OP_PUTFH);
4811}
4812
4813static int decode_putrootfh(struct xdr_stream *xdr)
4814{
4815 return decode_op_hdr(xdr, OP_PUTROOTFH);
4816}
4817
4818static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
4819{
4820 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07004821 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822 uint32_t count, eof, recvd, hdrlen;
4823 int status;
4824
4825 status = decode_op_hdr(xdr, OP_READ);
4826 if (status)
4827 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004828 p = xdr_inline_decode(xdr, 8);
4829 if (unlikely(!p))
4830 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004831 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004832 count = be32_to_cpup(p);
Chuck Lever8111f372010-12-14 14:58:01 +00004833 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004834 recvd = req->rq_rcv_buf.len - hdrlen;
4835 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004836 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837 "count %u > recvd %u\n", count, recvd);
4838 count = recvd;
4839 eof = 0;
4840 }
4841 xdr_read_pages(xdr, count);
4842 res->eof = eof;
4843 res->count = count;
4844 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004845out_overflow:
4846 print_overflow_msg(__func__, xdr);
4847 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848}
4849
4850static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
4851{
4852 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004854 size_t hdrlen;
4855 u32 recvd, pglen = rcvbuf->page_len;
Chuck Leverbcecff72007-10-26 13:32:03 -04004856 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857
4858 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03004859 if (!status)
4860 status = decode_verifier(xdr, readdir->verifier.data);
4861 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862 return status;
Fred Isaman44109242008-04-02 15:21:15 +03004863 dprintk("%s: verifier = %08x:%08x\n",
4864 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00004865 ((u32 *)readdir->verifier.data)[0],
4866 ((u32 *)readdir->verifier.data)[1]);
4867
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868
Benny Halevydb942bb2009-08-14 17:19:56 +03004869 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004870 recvd = rcvbuf->len - hdrlen;
4871 if (pglen > recvd)
4872 pglen = recvd;
4873 xdr_read_pages(xdr, pglen);
4874
Jeff Layton7bda2cd2008-02-22 14:50:01 -05004875
Trond Myklebustac396122010-11-15 20:26:22 -05004876 return pglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004877}
4878
4879static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
4880{
4881 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
4882 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04004883 size_t hdrlen;
4884 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07004885 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886 int status;
4887
4888 status = decode_op_hdr(xdr, OP_READLINK);
4889 if (status)
4890 return status;
4891
4892 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03004893 p = xdr_inline_decode(xdr, 4);
4894 if (unlikely(!p))
4895 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004896 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004898 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899 return -ENAMETOOLONG;
4900 }
4901 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4902 recvd = req->rq_rcv_buf.len - hdrlen;
4903 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004904 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 "count %u > recvd %u\n", len, recvd);
4906 return -EIO;
4907 }
4908 xdr_read_pages(xdr, len);
4909 /*
4910 * The XDR encode routine has set things up so that
4911 * the link text will be copied directly into the
4912 * buffer. We just have to do overflow-checking,
4913 * and and null-terminate the text (the VFS expects
4914 * null-termination).
4915 */
Chuck Leverb4687da2010-09-21 16:55:48 -04004916 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004917 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004918out_overflow:
4919 print_overflow_msg(__func__, xdr);
4920 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921}
4922
4923static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4924{
4925 int status;
4926
4927 status = decode_op_hdr(xdr, OP_REMOVE);
4928 if (status)
4929 goto out;
4930 status = decode_change_info(xdr, cinfo);
4931out:
4932 return status;
4933}
4934
4935static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
4936 struct nfs4_change_info *new_cinfo)
4937{
4938 int status;
4939
4940 status = decode_op_hdr(xdr, OP_RENAME);
4941 if (status)
4942 goto out;
4943 if ((status = decode_change_info(xdr, old_cinfo)))
4944 goto out;
4945 status = decode_change_info(xdr, new_cinfo);
4946out:
4947 return status;
4948}
4949
4950static int decode_renew(struct xdr_stream *xdr)
4951{
4952 return decode_op_hdr(xdr, OP_RENEW);
4953}
4954
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004955static int
4956decode_restorefh(struct xdr_stream *xdr)
4957{
4958 return decode_op_hdr(xdr, OP_RESTOREFH);
4959}
4960
J. Bruce Fields029d1052005-06-22 17:16:22 +00004961static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05004962 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004963{
Andy Adamsonbf118a32011-12-07 11:55:27 -05004964 __be32 *savep, *bm_p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004965 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004966 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00004967 struct kvec *iov = req->rq_rcv_buf.head;
4968 int status;
4969
Andy Adamsonbf118a32011-12-07 11:55:27 -05004970 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004971 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4972 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004973 bm_p = xdr->p;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004974 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4975 goto out;
4976 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4977 goto out;
4978
4979 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
4980 return -EIO;
4981 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04004982 size_t hdrlen;
4983 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004984
Andy Adamsonbf118a32011-12-07 11:55:27 -05004985 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
4986 * are stored with the acl data to handle the problem of
4987 * variable length bitmaps.*/
4988 xdr->p = bm_p;
4989 res->acl_data_offset = be32_to_cpup(bm_p) + 2;
4990 res->acl_data_offset <<= 2;
4991
J. Bruce Fields029d1052005-06-22 17:16:22 +00004992 /* We ignore &savep and don't do consistency checks on
4993 * the attr length. Let userspace figure it out.... */
4994 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
Andy Adamsonbf118a32011-12-07 11:55:27 -05004995 attrlen += res->acl_data_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00004996 recvd = req->rq_rcv_buf.len - hdrlen;
4997 if (attrlen > recvd) {
Andy Adamsonbf118a32011-12-07 11:55:27 -05004998 if (res->acl_flags & NFS4_ACL_LEN_REQUEST) {
4999 /* getxattr interface called with a NULL buf */
5000 res->acl_len = attrlen;
5001 goto out;
5002 }
5003 dprintk("NFS: acl reply: attrlen %u > recvd %u\n",
J. Bruce Fields029d1052005-06-22 17:16:22 +00005004 attrlen, recvd);
5005 return -EINVAL;
5006 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04005007 xdr_read_pages(xdr, attrlen);
Andy Adamsonbf118a32011-12-07 11:55:27 -05005008 res->acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005009 } else
5010 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005011
5012out:
5013 return status;
5014}
5015
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016static int
5017decode_savefh(struct xdr_stream *xdr)
5018{
5019 return decode_op_hdr(xdr, OP_SAVEFH);
5020}
5021
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005022static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023{
Al Viro8687b632006-10-19 23:28:48 -07005024 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 uint32_t bmlen;
5026 int status;
5027
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028 status = decode_op_hdr(xdr, OP_SETATTR);
5029 if (status)
5030 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005031 p = xdr_inline_decode(xdr, 4);
5032 if (unlikely(!p))
5033 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005034 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005035 p = xdr_inline_decode(xdr, bmlen << 2);
5036 if (likely(p))
5037 return 0;
5038out_overflow:
5039 print_overflow_msg(__func__, xdr);
5040 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041}
5042
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005043static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044{
Al Viro8687b632006-10-19 23:28:48 -07005045 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 uint32_t opnum;
5047 int32_t nfserr;
5048
Benny Halevyc0eae662009-08-14 17:20:14 +03005049 p = xdr_inline_decode(xdr, 8);
5050 if (unlikely(!p))
5051 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005052 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005054 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005055 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056 return -EIO;
5057 }
Benny Halevycccddf42009-08-14 17:20:19 +03005058 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005059 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005060 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5061 if (unlikely(!p))
5062 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005063 p = xdr_decode_hyper(p, &res->clientid);
5064 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005065 } else if (nfserr == NFSERR_CLID_INUSE) {
5066 uint32_t len;
5067
5068 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005069 p = xdr_inline_decode(xdr, 4);
5070 if (unlikely(!p))
5071 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005072 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005073 p = xdr_inline_decode(xdr, len);
5074 if (unlikely(!p))
5075 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005076
5077 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005078 p = xdr_inline_decode(xdr, 4);
5079 if (unlikely(!p))
5080 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005081 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005082 p = xdr_inline_decode(xdr, len);
5083 if (unlikely(!p))
5084 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085 return -NFSERR_CLID_INUSE;
5086 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005087 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088
5089 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005090out_overflow:
5091 print_overflow_msg(__func__, xdr);
5092 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093}
5094
5095static int decode_setclientid_confirm(struct xdr_stream *xdr)
5096{
5097 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5098}
5099
5100static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5101{
Al Viro8687b632006-10-19 23:28:48 -07005102 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103 int status;
5104
5105 status = decode_op_hdr(xdr, OP_WRITE);
5106 if (status)
5107 return status;
5108
Benny Halevyc0eae662009-08-14 17:20:14 +03005109 p = xdr_inline_decode(xdr, 16);
5110 if (unlikely(!p))
5111 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005112 res->count = be32_to_cpup(p++);
5113 res->verf->committed = be32_to_cpup(p++);
Benny Halevy99398d02009-08-14 17:20:05 +03005114 memcpy(res->verf->verifier, p, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005116out_overflow:
5117 print_overflow_msg(__func__, xdr);
5118 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119}
5120
5121static int decode_delegreturn(struct xdr_stream *xdr)
5122{
5123 return decode_op_hdr(xdr, OP_DELEGRETURN);
5124}
5125
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005126static int decode_secinfo_gss(struct xdr_stream *xdr, struct nfs4_secinfo_flavor *flavor)
5127{
5128 __be32 *p;
5129
5130 p = xdr_inline_decode(xdr, 4);
5131 if (unlikely(!p))
5132 goto out_overflow;
5133 flavor->gss.sec_oid4.len = be32_to_cpup(p);
5134 if (flavor->gss.sec_oid4.len > GSS_OID_MAX_LEN)
5135 goto out_err;
5136
5137 p = xdr_inline_decode(xdr, flavor->gss.sec_oid4.len);
5138 if (unlikely(!p))
5139 goto out_overflow;
5140 memcpy(flavor->gss.sec_oid4.data, p, flavor->gss.sec_oid4.len);
5141
5142 p = xdr_inline_decode(xdr, 8);
5143 if (unlikely(!p))
5144 goto out_overflow;
5145 flavor->gss.qop4 = be32_to_cpup(p++);
5146 flavor->gss.service = be32_to_cpup(p);
5147
5148 return 0;
5149
5150out_overflow:
5151 print_overflow_msg(__func__, xdr);
5152 return -EIO;
5153out_err:
5154 return -EINVAL;
5155}
5156
5157static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5158{
5159 struct nfs4_secinfo_flavor *sec_flavor;
5160 int status;
5161 __be32 *p;
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005162 int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005163
5164 status = decode_op_hdr(xdr, OP_SECINFO);
Bryan Schumaker613e9012011-04-27 15:28:44 -04005165 if (status)
5166 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005167 p = xdr_inline_decode(xdr, 4);
5168 if (unlikely(!p))
5169 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005170
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005171 res->flavors->num_flavors = 0;
5172 num_flavors = be32_to_cpup(p);
5173
5174 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005175 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005176 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005177 break;
5178
5179 p = xdr_inline_decode(xdr, 4);
5180 if (unlikely(!p))
5181 goto out_overflow;
5182 sec_flavor->flavor = be32_to_cpup(p);
5183
5184 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005185 status = decode_secinfo_gss(xdr, sec_flavor);
5186 if (status)
5187 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005188 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005189 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005190 }
5191
Bryan Schumaker613e9012011-04-27 15:28:44 -04005192out:
5193 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005194out_overflow:
5195 print_overflow_msg(__func__, xdr);
5196 return -EIO;
5197}
5198
Benny Halevy99fe60d2009-04-01 09:22:29 -04005199#if defined(CONFIG_NFS_V4_1)
5200static int decode_exchange_id(struct xdr_stream *xdr,
5201 struct nfs41_exchange_id_res *res)
5202{
5203 __be32 *p;
5204 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005205 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005206 int status;
5207 struct nfs_client *clp = res->client;
5208
5209 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5210 if (status)
5211 return status;
5212
Benny Halevyc0eae662009-08-14 17:20:14 +03005213 p = xdr_inline_decode(xdr, 8);
5214 if (unlikely(!p))
5215 goto out_overflow;
Andy Adamson114f64b2011-03-09 13:13:45 -05005216 xdr_decode_hyper(p, &clp->cl_clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005217 p = xdr_inline_decode(xdr, 12);
5218 if (unlikely(!p))
5219 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005220 clp->cl_seqid = be32_to_cpup(p++);
5221 clp->cl_exchange_flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005222
5223 /* We ask for SP4_NONE */
Benny Halevycccddf42009-08-14 17:20:19 +03005224 dummy = be32_to_cpup(p);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005225 if (dummy != SP4_NONE)
5226 return -EIO;
5227
5228 /* Throw away minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005229 p = xdr_inline_decode(xdr, 8);
5230 if (unlikely(!p))
5231 goto out_overflow;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005232
5233 /* Throw away Major id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005234 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5235 if (unlikely(status))
5236 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005237
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005238 /* Save server_scope */
Benny Halevy2460ba52009-08-14 17:20:10 +03005239 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5240 if (unlikely(status))
5241 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005242
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005243 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5244 return -EIO;
5245
5246 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5247 res->server_scope->server_scope_sz = dummy;
5248
Benny Halevy99fe60d2009-04-01 09:22:29 -04005249 /* Throw away Implementation id array */
Benny Halevy2460ba52009-08-14 17:20:10 +03005250 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5251 if (unlikely(status))
5252 return status;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005253
5254 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005255out_overflow:
5256 print_overflow_msg(__func__, xdr);
5257 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005258}
Andy Adamsonfc931582009-04-01 09:22:31 -04005259
5260static int decode_chan_attrs(struct xdr_stream *xdr,
5261 struct nfs4_channel_attrs *attrs)
5262{
5263 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005264 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005265
Benny Halevyc0eae662009-08-14 17:20:14 +03005266 p = xdr_inline_decode(xdr, 28);
5267 if (unlikely(!p))
5268 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005269 val = be32_to_cpup(p++); /* headerpadsz */
5270 if (val)
5271 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005272 attrs->max_rqst_sz = be32_to_cpup(p++);
5273 attrs->max_resp_sz = be32_to_cpup(p++);
5274 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5275 attrs->max_ops = be32_to_cpup(p++);
5276 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005277 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005278 if (unlikely(nr_attrs > 1)) {
5279 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
5280 __func__, nr_attrs);
5281 return -EINVAL;
5282 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005283 if (nr_attrs == 1) {
5284 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5285 if (unlikely(!p))
5286 goto out_overflow;
5287 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005288 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005289out_overflow:
5290 print_overflow_msg(__func__, xdr);
5291 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005292}
5293
Benny Halevye78291e2009-08-14 17:20:00 +03005294static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5295{
5296 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005297}
5298
5299static int decode_create_session(struct xdr_stream *xdr,
5300 struct nfs41_create_session_res *res)
5301{
5302 __be32 *p;
5303 int status;
5304 struct nfs_client *clp = res->client;
5305 struct nfs4_session *session = clp->cl_session;
5306
5307 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005308 if (!status)
5309 status = decode_sessionid(xdr, &session->sess_id);
5310 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005311 return status;
5312
Andy Adamsonfc931582009-04-01 09:22:31 -04005313 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005314 p = xdr_inline_decode(xdr, 8);
5315 if (unlikely(!p))
5316 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005317 clp->cl_seqid = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005318 session->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005319
5320 /* Channel attributes */
5321 status = decode_chan_attrs(xdr, &session->fc_attrs);
5322 if (!status)
5323 status = decode_chan_attrs(xdr, &session->bc_attrs);
5324 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005325out_overflow:
5326 print_overflow_msg(__func__, xdr);
5327 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005328}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005329
5330static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5331{
5332 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5333}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005334
5335static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5336{
5337 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5338}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005339#endif /* CONFIG_NFS_V4_1 */
5340
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005341static int decode_sequence(struct xdr_stream *xdr,
5342 struct nfs4_sequence_res *res,
5343 struct rpc_rqst *rqstp)
5344{
5345#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005346 struct nfs4_sessionid id;
5347 u32 dummy;
5348 int status;
5349 __be32 *p;
5350
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005351 if (!res->sr_session)
5352 return 0;
5353
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005354 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005355 if (!status)
5356 status = decode_sessionid(xdr, &id);
5357 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005358 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005359
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005360 /*
5361 * If the server returns different values for sessionID, slotID or
5362 * sequence number, the server is looney tunes.
5363 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005364 status = -EREMOTEIO;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005365
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005366 if (memcmp(id.data, res->sr_session->sess_id.data,
5367 NFS4_MAX_SESSIONID_LEN)) {
5368 dprintk("%s Invalid session id\n", __func__);
5369 goto out_err;
5370 }
Benny Halevye78291e2009-08-14 17:20:00 +03005371
Benny Halevyc0eae662009-08-14 17:20:14 +03005372 p = xdr_inline_decode(xdr, 20);
5373 if (unlikely(!p))
5374 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005375
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005376 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005377 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005378 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005379 dprintk("%s Invalid sequence number\n", __func__);
5380 goto out_err;
5381 }
5382 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005383 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005384 if (dummy != res->sr_slot - res->sr_session->fc_slot_table.slots) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005385 dprintk("%s Invalid slot id\n", __func__);
5386 goto out_err;
5387 }
5388 /* highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005389 dummy = be32_to_cpup(p++);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005390 /* target highest slot id - currently not processed */
Benny Halevy6f723f72009-08-14 17:19:37 +03005391 dummy = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005392 /* result flags */
5393 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005394 status = 0;
5395out_err:
5396 res->sr_status = status;
5397 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005398out_overflow:
5399 print_overflow_msg(__func__, xdr);
5400 status = -EIO;
5401 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005402#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005403 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005404#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005405}
5406
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005407#if defined(CONFIG_NFS_V4_1)
Andy Adamson7f11d8d2011-07-30 20:52:35 -04005408/*
5409 * TODO: Need to handle case when EOF != true;
5410 */
5411static int decode_getdevicelist(struct xdr_stream *xdr,
5412 struct pnfs_devicelist *res)
5413{
5414 __be32 *p;
5415 int status, i;
5416 struct nfs_writeverf verftemp;
5417
5418 status = decode_op_hdr(xdr, OP_GETDEVICELIST);
5419 if (status)
5420 return status;
5421
5422 p = xdr_inline_decode(xdr, 8 + 8 + 4);
5423 if (unlikely(!p))
5424 goto out_overflow;
5425
5426 /* TODO: Skip cookie for now */
5427 p += 2;
5428
5429 /* Read verifier */
5430 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8);
5431
5432 res->num_devs = be32_to_cpup(p);
5433
5434 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5435
5436 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5437 printk(KERN_ERR "%s too many result dev_num %u\n",
5438 __func__, res->num_devs);
5439 return -EIO;
5440 }
5441
5442 p = xdr_inline_decode(xdr,
5443 res->num_devs * NFS4_DEVICEID4_SIZE + 4);
5444 if (unlikely(!p))
5445 goto out_overflow;
5446 for (i = 0; i < res->num_devs; i++)
5447 p = xdr_decode_opaque_fixed(p, res->dev_id[i].data,
5448 NFS4_DEVICEID4_SIZE);
5449 res->eof = be32_to_cpup(p);
5450 return 0;
5451out_overflow:
5452 print_overflow_msg(__func__, xdr);
5453 return -EIO;
5454}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005455
5456static int decode_getdeviceinfo(struct xdr_stream *xdr,
5457 struct pnfs_device *pdev)
5458{
5459 __be32 *p;
5460 uint32_t len, type;
5461 int status;
5462
5463 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5464 if (status) {
5465 if (status == -ETOOSMALL) {
5466 p = xdr_inline_decode(xdr, 4);
5467 if (unlikely(!p))
5468 goto out_overflow;
5469 pdev->mincount = be32_to_cpup(p);
5470 dprintk("%s: Min count too small. mincnt = %u\n",
5471 __func__, pdev->mincount);
5472 }
5473 return status;
5474 }
5475
5476 p = xdr_inline_decode(xdr, 8);
5477 if (unlikely(!p))
5478 goto out_overflow;
5479 type = be32_to_cpup(p++);
5480 if (type != pdev->layout_type) {
5481 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5482 __func__, pdev->layout_type, type);
5483 return -EINVAL;
5484 }
5485 /*
5486 * Get the length of the opaque device_addr4. xdr_read_pages places
5487 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5488 * and places the remaining xdr data in xdr_buf->tail
5489 */
5490 pdev->mincount = be32_to_cpup(p);
5491 xdr_read_pages(xdr, pdev->mincount); /* include space for the length */
5492
5493 /* Parse notification bitmap, verifying that it is zero. */
5494 p = xdr_inline_decode(xdr, 4);
5495 if (unlikely(!p))
5496 goto out_overflow;
5497 len = be32_to_cpup(p);
5498 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005499 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005500
5501 p = xdr_inline_decode(xdr, 4 * len);
5502 if (unlikely(!p))
5503 goto out_overflow;
5504 for (i = 0; i < len; i++, p++) {
5505 if (be32_to_cpup(p)) {
5506 dprintk("%s: notifications not supported\n",
5507 __func__);
5508 return -EIO;
5509 }
5510 }
5511 }
5512 return 0;
5513out_overflow:
5514 print_overflow_msg(__func__, xdr);
5515 return -EIO;
5516}
5517
5518static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5519 struct nfs4_layoutget_res *res)
5520{
5521 __be32 *p;
5522 int status;
5523 u32 layout_count;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005524 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5525 struct kvec *iov = rcvbuf->head;
5526 u32 hdrlen, recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005527
5528 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5529 if (status)
5530 return status;
5531 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
5532 if (unlikely(!p))
5533 goto out_overflow;
5534 res->return_on_close = be32_to_cpup(p++);
5535 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5536 layout_count = be32_to_cpup(p);
5537 if (!layout_count) {
5538 dprintk("%s: server responded with empty layout array\n",
5539 __func__);
5540 return -EINVAL;
5541 }
5542
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005543 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005544 if (unlikely(!p))
5545 goto out_overflow;
5546 p = xdr_decode_hyper(p, &res->range.offset);
5547 p = xdr_decode_hyper(p, &res->range.length);
5548 res->range.iomode = be32_to_cpup(p++);
5549 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005550 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005551
5552 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5553 __func__,
5554 (unsigned long)res->range.offset,
5555 (unsigned long)res->range.length,
5556 res->range.iomode,
5557 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005558 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005559
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005560 hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base;
5561 recvd = req->rq_rcv_buf.len - hdrlen;
5562 if (res->layoutp->len > recvd) {
5563 dprintk("NFS: server cheating in layoutget reply: "
5564 "layout len %u > recvd %u\n",
5565 res->layoutp->len, recvd);
5566 return -EINVAL;
5567 }
5568
5569 xdr_read_pages(xdr, res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005570
5571 if (layout_count > 1) {
5572 /* We only handle a length one array at the moment. Any
5573 * further entries are just ignored. Note that this means
5574 * the client may see a response that is less than the
5575 * minimum it requested.
5576 */
5577 dprintk("%s: server responded with %d layouts, dropping tail\n",
5578 __func__, layout_count);
5579 }
5580
5581 return 0;
5582out_overflow:
5583 print_overflow_msg(__func__, xdr);
5584 return -EIO;
5585}
Andy Adamson863a3c62011-03-23 13:27:54 +00005586
Benny Halevycbe82602011-05-22 19:52:37 +03005587static int decode_layoutreturn(struct xdr_stream *xdr,
5588 struct nfs4_layoutreturn_res *res)
5589{
5590 __be32 *p;
5591 int status;
5592
5593 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
5594 if (status)
5595 return status;
5596 p = xdr_inline_decode(xdr, 4);
5597 if (unlikely(!p))
5598 goto out_overflow;
5599 res->lrs_present = be32_to_cpup(p);
5600 if (res->lrs_present)
5601 status = decode_stateid(xdr, &res->stateid);
5602 return status;
5603out_overflow:
5604 print_overflow_msg(__func__, xdr);
5605 return -EIO;
5606}
5607
Andy Adamson863a3c62011-03-23 13:27:54 +00005608static int decode_layoutcommit(struct xdr_stream *xdr,
5609 struct rpc_rqst *req,
5610 struct nfs4_layoutcommit_res *res)
5611{
5612 __be32 *p;
5613 __u32 sizechanged;
5614 int status;
5615
5616 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04005617 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00005618 if (status)
5619 return status;
5620
5621 p = xdr_inline_decode(xdr, 4);
5622 if (unlikely(!p))
5623 goto out_overflow;
5624 sizechanged = be32_to_cpup(p);
5625
5626 if (sizechanged) {
5627 /* throw away new size */
5628 p = xdr_inline_decode(xdr, 8);
5629 if (unlikely(!p))
5630 goto out_overflow;
5631 }
5632 return 0;
5633out_overflow:
5634 print_overflow_msg(__func__, xdr);
5635 return -EIO;
5636}
Bryan Schumaker7d974792011-06-02 14:59:08 -04005637
5638static int decode_test_stateid(struct xdr_stream *xdr,
5639 struct nfs41_test_stateid_res *res)
5640{
5641 __be32 *p;
5642 int status;
5643 int num_res;
5644
5645 status = decode_op_hdr(xdr, OP_TEST_STATEID);
5646 if (status)
5647 return status;
5648
5649 p = xdr_inline_decode(xdr, 4);
5650 if (unlikely(!p))
5651 goto out_overflow;
5652 num_res = be32_to_cpup(p++);
5653 if (num_res != 1)
5654 goto out;
5655
5656 p = xdr_inline_decode(xdr, 4);
5657 if (unlikely(!p))
5658 goto out_overflow;
5659 res->status = be32_to_cpup(p++);
5660 return res->status;
5661out_overflow:
5662 print_overflow_msg(__func__, xdr);
5663out:
5664 return -EIO;
5665}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04005666
5667static int decode_free_stateid(struct xdr_stream *xdr,
5668 struct nfs41_free_stateid_res *res)
5669{
5670 __be32 *p;
5671 int status;
5672
5673 status = decode_op_hdr(xdr, OP_FREE_STATEID);
5674 if (status)
5675 return status;
5676
5677 p = xdr_inline_decode(xdr, 4);
5678 if (unlikely(!p))
5679 goto out_overflow;
5680 res->status = be32_to_cpup(p++);
5681 return res->status;
5682out_overflow:
5683 print_overflow_msg(__func__, xdr);
5684 return -EIO;
5685}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005686#endif /* CONFIG_NFS_V4_1 */
5687
Linus Torvalds1da177e2005-04-16 15:20:36 -07005688/*
Benny Halevy49c25592008-12-23 16:06:16 -05005689 * END OF "GENERIC" DECODE ROUTINES.
5690 */
5691
5692/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005693 * Decode OPEN_DOWNGRADE response
5694 */
Chuck Leverbf269552010-12-14 14:59:29 +00005695static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
5696 struct xdr_stream *xdr,
5697 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005698{
Andy Adamson05d564f2008-12-23 16:06:15 -05005699 struct compound_hdr hdr;
5700 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005701
Chuck Leverbf269552010-12-14 14:59:29 +00005702 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005703 if (status)
5704 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005705 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005706 if (status)
5707 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005708 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05005709 if (status)
5710 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005711 status = decode_open_downgrade(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04005712 if (status != 0)
5713 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005714 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005715 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005716out:
Andy Adamson05d564f2008-12-23 16:06:15 -05005717 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005718}
5719
5720/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005721 * Decode ACCESS response
5722 */
Chuck Leverbf269552010-12-14 14:59:29 +00005723static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5724 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005725{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005726 struct compound_hdr hdr;
5727 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005728
Chuck Leverbf269552010-12-14 14:59:29 +00005729 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005730 if (status)
5731 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005732 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005733 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005735 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04005736 if (status != 0)
5737 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005738 status = decode_access(xdr, res);
Trond Myklebust76b32992007-08-10 17:45:11 -04005739 if (status != 0)
5740 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005741 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005742 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005743out:
5744 return status;
5745}
5746
5747/*
5748 * Decode LOOKUP response
5749 */
Chuck Leverbf269552010-12-14 14:59:29 +00005750static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5751 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005752{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005753 struct compound_hdr hdr;
5754 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005755
Chuck Leverbf269552010-12-14 14:59:29 +00005756 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005757 if (status)
5758 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005759 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005760 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005761 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005762 status = decode_putfh(xdr);
5763 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005764 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005765 status = decode_lookup(xdr);
5766 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005768 status = decode_getfh(xdr, res->fh);
5769 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005770 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005771 status = decode_getfattr(xdr, res->fattr, res->server
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005772 ,!RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005773out:
5774 return status;
5775}
5776
5777/*
5778 * Decode LOOKUP_ROOT response
5779 */
Chuck Leverbf269552010-12-14 14:59:29 +00005780static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
5781 struct xdr_stream *xdr,
5782 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005783{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005784 struct compound_hdr hdr;
5785 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005786
Chuck Leverbf269552010-12-14 14:59:29 +00005787 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005788 if (status)
5789 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005790 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005791 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005792 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005793 status = decode_putrootfh(xdr);
5794 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005795 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005796 status = decode_getfh(xdr, res->fh);
5797 if (status == 0)
5798 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005799 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005800out:
5801 return status;
5802}
5803
5804/*
5805 * Decode REMOVE response
5806 */
Chuck Leverbf269552010-12-14 14:59:29 +00005807static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5808 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005810 struct compound_hdr hdr;
5811 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005812
Chuck Leverbf269552010-12-14 14:59:29 +00005813 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005814 if (status)
5815 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005816 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005817 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005818 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005819 status = decode_putfh(xdr);
5820 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005821 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005822 status = decode_remove(xdr, &res->cinfo);
5823 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04005824 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005825 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005826 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005827out:
5828 return status;
5829}
5830
5831/*
5832 * Decode RENAME response
5833 */
Chuck Leverbf269552010-12-14 14:59:29 +00005834static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5835 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005837 struct compound_hdr hdr;
5838 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005839
Chuck Leverbf269552010-12-14 14:59:29 +00005840 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005841 if (status)
5842 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005843 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005844 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005846 status = decode_putfh(xdr);
5847 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005848 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005849 status = decode_savefh(xdr);
5850 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005851 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005852 status = decode_putfh(xdr);
5853 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005855 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
5856 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005857 goto out;
5858 /* Current FH is target directory */
Chuck Leverbf269552010-12-14 14:59:29 +00005859 if (decode_getfattr(xdr, res->new_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005860 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005861 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005862 status = decode_restorefh(xdr);
5863 if (status)
Trond Myklebust6caf2c82005-10-27 22:12:43 -04005864 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005865 decode_getfattr(xdr, res->old_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005866 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867out:
5868 return status;
5869}
5870
5871/*
5872 * Decode LINK response
5873 */
Chuck Leverbf269552010-12-14 14:59:29 +00005874static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5875 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005876{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 struct compound_hdr hdr;
5878 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005879
Chuck Leverbf269552010-12-14 14:59:29 +00005880 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005881 if (status)
5882 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005883 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005884 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005885 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005886 status = decode_putfh(xdr);
5887 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005889 status = decode_savefh(xdr);
5890 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005891 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005892 status = decode_putfh(xdr);
5893 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005894 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005895 status = decode_link(xdr, &res->cinfo);
5896 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005897 goto out;
5898 /*
5899 * Note order: OP_LINK leaves the directory as the current
5900 * filehandle.
5901 */
Chuck Leverbf269552010-12-14 14:59:29 +00005902 if (decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005903 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005904 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005905 status = decode_restorefh(xdr);
5906 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04005907 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005908 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005909 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005910out:
5911 return status;
5912}
5913
5914/*
5915 * Decode CREATE response
5916 */
Chuck Leverbf269552010-12-14 14:59:29 +00005917static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5918 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005919{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005920 struct compound_hdr hdr;
5921 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005922
Chuck Leverbf269552010-12-14 14:59:29 +00005923 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005924 if (status)
5925 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005926 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005927 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005928 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005929 status = decode_putfh(xdr);
5930 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005932 status = decode_savefh(xdr);
5933 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005934 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005935 status = decode_create(xdr, &res->dir_cinfo);
5936 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005938 status = decode_getfh(xdr, res->fh);
5939 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005941 if (decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005942 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005943 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005944 status = decode_restorefh(xdr);
5945 if (status)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005946 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005947 decode_getfattr(xdr, res->dir_fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005948 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949out:
5950 return status;
5951}
5952
5953/*
5954 * Decode SYMLINK response
5955 */
Chuck Leverbf269552010-12-14 14:59:29 +00005956static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5957 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005958{
Chuck Leverbf269552010-12-14 14:59:29 +00005959 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005960}
5961
5962/*
5963 * Decode GETATTR response
5964 */
Chuck Leverbf269552010-12-14 14:59:29 +00005965static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
5966 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005968 struct compound_hdr hdr;
5969 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005970
Chuck Leverbf269552010-12-14 14:59:29 +00005971 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972 if (status)
5973 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005974 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005975 if (status)
5976 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005977 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005978 if (status)
5979 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00005980 status = decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04005981 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982out:
5983 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984}
5985
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005986/*
5987 * Encode an SETACL request
5988 */
Chuck Lever9f06c712010-12-14 14:59:18 +00005989static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
5990 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005991{
Andy Adamson05d564f2008-12-23 16:06:15 -05005992 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04005993 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05005994 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00005995
Chuck Lever9f06c712010-12-14 14:59:18 +00005996 encode_compound_hdr(xdr, req, &hdr);
5997 encode_sequence(xdr, &args->seq_args, &hdr);
5998 encode_putfh(xdr, args->fh, &hdr);
5999 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006000 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006001}
Andy Adamson05d564f2008-12-23 16:06:15 -05006002
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006003/*
6004 * Decode SETACL response
6005 */
6006static int
Chuck Leverbf269552010-12-14 14:59:29 +00006007nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006008 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006009{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006010 struct compound_hdr hdr;
6011 int status;
6012
Chuck Leverbf269552010-12-14 14:59:29 +00006013 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006014 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);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006020 if (status)
6021 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006022 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006023out:
6024 return status;
6025}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006026
6027/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006028 * Decode GETACL response
6029 */
6030static int
Chuck Leverbf269552010-12-14 14:59:29 +00006031nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006032 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006033{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006034 struct compound_hdr hdr;
6035 int status;
6036
Chuck Leverbf269552010-12-14 14:59:29 +00006037 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006038 if (status)
6039 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006040 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006041 if (status)
6042 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006043 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006044 if (status)
6045 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006046 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006047
6048out:
6049 return status;
6050}
6051
6052/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006053 * Decode CLOSE response
6054 */
Chuck Leverbf269552010-12-14 14:59:29 +00006055static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6056 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006057{
Andy Adamson05d564f2008-12-23 16:06:15 -05006058 struct compound_hdr hdr;
6059 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006060
Chuck Leverbf269552010-12-14 14:59:29 +00006061 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006062 if (status)
6063 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006064 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006065 if (status)
6066 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006067 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006068 if (status)
6069 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006070 status = decode_close(xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04006071 if (status != 0)
6072 goto out;
6073 /*
6074 * Note: Server may do delete on close for this file
6075 * in which case the getattr call will fail with
6076 * an ESTALE error. Shouldn't be a problem,
6077 * though, since fattr->valid will remain unset.
6078 */
Chuck Leverbf269552010-12-14 14:59:29 +00006079 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006080 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006082 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006083}
6084
6085/*
6086 * Decode OPEN response
6087 */
Chuck Leverbf269552010-12-14 14:59:29 +00006088static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6089 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090{
Andy Adamson05d564f2008-12-23 16:06:15 -05006091 struct compound_hdr hdr;
6092 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006093
Chuck Leverbf269552010-12-14 14:59:29 +00006094 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006095 if (status)
6096 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006097 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006098 if (status)
6099 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006100 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006101 if (status)
6102 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006103 status = decode_savefh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006104 if (status)
6105 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006106 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006107 if (status)
6108 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006109 if (decode_getfh(xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006110 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006111 if (decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006112 !RPC_IS_ASYNC(rqstp->rq_task)) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006113 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006114 if (decode_restorefh(xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006115 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006116 decode_getfattr(xdr, res->dir_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006117 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006119 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006120}
6121
6122/*
6123 * Decode OPEN_CONFIRM response
6124 */
Chuck Leverbf269552010-12-14 14:59:29 +00006125static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6126 struct xdr_stream *xdr,
6127 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128{
Andy Adamson05d564f2008-12-23 16:06:15 -05006129 struct compound_hdr hdr;
6130 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006131
Chuck Leverbf269552010-12-14 14:59:29 +00006132 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006133 if (status)
6134 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006135 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006136 if (status)
6137 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006138 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006139out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006140 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006141}
6142
6143/*
6144 * Decode OPEN response
6145 */
Chuck Leverbf269552010-12-14 14:59:29 +00006146static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6147 struct xdr_stream *xdr,
6148 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006149{
Andy Adamson05d564f2008-12-23 16:06:15 -05006150 struct compound_hdr hdr;
6151 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006152
Chuck Leverbf269552010-12-14 14:59:29 +00006153 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006154 if (status)
6155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006156 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006157 if (status)
6158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006159 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006160 if (status)
6161 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006162 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006163 if (status)
6164 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006165 decode_getfattr(xdr, res->f_attr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006166 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006168 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006169}
6170
6171/*
6172 * Decode SETATTR response
6173 */
Chuck Leverbf269552010-12-14 14:59:29 +00006174static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6175 struct xdr_stream *xdr,
6176 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006177{
Andy Adamson05d564f2008-12-23 16:06:15 -05006178 struct compound_hdr hdr;
6179 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180
Chuck Leverbf269552010-12-14 14:59:29 +00006181 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006182 if (status)
6183 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006184 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006185 if (status)
6186 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006187 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006188 if (status)
6189 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006190 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006191 if (status)
6192 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006193 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006194 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006196 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197}
6198
6199/*
6200 * Decode LOCK response
6201 */
Chuck Leverbf269552010-12-14 14:59:29 +00006202static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6203 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205 struct compound_hdr hdr;
6206 int status;
6207
Chuck Leverbf269552010-12-14 14:59:29 +00006208 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209 if (status)
6210 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006211 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006212 if (status)
6213 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006214 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006215 if (status)
6216 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006217 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218out:
6219 return status;
6220}
6221
6222/*
6223 * Decode LOCKT response
6224 */
Chuck Leverbf269552010-12-14 14:59:29 +00006225static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6226 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228 struct compound_hdr hdr;
6229 int status;
6230
Chuck Leverbf269552010-12-14 14:59:29 +00006231 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232 if (status)
6233 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006234 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006235 if (status)
6236 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006237 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238 if (status)
6239 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006240 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241out:
6242 return status;
6243}
6244
6245/*
6246 * Decode LOCKU response
6247 */
Chuck Leverbf269552010-12-14 14:59:29 +00006248static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6249 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251 struct compound_hdr hdr;
6252 int status;
6253
Chuck Leverbf269552010-12-14 14:59:29 +00006254 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006255 if (status)
6256 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006257 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006258 if (status)
6259 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006260 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261 if (status)
6262 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006263 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006264out:
6265 return status;
6266}
6267
Chuck Leverbf269552010-12-14 14:59:29 +00006268static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6269 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006270{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006271 struct compound_hdr hdr;
6272 int status;
6273
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006275 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006277 return status;
6278}
6279
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280/*
6281 * Decode READLINK response
6282 */
Chuck Leverbf269552010-12-14 14:59:29 +00006283static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6284 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006285 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006286{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006287 struct compound_hdr hdr;
6288 int status;
6289
Chuck Leverbf269552010-12-14 14:59:29 +00006290 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006291 if (status)
6292 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006293 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006294 if (status)
6295 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006296 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297 if (status)
6298 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006299 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006300out:
6301 return status;
6302}
6303
6304/*
6305 * Decode READDIR response
6306 */
Chuck Leverbf269552010-12-14 14:59:29 +00006307static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6308 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310 struct compound_hdr hdr;
6311 int status;
6312
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006314 if (status)
6315 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006316 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006317 if (status)
6318 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006320 if (status)
6321 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006322 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006323out:
6324 return status;
6325}
6326
6327/*
6328 * Decode Read response
6329 */
Chuck Leverbf269552010-12-14 14:59:29 +00006330static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6331 struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006333 struct compound_hdr hdr;
6334 int status;
6335
Chuck Leverbf269552010-12-14 14:59:29 +00006336 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337 if (status)
6338 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006339 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006340 if (status)
6341 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006342 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006343 if (status)
6344 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006345 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006346 if (!status)
6347 status = res->count;
6348out:
6349 return status;
6350}
6351
6352/*
6353 * Decode WRITE response
6354 */
Chuck Leverbf269552010-12-14 14:59:29 +00006355static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6356 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006358 struct compound_hdr hdr;
6359 int status;
6360
Chuck Leverbf269552010-12-14 14:59:29 +00006361 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 if (status)
6363 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006365 if (status)
6366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006368 if (status)
6369 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006371 if (status)
6372 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006373 if (res->fattr)
6374 decode_getfattr(xdr, res->fattr, res->server,
6375 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006376 if (!status)
6377 status = res->count;
6378out:
6379 return status;
6380}
6381
6382/*
6383 * Decode COMMIT response
6384 */
Chuck Leverbf269552010-12-14 14:59:29 +00006385static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6386 struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006387{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006388 struct compound_hdr hdr;
6389 int status;
6390
Chuck Leverbf269552010-12-14 14:59:29 +00006391 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392 if (status)
6393 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006394 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006395 if (status)
6396 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006397 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006398 if (status)
6399 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006400 status = decode_commit(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006401 if (status)
6402 goto out;
Fred Isaman988b6dc2011-03-23 13:27:52 +00006403 if (res->fattr)
6404 decode_getfattr(xdr, res->fattr, res->server,
6405 !RPC_IS_ASYNC(rqstp->rq_task));
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406out:
6407 return status;
6408}
6409
6410/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006411 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006412 */
Chuck Leverbf269552010-12-14 14:59:29 +00006413static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006414 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416 struct compound_hdr hdr;
6417 int status;
6418
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006421 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006422 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006423 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006424 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006425 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426 return status;
6427}
6428
6429/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006430 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 */
Chuck Leverbf269552010-12-14 14:59:29 +00006432static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006433 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006434{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435 struct compound_hdr hdr;
6436 int status;
6437
Chuck Leverbf269552010-12-14 14:59:29 +00006438 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006440 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006441 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006442 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006444 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006445 return status;
6446}
6447
6448/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006449 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450 */
Chuck Leverbf269552010-12-14 14:59:29 +00006451static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006452 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 struct compound_hdr hdr;
6455 int status;
6456
Chuck Leverbf269552010-12-14 14:59:29 +00006457 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006458 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006459 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006460 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006461 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006462 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006463 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464 return status;
6465}
6466
6467/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006468 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006469 */
Chuck Leverbf269552010-12-14 14:59:29 +00006470static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6471 struct xdr_stream *xdr,
6472 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006473{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006474 struct compound_hdr hdr;
6475 int status;
6476
Chuck Leverbf269552010-12-14 14:59:29 +00006477 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006478 if (status)
6479 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006480 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006481 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006482 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006483 status = decode_putfh(xdr);
6484 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006487out:
6488 return status;
6489}
6490
6491/*
6492 * Decode RENEW response
6493 */
Chuck Leverbf269552010-12-14 14:59:29 +00006494static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6495 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497 struct compound_hdr hdr;
6498 int status;
6499
Chuck Leverbf269552010-12-14 14:59:29 +00006500 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006501 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006502 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006503 return status;
6504}
6505
6506/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006507 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006508 */
Chuck Leverbf269552010-12-14 14:59:29 +00006509static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6510 struct xdr_stream *xdr,
6511 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006512{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006513 struct compound_hdr hdr;
6514 int status;
6515
Chuck Leverbf269552010-12-14 14:59:29 +00006516 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006517 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006518 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006519 return status;
6520}
6521
6522/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006523 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 */
Chuck Leverbf269552010-12-14 14:59:29 +00006525static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
6526 struct xdr_stream *xdr,
6527 struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006528{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529 struct compound_hdr hdr;
6530 int status;
6531
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006533 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006534 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006535 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006536 status = decode_putrootfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006537 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006538 status = decode_fsinfo(xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539 return status;
6540}
6541
6542/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006543 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006544 */
Chuck Leverbf269552010-12-14 14:59:29 +00006545static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6546 struct xdr_stream *xdr,
6547 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006549 struct compound_hdr hdr;
6550 int status;
6551
Chuck Leverbf269552010-12-14 14:59:29 +00006552 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006553 if (status)
6554 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006555 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006556 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006557 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006558 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006559 if (status != 0)
6560 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_delegreturn(xdr);
Jeff Layton556ae3b2010-03-21 12:10:36 -04006562 if (status != 0)
6563 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006564 decode_getfattr(xdr, res->fattr, res->server,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006565 !RPC_IS_ASYNC(rqstp->rq_task));
Trond Myklebustfa178f22006-01-03 09:55:38 +01006566out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006567 return status;
6568}
6569
Trond Myklebust683b57b2006-06-09 09:34:22 -04006570/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006571 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006572 */
Chuck Leverbf269552010-12-14 14:59:29 +00006573static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6574 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006575 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006576{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006577 struct compound_hdr hdr;
6578 int status;
6579
Chuck Leverbf269552010-12-14 14:59:29 +00006580 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006581 if (status)
6582 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006583 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006584 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006585 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006586 status = decode_putfh(xdr);
6587 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006588 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006589 status = decode_lookup(xdr);
6590 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006591 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006592 xdr_enter_page(xdr, PAGE_SIZE);
6593 status = decode_getfattr(xdr, &res->fs_locations->fattr,
Trond Myklebust80e52ac2009-08-09 15:06:19 -04006594 res->fs_locations->server,
6595 !RPC_IS_ASYNC(req->rq_task));
Trond Myklebust683b57b2006-06-09 09:34:22 -04006596out:
6597 return status;
6598}
6599
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006600/*
6601 * Decode SECINFO response
6602 */
6603static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6604 struct xdr_stream *xdr,
6605 struct nfs4_secinfo_res *res)
6606{
6607 struct compound_hdr hdr;
6608 int status;
6609
6610 status = decode_compound_hdr(xdr, &hdr);
6611 if (status)
6612 goto out;
6613 status = decode_sequence(xdr, &res->seq_res, rqstp);
6614 if (status)
6615 goto out;
6616 status = decode_putfh(xdr);
6617 if (status)
6618 goto out;
6619 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006620out:
6621 return status;
6622}
6623
Benny Halevy99fe60d2009-04-01 09:22:29 -04006624#if defined(CONFIG_NFS_V4_1)
6625/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006626 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04006627 */
Chuck Leverbf269552010-12-14 14:59:29 +00006628static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
6629 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04006630 void *res)
6631{
Benny Halevy99fe60d2009-04-01 09:22:29 -04006632 struct compound_hdr hdr;
6633 int status;
6634
Chuck Leverbf269552010-12-14 14:59:29 +00006635 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006636 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006637 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04006638 return status;
6639}
Andy Adamson2050f0c2009-04-01 09:22:30 -04006640
6641/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006642 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04006643 */
Chuck Leverbf269552010-12-14 14:59:29 +00006644static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
6645 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04006646 struct nfs41_create_session_res *res)
6647{
Andy Adamsonfc931582009-04-01 09:22:31 -04006648 struct compound_hdr hdr;
6649 int status;
6650
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04006652 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04006654 return status;
6655}
6656
6657/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006658 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006659 */
Chuck Leverbf269552010-12-14 14:59:29 +00006660static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
6661 struct xdr_stream *xdr,
6662 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006663{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006664 struct compound_hdr hdr;
6665 int status;
6666
Chuck Leverbf269552010-12-14 14:59:29 +00006667 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006668 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04006670 return status;
6671}
6672
6673/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006674 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006675 */
Chuck Leverbf269552010-12-14 14:59:29 +00006676static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
6677 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006678 struct nfs4_sequence_res *res)
6679{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006680 struct compound_hdr hdr;
6681 int status;
6682
Chuck Leverbf269552010-12-14 14:59:29 +00006683 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006684 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006685 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04006686 return status;
6687}
6688
6689/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006690 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04006691 */
Chuck Leverbf269552010-12-14 14:59:29 +00006692static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
6693 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04006694 struct nfs4_get_lease_time_res *res)
6695{
Andy Adamson2050f0c2009-04-01 09:22:30 -04006696 struct compound_hdr hdr;
6697 int status;
6698
Chuck Leverbf269552010-12-14 14:59:29 +00006699 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006700 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006702 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006703 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006704 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006705 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04006706 return status;
6707}
Ricardo Labiaga180197532009-12-05 16:08:40 -05006708
6709/*
6710 * Decode RECLAIM_COMPLETE response
6711 */
Chuck Leverbf269552010-12-14 14:59:29 +00006712static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
6713 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05006714 struct nfs41_reclaim_complete_res *res)
6715{
Ricardo Labiaga180197532009-12-05 16:08:40 -05006716 struct compound_hdr hdr;
6717 int status;
6718
Chuck Leverbf269552010-12-14 14:59:29 +00006719 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006720 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006721 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006722 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006723 status = decode_reclaim_complete(xdr, (void *)NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05006724 return status;
6725}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006726
6727/*
Andy Adamson7f11d8d2011-07-30 20:52:35 -04006728 * Decode GETDEVICELIST response
6729 */
6730static int nfs4_xdr_dec_getdevicelist(struct rpc_rqst *rqstp,
6731 struct xdr_stream *xdr,
6732 struct nfs4_getdevicelist_res *res)
6733{
6734 struct compound_hdr hdr;
6735 int status;
6736
6737 dprintk("encoding getdevicelist!\n");
6738
6739 status = decode_compound_hdr(xdr, &hdr);
6740 if (status != 0)
6741 goto out;
6742 status = decode_sequence(xdr, &res->seq_res, rqstp);
6743 if (status != 0)
6744 goto out;
6745 status = decode_putfh(xdr);
6746 if (status != 0)
6747 goto out;
6748 status = decode_getdevicelist(xdr, res->devlist);
6749out:
6750 return status;
6751}
6752
6753/*
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006754 * Decode GETDEVINFO response
6755 */
Chuck Leverbf269552010-12-14 14:59:29 +00006756static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
6757 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006758 struct nfs4_getdeviceinfo_res *res)
6759{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006760 struct compound_hdr hdr;
6761 int status;
6762
Chuck Leverbf269552010-12-14 14:59:29 +00006763 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006764 if (status != 0)
6765 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006766 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006767 if (status != 0)
6768 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006769 status = decode_getdeviceinfo(xdr, res->pdev);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006770out:
6771 return status;
6772}
6773
6774/*
6775 * Decode LAYOUTGET response
6776 */
Chuck Leverbf269552010-12-14 14:59:29 +00006777static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
6778 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006779 struct nfs4_layoutget_res *res)
6780{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006781 struct compound_hdr hdr;
6782 int status;
6783
Chuck Leverbf269552010-12-14 14:59:29 +00006784 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006785 if (status)
6786 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006788 if (status)
6789 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006790 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006791 if (status)
6792 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006793 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006794out:
6795 return status;
6796}
Andy Adamson863a3c62011-03-23 13:27:54 +00006797
6798/*
Benny Halevycbe82602011-05-22 19:52:37 +03006799 * Decode LAYOUTRETURN response
6800 */
6801static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
6802 struct xdr_stream *xdr,
6803 struct nfs4_layoutreturn_res *res)
6804{
6805 struct compound_hdr hdr;
6806 int status;
6807
6808 status = decode_compound_hdr(xdr, &hdr);
6809 if (status)
6810 goto out;
6811 status = decode_sequence(xdr, &res->seq_res, rqstp);
6812 if (status)
6813 goto out;
6814 status = decode_putfh(xdr);
6815 if (status)
6816 goto out;
6817 status = decode_layoutreturn(xdr, res);
6818out:
6819 return status;
6820}
6821
6822/*
Andy Adamson863a3c62011-03-23 13:27:54 +00006823 * Decode LAYOUTCOMMIT response
6824 */
6825static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
6826 struct xdr_stream *xdr,
6827 struct nfs4_layoutcommit_res *res)
6828{
6829 struct compound_hdr hdr;
6830 int status;
6831
6832 status = decode_compound_hdr(xdr, &hdr);
6833 if (status)
6834 goto out;
6835 status = decode_sequence(xdr, &res->seq_res, rqstp);
6836 if (status)
6837 goto out;
6838 status = decode_putfh(xdr);
6839 if (status)
6840 goto out;
6841 status = decode_layoutcommit(xdr, rqstp, res);
6842 if (status)
6843 goto out;
6844 decode_getfattr(xdr, res->fattr, res->server,
6845 !RPC_IS_ASYNC(rqstp->rq_task));
6846out:
6847 return status;
6848}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04006849
6850/*
6851 * Decode SECINFO_NO_NAME response
6852 */
6853static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
6854 struct xdr_stream *xdr,
6855 struct nfs4_secinfo_res *res)
6856{
6857 struct compound_hdr hdr;
6858 int status;
6859
6860 status = decode_compound_hdr(xdr, &hdr);
6861 if (status)
6862 goto out;
6863 status = decode_sequence(xdr, &res->seq_res, rqstp);
6864 if (status)
6865 goto out;
6866 status = decode_putrootfh(xdr);
6867 if (status)
6868 goto out;
6869 status = decode_secinfo(xdr, res);
6870out:
6871 return status;
6872}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006873
6874/*
6875 * Decode TEST_STATEID response
6876 */
6877static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
6878 struct xdr_stream *xdr,
6879 struct nfs41_test_stateid_res *res)
6880{
6881 struct compound_hdr hdr;
6882 int status;
6883
6884 status = decode_compound_hdr(xdr, &hdr);
6885 if (status)
6886 goto out;
6887 status = decode_sequence(xdr, &res->seq_res, rqstp);
6888 if (status)
6889 goto out;
6890 status = decode_test_stateid(xdr, res);
6891out:
6892 return status;
6893}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006894
6895/*
6896 * Decode FREE_STATEID response
6897 */
6898static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
6899 struct xdr_stream *xdr,
6900 struct nfs41_free_stateid_res *res)
6901{
6902 struct compound_hdr hdr;
6903 int status;
6904
6905 status = decode_compound_hdr(xdr, &hdr);
6906 if (status)
6907 goto out;
6908 status = decode_sequence(xdr, &res->seq_res, rqstp);
6909 if (status)
6910 goto out;
6911 status = decode_free_stateid(xdr, res);
6912out:
6913 return status;
6914}
Benny Halevy99fe60d2009-04-01 09:22:29 -04006915#endif /* CONFIG_NFS_V4_1 */
6916
Chuck Lever573c4e12010-12-14 14:58:11 +00006917/**
6918 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
6919 * the local page cache.
6920 * @xdr: XDR stream where entry resides
6921 * @entry: buffer to fill in with entry data
6922 * @plus: boolean indicating whether this should be a readdirplus entry
6923 *
6924 * Returns zero if successful, otherwise a negative errno value is
6925 * returned.
6926 *
6927 * This function is not invoked during READDIR reply decoding, but
6928 * rather whenever an application invokes the getdents(2) system call
6929 * on a directory already in our cache.
6930 */
6931int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6932 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006933{
Fred Isamandae100c2011-07-30 20:52:37 -04006934 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07006935 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006936 __be32 *p = xdr_inline_decode(xdr, 4);
6937 if (unlikely(!p))
6938 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006939 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006940 p = xdr_inline_decode(xdr, 4);
6941 if (unlikely(!p))
6942 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05006943 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00006944 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006945 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00006946 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006947 }
6948
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006949 p = xdr_inline_decode(xdr, 12);
6950 if (unlikely(!p))
6951 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006952 entry->prev_cookie = entry->cookie;
6953 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05006954 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006955
Trond Myklebust9af8c222010-10-24 11:52:55 -04006956 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006957 if (unlikely(!p))
6958 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006959 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006960
6961 /*
6962 * In case the server doesn't return an inode number,
6963 * we fake one here. (We don't use inode number 0,
6964 * since glibc seems to choke on it...)
6965 */
6966 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04006967 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006968
Trond Myklebust9af8c222010-10-24 11:52:55 -04006969 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006970 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04006971
6972 if (decode_attr_length(xdr, &len, &p) < 0)
6973 goto out_overflow;
6974
Chuck Lever573c4e12010-12-14 14:58:11 +00006975 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6976 entry->server, 1) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006977 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04006978 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6979 entry->ino = entry->fattr->mounted_on_fileid;
6980 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04006981 entry->ino = entry->fattr->fileid;
6982
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05006983 entry->d_type = DT_UNKNOWN;
6984 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
6985 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
6986
Chuck Lever573c4e12010-12-14 14:58:11 +00006987 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04006988
6989out_overflow:
6990 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00006991 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006992}
6993
6994/*
6995 * We need to translate between nfs status return values and
6996 * the local errno values which may not be the same.
6997 */
6998static struct {
6999 int stat;
7000 int errno;
7001} nfs_errtbl[] = {
7002 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007003 { NFS4ERR_PERM, -EPERM },
7004 { NFS4ERR_NOENT, -ENOENT },
7005 { NFS4ERR_IO, -errno_NFSERR_IO},
7006 { NFS4ERR_NXIO, -ENXIO },
7007 { NFS4ERR_ACCESS, -EACCES },
7008 { NFS4ERR_EXIST, -EEXIST },
7009 { NFS4ERR_XDEV, -EXDEV },
7010 { NFS4ERR_NOTDIR, -ENOTDIR },
7011 { NFS4ERR_ISDIR, -EISDIR },
7012 { NFS4ERR_INVAL, -EINVAL },
7013 { NFS4ERR_FBIG, -EFBIG },
7014 { NFS4ERR_NOSPC, -ENOSPC },
7015 { NFS4ERR_ROFS, -EROFS },
7016 { NFS4ERR_MLINK, -EMLINK },
7017 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7018 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7019 { NFS4ERR_DQUOT, -EDQUOT },
7020 { NFS4ERR_STALE, -ESTALE },
7021 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007022 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7023 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7024 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007025 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007026 { NFS4ERR_BADTYPE, -EBADTYPE },
7027 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007028 { NFS4ERR_SYMLINK, -ELOOP },
7029 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7030 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007031 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007032};
7033
7034/*
7035 * Convert an NFS error code to a local one.
7036 * This one is used jointly by NFSv2 and NFSv3.
7037 */
7038static int
David Howells0a8ea432006-08-22 20:06:08 -04007039nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007040{
7041 int i;
7042 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7043 if (nfs_errtbl[i].stat == stat)
7044 return nfs_errtbl[i].errno;
7045 }
7046 if (stat <= 10000 || stat > 10100) {
7047 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007048 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007049 }
7050 /* If we cannot translate the error, the recovery routines should
7051 * handle it.
7052 * Note: remaining NFSv4 error codes have values > 10000, so should
7053 * not conflict with native Linux error codes.
7054 */
Benny Halevy856dff32008-03-31 17:39:06 +03007055 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007056}
7057
Linus Torvalds1da177e2005-04-16 15:20:36 -07007058#define PROC(proc, argtype, restype) \
7059[NFSPROC4_CLNT_##proc] = { \
7060 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007061 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007062 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007063 .p_arglen = NFS4_##argtype##_sz, \
7064 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007065 .p_statidx = NFSPROC4_CLNT_##proc, \
7066 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007067}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007068
7069struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007070 PROC(READ, enc_read, dec_read),
7071 PROC(WRITE, enc_write, dec_write),
7072 PROC(COMMIT, enc_commit, dec_commit),
7073 PROC(OPEN, enc_open, dec_open),
7074 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7075 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7076 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7077 PROC(CLOSE, enc_close, dec_close),
7078 PROC(SETATTR, enc_setattr, dec_setattr),
7079 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7080 PROC(RENEW, enc_renew, dec_renew),
7081 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7082 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7083 PROC(LOCK, enc_lock, dec_lock),
7084 PROC(LOCKT, enc_lockt, dec_lockt),
7085 PROC(LOCKU, enc_locku, dec_locku),
7086 PROC(ACCESS, enc_access, dec_access),
7087 PROC(GETATTR, enc_getattr, dec_getattr),
7088 PROC(LOOKUP, enc_lookup, dec_lookup),
7089 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7090 PROC(REMOVE, enc_remove, dec_remove),
7091 PROC(RENAME, enc_rename, dec_rename),
7092 PROC(LINK, enc_link, dec_link),
7093 PROC(SYMLINK, enc_symlink, dec_symlink),
7094 PROC(CREATE, enc_create, dec_create),
7095 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7096 PROC(STATFS, enc_statfs, dec_statfs),
7097 PROC(READLINK, enc_readlink, dec_readlink),
7098 PROC(READDIR, enc_readdir, dec_readdir),
7099 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7100 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7101 PROC(GETACL, enc_getacl, dec_getacl),
7102 PROC(SETACL, enc_setacl, dec_setacl),
7103 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7104 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007105 PROC(SECINFO, enc_secinfo, dec_secinfo),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007106#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007107 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7108 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7109 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7110 PROC(SEQUENCE, enc_sequence, dec_sequence),
7111 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7112 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7113 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7114 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007115 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007116 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007117 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007118 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007119 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Andy Adamson7f11d8d2011-07-30 20:52:35 -04007120 PROC(GETDEVICELIST, enc_getdevicelist, dec_getdevicelist),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007121#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007122};
7123
7124struct rpc_version nfs_version4 = {
7125 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007126 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007127 .procs = nfs4_procedures
7128};
7129
7130/*
7131 * Local variables:
7132 * c-basic-offset: 8
7133 * End:
7134 */