blob: aa350d5bf2070f8e8bea47a36154734545664f74 [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>
41#include <linux/slab.h>
42#include <linux/utsname.h>
43#include <linux/errno.h>
44#include <linux/string.h>
45#include <linux/in.h>
46#include <linux/pagemap.h>
47#include <linux/proc_fs.h>
48#include <linux/kdev_t.h>
49#include <linux/sunrpc/clnt.h>
50#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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#define NFSDBG_FACILITY NFSDBG_XDR
57
58/* Mapping from NFS error code to "errno" error code. */
59#define errno_NFSERR_IO EIO
60
David Howells0a8ea432006-08-22 20:06:08 -040061static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
64#ifdef DEBUG
65#define NFS4_MAXTAGLEN 20
66#else
67#define NFS4_MAXTAGLEN 0
68#endif
69
Andy Adamson6c0195a2008-12-23 16:06:15 -050070/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040071 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 */
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073#define open_owner_id_maxsz (1 + 4)
74#define lock_owner_id_maxsz (1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040075#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78#define op_encode_hdr_maxsz (1)
79#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040080#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
85 (NFS4_FHSIZE >> 2))
86#define decode_putfh_maxsz (op_decode_hdr_maxsz)
87#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89#define encode_getfh_maxsz (op_encode_hdr_maxsz)
90#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000092#define nfs4_fattr_bitmap_maxsz 3
93#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040096#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +000098/* This is based on getfattr, which uses the most attributes: */
99#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000101#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400104#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
105 1 + 2 + 1 + \
106 nfs4_owner_maxsz + \
107 nfs4_group_maxsz + \
108 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define encode_savefh_maxsz (op_encode_hdr_maxsz)
110#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400111#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200113#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116#define decode_renew_maxsz (op_decode_hdr_maxsz)
117#define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
121 1 /* sc_prog */ + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
124 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
127 2 + \
128 1024) /* large value for CLID_INUSE */
129#define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132#define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400134#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400136#define encode_share_access_maxsz \
137 (2)
Trond Myklebust9104a552007-07-17 21:52:42 -0400138#define encode_createmode_maxsz (1 + encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400139#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141#define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400147#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400148 decode_ace_maxsz)
149#define decode_change_info_maxsz (5)
150#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400151 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158#define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161#define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165#define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168#define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170#define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
174 encode_attrs_maxsz)
175#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177#define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184#define encode_readlink_maxsz (op_encode_hdr_maxsz)
185#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186#define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188#define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191#define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193#define encode_remove_maxsz (op_encode_hdr_maxsz + \
194 nfs4_name_maxsz)
195#define encode_rename_maxsz (op_encode_hdr_maxsz + \
196 2 * nfs4_name_maxsz)
197#define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
198#define encode_link_maxsz (op_encode_hdr_maxsz + \
199 nfs4_name_maxsz)
200#define decode_link_maxsz (op_decode_hdr_maxsz + 5)
Trond Myklebust9104a552007-07-17 21:52:42 -0400201#define encode_lock_maxsz (op_encode_hdr_maxsz + \
202 7 + \
203 1 + encode_stateid_maxsz + 8)
204#define decode_lock_denied_maxsz \
205 (8 + decode_lockowner_maxsz)
206#define decode_lock_maxsz (op_decode_hdr_maxsz + \
207 decode_lock_denied_maxsz)
208#define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
209#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
210 decode_lock_denied_maxsz)
211#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
212 encode_stateid_maxsz + \
213 4)
214#define decode_locku_maxsz (op_decode_hdr_maxsz + \
215 decode_stateid_maxsz)
216#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
217#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
219 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400220 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000221 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
223#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400224 1 + 2 + nfs4_name_maxsz + \
225 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400226#define decode_create_maxsz (op_decode_hdr_maxsz + \
227 decode_change_info_maxsz + \
228 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400229#define encode_statfs_maxsz (encode_getattr_maxsz)
230#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
232#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400233#define encode_getacl_maxsz (encode_getattr_maxsz)
234#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
235 nfs4_fattr_bitmap_maxsz + 1)
236#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
237 encode_stateid_maxsz + 3)
238#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400239#define encode_fs_locations_maxsz \
240 (encode_getattr_maxsz)
241#define decode_fs_locations_maxsz \
242 (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
244#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
245#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
246 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400247 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
249 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400250 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
252 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400253 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
255 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400256 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
258 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400259 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
261 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400262 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
264 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400265 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400266 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
268 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400269 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400270 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
272 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400273 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400274 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
276 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400277 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400278 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400280 encode_putfh_maxsz + \
281 encode_savefh_maxsz + \
282 encode_open_maxsz + \
283 encode_getfh_maxsz + \
284 encode_getattr_maxsz + \
285 encode_restorefh_maxsz + \
286 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400288 decode_putfh_maxsz + \
289 decode_savefh_maxsz + \
290 decode_open_maxsz + \
291 decode_getfh_maxsz + \
292 decode_getattr_maxsz + \
293 decode_restorefh_maxsz + \
294 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400295#define NFS4_enc_open_confirm_sz \
296 (compound_encode_hdr_maxsz + \
297 encode_putfh_maxsz + \
298 encode_open_confirm_maxsz)
299#define NFS4_dec_open_confirm_sz \
300 (compound_decode_hdr_maxsz + \
301 decode_putfh_maxsz + \
302 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
304 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400305 encode_open_maxsz + \
306 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
308 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400309 decode_open_maxsz + \
310 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311#define NFS4_enc_open_downgrade_sz \
312 (compound_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400313 encode_putfh_maxsz + \
314 encode_open_downgrade_maxsz + \
315 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316#define NFS4_dec_open_downgrade_sz \
317 (compound_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400318 decode_putfh_maxsz + \
319 decode_open_downgrade_maxsz + \
320 decode_getattr_maxsz)
321#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
322 encode_putfh_maxsz + \
323 encode_close_maxsz + \
324 encode_getattr_maxsz)
325#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
326 decode_putfh_maxsz + \
327 decode_close_maxsz + \
328 decode_getattr_maxsz)
329#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
330 encode_putfh_maxsz + \
331 encode_setattr_maxsz + \
332 encode_getattr_maxsz)
333#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
334 decode_putfh_maxsz + \
335 decode_setattr_maxsz + \
336 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
338 encode_putfh_maxsz + \
339 encode_fsinfo_maxsz)
340#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
341 decode_putfh_maxsz + \
342 decode_fsinfo_maxsz)
343#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
344 encode_renew_maxsz)
345#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
346 decode_renew_maxsz)
347#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
348 encode_setclientid_maxsz)
349#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
350 decode_setclientid_maxsz)
351#define NFS4_enc_setclientid_confirm_sz \
352 (compound_encode_hdr_maxsz + \
353 encode_setclientid_confirm_maxsz + \
354 encode_putrootfh_maxsz + \
355 encode_fsinfo_maxsz)
356#define NFS4_dec_setclientid_confirm_sz \
357 (compound_decode_hdr_maxsz + \
358 decode_setclientid_confirm_maxsz + \
359 decode_putrootfh_maxsz + \
360 decode_fsinfo_maxsz)
361#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
362 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400363 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
365 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400366 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
368 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400369 encode_lockt_maxsz)
370#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
371 decode_putfh_maxsz + \
372 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
374 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400375 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
377 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400378 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
380 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400381 encode_access_maxsz + \
382 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
384 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400385 decode_access_maxsz + \
386 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
388 encode_putfh_maxsz + \
389 encode_getattr_maxsz)
390#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
391 decode_putfh_maxsz + \
392 decode_getattr_maxsz)
393#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
394 encode_putfh_maxsz + \
395 encode_lookup_maxsz + \
396 encode_getattr_maxsz + \
397 encode_getfh_maxsz)
398#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
399 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400400 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 decode_getattr_maxsz + \
402 decode_getfh_maxsz)
403#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
404 encode_putrootfh_maxsz + \
405 encode_getattr_maxsz + \
406 encode_getfh_maxsz)
407#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
408 decode_putrootfh_maxsz + \
409 decode_getattr_maxsz + \
410 decode_getfh_maxsz)
411#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
412 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400413 encode_remove_maxsz + \
414 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
416 decode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400417 op_decode_hdr_maxsz + 5 + \
418 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
420 encode_putfh_maxsz + \
421 encode_savefh_maxsz + \
422 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400423 encode_rename_maxsz + \
424 encode_getattr_maxsz + \
425 encode_restorefh_maxsz + \
426 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
428 decode_putfh_maxsz + \
429 decode_savefh_maxsz + \
430 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400431 decode_rename_maxsz + \
432 decode_getattr_maxsz + \
433 decode_restorefh_maxsz + \
434 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
436 encode_putfh_maxsz + \
437 encode_savefh_maxsz + \
438 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400439 encode_link_maxsz + \
440 decode_getattr_maxsz + \
441 encode_restorefh_maxsz + \
442 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
444 decode_putfh_maxsz + \
445 decode_savefh_maxsz + \
446 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400447 decode_link_maxsz + \
448 decode_getattr_maxsz + \
449 decode_restorefh_maxsz + \
450 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
452 encode_putfh_maxsz + \
453 encode_symlink_maxsz + \
454 encode_getattr_maxsz + \
455 encode_getfh_maxsz)
456#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
457 decode_putfh_maxsz + \
458 decode_symlink_maxsz + \
459 decode_getattr_maxsz + \
460 decode_getfh_maxsz)
461#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
462 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400463 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400465 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400467 encode_restorefh_maxsz + \
468 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
470 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400471 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400473 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400475 decode_restorefh_maxsz + \
476 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
478 encode_putfh_maxsz + \
479 encode_getattr_maxsz)
480#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
481 decode_putfh_maxsz + \
482 decode_getattr_maxsz)
483#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
484 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400485 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
487 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400488 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800490 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 encode_getattr_maxsz)
492#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800493 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 decode_getattr_maxsz)
495#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
496 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100497 encode_delegreturn_maxsz + \
498 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100500 decode_delegreturn_maxsz + \
501 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000502#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
503 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400504 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000505#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
506 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400507 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000508#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
509 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400510 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000511#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
512 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400513 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400514#define NFS4_enc_fs_locations_sz \
515 (compound_encode_hdr_maxsz + \
516 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400517 encode_lookup_maxsz + \
518 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400519#define NFS4_dec_fs_locations_sz \
520 (compound_decode_hdr_maxsz + \
521 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400522 decode_lookup_maxsz + \
523 decode_fs_locations_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Trond Myklebustbca79472009-03-11 14:10:26 -0400525static const umode_t nfs_type2fmt[] = {
526 [NF4BAD] = 0,
527 [NF4REG] = S_IFREG,
528 [NF4DIR] = S_IFDIR,
529 [NF4BLK] = S_IFBLK,
530 [NF4CHR] = S_IFCHR,
531 [NF4LNK] = S_IFLNK,
532 [NF4SOCK] = S_IFSOCK,
533 [NF4FIFO] = S_IFIFO,
534 [NF4ATTRDIR] = 0,
535 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536};
537
538struct compound_hdr {
539 int32_t status;
540 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500541 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 uint32_t taglen;
543 char * tag;
544};
545
546/*
547 * START OF "GENERIC" ENCODE ROUTINES.
548 * These may look a little ugly since they are imported from a "generic"
549 * set of XDR encode/decode routines which are intended to be shared by
550 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
551 *
552 * If the pain of reading these is too great, it should be a straightforward
553 * task to translate them into Linux-specific versions which are more
554 * consistent with the style used in NFSv2/v3...
555 */
556#define WRITE32(n) *p++ = htonl(n)
557#define WRITE64(n) do { \
558 *p++ = htonl((uint32_t)((n) >> 32)); \
559 *p++ = htonl((uint32_t)(n)); \
560} while (0)
561#define WRITEMEM(ptr,nbytes) do { \
562 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
563} while (0)
564
565#define RESERVE_SPACE(nbytes) do { \
566 p = xdr_reserve_space(xdr, nbytes); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 BUG_ON(!p); \
568} while (0)
569
570static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
571{
Al Viro8687b632006-10-19 23:28:48 -0700572 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574 p = xdr_reserve_space(xdr, 4 + len);
575 BUG_ON(p == NULL);
576 xdr_encode_opaque(p, str, len);
577}
578
Andy Adamsond0179312008-12-23 16:06:17 -0500579static void encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Al Viro8687b632006-10-19 23:28:48 -0700581 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
584 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
585 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
586 WRITE32(hdr->taglen);
587 WRITEMEM(hdr->tag, hdr->taglen);
588 WRITE32(NFS4_MINOR_VERSION);
Andy Adamsond0179312008-12-23 16:06:17 -0500589 hdr->nops_p = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 WRITE32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500591}
592
593static void encode_nops(struct compound_hdr *hdr)
594{
595 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
597
598static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
599{
Al Viro8687b632006-10-19 23:28:48 -0700600 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
603 BUG_ON(p == NULL);
604 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
605}
606
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500607static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
609 char owner_name[IDMAP_NAMESZ];
610 char owner_group[IDMAP_NAMESZ];
611 int owner_namelen = 0;
612 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700613 __be32 *p;
614 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 int len;
616 uint32_t bmval0 = 0;
617 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
619 /*
620 * We reserve enough space to write the entire attribute buffer at once.
621 * In the worst-case, this would be
622 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
623 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000624 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 */
626 len = 16;
627
628 /* Sigh */
629 if (iap->ia_valid & ATTR_SIZE)
630 len += 8;
631 if (iap->ia_valid & ATTR_MODE)
632 len += 4;
633 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400634 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400636 dprintk("nfs: couldn't resolve uid %d to string\n",
637 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 /* XXX */
639 strcpy(owner_name, "nobody");
640 owner_namelen = sizeof("nobody") - 1;
641 /* goto out; */
642 }
643 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
644 }
645 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400646 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400648 dprintk("nfs: couldn't resolve gid %d to string\n",
649 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 strcpy(owner_group, "nobody");
651 owner_grouplen = sizeof("nobody") - 1;
652 /* goto out; */
653 }
654 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
655 }
656 if (iap->ia_valid & ATTR_ATIME_SET)
657 len += 16;
658 else if (iap->ia_valid & ATTR_ATIME)
659 len += 4;
660 if (iap->ia_valid & ATTR_MTIME_SET)
661 len += 16;
662 else if (iap->ia_valid & ATTR_MTIME)
663 len += 4;
664 RESERVE_SPACE(len);
665
666 /*
667 * We write the bitmap length now, but leave the bitmap and the attribute
668 * buffer length to be backfilled at the end of this routine.
669 */
670 WRITE32(2);
671 q = p;
672 p += 3;
673
674 if (iap->ia_valid & ATTR_SIZE) {
675 bmval0 |= FATTR4_WORD0_SIZE;
676 WRITE64(iap->ia_size);
677 }
678 if (iap->ia_valid & ATTR_MODE) {
679 bmval1 |= FATTR4_WORD1_MODE;
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100680 WRITE32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
682 if (iap->ia_valid & ATTR_UID) {
683 bmval1 |= FATTR4_WORD1_OWNER;
684 WRITE32(owner_namelen);
685 WRITEMEM(owner_name, owner_namelen);
686 }
687 if (iap->ia_valid & ATTR_GID) {
688 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
689 WRITE32(owner_grouplen);
690 WRITEMEM(owner_group, owner_grouplen);
691 }
692 if (iap->ia_valid & ATTR_ATIME_SET) {
693 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
694 WRITE32(NFS4_SET_TO_CLIENT_TIME);
695 WRITE32(0);
696 WRITE32(iap->ia_mtime.tv_sec);
697 WRITE32(iap->ia_mtime.tv_nsec);
698 }
699 else if (iap->ia_valid & ATTR_ATIME) {
700 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
701 WRITE32(NFS4_SET_TO_SERVER_TIME);
702 }
703 if (iap->ia_valid & ATTR_MTIME_SET) {
704 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
705 WRITE32(NFS4_SET_TO_CLIENT_TIME);
706 WRITE32(0);
707 WRITE32(iap->ia_mtime.tv_sec);
708 WRITE32(iap->ia_mtime.tv_nsec);
709 }
710 else if (iap->ia_valid & ATTR_MTIME) {
711 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
712 WRITE32(NFS4_SET_TO_SERVER_TIME);
713 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 /*
716 * Now we backfill the bitmap and the attribute buffer length.
717 */
718 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400719 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 len, ((char *)p - (char *)q) + 4);
721 BUG();
722 }
723 len = (char *)p - (char *)q - 12;
724 *q++ = htonl(bmval0);
725 *q++ = htonl(bmval1);
726 *q++ = htonl(len);
727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729}
730
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500731static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
Al Viro8687b632006-10-19 23:28:48 -0700733 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735 RESERVE_SPACE(8);
736 WRITE32(OP_ACCESS);
737 WRITE32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500738 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739}
740
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500741static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
Al Viro8687b632006-10-19 23:28:48 -0700743 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400745 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 WRITE32(OP_CLOSE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700747 WRITE32(arg->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400748 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500749 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750}
751
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500752static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753{
Al Viro8687b632006-10-19 23:28:48 -0700754 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500755
Andy Adamson05d564f2008-12-23 16:06:15 -0500756 RESERVE_SPACE(16);
757 WRITE32(OP_COMMIT);
758 WRITE64(args->offset);
759 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500760 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761}
762
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500763static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764{
Al Viro8687b632006-10-19 23:28:48 -0700765 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 RESERVE_SPACE(8);
768 WRITE32(OP_CREATE);
769 WRITE32(create->ftype);
770
771 switch (create->ftype) {
772 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400773 RESERVE_SPACE(4);
774 WRITE32(create->u.symlink.len);
775 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 break;
777
778 case NF4BLK: case NF4CHR:
779 RESERVE_SPACE(8);
780 WRITE32(create->u.device.specdata1);
781 WRITE32(create->u.device.specdata2);
782 break;
783
784 default:
785 break;
786 }
787
788 RESERVE_SPACE(4 + create->name->len);
789 WRITE32(create->name->len);
790 WRITEMEM(create->name->name, create->name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500791 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500793 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794}
795
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500796static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
Andy Adamson05d564f2008-12-23 16:06:15 -0500798 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Andy Adamson05d564f2008-12-23 16:06:15 -0500800 RESERVE_SPACE(12);
801 WRITE32(OP_GETATTR);
802 WRITE32(1);
803 WRITE32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500804 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805}
806
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500807static 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 -0700808{
Andy Adamson05d564f2008-12-23 16:06:15 -0500809 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Andy Adamson05d564f2008-12-23 16:06:15 -0500811 RESERVE_SPACE(16);
812 WRITE32(OP_GETATTR);
813 WRITE32(2);
814 WRITE32(bm0);
815 WRITE32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500816 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817}
818
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500819static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500821 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
822 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
824
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500825static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500827 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
828 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829}
830
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500831static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -0400832{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500833 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
834 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -0400835}
836
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500837static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838{
Al Viro8687b632006-10-19 23:28:48 -0700839 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 RESERVE_SPACE(4);
842 WRITE32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -0500843 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844}
845
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500846static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847{
Al Viro8687b632006-10-19 23:28:48 -0700848 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850 RESERVE_SPACE(8 + name->len);
851 WRITE32(OP_LINK);
852 WRITE32(name->len);
853 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500854 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855}
856
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100857static inline int nfs4_lock_type(struct file_lock *fl, int block)
858{
859 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
860 return block ? NFS4_READW_LT : NFS4_READ_LT;
861 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
862}
863
864static inline uint64_t nfs4_lock_length(struct file_lock *fl)
865{
866 if (fl->fl_end == OFFSET_MAX)
867 return ~(uint64_t)0;
868 return fl->fl_end - fl->fl_start + 1;
869}
870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871/*
872 * opcode,type,reclaim,offset,length,new_lock_owner = 32
873 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
874 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500875static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876{
Al Viro8687b632006-10-19 23:28:48 -0700877 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
879 RESERVE_SPACE(32);
880 WRITE32(OP_LOCK);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100881 WRITE32(nfs4_lock_type(args->fl, args->block));
882 WRITE32(args->reclaim);
883 WRITE64(args->fl->fl_start);
884 WRITE64(nfs4_lock_length(args->fl));
885 WRITE32(args->new_lock_owner);
886 if (args->new_lock_owner){
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400887 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100888 WRITE32(args->open_seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400889 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100890 WRITE32(args->lock_seqid->sequence->counter);
891 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400892 WRITE32(16);
893 WRITEMEM("lock id:", 8);
894 WRITE64(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 }
896 else {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400897 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
898 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100899 WRITE32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 }
Andy Adamsond0179312008-12-23 16:06:17 -0500901 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902}
903
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500904static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Al Viro8687b632006-10-19 23:28:48 -0700906 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400908 RESERVE_SPACE(52);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 WRITE32(OP_LOCKT);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100910 WRITE32(nfs4_lock_type(args->fl, 0));
911 WRITE64(args->fl->fl_start);
912 WRITE64(nfs4_lock_length(args->fl));
913 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400914 WRITE32(16);
915 WRITEMEM("lock id:", 8);
916 WRITE64(args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -0500917 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918}
919
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500920static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921{
Al Viro8687b632006-10-19 23:28:48 -0700922 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400924 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 WRITE32(OP_LOCKU);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100926 WRITE32(nfs4_lock_type(args->fl, 0));
927 WRITE32(args->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400928 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100929 WRITE64(args->fl->fl_start);
930 WRITE64(nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -0500931 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932}
933
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500934static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935{
936 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -0700937 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 RESERVE_SPACE(8 + len);
940 WRITE32(OP_LOOKUP);
941 WRITE32(len);
942 WRITEMEM(name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -0500943 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944}
945
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500946static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947{
Al Viro8687b632006-10-19 23:28:48 -0700948 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950 RESERVE_SPACE(8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500951 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -0500952 case FMODE_READ:
953 WRITE32(NFS4_SHARE_ACCESS_READ);
954 break;
955 case FMODE_WRITE:
956 WRITE32(NFS4_SHARE_ACCESS_WRITE);
957 break;
958 case FMODE_READ|FMODE_WRITE:
959 WRITE32(NFS4_SHARE_ACCESS_BOTH);
960 break;
961 default:
962 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 }
964 WRITE32(0); /* for linux, share_deny = 0 always */
965}
966
967static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
968{
Al Viro8687b632006-10-19 23:28:48 -0700969 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 /*
971 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
972 * owner 4 = 32
973 */
974 RESERVE_SPACE(8);
975 WRITE32(OP_OPEN);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700976 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500977 encode_share_access(xdr, arg->fmode);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400978 RESERVE_SPACE(28);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 WRITE64(arg->clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400980 WRITE32(16);
981 WRITEMEM("open id:", 8);
982 WRITE64(arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983}
984
985static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
986{
Al Viro8687b632006-10-19 23:28:48 -0700987 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
989 RESERVE_SPACE(4);
990 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -0500991 case 0:
992 WRITE32(NFS4_CREATE_UNCHECKED);
993 encode_attrs(xdr, arg->u.attrs, arg->server);
994 break;
995 default:
996 WRITE32(NFS4_CREATE_EXCLUSIVE);
997 encode_nfs4_verifier(xdr, &arg->u.verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 }
999}
1000
1001static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1002{
Al Viro8687b632006-10-19 23:28:48 -07001003 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 RESERVE_SPACE(4);
1006 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001007 case 0:
1008 WRITE32(NFS4_OPEN_NOCREATE);
1009 break;
1010 default:
1011 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1012 WRITE32(NFS4_OPEN_CREATE);
1013 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 }
1015}
1016
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001017static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
Al Viro8687b632006-10-19 23:28:48 -07001019 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
1021 RESERVE_SPACE(4);
1022 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001023 case 0:
1024 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1025 break;
1026 case FMODE_READ:
1027 WRITE32(NFS4_OPEN_DELEGATE_READ);
1028 break;
1029 case FMODE_WRITE|FMODE_READ:
1030 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1031 break;
1032 default:
1033 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 }
1035}
1036
1037static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1038{
Al Viro8687b632006-10-19 23:28:48 -07001039 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
1041 RESERVE_SPACE(4);
1042 WRITE32(NFS4_OPEN_CLAIM_NULL);
1043 encode_string(xdr, name->len, name->name);
1044}
1045
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001046static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047{
Al Viro8687b632006-10-19 23:28:48 -07001048 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050 RESERVE_SPACE(4);
1051 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1052 encode_delegation_type(xdr, type);
1053}
1054
1055static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1056{
Al Viro8687b632006-10-19 23:28:48 -07001057 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001059 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001061 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 encode_string(xdr, name->len, name->name);
1063}
1064
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001065static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
1067 encode_openhdr(xdr, arg);
1068 encode_opentype(xdr, arg);
1069 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001070 case NFS4_OPEN_CLAIM_NULL:
1071 encode_claim_null(xdr, arg->name);
1072 break;
1073 case NFS4_OPEN_CLAIM_PREVIOUS:
1074 encode_claim_previous(xdr, arg->u.delegation_type);
1075 break;
1076 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1077 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1078 break;
1079 default:
1080 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 }
Andy Adamsond0179312008-12-23 16:06:17 -05001082 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083}
1084
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001085static 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 -07001086{
Al Viro8687b632006-10-19 23:28:48 -07001087 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001089 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 WRITE32(OP_OPEN_CONFIRM);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001091 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001092 WRITE32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001093 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001096static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097{
Al Viro8687b632006-10-19 23:28:48 -07001098 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001100 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 WRITE32(OP_OPEN_DOWNGRADE);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001102 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001103 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001104 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001105 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106}
1107
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001108static void
Andy Adamsond0179312008-12-23 16:06:17 -05001109encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
1111 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001112 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
1114 RESERVE_SPACE(8 + len);
1115 WRITE32(OP_PUTFH);
1116 WRITE32(len);
1117 WRITEMEM(fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001118 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119}
1120
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001121static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
Andy Adamson05d564f2008-12-23 16:06:15 -05001123 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001124
Andy Adamson05d564f2008-12-23 16:06:15 -05001125 RESERVE_SPACE(4);
1126 WRITE32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001127 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
1130static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1131{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001133 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001135 RESERVE_SPACE(NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 if (ctx->state != NULL) {
1137 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001138 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 } else
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001140 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001143static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144{
Al Viro8687b632006-10-19 23:28:48 -07001145 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
1147 RESERVE_SPACE(4);
1148 WRITE32(OP_READ);
1149
1150 encode_stateid(xdr, args->context);
1151
1152 RESERVE_SPACE(12);
1153 WRITE64(args->offset);
1154 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001155 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156}
1157
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001158static 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 -07001159{
Manoj Naik97d312d2005-06-22 17:16:39 +00001160 uint32_t attrs[2] = {
1161 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1162 FATTR4_WORD1_MOUNTED_ON_FILEID,
1163 };
Al Viro8687b632006-10-19 23:28:48 -07001164 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001166 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 WRITE32(OP_READDIR);
1168 WRITE64(readdir->cookie);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001169 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1171 WRITE32(readdir->count);
1172 WRITE32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001173 /* Switch to mounted_on_fileid if the server supports it */
1174 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1175 attrs[0] &= ~FATTR4_WORD0_FILEID;
1176 else
1177 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1178 WRITE32(attrs[0] & readdir->bitmask[0]);
1179 WRITE32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001180 hdr->nops++;
Fred Isaman44109242008-04-02 15:21:15 +03001181 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1182 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001183 (unsigned long long)readdir->cookie,
1184 ((u32 *)readdir->verifier.data)[0],
1185 ((u32 *)readdir->verifier.data)[1],
1186 attrs[0] & readdir->bitmask[0],
1187 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188}
1189
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001190static 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 -07001191{
Al Viro8687b632006-10-19 23:28:48 -07001192 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
1194 RESERVE_SPACE(4);
1195 WRITE32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001196 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197}
1198
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001199static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200{
Al Viro8687b632006-10-19 23:28:48 -07001201 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
1203 RESERVE_SPACE(8 + name->len);
1204 WRITE32(OP_REMOVE);
1205 WRITE32(name->len);
1206 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001207 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208}
1209
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001210static 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 -07001211{
Al Viro8687b632006-10-19 23:28:48 -07001212 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
1214 RESERVE_SPACE(8 + oldname->len);
1215 WRITE32(OP_RENAME);
1216 WRITE32(oldname->len);
1217 WRITEMEM(oldname->name, oldname->len);
Andy Adamson6c0195a2008-12-23 16:06:15 -05001218
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 RESERVE_SPACE(4 + newname->len);
1220 WRITE32(newname->len);
1221 WRITEMEM(newname->name, newname->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001222 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223}
1224
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001225static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
Al Viro8687b632006-10-19 23:28:48 -07001227 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
1229 RESERVE_SPACE(12);
1230 WRITE32(OP_RENEW);
1231 WRITE64(client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001232 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233}
1234
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001235static void
Andy Adamsond0179312008-12-23 16:06:17 -05001236encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001237{
Al Viro8687b632006-10-19 23:28:48 -07001238 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001239
1240 RESERVE_SPACE(4);
1241 WRITE32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001242 hdr->nops++;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001243}
1244
1245static int
Andy Adamsond0179312008-12-23 16:06:17 -05001246encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001247{
Al Viro8687b632006-10-19 23:28:48 -07001248 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001249
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001250 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001251 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001252 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001253 RESERVE_SPACE(2*4);
1254 WRITE32(1);
1255 WRITE32(FATTR4_WORD0_ACL);
1256 if (arg->acl_len % 4)
1257 return -EINVAL;
1258 RESERVE_SPACE(4);
1259 WRITE32(arg->acl_len);
1260 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001261 hdr->nops++;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001262 return 0;
1263}
1264
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001265static void
Andy Adamsond0179312008-12-23 16:06:17 -05001266encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267{
Al Viro8687b632006-10-19 23:28:48 -07001268 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
1270 RESERVE_SPACE(4);
1271 WRITE32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001272 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273}
1274
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001275static 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 -07001276{
Al Viro8687b632006-10-19 23:28:48 -07001277 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001278
Andy Adamson05d564f2008-12-23 16:06:15 -05001279 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1280 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001281 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001282 hdr->nops++;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001283 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284}
1285
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001286static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287{
Al Viro8687b632006-10-19 23:28:48 -07001288 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001290 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 WRITE32(OP_SETCLIENTID);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001292 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1295 RESERVE_SPACE(4);
1296 WRITE32(setclientid->sc_prog);
1297 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1298 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1299 RESERVE_SPACE(4);
1300 WRITE32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001301 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302}
1303
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001304static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305{
Andy Adamson05d564f2008-12-23 16:06:15 -05001306 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
Andy Adamson05d564f2008-12-23 16:06:15 -05001308 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1309 WRITE32(OP_SETCLIENTID_CONFIRM);
1310 WRITE64(client_state->cl_clientid);
1311 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001312 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313}
1314
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001315static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
Al Viro8687b632006-10-19 23:28:48 -07001317 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
1319 RESERVE_SPACE(4);
1320 WRITE32(OP_WRITE);
1321
1322 encode_stateid(xdr, args->context);
1323
1324 RESERVE_SPACE(16);
1325 WRITE64(args->offset);
1326 WRITE32(args->stable);
1327 WRITE32(args->count);
1328
1329 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001330 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001333static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334{
Al Viro8687b632006-10-19 23:28:48 -07001335 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001337 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
1339 WRITE32(OP_DELEGRETURN);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001340 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001341 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342}
1343/*
1344 * END OF "GENERIC" ENCODE ROUTINES.
1345 */
1346
1347/*
1348 * Encode an ACCESS request
1349 */
Al Viro8687b632006-10-19 23:28:48 -07001350static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351{
1352 struct xdr_stream xdr;
1353 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001354 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
1357 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1358 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001359 encode_putfh(&xdr, args->fh, &hdr);
1360 encode_access(&xdr, args->access, &hdr);
1361 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001362 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001363 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364}
1365
1366/*
1367 * Encode LOOKUP request
1368 */
Al Viro8687b632006-10-19 23:28:48 -07001369static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370{
1371 struct xdr_stream xdr;
1372 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001373 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1377 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001378 encode_putfh(&xdr, args->dir_fh, &hdr);
1379 encode_lookup(&xdr, args->name, &hdr);
1380 encode_getfh(&xdr, &hdr);
1381 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001382 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001383 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384}
1385
1386/*
1387 * Encode LOOKUP_ROOT request
1388 */
Al Viro8687b632006-10-19 23:28:48 -07001389static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390{
1391 struct xdr_stream xdr;
1392 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001393 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
1396 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1397 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001398 encode_putrootfh(&xdr, &hdr);
1399 encode_getfh(&xdr, &hdr);
1400 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001401 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001402 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403}
1404
1405/*
1406 * Encode REMOVE request
1407 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001408static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409{
1410 struct xdr_stream xdr;
1411 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001412 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
1415 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1416 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001417 encode_putfh(&xdr, args->fh, &hdr);
1418 encode_remove(&xdr, &args->name, &hdr);
1419 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001420 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001421 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422}
1423
1424/*
1425 * Encode RENAME request
1426 */
Al Viro8687b632006-10-19 23:28:48 -07001427static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428{
1429 struct xdr_stream xdr;
1430 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001431 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
1434 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1435 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001436 encode_putfh(&xdr, args->old_dir, &hdr);
1437 encode_savefh(&xdr, &hdr);
1438 encode_putfh(&xdr, args->new_dir, &hdr);
1439 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1440 encode_getfattr(&xdr, args->bitmask, &hdr);
1441 encode_restorefh(&xdr, &hdr);
1442 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001443 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001444 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445}
1446
1447/*
1448 * Encode LINK request
1449 */
Al Viro8687b632006-10-19 23:28:48 -07001450static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451{
1452 struct xdr_stream xdr;
1453 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001454 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
1457 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1458 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001459 encode_putfh(&xdr, args->fh, &hdr);
1460 encode_savefh(&xdr, &hdr);
1461 encode_putfh(&xdr, args->dir_fh, &hdr);
1462 encode_link(&xdr, args->name, &hdr);
1463 encode_getfattr(&xdr, args->bitmask, &hdr);
1464 encode_restorefh(&xdr, &hdr);
1465 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001466 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001467 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468}
1469
1470/*
1471 * Encode CREATE request
1472 */
Al Viro8687b632006-10-19 23:28:48 -07001473static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
1475 struct xdr_stream xdr;
1476 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001477 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
1480 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1481 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001482 encode_putfh(&xdr, args->dir_fh, &hdr);
1483 encode_savefh(&xdr, &hdr);
1484 encode_create(&xdr, args, &hdr);
1485 encode_getfh(&xdr, &hdr);
1486 encode_getfattr(&xdr, args->bitmask, &hdr);
1487 encode_restorefh(&xdr, &hdr);
1488 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001489 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001490 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491}
1492
1493/*
1494 * Encode SYMLINK request
1495 */
Al Viro8687b632006-10-19 23:28:48 -07001496static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497{
1498 return nfs4_xdr_enc_create(req, p, args);
1499}
1500
1501/*
1502 * Encode GETATTR request
1503 */
Al Viro8687b632006-10-19 23:28:48 -07001504static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505{
1506 struct xdr_stream xdr;
1507 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001508 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
1511 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1512 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001513 encode_putfh(&xdr, args->fh, &hdr);
1514 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001515 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001516 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517}
1518
1519/*
1520 * Encode a CLOSE request
1521 */
Al Viro8687b632006-10-19 23:28:48 -07001522static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
Andy Adamson05d564f2008-12-23 16:06:15 -05001524 struct xdr_stream xdr;
1525 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001526 .nops = 0,
Andy Adamson05d564f2008-12-23 16:06:15 -05001527 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Andy Adamson05d564f2008-12-23 16:06:15 -05001529 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1530 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001531 encode_putfh(&xdr, args->fh, &hdr);
1532 encode_close(&xdr, args, &hdr);
1533 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001534 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001535 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536}
1537
1538/*
1539 * Encode an OPEN request
1540 */
Al Viro8687b632006-10-19 23:28:48 -07001541static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542{
1543 struct xdr_stream xdr;
1544 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001545 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
1548 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1549 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001550 encode_putfh(&xdr, args->fh, &hdr);
1551 encode_savefh(&xdr, &hdr);
1552 encode_open(&xdr, args, &hdr);
1553 encode_getfh(&xdr, &hdr);
1554 encode_getfattr(&xdr, args->bitmask, &hdr);
1555 encode_restorefh(&xdr, &hdr);
1556 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001557 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001558 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559}
1560
1561/*
1562 * Encode an OPEN_CONFIRM request
1563 */
Al Viro8687b632006-10-19 23:28:48 -07001564static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
1566 struct xdr_stream xdr;
1567 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001568 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
1571 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1572 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001573 encode_putfh(&xdr, args->fh, &hdr);
1574 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001575 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001576 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
1579/*
1580 * Encode an OPEN request with no attributes.
1581 */
Al Viro8687b632006-10-19 23:28:48 -07001582static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583{
1584 struct xdr_stream xdr;
1585 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001586 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
1589 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1590 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001591 encode_putfh(&xdr, args->fh, &hdr);
1592 encode_open(&xdr, args, &hdr);
1593 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001594 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001595 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596}
1597
1598/*
1599 * Encode an OPEN_DOWNGRADE request
1600 */
Al Viro8687b632006-10-19 23:28:48 -07001601static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602{
1603 struct xdr_stream xdr;
1604 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001605 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
1608 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1609 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001610 encode_putfh(&xdr, args->fh, &hdr);
1611 encode_open_downgrade(&xdr, args, &hdr);
1612 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001613 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
1616
1617/*
1618 * Encode a LOCK request
1619 */
Al Viro8687b632006-10-19 23:28:48 -07001620static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621{
1622 struct xdr_stream xdr;
1623 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001624 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
1627 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1628 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001629 encode_putfh(&xdr, args->fh, &hdr);
1630 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001631 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001632 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633}
1634
1635/*
1636 * Encode a LOCKT request
1637 */
Al Viro8687b632006-10-19 23:28:48 -07001638static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639{
1640 struct xdr_stream xdr;
1641 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001642 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
1645 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1646 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001647 encode_putfh(&xdr, args->fh, &hdr);
1648 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001649 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001650 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651}
1652
1653/*
1654 * Encode a LOCKU request
1655 */
Al Viro8687b632006-10-19 23:28:48 -07001656static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657{
1658 struct xdr_stream xdr;
1659 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001660 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
1663 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1664 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001665 encode_putfh(&xdr, args->fh, &hdr);
1666 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001667 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001668 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669}
1670
1671/*
1672 * Encode a READLINK request
1673 */
Al Viro8687b632006-10-19 23:28:48 -07001674static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
1676 struct xdr_stream xdr;
1677 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001678 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 };
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001680 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1681 unsigned int replen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682
1683 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1684 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001685 encode_putfh(&xdr, args->fh, &hdr);
1686 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001687
1688 /* set up reply kvec
1689 * toplevel_status + taglen + rescount + OP_PUTFH + status
1690 * + OP_READLINK + status + string length = 8
1691 */
1692 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readlink_sz) << 2;
1693 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1694 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05001695 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001696 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697}
1698
1699/*
1700 * Encode a READDIR request
1701 */
Al Viro8687b632006-10-19 23:28:48 -07001702static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703{
1704 struct xdr_stream xdr;
1705 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001706 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 };
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001708 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1709 int replen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
1711 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1712 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001713 encode_putfh(&xdr, args->fh, &hdr);
1714 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001715
1716 /* set up reply kvec
1717 * toplevel_status + taglen + rescount + OP_PUTFH + status
1718 * + OP_READDIR + status + verifer(2) = 9
1719 */
1720 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readdir_sz) << 2;
1721 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1722 args->pgbase, args->count);
1723 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07001724 __func__, replen, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001725 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001726 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001727 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728}
1729
1730/*
1731 * Encode a READ request
1732 */
Al Viro8687b632006-10-19 23:28:48 -07001733static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734{
Trond Myklebust1be27f32007-06-27 14:29:04 -04001735 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 struct xdr_stream xdr;
1737 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001738 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 };
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001740 int replen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
1742 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1743 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001744 encode_putfh(&xdr, args->fh, &hdr);
1745 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
1747 /* set up reply kvec
1748 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1749 * + OP_READ + status + eof + datalen = 9
1750 */
1751 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1752 xdr_inline_pages(&req->rq_rcv_buf, replen,
1753 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001754 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05001755 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001756 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757}
1758
1759/*
1760 * Encode an SETATTR request
1761 */
Al Viro8687b632006-10-19 23:28:48 -07001762static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763{
Andy Adamson05d564f2008-12-23 16:06:15 -05001764 struct xdr_stream xdr;
1765 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001766 .nops = 0,
Andy Adamson05d564f2008-12-23 16:06:15 -05001767 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
Andy Adamson05d564f2008-12-23 16:06:15 -05001769 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1770 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001771 encode_putfh(&xdr, args->fh, &hdr);
1772 encode_setattr(&xdr, args, args->server, &hdr);
1773 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001774 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001775 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776}
1777
1778/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00001779 * Encode a GETACL request
1780 */
1781static int
Al Viro8687b632006-10-19 23:28:48 -07001782nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001783 struct nfs_getaclargs *args)
1784{
1785 struct xdr_stream xdr;
Trond Myklebust1be27f32007-06-27 14:29:04 -04001786 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001787 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001788 .nops = 0,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001789 };
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001790 int replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001791
1792 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1793 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001794 encode_putfh(&xdr, args->fh, &hdr);
1795 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1796
J. Bruce Fields029d1052005-06-22 17:16:22 +00001797 /* set up reply buffer: */
1798 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1799 xdr_inline_pages(&req->rq_rcv_buf, replen,
1800 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001801 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001802 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001803}
1804
1805/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 * Encode a WRITE request
1807 */
Al Viro8687b632006-10-19 23:28:48 -07001808static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809{
1810 struct xdr_stream xdr;
1811 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001812 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
1815 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1816 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001817 encode_putfh(&xdr, args->fh, &hdr);
1818 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001819 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001820 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001821 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001822 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823}
1824
1825/*
1826 * a COMMIT request
1827 */
Al Viro8687b632006-10-19 23:28:48 -07001828static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829{
1830 struct xdr_stream xdr;
1831 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001832 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
1835 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1836 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001837 encode_putfh(&xdr, args->fh, &hdr);
1838 encode_commit(&xdr, args, &hdr);
1839 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001840 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001841 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842}
1843
1844/*
1845 * FSINFO request
1846 */
Al Viro8687b632006-10-19 23:28:48 -07001847static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848{
1849 struct xdr_stream xdr;
1850 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001851 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853
1854 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1855 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001856 encode_putfh(&xdr, args->fh, &hdr);
1857 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001858 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001859 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860}
1861
1862/*
1863 * a PATHCONF request
1864 */
Al Viro8687b632006-10-19 23:28:48 -07001865static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 struct xdr_stream xdr;
1868 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001869 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
1872 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1873 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001874 encode_putfh(&xdr, args->fh, &hdr);
1875 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
1876 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001877 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001878 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879}
1880
1881/*
1882 * a STATFS request
1883 */
Al Viro8687b632006-10-19 23:28:48 -07001884static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 struct xdr_stream xdr;
1887 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001888 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
1891 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1892 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001893 encode_putfh(&xdr, args->fh, &hdr);
1894 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
1895 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001896 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001897 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898}
1899
1900/*
1901 * GETATTR_BITMAP request
1902 */
Benny Halevy43652ad2009-04-01 09:21:54 -04001903static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
1904 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905{
1906 struct xdr_stream xdr;
1907 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001908 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910
1911 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1912 encode_compound_hdr(&xdr, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04001913 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001914 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1915 FATTR4_WORD0_LINK_SUPPORT|
1916 FATTR4_WORD0_SYMLINK_SUPPORT|
1917 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001918 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001919 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920}
1921
1922/*
1923 * a RENEW request
1924 */
Al Viro8687b632006-10-19 23:28:48 -07001925static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926{
1927 struct xdr_stream xdr;
1928 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001929 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 };
1931
1932 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1933 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001934 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001935 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001936 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937}
1938
1939/*
1940 * a SETCLIENTID request
1941 */
Al Viro8687b632006-10-19 23:28:48 -07001942static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943{
1944 struct xdr_stream xdr;
1945 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001946 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 };
1948
1949 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1950 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001951 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001952 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001953 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954}
1955
1956/*
1957 * a SETCLIENTID_CONFIRM request
1958 */
Al Viro8687b632006-10-19 23:28:48 -07001959static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960{
1961 struct xdr_stream xdr;
1962 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001963 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 };
1965 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
1967 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1968 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001969 encode_setclientid_confirm(&xdr, clp, &hdr);
1970 encode_putrootfh(&xdr, &hdr);
1971 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001972 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001973 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974}
1975
1976/*
1977 * DELEGRETURN request
1978 */
Al Viro8687b632006-10-19 23:28:48 -07001979static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980{
1981 struct xdr_stream xdr;
1982 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001983 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985
1986 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1987 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001988 encode_putfh(&xdr, args->fhandle, &hdr);
1989 encode_delegreturn(&xdr, args->stateid, &hdr);
1990 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001991 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001992 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993}
1994
1995/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04001996 * Encode FS_LOCATIONS request
1997 */
Al Viro8687b632006-10-19 23:28:48 -07001998static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04001999{
2000 struct xdr_stream xdr;
2001 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002002 .nops = 0,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002003 };
Trond Myklebust1be27f32007-06-27 14:29:04 -04002004 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002005 int replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002006
2007 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2008 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002009 encode_putfh(&xdr, args->dir_fh, &hdr);
2010 encode_lookup(&xdr, args->name, &hdr);
2011 encode_fs_locations(&xdr, args->bitmask, &hdr);
2012
Trond Myklebust683b57b2006-06-09 09:34:22 -04002013 /* set up reply
Manoj Naik830b8e32006-06-09 09:34:25 -04002014 * toplevel_status + OP_PUTFH + status
Trond Myklebust683b57b2006-06-09 09:34:22 -04002015 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2016 */
2017 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2018 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2019 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002020 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002021 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002022}
2023
2024/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 * START OF "GENERIC" DECODE ROUTINES.
2026 * These may look a little ugly since they are imported from a "generic"
2027 * set of XDR encode/decode routines which are intended to be shared by
2028 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2029 *
2030 * If the pain of reading these is too great, it should be a straightforward
2031 * task to translate them into Linux-specific versions which are more
2032 * consistent with the style used in NFSv2/v3...
2033 */
2034#define READ32(x) (x) = ntohl(*p++)
2035#define READ64(x) do { \
2036 (x) = (u64)ntohl(*p++) << 32; \
2037 (x) |= ntohl(*p++); \
2038} while (0)
2039#define READTIME(x) do { \
2040 p++; \
2041 (x.tv_sec) = ntohl(*p++); \
2042 (x.tv_nsec) = ntohl(*p++); \
2043} while (0)
2044#define COPYMEM(x,nbytes) do { \
2045 memcpy((x), p, nbytes); \
2046 p += XDR_QUADLEN(nbytes); \
2047} while (0)
2048
2049#define READ_BUF(nbytes) do { \
2050 p = xdr_inline_decode(xdr, nbytes); \
Chuck Levere4cc6ee2007-05-08 18:23:28 -04002051 if (unlikely(!p)) { \
Chuck Leverfe82a182007-09-11 18:01:10 -04002052 dprintk("nfs: %s: prematurely hit end of receive" \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002053 " buffer\n", __func__); \
Chuck Leverfe82a182007-09-11 18:01:10 -04002054 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002055 __func__, xdr->p, nbytes, xdr->end); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 return -EIO; \
2057 } \
2058} while (0)
2059
Trond Myklebust683b57b2006-06-09 09:34:22 -04002060static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061{
Al Viro8687b632006-10-19 23:28:48 -07002062 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
2064 READ_BUF(4);
2065 READ32(*len);
2066 READ_BUF(*len);
2067 *string = (char *)p;
2068 return 0;
2069}
2070
2071static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2072{
Al Viro8687b632006-10-19 23:28:48 -07002073 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
2075 READ_BUF(8);
2076 READ32(hdr->status);
2077 READ32(hdr->taglen);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002078
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 READ_BUF(hdr->taglen + 4);
2080 hdr->tag = (char *)p;
2081 p += XDR_QUADLEN(hdr->taglen);
2082 READ32(hdr->nops);
Benny Halevyaadf6152008-12-23 16:06:13 -05002083 if (unlikely(hdr->nops < 1))
2084 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 return 0;
2086}
2087
2088static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2089{
Al Viro8687b632006-10-19 23:28:48 -07002090 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 uint32_t opnum;
2092 int32_t nfserr;
2093
2094 READ_BUF(8);
2095 READ32(opnum);
2096 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002097 dprintk("nfs: Server returned operation"
2098 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 opnum, expected);
2100 return -EIO;
2101 }
2102 READ32(nfserr);
2103 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002104 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 return 0;
2106}
2107
2108/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002109static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110{
Al Viro8687b632006-10-19 23:28:48 -07002111 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002112 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 char *str;
2114
2115 READ_BUF(12);
2116 return decode_opaque_inline(xdr, &strlen, &str);
2117}
2118
2119static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2120{
Al Viro8687b632006-10-19 23:28:48 -07002121 uint32_t bmlen;
2122 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
2124 READ_BUF(4);
2125 READ32(bmlen);
2126
2127 bitmap[0] = bitmap[1] = 0;
2128 READ_BUF((bmlen << 2));
2129 if (bmlen > 0) {
2130 READ32(bitmap[0]);
2131 if (bmlen > 1)
2132 READ32(bitmap[1]);
2133 }
2134 return 0;
2135}
2136
Al Viro8687b632006-10-19 23:28:48 -07002137static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
Al Viro8687b632006-10-19 23:28:48 -07002139 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
2141 READ_BUF(4);
2142 READ32(*attrlen);
2143 *savep = xdr->p;
2144 return 0;
2145}
2146
2147static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2148{
2149 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2150 decode_attr_bitmap(xdr, bitmask);
2151 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2152 } else
2153 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002154 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 return 0;
2156}
2157
2158static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2159{
Al Viro8687b632006-10-19 23:28:48 -07002160 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002161 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
2163 *type = 0;
2164 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2165 return -EIO;
2166 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2167 READ_BUF(4);
2168 READ32(*type);
2169 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002170 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 return -EIO;
2172 }
2173 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002174 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002176 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002177 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178}
2179
2180static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2181{
Al Viro8687b632006-10-19 23:28:48 -07002182 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002183 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
2185 *change = 0;
2186 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2187 return -EIO;
2188 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2189 READ_BUF(8);
2190 READ64(*change);
2191 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002192 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002194 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002196 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197}
2198
2199static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2200{
Al Viro8687b632006-10-19 23:28:48 -07002201 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002202 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203
2204 *size = 0;
2205 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2206 return -EIO;
2207 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2208 READ_BUF(8);
2209 READ64(*size);
2210 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002211 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002213 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002214 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215}
2216
2217static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2218{
Al Viro8687b632006-10-19 23:28:48 -07002219 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
2221 *res = 0;
2222 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2223 return -EIO;
2224 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2225 READ_BUF(4);
2226 READ32(*res);
2227 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2228 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002229 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 return 0;
2231}
2232
2233static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2234{
Al Viro8687b632006-10-19 23:28:48 -07002235 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
2237 *res = 0;
2238 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2239 return -EIO;
2240 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2241 READ_BUF(4);
2242 READ32(*res);
2243 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2244 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002245 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 return 0;
2247}
2248
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002249static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250{
Al Viro8687b632006-10-19 23:28:48 -07002251 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002252 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253
2254 fsid->major = 0;
2255 fsid->minor = 0;
2256 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2257 return -EIO;
2258 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2259 READ_BUF(16);
2260 READ64(fsid->major);
2261 READ64(fsid->minor);
2262 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002263 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002265 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 (unsigned long long)fsid->major,
2267 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002268 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269}
2270
2271static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2272{
Al Viro8687b632006-10-19 23:28:48 -07002273 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274
2275 *res = 60;
2276 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2277 return -EIO;
2278 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2279 READ_BUF(4);
2280 READ32(*res);
2281 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2282 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002283 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 return 0;
2285}
2286
2287static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2288{
Al Viro8687b632006-10-19 23:28:48 -07002289 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
2291 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2292 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2293 return -EIO;
2294 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2295 READ_BUF(4);
2296 READ32(*res);
2297 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2298 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002299 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 return 0;
2301}
2302
2303static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2304{
Al Viro8687b632006-10-19 23:28:48 -07002305 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002306 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
2308 *fileid = 0;
2309 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2310 return -EIO;
2311 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2312 READ_BUF(8);
2313 READ64(*fileid);
2314 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002315 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002317 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002318 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319}
2320
Manoj Naik99baf622006-06-09 09:34:24 -04002321static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2322{
Al Viro8687b632006-10-19 23:28:48 -07002323 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002324 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002325
2326 *fileid = 0;
2327 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2328 return -EIO;
2329 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2330 READ_BUF(8);
2331 READ64(*fileid);
2332 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002333 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002334 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002335 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002336 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04002337}
2338
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2340{
Al Viro8687b632006-10-19 23:28:48 -07002341 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 int status = 0;
2343
2344 *res = 0;
2345 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2346 return -EIO;
2347 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2348 READ_BUF(8);
2349 READ64(*res);
2350 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2351 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002352 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 return status;
2354}
2355
2356static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2357{
Al Viro8687b632006-10-19 23:28:48 -07002358 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 int status = 0;
2360
2361 *res = 0;
2362 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2363 return -EIO;
2364 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2365 READ_BUF(8);
2366 READ64(*res);
2367 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2368 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002369 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 return status;
2371}
2372
2373static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2374{
Al Viro8687b632006-10-19 23:28:48 -07002375 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 int status = 0;
2377
2378 *res = 0;
2379 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2380 return -EIO;
2381 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2382 READ_BUF(8);
2383 READ64(*res);
2384 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2385 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002386 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 return status;
2388}
2389
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002390static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2391{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002392 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002393 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002394 int status = 0;
2395
2396 READ_BUF(4);
2397 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002398 if (n == 0)
2399 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002400 dprintk("path ");
2401 path->ncomponents = 0;
2402 while (path->ncomponents < n) {
2403 struct nfs4_string *component = &path->components[path->ncomponents];
2404 status = decode_opaque_inline(xdr, &component->len, &component->data);
2405 if (unlikely(status != 0))
2406 goto out_eio;
2407 if (path->ncomponents != n)
2408 dprintk("/");
2409 dprintk("%s", component->data);
2410 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2411 path->ncomponents++;
2412 else {
2413 dprintk("cannot parse %d components in path\n", n);
2414 goto out_eio;
2415 }
2416 }
2417out:
2418 dprintk("\n");
2419 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002420root_path:
2421/* a root pathname is sent as a zero component4 */
2422 path->ncomponents = 1;
2423 path->components[0].len=0;
2424 path->components[0].data=NULL;
2425 dprintk("path /\n");
2426 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002427out_eio:
2428 dprintk(" status %d", status);
2429 status = -EIO;
2430 goto out;
2431}
2432
2433static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002434{
2435 int n;
Al Viro8687b632006-10-19 23:28:48 -07002436 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002437 int status = -EIO;
2438
2439 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2440 goto out;
2441 status = 0;
2442 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2443 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002444 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002445 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002446 if (unlikely(status != 0))
2447 goto out;
2448 READ_BUF(4);
2449 READ32(n);
2450 if (n <= 0)
2451 goto out_eio;
2452 res->nlocations = 0;
2453 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002454 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002455 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002456
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002457 READ_BUF(4);
2458 READ32(m);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002459
2460 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002461 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002462 while (loc->nservers < m) {
2463 struct nfs4_string *server = &loc->servers[loc->nservers];
2464 status = decode_opaque_inline(xdr, &server->len, &server->data);
2465 if (unlikely(status != 0))
2466 goto out_eio;
2467 dprintk("%s ", server->data);
2468 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2469 loc->nservers++;
2470 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002471 unsigned int i;
2472 dprintk("%s: using first %u of %u servers "
2473 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002474 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002475 NFS4_FS_LOCATION_MAXSERVERS,
2476 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002477 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002478 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002479 char *data;
2480 status = decode_opaque_inline(xdr, &len, &data);
2481 if (unlikely(status != 0))
2482 goto out_eio;
2483 }
2484 }
2485 }
2486 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002487 if (unlikely(status != 0))
2488 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002489 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002490 res->nlocations++;
2491 }
Trond Myklebust409924e2009-03-11 14:10:27 -04002492 if (res->nlocations != 0)
2493 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002494out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002495 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002496 return status;
2497out_eio:
2498 status = -EIO;
2499 goto out;
2500}
2501
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2503{
Al Viro8687b632006-10-19 23:28:48 -07002504 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 int status = 0;
2506
2507 *res = 0;
2508 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2509 return -EIO;
2510 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2511 READ_BUF(8);
2512 READ64(*res);
2513 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2514 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002515 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 return status;
2517}
2518
2519static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2520{
Al Viro8687b632006-10-19 23:28:48 -07002521 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 int status = 0;
2523
2524 *maxlink = 1;
2525 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2526 return -EIO;
2527 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2528 READ_BUF(4);
2529 READ32(*maxlink);
2530 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2531 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002532 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 return status;
2534}
2535
2536static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2537{
Al Viro8687b632006-10-19 23:28:48 -07002538 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 int status = 0;
2540
2541 *maxname = 1024;
2542 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2543 return -EIO;
2544 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2545 READ_BUF(4);
2546 READ32(*maxname);
2547 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2548 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002549 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 return status;
2551}
2552
2553static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2554{
Al Viro8687b632006-10-19 23:28:48 -07002555 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 int status = 0;
2557
2558 *res = 1024;
2559 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2560 return -EIO;
2561 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2562 uint64_t maxread;
2563 READ_BUF(8);
2564 READ64(maxread);
2565 if (maxread > 0x7FFFFFFF)
2566 maxread = 0x7FFFFFFF;
2567 *res = (uint32_t)maxread;
2568 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2569 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002570 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 return status;
2572}
2573
2574static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2575{
Al Viro8687b632006-10-19 23:28:48 -07002576 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 int status = 0;
2578
2579 *res = 1024;
2580 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2581 return -EIO;
2582 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2583 uint64_t maxwrite;
2584 READ_BUF(8);
2585 READ64(maxwrite);
2586 if (maxwrite > 0x7FFFFFFF)
2587 maxwrite = 0x7FFFFFFF;
2588 *res = (uint32_t)maxwrite;
2589 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2590 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002591 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 return status;
2593}
2594
Trond Myklebustbca79472009-03-11 14:10:26 -04002595static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596{
Trond Myklebustbca79472009-03-11 14:10:26 -04002597 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07002598 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002599 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600
2601 *mode = 0;
2602 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2603 return -EIO;
2604 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2605 READ_BUF(4);
Trond Myklebustbca79472009-03-11 14:10:26 -04002606 READ32(tmp);
2607 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002609 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002611 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04002612 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613}
2614
2615static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2616{
Al Viro8687b632006-10-19 23:28:48 -07002617 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002618 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619
2620 *nlink = 1;
2621 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2622 return -EIO;
2623 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2624 READ_BUF(4);
2625 READ32(*nlink);
2626 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04002627 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002629 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04002630 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631}
2632
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002633static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634{
Al Viro8687b632006-10-19 23:28:48 -07002635 uint32_t len;
2636 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002637 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638
2639 *uid = -2;
2640 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2641 return -EIO;
2642 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2643 READ_BUF(4);
2644 READ32(len);
2645 READ_BUF(len);
2646 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04002647 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
2648 ret = NFS_ATTR_FATTR_OWNER;
2649 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002651 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002653 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002654 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2656 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002657 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002658 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659}
2660
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002661static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662{
Al Viro8687b632006-10-19 23:28:48 -07002663 uint32_t len;
2664 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002665 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
2667 *gid = -2;
2668 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2669 return -EIO;
2670 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2671 READ_BUF(4);
2672 READ32(len);
2673 READ_BUF(len);
2674 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04002675 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
2676 ret = NFS_ATTR_FATTR_GROUP;
2677 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002679 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002681 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002682 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2684 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002685 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002686 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687}
2688
2689static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2690{
Al Viro8687b632006-10-19 23:28:48 -07002691 uint32_t major = 0, minor = 0;
2692 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002693 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694
2695 *rdev = MKDEV(0,0);
2696 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2697 return -EIO;
2698 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2699 dev_t tmp;
2700
2701 READ_BUF(8);
2702 READ32(major);
2703 READ32(minor);
2704 tmp = MKDEV(major, minor);
2705 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2706 *rdev = tmp;
2707 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04002708 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002710 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002711 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712}
2713
2714static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2715{
Al Viro8687b632006-10-19 23:28:48 -07002716 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 int status = 0;
2718
2719 *res = 0;
2720 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2721 return -EIO;
2722 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2723 READ_BUF(8);
2724 READ64(*res);
2725 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2726 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002727 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 return status;
2729}
2730
2731static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2732{
Al Viro8687b632006-10-19 23:28:48 -07002733 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 int status = 0;
2735
2736 *res = 0;
2737 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2738 return -EIO;
2739 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2740 READ_BUF(8);
2741 READ64(*res);
2742 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2743 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002744 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 return status;
2746}
2747
2748static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2749{
Al Viro8687b632006-10-19 23:28:48 -07002750 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 int status = 0;
2752
2753 *res = 0;
2754 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2755 return -EIO;
2756 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2757 READ_BUF(8);
2758 READ64(*res);
2759 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2760 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002761 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 return status;
2763}
2764
2765static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2766{
Al Viro8687b632006-10-19 23:28:48 -07002767 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002768 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769
2770 *used = 0;
2771 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2772 return -EIO;
2773 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2774 READ_BUF(8);
2775 READ64(*used);
2776 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04002777 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002779 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04002781 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782}
2783
2784static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2785{
Al Viro8687b632006-10-19 23:28:48 -07002786 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 uint64_t sec;
2788 uint32_t nsec;
2789
2790 READ_BUF(12);
2791 READ64(sec);
2792 READ32(nsec);
2793 time->tv_sec = (time_t)sec;
2794 time->tv_nsec = (long)nsec;
2795 return 0;
2796}
2797
2798static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2799{
2800 int status = 0;
2801
2802 time->tv_sec = 0;
2803 time->tv_nsec = 0;
2804 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2805 return -EIO;
2806 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2807 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002808 if (status == 0)
2809 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2811 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002812 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 return status;
2814}
2815
2816static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2817{
2818 int status = 0;
2819
2820 time->tv_sec = 0;
2821 time->tv_nsec = 0;
2822 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2823 return -EIO;
2824 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2825 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002826 if (status == 0)
2827 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2829 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002830 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 return status;
2832}
2833
2834static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2835{
2836 int status = 0;
2837
2838 time->tv_sec = 0;
2839 time->tv_nsec = 0;
2840 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2841 return -EIO;
2842 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2843 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002844 if (status == 0)
2845 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2847 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002848 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 return status;
2850}
2851
Al Viro8687b632006-10-19 23:28:48 -07002852static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853{
2854 unsigned int attrwords = XDR_QUADLEN(attrlen);
2855 unsigned int nwords = xdr->p - savep;
2856
2857 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002858 dprintk("%s: server returned incorrect attribute length: "
2859 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002860 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 attrwords << 2,
2862 (attrwords < nwords) ? '<' : '>',
2863 nwords << 2);
2864 return -EIO;
2865 }
2866 return 0;
2867}
2868
2869static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2870{
Al Viro8687b632006-10-19 23:28:48 -07002871 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872
2873 READ_BUF(20);
2874 READ32(cinfo->atomic);
2875 READ64(cinfo->before);
2876 READ64(cinfo->after);
2877 return 0;
2878}
2879
2880static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2881{
Al Viro8687b632006-10-19 23:28:48 -07002882 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 uint32_t supp, acc;
2884 int status;
2885
2886 status = decode_op_hdr(xdr, OP_ACCESS);
2887 if (status)
2888 return status;
2889 READ_BUF(8);
2890 READ32(supp);
2891 READ32(acc);
2892 access->supported = supp;
2893 access->access = acc;
2894 return 0;
2895}
2896
2897static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2898{
Al Viro8687b632006-10-19 23:28:48 -07002899 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 int status;
2901
2902 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04002903 if (status != -EIO)
2904 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 if (status)
2906 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04002907 READ_BUF(NFS4_STATEID_SIZE);
2908 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 return 0;
2910}
2911
2912static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2913{
Al Viro8687b632006-10-19 23:28:48 -07002914 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 int status;
2916
2917 status = decode_op_hdr(xdr, OP_COMMIT);
2918 if (status)
2919 return status;
2920 READ_BUF(8);
2921 COPYMEM(res->verf->verifier, 8);
2922 return 0;
2923}
2924
2925static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2926{
Al Viro8687b632006-10-19 23:28:48 -07002927 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 uint32_t bmlen;
2929 int status;
2930
2931 status = decode_op_hdr(xdr, OP_CREATE);
2932 if (status)
2933 return status;
2934 if ((status = decode_change_info(xdr, cinfo)))
2935 return status;
2936 READ_BUF(4);
2937 READ32(bmlen);
2938 READ_BUF(bmlen << 2);
2939 return 0;
2940}
2941
2942static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2943{
Al Viro8687b632006-10-19 23:28:48 -07002944 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002945 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 int status;
2947
2948 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2949 goto xdr_error;
2950 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2951 goto xdr_error;
2952 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2953 goto xdr_error;
2954 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2955 goto xdr_error;
2956 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2957 goto xdr_error;
2958 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2959 goto xdr_error;
2960 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2961 goto xdr_error;
2962 status = verify_attr_len(xdr, savep, attrlen);
2963xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002964 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 return status;
2966}
Andy Adamson6c0195a2008-12-23 16:06:15 -05002967
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2969{
Al Viro8687b632006-10-19 23:28:48 -07002970 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002971 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002973
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2975 goto xdr_error;
2976 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2977 goto xdr_error;
2978 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2979 goto xdr_error;
2980
2981 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2982 goto xdr_error;
2983 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2984 goto xdr_error;
2985 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2986 goto xdr_error;
2987 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2988 goto xdr_error;
2989 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2990 goto xdr_error;
2991 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2992 goto xdr_error;
2993
2994 status = verify_attr_len(xdr, savep, attrlen);
2995xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002996 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 return status;
2998}
2999
3000static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3001{
Al Viro8687b632006-10-19 23:28:48 -07003002 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003003 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003005
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3007 goto xdr_error;
3008 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3009 goto xdr_error;
3010 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3011 goto xdr_error;
3012
3013 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3014 goto xdr_error;
3015 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3016 goto xdr_error;
3017
3018 status = verify_attr_len(xdr, savep, attrlen);
3019xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003020 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 return status;
3022}
3023
3024static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3025{
Al Viro8687b632006-10-19 23:28:48 -07003026 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 uint32_t attrlen,
3028 bitmap[2] = {0},
3029 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003030 int status;
3031 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003032 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003034 status = decode_op_hdr(xdr, OP_GETATTR);
3035 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 goto xdr_error;
3037
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003038 status = decode_attr_bitmap(xdr, bitmap);
3039 if (status < 0)
3040 goto xdr_error;
3041
3042 status = decode_attr_length(xdr, &attrlen, &savep);
3043 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 goto xdr_error;
3045
3046
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003047 status = decode_attr_type(xdr, bitmap, &type);
3048 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003050 fattr->mode = 0;
3051 if (status != 0) {
3052 fattr->mode |= nfs_type2fmt[type];
3053 fattr->valid |= status;
3054 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003056 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3057 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003059 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003060
3061 status = decode_attr_size(xdr, bitmap, &fattr->size);
3062 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003064 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003065
3066 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3067 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003069 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003070
3071 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3072 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003074 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003075
3076 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003077 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003078 fattr));
3079 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003080 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003081 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003082
3083 status = decode_attr_mode(xdr, bitmap, &fmode);
3084 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003086 if (status != 0) {
3087 fattr->mode |= fmode;
3088 fattr->valid |= status;
3089 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003090
3091 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3092 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003094 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003095
3096 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3097 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003099 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003100
3101 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3102 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003104 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003105
3106 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3107 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003109 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003110
3111 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3112 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003114 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003115
3116 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3117 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003119 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003120
3121 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3122 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003124 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003125
3126 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3127 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003129 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003130
3131 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3132 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003133 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003134 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003135 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003136 fattr->valid |= status;
3137 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003138
3139 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003141 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 return status;
3143}
3144
3145
3146static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3147{
Al Viro8687b632006-10-19 23:28:48 -07003148 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 uint32_t attrlen, bitmap[2];
3150 int status;
3151
3152 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3153 goto xdr_error;
3154 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3155 goto xdr_error;
3156 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3157 goto xdr_error;
3158
3159 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3160
3161 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3162 goto xdr_error;
3163 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3164 goto xdr_error;
3165 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3166 goto xdr_error;
3167 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3168 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3169 goto xdr_error;
3170 fsinfo->wtpref = fsinfo->wtmax;
3171
3172 status = verify_attr_len(xdr, savep, attrlen);
3173xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003174 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 return status;
3176}
3177
3178static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3179{
Al Viro8687b632006-10-19 23:28:48 -07003180 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 uint32_t len;
3182 int status;
3183
Trond Myklebust99367812007-07-17 21:52:41 -04003184 /* Zero handle first to allow comparisons */
3185 memset(fh, 0, sizeof(*fh));
3186
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 status = decode_op_hdr(xdr, OP_GETFH);
3188 if (status)
3189 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190
3191 READ_BUF(4);
3192 READ32(len);
3193 if (len > NFS4_FHSIZE)
3194 return -EIO;
3195 fh->size = len;
3196 READ_BUF(len);
3197 COPYMEM(fh->data, len);
3198 return 0;
3199}
3200
3201static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3202{
3203 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003204
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 status = decode_op_hdr(xdr, OP_LINK);
3206 if (status)
3207 return status;
3208 return decode_change_info(xdr, cinfo);
3209}
3210
3211/*
3212 * We create the owner, so we know a proper owner.id length is 4.
3213 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003214static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003216 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003217 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003218 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219
3220 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003221 READ64(offset);
3222 READ64(length);
3223 READ32(type);
3224 if (fl != NULL) {
3225 fl->fl_start = (loff_t)offset;
3226 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3227 if (length == ~(uint64_t)0)
3228 fl->fl_end = OFFSET_MAX;
3229 fl->fl_type = F_WRLCK;
3230 if (type & 1)
3231 fl->fl_type = F_RDLCK;
3232 fl->fl_pid = 0;
3233 }
3234 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 READ32(namelen);
3236 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 return -NFS4ERR_DENIED;
3238}
3239
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003240static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241{
Al Viro8687b632006-10-19 23:28:48 -07003242 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 int status;
3244
3245 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003246 if (status == -EIO)
3247 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003249 READ_BUF(NFS4_STATEID_SIZE);
3250 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003252 status = decode_lock_denied(xdr, NULL);
3253 if (res->open_seqid != NULL)
3254 nfs_increment_open_seqid(status, res->open_seqid);
3255 nfs_increment_lock_seqid(status, res->lock_seqid);
3256out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 return status;
3258}
3259
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003260static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261{
3262 int status;
3263 status = decode_op_hdr(xdr, OP_LOCKT);
3264 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003265 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 return status;
3267}
3268
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003269static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270{
Al Viro8687b632006-10-19 23:28:48 -07003271 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 int status;
3273
3274 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003275 if (status != -EIO)
3276 nfs_increment_lock_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003278 READ_BUF(NFS4_STATEID_SIZE);
3279 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 }
3281 return status;
3282}
3283
3284static int decode_lookup(struct xdr_stream *xdr)
3285{
3286 return decode_op_hdr(xdr, OP_LOOKUP);
3287}
3288
3289/* This is too sick! */
3290static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3291{
Andy Adamson05d564f2008-12-23 16:06:15 -05003292 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 uint32_t limit_type, nblocks, blocksize;
3294
3295 READ_BUF(12);
3296 READ32(limit_type);
3297 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003298 case 1:
3299 READ64(*maxsize);
3300 break;
3301 case 2:
3302 READ32(nblocks);
3303 READ32(blocksize);
3304 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 }
3306 return 0;
3307}
3308
3309static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3310{
Andy Adamson05d564f2008-12-23 16:06:15 -05003311 __be32 *p;
3312 uint32_t delegation_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313
3314 READ_BUF(4);
3315 READ32(delegation_type);
3316 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3317 res->delegation_type = 0;
3318 return 0;
3319 }
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003320 READ_BUF(NFS4_STATEID_SIZE+4);
3321 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 READ32(res->do_recall);
Andy Adamson05d564f2008-12-23 16:06:15 -05003323
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003325 case NFS4_OPEN_DELEGATE_READ:
3326 res->delegation_type = FMODE_READ;
3327 break;
3328 case NFS4_OPEN_DELEGATE_WRITE:
3329 res->delegation_type = FMODE_WRITE|FMODE_READ;
3330 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 return -EIO;
3332 }
David Howells7539bba2006-08-22 20:06:09 -04003333 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334}
3335
3336static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3337{
Andy Adamson05d564f2008-12-23 16:06:15 -05003338 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003339 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003340 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341
Andy Adamson05d564f2008-12-23 16:06:15 -05003342 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003343 if (status != -EIO)
3344 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003345 if (status)
3346 return status;
3347 READ_BUF(NFS4_STATEID_SIZE);
3348 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349
Andy Adamson05d564f2008-12-23 16:06:15 -05003350 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351
Andy Adamson05d564f2008-12-23 16:06:15 -05003352 READ_BUF(8);
3353 READ32(res->rflags);
3354 READ32(bmlen);
3355 if (bmlen > 10)
3356 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357
Andy Adamson05d564f2008-12-23 16:06:15 -05003358 READ_BUF(bmlen << 2);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003359 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3360 for (i = 0; i < savewords; ++i)
3361 READ32(res->attrset[i]);
3362 for (; i < NFS4_BITMAP_SIZE; i++)
3363 res->attrset[i] = 0;
3364
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 return decode_delegation(xdr, res);
3366xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003367 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 return -EIO;
3369}
3370
3371static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3372{
Andy Adamson05d564f2008-12-23 16:06:15 -05003373 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 int status;
3375
Andy Adamson05d564f2008-12-23 16:06:15 -05003376 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003377 if (status != -EIO)
3378 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003379 if (status)
3380 return status;
3381 READ_BUF(NFS4_STATEID_SIZE);
3382 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3383 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384}
3385
3386static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3387{
Al Viro8687b632006-10-19 23:28:48 -07003388 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 int status;
3390
3391 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003392 if (status != -EIO)
3393 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 if (status)
3395 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003396 READ_BUF(NFS4_STATEID_SIZE);
3397 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 return 0;
3399}
3400
3401static int decode_putfh(struct xdr_stream *xdr)
3402{
3403 return decode_op_hdr(xdr, OP_PUTFH);
3404}
3405
3406static int decode_putrootfh(struct xdr_stream *xdr)
3407{
3408 return decode_op_hdr(xdr, OP_PUTROOTFH);
3409}
3410
3411static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3412{
3413 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003414 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 uint32_t count, eof, recvd, hdrlen;
3416 int status;
3417
3418 status = decode_op_hdr(xdr, OP_READ);
3419 if (status)
3420 return status;
3421 READ_BUF(8);
3422 READ32(eof);
3423 READ32(count);
3424 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3425 recvd = req->rq_rcv_buf.len - hdrlen;
3426 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003427 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 "count %u > recvd %u\n", count, recvd);
3429 count = recvd;
3430 eof = 0;
3431 }
3432 xdr_read_pages(xdr, count);
3433 res->eof = eof;
3434 res->count = count;
3435 return 0;
3436}
3437
3438static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3439{
3440 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3441 struct page *page = *rcvbuf->pages;
3442 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003443 size_t hdrlen;
3444 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003445 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003446 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04003447 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448
3449 status = decode_op_hdr(xdr, OP_READDIR);
3450 if (status)
3451 return status;
3452 READ_BUF(8);
3453 COPYMEM(readdir->verifier.data, 8);
Fred Isaman44109242008-04-02 15:21:15 +03003454 dprintk("%s: verifier = %08x:%08x\n",
3455 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00003456 ((u32 *)readdir->verifier.data)[0],
3457 ((u32 *)readdir->verifier.data)[1]);
3458
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459
3460 hdrlen = (char *) p - (char *) iov->iov_base;
3461 recvd = rcvbuf->len - hdrlen;
3462 if (pglen > recvd)
3463 pglen = recvd;
3464 xdr_read_pages(xdr, pglen);
3465
3466 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003467 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003468 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003470
3471 /* Make sure the packet actually has a value_follows and EOF entry */
3472 if ((entry + 1) > end)
3473 goto short_pkt;
3474
3475 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003476 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04003477 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003479 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 p += 2; /* cookie */
3481 len = ntohl(*p++); /* filename length */
3482 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003483 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3484 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 goto err_unmap;
3486 }
David Howellse8896492006-08-24 15:44:19 -04003487 xlen = XDR_QUADLEN(len);
3488 if (end - p < xlen + 1)
3489 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003490 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003491 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003493 if (end - p < len + 1)
3494 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003497 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003499 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 entry = p;
3501 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003502 /*
3503 * Apparently some server sends responses that are a valid size, but
3504 * contain no entries, and have value_follows==0 and EOF==0. For
3505 * those, just set the EOF marker.
3506 */
3507 if (!nr && entry[1] == 0) {
3508 dprintk("NFS: readdir reply truncated!\n");
3509 entry[1] = 1;
3510 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05003511out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 kunmap_atomic(kaddr, KM_USER0);
3513 return 0;
3514short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003515 /*
3516 * When we get a short packet there are 2 possibilities. We can
3517 * return an error, or fix up the response to look like a valid
3518 * response and return what we have so far. If there are no
3519 * entries and the packet was short, then return -EIO. If there
3520 * are valid entries in the response, return them and pretend that
3521 * the call was successful, but incomplete. The caller can retry the
3522 * readdir starting at the last cookie.
3523 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07003524 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003526 if (nr)
3527 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528err_unmap:
3529 kunmap_atomic(kaddr, KM_USER0);
3530 return -errno_NFSERR_IO;
3531}
3532
3533static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3534{
3535 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3536 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003537 size_t hdrlen;
3538 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003539 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 char *kaddr;
3541 int status;
3542
3543 status = decode_op_hdr(xdr, OP_READLINK);
3544 if (status)
3545 return status;
3546
3547 /* Convert length of symlink */
3548 READ_BUF(4);
3549 READ32(len);
3550 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003551 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 return -ENAMETOOLONG;
3553 }
3554 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3555 recvd = req->rq_rcv_buf.len - hdrlen;
3556 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003557 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 "count %u > recvd %u\n", len, recvd);
3559 return -EIO;
3560 }
3561 xdr_read_pages(xdr, len);
3562 /*
3563 * The XDR encode routine has set things up so that
3564 * the link text will be copied directly into the
3565 * buffer. We just have to do overflow-checking,
3566 * and and null-terminate the text (the VFS expects
3567 * null-termination).
3568 */
3569 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3570 kaddr[len+rcvbuf->page_base] = '\0';
3571 kunmap_atomic(kaddr, KM_USER0);
3572 return 0;
3573}
3574
3575static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3576{
3577 int status;
3578
3579 status = decode_op_hdr(xdr, OP_REMOVE);
3580 if (status)
3581 goto out;
3582 status = decode_change_info(xdr, cinfo);
3583out:
3584 return status;
3585}
3586
3587static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3588 struct nfs4_change_info *new_cinfo)
3589{
3590 int status;
3591
3592 status = decode_op_hdr(xdr, OP_RENAME);
3593 if (status)
3594 goto out;
3595 if ((status = decode_change_info(xdr, old_cinfo)))
3596 goto out;
3597 status = decode_change_info(xdr, new_cinfo);
3598out:
3599 return status;
3600}
3601
3602static int decode_renew(struct xdr_stream *xdr)
3603{
3604 return decode_op_hdr(xdr, OP_RENEW);
3605}
3606
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003607static int
3608decode_restorefh(struct xdr_stream *xdr)
3609{
3610 return decode_op_hdr(xdr, OP_RESTOREFH);
3611}
3612
J. Bruce Fields029d1052005-06-22 17:16:22 +00003613static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3614 size_t *acl_len)
3615{
Al Viro8687b632006-10-19 23:28:48 -07003616 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003617 uint32_t attrlen,
3618 bitmap[2] = {0};
3619 struct kvec *iov = req->rq_rcv_buf.head;
3620 int status;
3621
3622 *acl_len = 0;
3623 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3624 goto out;
3625 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3626 goto out;
3627 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3628 goto out;
3629
3630 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3631 return -EIO;
3632 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003633 size_t hdrlen;
3634 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003635
3636 /* We ignore &savep and don't do consistency checks on
3637 * the attr length. Let userspace figure it out.... */
3638 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3639 recvd = req->rq_rcv_buf.len - hdrlen;
3640 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003641 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00003642 " acl reply: attrlen %u > recvd %u\n",
3643 attrlen, recvd);
3644 return -EINVAL;
3645 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04003646 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00003647 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04003648 } else
3649 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003650
3651out:
3652 return status;
3653}
3654
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655static int
3656decode_savefh(struct xdr_stream *xdr)
3657{
3658 return decode_op_hdr(xdr, OP_SAVEFH);
3659}
3660
Benny Halevy9e9ecc02009-04-01 09:22:00 -04003661static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662{
Al Viro8687b632006-10-19 23:28:48 -07003663 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664 uint32_t bmlen;
3665 int status;
3666
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 status = decode_op_hdr(xdr, OP_SETATTR);
3668 if (status)
3669 return status;
3670 READ_BUF(4);
3671 READ32(bmlen);
3672 READ_BUF(bmlen << 2);
3673 return 0;
3674}
3675
David Howellsadfa6f92006-08-22 20:06:08 -04003676static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677{
Al Viro8687b632006-10-19 23:28:48 -07003678 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 uint32_t opnum;
3680 int32_t nfserr;
3681
3682 READ_BUF(8);
3683 READ32(opnum);
3684 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003685 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05003686 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 return -EIO;
3688 }
3689 READ32(nfserr);
3690 if (nfserr == NFS_OK) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003691 READ_BUF(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 READ64(clp->cl_clientid);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003693 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 } else if (nfserr == NFSERR_CLID_INUSE) {
3695 uint32_t len;
3696
3697 /* skip netid string */
3698 READ_BUF(4);
3699 READ32(len);
3700 READ_BUF(len);
3701
3702 /* skip uaddr string */
3703 READ_BUF(4);
3704 READ32(len);
3705 READ_BUF(len);
3706 return -NFSERR_CLID_INUSE;
3707 } else
Benny Halevy856dff32008-03-31 17:39:06 +03003708 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709
3710 return 0;
3711}
3712
3713static int decode_setclientid_confirm(struct xdr_stream *xdr)
3714{
3715 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3716}
3717
3718static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3719{
Al Viro8687b632006-10-19 23:28:48 -07003720 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 int status;
3722
3723 status = decode_op_hdr(xdr, OP_WRITE);
3724 if (status)
3725 return status;
3726
3727 READ_BUF(16);
3728 READ32(res->count);
3729 READ32(res->verf->committed);
3730 COPYMEM(res->verf->verifier, 8);
3731 return 0;
3732}
3733
3734static int decode_delegreturn(struct xdr_stream *xdr)
3735{
3736 return decode_op_hdr(xdr, OP_DELEGRETURN);
3737}
3738
3739/*
Benny Halevy49c25592008-12-23 16:06:16 -05003740 * END OF "GENERIC" DECODE ROUTINES.
3741 */
3742
3743/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 * Decode OPEN_DOWNGRADE response
3745 */
Al Viro8687b632006-10-19 23:28:48 -07003746static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747{
Andy Adamson05d564f2008-12-23 16:06:15 -05003748 struct xdr_stream xdr;
3749 struct compound_hdr hdr;
3750 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751
Andy Adamson05d564f2008-12-23 16:06:15 -05003752 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3753 status = decode_compound_hdr(&xdr, &hdr);
3754 if (status)
3755 goto out;
3756 status = decode_putfh(&xdr);
3757 if (status)
3758 goto out;
3759 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003760 if (status != 0)
3761 goto out;
3762 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763out:
Andy Adamson05d564f2008-12-23 16:06:15 -05003764 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765}
3766
3767/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 * Decode ACCESS response
3769 */
Al Viro8687b632006-10-19 23:28:48 -07003770static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771{
3772 struct xdr_stream xdr;
3773 struct compound_hdr hdr;
3774 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003775
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3777 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3778 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04003779 status = decode_putfh(&xdr);
3780 if (status != 0)
3781 goto out;
3782 status = decode_access(&xdr, res);
3783 if (status != 0)
3784 goto out;
3785 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786out:
3787 return status;
3788}
3789
3790/*
3791 * Decode LOOKUP response
3792 */
Al Viro8687b632006-10-19 23:28:48 -07003793static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794{
3795 struct xdr_stream xdr;
3796 struct compound_hdr hdr;
3797 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003798
Linus Torvalds1da177e2005-04-16 15:20:36 -07003799 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3800 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3801 goto out;
3802 if ((status = decode_putfh(&xdr)) != 0)
3803 goto out;
3804 if ((status = decode_lookup(&xdr)) != 0)
3805 goto out;
3806 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3807 goto out;
3808 status = decode_getfattr(&xdr, res->fattr, res->server);
3809out:
3810 return status;
3811}
3812
3813/*
3814 * Decode LOOKUP_ROOT response
3815 */
Al Viro8687b632006-10-19 23:28:48 -07003816static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817{
3818 struct xdr_stream xdr;
3819 struct compound_hdr hdr;
3820 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003821
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3823 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3824 goto out;
3825 if ((status = decode_putrootfh(&xdr)) != 0)
3826 goto out;
3827 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3828 status = decode_getfattr(&xdr, res->fattr, res->server);
3829out:
3830 return status;
3831}
3832
3833/*
3834 * Decode REMOVE response
3835 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04003836static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837{
3838 struct xdr_stream xdr;
3839 struct compound_hdr hdr;
3840 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003841
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3843 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3844 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04003845 if ((status = decode_putfh(&xdr)) != 0)
3846 goto out;
3847 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3848 goto out;
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04003849 decode_getfattr(&xdr, &res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850out:
3851 return status;
3852}
3853
3854/*
3855 * Decode RENAME response
3856 */
Al Viro8687b632006-10-19 23:28:48 -07003857static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858{
3859 struct xdr_stream xdr;
3860 struct compound_hdr hdr;
3861 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003862
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3864 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3865 goto out;
3866 if ((status = decode_putfh(&xdr)) != 0)
3867 goto out;
3868 if ((status = decode_savefh(&xdr)) != 0)
3869 goto out;
3870 if ((status = decode_putfh(&xdr)) != 0)
3871 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04003872 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3873 goto out;
3874 /* Current FH is target directory */
3875 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3876 goto out;
3877 if ((status = decode_restorefh(&xdr)) != 0)
3878 goto out;
3879 decode_getfattr(&xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880out:
3881 return status;
3882}
3883
3884/*
3885 * Decode LINK response
3886 */
Al Viro8687b632006-10-19 23:28:48 -07003887static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888{
3889 struct xdr_stream xdr;
3890 struct compound_hdr hdr;
3891 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003892
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3894 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3895 goto out;
3896 if ((status = decode_putfh(&xdr)) != 0)
3897 goto out;
3898 if ((status = decode_savefh(&xdr)) != 0)
3899 goto out;
3900 if ((status = decode_putfh(&xdr)) != 0)
3901 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04003902 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3903 goto out;
3904 /*
3905 * Note order: OP_LINK leaves the directory as the current
3906 * filehandle.
3907 */
3908 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3909 goto out;
3910 if ((status = decode_restorefh(&xdr)) != 0)
3911 goto out;
3912 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913out:
3914 return status;
3915}
3916
3917/*
3918 * Decode CREATE response
3919 */
Al Viro8687b632006-10-19 23:28:48 -07003920static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921{
3922 struct xdr_stream xdr;
3923 struct compound_hdr hdr;
3924 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003925
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3927 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3928 goto out;
3929 if ((status = decode_putfh(&xdr)) != 0)
3930 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003931 if ((status = decode_savefh(&xdr)) != 0)
3932 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3934 goto out;
3935 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3936 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003937 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3938 goto out;
3939 if ((status = decode_restorefh(&xdr)) != 0)
3940 goto out;
3941 decode_getfattr(&xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942out:
3943 return status;
3944}
3945
3946/*
3947 * Decode SYMLINK response
3948 */
Al Viro8687b632006-10-19 23:28:48 -07003949static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950{
3951 return nfs4_xdr_dec_create(rqstp, p, res);
3952}
3953
3954/*
3955 * Decode GETATTR response
3956 */
Al Viro8687b632006-10-19 23:28:48 -07003957static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958{
3959 struct xdr_stream xdr;
3960 struct compound_hdr hdr;
3961 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003962
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3964 status = decode_compound_hdr(&xdr, &hdr);
3965 if (status)
3966 goto out;
3967 status = decode_putfh(&xdr);
3968 if (status)
3969 goto out;
3970 status = decode_getfattr(&xdr, res->fattr, res->server);
3971out:
3972 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973}
3974
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003975/*
3976 * Encode an SETACL request
3977 */
3978static int
Al Viro8687b632006-10-19 23:28:48 -07003979nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003980{
Andy Adamson05d564f2008-12-23 16:06:15 -05003981 struct xdr_stream xdr;
3982 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05003983 .nops = 0,
Andy Adamson05d564f2008-12-23 16:06:15 -05003984 };
3985 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003986
Andy Adamson05d564f2008-12-23 16:06:15 -05003987 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3988 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05003989 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05003990 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05003991 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05003992 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003993}
Andy Adamson05d564f2008-12-23 16:06:15 -05003994
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003995/*
3996 * Decode SETACL response
3997 */
3998static int
Benny Halevy73c403a2009-04-01 09:22:01 -04003999nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4000 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004001{
4002 struct xdr_stream xdr;
4003 struct compound_hdr hdr;
4004 int status;
4005
4006 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4007 status = decode_compound_hdr(&xdr, &hdr);
4008 if (status)
4009 goto out;
4010 status = decode_putfh(&xdr);
4011 if (status)
4012 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004013 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004014out:
4015 return status;
4016}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017
4018/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00004019 * Decode GETACL response
4020 */
4021static int
Benny Halevy663c79b2009-04-01 09:21:59 -04004022nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4023 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004024{
4025 struct xdr_stream xdr;
4026 struct compound_hdr hdr;
4027 int status;
4028
4029 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4030 status = decode_compound_hdr(&xdr, &hdr);
4031 if (status)
4032 goto out;
4033 status = decode_putfh(&xdr);
4034 if (status)
4035 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04004036 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004037
4038out:
4039 return status;
4040}
4041
4042/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 * Decode CLOSE response
4044 */
Al Viro8687b632006-10-19 23:28:48 -07004045static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046{
Andy Adamson05d564f2008-12-23 16:06:15 -05004047 struct xdr_stream xdr;
4048 struct compound_hdr hdr;
4049 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050
Andy Adamson05d564f2008-12-23 16:06:15 -05004051 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4052 status = decode_compound_hdr(&xdr, &hdr);
4053 if (status)
4054 goto out;
4055 status = decode_putfh(&xdr);
4056 if (status)
4057 goto out;
4058 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004059 if (status != 0)
4060 goto out;
4061 /*
4062 * Note: Server may do delete on close for this file
4063 * in which case the getattr call will fail with
4064 * an ESTALE error. Shouldn't be a problem,
4065 * though, since fattr->valid will remain unset.
4066 */
4067 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004069 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070}
4071
4072/*
4073 * Decode OPEN response
4074 */
Al Viro8687b632006-10-19 23:28:48 -07004075static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076{
Andy Adamson05d564f2008-12-23 16:06:15 -05004077 struct xdr_stream xdr;
4078 struct compound_hdr hdr;
4079 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080
Andy Adamson05d564f2008-12-23 16:06:15 -05004081 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4082 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004083 if (status)
4084 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004085 status = decode_putfh(&xdr);
4086 if (status)
4087 goto out;
4088 status = decode_savefh(&xdr);
4089 if (status)
4090 goto out;
4091 status = decode_open(&xdr, res);
4092 if (status)
4093 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04004094 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004096 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4097 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04004098 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004099 goto out;
4100 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004102 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103}
4104
4105/*
4106 * Decode OPEN_CONFIRM response
4107 */
Al Viro8687b632006-10-19 23:28:48 -07004108static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109{
Andy Adamson05d564f2008-12-23 16:06:15 -05004110 struct xdr_stream xdr;
4111 struct compound_hdr hdr;
4112 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113
Andy Adamson05d564f2008-12-23 16:06:15 -05004114 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4115 status = decode_compound_hdr(&xdr, &hdr);
4116 if (status)
4117 goto out;
4118 status = decode_putfh(&xdr);
4119 if (status)
4120 goto out;
4121 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004123 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124}
4125
4126/*
4127 * Decode OPEN response
4128 */
Al Viro8687b632006-10-19 23:28:48 -07004129static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130{
Andy Adamson05d564f2008-12-23 16:06:15 -05004131 struct xdr_stream xdr;
4132 struct compound_hdr hdr;
4133 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134
Andy Adamson05d564f2008-12-23 16:06:15 -05004135 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4136 status = decode_compound_hdr(&xdr, &hdr);
4137 if (status)
4138 goto out;
4139 status = decode_putfh(&xdr);
4140 if (status)
4141 goto out;
4142 status = decode_open(&xdr, res);
4143 if (status)
4144 goto out;
Trond Myklebust864472e2006-01-03 09:55:15 +01004145 decode_getfattr(&xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004147 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148}
4149
4150/*
4151 * Decode SETATTR response
4152 */
Al Viro8687b632006-10-19 23:28:48 -07004153static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154{
Andy Adamson05d564f2008-12-23 16:06:15 -05004155 struct xdr_stream xdr;
4156 struct compound_hdr hdr;
4157 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158
Andy Adamson05d564f2008-12-23 16:06:15 -05004159 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4160 status = decode_compound_hdr(&xdr, &hdr);
4161 if (status)
4162 goto out;
4163 status = decode_putfh(&xdr);
4164 if (status)
4165 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004166 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004167 if (status)
4168 goto out;
Trond Myklebust78f945f2009-03-11 14:10:23 -04004169 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004171 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172}
4173
4174/*
4175 * Decode LOCK response
4176 */
Al Viro8687b632006-10-19 23:28:48 -07004177static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178{
4179 struct xdr_stream xdr;
4180 struct compound_hdr hdr;
4181 int status;
4182
4183 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4184 status = decode_compound_hdr(&xdr, &hdr);
4185 if (status)
4186 goto out;
4187 status = decode_putfh(&xdr);
4188 if (status)
4189 goto out;
4190 status = decode_lock(&xdr, res);
4191out:
4192 return status;
4193}
4194
4195/*
4196 * Decode LOCKT response
4197 */
Al Viro8687b632006-10-19 23:28:48 -07004198static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199{
4200 struct xdr_stream xdr;
4201 struct compound_hdr hdr;
4202 int status;
4203
4204 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4205 status = decode_compound_hdr(&xdr, &hdr);
4206 if (status)
4207 goto out;
4208 status = decode_putfh(&xdr);
4209 if (status)
4210 goto out;
4211 status = decode_lockt(&xdr, res);
4212out:
4213 return status;
4214}
4215
4216/*
4217 * Decode LOCKU response
4218 */
Al Viro8687b632006-10-19 23:28:48 -07004219static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220{
4221 struct xdr_stream xdr;
4222 struct compound_hdr hdr;
4223 int status;
4224
4225 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4226 status = decode_compound_hdr(&xdr, &hdr);
4227 if (status)
4228 goto out;
4229 status = decode_putfh(&xdr);
4230 if (status)
4231 goto out;
4232 status = decode_locku(&xdr, res);
4233out:
4234 return status;
4235}
4236
4237/*
4238 * Decode READLINK response
4239 */
Benny Halevyf50c7002009-04-01 09:21:55 -04004240static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4241 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242{
4243 struct xdr_stream xdr;
4244 struct compound_hdr hdr;
4245 int status;
4246
4247 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4248 status = decode_compound_hdr(&xdr, &hdr);
4249 if (status)
4250 goto out;
4251 status = decode_putfh(&xdr);
4252 if (status)
4253 goto out;
4254 status = decode_readlink(&xdr, rqstp);
4255out:
4256 return status;
4257}
4258
4259/*
4260 * Decode READDIR response
4261 */
Al Viro8687b632006-10-19 23:28:48 -07004262static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263{
4264 struct xdr_stream xdr;
4265 struct compound_hdr hdr;
4266 int status;
4267
4268 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4269 status = decode_compound_hdr(&xdr, &hdr);
4270 if (status)
4271 goto out;
4272 status = decode_putfh(&xdr);
4273 if (status)
4274 goto out;
4275 status = decode_readdir(&xdr, rqstp, res);
4276out:
4277 return status;
4278}
4279
4280/*
4281 * Decode Read response
4282 */
Al Viro8687b632006-10-19 23:28:48 -07004283static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284{
4285 struct xdr_stream xdr;
4286 struct compound_hdr hdr;
4287 int status;
4288
4289 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4290 status = decode_compound_hdr(&xdr, &hdr);
4291 if (status)
4292 goto out;
4293 status = decode_putfh(&xdr);
4294 if (status)
4295 goto out;
4296 status = decode_read(&xdr, rqstp, res);
4297 if (!status)
4298 status = res->count;
4299out:
4300 return status;
4301}
4302
4303/*
4304 * Decode WRITE response
4305 */
Al Viro8687b632006-10-19 23:28:48 -07004306static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307{
4308 struct xdr_stream xdr;
4309 struct compound_hdr hdr;
4310 int status;
4311
4312 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4313 status = decode_compound_hdr(&xdr, &hdr);
4314 if (status)
4315 goto out;
4316 status = decode_putfh(&xdr);
4317 if (status)
4318 goto out;
4319 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004320 if (status)
4321 goto out;
4322 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 if (!status)
4324 status = res->count;
4325out:
4326 return status;
4327}
4328
4329/*
4330 * Decode COMMIT response
4331 */
Al Viro8687b632006-10-19 23:28:48 -07004332static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333{
4334 struct xdr_stream xdr;
4335 struct compound_hdr hdr;
4336 int status;
4337
4338 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4339 status = decode_compound_hdr(&xdr, &hdr);
4340 if (status)
4341 goto out;
4342 status = decode_putfh(&xdr);
4343 if (status)
4344 goto out;
4345 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004346 if (status)
4347 goto out;
4348 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349out:
4350 return status;
4351}
4352
4353/*
4354 * FSINFO request
4355 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04004356static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
4357 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358{
4359 struct xdr_stream xdr;
4360 struct compound_hdr hdr;
4361 int status;
4362
4363 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4364 status = decode_compound_hdr(&xdr, &hdr);
4365 if (!status)
4366 status = decode_putfh(&xdr);
4367 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04004368 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369 return status;
4370}
4371
4372/*
4373 * PATHCONF request
4374 */
Benny Halevyd45b2982009-04-01 09:21:58 -04004375static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
4376 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377{
4378 struct xdr_stream xdr;
4379 struct compound_hdr hdr;
4380 int status;
4381
4382 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4383 status = decode_compound_hdr(&xdr, &hdr);
4384 if (!status)
4385 status = decode_putfh(&xdr);
4386 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04004387 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388 return status;
4389}
4390
4391/*
4392 * STATFS request
4393 */
Benny Halevy24ad1482009-04-01 09:21:56 -04004394static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
4395 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396{
4397 struct xdr_stream xdr;
4398 struct compound_hdr hdr;
4399 int status;
4400
4401 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4402 status = decode_compound_hdr(&xdr, &hdr);
4403 if (!status)
4404 status = decode_putfh(&xdr);
4405 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04004406 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407 return status;
4408}
4409
4410/*
4411 * GETATTR_BITMAP request
4412 */
Al Viro8687b632006-10-19 23:28:48 -07004413static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414{
4415 struct xdr_stream xdr;
4416 struct compound_hdr hdr;
4417 int status;
4418
4419 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4420 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4421 goto out;
4422 if ((status = decode_putfh(&xdr)) != 0)
4423 goto out;
4424 status = decode_server_caps(&xdr, res);
4425out:
4426 return status;
4427}
4428
4429/*
4430 * Decode RENEW response
4431 */
Al Viro8687b632006-10-19 23:28:48 -07004432static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433{
4434 struct xdr_stream xdr;
4435 struct compound_hdr hdr;
4436 int status;
4437
4438 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4439 status = decode_compound_hdr(&xdr, &hdr);
4440 if (!status)
4441 status = decode_renew(&xdr);
4442 return status;
4443}
4444
4445/*
4446 * a SETCLIENTID request
4447 */
Al Viro8687b632006-10-19 23:28:48 -07004448static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04004449 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450{
4451 struct xdr_stream xdr;
4452 struct compound_hdr hdr;
4453 int status;
4454
4455 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4456 status = decode_compound_hdr(&xdr, &hdr);
4457 if (!status)
4458 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004459 return status;
4460}
4461
4462/*
4463 * a SETCLIENTID_CONFIRM request
4464 */
Al Viro8687b632006-10-19 23:28:48 -07004465static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466{
4467 struct xdr_stream xdr;
4468 struct compound_hdr hdr;
4469 int status;
4470
4471 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4472 status = decode_compound_hdr(&xdr, &hdr);
4473 if (!status)
4474 status = decode_setclientid_confirm(&xdr);
4475 if (!status)
4476 status = decode_putrootfh(&xdr);
4477 if (!status)
4478 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004479 return status;
4480}
4481
4482/*
4483 * DELEGRETURN request
4484 */
Al Viro8687b632006-10-19 23:28:48 -07004485static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486{
4487 struct xdr_stream xdr;
4488 struct compound_hdr hdr;
4489 int status;
4490
4491 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4492 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01004493 if (status != 0)
4494 goto out;
4495 status = decode_putfh(&xdr);
4496 if (status != 0)
4497 goto out;
4498 status = decode_delegreturn(&xdr);
4499 decode_getfattr(&xdr, res->fattr, res->server);
4500out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004501 return status;
4502}
4503
Trond Myklebust683b57b2006-06-09 09:34:22 -04004504/*
4505 * FS_LOCATIONS request
4506 */
Al Viro8687b632006-10-19 23:28:48 -07004507static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004508{
4509 struct xdr_stream xdr;
4510 struct compound_hdr hdr;
4511 int status;
4512
4513 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4514 status = decode_compound_hdr(&xdr, &hdr);
4515 if (status != 0)
4516 goto out;
4517 if ((status = decode_putfh(&xdr)) != 0)
4518 goto out;
4519 if ((status = decode_lookup(&xdr)) != 0)
4520 goto out;
4521 xdr_enter_page(&xdr, PAGE_SIZE);
4522 status = decode_getfattr(&xdr, &res->fattr, res->server);
4523out:
4524 return status;
4525}
4526
Al Viro0dbb4c62006-10-19 23:28:49 -07004527__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528{
4529 uint32_t bitmap[2] = {0};
4530 uint32_t len;
4531
4532 if (!*p++) {
4533 if (!*p)
4534 return ERR_PTR(-EAGAIN);
4535 entry->eof = 1;
4536 return ERR_PTR(-EBADCOOKIE);
4537 }
4538
4539 entry->prev_cookie = entry->cookie;
4540 p = xdr_decode_hyper(p, &entry->cookie);
4541 entry->len = ntohl(*p++);
4542 entry->name = (const char *) p;
4543 p += XDR_QUADLEN(entry->len);
4544
4545 /*
4546 * In case the server doesn't return an inode number,
4547 * we fake one here. (We don't use inode number 0,
4548 * since glibc seems to choke on it...)
4549 */
4550 entry->ino = 1;
4551
4552 len = ntohl(*p++); /* bitmap length */
4553 if (len-- > 0) {
4554 bitmap[0] = ntohl(*p++);
4555 if (len-- > 0) {
4556 bitmap[1] = ntohl(*p++);
4557 p += len;
4558 }
4559 }
4560 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4561 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00004562 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4563 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4564 /* Ignore the return value of rdattr_error for now */
4565 p++;
4566 len--;
4567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4569 xdr_decode_hyper(p, &entry->ino);
4570 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4571 xdr_decode_hyper(p, &entry->ino);
4572 p += len;
4573 }
4574
4575 entry->eof = !p[0] && p[1];
4576 return p;
4577}
4578
4579/*
4580 * We need to translate between nfs status return values and
4581 * the local errno values which may not be the same.
4582 */
4583static struct {
4584 int stat;
4585 int errno;
4586} nfs_errtbl[] = {
4587 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03004588 { NFS4ERR_PERM, -EPERM },
4589 { NFS4ERR_NOENT, -ENOENT },
4590 { NFS4ERR_IO, -errno_NFSERR_IO},
4591 { NFS4ERR_NXIO, -ENXIO },
4592 { NFS4ERR_ACCESS, -EACCES },
4593 { NFS4ERR_EXIST, -EEXIST },
4594 { NFS4ERR_XDEV, -EXDEV },
4595 { NFS4ERR_NOTDIR, -ENOTDIR },
4596 { NFS4ERR_ISDIR, -EISDIR },
4597 { NFS4ERR_INVAL, -EINVAL },
4598 { NFS4ERR_FBIG, -EFBIG },
4599 { NFS4ERR_NOSPC, -ENOSPC },
4600 { NFS4ERR_ROFS, -EROFS },
4601 { NFS4ERR_MLINK, -EMLINK },
4602 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4603 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4604 { NFS4ERR_DQUOT, -EDQUOT },
4605 { NFS4ERR_STALE, -ESTALE },
4606 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4607 { NFS4ERR_BADOWNER, -EINVAL },
4608 { NFS4ERR_BADNAME, -EINVAL },
4609 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4610 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4611 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4612 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4613 { NFS4ERR_BADTYPE, -EBADTYPE },
4614 { NFS4ERR_LOCKED, -EAGAIN },
4615 { NFS4ERR_RESOURCE, -EREMOTEIO },
4616 { NFS4ERR_SYMLINK, -ELOOP },
4617 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
4618 { NFS4ERR_DEADLOCK, -EDEADLK },
4619 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07004620 * to be handled by a
4621 * middle-layer.
4622 */
Benny Halevy856dff32008-03-31 17:39:06 +03004623 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624};
4625
4626/*
4627 * Convert an NFS error code to a local one.
4628 * This one is used jointly by NFSv2 and NFSv3.
4629 */
4630static int
David Howells0a8ea432006-08-22 20:06:08 -04004631nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632{
4633 int i;
4634 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4635 if (nfs_errtbl[i].stat == stat)
4636 return nfs_errtbl[i].errno;
4637 }
4638 if (stat <= 10000 || stat > 10100) {
4639 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03004640 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641 }
4642 /* If we cannot translate the error, the recovery routines should
4643 * handle it.
4644 * Note: remaining NFSv4 error codes have values > 10000, so should
4645 * not conflict with native Linux error codes.
4646 */
Benny Halevy856dff32008-03-31 17:39:06 +03004647 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648}
4649
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650#define PROC(proc, argtype, restype) \
4651[NFSPROC4_CLNT_##proc] = { \
4652 .p_proc = NFSPROC4_COMPOUND, \
4653 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4654 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04004655 .p_arglen = NFS4_##argtype##_sz, \
4656 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05004657 .p_statidx = NFSPROC4_CLNT_##proc, \
4658 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05004659}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660
4661struct rpc_procinfo nfs4_procedures[] = {
4662 PROC(READ, enc_read, dec_read),
4663 PROC(WRITE, enc_write, dec_write),
4664 PROC(COMMIT, enc_commit, dec_commit),
4665 PROC(OPEN, enc_open, dec_open),
4666 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4667 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4668 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4669 PROC(CLOSE, enc_close, dec_close),
4670 PROC(SETATTR, enc_setattr, dec_setattr),
4671 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4672 PROC(RENEW, enc_renew, dec_renew),
4673 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4674 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4675 PROC(LOCK, enc_lock, dec_lock),
4676 PROC(LOCKT, enc_lockt, dec_lockt),
4677 PROC(LOCKU, enc_locku, dec_locku),
4678 PROC(ACCESS, enc_access, dec_access),
4679 PROC(GETATTR, enc_getattr, dec_getattr),
4680 PROC(LOOKUP, enc_lookup, dec_lookup),
4681 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4682 PROC(REMOVE, enc_remove, dec_remove),
4683 PROC(RENAME, enc_rename, dec_rename),
4684 PROC(LINK, enc_link, dec_link),
4685 PROC(SYMLINK, enc_symlink, dec_symlink),
4686 PROC(CREATE, enc_create, dec_create),
4687 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4688 PROC(STATFS, enc_statfs, dec_statfs),
4689 PROC(READLINK, enc_readlink, dec_readlink),
4690 PROC(READDIR, enc_readdir, dec_readdir),
4691 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4692 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00004693 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004694 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04004695 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004696};
4697
4698struct rpc_version nfs_version4 = {
4699 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08004700 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701 .procs = nfs4_procedures
4702};
4703
4704/*
4705 * Local variables:
4706 * c-basic-offset: 8
4707 * End:
4708 */