blob: d1e4c8f8a0a9e8b5106564cf71986579340efa77 [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
525static struct {
526 unsigned int mode;
527 unsigned int nfs2type;
528} nfs_type2fmt[] = {
529 { 0, NFNON },
530 { S_IFREG, NFREG },
531 { S_IFDIR, NFDIR },
532 { S_IFBLK, NFBLK },
533 { S_IFCHR, NFCHR },
534 { S_IFLNK, NFLNK },
535 { S_IFSOCK, NFSOCK },
536 { S_IFIFO, NFFIFO },
537 { 0, NFNON },
538 { 0, NFNON },
539};
540
541struct compound_hdr {
542 int32_t status;
543 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500544 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 uint32_t taglen;
546 char * tag;
547};
548
549/*
550 * START OF "GENERIC" ENCODE ROUTINES.
551 * These may look a little ugly since they are imported from a "generic"
552 * set of XDR encode/decode routines which are intended to be shared by
553 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
554 *
555 * If the pain of reading these is too great, it should be a straightforward
556 * task to translate them into Linux-specific versions which are more
557 * consistent with the style used in NFSv2/v3...
558 */
559#define WRITE32(n) *p++ = htonl(n)
560#define WRITE64(n) do { \
561 *p++ = htonl((uint32_t)((n) >> 32)); \
562 *p++ = htonl((uint32_t)(n)); \
563} while (0)
564#define WRITEMEM(ptr,nbytes) do { \
565 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
566} while (0)
567
568#define RESERVE_SPACE(nbytes) do { \
569 p = xdr_reserve_space(xdr, nbytes); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 BUG_ON(!p); \
571} while (0)
572
573static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
574{
Al Viro8687b632006-10-19 23:28:48 -0700575 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 p = xdr_reserve_space(xdr, 4 + len);
578 BUG_ON(p == NULL);
579 xdr_encode_opaque(p, str, len);
580}
581
Andy Adamsond0179312008-12-23 16:06:17 -0500582static void encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583{
Al Viro8687b632006-10-19 23:28:48 -0700584 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
587 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
588 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
589 WRITE32(hdr->taglen);
590 WRITEMEM(hdr->tag, hdr->taglen);
591 WRITE32(NFS4_MINOR_VERSION);
Andy Adamsond0179312008-12-23 16:06:17 -0500592 hdr->nops_p = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 WRITE32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500594}
595
596static void encode_nops(struct compound_hdr *hdr)
597{
598 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
601static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
602{
Al Viro8687b632006-10-19 23:28:48 -0700603 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
606 BUG_ON(p == NULL);
607 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
608}
609
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500610static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
612 char owner_name[IDMAP_NAMESZ];
613 char owner_group[IDMAP_NAMESZ];
614 int owner_namelen = 0;
615 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700616 __be32 *p;
617 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 int len;
619 uint32_t bmval0 = 0;
620 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 /*
623 * We reserve enough space to write the entire attribute buffer at once.
624 * In the worst-case, this would be
625 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
626 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000627 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 */
629 len = 16;
630
631 /* Sigh */
632 if (iap->ia_valid & ATTR_SIZE)
633 len += 8;
634 if (iap->ia_valid & ATTR_MODE)
635 len += 4;
636 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400637 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400639 dprintk("nfs: couldn't resolve uid %d to string\n",
640 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 /* XXX */
642 strcpy(owner_name, "nobody");
643 owner_namelen = sizeof("nobody") - 1;
644 /* goto out; */
645 }
646 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
647 }
648 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400649 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400651 dprintk("nfs: couldn't resolve gid %d to string\n",
652 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 strcpy(owner_group, "nobody");
654 owner_grouplen = sizeof("nobody") - 1;
655 /* goto out; */
656 }
657 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
658 }
659 if (iap->ia_valid & ATTR_ATIME_SET)
660 len += 16;
661 else if (iap->ia_valid & ATTR_ATIME)
662 len += 4;
663 if (iap->ia_valid & ATTR_MTIME_SET)
664 len += 16;
665 else if (iap->ia_valid & ATTR_MTIME)
666 len += 4;
667 RESERVE_SPACE(len);
668
669 /*
670 * We write the bitmap length now, but leave the bitmap and the attribute
671 * buffer length to be backfilled at the end of this routine.
672 */
673 WRITE32(2);
674 q = p;
675 p += 3;
676
677 if (iap->ia_valid & ATTR_SIZE) {
678 bmval0 |= FATTR4_WORD0_SIZE;
679 WRITE64(iap->ia_size);
680 }
681 if (iap->ia_valid & ATTR_MODE) {
682 bmval1 |= FATTR4_WORD1_MODE;
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100683 WRITE32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
685 if (iap->ia_valid & ATTR_UID) {
686 bmval1 |= FATTR4_WORD1_OWNER;
687 WRITE32(owner_namelen);
688 WRITEMEM(owner_name, owner_namelen);
689 }
690 if (iap->ia_valid & ATTR_GID) {
691 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
692 WRITE32(owner_grouplen);
693 WRITEMEM(owner_group, owner_grouplen);
694 }
695 if (iap->ia_valid & ATTR_ATIME_SET) {
696 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
697 WRITE32(NFS4_SET_TO_CLIENT_TIME);
698 WRITE32(0);
699 WRITE32(iap->ia_mtime.tv_sec);
700 WRITE32(iap->ia_mtime.tv_nsec);
701 }
702 else if (iap->ia_valid & ATTR_ATIME) {
703 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
704 WRITE32(NFS4_SET_TO_SERVER_TIME);
705 }
706 if (iap->ia_valid & ATTR_MTIME_SET) {
707 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
708 WRITE32(NFS4_SET_TO_CLIENT_TIME);
709 WRITE32(0);
710 WRITE32(iap->ia_mtime.tv_sec);
711 WRITE32(iap->ia_mtime.tv_nsec);
712 }
713 else if (iap->ia_valid & ATTR_MTIME) {
714 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
715 WRITE32(NFS4_SET_TO_SERVER_TIME);
716 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 /*
719 * Now we backfill the bitmap and the attribute buffer length.
720 */
721 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400722 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 len, ((char *)p - (char *)q) + 4);
724 BUG();
725 }
726 len = (char *)p - (char *)q - 12;
727 *q++ = htonl(bmval0);
728 *q++ = htonl(bmval1);
729 *q++ = htonl(len);
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732}
733
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500734static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Al Viro8687b632006-10-19 23:28:48 -0700736 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 RESERVE_SPACE(8);
739 WRITE32(OP_ACCESS);
740 WRITE32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500741 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
743
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500744static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745{
Al Viro8687b632006-10-19 23:28:48 -0700746 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400748 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 WRITE32(OP_CLOSE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700750 WRITE32(arg->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400751 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500752 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753}
754
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500755static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756{
Al Viro8687b632006-10-19 23:28:48 -0700757 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500758
Andy Adamson05d564f2008-12-23 16:06:15 -0500759 RESERVE_SPACE(16);
760 WRITE32(OP_COMMIT);
761 WRITE64(args->offset);
762 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500763 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764}
765
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500766static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
Al Viro8687b632006-10-19 23:28:48 -0700768 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 RESERVE_SPACE(8);
771 WRITE32(OP_CREATE);
772 WRITE32(create->ftype);
773
774 switch (create->ftype) {
775 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400776 RESERVE_SPACE(4);
777 WRITE32(create->u.symlink.len);
778 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 break;
780
781 case NF4BLK: case NF4CHR:
782 RESERVE_SPACE(8);
783 WRITE32(create->u.device.specdata1);
784 WRITE32(create->u.device.specdata2);
785 break;
786
787 default:
788 break;
789 }
790
791 RESERVE_SPACE(4 + create->name->len);
792 WRITE32(create->name->len);
793 WRITEMEM(create->name->name, create->name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500794 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500796 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797}
798
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500799static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800{
Andy Adamson05d564f2008-12-23 16:06:15 -0500801 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Andy Adamson05d564f2008-12-23 16:06:15 -0500803 RESERVE_SPACE(12);
804 WRITE32(OP_GETATTR);
805 WRITE32(1);
806 WRITE32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500807 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808}
809
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500810static 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 -0700811{
Andy Adamson05d564f2008-12-23 16:06:15 -0500812 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Andy Adamson05d564f2008-12-23 16:06:15 -0500814 RESERVE_SPACE(16);
815 WRITE32(OP_GETATTR);
816 WRITE32(2);
817 WRITE32(bm0);
818 WRITE32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500819 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820}
821
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500822static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500824 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
825 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826}
827
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500828static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500830 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
831 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832}
833
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500834static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -0400835{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500836 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
837 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -0400838}
839
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500840static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
Al Viro8687b632006-10-19 23:28:48 -0700842 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
844 RESERVE_SPACE(4);
845 WRITE32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -0500846 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847}
848
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500849static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850{
Al Viro8687b632006-10-19 23:28:48 -0700851 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 RESERVE_SPACE(8 + name->len);
854 WRITE32(OP_LINK);
855 WRITE32(name->len);
856 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500857 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858}
859
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100860static inline int nfs4_lock_type(struct file_lock *fl, int block)
861{
862 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
863 return block ? NFS4_READW_LT : NFS4_READ_LT;
864 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
865}
866
867static inline uint64_t nfs4_lock_length(struct file_lock *fl)
868{
869 if (fl->fl_end == OFFSET_MAX)
870 return ~(uint64_t)0;
871 return fl->fl_end - fl->fl_start + 1;
872}
873
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874/*
875 * opcode,type,reclaim,offset,length,new_lock_owner = 32
876 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
877 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500878static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
Al Viro8687b632006-10-19 23:28:48 -0700880 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
882 RESERVE_SPACE(32);
883 WRITE32(OP_LOCK);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100884 WRITE32(nfs4_lock_type(args->fl, args->block));
885 WRITE32(args->reclaim);
886 WRITE64(args->fl->fl_start);
887 WRITE64(nfs4_lock_length(args->fl));
888 WRITE32(args->new_lock_owner);
889 if (args->new_lock_owner){
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400890 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100891 WRITE32(args->open_seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400892 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100893 WRITE32(args->lock_seqid->sequence->counter);
894 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400895 WRITE32(16);
896 WRITEMEM("lock id:", 8);
897 WRITE64(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899 else {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400900 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
901 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100902 WRITE32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 }
Andy Adamsond0179312008-12-23 16:06:17 -0500904 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905}
906
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500907static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
Al Viro8687b632006-10-19 23:28:48 -0700909 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400911 RESERVE_SPACE(52);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 WRITE32(OP_LOCKT);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100913 WRITE32(nfs4_lock_type(args->fl, 0));
914 WRITE64(args->fl->fl_start);
915 WRITE64(nfs4_lock_length(args->fl));
916 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400917 WRITE32(16);
918 WRITEMEM("lock id:", 8);
919 WRITE64(args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -0500920 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921}
922
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500923static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924{
Al Viro8687b632006-10-19 23:28:48 -0700925 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400927 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 WRITE32(OP_LOCKU);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100929 WRITE32(nfs4_lock_type(args->fl, 0));
930 WRITE32(args->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400931 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100932 WRITE64(args->fl->fl_start);
933 WRITE64(nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -0500934 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935}
936
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500937static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
939 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -0700940 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 RESERVE_SPACE(8 + len);
943 WRITE32(OP_LOOKUP);
944 WRITE32(len);
945 WRITEMEM(name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -0500946 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
948
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500949static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
Al Viro8687b632006-10-19 23:28:48 -0700951 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
953 RESERVE_SPACE(8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500954 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -0500955 case FMODE_READ:
956 WRITE32(NFS4_SHARE_ACCESS_READ);
957 break;
958 case FMODE_WRITE:
959 WRITE32(NFS4_SHARE_ACCESS_WRITE);
960 break;
961 case FMODE_READ|FMODE_WRITE:
962 WRITE32(NFS4_SHARE_ACCESS_BOTH);
963 break;
964 default:
965 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 }
967 WRITE32(0); /* for linux, share_deny = 0 always */
968}
969
970static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
971{
Al Viro8687b632006-10-19 23:28:48 -0700972 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 /*
974 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
975 * owner 4 = 32
976 */
977 RESERVE_SPACE(8);
978 WRITE32(OP_OPEN);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700979 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500980 encode_share_access(xdr, arg->fmode);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400981 RESERVE_SPACE(28);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 WRITE64(arg->clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400983 WRITE32(16);
984 WRITEMEM("open id:", 8);
985 WRITE64(arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986}
987
988static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
989{
Al Viro8687b632006-10-19 23:28:48 -0700990 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
992 RESERVE_SPACE(4);
993 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -0500994 case 0:
995 WRITE32(NFS4_CREATE_UNCHECKED);
996 encode_attrs(xdr, arg->u.attrs, arg->server);
997 break;
998 default:
999 WRITE32(NFS4_CREATE_EXCLUSIVE);
1000 encode_nfs4_verifier(xdr, &arg->u.verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 }
1002}
1003
1004static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1005{
Al Viro8687b632006-10-19 23:28:48 -07001006 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
1008 RESERVE_SPACE(4);
1009 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001010 case 0:
1011 WRITE32(NFS4_OPEN_NOCREATE);
1012 break;
1013 default:
1014 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1015 WRITE32(NFS4_OPEN_CREATE);
1016 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 }
1018}
1019
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001020static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021{
Al Viro8687b632006-10-19 23:28:48 -07001022 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 RESERVE_SPACE(4);
1025 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001026 case 0:
1027 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1028 break;
1029 case FMODE_READ:
1030 WRITE32(NFS4_OPEN_DELEGATE_READ);
1031 break;
1032 case FMODE_WRITE|FMODE_READ:
1033 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1034 break;
1035 default:
1036 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
1038}
1039
1040static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1041{
Al Viro8687b632006-10-19 23:28:48 -07001042 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044 RESERVE_SPACE(4);
1045 WRITE32(NFS4_OPEN_CLAIM_NULL);
1046 encode_string(xdr, name->len, name->name);
1047}
1048
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001049static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050{
Al Viro8687b632006-10-19 23:28:48 -07001051 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
1053 RESERVE_SPACE(4);
1054 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1055 encode_delegation_type(xdr, type);
1056}
1057
1058static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1059{
Al Viro8687b632006-10-19 23:28:48 -07001060 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001062 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001064 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 encode_string(xdr, name->len, name->name);
1066}
1067
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001068static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
1070 encode_openhdr(xdr, arg);
1071 encode_opentype(xdr, arg);
1072 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001073 case NFS4_OPEN_CLAIM_NULL:
1074 encode_claim_null(xdr, arg->name);
1075 break;
1076 case NFS4_OPEN_CLAIM_PREVIOUS:
1077 encode_claim_previous(xdr, arg->u.delegation_type);
1078 break;
1079 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1080 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1081 break;
1082 default:
1083 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 }
Andy Adamsond0179312008-12-23 16:06:17 -05001085 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086}
1087
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001088static 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 -07001089{
Al Viro8687b632006-10-19 23:28:48 -07001090 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001092 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 WRITE32(OP_OPEN_CONFIRM);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001094 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001095 WRITE32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001096 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097}
1098
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001099static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100{
Al Viro8687b632006-10-19 23:28:48 -07001101 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001103 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 WRITE32(OP_OPEN_DOWNGRADE);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001105 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001106 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001107 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001108 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109}
1110
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001111static void
Andy Adamsond0179312008-12-23 16:06:17 -05001112encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113{
1114 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001115 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
1117 RESERVE_SPACE(8 + len);
1118 WRITE32(OP_PUTFH);
1119 WRITE32(len);
1120 WRITEMEM(fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001121 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122}
1123
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001124static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
Andy Adamson05d564f2008-12-23 16:06:15 -05001126 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001127
Andy Adamson05d564f2008-12-23 16:06:15 -05001128 RESERVE_SPACE(4);
1129 WRITE32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001130 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131}
1132
1133static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1134{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001136 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001138 RESERVE_SPACE(NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 if (ctx->state != NULL) {
1140 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001141 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 } else
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001143 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001146static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147{
Al Viro8687b632006-10-19 23:28:48 -07001148 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
1150 RESERVE_SPACE(4);
1151 WRITE32(OP_READ);
1152
1153 encode_stateid(xdr, args->context);
1154
1155 RESERVE_SPACE(12);
1156 WRITE64(args->offset);
1157 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001158 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159}
1160
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001161static 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 -07001162{
Manoj Naik97d312d2005-06-22 17:16:39 +00001163 uint32_t attrs[2] = {
1164 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1165 FATTR4_WORD1_MOUNTED_ON_FILEID,
1166 };
Al Viro8687b632006-10-19 23:28:48 -07001167 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001169 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 WRITE32(OP_READDIR);
1171 WRITE64(readdir->cookie);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001172 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1174 WRITE32(readdir->count);
1175 WRITE32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001176 /* Switch to mounted_on_fileid if the server supports it */
1177 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1178 attrs[0] &= ~FATTR4_WORD0_FILEID;
1179 else
1180 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1181 WRITE32(attrs[0] & readdir->bitmask[0]);
1182 WRITE32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001183 hdr->nops++;
Fred Isaman44109242008-04-02 15:21:15 +03001184 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1185 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001186 (unsigned long long)readdir->cookie,
1187 ((u32 *)readdir->verifier.data)[0],
1188 ((u32 *)readdir->verifier.data)[1],
1189 attrs[0] & readdir->bitmask[0],
1190 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191}
1192
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001193static 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 -07001194{
Al Viro8687b632006-10-19 23:28:48 -07001195 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
1197 RESERVE_SPACE(4);
1198 WRITE32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001199 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200}
1201
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001202static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203{
Al Viro8687b632006-10-19 23:28:48 -07001204 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
1206 RESERVE_SPACE(8 + name->len);
1207 WRITE32(OP_REMOVE);
1208 WRITE32(name->len);
1209 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001210 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211}
1212
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001213static 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 -07001214{
Al Viro8687b632006-10-19 23:28:48 -07001215 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
1217 RESERVE_SPACE(8 + oldname->len);
1218 WRITE32(OP_RENAME);
1219 WRITE32(oldname->len);
1220 WRITEMEM(oldname->name, oldname->len);
Andy Adamson6c0195a2008-12-23 16:06:15 -05001221
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 RESERVE_SPACE(4 + newname->len);
1223 WRITE32(newname->len);
1224 WRITEMEM(newname->name, newname->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001225 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226}
1227
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001228static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229{
Al Viro8687b632006-10-19 23:28:48 -07001230 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
1232 RESERVE_SPACE(12);
1233 WRITE32(OP_RENEW);
1234 WRITE64(client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001235 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236}
1237
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001238static void
Andy Adamsond0179312008-12-23 16:06:17 -05001239encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001240{
Al Viro8687b632006-10-19 23:28:48 -07001241 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001242
1243 RESERVE_SPACE(4);
1244 WRITE32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001245 hdr->nops++;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001246}
1247
1248static int
Andy Adamsond0179312008-12-23 16:06:17 -05001249encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001250{
Al Viro8687b632006-10-19 23:28:48 -07001251 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001252
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001253 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001254 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001255 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001256 RESERVE_SPACE(2*4);
1257 WRITE32(1);
1258 WRITE32(FATTR4_WORD0_ACL);
1259 if (arg->acl_len % 4)
1260 return -EINVAL;
1261 RESERVE_SPACE(4);
1262 WRITE32(arg->acl_len);
1263 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001264 hdr->nops++;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001265 return 0;
1266}
1267
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001268static void
Andy Adamsond0179312008-12-23 16:06:17 -05001269encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
Al Viro8687b632006-10-19 23:28:48 -07001271 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
1273 RESERVE_SPACE(4);
1274 WRITE32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001275 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276}
1277
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001278static 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 -07001279{
Al Viro8687b632006-10-19 23:28:48 -07001280 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001281
Andy Adamson05d564f2008-12-23 16:06:15 -05001282 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1283 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001284 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001285 hdr->nops++;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001286 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001289static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
Al Viro8687b632006-10-19 23:28:48 -07001291 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001293 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 WRITE32(OP_SETCLIENTID);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001295 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
1297 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1298 RESERVE_SPACE(4);
1299 WRITE32(setclientid->sc_prog);
1300 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1301 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1302 RESERVE_SPACE(4);
1303 WRITE32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001304 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305}
1306
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001307static 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 -07001308{
Andy Adamson05d564f2008-12-23 16:06:15 -05001309 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Andy Adamson05d564f2008-12-23 16:06:15 -05001311 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1312 WRITE32(OP_SETCLIENTID_CONFIRM);
1313 WRITE64(client_state->cl_clientid);
1314 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001315 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316}
1317
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001318static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319{
Al Viro8687b632006-10-19 23:28:48 -07001320 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
1322 RESERVE_SPACE(4);
1323 WRITE32(OP_WRITE);
1324
1325 encode_stateid(xdr, args->context);
1326
1327 RESERVE_SPACE(16);
1328 WRITE64(args->offset);
1329 WRITE32(args->stable);
1330 WRITE32(args->count);
1331
1332 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001333 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334}
1335
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001336static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
Al Viro8687b632006-10-19 23:28:48 -07001338 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001340 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
1342 WRITE32(OP_DELEGRETURN);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001343 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001344 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345}
1346/*
1347 * END OF "GENERIC" ENCODE ROUTINES.
1348 */
1349
1350/*
1351 * Encode an ACCESS request
1352 */
Al Viro8687b632006-10-19 23:28:48 -07001353static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354{
1355 struct xdr_stream xdr;
1356 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001357 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
1360 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1361 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001362 encode_putfh(&xdr, args->fh, &hdr);
1363 encode_access(&xdr, args->access, &hdr);
1364 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001365 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001366 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367}
1368
1369/*
1370 * Encode LOOKUP request
1371 */
Al Viro8687b632006-10-19 23:28:48 -07001372static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373{
1374 struct xdr_stream xdr;
1375 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001376 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
1379 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1380 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001381 encode_putfh(&xdr, args->dir_fh, &hdr);
1382 encode_lookup(&xdr, args->name, &hdr);
1383 encode_getfh(&xdr, &hdr);
1384 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001385 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001386 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387}
1388
1389/*
1390 * Encode LOOKUP_ROOT request
1391 */
Al Viro8687b632006-10-19 23:28:48 -07001392static 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 -07001393{
1394 struct xdr_stream xdr;
1395 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001396 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
1399 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1400 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001401 encode_putrootfh(&xdr, &hdr);
1402 encode_getfh(&xdr, &hdr);
1403 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001404 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001405 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406}
1407
1408/*
1409 * Encode REMOVE request
1410 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001411static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412{
1413 struct xdr_stream xdr;
1414 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001415 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
1418 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1419 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001420 encode_putfh(&xdr, args->fh, &hdr);
1421 encode_remove(&xdr, &args->name, &hdr);
1422 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001423 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001424 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425}
1426
1427/*
1428 * Encode RENAME request
1429 */
Al Viro8687b632006-10-19 23:28:48 -07001430static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431{
1432 struct xdr_stream xdr;
1433 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001434 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
1437 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1438 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001439 encode_putfh(&xdr, args->old_dir, &hdr);
1440 encode_savefh(&xdr, &hdr);
1441 encode_putfh(&xdr, args->new_dir, &hdr);
1442 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1443 encode_getfattr(&xdr, args->bitmask, &hdr);
1444 encode_restorefh(&xdr, &hdr);
1445 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001446 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001447 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448}
1449
1450/*
1451 * Encode LINK request
1452 */
Al Viro8687b632006-10-19 23:28:48 -07001453static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
1455 struct xdr_stream xdr;
1456 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001457 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
1460 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1461 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001462 encode_putfh(&xdr, args->fh, &hdr);
1463 encode_savefh(&xdr, &hdr);
1464 encode_putfh(&xdr, args->dir_fh, &hdr);
1465 encode_link(&xdr, args->name, &hdr);
1466 encode_getfattr(&xdr, args->bitmask, &hdr);
1467 encode_restorefh(&xdr, &hdr);
1468 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001469 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001470 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471}
1472
1473/*
1474 * Encode CREATE request
1475 */
Al Viro8687b632006-10-19 23:28:48 -07001476static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477{
1478 struct xdr_stream xdr;
1479 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001480 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
1483 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1484 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001485 encode_putfh(&xdr, args->dir_fh, &hdr);
1486 encode_savefh(&xdr, &hdr);
1487 encode_create(&xdr, args, &hdr);
1488 encode_getfh(&xdr, &hdr);
1489 encode_getfattr(&xdr, args->bitmask, &hdr);
1490 encode_restorefh(&xdr, &hdr);
1491 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001492 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001493 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494}
1495
1496/*
1497 * Encode SYMLINK request
1498 */
Al Viro8687b632006-10-19 23:28:48 -07001499static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500{
1501 return nfs4_xdr_enc_create(req, p, args);
1502}
1503
1504/*
1505 * Encode GETATTR request
1506 */
Al Viro8687b632006-10-19 23:28:48 -07001507static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
1509 struct xdr_stream xdr;
1510 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001511 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
1514 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1515 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001516 encode_putfh(&xdr, args->fh, &hdr);
1517 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001518 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001519 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520}
1521
1522/*
1523 * Encode a CLOSE request
1524 */
Al Viro8687b632006-10-19 23:28:48 -07001525static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
Andy Adamson05d564f2008-12-23 16:06:15 -05001527 struct xdr_stream xdr;
1528 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001529 .nops = 0,
Andy Adamson05d564f2008-12-23 16:06:15 -05001530 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Andy Adamson05d564f2008-12-23 16:06:15 -05001532 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1533 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001534 encode_putfh(&xdr, args->fh, &hdr);
1535 encode_close(&xdr, args, &hdr);
1536 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001537 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001538 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539}
1540
1541/*
1542 * Encode an OPEN request
1543 */
Al Viro8687b632006-10-19 23:28:48 -07001544static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
1546 struct xdr_stream xdr;
1547 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001548 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
1551 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1552 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001553 encode_putfh(&xdr, args->fh, &hdr);
1554 encode_savefh(&xdr, &hdr);
1555 encode_open(&xdr, args, &hdr);
1556 encode_getfh(&xdr, &hdr);
1557 encode_getfattr(&xdr, args->bitmask, &hdr);
1558 encode_restorefh(&xdr, &hdr);
1559 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001560 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001561 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562}
1563
1564/*
1565 * Encode an OPEN_CONFIRM request
1566 */
Al Viro8687b632006-10-19 23:28:48 -07001567static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568{
1569 struct xdr_stream xdr;
1570 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001571 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
1574 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1575 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001576 encode_putfh(&xdr, args->fh, &hdr);
1577 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001578 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001579 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580}
1581
1582/*
1583 * Encode an OPEN request with no attributes.
1584 */
Al Viro8687b632006-10-19 23:28:48 -07001585static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586{
1587 struct xdr_stream xdr;
1588 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001589 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
1592 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1593 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001594 encode_putfh(&xdr, args->fh, &hdr);
1595 encode_open(&xdr, args, &hdr);
1596 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001597 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001598 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599}
1600
1601/*
1602 * Encode an OPEN_DOWNGRADE request
1603 */
Al Viro8687b632006-10-19 23:28:48 -07001604static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605{
1606 struct xdr_stream xdr;
1607 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001608 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
1611 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1612 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001613 encode_putfh(&xdr, args->fh, &hdr);
1614 encode_open_downgrade(&xdr, args, &hdr);
1615 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001616 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001617 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618}
1619
1620/*
1621 * Encode a LOCK request
1622 */
Al Viro8687b632006-10-19 23:28:48 -07001623static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
1625 struct xdr_stream xdr;
1626 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001627 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629
1630 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1631 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001632 encode_putfh(&xdr, args->fh, &hdr);
1633 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001634 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001635 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636}
1637
1638/*
1639 * Encode a LOCKT request
1640 */
Al Viro8687b632006-10-19 23:28:48 -07001641static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642{
1643 struct xdr_stream xdr;
1644 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001645 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
1648 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1649 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001650 encode_putfh(&xdr, args->fh, &hdr);
1651 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001652 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001653 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654}
1655
1656/*
1657 * Encode a LOCKU request
1658 */
Al Viro8687b632006-10-19 23:28:48 -07001659static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660{
1661 struct xdr_stream xdr;
1662 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001663 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
1666 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1667 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001668 encode_putfh(&xdr, args->fh, &hdr);
1669 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001670 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001671 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672}
1673
1674/*
1675 * Encode a READLINK request
1676 */
Al Viro8687b632006-10-19 23:28:48 -07001677static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678{
1679 struct xdr_stream xdr;
1680 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001681 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 };
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001683 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1684 unsigned int replen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
1686 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1687 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001688 encode_putfh(&xdr, args->fh, &hdr);
1689 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001690
1691 /* set up reply kvec
1692 * toplevel_status + taglen + rescount + OP_PUTFH + status
1693 * + OP_READLINK + status + string length = 8
1694 */
1695 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readlink_sz) << 2;
1696 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1697 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05001698 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001699 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
1701
1702/*
1703 * Encode a READDIR request
1704 */
Al Viro8687b632006-10-19 23:28:48 -07001705static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706{
1707 struct xdr_stream xdr;
1708 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001709 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 };
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001711 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1712 int replen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
1714 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1715 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001716 encode_putfh(&xdr, args->fh, &hdr);
1717 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001718
1719 /* set up reply kvec
1720 * toplevel_status + taglen + rescount + OP_PUTFH + status
1721 * + OP_READDIR + status + verifer(2) = 9
1722 */
1723 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readdir_sz) << 2;
1724 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1725 args->pgbase, args->count);
1726 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07001727 __func__, replen, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001728 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001729 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001730 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731}
1732
1733/*
1734 * Encode a READ request
1735 */
Al Viro8687b632006-10-19 23:28:48 -07001736static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737{
Trond Myklebust1be27f32007-06-27 14:29:04 -04001738 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 struct xdr_stream xdr;
1740 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001741 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 };
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001743 int replen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
1745 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1746 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001747 encode_putfh(&xdr, args->fh, &hdr);
1748 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
1750 /* set up reply kvec
1751 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1752 * + OP_READ + status + eof + datalen = 9
1753 */
1754 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1755 xdr_inline_pages(&req->rq_rcv_buf, replen,
1756 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001757 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05001758 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001759 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760}
1761
1762/*
1763 * Encode an SETATTR request
1764 */
Al Viro8687b632006-10-19 23:28:48 -07001765static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766{
Andy Adamson05d564f2008-12-23 16:06:15 -05001767 struct xdr_stream xdr;
1768 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001769 .nops = 0,
Andy Adamson05d564f2008-12-23 16:06:15 -05001770 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
Andy Adamson05d564f2008-12-23 16:06:15 -05001772 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1773 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001774 encode_putfh(&xdr, args->fh, &hdr);
1775 encode_setattr(&xdr, args, args->server, &hdr);
1776 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001777 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001778 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779}
1780
1781/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00001782 * Encode a GETACL request
1783 */
1784static int
Al Viro8687b632006-10-19 23:28:48 -07001785nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001786 struct nfs_getaclargs *args)
1787{
1788 struct xdr_stream xdr;
Trond Myklebust1be27f32007-06-27 14:29:04 -04001789 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001790 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001791 .nops = 0,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001792 };
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001793 int replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001794
1795 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1796 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001797 encode_putfh(&xdr, args->fh, &hdr);
1798 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1799
J. Bruce Fields029d1052005-06-22 17:16:22 +00001800 /* set up reply buffer: */
1801 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1802 xdr_inline_pages(&req->rq_rcv_buf, replen,
1803 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001804 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001805 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001806}
1807
1808/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 * Encode a WRITE request
1810 */
Al Viro8687b632006-10-19 23:28:48 -07001811static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812{
1813 struct xdr_stream xdr;
1814 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001815 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
1818 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1819 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001820 encode_putfh(&xdr, args->fh, &hdr);
1821 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001822 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001823 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001824 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001825 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826}
1827
1828/*
1829 * a COMMIT request
1830 */
Al Viro8687b632006-10-19 23:28:48 -07001831static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832{
1833 struct xdr_stream xdr;
1834 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001835 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
1838 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1839 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001840 encode_putfh(&xdr, args->fh, &hdr);
1841 encode_commit(&xdr, args, &hdr);
1842 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001843 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001844 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845}
1846
1847/*
1848 * FSINFO request
1849 */
Al Viro8687b632006-10-19 23:28:48 -07001850static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851{
1852 struct xdr_stream xdr;
1853 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001854 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
1857 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1858 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001859 encode_putfh(&xdr, args->fh, &hdr);
1860 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001861 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001862 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863}
1864
1865/*
1866 * a PATHCONF request
1867 */
Al Viro8687b632006-10-19 23:28:48 -07001868static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 struct xdr_stream xdr;
1871 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001872 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
1875 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1876 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001877 encode_putfh(&xdr, args->fh, &hdr);
1878 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
1879 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001880 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001881 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882}
1883
1884/*
1885 * a STATFS request
1886 */
Al Viro8687b632006-10-19 23:28:48 -07001887static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 struct xdr_stream xdr;
1890 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001891 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
1894 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1895 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001896 encode_putfh(&xdr, args->fh, &hdr);
1897 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
1898 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001899 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001900 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901}
1902
1903/*
1904 * GETATTR_BITMAP request
1905 */
Al Viro8687b632006-10-19 23:28:48 -07001906static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907{
1908 struct xdr_stream xdr;
1909 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001910 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
1913 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1914 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001915 encode_putfh(&xdr, fhandle, &hdr);
1916 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1917 FATTR4_WORD0_LINK_SUPPORT|
1918 FATTR4_WORD0_SYMLINK_SUPPORT|
1919 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001920 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001921 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922}
1923
1924/*
1925 * a RENEW request
1926 */
Al Viro8687b632006-10-19 23:28:48 -07001927static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928{
1929 struct xdr_stream xdr;
1930 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001931 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 };
1933
1934 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1935 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001936 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001937 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001938 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939}
1940
1941/*
1942 * a SETCLIENTID request
1943 */
Al Viro8687b632006-10-19 23:28:48 -07001944static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945{
1946 struct xdr_stream xdr;
1947 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001948 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 };
1950
1951 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1952 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001953 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001954 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001955 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956}
1957
1958/*
1959 * a SETCLIENTID_CONFIRM request
1960 */
Al Viro8687b632006-10-19 23:28:48 -07001961static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962{
1963 struct xdr_stream xdr;
1964 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001965 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 };
1967 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968
1969 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1970 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001971 encode_setclientid_confirm(&xdr, clp, &hdr);
1972 encode_putrootfh(&xdr, &hdr);
1973 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001974 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001975 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976}
1977
1978/*
1979 * DELEGRETURN request
1980 */
Al Viro8687b632006-10-19 23:28:48 -07001981static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982{
1983 struct xdr_stream xdr;
1984 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001985 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
1988 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1989 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001990 encode_putfh(&xdr, args->fhandle, &hdr);
1991 encode_delegreturn(&xdr, args->stateid, &hdr);
1992 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001993 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001994 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995}
1996
1997/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04001998 * Encode FS_LOCATIONS request
1999 */
Al Viro8687b632006-10-19 23:28:48 -07002000static 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 -04002001{
2002 struct xdr_stream xdr;
2003 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002004 .nops = 0,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002005 };
Trond Myklebust1be27f32007-06-27 14:29:04 -04002006 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002007 int replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002008
2009 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2010 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002011 encode_putfh(&xdr, args->dir_fh, &hdr);
2012 encode_lookup(&xdr, args->name, &hdr);
2013 encode_fs_locations(&xdr, args->bitmask, &hdr);
2014
Trond Myklebust683b57b2006-06-09 09:34:22 -04002015 /* set up reply
Manoj Naik830b8e32006-06-09 09:34:25 -04002016 * toplevel_status + OP_PUTFH + status
Trond Myklebust683b57b2006-06-09 09:34:22 -04002017 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2018 */
2019 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2020 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2021 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002022 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002023 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002024}
2025
2026/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 * START OF "GENERIC" DECODE ROUTINES.
2028 * These may look a little ugly since they are imported from a "generic"
2029 * set of XDR encode/decode routines which are intended to be shared by
2030 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2031 *
2032 * If the pain of reading these is too great, it should be a straightforward
2033 * task to translate them into Linux-specific versions which are more
2034 * consistent with the style used in NFSv2/v3...
2035 */
2036#define READ32(x) (x) = ntohl(*p++)
2037#define READ64(x) do { \
2038 (x) = (u64)ntohl(*p++) << 32; \
2039 (x) |= ntohl(*p++); \
2040} while (0)
2041#define READTIME(x) do { \
2042 p++; \
2043 (x.tv_sec) = ntohl(*p++); \
2044 (x.tv_nsec) = ntohl(*p++); \
2045} while (0)
2046#define COPYMEM(x,nbytes) do { \
2047 memcpy((x), p, nbytes); \
2048 p += XDR_QUADLEN(nbytes); \
2049} while (0)
2050
2051#define READ_BUF(nbytes) do { \
2052 p = xdr_inline_decode(xdr, nbytes); \
Chuck Levere4cc6ee2007-05-08 18:23:28 -04002053 if (unlikely(!p)) { \
Chuck Leverfe82a182007-09-11 18:01:10 -04002054 dprintk("nfs: %s: prematurely hit end of receive" \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002055 " buffer\n", __func__); \
Chuck Leverfe82a182007-09-11 18:01:10 -04002056 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002057 __func__, xdr->p, nbytes, xdr->end); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 return -EIO; \
2059 } \
2060} while (0)
2061
Trond Myklebust683b57b2006-06-09 09:34:22 -04002062static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063{
Al Viro8687b632006-10-19 23:28:48 -07002064 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
2066 READ_BUF(4);
2067 READ32(*len);
2068 READ_BUF(*len);
2069 *string = (char *)p;
2070 return 0;
2071}
2072
2073static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2074{
Al Viro8687b632006-10-19 23:28:48 -07002075 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
2077 READ_BUF(8);
2078 READ32(hdr->status);
2079 READ32(hdr->taglen);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002080
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 READ_BUF(hdr->taglen + 4);
2082 hdr->tag = (char *)p;
2083 p += XDR_QUADLEN(hdr->taglen);
2084 READ32(hdr->nops);
Benny Halevyaadf6152008-12-23 16:06:13 -05002085 if (unlikely(hdr->nops < 1))
2086 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 return 0;
2088}
2089
2090static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2091{
Al Viro8687b632006-10-19 23:28:48 -07002092 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 uint32_t opnum;
2094 int32_t nfserr;
2095
2096 READ_BUF(8);
2097 READ32(opnum);
2098 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002099 dprintk("nfs: Server returned operation"
2100 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 opnum, expected);
2102 return -EIO;
2103 }
2104 READ32(nfserr);
2105 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002106 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 return 0;
2108}
2109
2110/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002111static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112{
Al Viro8687b632006-10-19 23:28:48 -07002113 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002114 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 char *str;
2116
2117 READ_BUF(12);
2118 return decode_opaque_inline(xdr, &strlen, &str);
2119}
2120
2121static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2122{
Al Viro8687b632006-10-19 23:28:48 -07002123 uint32_t bmlen;
2124 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
2126 READ_BUF(4);
2127 READ32(bmlen);
2128
2129 bitmap[0] = bitmap[1] = 0;
2130 READ_BUF((bmlen << 2));
2131 if (bmlen > 0) {
2132 READ32(bitmap[0]);
2133 if (bmlen > 1)
2134 READ32(bitmap[1]);
2135 }
2136 return 0;
2137}
2138
Al Viro8687b632006-10-19 23:28:48 -07002139static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140{
Al Viro8687b632006-10-19 23:28:48 -07002141 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
2143 READ_BUF(4);
2144 READ32(*attrlen);
2145 *savep = xdr->p;
2146 return 0;
2147}
2148
2149static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2150{
2151 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2152 decode_attr_bitmap(xdr, bitmask);
2153 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2154 } else
2155 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002156 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 return 0;
2158}
2159
2160static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2161{
Al Viro8687b632006-10-19 23:28:48 -07002162 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
2164 *type = 0;
2165 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2166 return -EIO;
2167 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2168 READ_BUF(4);
2169 READ32(*type);
2170 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002171 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 return -EIO;
2173 }
2174 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2175 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002176 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type].nfs2type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 return 0;
2178}
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183
2184 *change = 0;
2185 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2186 return -EIO;
2187 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2188 READ_BUF(8);
2189 READ64(*change);
2190 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2191 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002192 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 (unsigned long long)*change);
2194 return 0;
2195}
2196
2197static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2198{
Al Viro8687b632006-10-19 23:28:48 -07002199 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
2201 *size = 0;
2202 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2203 return -EIO;
2204 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2205 READ_BUF(8);
2206 READ64(*size);
2207 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2208 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002209 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 return 0;
2211}
2212
2213static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2214{
Al Viro8687b632006-10-19 23:28:48 -07002215 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
2217 *res = 0;
2218 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2219 return -EIO;
2220 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2221 READ_BUF(4);
2222 READ32(*res);
2223 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2224 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002225 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 return 0;
2227}
2228
2229static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2230{
Al Viro8687b632006-10-19 23:28:48 -07002231 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
2233 *res = 0;
2234 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2235 return -EIO;
2236 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2237 READ_BUF(4);
2238 READ32(*res);
2239 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2240 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002241 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 return 0;
2243}
2244
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002245static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246{
Al Viro8687b632006-10-19 23:28:48 -07002247 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
2249 fsid->major = 0;
2250 fsid->minor = 0;
2251 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2252 return -EIO;
2253 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2254 READ_BUF(16);
2255 READ64(fsid->major);
2256 READ64(fsid->minor);
2257 bitmap[0] &= ~FATTR4_WORD0_FSID;
2258 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002259 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 (unsigned long long)fsid->major,
2261 (unsigned long long)fsid->minor);
2262 return 0;
2263}
2264
2265static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2266{
Al Viro8687b632006-10-19 23:28:48 -07002267 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
2269 *res = 60;
2270 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2271 return -EIO;
2272 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2273 READ_BUF(4);
2274 READ32(*res);
2275 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2276 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002277 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 return 0;
2279}
2280
2281static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2282{
Al Viro8687b632006-10-19 23:28:48 -07002283 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
2285 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2286 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2287 return -EIO;
2288 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2289 READ_BUF(4);
2290 READ32(*res);
2291 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2292 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002293 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 return 0;
2295}
2296
2297static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2298{
Al Viro8687b632006-10-19 23:28:48 -07002299 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
2301 *fileid = 0;
2302 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2303 return -EIO;
2304 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2305 READ_BUF(8);
2306 READ64(*fileid);
2307 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2308 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002309 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 return 0;
2311}
2312
Manoj Naik99baf622006-06-09 09:34:24 -04002313static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2314{
Al Viro8687b632006-10-19 23:28:48 -07002315 __be32 *p;
Manoj Naik99baf622006-06-09 09:34:24 -04002316
2317 *fileid = 0;
2318 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2319 return -EIO;
2320 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2321 READ_BUF(8);
2322 READ64(*fileid);
2323 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2324 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002325 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04002326 return 0;
2327}
2328
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2330{
Al Viro8687b632006-10-19 23:28:48 -07002331 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 int status = 0;
2333
2334 *res = 0;
2335 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2336 return -EIO;
2337 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2338 READ_BUF(8);
2339 READ64(*res);
2340 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2341 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002342 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 return status;
2344}
2345
2346static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2347{
Al Viro8687b632006-10-19 23:28:48 -07002348 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 int status = 0;
2350
2351 *res = 0;
2352 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2353 return -EIO;
2354 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2355 READ_BUF(8);
2356 READ64(*res);
2357 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2358 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002359 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 return status;
2361}
2362
2363static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2364{
Al Viro8687b632006-10-19 23:28:48 -07002365 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 int status = 0;
2367
2368 *res = 0;
2369 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2370 return -EIO;
2371 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2372 READ_BUF(8);
2373 READ64(*res);
2374 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2375 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002376 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 return status;
2378}
2379
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002380static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2381{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002382 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002383 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002384 int status = 0;
2385
2386 READ_BUF(4);
2387 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002388 if (n == 0)
2389 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002390 dprintk("path ");
2391 path->ncomponents = 0;
2392 while (path->ncomponents < n) {
2393 struct nfs4_string *component = &path->components[path->ncomponents];
2394 status = decode_opaque_inline(xdr, &component->len, &component->data);
2395 if (unlikely(status != 0))
2396 goto out_eio;
2397 if (path->ncomponents != n)
2398 dprintk("/");
2399 dprintk("%s", component->data);
2400 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2401 path->ncomponents++;
2402 else {
2403 dprintk("cannot parse %d components in path\n", n);
2404 goto out_eio;
2405 }
2406 }
2407out:
2408 dprintk("\n");
2409 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002410root_path:
2411/* a root pathname is sent as a zero component4 */
2412 path->ncomponents = 1;
2413 path->components[0].len=0;
2414 path->components[0].data=NULL;
2415 dprintk("path /\n");
2416 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002417out_eio:
2418 dprintk(" status %d", status);
2419 status = -EIO;
2420 goto out;
2421}
2422
2423static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002424{
2425 int n;
Al Viro8687b632006-10-19 23:28:48 -07002426 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002427 int status = -EIO;
2428
2429 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2430 goto out;
2431 status = 0;
2432 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2433 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002434 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002435 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002436 if (unlikely(status != 0))
2437 goto out;
2438 READ_BUF(4);
2439 READ32(n);
2440 if (n <= 0)
2441 goto out_eio;
2442 res->nlocations = 0;
2443 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002444 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002445 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002446
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002447 READ_BUF(4);
2448 READ32(m);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002449
2450 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002451 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002452 while (loc->nservers < m) {
2453 struct nfs4_string *server = &loc->servers[loc->nservers];
2454 status = decode_opaque_inline(xdr, &server->len, &server->data);
2455 if (unlikely(status != 0))
2456 goto out_eio;
2457 dprintk("%s ", server->data);
2458 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2459 loc->nservers++;
2460 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002461 unsigned int i;
2462 dprintk("%s: using first %u of %u servers "
2463 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002464 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002465 NFS4_FS_LOCATION_MAXSERVERS,
2466 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002467 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002468 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002469 char *data;
2470 status = decode_opaque_inline(xdr, &len, &data);
2471 if (unlikely(status != 0))
2472 goto out_eio;
2473 }
2474 }
2475 }
2476 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002477 if (unlikely(status != 0))
2478 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002479 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002480 res->nlocations++;
2481 }
2482out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002483 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002484 return status;
2485out_eio:
2486 status = -EIO;
2487 goto out;
2488}
2489
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2491{
Al Viro8687b632006-10-19 23:28:48 -07002492 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 int status = 0;
2494
2495 *res = 0;
2496 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2497 return -EIO;
2498 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2499 READ_BUF(8);
2500 READ64(*res);
2501 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2502 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002503 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 return status;
2505}
2506
2507static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2508{
Al Viro8687b632006-10-19 23:28:48 -07002509 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 int status = 0;
2511
2512 *maxlink = 1;
2513 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2514 return -EIO;
2515 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2516 READ_BUF(4);
2517 READ32(*maxlink);
2518 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2519 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002520 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 return status;
2522}
2523
2524static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2525{
Al Viro8687b632006-10-19 23:28:48 -07002526 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 int status = 0;
2528
2529 *maxname = 1024;
2530 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2531 return -EIO;
2532 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2533 READ_BUF(4);
2534 READ32(*maxname);
2535 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2536 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002537 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 return status;
2539}
2540
2541static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2542{
Al Viro8687b632006-10-19 23:28:48 -07002543 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 int status = 0;
2545
2546 *res = 1024;
2547 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2548 return -EIO;
2549 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2550 uint64_t maxread;
2551 READ_BUF(8);
2552 READ64(maxread);
2553 if (maxread > 0x7FFFFFFF)
2554 maxread = 0x7FFFFFFF;
2555 *res = (uint32_t)maxread;
2556 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2557 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002558 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 return status;
2560}
2561
2562static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2563{
Al Viro8687b632006-10-19 23:28:48 -07002564 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 int status = 0;
2566
2567 *res = 1024;
2568 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2569 return -EIO;
2570 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2571 uint64_t maxwrite;
2572 READ_BUF(8);
2573 READ64(maxwrite);
2574 if (maxwrite > 0x7FFFFFFF)
2575 maxwrite = 0x7FFFFFFF;
2576 *res = (uint32_t)maxwrite;
2577 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2578 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002579 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 return status;
2581}
2582
2583static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2584{
Al Viro8687b632006-10-19 23:28:48 -07002585 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
2587 *mode = 0;
2588 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2589 return -EIO;
2590 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2591 READ_BUF(4);
2592 READ32(*mode);
2593 *mode &= ~S_IFMT;
2594 bitmap[1] &= ~FATTR4_WORD1_MODE;
2595 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002596 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 return 0;
2598}
2599
2600static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2601{
Al Viro8687b632006-10-19 23:28:48 -07002602 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603
2604 *nlink = 1;
2605 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2606 return -EIO;
2607 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2608 READ_BUF(4);
2609 READ32(*nlink);
2610 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2611 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002612 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 return 0;
2614}
2615
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002616static 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 -07002617{
Al Viro8687b632006-10-19 23:28:48 -07002618 uint32_t len;
2619 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620
2621 *uid = -2;
2622 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2623 return -EIO;
2624 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2625 READ_BUF(4);
2626 READ32(len);
2627 READ_BUF(len);
2628 if (len < XDR_MAX_NETOBJ) {
2629 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2630 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002631 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002633 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002634 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2636 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002637 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 return 0;
2639}
2640
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002641static 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 -07002642{
Al Viro8687b632006-10-19 23:28:48 -07002643 uint32_t len;
2644 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
2646 *gid = -2;
2647 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2648 return -EIO;
2649 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2650 READ_BUF(4);
2651 READ32(len);
2652 READ_BUF(len);
2653 if (len < XDR_MAX_NETOBJ) {
2654 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2655 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002656 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002658 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002659 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2661 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002662 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 return 0;
2664}
2665
2666static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2667{
Al Viro8687b632006-10-19 23:28:48 -07002668 uint32_t major = 0, minor = 0;
2669 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670
2671 *rdev = MKDEV(0,0);
2672 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2673 return -EIO;
2674 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2675 dev_t tmp;
2676
2677 READ_BUF(8);
2678 READ32(major);
2679 READ32(minor);
2680 tmp = MKDEV(major, minor);
2681 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2682 *rdev = tmp;
2683 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2684 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002685 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 return 0;
2687}
2688
2689static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2690{
Al Viro8687b632006-10-19 23:28:48 -07002691 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 int status = 0;
2693
2694 *res = 0;
2695 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2696 return -EIO;
2697 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2698 READ_BUF(8);
2699 READ64(*res);
2700 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2701 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002702 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 return status;
2704}
2705
2706static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2707{
Al Viro8687b632006-10-19 23:28:48 -07002708 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 int status = 0;
2710
2711 *res = 0;
2712 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2713 return -EIO;
2714 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2715 READ_BUF(8);
2716 READ64(*res);
2717 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2718 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002719 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 return status;
2721}
2722
2723static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2724{
Al Viro8687b632006-10-19 23:28:48 -07002725 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 int status = 0;
2727
2728 *res = 0;
2729 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2730 return -EIO;
2731 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2732 READ_BUF(8);
2733 READ64(*res);
2734 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2735 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002736 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 return status;
2738}
2739
2740static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2741{
Al Viro8687b632006-10-19 23:28:48 -07002742 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743
2744 *used = 0;
2745 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2746 return -EIO;
2747 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2748 READ_BUF(8);
2749 READ64(*used);
2750 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2751 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002752 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 (unsigned long long)*used);
2754 return 0;
2755}
2756
2757static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2758{
Al Viro8687b632006-10-19 23:28:48 -07002759 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 uint64_t sec;
2761 uint32_t nsec;
2762
2763 READ_BUF(12);
2764 READ64(sec);
2765 READ32(nsec);
2766 time->tv_sec = (time_t)sec;
2767 time->tv_nsec = (long)nsec;
2768 return 0;
2769}
2770
2771static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2772{
2773 int status = 0;
2774
2775 time->tv_sec = 0;
2776 time->tv_nsec = 0;
2777 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2778 return -EIO;
2779 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2780 status = decode_attr_time(xdr, time);
2781 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2782 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002783 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 return status;
2785}
2786
2787static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2788{
2789 int status = 0;
2790
2791 time->tv_sec = 0;
2792 time->tv_nsec = 0;
2793 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2794 return -EIO;
2795 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2796 status = decode_attr_time(xdr, time);
2797 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2798 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002799 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 return status;
2801}
2802
2803static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2804{
2805 int status = 0;
2806
2807 time->tv_sec = 0;
2808 time->tv_nsec = 0;
2809 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2810 return -EIO;
2811 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2812 status = decode_attr_time(xdr, time);
2813 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2814 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002815 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 return status;
2817}
2818
Al Viro8687b632006-10-19 23:28:48 -07002819static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820{
2821 unsigned int attrwords = XDR_QUADLEN(attrlen);
2822 unsigned int nwords = xdr->p - savep;
2823
2824 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002825 dprintk("%s: server returned incorrect attribute length: "
2826 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002827 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 attrwords << 2,
2829 (attrwords < nwords) ? '<' : '>',
2830 nwords << 2);
2831 return -EIO;
2832 }
2833 return 0;
2834}
2835
2836static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2837{
Al Viro8687b632006-10-19 23:28:48 -07002838 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839
2840 READ_BUF(20);
2841 READ32(cinfo->atomic);
2842 READ64(cinfo->before);
2843 READ64(cinfo->after);
2844 return 0;
2845}
2846
2847static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2848{
Al Viro8687b632006-10-19 23:28:48 -07002849 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 uint32_t supp, acc;
2851 int status;
2852
2853 status = decode_op_hdr(xdr, OP_ACCESS);
2854 if (status)
2855 return status;
2856 READ_BUF(8);
2857 READ32(supp);
2858 READ32(acc);
2859 access->supported = supp;
2860 access->access = acc;
2861 return 0;
2862}
2863
2864static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2865{
Al Viro8687b632006-10-19 23:28:48 -07002866 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 int status;
2868
2869 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04002870 if (status != -EIO)
2871 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 if (status)
2873 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04002874 READ_BUF(NFS4_STATEID_SIZE);
2875 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 return 0;
2877}
2878
2879static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2880{
Al Viro8687b632006-10-19 23:28:48 -07002881 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 int status;
2883
2884 status = decode_op_hdr(xdr, OP_COMMIT);
2885 if (status)
2886 return status;
2887 READ_BUF(8);
2888 COPYMEM(res->verf->verifier, 8);
2889 return 0;
2890}
2891
2892static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2893{
Al Viro8687b632006-10-19 23:28:48 -07002894 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 uint32_t bmlen;
2896 int status;
2897
2898 status = decode_op_hdr(xdr, OP_CREATE);
2899 if (status)
2900 return status;
2901 if ((status = decode_change_info(xdr, cinfo)))
2902 return status;
2903 READ_BUF(4);
2904 READ32(bmlen);
2905 READ_BUF(bmlen << 2);
2906 return 0;
2907}
2908
2909static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2910{
Al Viro8687b632006-10-19 23:28:48 -07002911 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002912 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 int status;
2914
2915 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2916 goto xdr_error;
2917 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2918 goto xdr_error;
2919 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2920 goto xdr_error;
2921 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2922 goto xdr_error;
2923 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2924 goto xdr_error;
2925 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2926 goto xdr_error;
2927 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2928 goto xdr_error;
2929 status = verify_attr_len(xdr, savep, attrlen);
2930xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002931 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 return status;
2933}
Andy Adamson6c0195a2008-12-23 16:06:15 -05002934
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2936{
Al Viro8687b632006-10-19 23:28:48 -07002937 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002938 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002940
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2942 goto xdr_error;
2943 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2944 goto xdr_error;
2945 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2946 goto xdr_error;
2947
2948 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2949 goto xdr_error;
2950 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2951 goto xdr_error;
2952 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2953 goto xdr_error;
2954 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2955 goto xdr_error;
2956 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2957 goto xdr_error;
2958 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2959 goto xdr_error;
2960
2961 status = verify_attr_len(xdr, savep, attrlen);
2962xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002963 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 return status;
2965}
2966
2967static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2968{
Al Viro8687b632006-10-19 23:28:48 -07002969 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002970 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002972
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2974 goto xdr_error;
2975 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2976 goto xdr_error;
2977 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2978 goto xdr_error;
2979
2980 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
2981 goto xdr_error;
2982 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
2983 goto xdr_error;
2984
2985 status = verify_attr_len(xdr, savep, attrlen);
2986xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002987 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 return status;
2989}
2990
2991static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
2992{
Al Viro8687b632006-10-19 23:28:48 -07002993 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 uint32_t attrlen,
2995 bitmap[2] = {0},
2996 type;
2997 int status, fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002998 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999
3000 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3001 goto xdr_error;
3002 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3003 goto xdr_error;
3004
3005 fattr->bitmap[0] = bitmap[0];
3006 fattr->bitmap[1] = bitmap[1];
3007
3008 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3009 goto xdr_error;
3010
3011
3012 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3013 goto xdr_error;
3014 fattr->type = nfs_type2fmt[type].nfs2type;
3015 fmode = nfs_type2fmt[type].mode;
3016
3017 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3018 goto xdr_error;
3019 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3020 goto xdr_error;
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003021 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 goto xdr_error;
3023 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3024 goto xdr_error;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003025 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003026 struct nfs4_fs_locations,
Trond Myklebust683b57b2006-06-09 09:34:22 -04003027 fattr))) != 0)
3028 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3030 goto xdr_error;
3031 fattr->mode |= fmode;
3032 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3033 goto xdr_error;
David Howells7539bba2006-08-22 20:06:09 -04003034 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 goto xdr_error;
David Howells7539bba2006-08-22 20:06:09 -04003036 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 goto xdr_error;
3038 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3039 goto xdr_error;
3040 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3041 goto xdr_error;
3042 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3043 goto xdr_error;
3044 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3045 goto xdr_error;
3046 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3047 goto xdr_error;
Manoj Naik99baf622006-06-09 09:34:24 -04003048 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3049 goto xdr_error;
3050 if (fattr->fileid == 0 && fileid != 0)
3051 fattr->fileid = fileid;
Trond Myklebust33801142005-10-27 22:12:39 -04003052 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003055 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 return status;
3057}
3058
3059
3060static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3061{
Al Viro8687b632006-10-19 23:28:48 -07003062 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 uint32_t attrlen, bitmap[2];
3064 int status;
3065
3066 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3067 goto xdr_error;
3068 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3069 goto xdr_error;
3070 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3071 goto xdr_error;
3072
3073 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3074
3075 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3076 goto xdr_error;
3077 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3078 goto xdr_error;
3079 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3080 goto xdr_error;
3081 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3082 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3083 goto xdr_error;
3084 fsinfo->wtpref = fsinfo->wtmax;
3085
3086 status = verify_attr_len(xdr, savep, attrlen);
3087xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003088 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 return status;
3090}
3091
3092static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3093{
Al Viro8687b632006-10-19 23:28:48 -07003094 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 uint32_t len;
3096 int status;
3097
Trond Myklebust99367812007-07-17 21:52:41 -04003098 /* Zero handle first to allow comparisons */
3099 memset(fh, 0, sizeof(*fh));
3100
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 status = decode_op_hdr(xdr, OP_GETFH);
3102 if (status)
3103 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104
3105 READ_BUF(4);
3106 READ32(len);
3107 if (len > NFS4_FHSIZE)
3108 return -EIO;
3109 fh->size = len;
3110 READ_BUF(len);
3111 COPYMEM(fh->data, len);
3112 return 0;
3113}
3114
3115static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3116{
3117 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003118
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 status = decode_op_hdr(xdr, OP_LINK);
3120 if (status)
3121 return status;
3122 return decode_change_info(xdr, cinfo);
3123}
3124
3125/*
3126 * We create the owner, so we know a proper owner.id length is 4.
3127 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003128static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003130 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003131 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003132 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133
3134 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003135 READ64(offset);
3136 READ64(length);
3137 READ32(type);
3138 if (fl != NULL) {
3139 fl->fl_start = (loff_t)offset;
3140 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3141 if (length == ~(uint64_t)0)
3142 fl->fl_end = OFFSET_MAX;
3143 fl->fl_type = F_WRLCK;
3144 if (type & 1)
3145 fl->fl_type = F_RDLCK;
3146 fl->fl_pid = 0;
3147 }
3148 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 READ32(namelen);
3150 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 return -NFS4ERR_DENIED;
3152}
3153
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003154static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155{
Al Viro8687b632006-10-19 23:28:48 -07003156 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 int status;
3158
3159 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003160 if (status == -EIO)
3161 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003163 READ_BUF(NFS4_STATEID_SIZE);
3164 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003166 status = decode_lock_denied(xdr, NULL);
3167 if (res->open_seqid != NULL)
3168 nfs_increment_open_seqid(status, res->open_seqid);
3169 nfs_increment_lock_seqid(status, res->lock_seqid);
3170out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 return status;
3172}
3173
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003174static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175{
3176 int status;
3177 status = decode_op_hdr(xdr, OP_LOCKT);
3178 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003179 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 return status;
3181}
3182
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003183static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184{
Al Viro8687b632006-10-19 23:28:48 -07003185 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 int status;
3187
3188 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003189 if (status != -EIO)
3190 nfs_increment_lock_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003192 READ_BUF(NFS4_STATEID_SIZE);
3193 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 }
3195 return status;
3196}
3197
3198static int decode_lookup(struct xdr_stream *xdr)
3199{
3200 return decode_op_hdr(xdr, OP_LOOKUP);
3201}
3202
3203/* This is too sick! */
3204static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3205{
Andy Adamson05d564f2008-12-23 16:06:15 -05003206 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 uint32_t limit_type, nblocks, blocksize;
3208
3209 READ_BUF(12);
3210 READ32(limit_type);
3211 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003212 case 1:
3213 READ64(*maxsize);
3214 break;
3215 case 2:
3216 READ32(nblocks);
3217 READ32(blocksize);
3218 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 }
3220 return 0;
3221}
3222
3223static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3224{
Andy Adamson05d564f2008-12-23 16:06:15 -05003225 __be32 *p;
3226 uint32_t delegation_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227
3228 READ_BUF(4);
3229 READ32(delegation_type);
3230 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3231 res->delegation_type = 0;
3232 return 0;
3233 }
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003234 READ_BUF(NFS4_STATEID_SIZE+4);
3235 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 READ32(res->do_recall);
Andy Adamson05d564f2008-12-23 16:06:15 -05003237
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003239 case NFS4_OPEN_DELEGATE_READ:
3240 res->delegation_type = FMODE_READ;
3241 break;
3242 case NFS4_OPEN_DELEGATE_WRITE:
3243 res->delegation_type = FMODE_WRITE|FMODE_READ;
3244 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 return -EIO;
3246 }
David Howells7539bba2006-08-22 20:06:09 -04003247 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248}
3249
3250static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3251{
Andy Adamson05d564f2008-12-23 16:06:15 -05003252 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003253 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003254 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255
Andy Adamson05d564f2008-12-23 16:06:15 -05003256 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003257 if (status != -EIO)
3258 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003259 if (status)
3260 return status;
3261 READ_BUF(NFS4_STATEID_SIZE);
3262 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263
Andy Adamson05d564f2008-12-23 16:06:15 -05003264 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265
Andy Adamson05d564f2008-12-23 16:06:15 -05003266 READ_BUF(8);
3267 READ32(res->rflags);
3268 READ32(bmlen);
3269 if (bmlen > 10)
3270 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271
Andy Adamson05d564f2008-12-23 16:06:15 -05003272 READ_BUF(bmlen << 2);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003273 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3274 for (i = 0; i < savewords; ++i)
3275 READ32(res->attrset[i]);
3276 for (; i < NFS4_BITMAP_SIZE; i++)
3277 res->attrset[i] = 0;
3278
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 return decode_delegation(xdr, res);
3280xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003281 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 return -EIO;
3283}
3284
3285static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3286{
Andy Adamson05d564f2008-12-23 16:06:15 -05003287 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 int status;
3289
Andy Adamson05d564f2008-12-23 16:06:15 -05003290 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003291 if (status != -EIO)
3292 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003293 if (status)
3294 return status;
3295 READ_BUF(NFS4_STATEID_SIZE);
3296 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3297 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298}
3299
3300static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3301{
Al Viro8687b632006-10-19 23:28:48 -07003302 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 int status;
3304
3305 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003306 if (status != -EIO)
3307 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 if (status)
3309 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003310 READ_BUF(NFS4_STATEID_SIZE);
3311 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 return 0;
3313}
3314
3315static int decode_putfh(struct xdr_stream *xdr)
3316{
3317 return decode_op_hdr(xdr, OP_PUTFH);
3318}
3319
3320static int decode_putrootfh(struct xdr_stream *xdr)
3321{
3322 return decode_op_hdr(xdr, OP_PUTROOTFH);
3323}
3324
3325static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3326{
3327 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003328 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 uint32_t count, eof, recvd, hdrlen;
3330 int status;
3331
3332 status = decode_op_hdr(xdr, OP_READ);
3333 if (status)
3334 return status;
3335 READ_BUF(8);
3336 READ32(eof);
3337 READ32(count);
3338 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3339 recvd = req->rq_rcv_buf.len - hdrlen;
3340 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003341 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 "count %u > recvd %u\n", count, recvd);
3343 count = recvd;
3344 eof = 0;
3345 }
3346 xdr_read_pages(xdr, count);
3347 res->eof = eof;
3348 res->count = count;
3349 return 0;
3350}
3351
3352static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3353{
3354 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3355 struct page *page = *rcvbuf->pages;
3356 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003357 size_t hdrlen;
3358 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003359 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003360 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04003361 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362
3363 status = decode_op_hdr(xdr, OP_READDIR);
3364 if (status)
3365 return status;
3366 READ_BUF(8);
3367 COPYMEM(readdir->verifier.data, 8);
Fred Isaman44109242008-04-02 15:21:15 +03003368 dprintk("%s: verifier = %08x:%08x\n",
3369 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00003370 ((u32 *)readdir->verifier.data)[0],
3371 ((u32 *)readdir->verifier.data)[1]);
3372
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373
3374 hdrlen = (char *) p - (char *) iov->iov_base;
3375 recvd = rcvbuf->len - hdrlen;
3376 if (pglen > recvd)
3377 pglen = recvd;
3378 xdr_read_pages(xdr, pglen);
3379
3380 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003381 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003382 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003384
3385 /* Make sure the packet actually has a value_follows and EOF entry */
3386 if ((entry + 1) > end)
3387 goto short_pkt;
3388
3389 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003390 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04003391 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003393 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 p += 2; /* cookie */
3395 len = ntohl(*p++); /* filename length */
3396 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003397 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3398 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 goto err_unmap;
3400 }
David Howellse8896492006-08-24 15:44:19 -04003401 xlen = XDR_QUADLEN(len);
3402 if (end - p < xlen + 1)
3403 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003404 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003405 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003407 if (end - p < len + 1)
3408 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003411 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003413 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 entry = p;
3415 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003416 /*
3417 * Apparently some server sends responses that are a valid size, but
3418 * contain no entries, and have value_follows==0 and EOF==0. For
3419 * those, just set the EOF marker.
3420 */
3421 if (!nr && entry[1] == 0) {
3422 dprintk("NFS: readdir reply truncated!\n");
3423 entry[1] = 1;
3424 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05003425out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 kunmap_atomic(kaddr, KM_USER0);
3427 return 0;
3428short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003429 /*
3430 * When we get a short packet there are 2 possibilities. We can
3431 * return an error, or fix up the response to look like a valid
3432 * response and return what we have so far. If there are no
3433 * entries and the packet was short, then return -EIO. If there
3434 * are valid entries in the response, return them and pretend that
3435 * the call was successful, but incomplete. The caller can retry the
3436 * readdir starting at the last cookie.
3437 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07003438 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003440 if (nr)
3441 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442err_unmap:
3443 kunmap_atomic(kaddr, KM_USER0);
3444 return -errno_NFSERR_IO;
3445}
3446
3447static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3448{
3449 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3450 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003451 size_t hdrlen;
3452 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003453 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 char *kaddr;
3455 int status;
3456
3457 status = decode_op_hdr(xdr, OP_READLINK);
3458 if (status)
3459 return status;
3460
3461 /* Convert length of symlink */
3462 READ_BUF(4);
3463 READ32(len);
3464 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003465 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 return -ENAMETOOLONG;
3467 }
3468 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3469 recvd = req->rq_rcv_buf.len - hdrlen;
3470 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003471 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 "count %u > recvd %u\n", len, recvd);
3473 return -EIO;
3474 }
3475 xdr_read_pages(xdr, len);
3476 /*
3477 * The XDR encode routine has set things up so that
3478 * the link text will be copied directly into the
3479 * buffer. We just have to do overflow-checking,
3480 * and and null-terminate the text (the VFS expects
3481 * null-termination).
3482 */
3483 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3484 kaddr[len+rcvbuf->page_base] = '\0';
3485 kunmap_atomic(kaddr, KM_USER0);
3486 return 0;
3487}
3488
3489static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3490{
3491 int status;
3492
3493 status = decode_op_hdr(xdr, OP_REMOVE);
3494 if (status)
3495 goto out;
3496 status = decode_change_info(xdr, cinfo);
3497out:
3498 return status;
3499}
3500
3501static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3502 struct nfs4_change_info *new_cinfo)
3503{
3504 int status;
3505
3506 status = decode_op_hdr(xdr, OP_RENAME);
3507 if (status)
3508 goto out;
3509 if ((status = decode_change_info(xdr, old_cinfo)))
3510 goto out;
3511 status = decode_change_info(xdr, new_cinfo);
3512out:
3513 return status;
3514}
3515
3516static int decode_renew(struct xdr_stream *xdr)
3517{
3518 return decode_op_hdr(xdr, OP_RENEW);
3519}
3520
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003521static int
3522decode_restorefh(struct xdr_stream *xdr)
3523{
3524 return decode_op_hdr(xdr, OP_RESTOREFH);
3525}
3526
J. Bruce Fields029d1052005-06-22 17:16:22 +00003527static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3528 size_t *acl_len)
3529{
Al Viro8687b632006-10-19 23:28:48 -07003530 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003531 uint32_t attrlen,
3532 bitmap[2] = {0};
3533 struct kvec *iov = req->rq_rcv_buf.head;
3534 int status;
3535
3536 *acl_len = 0;
3537 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3538 goto out;
3539 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3540 goto out;
3541 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3542 goto out;
3543
3544 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3545 return -EIO;
3546 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003547 size_t hdrlen;
3548 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003549
3550 /* We ignore &savep and don't do consistency checks on
3551 * the attr length. Let userspace figure it out.... */
3552 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3553 recvd = req->rq_rcv_buf.len - hdrlen;
3554 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003555 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00003556 " acl reply: attrlen %u > recvd %u\n",
3557 attrlen, recvd);
3558 return -EINVAL;
3559 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04003560 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00003561 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04003562 } else
3563 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003564
3565out:
3566 return status;
3567}
3568
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569static int
3570decode_savefh(struct xdr_stream *xdr)
3571{
3572 return decode_op_hdr(xdr, OP_SAVEFH);
3573}
3574
3575static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3576{
Al Viro8687b632006-10-19 23:28:48 -07003577 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 uint32_t bmlen;
3579 int status;
3580
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 status = decode_op_hdr(xdr, OP_SETATTR);
3582 if (status)
3583 return status;
3584 READ_BUF(4);
3585 READ32(bmlen);
3586 READ_BUF(bmlen << 2);
3587 return 0;
3588}
3589
David Howellsadfa6f92006-08-22 20:06:08 -04003590static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591{
Al Viro8687b632006-10-19 23:28:48 -07003592 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 uint32_t opnum;
3594 int32_t nfserr;
3595
3596 READ_BUF(8);
3597 READ32(opnum);
3598 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003599 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05003600 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 return -EIO;
3602 }
3603 READ32(nfserr);
3604 if (nfserr == NFS_OK) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003605 READ_BUF(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 READ64(clp->cl_clientid);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003607 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608 } else if (nfserr == NFSERR_CLID_INUSE) {
3609 uint32_t len;
3610
3611 /* skip netid string */
3612 READ_BUF(4);
3613 READ32(len);
3614 READ_BUF(len);
3615
3616 /* skip uaddr string */
3617 READ_BUF(4);
3618 READ32(len);
3619 READ_BUF(len);
3620 return -NFSERR_CLID_INUSE;
3621 } else
Benny Halevy856dff32008-03-31 17:39:06 +03003622 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623
3624 return 0;
3625}
3626
3627static int decode_setclientid_confirm(struct xdr_stream *xdr)
3628{
3629 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3630}
3631
3632static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3633{
Al Viro8687b632006-10-19 23:28:48 -07003634 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 int status;
3636
3637 status = decode_op_hdr(xdr, OP_WRITE);
3638 if (status)
3639 return status;
3640
3641 READ_BUF(16);
3642 READ32(res->count);
3643 READ32(res->verf->committed);
3644 COPYMEM(res->verf->verifier, 8);
3645 return 0;
3646}
3647
3648static int decode_delegreturn(struct xdr_stream *xdr)
3649{
3650 return decode_op_hdr(xdr, OP_DELEGRETURN);
3651}
3652
3653/*
Benny Halevy49c25592008-12-23 16:06:16 -05003654 * END OF "GENERIC" DECODE ROUTINES.
3655 */
3656
3657/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658 * Decode OPEN_DOWNGRADE response
3659 */
Al Viro8687b632006-10-19 23:28:48 -07003660static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661{
Andy Adamson05d564f2008-12-23 16:06:15 -05003662 struct xdr_stream xdr;
3663 struct compound_hdr hdr;
3664 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665
Andy Adamson05d564f2008-12-23 16:06:15 -05003666 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3667 status = decode_compound_hdr(&xdr, &hdr);
3668 if (status)
3669 goto out;
3670 status = decode_putfh(&xdr);
3671 if (status)
3672 goto out;
3673 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003674 if (status != 0)
3675 goto out;
3676 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677out:
Andy Adamson05d564f2008-12-23 16:06:15 -05003678 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679}
3680
3681/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 * Decode ACCESS response
3683 */
Al Viro8687b632006-10-19 23:28:48 -07003684static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685{
3686 struct xdr_stream xdr;
3687 struct compound_hdr hdr;
3688 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003689
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3691 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3692 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04003693 status = decode_putfh(&xdr);
3694 if (status != 0)
3695 goto out;
3696 status = decode_access(&xdr, res);
3697 if (status != 0)
3698 goto out;
3699 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700out:
3701 return status;
3702}
3703
3704/*
3705 * Decode LOOKUP response
3706 */
Al Viro8687b632006-10-19 23:28:48 -07003707static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708{
3709 struct xdr_stream xdr;
3710 struct compound_hdr hdr;
3711 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003712
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3714 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3715 goto out;
3716 if ((status = decode_putfh(&xdr)) != 0)
3717 goto out;
3718 if ((status = decode_lookup(&xdr)) != 0)
3719 goto out;
3720 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3721 goto out;
3722 status = decode_getfattr(&xdr, res->fattr, res->server);
3723out:
3724 return status;
3725}
3726
3727/*
3728 * Decode LOOKUP_ROOT response
3729 */
Al Viro8687b632006-10-19 23:28:48 -07003730static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731{
3732 struct xdr_stream xdr;
3733 struct compound_hdr hdr;
3734 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003735
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3737 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3738 goto out;
3739 if ((status = decode_putrootfh(&xdr)) != 0)
3740 goto out;
3741 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3742 status = decode_getfattr(&xdr, res->fattr, res->server);
3743out:
3744 return status;
3745}
3746
3747/*
3748 * Decode REMOVE response
3749 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04003750static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751{
3752 struct xdr_stream xdr;
3753 struct compound_hdr hdr;
3754 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003755
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3757 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3758 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04003759 if ((status = decode_putfh(&xdr)) != 0)
3760 goto out;
3761 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3762 goto out;
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04003763 decode_getfattr(&xdr, &res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764out:
3765 return status;
3766}
3767
3768/*
3769 * Decode RENAME response
3770 */
Al Viro8687b632006-10-19 23:28:48 -07003771static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772{
3773 struct xdr_stream xdr;
3774 struct compound_hdr hdr;
3775 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003776
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3778 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3779 goto out;
3780 if ((status = decode_putfh(&xdr)) != 0)
3781 goto out;
3782 if ((status = decode_savefh(&xdr)) != 0)
3783 goto out;
3784 if ((status = decode_putfh(&xdr)) != 0)
3785 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04003786 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3787 goto out;
3788 /* Current FH is target directory */
3789 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3790 goto out;
3791 if ((status = decode_restorefh(&xdr)) != 0)
3792 goto out;
3793 decode_getfattr(&xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794out:
3795 return status;
3796}
3797
3798/*
3799 * Decode LINK response
3800 */
Al Viro8687b632006-10-19 23:28:48 -07003801static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802{
3803 struct xdr_stream xdr;
3804 struct compound_hdr hdr;
3805 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003806
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3808 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3809 goto out;
3810 if ((status = decode_putfh(&xdr)) != 0)
3811 goto out;
3812 if ((status = decode_savefh(&xdr)) != 0)
3813 goto out;
3814 if ((status = decode_putfh(&xdr)) != 0)
3815 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04003816 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3817 goto out;
3818 /*
3819 * Note order: OP_LINK leaves the directory as the current
3820 * filehandle.
3821 */
3822 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3823 goto out;
3824 if ((status = decode_restorefh(&xdr)) != 0)
3825 goto out;
3826 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827out:
3828 return status;
3829}
3830
3831/*
3832 * Decode CREATE response
3833 */
Al Viro8687b632006-10-19 23:28:48 -07003834static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835{
3836 struct xdr_stream xdr;
3837 struct compound_hdr hdr;
3838 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003839
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3841 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3842 goto out;
3843 if ((status = decode_putfh(&xdr)) != 0)
3844 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003845 if ((status = decode_savefh(&xdr)) != 0)
3846 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3848 goto out;
3849 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3850 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003851 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3852 goto out;
3853 if ((status = decode_restorefh(&xdr)) != 0)
3854 goto out;
3855 decode_getfattr(&xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856out:
3857 return status;
3858}
3859
3860/*
3861 * Decode SYMLINK response
3862 */
Al Viro8687b632006-10-19 23:28:48 -07003863static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864{
3865 return nfs4_xdr_dec_create(rqstp, p, res);
3866}
3867
3868/*
3869 * Decode GETATTR response
3870 */
Al Viro8687b632006-10-19 23:28:48 -07003871static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872{
3873 struct xdr_stream xdr;
3874 struct compound_hdr hdr;
3875 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003876
Linus Torvalds1da177e2005-04-16 15:20:36 -07003877 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3878 status = decode_compound_hdr(&xdr, &hdr);
3879 if (status)
3880 goto out;
3881 status = decode_putfh(&xdr);
3882 if (status)
3883 goto out;
3884 status = decode_getfattr(&xdr, res->fattr, res->server);
3885out:
3886 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887}
3888
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003889/*
3890 * Encode an SETACL request
3891 */
3892static int
Al Viro8687b632006-10-19 23:28:48 -07003893nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003894{
Andy Adamson05d564f2008-12-23 16:06:15 -05003895 struct xdr_stream xdr;
3896 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05003897 .nops = 0,
Andy Adamson05d564f2008-12-23 16:06:15 -05003898 };
3899 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003900
Andy Adamson05d564f2008-12-23 16:06:15 -05003901 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3902 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05003903 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05003904 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05003905 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05003906 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003907}
Andy Adamson05d564f2008-12-23 16:06:15 -05003908
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003909/*
3910 * Decode SETACL response
3911 */
3912static int
Al Viro8687b632006-10-19 23:28:48 -07003913nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003914{
3915 struct xdr_stream xdr;
3916 struct compound_hdr hdr;
3917 int status;
3918
3919 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3920 status = decode_compound_hdr(&xdr, &hdr);
3921 if (status)
3922 goto out;
3923 status = decode_putfh(&xdr);
3924 if (status)
3925 goto out;
3926 status = decode_setattr(&xdr, res);
3927out:
3928 return status;
3929}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930
3931/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00003932 * Decode GETACL response
3933 */
3934static int
Al Viro8687b632006-10-19 23:28:48 -07003935nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
J. Bruce Fields029d1052005-06-22 17:16:22 +00003936{
3937 struct xdr_stream xdr;
3938 struct compound_hdr hdr;
3939 int status;
3940
3941 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3942 status = decode_compound_hdr(&xdr, &hdr);
3943 if (status)
3944 goto out;
3945 status = decode_putfh(&xdr);
3946 if (status)
3947 goto out;
3948 status = decode_getacl(&xdr, rqstp, acl_len);
3949
3950out:
3951 return status;
3952}
3953
3954/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955 * Decode CLOSE response
3956 */
Al Viro8687b632006-10-19 23:28:48 -07003957static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958{
Andy Adamson05d564f2008-12-23 16:06:15 -05003959 struct xdr_stream xdr;
3960 struct compound_hdr hdr;
3961 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962
Andy Adamson05d564f2008-12-23 16:06:15 -05003963 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_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003971 if (status != 0)
3972 goto out;
3973 /*
3974 * Note: Server may do delete on close for this file
3975 * in which case the getattr call will fail with
3976 * an ESTALE error. Shouldn't be a problem,
3977 * though, since fattr->valid will remain unset.
3978 */
3979 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980out:
Andy Adamson05d564f2008-12-23 16:06:15 -05003981 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982}
3983
3984/*
3985 * Decode OPEN response
3986 */
Al Viro8687b632006-10-19 23:28:48 -07003987static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988{
Andy Adamson05d564f2008-12-23 16:06:15 -05003989 struct xdr_stream xdr;
3990 struct compound_hdr hdr;
3991 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992
Andy Adamson05d564f2008-12-23 16:06:15 -05003993 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3994 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003995 if (status)
3996 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05003997 status = decode_putfh(&xdr);
3998 if (status)
3999 goto out;
4000 status = decode_savefh(&xdr);
4001 if (status)
4002 goto out;
4003 status = decode_open(&xdr, res);
4004 if (status)
4005 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04004006 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004008 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4009 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04004010 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004011 goto out;
4012 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004014 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015}
4016
4017/*
4018 * Decode OPEN_CONFIRM response
4019 */
Al Viro8687b632006-10-19 23:28:48 -07004020static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021{
Andy Adamson05d564f2008-12-23 16:06:15 -05004022 struct xdr_stream xdr;
4023 struct compound_hdr hdr;
4024 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025
Andy Adamson05d564f2008-12-23 16:06:15 -05004026 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4027 status = decode_compound_hdr(&xdr, &hdr);
4028 if (status)
4029 goto out;
4030 status = decode_putfh(&xdr);
4031 if (status)
4032 goto out;
4033 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004035 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036}
4037
4038/*
4039 * Decode OPEN response
4040 */
Al Viro8687b632006-10-19 23:28:48 -07004041static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042{
Andy Adamson05d564f2008-12-23 16:06:15 -05004043 struct xdr_stream xdr;
4044 struct compound_hdr hdr;
4045 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046
Andy Adamson05d564f2008-12-23 16:06:15 -05004047 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4048 status = decode_compound_hdr(&xdr, &hdr);
4049 if (status)
4050 goto out;
4051 status = decode_putfh(&xdr);
4052 if (status)
4053 goto out;
4054 status = decode_open(&xdr, res);
4055 if (status)
4056 goto out;
Trond Myklebust864472e2006-01-03 09:55:15 +01004057 decode_getfattr(&xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004059 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060}
4061
4062/*
4063 * Decode SETATTR response
4064 */
Al Viro8687b632006-10-19 23:28:48 -07004065static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066{
Andy Adamson05d564f2008-12-23 16:06:15 -05004067 struct xdr_stream xdr;
4068 struct compound_hdr hdr;
4069 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070
Andy Adamson05d564f2008-12-23 16:06:15 -05004071 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4072 status = decode_compound_hdr(&xdr, &hdr);
4073 if (status)
4074 goto out;
4075 status = decode_putfh(&xdr);
4076 if (status)
4077 goto out;
4078 status = decode_setattr(&xdr, res);
4079 if (status)
4080 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 status = decode_getfattr(&xdr, res->fattr, res->server);
4082 if (status == NFS4ERR_DELAY)
4083 status = 0;
4084out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004085 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086}
4087
4088/*
4089 * Decode LOCK response
4090 */
Al Viro8687b632006-10-19 23:28:48 -07004091static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092{
4093 struct xdr_stream xdr;
4094 struct compound_hdr hdr;
4095 int status;
4096
4097 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4098 status = decode_compound_hdr(&xdr, &hdr);
4099 if (status)
4100 goto out;
4101 status = decode_putfh(&xdr);
4102 if (status)
4103 goto out;
4104 status = decode_lock(&xdr, res);
4105out:
4106 return status;
4107}
4108
4109/*
4110 * Decode LOCKT response
4111 */
Al Viro8687b632006-10-19 23:28:48 -07004112static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113{
4114 struct xdr_stream xdr;
4115 struct compound_hdr hdr;
4116 int status;
4117
4118 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4119 status = decode_compound_hdr(&xdr, &hdr);
4120 if (status)
4121 goto out;
4122 status = decode_putfh(&xdr);
4123 if (status)
4124 goto out;
4125 status = decode_lockt(&xdr, res);
4126out:
4127 return status;
4128}
4129
4130/*
4131 * Decode LOCKU response
4132 */
Al Viro8687b632006-10-19 23:28:48 -07004133static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134{
4135 struct xdr_stream xdr;
4136 struct compound_hdr hdr;
4137 int status;
4138
4139 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4140 status = decode_compound_hdr(&xdr, &hdr);
4141 if (status)
4142 goto out;
4143 status = decode_putfh(&xdr);
4144 if (status)
4145 goto out;
4146 status = decode_locku(&xdr, res);
4147out:
4148 return status;
4149}
4150
4151/*
4152 * Decode READLINK response
4153 */
Al Viro8687b632006-10-19 23:28:48 -07004154static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155{
4156 struct xdr_stream xdr;
4157 struct compound_hdr hdr;
4158 int status;
4159
4160 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4161 status = decode_compound_hdr(&xdr, &hdr);
4162 if (status)
4163 goto out;
4164 status = decode_putfh(&xdr);
4165 if (status)
4166 goto out;
4167 status = decode_readlink(&xdr, rqstp);
4168out:
4169 return status;
4170}
4171
4172/*
4173 * Decode READDIR response
4174 */
Al Viro8687b632006-10-19 23:28:48 -07004175static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176{
4177 struct xdr_stream xdr;
4178 struct compound_hdr hdr;
4179 int status;
4180
4181 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4182 status = decode_compound_hdr(&xdr, &hdr);
4183 if (status)
4184 goto out;
4185 status = decode_putfh(&xdr);
4186 if (status)
4187 goto out;
4188 status = decode_readdir(&xdr, rqstp, res);
4189out:
4190 return status;
4191}
4192
4193/*
4194 * Decode Read response
4195 */
Al Viro8687b632006-10-19 23:28:48 -07004196static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197{
4198 struct xdr_stream xdr;
4199 struct compound_hdr hdr;
4200 int status;
4201
4202 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4203 status = decode_compound_hdr(&xdr, &hdr);
4204 if (status)
4205 goto out;
4206 status = decode_putfh(&xdr);
4207 if (status)
4208 goto out;
4209 status = decode_read(&xdr, rqstp, res);
4210 if (!status)
4211 status = res->count;
4212out:
4213 return status;
4214}
4215
4216/*
4217 * Decode WRITE response
4218 */
Al Viro8687b632006-10-19 23:28:48 -07004219static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *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_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004233 if (status)
4234 goto out;
4235 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236 if (!status)
4237 status = res->count;
4238out:
4239 return status;
4240}
4241
4242/*
4243 * Decode COMMIT response
4244 */
Al Viro8687b632006-10-19 23:28:48 -07004245static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246{
4247 struct xdr_stream xdr;
4248 struct compound_hdr hdr;
4249 int status;
4250
4251 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4252 status = decode_compound_hdr(&xdr, &hdr);
4253 if (status)
4254 goto out;
4255 status = decode_putfh(&xdr);
4256 if (status)
4257 goto out;
4258 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004259 if (status)
4260 goto out;
4261 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262out:
4263 return status;
4264}
4265
4266/*
4267 * FSINFO request
4268 */
Al Viro8687b632006-10-19 23:28:48 -07004269static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270{
4271 struct xdr_stream xdr;
4272 struct compound_hdr hdr;
4273 int status;
4274
4275 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4276 status = decode_compound_hdr(&xdr, &hdr);
4277 if (!status)
4278 status = decode_putfh(&xdr);
4279 if (!status)
4280 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281 return status;
4282}
4283
4284/*
4285 * PATHCONF request
4286 */
Al Viro8687b632006-10-19 23:28:48 -07004287static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288{
4289 struct xdr_stream xdr;
4290 struct compound_hdr hdr;
4291 int status;
4292
4293 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4294 status = decode_compound_hdr(&xdr, &hdr);
4295 if (!status)
4296 status = decode_putfh(&xdr);
4297 if (!status)
4298 status = decode_pathconf(&xdr, pathconf);
4299 return status;
4300}
4301
4302/*
4303 * STATFS request
4304 */
Al Viro8687b632006-10-19 23:28:48 -07004305static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306{
4307 struct xdr_stream xdr;
4308 struct compound_hdr hdr;
4309 int status;
4310
4311 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4312 status = decode_compound_hdr(&xdr, &hdr);
4313 if (!status)
4314 status = decode_putfh(&xdr);
4315 if (!status)
4316 status = decode_statfs(&xdr, fsstat);
4317 return status;
4318}
4319
4320/*
4321 * GETATTR_BITMAP request
4322 */
Al Viro8687b632006-10-19 23:28:48 -07004323static 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 -07004324{
4325 struct xdr_stream xdr;
4326 struct compound_hdr hdr;
4327 int status;
4328
4329 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4330 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4331 goto out;
4332 if ((status = decode_putfh(&xdr)) != 0)
4333 goto out;
4334 status = decode_server_caps(&xdr, res);
4335out:
4336 return status;
4337}
4338
4339/*
4340 * Decode RENEW response
4341 */
Al Viro8687b632006-10-19 23:28:48 -07004342static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343{
4344 struct xdr_stream xdr;
4345 struct compound_hdr hdr;
4346 int status;
4347
4348 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4349 status = decode_compound_hdr(&xdr, &hdr);
4350 if (!status)
4351 status = decode_renew(&xdr);
4352 return status;
4353}
4354
4355/*
4356 * a SETCLIENTID request
4357 */
Al Viro8687b632006-10-19 23:28:48 -07004358static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04004359 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360{
4361 struct xdr_stream xdr;
4362 struct compound_hdr hdr;
4363 int status;
4364
4365 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4366 status = decode_compound_hdr(&xdr, &hdr);
4367 if (!status)
4368 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369 return status;
4370}
4371
4372/*
4373 * a SETCLIENTID_CONFIRM request
4374 */
Al Viro8687b632006-10-19 23:28:48 -07004375static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376{
4377 struct xdr_stream xdr;
4378 struct compound_hdr hdr;
4379 int status;
4380
4381 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4382 status = decode_compound_hdr(&xdr, &hdr);
4383 if (!status)
4384 status = decode_setclientid_confirm(&xdr);
4385 if (!status)
4386 status = decode_putrootfh(&xdr);
4387 if (!status)
4388 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 return status;
4390}
4391
4392/*
4393 * DELEGRETURN request
4394 */
Al Viro8687b632006-10-19 23:28:48 -07004395static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *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, &rqstp->rq_rcv_buf, p);
4402 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01004403 if (status != 0)
4404 goto out;
4405 status = decode_putfh(&xdr);
4406 if (status != 0)
4407 goto out;
4408 status = decode_delegreturn(&xdr);
4409 decode_getfattr(&xdr, res->fattr, res->server);
4410out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 return status;
4412}
4413
Trond Myklebust683b57b2006-06-09 09:34:22 -04004414/*
4415 * FS_LOCATIONS request
4416 */
Al Viro8687b632006-10-19 23:28:48 -07004417static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004418{
4419 struct xdr_stream xdr;
4420 struct compound_hdr hdr;
4421 int status;
4422
4423 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4424 status = decode_compound_hdr(&xdr, &hdr);
4425 if (status != 0)
4426 goto out;
4427 if ((status = decode_putfh(&xdr)) != 0)
4428 goto out;
4429 if ((status = decode_lookup(&xdr)) != 0)
4430 goto out;
4431 xdr_enter_page(&xdr, PAGE_SIZE);
4432 status = decode_getfattr(&xdr, &res->fattr, res->server);
4433out:
4434 return status;
4435}
4436
Al Viro0dbb4c62006-10-19 23:28:49 -07004437__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438{
4439 uint32_t bitmap[2] = {0};
4440 uint32_t len;
4441
4442 if (!*p++) {
4443 if (!*p)
4444 return ERR_PTR(-EAGAIN);
4445 entry->eof = 1;
4446 return ERR_PTR(-EBADCOOKIE);
4447 }
4448
4449 entry->prev_cookie = entry->cookie;
4450 p = xdr_decode_hyper(p, &entry->cookie);
4451 entry->len = ntohl(*p++);
4452 entry->name = (const char *) p;
4453 p += XDR_QUADLEN(entry->len);
4454
4455 /*
4456 * In case the server doesn't return an inode number,
4457 * we fake one here. (We don't use inode number 0,
4458 * since glibc seems to choke on it...)
4459 */
4460 entry->ino = 1;
4461
4462 len = ntohl(*p++); /* bitmap length */
4463 if (len-- > 0) {
4464 bitmap[0] = ntohl(*p++);
4465 if (len-- > 0) {
4466 bitmap[1] = ntohl(*p++);
4467 p += len;
4468 }
4469 }
4470 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4471 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00004472 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4473 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4474 /* Ignore the return value of rdattr_error for now */
4475 p++;
4476 len--;
4477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4479 xdr_decode_hyper(p, &entry->ino);
4480 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4481 xdr_decode_hyper(p, &entry->ino);
4482 p += len;
4483 }
4484
4485 entry->eof = !p[0] && p[1];
4486 return p;
4487}
4488
4489/*
4490 * We need to translate between nfs status return values and
4491 * the local errno values which may not be the same.
4492 */
4493static struct {
4494 int stat;
4495 int errno;
4496} nfs_errtbl[] = {
4497 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03004498 { NFS4ERR_PERM, -EPERM },
4499 { NFS4ERR_NOENT, -ENOENT },
4500 { NFS4ERR_IO, -errno_NFSERR_IO},
4501 { NFS4ERR_NXIO, -ENXIO },
4502 { NFS4ERR_ACCESS, -EACCES },
4503 { NFS4ERR_EXIST, -EEXIST },
4504 { NFS4ERR_XDEV, -EXDEV },
4505 { NFS4ERR_NOTDIR, -ENOTDIR },
4506 { NFS4ERR_ISDIR, -EISDIR },
4507 { NFS4ERR_INVAL, -EINVAL },
4508 { NFS4ERR_FBIG, -EFBIG },
4509 { NFS4ERR_NOSPC, -ENOSPC },
4510 { NFS4ERR_ROFS, -EROFS },
4511 { NFS4ERR_MLINK, -EMLINK },
4512 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4513 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4514 { NFS4ERR_DQUOT, -EDQUOT },
4515 { NFS4ERR_STALE, -ESTALE },
4516 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4517 { NFS4ERR_BADOWNER, -EINVAL },
4518 { NFS4ERR_BADNAME, -EINVAL },
4519 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4520 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4521 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4522 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4523 { NFS4ERR_BADTYPE, -EBADTYPE },
4524 { NFS4ERR_LOCKED, -EAGAIN },
4525 { NFS4ERR_RESOURCE, -EREMOTEIO },
4526 { NFS4ERR_SYMLINK, -ELOOP },
4527 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
4528 { NFS4ERR_DEADLOCK, -EDEADLK },
4529 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530 * to be handled by a
4531 * middle-layer.
4532 */
Benny Halevy856dff32008-03-31 17:39:06 +03004533 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534};
4535
4536/*
4537 * Convert an NFS error code to a local one.
4538 * This one is used jointly by NFSv2 and NFSv3.
4539 */
4540static int
David Howells0a8ea432006-08-22 20:06:08 -04004541nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004542{
4543 int i;
4544 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4545 if (nfs_errtbl[i].stat == stat)
4546 return nfs_errtbl[i].errno;
4547 }
4548 if (stat <= 10000 || stat > 10100) {
4549 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03004550 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551 }
4552 /* If we cannot translate the error, the recovery routines should
4553 * handle it.
4554 * Note: remaining NFSv4 error codes have values > 10000, so should
4555 * not conflict with native Linux error codes.
4556 */
Benny Halevy856dff32008-03-31 17:39:06 +03004557 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558}
4559
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560#define PROC(proc, argtype, restype) \
4561[NFSPROC4_CLNT_##proc] = { \
4562 .p_proc = NFSPROC4_COMPOUND, \
4563 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4564 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04004565 .p_arglen = NFS4_##argtype##_sz, \
4566 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05004567 .p_statidx = NFSPROC4_CLNT_##proc, \
4568 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05004569}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570
4571struct rpc_procinfo nfs4_procedures[] = {
4572 PROC(READ, enc_read, dec_read),
4573 PROC(WRITE, enc_write, dec_write),
4574 PROC(COMMIT, enc_commit, dec_commit),
4575 PROC(OPEN, enc_open, dec_open),
4576 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4577 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4578 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4579 PROC(CLOSE, enc_close, dec_close),
4580 PROC(SETATTR, enc_setattr, dec_setattr),
4581 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4582 PROC(RENEW, enc_renew, dec_renew),
4583 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4584 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4585 PROC(LOCK, enc_lock, dec_lock),
4586 PROC(LOCKT, enc_lockt, dec_lockt),
4587 PROC(LOCKU, enc_locku, dec_locku),
4588 PROC(ACCESS, enc_access, dec_access),
4589 PROC(GETATTR, enc_getattr, dec_getattr),
4590 PROC(LOOKUP, enc_lookup, dec_lookup),
4591 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4592 PROC(REMOVE, enc_remove, dec_remove),
4593 PROC(RENAME, enc_rename, dec_rename),
4594 PROC(LINK, enc_link, dec_link),
4595 PROC(SYMLINK, enc_symlink, dec_symlink),
4596 PROC(CREATE, enc_create, dec_create),
4597 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4598 PROC(STATFS, enc_statfs, dec_statfs),
4599 PROC(READLINK, enc_readlink, dec_readlink),
4600 PROC(READDIR, enc_readdir, dec_readdir),
4601 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4602 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00004603 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004604 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04004605 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606};
4607
4608struct rpc_version nfs_version4 = {
4609 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08004610 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611 .procs = nfs4_procedures
4612};
4613
4614/*
4615 * Local variables:
4616 * c-basic-offset: 8
4617 * End:
4618 */