blob: f1e2b8cdf33c62e93a518b17ef85de7d034b577a [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>
11 *
12 * 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
70/* lock,open owner id:
71 * we currently use size 1 (u32) out of (NFS4_OPAQUE_LIMIT >> 2)
72 */
73#define owner_id_maxsz (1 + 1)
74#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
75#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
76#define op_encode_hdr_maxsz (1)
77#define op_decode_hdr_maxsz (2)
78#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
79 (NFS4_FHSIZE >> 2))
80#define decode_putfh_maxsz (op_decode_hdr_maxsz)
81#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
82#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
83#define encode_getfh_maxsz (op_encode_hdr_maxsz)
84#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
85 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000086#define nfs4_fattr_bitmap_maxsz 3
87#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
89#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000090/* This is based on getfattr, which uses the most attributes: */
91#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
92 3 + 3 + 3 + 2 * nfs4_name_maxsz))
93#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
94 nfs4_fattr_value_maxsz)
95#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#define encode_savefh_maxsz (op_encode_hdr_maxsz)
97#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -040098#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
99#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2)
101#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
102#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
103#define decode_renew_maxsz (op_decode_hdr_maxsz)
104#define encode_setclientid_maxsz \
105 (op_encode_hdr_maxsz + \
106 4 /*server->ip_addr*/ + \
107 1 /*Netid*/ + \
108 6 /*uaddr*/ + \
109 6 + (NFS4_VERIFIER_SIZE >> 2))
110#define decode_setclientid_maxsz \
111 (op_decode_hdr_maxsz + \
112 2 + \
113 1024) /* large value for CLID_INUSE */
114#define encode_setclientid_confirm_maxsz \
115 (op_encode_hdr_maxsz + \
116 3 + (NFS4_VERIFIER_SIZE >> 2))
117#define decode_setclientid_confirm_maxsz \
118 (op_decode_hdr_maxsz)
119#define encode_lookup_maxsz (op_encode_hdr_maxsz + \
120 1 + ((3 + NFS4_FHSIZE) >> 2))
121#define encode_remove_maxsz (op_encode_hdr_maxsz + \
122 nfs4_name_maxsz)
123#define encode_rename_maxsz (op_encode_hdr_maxsz + \
124 2 * nfs4_name_maxsz)
125#define decode_rename_maxsz (op_decode_hdr_maxsz + 5 + 5)
126#define encode_link_maxsz (op_encode_hdr_maxsz + \
127 nfs4_name_maxsz)
128#define decode_link_maxsz (op_decode_hdr_maxsz + 5)
129#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
130 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400131 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000132 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
134#define encode_create_maxsz (op_encode_hdr_maxsz + \
135 2 + nfs4_name_maxsz + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000136 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define decode_create_maxsz (op_decode_hdr_maxsz + 8)
138#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
139#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
140#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
141#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
142#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
143 encode_putfh_maxsz + \
144 op_encode_hdr_maxsz + 7)
145#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
146 decode_putfh_maxsz + \
147 op_decode_hdr_maxsz + 2)
148#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
149 encode_putfh_maxsz + \
150 op_encode_hdr_maxsz)
151#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
152 decode_putfh_maxsz + \
153 op_decode_hdr_maxsz)
154#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
155 encode_putfh_maxsz + \
156 op_encode_hdr_maxsz + 9)
157#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
158 decode_putfh_maxsz + \
159 op_decode_hdr_maxsz + 2)
160#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
161 encode_putfh_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400162 op_encode_hdr_maxsz + 8 + \
163 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
165 decode_putfh_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400166 op_decode_hdr_maxsz + 4 + \
167 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
169 encode_putfh_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400170 op_encode_hdr_maxsz + 3 + \
171 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
173 decode_putfh_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400174 op_decode_hdr_maxsz + 2 + \
175 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
177 encode_putfh_maxsz + \
178 op_encode_hdr_maxsz + \
179 13 + 3 + 2 + 64 + \
180 encode_getattr_maxsz + \
181 encode_getfh_maxsz)
182#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
183 decode_putfh_maxsz + \
184 op_decode_hdr_maxsz + 4 + 5 + 2 + 3 + \
185 decode_getattr_maxsz + \
186 decode_getfh_maxsz)
187#define NFS4_enc_open_confirm_sz \
188 (compound_encode_hdr_maxsz + \
189 encode_putfh_maxsz + \
190 op_encode_hdr_maxsz + 5)
191#define NFS4_dec_open_confirm_sz (compound_decode_hdr_maxsz + \
192 decode_putfh_maxsz + \
193 op_decode_hdr_maxsz + 4)
194#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
195 encode_putfh_maxsz + \
196 op_encode_hdr_maxsz + \
197 11)
198#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
199 decode_putfh_maxsz + \
200 op_decode_hdr_maxsz + \
201 4 + 5 + 2 + 3)
202#define NFS4_enc_open_downgrade_sz \
203 (compound_encode_hdr_maxsz + \
204 encode_putfh_maxsz + \
Trond Myklebust516a6af2005-10-27 22:12:41 -0400205 op_encode_hdr_maxsz + 7 + \
206 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#define NFS4_dec_open_downgrade_sz \
208 (compound_decode_hdr_maxsz + \
209 decode_putfh_maxsz + \
Trond Myklebust516a6af2005-10-27 22:12:41 -0400210 op_decode_hdr_maxsz + 4 + \
211 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
213 encode_putfh_maxsz + \
Trond Myklebust516a6af2005-10-27 22:12:41 -0400214 op_encode_hdr_maxsz + 5 + \
215 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
217 decode_putfh_maxsz + \
Trond Myklebust516a6af2005-10-27 22:12:41 -0400218 op_decode_hdr_maxsz + 4 + \
219 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
221 encode_putfh_maxsz + \
222 op_encode_hdr_maxsz + 4 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000223 nfs4_fattr_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 encode_getattr_maxsz)
225#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
226 decode_putfh_maxsz + \
Chuck Lever6ce7dc92007-05-08 18:23:28 -0400227 op_decode_hdr_maxsz + 3 + \
228 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
230 encode_putfh_maxsz + \
231 encode_fsinfo_maxsz)
232#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
233 decode_putfh_maxsz + \
234 decode_fsinfo_maxsz)
235#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
236 encode_renew_maxsz)
237#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
238 decode_renew_maxsz)
239#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
240 encode_setclientid_maxsz)
241#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
242 decode_setclientid_maxsz)
243#define NFS4_enc_setclientid_confirm_sz \
244 (compound_encode_hdr_maxsz + \
245 encode_setclientid_confirm_maxsz + \
246 encode_putrootfh_maxsz + \
247 encode_fsinfo_maxsz)
248#define NFS4_dec_setclientid_confirm_sz \
249 (compound_decode_hdr_maxsz + \
250 decode_setclientid_confirm_maxsz + \
251 decode_putrootfh_maxsz + \
252 decode_fsinfo_maxsz)
253#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
254 encode_putfh_maxsz + \
255 encode_getattr_maxsz + \
256 op_encode_hdr_maxsz + \
257 1 + 1 + 2 + 2 + \
258 1 + 4 + 1 + 2 + \
259 owner_id_maxsz)
260#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
261 decode_putfh_maxsz + \
262 decode_getattr_maxsz + \
263 op_decode_hdr_maxsz + \
264 2 + 2 + 1 + 2 + \
265 owner_id_maxsz)
266#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
267 encode_putfh_maxsz + \
268 encode_getattr_maxsz + \
269 op_encode_hdr_maxsz + \
270 1 + 2 + 2 + 2 + \
271 owner_id_maxsz)
272#define NFS4_dec_lockt_sz (NFS4_dec_lock_sz)
273#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
274 encode_putfh_maxsz + \
275 encode_getattr_maxsz + \
276 op_encode_hdr_maxsz + \
277 1 + 1 + 4 + 2 + 2)
278#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
279 decode_putfh_maxsz + \
280 decode_getattr_maxsz + \
281 op_decode_hdr_maxsz + 4)
282#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
283 encode_putfh_maxsz + \
284 op_encode_hdr_maxsz + 1)
285#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
286 decode_putfh_maxsz + \
287 op_decode_hdr_maxsz + 2)
288#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
289 encode_putfh_maxsz + \
290 encode_getattr_maxsz)
291#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
292 decode_putfh_maxsz + \
293 decode_getattr_maxsz)
294#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
295 encode_putfh_maxsz + \
296 encode_lookup_maxsz + \
297 encode_getattr_maxsz + \
298 encode_getfh_maxsz)
299#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
300 decode_putfh_maxsz + \
301 op_decode_hdr_maxsz + \
302 decode_getattr_maxsz + \
303 decode_getfh_maxsz)
304#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
305 encode_putrootfh_maxsz + \
306 encode_getattr_maxsz + \
307 encode_getfh_maxsz)
308#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
309 decode_putrootfh_maxsz + \
310 decode_getattr_maxsz + \
311 decode_getfh_maxsz)
312#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
313 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400314 encode_remove_maxsz + \
315 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
317 decode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400318 op_decode_hdr_maxsz + 5 + \
319 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
321 encode_putfh_maxsz + \
322 encode_savefh_maxsz + \
323 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400324 encode_rename_maxsz + \
325 encode_getattr_maxsz + \
326 encode_restorefh_maxsz + \
327 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
329 decode_putfh_maxsz + \
330 decode_savefh_maxsz + \
331 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400332 decode_rename_maxsz + \
333 decode_getattr_maxsz + \
334 decode_restorefh_maxsz + \
335 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
337 encode_putfh_maxsz + \
338 encode_savefh_maxsz + \
339 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400340 encode_link_maxsz + \
341 decode_getattr_maxsz + \
342 encode_restorefh_maxsz + \
343 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
345 decode_putfh_maxsz + \
346 decode_savefh_maxsz + \
347 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400348 decode_link_maxsz + \
349 decode_getattr_maxsz + \
350 decode_restorefh_maxsz + \
351 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
353 encode_putfh_maxsz + \
354 encode_symlink_maxsz + \
355 encode_getattr_maxsz + \
356 encode_getfh_maxsz)
357#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
358 decode_putfh_maxsz + \
359 decode_symlink_maxsz + \
360 decode_getattr_maxsz + \
361 decode_getfh_maxsz)
362#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
363 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400364 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400366 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400368 encode_restorefh_maxsz + \
369 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
371 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400372 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400374 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400376 decode_restorefh_maxsz + \
377 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
379 encode_putfh_maxsz + \
380 encode_getattr_maxsz)
381#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
382 decode_putfh_maxsz + \
383 decode_getattr_maxsz)
384#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
385 encode_putfh_maxsz + \
386 encode_getattr_maxsz)
387#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
388 decode_putfh_maxsz + \
389 op_decode_hdr_maxsz + 12)
390#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800391 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 encode_getattr_maxsz)
393#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800394 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 decode_getattr_maxsz)
396#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
397 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100398 encode_delegreturn_maxsz + \
399 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100401 decode_delegreturn_maxsz + \
402 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000403#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
404 encode_putfh_maxsz + \
405 encode_getattr_maxsz)
406#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
407 decode_putfh_maxsz + \
408 op_decode_hdr_maxsz + \
409 nfs4_fattr_bitmap_maxsz + 1)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000410#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
411 encode_putfh_maxsz + \
412 op_encode_hdr_maxsz + 4 + \
413 nfs4_fattr_bitmap_maxsz + 1)
414#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
415 decode_putfh_maxsz + \
416 op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400417#define NFS4_enc_fs_locations_sz \
418 (compound_encode_hdr_maxsz + \
419 encode_putfh_maxsz + \
420 encode_getattr_maxsz)
421#define NFS4_dec_fs_locations_sz \
422 (compound_decode_hdr_maxsz + \
423 decode_putfh_maxsz + \
424 op_decode_hdr_maxsz + \
425 nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427static struct {
428 unsigned int mode;
429 unsigned int nfs2type;
430} nfs_type2fmt[] = {
431 { 0, NFNON },
432 { S_IFREG, NFREG },
433 { S_IFDIR, NFDIR },
434 { S_IFBLK, NFBLK },
435 { S_IFCHR, NFCHR },
436 { S_IFLNK, NFLNK },
437 { S_IFSOCK, NFSOCK },
438 { S_IFIFO, NFFIFO },
439 { 0, NFNON },
440 { 0, NFNON },
441};
442
443struct compound_hdr {
444 int32_t status;
445 uint32_t nops;
446 uint32_t taglen;
447 char * tag;
448};
449
450/*
451 * START OF "GENERIC" ENCODE ROUTINES.
452 * These may look a little ugly since they are imported from a "generic"
453 * set of XDR encode/decode routines which are intended to be shared by
454 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
455 *
456 * If the pain of reading these is too great, it should be a straightforward
457 * task to translate them into Linux-specific versions which are more
458 * consistent with the style used in NFSv2/v3...
459 */
460#define WRITE32(n) *p++ = htonl(n)
461#define WRITE64(n) do { \
462 *p++ = htonl((uint32_t)((n) >> 32)); \
463 *p++ = htonl((uint32_t)(n)); \
464} while (0)
465#define WRITEMEM(ptr,nbytes) do { \
466 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
467} while (0)
468
469#define RESERVE_SPACE(nbytes) do { \
470 p = xdr_reserve_space(xdr, nbytes); \
471 if (!p) printk("RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \
472 BUG_ON(!p); \
473} while (0)
474
475static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
476{
Al Viro8687b632006-10-19 23:28:48 -0700477 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 p = xdr_reserve_space(xdr, 4 + len);
480 BUG_ON(p == NULL);
481 xdr_encode_opaque(p, str, len);
482}
483
484static int encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
485{
Al Viro8687b632006-10-19 23:28:48 -0700486 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
489 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
490 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
491 WRITE32(hdr->taglen);
492 WRITEMEM(hdr->tag, hdr->taglen);
493 WRITE32(NFS4_MINOR_VERSION);
494 WRITE32(hdr->nops);
495 return 0;
496}
497
498static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
499{
Al Viro8687b632006-10-19 23:28:48 -0700500 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
503 BUG_ON(p == NULL);
504 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
505}
506
507static int encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
508{
509 char owner_name[IDMAP_NAMESZ];
510 char owner_group[IDMAP_NAMESZ];
511 int owner_namelen = 0;
512 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700513 __be32 *p;
514 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 int len;
516 uint32_t bmval0 = 0;
517 uint32_t bmval1 = 0;
518 int status;
519
520 /*
521 * We reserve enough space to write the entire attribute buffer at once.
522 * In the worst-case, this would be
523 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
524 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000525 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 */
527 len = 16;
528
529 /* Sigh */
530 if (iap->ia_valid & ATTR_SIZE)
531 len += 8;
532 if (iap->ia_valid & ATTR_MODE)
533 len += 4;
534 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400535 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 if (owner_namelen < 0) {
537 printk(KERN_WARNING "nfs: couldn't resolve uid %d to string\n",
538 iap->ia_uid);
539 /* XXX */
540 strcpy(owner_name, "nobody");
541 owner_namelen = sizeof("nobody") - 1;
542 /* goto out; */
543 }
544 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
545 }
546 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400547 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 if (owner_grouplen < 0) {
549 printk(KERN_WARNING "nfs4: couldn't resolve gid %d to string\n",
550 iap->ia_gid);
551 strcpy(owner_group, "nobody");
552 owner_grouplen = sizeof("nobody") - 1;
553 /* goto out; */
554 }
555 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
556 }
557 if (iap->ia_valid & ATTR_ATIME_SET)
558 len += 16;
559 else if (iap->ia_valid & ATTR_ATIME)
560 len += 4;
561 if (iap->ia_valid & ATTR_MTIME_SET)
562 len += 16;
563 else if (iap->ia_valid & ATTR_MTIME)
564 len += 4;
565 RESERVE_SPACE(len);
566
567 /*
568 * We write the bitmap length now, but leave the bitmap and the attribute
569 * buffer length to be backfilled at the end of this routine.
570 */
571 WRITE32(2);
572 q = p;
573 p += 3;
574
575 if (iap->ia_valid & ATTR_SIZE) {
576 bmval0 |= FATTR4_WORD0_SIZE;
577 WRITE64(iap->ia_size);
578 }
579 if (iap->ia_valid & ATTR_MODE) {
580 bmval1 |= FATTR4_WORD1_MODE;
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100581 WRITE32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 }
583 if (iap->ia_valid & ATTR_UID) {
584 bmval1 |= FATTR4_WORD1_OWNER;
585 WRITE32(owner_namelen);
586 WRITEMEM(owner_name, owner_namelen);
587 }
588 if (iap->ia_valid & ATTR_GID) {
589 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
590 WRITE32(owner_grouplen);
591 WRITEMEM(owner_group, owner_grouplen);
592 }
593 if (iap->ia_valid & ATTR_ATIME_SET) {
594 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
595 WRITE32(NFS4_SET_TO_CLIENT_TIME);
596 WRITE32(0);
597 WRITE32(iap->ia_mtime.tv_sec);
598 WRITE32(iap->ia_mtime.tv_nsec);
599 }
600 else if (iap->ia_valid & ATTR_ATIME) {
601 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
602 WRITE32(NFS4_SET_TO_SERVER_TIME);
603 }
604 if (iap->ia_valid & ATTR_MTIME_SET) {
605 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
606 WRITE32(NFS4_SET_TO_CLIENT_TIME);
607 WRITE32(0);
608 WRITE32(iap->ia_mtime.tv_sec);
609 WRITE32(iap->ia_mtime.tv_nsec);
610 }
611 else if (iap->ia_valid & ATTR_MTIME) {
612 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
613 WRITE32(NFS4_SET_TO_SERVER_TIME);
614 }
615
616 /*
617 * Now we backfill the bitmap and the attribute buffer length.
618 */
619 if (len != ((char *)p - (char *)q) + 4) {
620 printk ("encode_attr: Attr length calculation error! %u != %Zu\n",
621 len, ((char *)p - (char *)q) + 4);
622 BUG();
623 }
624 len = (char *)p - (char *)q - 12;
625 *q++ = htonl(bmval0);
626 *q++ = htonl(bmval1);
627 *q++ = htonl(len);
628
629 status = 0;
630/* out: */
631 return status;
632}
633
634static int encode_access(struct xdr_stream *xdr, u32 access)
635{
Al Viro8687b632006-10-19 23:28:48 -0700636 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
638 RESERVE_SPACE(8);
639 WRITE32(OP_ACCESS);
640 WRITE32(access);
641
642 return 0;
643}
644
645static int encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
646{
Al Viro8687b632006-10-19 23:28:48 -0700647 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Trond Myklebust95121352005-10-18 14:20:12 -0700649 RESERVE_SPACE(8+sizeof(arg->stateid->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 WRITE32(OP_CLOSE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700651 WRITE32(arg->seqid->sequence->counter);
Trond Myklebust95121352005-10-18 14:20:12 -0700652 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654 return 0;
655}
656
657static int encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args)
658{
Al Viro8687b632006-10-19 23:28:48 -0700659 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
661 RESERVE_SPACE(16);
662 WRITE32(OP_COMMIT);
663 WRITE64(args->offset);
664 WRITE32(args->count);
665
666 return 0;
667}
668
669static int encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create)
670{
Al Viro8687b632006-10-19 23:28:48 -0700671 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673 RESERVE_SPACE(8);
674 WRITE32(OP_CREATE);
675 WRITE32(create->ftype);
676
677 switch (create->ftype) {
678 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400679 RESERVE_SPACE(4);
680 WRITE32(create->u.symlink.len);
681 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 break;
683
684 case NF4BLK: case NF4CHR:
685 RESERVE_SPACE(8);
686 WRITE32(create->u.device.specdata1);
687 WRITE32(create->u.device.specdata2);
688 break;
689
690 default:
691 break;
692 }
693
694 RESERVE_SPACE(4 + create->name->len);
695 WRITE32(create->name->len);
696 WRITEMEM(create->name->name, create->name->len);
697
698 return encode_attrs(xdr, create->attrs, create->server);
699}
700
701static int encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap)
702{
Al Viro8687b632006-10-19 23:28:48 -0700703 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
705 RESERVE_SPACE(12);
706 WRITE32(OP_GETATTR);
707 WRITE32(1);
708 WRITE32(bitmap);
709 return 0;
710}
711
712static int encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1)
713{
Al Viro8687b632006-10-19 23:28:48 -0700714 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 RESERVE_SPACE(16);
717 WRITE32(OP_GETATTR);
718 WRITE32(2);
719 WRITE32(bm0);
720 WRITE32(bm1);
721 return 0;
722}
723
724static int encode_getfattr(struct xdr_stream *xdr, const u32* bitmask)
725{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 return encode_getattr_two(xdr,
727 bitmask[0] & nfs4_fattr_bitmap[0],
728 bitmask[1] & nfs4_fattr_bitmap[1]);
729}
730
731static int encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask)
732{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 return encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
734 bitmask[1] & nfs4_fsinfo_bitmap[1]);
735}
736
Manoj Naik830b8e32006-06-09 09:34:25 -0400737static int encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask)
738{
739 return encode_getattr_two(xdr,
740 bitmask[0] & nfs4_fs_locations_bitmap[0],
741 bitmask[1] & nfs4_fs_locations_bitmap[1]);
742}
743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744static int encode_getfh(struct xdr_stream *xdr)
745{
Al Viro8687b632006-10-19 23:28:48 -0700746 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 RESERVE_SPACE(4);
749 WRITE32(OP_GETFH);
750
751 return 0;
752}
753
754static int encode_link(struct xdr_stream *xdr, const struct qstr *name)
755{
Al Viro8687b632006-10-19 23:28:48 -0700756 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
758 RESERVE_SPACE(8 + name->len);
759 WRITE32(OP_LINK);
760 WRITE32(name->len);
761 WRITEMEM(name->name, name->len);
762
763 return 0;
764}
765
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100766static inline int nfs4_lock_type(struct file_lock *fl, int block)
767{
768 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
769 return block ? NFS4_READW_LT : NFS4_READ_LT;
770 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
771}
772
773static inline uint64_t nfs4_lock_length(struct file_lock *fl)
774{
775 if (fl->fl_end == OFFSET_MAX)
776 return ~(uint64_t)0;
777 return fl->fl_end - fl->fl_start + 1;
778}
779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780/*
781 * opcode,type,reclaim,offset,length,new_lock_owner = 32
782 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
783 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100784static int encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785{
Al Viro8687b632006-10-19 23:28:48 -0700786 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
788 RESERVE_SPACE(32);
789 WRITE32(OP_LOCK);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100790 WRITE32(nfs4_lock_type(args->fl, args->block));
791 WRITE32(args->reclaim);
792 WRITE64(args->fl->fl_start);
793 WRITE64(nfs4_lock_length(args->fl));
794 WRITE32(args->new_lock_owner);
795 if (args->new_lock_owner){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 RESERVE_SPACE(40);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100797 WRITE32(args->open_seqid->sequence->counter);
798 WRITEMEM(args->open_stateid->data, sizeof(args->open_stateid->data));
799 WRITE32(args->lock_seqid->sequence->counter);
800 WRITE64(args->lock_owner.clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 WRITE32(4);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100802 WRITE32(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 }
804 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 RESERVE_SPACE(20);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100806 WRITEMEM(args->lock_stateid->data, sizeof(args->lock_stateid->data));
807 WRITE32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 }
809
810 return 0;
811}
812
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100813static int encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
Al Viro8687b632006-10-19 23:28:48 -0700815 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
817 RESERVE_SPACE(40);
818 WRITE32(OP_LOCKT);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100819 WRITE32(nfs4_lock_type(args->fl, 0));
820 WRITE64(args->fl->fl_start);
821 WRITE64(nfs4_lock_length(args->fl));
822 WRITE64(args->lock_owner.clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 WRITE32(4);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100824 WRITE32(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 return 0;
827}
828
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100829static int encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830{
Al Viro8687b632006-10-19 23:28:48 -0700831 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 RESERVE_SPACE(44);
834 WRITE32(OP_LOCKU);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100835 WRITE32(nfs4_lock_type(args->fl, 0));
836 WRITE32(args->seqid->sequence->counter);
837 WRITEMEM(args->stateid->data, sizeof(args->stateid->data));
838 WRITE64(args->fl->fl_start);
839 WRITE64(nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 return 0;
842}
843
844static int encode_lookup(struct xdr_stream *xdr, const struct qstr *name)
845{
846 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -0700847 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
849 RESERVE_SPACE(8 + len);
850 WRITE32(OP_LOOKUP);
851 WRITE32(len);
852 WRITEMEM(name->name, len);
853
854 return 0;
855}
856
857static void encode_share_access(struct xdr_stream *xdr, int open_flags)
858{
Al Viro8687b632006-10-19 23:28:48 -0700859 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
861 RESERVE_SPACE(8);
862 switch (open_flags & (FMODE_READ|FMODE_WRITE)) {
863 case FMODE_READ:
864 WRITE32(NFS4_SHARE_ACCESS_READ);
865 break;
866 case FMODE_WRITE:
867 WRITE32(NFS4_SHARE_ACCESS_WRITE);
868 break;
869 case FMODE_READ|FMODE_WRITE:
870 WRITE32(NFS4_SHARE_ACCESS_BOTH);
871 break;
872 default:
873 BUG();
874 }
875 WRITE32(0); /* for linux, share_deny = 0 always */
876}
877
878static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
879{
Al Viro8687b632006-10-19 23:28:48 -0700880 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 /*
882 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
883 * owner 4 = 32
884 */
885 RESERVE_SPACE(8);
886 WRITE32(OP_OPEN);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700887 WRITE32(arg->seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 encode_share_access(xdr, arg->open_flags);
889 RESERVE_SPACE(16);
890 WRITE64(arg->clientid);
891 WRITE32(4);
892 WRITE32(arg->id);
893}
894
895static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
896{
Al Viro8687b632006-10-19 23:28:48 -0700897 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899 RESERVE_SPACE(4);
900 switch(arg->open_flags & O_EXCL) {
901 case 0:
902 WRITE32(NFS4_CREATE_UNCHECKED);
903 encode_attrs(xdr, arg->u.attrs, arg->server);
904 break;
905 default:
906 WRITE32(NFS4_CREATE_EXCLUSIVE);
907 encode_nfs4_verifier(xdr, &arg->u.verifier);
908 }
909}
910
911static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
912{
Al Viro8687b632006-10-19 23:28:48 -0700913 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 RESERVE_SPACE(4);
916 switch (arg->open_flags & O_CREAT) {
917 case 0:
918 WRITE32(NFS4_OPEN_NOCREATE);
919 break;
920 default:
921 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
922 WRITE32(NFS4_OPEN_CREATE);
923 encode_createmode(xdr, arg);
924 }
925}
926
927static inline void encode_delegation_type(struct xdr_stream *xdr, int delegation_type)
928{
Al Viro8687b632006-10-19 23:28:48 -0700929 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931 RESERVE_SPACE(4);
932 switch (delegation_type) {
933 case 0:
934 WRITE32(NFS4_OPEN_DELEGATE_NONE);
935 break;
936 case FMODE_READ:
937 WRITE32(NFS4_OPEN_DELEGATE_READ);
938 break;
939 case FMODE_WRITE|FMODE_READ:
940 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
941 break;
942 default:
943 BUG();
944 }
945}
946
947static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
948{
Al Viro8687b632006-10-19 23:28:48 -0700949 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
951 RESERVE_SPACE(4);
952 WRITE32(NFS4_OPEN_CLAIM_NULL);
953 encode_string(xdr, name->len, name->name);
954}
955
956static inline void encode_claim_previous(struct xdr_stream *xdr, int type)
957{
Al Viro8687b632006-10-19 23:28:48 -0700958 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
960 RESERVE_SPACE(4);
961 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
962 encode_delegation_type(xdr, type);
963}
964
965static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
966{
Al Viro8687b632006-10-19 23:28:48 -0700967 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
969 RESERVE_SPACE(4+sizeof(stateid->data));
970 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
971 WRITEMEM(stateid->data, sizeof(stateid->data));
972 encode_string(xdr, name->len, name->name);
973}
974
975static int encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg)
976{
977 encode_openhdr(xdr, arg);
978 encode_opentype(xdr, arg);
979 switch (arg->claim) {
980 case NFS4_OPEN_CLAIM_NULL:
981 encode_claim_null(xdr, arg->name);
982 break;
983 case NFS4_OPEN_CLAIM_PREVIOUS:
984 encode_claim_previous(xdr, arg->u.delegation_type);
985 break;
986 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
987 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
988 break;
989 default:
990 BUG();
991 }
992 return 0;
993}
994
995static int encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg)
996{
Al Viro8687b632006-10-19 23:28:48 -0700997 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
Trond Myklebustcdd4e682006-01-03 09:55:12 +0100999 RESERVE_SPACE(8+sizeof(arg->stateid->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 WRITE32(OP_OPEN_CONFIRM);
Trond Myklebustcdd4e682006-01-03 09:55:12 +01001001 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001002 WRITE32(arg->seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 return 0;
1005}
1006
1007static int encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg)
1008{
Al Viro8687b632006-10-19 23:28:48 -07001009 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Trond Myklebust95121352005-10-18 14:20:12 -07001011 RESERVE_SPACE(8+sizeof(arg->stateid->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 WRITE32(OP_OPEN_DOWNGRADE);
Trond Myklebust95121352005-10-18 14:20:12 -07001013 WRITEMEM(arg->stateid->data, sizeof(arg->stateid->data));
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001014 WRITE32(arg->seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 encode_share_access(xdr, arg->open_flags);
1016 return 0;
1017}
1018
1019static int
1020encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1021{
1022 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001023 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
1025 RESERVE_SPACE(8 + len);
1026 WRITE32(OP_PUTFH);
1027 WRITE32(len);
1028 WRITEMEM(fh->data, len);
1029
1030 return 0;
1031}
1032
1033static int encode_putrootfh(struct xdr_stream *xdr)
1034{
Al Viro8687b632006-10-19 23:28:48 -07001035 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
1037 RESERVE_SPACE(4);
1038 WRITE32(OP_PUTROOTFH);
1039
1040 return 0;
1041}
1042
1043static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1044{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001046 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
1048 RESERVE_SPACE(16);
1049 if (ctx->state != NULL) {
1050 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
1051 WRITEMEM(stateid.data, sizeof(stateid.data));
1052 } else
1053 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1054}
1055
1056static int encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args)
1057{
Al Viro8687b632006-10-19 23:28:48 -07001058 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
1060 RESERVE_SPACE(4);
1061 WRITE32(OP_READ);
1062
1063 encode_stateid(xdr, args->context);
1064
1065 RESERVE_SPACE(12);
1066 WRITE64(args->offset);
1067 WRITE32(args->count);
1068
1069 return 0;
1070}
1071
1072static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req)
1073{
1074 struct rpc_auth *auth = req->rq_task->tk_auth;
Manoj Naik97d312d2005-06-22 17:16:39 +00001075 uint32_t attrs[2] = {
1076 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1077 FATTR4_WORD1_MOUNTED_ON_FILEID,
1078 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 int replen;
Al Viro8687b632006-10-19 23:28:48 -07001080 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
1082 RESERVE_SPACE(32+sizeof(nfs4_verifier));
1083 WRITE32(OP_READDIR);
1084 WRITE64(readdir->cookie);
1085 WRITEMEM(readdir->verifier.data, sizeof(readdir->verifier.data));
1086 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1087 WRITE32(readdir->count);
1088 WRITE32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001089 /* Switch to mounted_on_fileid if the server supports it */
1090 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1091 attrs[0] &= ~FATTR4_WORD0_FILEID;
1092 else
1093 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1094 WRITE32(attrs[0] & readdir->bitmask[0]);
1095 WRITE32(attrs[1] & readdir->bitmask[1]);
Trond Myklebusteadf4592005-06-22 17:16:39 +00001096 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n",
1097 __FUNCTION__,
1098 (unsigned long long)readdir->cookie,
1099 ((u32 *)readdir->verifier.data)[0],
1100 ((u32 *)readdir->verifier.data)[1],
1101 attrs[0] & readdir->bitmask[0],
1102 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
1104 /* set up reply kvec
1105 * toplevel_status + taglen + rescount + OP_PUTFH + status
1106 * + OP_READDIR + status + verifer(2) = 9
1107 */
1108 replen = (RPC_REPHDRSIZE + auth->au_rslack + 9) << 2;
1109 xdr_inline_pages(&req->rq_rcv_buf, replen, readdir->pages,
1110 readdir->pgbase, readdir->count);
Trond Myklebusteadf4592005-06-22 17:16:39 +00001111 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
1112 __FUNCTION__, replen, readdir->pages,
1113 readdir->pgbase, readdir->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
1115 return 0;
1116}
1117
1118static int encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req)
1119{
1120 struct rpc_auth *auth = req->rq_task->tk_auth;
1121 unsigned int replen;
Al Viro8687b632006-10-19 23:28:48 -07001122 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
1124 RESERVE_SPACE(4);
1125 WRITE32(OP_READLINK);
1126
1127 /* set up reply kvec
1128 * toplevel_status + taglen + rescount + OP_PUTFH + status
1129 * + OP_READLINK + status + string length = 8
1130 */
1131 replen = (RPC_REPHDRSIZE + auth->au_rslack + 8) << 2;
1132 xdr_inline_pages(&req->rq_rcv_buf, replen, readlink->pages,
1133 readlink->pgbase, readlink->pglen);
1134
1135 return 0;
1136}
1137
1138static int encode_remove(struct xdr_stream *xdr, const struct qstr *name)
1139{
Al Viro8687b632006-10-19 23:28:48 -07001140 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
1142 RESERVE_SPACE(8 + name->len);
1143 WRITE32(OP_REMOVE);
1144 WRITE32(name->len);
1145 WRITEMEM(name->name, name->len);
1146
1147 return 0;
1148}
1149
1150static int encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname)
1151{
Al Viro8687b632006-10-19 23:28:48 -07001152 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
1154 RESERVE_SPACE(8 + oldname->len);
1155 WRITE32(OP_RENAME);
1156 WRITE32(oldname->len);
1157 WRITEMEM(oldname->name, oldname->len);
1158
1159 RESERVE_SPACE(4 + newname->len);
1160 WRITE32(newname->len);
1161 WRITEMEM(newname->name, newname->len);
1162
1163 return 0;
1164}
1165
David Howellsadfa6f92006-08-22 20:06:08 -04001166static int encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167{
Al Viro8687b632006-10-19 23:28:48 -07001168 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170 RESERVE_SPACE(12);
1171 WRITE32(OP_RENEW);
1172 WRITE64(client_stateid->cl_clientid);
1173
1174 return 0;
1175}
1176
1177static int
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001178encode_restorefh(struct xdr_stream *xdr)
1179{
Al Viro8687b632006-10-19 23:28:48 -07001180 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001181
1182 RESERVE_SPACE(4);
1183 WRITE32(OP_RESTOREFH);
1184
1185 return 0;
1186}
1187
1188static int
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001189encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg)
1190{
Al Viro8687b632006-10-19 23:28:48 -07001191 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001192
1193 RESERVE_SPACE(4+sizeof(zero_stateid.data));
1194 WRITE32(OP_SETATTR);
1195 WRITEMEM(zero_stateid.data, sizeof(zero_stateid.data));
1196 RESERVE_SPACE(2*4);
1197 WRITE32(1);
1198 WRITE32(FATTR4_WORD0_ACL);
1199 if (arg->acl_len % 4)
1200 return -EINVAL;
1201 RESERVE_SPACE(4);
1202 WRITE32(arg->acl_len);
1203 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1204 return 0;
1205}
1206
1207static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208encode_savefh(struct xdr_stream *xdr)
1209{
Al Viro8687b632006-10-19 23:28:48 -07001210 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 RESERVE_SPACE(4);
1213 WRITE32(OP_SAVEFH);
1214
1215 return 0;
1216}
1217
1218static int encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server)
1219{
1220 int status;
Al Viro8687b632006-10-19 23:28:48 -07001221 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
1223 RESERVE_SPACE(4+sizeof(arg->stateid.data));
1224 WRITE32(OP_SETATTR);
1225 WRITEMEM(arg->stateid.data, sizeof(arg->stateid.data));
1226
1227 if ((status = encode_attrs(xdr, arg->iap, server)))
1228 return status;
1229
1230 return 0;
1231}
1232
1233static int encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid)
1234{
Al Viro8687b632006-10-19 23:28:48 -07001235 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
1237 RESERVE_SPACE(4 + sizeof(setclientid->sc_verifier->data));
1238 WRITE32(OP_SETCLIENTID);
1239 WRITEMEM(setclientid->sc_verifier->data, sizeof(setclientid->sc_verifier->data));
1240
1241 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1242 RESERVE_SPACE(4);
1243 WRITE32(setclientid->sc_prog);
1244 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1245 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1246 RESERVE_SPACE(4);
1247 WRITE32(setclientid->sc_cb_ident);
1248
1249 return 0;
1250}
1251
David Howellsadfa6f92006-08-22 20:06:08 -04001252static int encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253{
Al Viro8687b632006-10-19 23:28:48 -07001254 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
1256 RESERVE_SPACE(12 + sizeof(client_state->cl_confirm.data));
1257 WRITE32(OP_SETCLIENTID_CONFIRM);
1258 WRITE64(client_state->cl_clientid);
1259 WRITEMEM(client_state->cl_confirm.data, sizeof(client_state->cl_confirm.data));
1260
1261 return 0;
1262}
1263
1264static int encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args)
1265{
Al Viro8687b632006-10-19 23:28:48 -07001266 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 RESERVE_SPACE(4);
1269 WRITE32(OP_WRITE);
1270
1271 encode_stateid(xdr, args->context);
1272
1273 RESERVE_SPACE(16);
1274 WRITE64(args->offset);
1275 WRITE32(args->stable);
1276 WRITE32(args->count);
1277
1278 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1279
1280 return 0;
1281}
1282
1283static int encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1284{
Al Viro8687b632006-10-19 23:28:48 -07001285 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
1287 RESERVE_SPACE(20);
1288
1289 WRITE32(OP_DELEGRETURN);
1290 WRITEMEM(stateid->data, sizeof(stateid->data));
1291 return 0;
1292
1293}
1294/*
1295 * END OF "GENERIC" ENCODE ROUTINES.
1296 */
1297
1298/*
1299 * Encode an ACCESS request
1300 */
Al Viro8687b632006-10-19 23:28:48 -07001301static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302{
1303 struct xdr_stream xdr;
1304 struct compound_hdr hdr = {
1305 .nops = 2,
1306 };
1307 int status;
1308
1309 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1310 encode_compound_hdr(&xdr, &hdr);
1311 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1312 status = encode_access(&xdr, args->access);
1313 return status;
1314}
1315
1316/*
1317 * Encode LOOKUP request
1318 */
Al Viro8687b632006-10-19 23:28:48 -07001319static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320{
1321 struct xdr_stream xdr;
1322 struct compound_hdr hdr = {
1323 .nops = 4,
1324 };
1325 int status;
1326
1327 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1328 encode_compound_hdr(&xdr, &hdr);
1329 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1330 goto out;
1331 if ((status = encode_lookup(&xdr, args->name)) != 0)
1332 goto out;
1333 if ((status = encode_getfh(&xdr)) != 0)
1334 goto out;
1335 status = encode_getfattr(&xdr, args->bitmask);
1336out:
1337 return status;
1338}
1339
1340/*
1341 * Encode LOOKUP_ROOT request
1342 */
Al Viro8687b632006-10-19 23:28:48 -07001343static 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 -07001344{
1345 struct xdr_stream xdr;
1346 struct compound_hdr hdr = {
1347 .nops = 3,
1348 };
1349 int status;
1350
1351 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1352 encode_compound_hdr(&xdr, &hdr);
1353 if ((status = encode_putrootfh(&xdr)) != 0)
1354 goto out;
1355 if ((status = encode_getfh(&xdr)) == 0)
1356 status = encode_getfattr(&xdr, args->bitmask);
1357out:
1358 return status;
1359}
1360
1361/*
1362 * Encode REMOVE request
1363 */
Al Viro8687b632006-10-19 23:28:48 -07001364static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs4_remove_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365{
1366 struct xdr_stream xdr;
1367 struct compound_hdr hdr = {
Trond Myklebust16e42952005-10-27 22:12:44 -04001368 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 };
1370 int status;
1371
1372 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1373 encode_compound_hdr(&xdr, &hdr);
Trond Myklebust16e42952005-10-27 22:12:44 -04001374 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1375 goto out;
1376 if ((status = encode_remove(&xdr, args->name)) != 0)
1377 goto out;
1378 status = encode_getfattr(&xdr, args->bitmask);
1379out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 return status;
1381}
1382
1383/*
1384 * Encode RENAME request
1385 */
Al Viro8687b632006-10-19 23:28:48 -07001386static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387{
1388 struct xdr_stream xdr;
1389 struct compound_hdr hdr = {
Trond Myklebust6caf2c82005-10-27 22:12:43 -04001390 .nops = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 };
1392 int status;
1393
1394 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1395 encode_compound_hdr(&xdr, &hdr);
1396 if ((status = encode_putfh(&xdr, args->old_dir)) != 0)
1397 goto out;
1398 if ((status = encode_savefh(&xdr)) != 0)
1399 goto out;
1400 if ((status = encode_putfh(&xdr, args->new_dir)) != 0)
1401 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04001402 if ((status = encode_rename(&xdr, args->old_name, args->new_name)) != 0)
1403 goto out;
1404 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1405 goto out;
1406 if ((status = encode_restorefh(&xdr)) != 0)
1407 goto out;
1408 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409out:
1410 return status;
1411}
1412
1413/*
1414 * Encode LINK request
1415 */
Al Viro8687b632006-10-19 23:28:48 -07001416static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417{
1418 struct xdr_stream xdr;
1419 struct compound_hdr hdr = {
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04001420 .nops = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 };
1422 int status;
1423
1424 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1425 encode_compound_hdr(&xdr, &hdr);
1426 if ((status = encode_putfh(&xdr, args->fh)) != 0)
1427 goto out;
1428 if ((status = encode_savefh(&xdr)) != 0)
1429 goto out;
1430 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1431 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04001432 if ((status = encode_link(&xdr, args->name)) != 0)
1433 goto out;
1434 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1435 goto out;
1436 if ((status = encode_restorefh(&xdr)) != 0)
1437 goto out;
1438 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439out:
1440 return status;
1441}
1442
1443/*
1444 * Encode CREATE request
1445 */
Al Viro8687b632006-10-19 23:28:48 -07001446static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447{
1448 struct xdr_stream xdr;
1449 struct compound_hdr hdr = {
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001450 .nops = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 };
1452 int status;
1453
1454 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1455 encode_compound_hdr(&xdr, &hdr);
1456 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
1457 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001458 if ((status = encode_savefh(&xdr)) != 0)
1459 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 if ((status = encode_create(&xdr, args)) != 0)
1461 goto out;
1462 if ((status = encode_getfh(&xdr)) != 0)
1463 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001464 if ((status = encode_getfattr(&xdr, args->bitmask)) != 0)
1465 goto out;
1466 if ((status = encode_restorefh(&xdr)) != 0)
1467 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 status = encode_getfattr(&xdr, args->bitmask);
1469out:
1470 return status;
1471}
1472
1473/*
1474 * Encode SYMLINK request
1475 */
Al Viro8687b632006-10-19 23:28:48 -07001476static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477{
1478 return nfs4_xdr_enc_create(req, p, args);
1479}
1480
1481/*
1482 * Encode GETATTR request
1483 */
Al Viro8687b632006-10-19 23:28:48 -07001484static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485{
1486 struct xdr_stream xdr;
1487 struct compound_hdr hdr = {
1488 .nops = 2,
1489 };
1490 int status;
1491
1492 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1493 encode_compound_hdr(&xdr, &hdr);
1494 if ((status = encode_putfh(&xdr, args->fh)) == 0)
1495 status = encode_getfattr(&xdr, args->bitmask);
1496 return status;
1497}
1498
1499/*
1500 * Encode a CLOSE request
1501 */
Al Viro8687b632006-10-19 23:28:48 -07001502static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503{
1504 struct xdr_stream xdr;
1505 struct compound_hdr hdr = {
Trond Myklebust516a6af2005-10-27 22:12:41 -04001506 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 };
1508 int status;
1509
1510 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1511 encode_compound_hdr(&xdr, &hdr);
1512 status = encode_putfh(&xdr, args->fh);
1513 if(status)
1514 goto out;
1515 status = encode_close(&xdr, args);
Trond Myklebust516a6af2005-10-27 22:12:41 -04001516 if (status != 0)
1517 goto out;
1518 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519out:
1520 return status;
1521}
1522
1523/*
1524 * Encode an OPEN request
1525 */
Al Viro8687b632006-10-19 23:28:48 -07001526static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527{
1528 struct xdr_stream xdr;
1529 struct compound_hdr hdr = {
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001530 .nops = 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 };
1532 int status;
1533
1534 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1535 encode_compound_hdr(&xdr, &hdr);
1536 status = encode_putfh(&xdr, args->fh);
1537 if (status)
1538 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001539 status = encode_savefh(&xdr);
1540 if (status)
1541 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 status = encode_open(&xdr, args);
1543 if (status)
1544 goto out;
1545 status = encode_getfh(&xdr);
1546 if (status)
1547 goto out;
1548 status = encode_getfattr(&xdr, args->bitmask);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001549 if (status)
1550 goto out;
1551 status = encode_restorefh(&xdr);
1552 if (status)
1553 goto out;
1554 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555out:
1556 return status;
1557}
1558
1559/*
1560 * Encode an OPEN_CONFIRM request
1561 */
Al Viro8687b632006-10-19 23:28:48 -07001562static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
1564 struct xdr_stream xdr;
1565 struct compound_hdr hdr = {
1566 .nops = 2,
1567 };
1568 int status;
1569
1570 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1571 encode_compound_hdr(&xdr, &hdr);
1572 status = encode_putfh(&xdr, args->fh);
1573 if(status)
1574 goto out;
1575 status = encode_open_confirm(&xdr, args);
1576out:
1577 return status;
1578}
1579
1580/*
1581 * Encode an OPEN request with no attributes.
1582 */
Al Viro8687b632006-10-19 23:28:48 -07001583static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584{
1585 struct xdr_stream xdr;
1586 struct compound_hdr hdr = {
Trond Myklebust864472e2006-01-03 09:55:15 +01001587 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 };
1589 int status;
1590
1591 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1592 encode_compound_hdr(&xdr, &hdr);
1593 status = encode_putfh(&xdr, args->fh);
1594 if (status)
1595 goto out;
1596 status = encode_open(&xdr, args);
Trond Myklebust864472e2006-01-03 09:55:15 +01001597 if (status)
1598 goto out;
1599 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600out:
1601 return status;
1602}
1603
1604/*
1605 * Encode an OPEN_DOWNGRADE request
1606 */
Al Viro8687b632006-10-19 23:28:48 -07001607static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608{
1609 struct xdr_stream xdr;
1610 struct compound_hdr hdr = {
Trond Myklebust516a6af2005-10-27 22:12:41 -04001611 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 };
1613 int status;
1614
1615 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1616 encode_compound_hdr(&xdr, &hdr);
1617 status = encode_putfh(&xdr, args->fh);
1618 if (status)
1619 goto out;
1620 status = encode_open_downgrade(&xdr, args);
Trond Myklebust516a6af2005-10-27 22:12:41 -04001621 if (status != 0)
1622 goto out;
1623 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624out:
1625 return status;
1626}
1627
1628/*
1629 * Encode a LOCK request
1630 */
Al Viro8687b632006-10-19 23:28:48 -07001631static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632{
1633 struct xdr_stream xdr;
1634 struct compound_hdr hdr = {
1635 .nops = 2,
1636 };
1637 int status;
1638
1639 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1640 encode_compound_hdr(&xdr, &hdr);
1641 status = encode_putfh(&xdr, args->fh);
1642 if(status)
1643 goto out;
1644 status = encode_lock(&xdr, args);
1645out:
1646 return status;
1647}
1648
1649/*
1650 * Encode a LOCKT request
1651 */
Al Viro8687b632006-10-19 23:28:48 -07001652static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653{
1654 struct xdr_stream xdr;
1655 struct compound_hdr hdr = {
1656 .nops = 2,
1657 };
1658 int status;
1659
1660 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1661 encode_compound_hdr(&xdr, &hdr);
1662 status = encode_putfh(&xdr, args->fh);
1663 if(status)
1664 goto out;
1665 status = encode_lockt(&xdr, args);
1666out:
1667 return status;
1668}
1669
1670/*
1671 * Encode a LOCKU request
1672 */
Al Viro8687b632006-10-19 23:28:48 -07001673static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674{
1675 struct xdr_stream xdr;
1676 struct compound_hdr hdr = {
1677 .nops = 2,
1678 };
1679 int status;
1680
1681 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1682 encode_compound_hdr(&xdr, &hdr);
1683 status = encode_putfh(&xdr, args->fh);
1684 if(status)
1685 goto out;
1686 status = encode_locku(&xdr, args);
1687out:
1688 return status;
1689}
1690
1691/*
1692 * Encode a READLINK request
1693 */
Al Viro8687b632006-10-19 23:28:48 -07001694static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695{
1696 struct xdr_stream xdr;
1697 struct compound_hdr hdr = {
1698 .nops = 2,
1699 };
1700 int status;
1701
1702 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1703 encode_compound_hdr(&xdr, &hdr);
1704 status = encode_putfh(&xdr, args->fh);
1705 if(status)
1706 goto out;
1707 status = encode_readlink(&xdr, args, req);
1708out:
1709 return status;
1710}
1711
1712/*
1713 * Encode a READDIR request
1714 */
Al Viro8687b632006-10-19 23:28:48 -07001715static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
1717 struct xdr_stream xdr;
1718 struct compound_hdr hdr = {
1719 .nops = 2,
1720 };
1721 int status;
1722
1723 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1724 encode_compound_hdr(&xdr, &hdr);
1725 status = encode_putfh(&xdr, args->fh);
1726 if(status)
1727 goto out;
1728 status = encode_readdir(&xdr, args, req);
1729out:
1730 return status;
1731}
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{
1738 struct rpc_auth *auth = req->rq_task->tk_auth;
1739 struct xdr_stream xdr;
1740 struct compound_hdr hdr = {
1741 .nops = 2,
1742 };
1743 int replen, status;
1744
1745 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1746 encode_compound_hdr(&xdr, &hdr);
1747 status = encode_putfh(&xdr, args->fh);
1748 if (status)
1749 goto out;
1750 status = encode_read(&xdr, args);
1751 if (status)
1752 goto out;
1753
1754 /* set up reply kvec
1755 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1756 * + OP_READ + status + eof + datalen = 9
1757 */
1758 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1759 xdr_inline_pages(&req->rq_rcv_buf, replen,
1760 args->pages, args->pgbase, args->count);
1761out:
1762 return status;
1763}
1764
1765/*
1766 * Encode an SETATTR request
1767 */
Al Viro8687b632006-10-19 23:28:48 -07001768static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
1770{
1771 struct xdr_stream xdr;
1772 struct compound_hdr hdr = {
1773 .nops = 3,
1774 };
1775 int status;
1776
1777 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1778 encode_compound_hdr(&xdr, &hdr);
1779 status = encode_putfh(&xdr, args->fh);
1780 if(status)
1781 goto out;
1782 status = encode_setattr(&xdr, args, args->server);
1783 if(status)
1784 goto out;
1785 status = encode_getfattr(&xdr, args->bitmask);
1786out:
1787 return status;
1788}
1789
1790/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00001791 * Encode a GETACL request
1792 */
1793static int
Al Viro8687b632006-10-19 23:28:48 -07001794nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001795 struct nfs_getaclargs *args)
1796{
1797 struct xdr_stream xdr;
1798 struct rpc_auth *auth = req->rq_task->tk_auth;
1799 struct compound_hdr hdr = {
1800 .nops = 2,
1801 };
1802 int replen, status;
1803
1804 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1805 encode_compound_hdr(&xdr, &hdr);
1806 status = encode_putfh(&xdr, args->fh);
1807 if (status)
1808 goto out;
1809 status = encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0);
1810 /* set up reply buffer: */
1811 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1812 xdr_inline_pages(&req->rq_rcv_buf, replen,
1813 args->acl_pages, args->acl_pgbase, args->acl_len);
1814out:
1815 return status;
1816}
1817
1818/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 * Encode a WRITE request
1820 */
Al Viro8687b632006-10-19 23:28:48 -07001821static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822{
1823 struct xdr_stream xdr;
1824 struct compound_hdr hdr = {
Trond Myklebust4f9838c2005-10-27 22:12:44 -04001825 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 };
1827 int status;
1828
1829 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1830 encode_compound_hdr(&xdr, &hdr);
1831 status = encode_putfh(&xdr, args->fh);
1832 if (status)
1833 goto out;
1834 status = encode_write(&xdr, args);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04001835 if (status)
1836 goto out;
1837 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838out:
1839 return status;
1840}
1841
1842/*
1843 * a COMMIT request
1844 */
Al Viro8687b632006-10-19 23:28:48 -07001845static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846{
1847 struct xdr_stream xdr;
1848 struct compound_hdr hdr = {
Trond Myklebust4f9838c2005-10-27 22:12:44 -04001849 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 };
1851 int status;
1852
1853 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1854 encode_compound_hdr(&xdr, &hdr);
1855 status = encode_putfh(&xdr, args->fh);
1856 if (status)
1857 goto out;
1858 status = encode_commit(&xdr, args);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04001859 if (status)
1860 goto out;
1861 status = encode_getfattr(&xdr, args->bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862out:
1863 return status;
1864}
1865
1866/*
1867 * FSINFO request
1868 */
Al Viro8687b632006-10-19 23:28:48 -07001869static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870{
1871 struct xdr_stream xdr;
1872 struct compound_hdr hdr = {
1873 .nops = 2,
1874 };
1875 int status;
1876
1877 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1878 encode_compound_hdr(&xdr, &hdr);
1879 status = encode_putfh(&xdr, args->fh);
1880 if (!status)
1881 status = encode_fsinfo(&xdr, args->bitmask);
1882 return status;
1883}
1884
1885/*
1886 * a PATHCONF request
1887 */
Al Viro8687b632006-10-19 23:28:48 -07001888static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 struct xdr_stream xdr;
1891 struct compound_hdr hdr = {
1892 .nops = 2,
1893 };
1894 int status;
1895
1896 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1897 encode_compound_hdr(&xdr, &hdr);
1898 status = encode_putfh(&xdr, args->fh);
1899 if (!status)
1900 status = encode_getattr_one(&xdr,
1901 args->bitmask[0] & nfs4_pathconf_bitmap[0]);
1902 return status;
1903}
1904
1905/*
1906 * a STATFS request
1907 */
Al Viro8687b632006-10-19 23:28:48 -07001908static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 struct xdr_stream xdr;
1911 struct compound_hdr hdr = {
1912 .nops = 2,
1913 };
1914 int status;
1915
1916 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1917 encode_compound_hdr(&xdr, &hdr);
1918 status = encode_putfh(&xdr, args->fh);
1919 if (status == 0)
1920 status = encode_getattr_two(&xdr,
1921 args->bitmask[0] & nfs4_statfs_bitmap[0],
1922 args->bitmask[1] & nfs4_statfs_bitmap[1]);
1923 return status;
1924}
1925
1926/*
1927 * GETATTR_BITMAP request
1928 */
Al Viro8687b632006-10-19 23:28:48 -07001929static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, const struct nfs_fh *fhandle)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930{
1931 struct xdr_stream xdr;
1932 struct compound_hdr hdr = {
1933 .nops = 2,
1934 };
1935 int status;
1936
1937 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1938 encode_compound_hdr(&xdr, &hdr);
1939 status = encode_putfh(&xdr, fhandle);
1940 if (status == 0)
1941 status = encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1942 FATTR4_WORD0_LINK_SUPPORT|
1943 FATTR4_WORD0_SYMLINK_SUPPORT|
1944 FATTR4_WORD0_ACLSUPPORT);
1945 return status;
1946}
1947
1948/*
1949 * a RENEW request
1950 */
Al Viro8687b632006-10-19 23:28:48 -07001951static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952{
1953 struct xdr_stream xdr;
1954 struct compound_hdr hdr = {
1955 .nops = 1,
1956 };
1957
1958 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1959 encode_compound_hdr(&xdr, &hdr);
1960 return encode_renew(&xdr, clp);
1961}
1962
1963/*
1964 * a SETCLIENTID request
1965 */
Al Viro8687b632006-10-19 23:28:48 -07001966static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967{
1968 struct xdr_stream xdr;
1969 struct compound_hdr hdr = {
1970 .nops = 1,
1971 };
1972
1973 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1974 encode_compound_hdr(&xdr, &hdr);
1975 return encode_setclientid(&xdr, sc);
1976}
1977
1978/*
1979 * a SETCLIENTID_CONFIRM request
1980 */
Al Viro8687b632006-10-19 23:28:48 -07001981static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982{
1983 struct xdr_stream xdr;
1984 struct compound_hdr hdr = {
1985 .nops = 3,
1986 };
1987 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
1988 int status;
1989
1990 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1991 encode_compound_hdr(&xdr, &hdr);
1992 status = encode_setclientid_confirm(&xdr, clp);
1993 if (!status)
1994 status = encode_putrootfh(&xdr);
1995 if (!status)
1996 status = encode_fsinfo(&xdr, lease_bitmap);
1997 return status;
1998}
1999
2000/*
2001 * DELEGRETURN request
2002 */
Al Viro8687b632006-10-19 23:28:48 -07002003static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004{
2005 struct xdr_stream xdr;
2006 struct compound_hdr hdr = {
Trond Myklebustfa178f22006-01-03 09:55:38 +01002007 .nops = 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 };
2009 int status;
2010
2011 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2012 encode_compound_hdr(&xdr, &hdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01002013 status = encode_putfh(&xdr, args->fhandle);
2014 if (status != 0)
2015 goto out;
2016 status = encode_delegreturn(&xdr, args->stateid);
2017 if (status != 0)
2018 goto out;
2019 status = encode_getfattr(&xdr, args->bitmask);
2020out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 return status;
2022}
2023
2024/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002025 * Encode FS_LOCATIONS request
2026 */
Al Viro8687b632006-10-19 23:28:48 -07002027static 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 -04002028{
2029 struct xdr_stream xdr;
2030 struct compound_hdr hdr = {
2031 .nops = 3,
2032 };
2033 struct rpc_auth *auth = req->rq_task->tk_auth;
2034 int replen;
2035 int status;
2036
2037 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2038 encode_compound_hdr(&xdr, &hdr);
2039 if ((status = encode_putfh(&xdr, args->dir_fh)) != 0)
2040 goto out;
2041 if ((status = encode_lookup(&xdr, args->name)) != 0)
2042 goto out;
Manoj Naik830b8e32006-06-09 09:34:25 -04002043 if ((status = encode_fs_locations(&xdr, args->bitmask)) != 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002044 goto out;
2045 /* set up reply
Manoj Naik830b8e32006-06-09 09:34:25 -04002046 * toplevel_status + OP_PUTFH + status
Trond Myklebust683b57b2006-06-09 09:34:22 -04002047 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2048 */
2049 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2050 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2051 0, PAGE_SIZE);
2052out:
2053 return status;
2054}
2055
2056/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 * START OF "GENERIC" DECODE ROUTINES.
2058 * These may look a little ugly since they are imported from a "generic"
2059 * set of XDR encode/decode routines which are intended to be shared by
2060 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2061 *
2062 * If the pain of reading these is too great, it should be a straightforward
2063 * task to translate them into Linux-specific versions which are more
2064 * consistent with the style used in NFSv2/v3...
2065 */
2066#define READ32(x) (x) = ntohl(*p++)
2067#define READ64(x) do { \
2068 (x) = (u64)ntohl(*p++) << 32; \
2069 (x) |= ntohl(*p++); \
2070} while (0)
2071#define READTIME(x) do { \
2072 p++; \
2073 (x.tv_sec) = ntohl(*p++); \
2074 (x.tv_nsec) = ntohl(*p++); \
2075} while (0)
2076#define COPYMEM(x,nbytes) do { \
2077 memcpy((x), p, nbytes); \
2078 p += XDR_QUADLEN(nbytes); \
2079} while (0)
2080
2081#define READ_BUF(nbytes) do { \
2082 p = xdr_inline_decode(xdr, nbytes); \
2083 if (!p) { \
2084 printk(KERN_WARNING "%s: reply buffer overflowed in line %d.", \
2085 __FUNCTION__, __LINE__); \
2086 return -EIO; \
2087 } \
2088} while (0)
2089
Trond Myklebust683b57b2006-06-09 09:34:22 -04002090static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091{
Al Viro8687b632006-10-19 23:28:48 -07002092 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
2094 READ_BUF(4);
2095 READ32(*len);
2096 READ_BUF(*len);
2097 *string = (char *)p;
2098 return 0;
2099}
2100
2101static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2102{
Al Viro8687b632006-10-19 23:28:48 -07002103 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
2105 READ_BUF(8);
2106 READ32(hdr->status);
2107 READ32(hdr->taglen);
2108
2109 READ_BUF(hdr->taglen + 4);
2110 hdr->tag = (char *)p;
2111 p += XDR_QUADLEN(hdr->taglen);
2112 READ32(hdr->nops);
2113 return 0;
2114}
2115
2116static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2117{
Al Viro8687b632006-10-19 23:28:48 -07002118 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 uint32_t opnum;
2120 int32_t nfserr;
2121
2122 READ_BUF(8);
2123 READ32(opnum);
2124 if (opnum != expected) {
2125 printk(KERN_NOTICE
2126 "nfs4_decode_op_hdr: Server returned operation"
2127 " %d but we issued a request for %d\n",
2128 opnum, expected);
2129 return -EIO;
2130 }
2131 READ32(nfserr);
2132 if (nfserr != NFS_OK)
David Howells0a8ea432006-08-22 20:06:08 -04002133 return -nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 return 0;
2135}
2136
2137/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002138static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139{
Al Viro8687b632006-10-19 23:28:48 -07002140 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002141 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 char *str;
2143
2144 READ_BUF(12);
2145 return decode_opaque_inline(xdr, &strlen, &str);
2146}
2147
2148static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2149{
Al Viro8687b632006-10-19 23:28:48 -07002150 uint32_t bmlen;
2151 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
2153 READ_BUF(4);
2154 READ32(bmlen);
2155
2156 bitmap[0] = bitmap[1] = 0;
2157 READ_BUF((bmlen << 2));
2158 if (bmlen > 0) {
2159 READ32(bitmap[0]);
2160 if (bmlen > 1)
2161 READ32(bitmap[1]);
2162 }
2163 return 0;
2164}
2165
Al Viro8687b632006-10-19 23:28:48 -07002166static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167{
Al Viro8687b632006-10-19 23:28:48 -07002168 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
2170 READ_BUF(4);
2171 READ32(*attrlen);
2172 *savep = xdr->p;
2173 return 0;
2174}
2175
2176static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2177{
2178 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2179 decode_attr_bitmap(xdr, bitmask);
2180 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2181 } else
2182 bitmask[0] = bitmask[1] = 0;
2183 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]);
2184 return 0;
2185}
2186
2187static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2188{
Al Viro8687b632006-10-19 23:28:48 -07002189 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190
2191 *type = 0;
2192 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2193 return -EIO;
2194 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2195 READ_BUF(4);
2196 READ32(*type);
2197 if (*type < NF4REG || *type > NF4NAMEDATTR) {
2198 dprintk("%s: bad type %d\n", __FUNCTION__, *type);
2199 return -EIO;
2200 }
2201 bitmap[0] &= ~FATTR4_WORD0_TYPE;
2202 }
2203 dprintk("%s: type=0%o\n", __FUNCTION__, nfs_type2fmt[*type].nfs2type);
2204 return 0;
2205}
2206
2207static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2208{
Al Viro8687b632006-10-19 23:28:48 -07002209 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
2211 *change = 0;
2212 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2213 return -EIO;
2214 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2215 READ_BUF(8);
2216 READ64(*change);
2217 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
2218 }
2219 dprintk("%s: change attribute=%Lu\n", __FUNCTION__,
2220 (unsigned long long)*change);
2221 return 0;
2222}
2223
2224static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2225{
Al Viro8687b632006-10-19 23:28:48 -07002226 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
2228 *size = 0;
2229 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2230 return -EIO;
2231 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2232 READ_BUF(8);
2233 READ64(*size);
2234 bitmap[0] &= ~FATTR4_WORD0_SIZE;
2235 }
2236 dprintk("%s: file size=%Lu\n", __FUNCTION__, (unsigned long long)*size);
2237 return 0;
2238}
2239
2240static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2241{
Al Viro8687b632006-10-19 23:28:48 -07002242 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
2244 *res = 0;
2245 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2246 return -EIO;
2247 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2248 READ_BUF(4);
2249 READ32(*res);
2250 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2251 }
2252 dprintk("%s: link support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2253 return 0;
2254}
2255
2256static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2257{
Al Viro8687b632006-10-19 23:28:48 -07002258 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
2260 *res = 0;
2261 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2262 return -EIO;
2263 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2264 READ_BUF(4);
2265 READ32(*res);
2266 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2267 }
2268 dprintk("%s: symlink support=%s\n", __FUNCTION__, *res == 0 ? "false" : "true");
2269 return 0;
2270}
2271
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002272static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273{
Al Viro8687b632006-10-19 23:28:48 -07002274 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
2276 fsid->major = 0;
2277 fsid->minor = 0;
2278 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2279 return -EIO;
2280 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2281 READ_BUF(16);
2282 READ64(fsid->major);
2283 READ64(fsid->minor);
2284 bitmap[0] &= ~FATTR4_WORD0_FSID;
2285 }
2286 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __FUNCTION__,
2287 (unsigned long long)fsid->major,
2288 (unsigned long long)fsid->minor);
2289 return 0;
2290}
2291
2292static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2293{
Al Viro8687b632006-10-19 23:28:48 -07002294 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
2296 *res = 60;
2297 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2298 return -EIO;
2299 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2300 READ_BUF(4);
2301 READ32(*res);
2302 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2303 }
2304 dprintk("%s: file size=%u\n", __FUNCTION__, (unsigned int)*res);
2305 return 0;
2306}
2307
2308static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2309{
Al Viro8687b632006-10-19 23:28:48 -07002310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
2312 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2313 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2314 return -EIO;
2315 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2316 READ_BUF(4);
2317 READ32(*res);
2318 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2319 }
2320 dprintk("%s: ACLs supported=%u\n", __FUNCTION__, (unsigned int)*res);
2321 return 0;
2322}
2323
2324static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2325{
Al Viro8687b632006-10-19 23:28:48 -07002326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
2328 *fileid = 0;
2329 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2330 return -EIO;
2331 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2332 READ_BUF(8);
2333 READ64(*fileid);
2334 bitmap[0] &= ~FATTR4_WORD0_FILEID;
2335 }
2336 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2337 return 0;
2338}
2339
Manoj Naik99baf622006-06-09 09:34:24 -04002340static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2341{
Al Viro8687b632006-10-19 23:28:48 -07002342 __be32 *p;
Manoj Naik99baf622006-06-09 09:34:24 -04002343
2344 *fileid = 0;
2345 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2346 return -EIO;
2347 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2348 READ_BUF(8);
2349 READ64(*fileid);
2350 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
2351 }
2352 dprintk("%s: fileid=%Lu\n", __FUNCTION__, (unsigned long long)*fileid);
2353 return 0;
2354}
2355
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2357{
Al Viro8687b632006-10-19 23:28:48 -07002358 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 int status = 0;
2360
2361 *res = 0;
2362 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2363 return -EIO;
2364 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2365 READ_BUF(8);
2366 READ64(*res);
2367 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2368 }
2369 dprintk("%s: files avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2370 return status;
2371}
2372
2373static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2374{
Al Viro8687b632006-10-19 23:28:48 -07002375 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 int status = 0;
2377
2378 *res = 0;
2379 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2380 return -EIO;
2381 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2382 READ_BUF(8);
2383 READ64(*res);
2384 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2385 }
2386 dprintk("%s: files free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2387 return status;
2388}
2389
2390static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2391{
Al Viro8687b632006-10-19 23:28:48 -07002392 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 int status = 0;
2394
2395 *res = 0;
2396 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2397 return -EIO;
2398 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2399 READ_BUF(8);
2400 READ64(*res);
2401 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2402 }
2403 dprintk("%s: files total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2404 return status;
2405}
2406
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002407static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2408{
2409 int n;
Al Viro8687b632006-10-19 23:28:48 -07002410 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002411 int status = 0;
2412
2413 READ_BUF(4);
2414 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002415 if (n < 0)
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002416 goto out_eio;
Andy Adamson33a43f22006-06-09 09:34:30 -04002417 if (n == 0)
2418 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002419 dprintk("path ");
2420 path->ncomponents = 0;
2421 while (path->ncomponents < n) {
2422 struct nfs4_string *component = &path->components[path->ncomponents];
2423 status = decode_opaque_inline(xdr, &component->len, &component->data);
2424 if (unlikely(status != 0))
2425 goto out_eio;
2426 if (path->ncomponents != n)
2427 dprintk("/");
2428 dprintk("%s", component->data);
2429 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2430 path->ncomponents++;
2431 else {
2432 dprintk("cannot parse %d components in path\n", n);
2433 goto out_eio;
2434 }
2435 }
2436out:
2437 dprintk("\n");
2438 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002439root_path:
2440/* a root pathname is sent as a zero component4 */
2441 path->ncomponents = 1;
2442 path->components[0].len=0;
2443 path->components[0].data=NULL;
2444 dprintk("path /\n");
2445 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002446out_eio:
2447 dprintk(" status %d", status);
2448 status = -EIO;
2449 goto out;
2450}
2451
2452static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002453{
2454 int n;
Al Viro8687b632006-10-19 23:28:48 -07002455 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002456 int status = -EIO;
2457
2458 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2459 goto out;
2460 status = 0;
2461 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2462 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002463 dprintk("%s: fsroot ", __FUNCTION__);
2464 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002465 if (unlikely(status != 0))
2466 goto out;
2467 READ_BUF(4);
2468 READ32(n);
2469 if (n <= 0)
2470 goto out_eio;
2471 res->nlocations = 0;
2472 while (res->nlocations < n) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002473 int m;
2474 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002475
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002476 READ_BUF(4);
2477 READ32(m);
2478 if (m <= 0)
2479 goto out_eio;
2480
2481 loc->nservers = 0;
2482 dprintk("%s: servers ", __FUNCTION__);
2483 while (loc->nservers < m) {
2484 struct nfs4_string *server = &loc->servers[loc->nservers];
2485 status = decode_opaque_inline(xdr, &server->len, &server->data);
2486 if (unlikely(status != 0))
2487 goto out_eio;
2488 dprintk("%s ", server->data);
2489 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2490 loc->nservers++;
2491 else {
2492 int i;
2493 dprintk("%s: using first %d of %d servers returned for location %d\n", __FUNCTION__, NFS4_FS_LOCATION_MAXSERVERS, m, res->nlocations);
2494 for (i = loc->nservers; i < m; i++) {
2495 int len;
2496 char *data;
2497 status = decode_opaque_inline(xdr, &len, &data);
2498 if (unlikely(status != 0))
2499 goto out_eio;
2500 }
2501 }
2502 }
2503 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002504 if (unlikely(status != 0))
2505 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002506 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002507 res->nlocations++;
2508 }
2509out:
2510 dprintk("%s: fs_locations done, error = %d\n", __FUNCTION__, status);
2511 return status;
2512out_eio:
2513 status = -EIO;
2514 goto out;
2515}
2516
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2518{
Al Viro8687b632006-10-19 23:28:48 -07002519 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 int status = 0;
2521
2522 *res = 0;
2523 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2524 return -EIO;
2525 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2526 READ_BUF(8);
2527 READ64(*res);
2528 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2529 }
2530 dprintk("%s: maxfilesize=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2531 return status;
2532}
2533
2534static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2535{
Al Viro8687b632006-10-19 23:28:48 -07002536 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 int status = 0;
2538
2539 *maxlink = 1;
2540 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2541 return -EIO;
2542 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2543 READ_BUF(4);
2544 READ32(*maxlink);
2545 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2546 }
2547 dprintk("%s: maxlink=%u\n", __FUNCTION__, *maxlink);
2548 return status;
2549}
2550
2551static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2552{
Al Viro8687b632006-10-19 23:28:48 -07002553 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 int status = 0;
2555
2556 *maxname = 1024;
2557 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2558 return -EIO;
2559 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2560 READ_BUF(4);
2561 READ32(*maxname);
2562 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2563 }
2564 dprintk("%s: maxname=%u\n", __FUNCTION__, *maxname);
2565 return status;
2566}
2567
2568static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2569{
Al Viro8687b632006-10-19 23:28:48 -07002570 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 int status = 0;
2572
2573 *res = 1024;
2574 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2575 return -EIO;
2576 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2577 uint64_t maxread;
2578 READ_BUF(8);
2579 READ64(maxread);
2580 if (maxread > 0x7FFFFFFF)
2581 maxread = 0x7FFFFFFF;
2582 *res = (uint32_t)maxread;
2583 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2584 }
2585 dprintk("%s: maxread=%lu\n", __FUNCTION__, (unsigned long)*res);
2586 return status;
2587}
2588
2589static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2590{
Al Viro8687b632006-10-19 23:28:48 -07002591 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 int status = 0;
2593
2594 *res = 1024;
2595 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2596 return -EIO;
2597 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2598 uint64_t maxwrite;
2599 READ_BUF(8);
2600 READ64(maxwrite);
2601 if (maxwrite > 0x7FFFFFFF)
2602 maxwrite = 0x7FFFFFFF;
2603 *res = (uint32_t)maxwrite;
2604 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2605 }
2606 dprintk("%s: maxwrite=%lu\n", __FUNCTION__, (unsigned long)*res);
2607 return status;
2608}
2609
2610static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *mode)
2611{
Al Viro8687b632006-10-19 23:28:48 -07002612 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613
2614 *mode = 0;
2615 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2616 return -EIO;
2617 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2618 READ_BUF(4);
2619 READ32(*mode);
2620 *mode &= ~S_IFMT;
2621 bitmap[1] &= ~FATTR4_WORD1_MODE;
2622 }
2623 dprintk("%s: file mode=0%o\n", __FUNCTION__, (unsigned int)*mode);
2624 return 0;
2625}
2626
2627static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2628{
Al Viro8687b632006-10-19 23:28:48 -07002629 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
2631 *nlink = 1;
2632 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2633 return -EIO;
2634 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2635 READ_BUF(4);
2636 READ32(*nlink);
2637 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
2638 }
2639 dprintk("%s: nlink=%u\n", __FUNCTION__, (unsigned int)*nlink);
2640 return 0;
2641}
2642
David Howellsadfa6f92006-08-22 20:06:08 -04002643static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, int32_t *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644{
Al Viro8687b632006-10-19 23:28:48 -07002645 uint32_t len;
2646 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
2648 *uid = -2;
2649 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2650 return -EIO;
2651 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2652 READ_BUF(4);
2653 READ32(len);
2654 READ_BUF(len);
2655 if (len < XDR_MAX_NETOBJ) {
2656 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) != 0)
2657 dprintk("%s: nfs_map_name_to_uid failed!\n",
2658 __FUNCTION__);
2659 } else
2660 printk(KERN_WARNING "%s: name too long (%u)!\n",
2661 __FUNCTION__, len);
2662 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2663 }
2664 dprintk("%s: uid=%d\n", __FUNCTION__, (int)*uid);
2665 return 0;
2666}
2667
David Howellsadfa6f92006-08-22 20:06:08 -04002668static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, int32_t *gid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669{
Al Viro8687b632006-10-19 23:28:48 -07002670 uint32_t len;
2671 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672
2673 *gid = -2;
2674 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2675 return -EIO;
2676 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2677 READ_BUF(4);
2678 READ32(len);
2679 READ_BUF(len);
2680 if (len < XDR_MAX_NETOBJ) {
2681 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) != 0)
2682 dprintk("%s: nfs_map_group_to_gid failed!\n",
2683 __FUNCTION__);
2684 } else
2685 printk(KERN_WARNING "%s: name too long (%u)!\n",
2686 __FUNCTION__, len);
2687 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2688 }
2689 dprintk("%s: gid=%d\n", __FUNCTION__, (int)*gid);
2690 return 0;
2691}
2692
2693static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
2694{
Al Viro8687b632006-10-19 23:28:48 -07002695 uint32_t major = 0, minor = 0;
2696 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697
2698 *rdev = MKDEV(0,0);
2699 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2700 return -EIO;
2701 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2702 dev_t tmp;
2703
2704 READ_BUF(8);
2705 READ32(major);
2706 READ32(minor);
2707 tmp = MKDEV(major, minor);
2708 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2709 *rdev = tmp;
2710 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
2711 }
2712 dprintk("%s: rdev=(0x%x:0x%x)\n", __FUNCTION__, major, minor);
2713 return 0;
2714}
2715
2716static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2717{
Al Viro8687b632006-10-19 23:28:48 -07002718 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 int status = 0;
2720
2721 *res = 0;
2722 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2723 return -EIO;
2724 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2725 READ_BUF(8);
2726 READ64(*res);
2727 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2728 }
2729 dprintk("%s: space avail=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2730 return status;
2731}
2732
2733static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2734{
Al Viro8687b632006-10-19 23:28:48 -07002735 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 int status = 0;
2737
2738 *res = 0;
2739 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2740 return -EIO;
2741 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2742 READ_BUF(8);
2743 READ64(*res);
2744 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2745 }
2746 dprintk("%s: space free=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2747 return status;
2748}
2749
2750static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2751{
Al Viro8687b632006-10-19 23:28:48 -07002752 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 int status = 0;
2754
2755 *res = 0;
2756 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2757 return -EIO;
2758 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2759 READ_BUF(8);
2760 READ64(*res);
2761 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2762 }
2763 dprintk("%s: space total=%Lu\n", __FUNCTION__, (unsigned long long)*res);
2764 return status;
2765}
2766
2767static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2768{
Al Viro8687b632006-10-19 23:28:48 -07002769 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770
2771 *used = 0;
2772 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2773 return -EIO;
2774 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2775 READ_BUF(8);
2776 READ64(*used);
2777 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
2778 }
2779 dprintk("%s: space used=%Lu\n", __FUNCTION__,
2780 (unsigned long long)*used);
2781 return 0;
2782}
2783
2784static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2785{
Al Viro8687b632006-10-19 23:28:48 -07002786 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 uint64_t sec;
2788 uint32_t nsec;
2789
2790 READ_BUF(12);
2791 READ64(sec);
2792 READ32(nsec);
2793 time->tv_sec = (time_t)sec;
2794 time->tv_nsec = (long)nsec;
2795 return 0;
2796}
2797
2798static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2799{
2800 int status = 0;
2801
2802 time->tv_sec = 0;
2803 time->tv_nsec = 0;
2804 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2805 return -EIO;
2806 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2807 status = decode_attr_time(xdr, time);
2808 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2809 }
2810 dprintk("%s: atime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2811 return status;
2812}
2813
2814static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2815{
2816 int status = 0;
2817
2818 time->tv_sec = 0;
2819 time->tv_nsec = 0;
2820 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2821 return -EIO;
2822 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2823 status = decode_attr_time(xdr, time);
2824 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2825 }
2826 dprintk("%s: ctime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2827 return status;
2828}
2829
2830static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2831{
2832 int status = 0;
2833
2834 time->tv_sec = 0;
2835 time->tv_nsec = 0;
2836 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2837 return -EIO;
2838 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2839 status = decode_attr_time(xdr, time);
2840 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2841 }
2842 dprintk("%s: mtime=%ld\n", __FUNCTION__, (long)time->tv_sec);
2843 return status;
2844}
2845
Al Viro8687b632006-10-19 23:28:48 -07002846static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847{
2848 unsigned int attrwords = XDR_QUADLEN(attrlen);
2849 unsigned int nwords = xdr->p - savep;
2850
2851 if (unlikely(attrwords != nwords)) {
2852 printk(KERN_WARNING "%s: server returned incorrect attribute length: %u %c %u\n",
2853 __FUNCTION__,
2854 attrwords << 2,
2855 (attrwords < nwords) ? '<' : '>',
2856 nwords << 2);
2857 return -EIO;
2858 }
2859 return 0;
2860}
2861
2862static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2863{
Al Viro8687b632006-10-19 23:28:48 -07002864 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865
2866 READ_BUF(20);
2867 READ32(cinfo->atomic);
2868 READ64(cinfo->before);
2869 READ64(cinfo->after);
2870 return 0;
2871}
2872
2873static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2874{
Al Viro8687b632006-10-19 23:28:48 -07002875 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 uint32_t supp, acc;
2877 int status;
2878
2879 status = decode_op_hdr(xdr, OP_ACCESS);
2880 if (status)
2881 return status;
2882 READ_BUF(8);
2883 READ32(supp);
2884 READ32(acc);
2885 access->supported = supp;
2886 access->access = acc;
2887 return 0;
2888}
2889
2890static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2891{
Al Viro8687b632006-10-19 23:28:48 -07002892 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 int status;
2894
2895 status = decode_op_hdr(xdr, OP_CLOSE);
2896 if (status)
2897 return status;
2898 READ_BUF(sizeof(res->stateid.data));
2899 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
2900 return 0;
2901}
2902
2903static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2904{
Al Viro8687b632006-10-19 23:28:48 -07002905 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 int status;
2907
2908 status = decode_op_hdr(xdr, OP_COMMIT);
2909 if (status)
2910 return status;
2911 READ_BUF(8);
2912 COPYMEM(res->verf->verifier, 8);
2913 return 0;
2914}
2915
2916static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2917{
Al Viro8687b632006-10-19 23:28:48 -07002918 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 uint32_t bmlen;
2920 int status;
2921
2922 status = decode_op_hdr(xdr, OP_CREATE);
2923 if (status)
2924 return status;
2925 if ((status = decode_change_info(xdr, cinfo)))
2926 return status;
2927 READ_BUF(4);
2928 READ32(bmlen);
2929 READ_BUF(bmlen << 2);
2930 return 0;
2931}
2932
2933static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2934{
Al Viro8687b632006-10-19 23:28:48 -07002935 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 uint32_t attrlen,
2937 bitmap[2] = {0};
2938 int status;
2939
2940 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2941 goto xdr_error;
2942 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2943 goto xdr_error;
2944 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2945 goto xdr_error;
2946 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2947 goto xdr_error;
2948 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2949 goto xdr_error;
2950 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2951 goto xdr_error;
2952 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2953 goto xdr_error;
2954 status = verify_attr_len(xdr, savep, attrlen);
2955xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04002956 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 return status;
2958}
2959
2960static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2961{
Al Viro8687b632006-10-19 23:28:48 -07002962 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 uint32_t attrlen,
2964 bitmap[2] = {0};
2965 int status;
2966
2967 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2968 goto xdr_error;
2969 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2970 goto xdr_error;
2971 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2972 goto xdr_error;
2973
2974 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2975 goto xdr_error;
2976 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2977 goto xdr_error;
2978 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2979 goto xdr_error;
2980 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2981 goto xdr_error;
2982 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2983 goto xdr_error;
2984 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2985 goto xdr_error;
2986
2987 status = verify_attr_len(xdr, savep, attrlen);
2988xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04002989 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 return status;
2991}
2992
2993static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
2994{
Al Viro8687b632006-10-19 23:28:48 -07002995 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 uint32_t attrlen,
2997 bitmap[2] = {0};
2998 int status;
2999
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 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3005 goto xdr_error;
3006
3007 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3008 goto xdr_error;
3009 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3010 goto xdr_error;
3011
3012 status = verify_attr_len(xdr, savep, attrlen);
3013xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04003014 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 return status;
3016}
3017
3018static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3019{
Al Viro8687b632006-10-19 23:28:48 -07003020 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 uint32_t attrlen,
3022 bitmap[2] = {0},
3023 type;
3024 int status, fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003025 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026
3027 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3028 goto xdr_error;
3029 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3030 goto xdr_error;
3031
3032 fattr->bitmap[0] = bitmap[0];
3033 fattr->bitmap[1] = bitmap[1];
3034
3035 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3036 goto xdr_error;
3037
3038
3039 if ((status = decode_attr_type(xdr, bitmap, &type)) != 0)
3040 goto xdr_error;
3041 fattr->type = nfs_type2fmt[type].nfs2type;
3042 fmode = nfs_type2fmt[type].mode;
3043
3044 if ((status = decode_attr_change(xdr, bitmap, &fattr->change_attr)) != 0)
3045 goto xdr_error;
3046 if ((status = decode_attr_size(xdr, bitmap, &fattr->size)) != 0)
3047 goto xdr_error;
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003048 if ((status = decode_attr_fsid(xdr, bitmap, &fattr->fsid)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 goto xdr_error;
3050 if ((status = decode_attr_fileid(xdr, bitmap, &fattr->fileid)) != 0)
3051 goto xdr_error;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003052 if ((status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003053 struct nfs4_fs_locations,
Trond Myklebust683b57b2006-06-09 09:34:22 -04003054 fattr))) != 0)
3055 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 if ((status = decode_attr_mode(xdr, bitmap, &fattr->mode)) != 0)
3057 goto xdr_error;
3058 fattr->mode |= fmode;
3059 if ((status = decode_attr_nlink(xdr, bitmap, &fattr->nlink)) != 0)
3060 goto xdr_error;
David Howells7539bba2006-08-22 20:06:09 -04003061 if ((status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 goto xdr_error;
David Howells7539bba2006-08-22 20:06:09 -04003063 if ((status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid)) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 goto xdr_error;
3065 if ((status = decode_attr_rdev(xdr, bitmap, &fattr->rdev)) != 0)
3066 goto xdr_error;
3067 if ((status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used)) != 0)
3068 goto xdr_error;
3069 if ((status = decode_attr_time_access(xdr, bitmap, &fattr->atime)) != 0)
3070 goto xdr_error;
3071 if ((status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime)) != 0)
3072 goto xdr_error;
3073 if ((status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime)) != 0)
3074 goto xdr_error;
Manoj Naik99baf622006-06-09 09:34:24 -04003075 if ((status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid)) != 0)
3076 goto xdr_error;
3077 if (fattr->fileid == 0 && fileid != 0)
3078 fattr->fileid = fileid;
Trond Myklebust33801142005-10-27 22:12:39 -04003079 if ((status = verify_attr_len(xdr, savep, attrlen)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 fattr->valid = NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04003082 dprintk("%s: xdr returned %d\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 return status;
3084}
3085
3086
3087static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3088{
Al Viro8687b632006-10-19 23:28:48 -07003089 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 uint32_t attrlen, bitmap[2];
3091 int status;
3092
3093 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3094 goto xdr_error;
3095 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3096 goto xdr_error;
3097 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3098 goto xdr_error;
3099
3100 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3101
3102 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3103 goto xdr_error;
3104 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3105 goto xdr_error;
3106 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3107 goto xdr_error;
3108 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3109 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3110 goto xdr_error;
3111 fsinfo->wtpref = fsinfo->wtmax;
3112
3113 status = verify_attr_len(xdr, savep, attrlen);
3114xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04003115 dprintk("%s: xdr returned %d!\n", __FUNCTION__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 return status;
3117}
3118
3119static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3120{
Al Viro8687b632006-10-19 23:28:48 -07003121 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 uint32_t len;
3123 int status;
3124
3125 status = decode_op_hdr(xdr, OP_GETFH);
3126 if (status)
3127 return status;
3128 /* Zero handle first to allow comparisons */
3129 memset(fh, 0, sizeof(*fh));
3130
3131 READ_BUF(4);
3132 READ32(len);
3133 if (len > NFS4_FHSIZE)
3134 return -EIO;
3135 fh->size = len;
3136 READ_BUF(len);
3137 COPYMEM(fh->data, len);
3138 return 0;
3139}
3140
3141static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3142{
3143 int status;
3144
3145 status = decode_op_hdr(xdr, OP_LINK);
3146 if (status)
3147 return status;
3148 return decode_change_info(xdr, cinfo);
3149}
3150
3151/*
3152 * We create the owner, so we know a proper owner.id length is 4.
3153 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003154static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003156 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003157 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003158 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159
3160 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003161 READ64(offset);
3162 READ64(length);
3163 READ32(type);
3164 if (fl != NULL) {
3165 fl->fl_start = (loff_t)offset;
3166 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3167 if (length == ~(uint64_t)0)
3168 fl->fl_end = OFFSET_MAX;
3169 fl->fl_type = F_WRLCK;
3170 if (type & 1)
3171 fl->fl_type = F_RDLCK;
3172 fl->fl_pid = 0;
3173 }
3174 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 READ32(namelen);
3176 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 return -NFS4ERR_DENIED;
3178}
3179
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003180static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181{
Al Viro8687b632006-10-19 23:28:48 -07003182 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 int status;
3184
3185 status = decode_op_hdr(xdr, OP_LOCK);
3186 if (status == 0) {
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003187 READ_BUF(sizeof(res->stateid.data));
3188 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 } else if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003190 return decode_lock_denied(xdr, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 return status;
3192}
3193
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003194static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195{
3196 int status;
3197 status = decode_op_hdr(xdr, OP_LOCKT);
3198 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003199 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 return status;
3201}
3202
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003203static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204{
Al Viro8687b632006-10-19 23:28:48 -07003205 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 int status;
3207
3208 status = decode_op_hdr(xdr, OP_LOCKU);
3209 if (status == 0) {
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003210 READ_BUF(sizeof(res->stateid.data));
3211 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 }
3213 return status;
3214}
3215
3216static int decode_lookup(struct xdr_stream *xdr)
3217{
3218 return decode_op_hdr(xdr, OP_LOOKUP);
3219}
3220
3221/* This is too sick! */
3222static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3223{
Al Viro8687b632006-10-19 23:28:48 -07003224 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 uint32_t limit_type, nblocks, blocksize;
3226
3227 READ_BUF(12);
3228 READ32(limit_type);
3229 switch (limit_type) {
3230 case 1:
3231 READ64(*maxsize);
3232 break;
3233 case 2:
3234 READ32(nblocks);
3235 READ32(blocksize);
3236 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
3237 }
3238 return 0;
3239}
3240
3241static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3242{
Al Viro8687b632006-10-19 23:28:48 -07003243 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 uint32_t delegation_type;
3245
3246 READ_BUF(4);
3247 READ32(delegation_type);
3248 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3249 res->delegation_type = 0;
3250 return 0;
3251 }
3252 READ_BUF(20);
3253 COPYMEM(res->delegation.data, sizeof(res->delegation.data));
3254 READ32(res->do_recall);
3255 switch (delegation_type) {
3256 case NFS4_OPEN_DELEGATE_READ:
3257 res->delegation_type = FMODE_READ;
3258 break;
3259 case NFS4_OPEN_DELEGATE_WRITE:
3260 res->delegation_type = FMODE_WRITE|FMODE_READ;
3261 if (decode_space_limit(xdr, &res->maxsize) < 0)
3262 return -EIO;
3263 }
David Howells7539bba2006-08-22 20:06:09 -04003264 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265}
3266
3267static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3268{
Al Viro8687b632006-10-19 23:28:48 -07003269 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 uint32_t bmlen;
3271 int status;
3272
3273 status = decode_op_hdr(xdr, OP_OPEN);
3274 if (status)
3275 return status;
3276 READ_BUF(sizeof(res->stateid.data));
3277 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3278
3279 decode_change_info(xdr, &res->cinfo);
3280
3281 READ_BUF(8);
3282 READ32(res->rflags);
3283 READ32(bmlen);
3284 if (bmlen > 10)
3285 goto xdr_error;
3286
3287 READ_BUF(bmlen << 2);
3288 p += bmlen;
3289 return decode_delegation(xdr, res);
3290xdr_error:
Trond Myklebust16c32b72005-10-27 22:12:45 -04003291 dprintk("%s: Bitmap too large! Length = %u\n", __FUNCTION__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 return -EIO;
3293}
3294
3295static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3296{
Al Viro8687b632006-10-19 23:28:48 -07003297 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 int status;
3299
3300 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3301 if (status)
3302 return status;
3303 READ_BUF(sizeof(res->stateid.data));
3304 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3305 return 0;
3306}
3307
3308static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3309{
Al Viro8687b632006-10-19 23:28:48 -07003310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 int status;
3312
3313 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3314 if (status)
3315 return status;
3316 READ_BUF(sizeof(res->stateid.data));
3317 COPYMEM(res->stateid.data, sizeof(res->stateid.data));
3318 return 0;
3319}
3320
3321static int decode_putfh(struct xdr_stream *xdr)
3322{
3323 return decode_op_hdr(xdr, OP_PUTFH);
3324}
3325
3326static int decode_putrootfh(struct xdr_stream *xdr)
3327{
3328 return decode_op_hdr(xdr, OP_PUTROOTFH);
3329}
3330
3331static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3332{
3333 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003334 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 uint32_t count, eof, recvd, hdrlen;
3336 int status;
3337
3338 status = decode_op_hdr(xdr, OP_READ);
3339 if (status)
3340 return status;
3341 READ_BUF(8);
3342 READ32(eof);
3343 READ32(count);
3344 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3345 recvd = req->rq_rcv_buf.len - hdrlen;
3346 if (count > recvd) {
3347 printk(KERN_WARNING "NFS: server cheating in read reply: "
3348 "count %u > recvd %u\n", count, recvd);
3349 count = recvd;
3350 eof = 0;
3351 }
3352 xdr_read_pages(xdr, count);
3353 res->eof = eof;
3354 res->count = count;
3355 return 0;
3356}
3357
3358static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3359{
3360 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3361 struct page *page = *rcvbuf->pages;
3362 struct kvec *iov = rcvbuf->head;
3363 unsigned int nr, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003364 __be32 *end, *entry, *p, *kaddr;
David Howellse8896492006-08-24 15:44:19 -04003365 uint32_t len, attrlen, xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 int hdrlen, recvd, status;
3367
3368 status = decode_op_hdr(xdr, OP_READDIR);
3369 if (status)
3370 return status;
3371 READ_BUF(8);
3372 COPYMEM(readdir->verifier.data, 8);
Trond Myklebusteadf4592005-06-22 17:16:39 +00003373 dprintk("%s: verifier = 0x%x%x\n",
3374 __FUNCTION__,
3375 ((u32 *)readdir->verifier.data)[0],
3376 ((u32 *)readdir->verifier.data)[1]);
3377
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
3379 hdrlen = (char *) p - (char *) iov->iov_base;
3380 recvd = rcvbuf->len - hdrlen;
3381 if (pglen > recvd)
3382 pglen = recvd;
3383 xdr_read_pages(xdr, pglen);
3384
3385 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003386 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003387 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 entry = p;
3389 for (nr = 0; *p++; nr++) {
David Howellse8896492006-08-24 15:44:19 -04003390 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003392 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 p += 2; /* cookie */
3394 len = ntohl(*p++); /* filename length */
3395 if (len > NFS4_MAXNAMLEN) {
3396 printk(KERN_WARNING "NFS: giant filename in readdir (len 0x%x)\n", len);
3397 goto err_unmap;
3398 }
David Howellse8896492006-08-24 15:44:19 -04003399 xlen = XDR_QUADLEN(len);
3400 if (end - p < xlen + 1)
3401 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003402 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003403 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003405 if (end - p < len + 1)
3406 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003409 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003411 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 entry = p;
3413 }
3414 if (!nr && (entry[0] != 0 || entry[1] == 0))
3415 goto short_pkt;
3416out:
3417 kunmap_atomic(kaddr, KM_USER0);
3418 return 0;
3419short_pkt:
Trond Myklebusteadf4592005-06-22 17:16:39 +00003420 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 entry[0] = entry[1] = 0;
3422 /* truncate listing ? */
3423 if (!nr) {
3424 printk(KERN_NOTICE "NFS: readdir reply truncated!\n");
3425 entry[1] = 1;
3426 }
3427 goto out;
3428err_unmap:
3429 kunmap_atomic(kaddr, KM_USER0);
3430 return -errno_NFSERR_IO;
3431}
3432
3433static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3434{
3435 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3436 struct kvec *iov = rcvbuf->head;
3437 int hdrlen, len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003438 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 char *kaddr;
3440 int status;
3441
3442 status = decode_op_hdr(xdr, OP_READLINK);
3443 if (status)
3444 return status;
3445
3446 /* Convert length of symlink */
3447 READ_BUF(4);
3448 READ32(len);
3449 if (len >= rcvbuf->page_len || len <= 0) {
3450 dprintk(KERN_WARNING "nfs: server returned giant symlink!\n");
3451 return -ENAMETOOLONG;
3452 }
3453 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3454 recvd = req->rq_rcv_buf.len - hdrlen;
3455 if (recvd < len) {
3456 printk(KERN_WARNING "NFS: server cheating in readlink reply: "
3457 "count %u > recvd %u\n", len, recvd);
3458 return -EIO;
3459 }
3460 xdr_read_pages(xdr, len);
3461 /*
3462 * The XDR encode routine has set things up so that
3463 * the link text will be copied directly into the
3464 * buffer. We just have to do overflow-checking,
3465 * and and null-terminate the text (the VFS expects
3466 * null-termination).
3467 */
3468 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3469 kaddr[len+rcvbuf->page_base] = '\0';
3470 kunmap_atomic(kaddr, KM_USER0);
3471 return 0;
3472}
3473
3474static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3475{
3476 int status;
3477
3478 status = decode_op_hdr(xdr, OP_REMOVE);
3479 if (status)
3480 goto out;
3481 status = decode_change_info(xdr, cinfo);
3482out:
3483 return status;
3484}
3485
3486static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3487 struct nfs4_change_info *new_cinfo)
3488{
3489 int status;
3490
3491 status = decode_op_hdr(xdr, OP_RENAME);
3492 if (status)
3493 goto out;
3494 if ((status = decode_change_info(xdr, old_cinfo)))
3495 goto out;
3496 status = decode_change_info(xdr, new_cinfo);
3497out:
3498 return status;
3499}
3500
3501static int decode_renew(struct xdr_stream *xdr)
3502{
3503 return decode_op_hdr(xdr, OP_RENEW);
3504}
3505
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003506static int
3507decode_restorefh(struct xdr_stream *xdr)
3508{
3509 return decode_op_hdr(xdr, OP_RESTOREFH);
3510}
3511
J. Bruce Fields029d1052005-06-22 17:16:22 +00003512static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3513 size_t *acl_len)
3514{
Al Viro8687b632006-10-19 23:28:48 -07003515 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003516 uint32_t attrlen,
3517 bitmap[2] = {0};
3518 struct kvec *iov = req->rq_rcv_buf.head;
3519 int status;
3520
3521 *acl_len = 0;
3522 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3523 goto out;
3524 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3525 goto out;
3526 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3527 goto out;
3528
3529 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3530 return -EIO;
3531 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
3532 int hdrlen, recvd;
3533
3534 /* We ignore &savep and don't do consistency checks on
3535 * the attr length. Let userspace figure it out.... */
3536 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3537 recvd = req->rq_rcv_buf.len - hdrlen;
3538 if (attrlen > recvd) {
3539 printk(KERN_WARNING "NFS: server cheating in getattr"
3540 " acl reply: attrlen %u > recvd %u\n",
3541 attrlen, recvd);
3542 return -EINVAL;
3543 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04003544 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00003545 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04003546 } else
3547 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003548
3549out:
3550 return status;
3551}
3552
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553static int
3554decode_savefh(struct xdr_stream *xdr)
3555{
3556 return decode_op_hdr(xdr, OP_SAVEFH);
3557}
3558
3559static int decode_setattr(struct xdr_stream *xdr, struct nfs_setattrres *res)
3560{
Al Viro8687b632006-10-19 23:28:48 -07003561 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 uint32_t bmlen;
3563 int status;
3564
3565
3566 status = decode_op_hdr(xdr, OP_SETATTR);
3567 if (status)
3568 return status;
3569 READ_BUF(4);
3570 READ32(bmlen);
3571 READ_BUF(bmlen << 2);
3572 return 0;
3573}
3574
David Howellsadfa6f92006-08-22 20:06:08 -04003575static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576{
Al Viro8687b632006-10-19 23:28:48 -07003577 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 uint32_t opnum;
3579 int32_t nfserr;
3580
3581 READ_BUF(8);
3582 READ32(opnum);
3583 if (opnum != OP_SETCLIENTID) {
3584 printk(KERN_NOTICE
3585 "nfs4_decode_setclientid: Server returned operation"
3586 " %d\n", opnum);
3587 return -EIO;
3588 }
3589 READ32(nfserr);
3590 if (nfserr == NFS_OK) {
3591 READ_BUF(8 + sizeof(clp->cl_confirm.data));
3592 READ64(clp->cl_clientid);
3593 COPYMEM(clp->cl_confirm.data, sizeof(clp->cl_confirm.data));
3594 } else if (nfserr == NFSERR_CLID_INUSE) {
3595 uint32_t len;
3596
3597 /* skip netid string */
3598 READ_BUF(4);
3599 READ32(len);
3600 READ_BUF(len);
3601
3602 /* skip uaddr string */
3603 READ_BUF(4);
3604 READ32(len);
3605 READ_BUF(len);
3606 return -NFSERR_CLID_INUSE;
3607 } else
David Howells0a8ea432006-08-22 20:06:08 -04003608 return -nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609
3610 return 0;
3611}
3612
3613static int decode_setclientid_confirm(struct xdr_stream *xdr)
3614{
3615 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3616}
3617
3618static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3619{
Al Viro8687b632006-10-19 23:28:48 -07003620 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 int status;
3622
3623 status = decode_op_hdr(xdr, OP_WRITE);
3624 if (status)
3625 return status;
3626
3627 READ_BUF(16);
3628 READ32(res->count);
3629 READ32(res->verf->committed);
3630 COPYMEM(res->verf->verifier, 8);
3631 return 0;
3632}
3633
3634static int decode_delegreturn(struct xdr_stream *xdr)
3635{
3636 return decode_op_hdr(xdr, OP_DELEGRETURN);
3637}
3638
3639/*
3640 * Decode OPEN_DOWNGRADE response
3641 */
Al Viro8687b632006-10-19 23:28:48 -07003642static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643{
3644 struct xdr_stream xdr;
3645 struct compound_hdr hdr;
3646 int status;
3647
3648 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3649 status = decode_compound_hdr(&xdr, &hdr);
3650 if (status)
3651 goto out;
3652 status = decode_putfh(&xdr);
3653 if (status)
3654 goto out;
3655 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003656 if (status != 0)
3657 goto out;
3658 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659out:
3660 return status;
3661}
3662
3663/*
3664 * END OF "GENERIC" DECODE ROUTINES.
3665 */
3666
3667/*
3668 * Decode ACCESS response
3669 */
Al Viro8687b632006-10-19 23:28:48 -07003670static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671{
3672 struct xdr_stream xdr;
3673 struct compound_hdr hdr;
3674 int status;
3675
3676 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3677 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3678 goto out;
3679 if ((status = decode_putfh(&xdr)) == 0)
3680 status = decode_access(&xdr, res);
3681out:
3682 return status;
3683}
3684
3685/*
3686 * Decode LOOKUP response
3687 */
Al Viro8687b632006-10-19 23:28:48 -07003688static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689{
3690 struct xdr_stream xdr;
3691 struct compound_hdr hdr;
3692 int status;
3693
3694 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3695 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3696 goto out;
3697 if ((status = decode_putfh(&xdr)) != 0)
3698 goto out;
3699 if ((status = decode_lookup(&xdr)) != 0)
3700 goto out;
3701 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3702 goto out;
3703 status = decode_getfattr(&xdr, res->fattr, res->server);
3704out:
3705 return status;
3706}
3707
3708/*
3709 * Decode LOOKUP_ROOT response
3710 */
Al Viro8687b632006-10-19 23:28:48 -07003711static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712{
3713 struct xdr_stream xdr;
3714 struct compound_hdr hdr;
3715 int status;
3716
3717 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3718 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3719 goto out;
3720 if ((status = decode_putrootfh(&xdr)) != 0)
3721 goto out;
3722 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3723 status = decode_getfattr(&xdr, res->fattr, res->server);
3724out:
3725 return status;
3726}
3727
3728/*
3729 * Decode REMOVE response
3730 */
Al Viro8687b632006-10-19 23:28:48 -07003731static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_remove_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732{
3733 struct xdr_stream xdr;
3734 struct compound_hdr hdr;
3735 int status;
3736
3737 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3738 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3739 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04003740 if ((status = decode_putfh(&xdr)) != 0)
3741 goto out;
3742 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3743 goto out;
3744 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745out:
3746 return status;
3747}
3748
3749/*
3750 * Decode RENAME response
3751 */
Al Viro8687b632006-10-19 23:28:48 -07003752static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753{
3754 struct xdr_stream xdr;
3755 struct compound_hdr hdr;
3756 int status;
3757
3758 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3759 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3760 goto out;
3761 if ((status = decode_putfh(&xdr)) != 0)
3762 goto out;
3763 if ((status = decode_savefh(&xdr)) != 0)
3764 goto out;
3765 if ((status = decode_putfh(&xdr)) != 0)
3766 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04003767 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3768 goto out;
3769 /* Current FH is target directory */
3770 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3771 goto out;
3772 if ((status = decode_restorefh(&xdr)) != 0)
3773 goto out;
3774 decode_getfattr(&xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775out:
3776 return status;
3777}
3778
3779/*
3780 * Decode LINK response
3781 */
Al Viro8687b632006-10-19 23:28:48 -07003782static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783{
3784 struct xdr_stream xdr;
3785 struct compound_hdr hdr;
3786 int status;
3787
3788 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3789 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3790 goto out;
3791 if ((status = decode_putfh(&xdr)) != 0)
3792 goto out;
3793 if ((status = decode_savefh(&xdr)) != 0)
3794 goto out;
3795 if ((status = decode_putfh(&xdr)) != 0)
3796 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04003797 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3798 goto out;
3799 /*
3800 * Note order: OP_LINK leaves the directory as the current
3801 * filehandle.
3802 */
3803 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3804 goto out;
3805 if ((status = decode_restorefh(&xdr)) != 0)
3806 goto out;
3807 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808out:
3809 return status;
3810}
3811
3812/*
3813 * Decode CREATE response
3814 */
Al Viro8687b632006-10-19 23:28:48 -07003815static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816{
3817 struct xdr_stream xdr;
3818 struct compound_hdr hdr;
3819 int status;
3820
3821 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3822 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3823 goto out;
3824 if ((status = decode_putfh(&xdr)) != 0)
3825 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003826 if ((status = decode_savefh(&xdr)) != 0)
3827 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3829 goto out;
3830 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3831 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003832 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3833 goto out;
3834 if ((status = decode_restorefh(&xdr)) != 0)
3835 goto out;
3836 decode_getfattr(&xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837out:
3838 return status;
3839}
3840
3841/*
3842 * Decode SYMLINK response
3843 */
Al Viro8687b632006-10-19 23:28:48 -07003844static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845{
3846 return nfs4_xdr_dec_create(rqstp, p, res);
3847}
3848
3849/*
3850 * Decode GETATTR response
3851 */
Al Viro8687b632006-10-19 23:28:48 -07003852static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853{
3854 struct xdr_stream xdr;
3855 struct compound_hdr hdr;
3856 int status;
3857
3858 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3859 status = decode_compound_hdr(&xdr, &hdr);
3860 if (status)
3861 goto out;
3862 status = decode_putfh(&xdr);
3863 if (status)
3864 goto out;
3865 status = decode_getfattr(&xdr, res->fattr, res->server);
3866out:
3867 return status;
3868
3869}
3870
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003871/*
3872 * Encode an SETACL request
3873 */
3874static int
Al Viro8687b632006-10-19 23:28:48 -07003875nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003876{
3877 struct xdr_stream xdr;
3878 struct compound_hdr hdr = {
3879 .nops = 2,
3880 };
3881 int status;
3882
3883 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3884 encode_compound_hdr(&xdr, &hdr);
3885 status = encode_putfh(&xdr, args->fh);
3886 if (status)
3887 goto out;
3888 status = encode_setacl(&xdr, args);
3889out:
3890 return status;
3891}
3892/*
3893 * Decode SETACL response
3894 */
3895static int
Al Viro8687b632006-10-19 23:28:48 -07003896nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, void *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003897{
3898 struct xdr_stream xdr;
3899 struct compound_hdr hdr;
3900 int status;
3901
3902 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3903 status = decode_compound_hdr(&xdr, &hdr);
3904 if (status)
3905 goto out;
3906 status = decode_putfh(&xdr);
3907 if (status)
3908 goto out;
3909 status = decode_setattr(&xdr, res);
3910out:
3911 return status;
3912}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913
3914/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00003915 * Decode GETACL response
3916 */
3917static int
Al Viro8687b632006-10-19 23:28:48 -07003918nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, size_t *acl_len)
J. Bruce Fields029d1052005-06-22 17:16:22 +00003919{
3920 struct xdr_stream xdr;
3921 struct compound_hdr hdr;
3922 int status;
3923
3924 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3925 status = decode_compound_hdr(&xdr, &hdr);
3926 if (status)
3927 goto out;
3928 status = decode_putfh(&xdr);
3929 if (status)
3930 goto out;
3931 status = decode_getacl(&xdr, rqstp, acl_len);
3932
3933out:
3934 return status;
3935}
3936
3937/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 * Decode CLOSE response
3939 */
Al Viro8687b632006-10-19 23:28:48 -07003940static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941{
3942 struct xdr_stream xdr;
3943 struct compound_hdr hdr;
3944 int status;
3945
3946 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3947 status = decode_compound_hdr(&xdr, &hdr);
3948 if (status)
3949 goto out;
3950 status = decode_putfh(&xdr);
3951 if (status)
3952 goto out;
3953 status = decode_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003954 if (status != 0)
3955 goto out;
3956 /*
3957 * Note: Server may do delete on close for this file
3958 * in which case the getattr call will fail with
3959 * an ESTALE error. Shouldn't be a problem,
3960 * though, since fattr->valid will remain unset.
3961 */
3962 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963out:
3964 return status;
3965}
3966
3967/*
3968 * Decode OPEN response
3969 */
Al Viro8687b632006-10-19 23:28:48 -07003970static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971{
3972 struct xdr_stream xdr;
3973 struct compound_hdr hdr;
3974 int status;
3975
3976 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3977 status = decode_compound_hdr(&xdr, &hdr);
3978 if (status)
3979 goto out;
3980 status = decode_putfh(&xdr);
3981 if (status)
3982 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003983 status = decode_savefh(&xdr);
3984 if (status)
3985 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 status = decode_open(&xdr, res);
3987 if (status)
3988 goto out;
3989 status = decode_getfh(&xdr, &res->fh);
3990 if (status)
3991 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003992 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
3993 goto out;
3994 if ((status = decode_restorefh(&xdr)) != 0)
3995 goto out;
3996 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997out:
3998 return status;
3999}
4000
4001/*
4002 * Decode OPEN_CONFIRM response
4003 */
Al Viro8687b632006-10-19 23:28:48 -07004004static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005{
4006 struct xdr_stream xdr;
4007 struct compound_hdr hdr;
4008 int status;
4009
4010 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4011 status = decode_compound_hdr(&xdr, &hdr);
4012 if (status)
4013 goto out;
4014 status = decode_putfh(&xdr);
4015 if (status)
4016 goto out;
4017 status = decode_open_confirm(&xdr, res);
4018out:
4019 return status;
4020}
4021
4022/*
4023 * Decode OPEN response
4024 */
Al Viro8687b632006-10-19 23:28:48 -07004025static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004026{
4027 struct xdr_stream xdr;
4028 struct compound_hdr hdr;
4029 int status;
4030
4031 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4032 status = decode_compound_hdr(&xdr, &hdr);
4033 if (status)
4034 goto out;
4035 status = decode_putfh(&xdr);
4036 if (status)
4037 goto out;
4038 status = decode_open(&xdr, res);
Trond Myklebust864472e2006-01-03 09:55:15 +01004039 if (status)
4040 goto out;
4041 decode_getfattr(&xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042out:
4043 return status;
4044}
4045
4046/*
4047 * Decode SETATTR response
4048 */
Al Viro8687b632006-10-19 23:28:48 -07004049static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050{
4051 struct xdr_stream xdr;
4052 struct compound_hdr hdr;
4053 int status;
4054
4055 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4056 status = decode_compound_hdr(&xdr, &hdr);
4057 if (status)
4058 goto out;
4059 status = decode_putfh(&xdr);
4060 if (status)
4061 goto out;
4062 status = decode_setattr(&xdr, res);
4063 if (status)
4064 goto out;
4065 status = decode_getfattr(&xdr, res->fattr, res->server);
4066 if (status == NFS4ERR_DELAY)
4067 status = 0;
4068out:
4069 return status;
4070}
4071
4072/*
4073 * Decode LOCK response
4074 */
Al Viro8687b632006-10-19 23:28:48 -07004075static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076{
4077 struct xdr_stream xdr;
4078 struct compound_hdr hdr;
4079 int status;
4080
4081 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4082 status = decode_compound_hdr(&xdr, &hdr);
4083 if (status)
4084 goto out;
4085 status = decode_putfh(&xdr);
4086 if (status)
4087 goto out;
4088 status = decode_lock(&xdr, res);
4089out:
4090 return status;
4091}
4092
4093/*
4094 * Decode LOCKT response
4095 */
Al Viro8687b632006-10-19 23:28:48 -07004096static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097{
4098 struct xdr_stream xdr;
4099 struct compound_hdr hdr;
4100 int status;
4101
4102 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4103 status = decode_compound_hdr(&xdr, &hdr);
4104 if (status)
4105 goto out;
4106 status = decode_putfh(&xdr);
4107 if (status)
4108 goto out;
4109 status = decode_lockt(&xdr, res);
4110out:
4111 return status;
4112}
4113
4114/*
4115 * Decode LOCKU response
4116 */
Al Viro8687b632006-10-19 23:28:48 -07004117static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118{
4119 struct xdr_stream xdr;
4120 struct compound_hdr hdr;
4121 int status;
4122
4123 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4124 status = decode_compound_hdr(&xdr, &hdr);
4125 if (status)
4126 goto out;
4127 status = decode_putfh(&xdr);
4128 if (status)
4129 goto out;
4130 status = decode_locku(&xdr, res);
4131out:
4132 return status;
4133}
4134
4135/*
4136 * Decode READLINK response
4137 */
Al Viro8687b632006-10-19 23:28:48 -07004138static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139{
4140 struct xdr_stream xdr;
4141 struct compound_hdr hdr;
4142 int status;
4143
4144 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4145 status = decode_compound_hdr(&xdr, &hdr);
4146 if (status)
4147 goto out;
4148 status = decode_putfh(&xdr);
4149 if (status)
4150 goto out;
4151 status = decode_readlink(&xdr, rqstp);
4152out:
4153 return status;
4154}
4155
4156/*
4157 * Decode READDIR response
4158 */
Al Viro8687b632006-10-19 23:28:48 -07004159static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160{
4161 struct xdr_stream xdr;
4162 struct compound_hdr hdr;
4163 int status;
4164
4165 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4166 status = decode_compound_hdr(&xdr, &hdr);
4167 if (status)
4168 goto out;
4169 status = decode_putfh(&xdr);
4170 if (status)
4171 goto out;
4172 status = decode_readdir(&xdr, rqstp, res);
4173out:
4174 return status;
4175}
4176
4177/*
4178 * Decode Read response
4179 */
Al Viro8687b632006-10-19 23:28:48 -07004180static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181{
4182 struct xdr_stream xdr;
4183 struct compound_hdr hdr;
4184 int status;
4185
4186 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4187 status = decode_compound_hdr(&xdr, &hdr);
4188 if (status)
4189 goto out;
4190 status = decode_putfh(&xdr);
4191 if (status)
4192 goto out;
4193 status = decode_read(&xdr, rqstp, res);
4194 if (!status)
4195 status = res->count;
4196out:
4197 return status;
4198}
4199
4200/*
4201 * Decode WRITE response
4202 */
Al Viro8687b632006-10-19 23:28:48 -07004203static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204{
4205 struct xdr_stream xdr;
4206 struct compound_hdr hdr;
4207 int status;
4208
4209 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4210 status = decode_compound_hdr(&xdr, &hdr);
4211 if (status)
4212 goto out;
4213 status = decode_putfh(&xdr);
4214 if (status)
4215 goto out;
4216 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004217 if (status)
4218 goto out;
4219 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 if (!status)
4221 status = res->count;
4222out:
4223 return status;
4224}
4225
4226/*
4227 * Decode COMMIT response
4228 */
Al Viro8687b632006-10-19 23:28:48 -07004229static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230{
4231 struct xdr_stream xdr;
4232 struct compound_hdr hdr;
4233 int status;
4234
4235 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4236 status = decode_compound_hdr(&xdr, &hdr);
4237 if (status)
4238 goto out;
4239 status = decode_putfh(&xdr);
4240 if (status)
4241 goto out;
4242 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004243 if (status)
4244 goto out;
4245 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246out:
4247 return status;
4248}
4249
4250/*
4251 * FSINFO request
4252 */
Al Viro8687b632006-10-19 23:28:48 -07004253static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254{
4255 struct xdr_stream xdr;
4256 struct compound_hdr hdr;
4257 int status;
4258
4259 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4260 status = decode_compound_hdr(&xdr, &hdr);
4261 if (!status)
4262 status = decode_putfh(&xdr);
4263 if (!status)
4264 status = decode_fsinfo(&xdr, fsinfo);
4265 if (!status)
David Howells0a8ea432006-08-22 20:06:08 -04004266 status = -nfs4_stat_to_errno(hdr.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267 return status;
4268}
4269
4270/*
4271 * PATHCONF request
4272 */
Al Viro8687b632006-10-19 23:28:48 -07004273static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *pathconf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274{
4275 struct xdr_stream xdr;
4276 struct compound_hdr hdr;
4277 int status;
4278
4279 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4280 status = decode_compound_hdr(&xdr, &hdr);
4281 if (!status)
4282 status = decode_putfh(&xdr);
4283 if (!status)
4284 status = decode_pathconf(&xdr, pathconf);
4285 return status;
4286}
4287
4288/*
4289 * STATFS request
4290 */
Al Viro8687b632006-10-19 23:28:48 -07004291static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *fsstat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292{
4293 struct xdr_stream xdr;
4294 struct compound_hdr hdr;
4295 int status;
4296
4297 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4298 status = decode_compound_hdr(&xdr, &hdr);
4299 if (!status)
4300 status = decode_putfh(&xdr);
4301 if (!status)
4302 status = decode_statfs(&xdr, fsstat);
4303 return status;
4304}
4305
4306/*
4307 * GETATTR_BITMAP request
4308 */
Al Viro8687b632006-10-19 23:28:48 -07004309static 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 -07004310{
4311 struct xdr_stream xdr;
4312 struct compound_hdr hdr;
4313 int status;
4314
4315 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4316 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4317 goto out;
4318 if ((status = decode_putfh(&xdr)) != 0)
4319 goto out;
4320 status = decode_server_caps(&xdr, res);
4321out:
4322 return status;
4323}
4324
4325/*
4326 * Decode RENEW response
4327 */
Al Viro8687b632006-10-19 23:28:48 -07004328static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329{
4330 struct xdr_stream xdr;
4331 struct compound_hdr hdr;
4332 int status;
4333
4334 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4335 status = decode_compound_hdr(&xdr, &hdr);
4336 if (!status)
4337 status = decode_renew(&xdr);
4338 return status;
4339}
4340
4341/*
4342 * a SETCLIENTID request
4343 */
Al Viro8687b632006-10-19 23:28:48 -07004344static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04004345 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346{
4347 struct xdr_stream xdr;
4348 struct compound_hdr hdr;
4349 int status;
4350
4351 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4352 status = decode_compound_hdr(&xdr, &hdr);
4353 if (!status)
4354 status = decode_setclientid(&xdr, clp);
4355 if (!status)
David Howells0a8ea432006-08-22 20:06:08 -04004356 status = -nfs4_stat_to_errno(hdr.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 return status;
4358}
4359
4360/*
4361 * a SETCLIENTID_CONFIRM request
4362 */
Al Viro8687b632006-10-19 23:28:48 -07004363static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364{
4365 struct xdr_stream xdr;
4366 struct compound_hdr hdr;
4367 int status;
4368
4369 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4370 status = decode_compound_hdr(&xdr, &hdr);
4371 if (!status)
4372 status = decode_setclientid_confirm(&xdr);
4373 if (!status)
4374 status = decode_putrootfh(&xdr);
4375 if (!status)
4376 status = decode_fsinfo(&xdr, fsinfo);
4377 if (!status)
David Howells0a8ea432006-08-22 20:06:08 -04004378 status = -nfs4_stat_to_errno(hdr.status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004379 return status;
4380}
4381
4382/*
4383 * DELEGRETURN request
4384 */
Al Viro8687b632006-10-19 23:28:48 -07004385static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386{
4387 struct xdr_stream xdr;
4388 struct compound_hdr hdr;
4389 int status;
4390
4391 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4392 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01004393 if (status != 0)
4394 goto out;
4395 status = decode_putfh(&xdr);
4396 if (status != 0)
4397 goto out;
4398 status = decode_delegreturn(&xdr);
4399 decode_getfattr(&xdr, res->fattr, res->server);
4400out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 return status;
4402}
4403
Trond Myklebust683b57b2006-06-09 09:34:22 -04004404/*
4405 * FS_LOCATIONS request
4406 */
Al Viro8687b632006-10-19 23:28:48 -07004407static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004408{
4409 struct xdr_stream xdr;
4410 struct compound_hdr hdr;
4411 int status;
4412
4413 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4414 status = decode_compound_hdr(&xdr, &hdr);
4415 if (status != 0)
4416 goto out;
4417 if ((status = decode_putfh(&xdr)) != 0)
4418 goto out;
4419 if ((status = decode_lookup(&xdr)) != 0)
4420 goto out;
4421 xdr_enter_page(&xdr, PAGE_SIZE);
4422 status = decode_getfattr(&xdr, &res->fattr, res->server);
4423out:
4424 return status;
4425}
4426
Al Viro0dbb4c62006-10-19 23:28:49 -07004427__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428{
4429 uint32_t bitmap[2] = {0};
4430 uint32_t len;
4431
4432 if (!*p++) {
4433 if (!*p)
4434 return ERR_PTR(-EAGAIN);
4435 entry->eof = 1;
4436 return ERR_PTR(-EBADCOOKIE);
4437 }
4438
4439 entry->prev_cookie = entry->cookie;
4440 p = xdr_decode_hyper(p, &entry->cookie);
4441 entry->len = ntohl(*p++);
4442 entry->name = (const char *) p;
4443 p += XDR_QUADLEN(entry->len);
4444
4445 /*
4446 * In case the server doesn't return an inode number,
4447 * we fake one here. (We don't use inode number 0,
4448 * since glibc seems to choke on it...)
4449 */
4450 entry->ino = 1;
4451
4452 len = ntohl(*p++); /* bitmap length */
4453 if (len-- > 0) {
4454 bitmap[0] = ntohl(*p++);
4455 if (len-- > 0) {
4456 bitmap[1] = ntohl(*p++);
4457 p += len;
4458 }
4459 }
4460 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4461 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00004462 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4463 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4464 /* Ignore the return value of rdattr_error for now */
4465 p++;
4466 len--;
4467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4469 xdr_decode_hyper(p, &entry->ino);
4470 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4471 xdr_decode_hyper(p, &entry->ino);
4472 p += len;
4473 }
4474
4475 entry->eof = !p[0] && p[1];
4476 return p;
4477}
4478
4479/*
4480 * We need to translate between nfs status return values and
4481 * the local errno values which may not be the same.
4482 */
4483static struct {
4484 int stat;
4485 int errno;
4486} nfs_errtbl[] = {
4487 { NFS4_OK, 0 },
4488 { NFS4ERR_PERM, EPERM },
4489 { NFS4ERR_NOENT, ENOENT },
4490 { NFS4ERR_IO, errno_NFSERR_IO },
4491 { NFS4ERR_NXIO, ENXIO },
4492 { NFS4ERR_ACCESS, EACCES },
4493 { NFS4ERR_EXIST, EEXIST },
4494 { NFS4ERR_XDEV, EXDEV },
4495 { NFS4ERR_NOTDIR, ENOTDIR },
4496 { NFS4ERR_ISDIR, EISDIR },
4497 { NFS4ERR_INVAL, EINVAL },
4498 { NFS4ERR_FBIG, EFBIG },
4499 { NFS4ERR_NOSPC, ENOSPC },
4500 { NFS4ERR_ROFS, EROFS },
4501 { NFS4ERR_MLINK, EMLINK },
4502 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
4503 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
4504 { NFS4ERR_DQUOT, EDQUOT },
4505 { NFS4ERR_STALE, ESTALE },
4506 { NFS4ERR_BADHANDLE, EBADHANDLE },
Manoj Naik6ebf3652005-06-22 17:16:39 +00004507 { NFS4ERR_BADOWNER, EINVAL },
4508 { NFS4ERR_BADNAME, EINVAL },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
4510 { NFS4ERR_NOTSUPP, ENOTSUPP },
4511 { NFS4ERR_TOOSMALL, ETOOSMALL },
4512 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
4513 { NFS4ERR_BADTYPE, EBADTYPE },
4514 { NFS4ERR_LOCKED, EAGAIN },
4515 { NFS4ERR_RESOURCE, EREMOTEIO },
4516 { NFS4ERR_SYMLINK, ELOOP },
4517 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
4518 { NFS4ERR_DEADLOCK, EDEADLK },
4519 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs
4520 * to be handled by a
4521 * middle-layer.
4522 */
4523 { -1, EIO }
4524};
4525
4526/*
4527 * Convert an NFS error code to a local one.
4528 * This one is used jointly by NFSv2 and NFSv3.
4529 */
4530static int
David Howells0a8ea432006-08-22 20:06:08 -04004531nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532{
4533 int i;
4534 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4535 if (nfs_errtbl[i].stat == stat)
4536 return nfs_errtbl[i].errno;
4537 }
4538 if (stat <= 10000 || stat > 10100) {
4539 /* The server is looney tunes. */
4540 return ESERVERFAULT;
4541 }
4542 /* If we cannot translate the error, the recovery routines should
4543 * handle it.
4544 * Note: remaining NFSv4 error codes have values > 10000, so should
4545 * not conflict with native Linux error codes.
4546 */
4547 return stat;
4548}
4549
Linus Torvalds1da177e2005-04-16 15:20:36 -07004550#define PROC(proc, argtype, restype) \
4551[NFSPROC4_CLNT_##proc] = { \
4552 .p_proc = NFSPROC4_COMPOUND, \
4553 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4554 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04004555 .p_arglen = NFS4_##argtype##_sz, \
4556 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05004557 .p_statidx = NFSPROC4_CLNT_##proc, \
4558 .p_name = #proc, \
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559 }
4560
4561struct rpc_procinfo nfs4_procedures[] = {
4562 PROC(READ, enc_read, dec_read),
4563 PROC(WRITE, enc_write, dec_write),
4564 PROC(COMMIT, enc_commit, dec_commit),
4565 PROC(OPEN, enc_open, dec_open),
4566 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4567 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4568 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4569 PROC(CLOSE, enc_close, dec_close),
4570 PROC(SETATTR, enc_setattr, dec_setattr),
4571 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4572 PROC(RENEW, enc_renew, dec_renew),
4573 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4574 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4575 PROC(LOCK, enc_lock, dec_lock),
4576 PROC(LOCKT, enc_lockt, dec_lockt),
4577 PROC(LOCKU, enc_locku, dec_locku),
4578 PROC(ACCESS, enc_access, dec_access),
4579 PROC(GETATTR, enc_getattr, dec_getattr),
4580 PROC(LOOKUP, enc_lookup, dec_lookup),
4581 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4582 PROC(REMOVE, enc_remove, dec_remove),
4583 PROC(RENAME, enc_rename, dec_rename),
4584 PROC(LINK, enc_link, dec_link),
4585 PROC(SYMLINK, enc_symlink, dec_symlink),
4586 PROC(CREATE, enc_create, dec_create),
4587 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4588 PROC(STATFS, enc_statfs, dec_statfs),
4589 PROC(READLINK, enc_readlink, dec_readlink),
4590 PROC(READDIR, enc_readdir, dec_readdir),
4591 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4592 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00004593 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004594 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04004595 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596};
4597
4598struct rpc_version nfs_version4 = {
4599 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08004600 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601 .procs = nfs4_procedures
4602};
4603
4604/*
4605 * Local variables:
4606 * c-basic-offset: 8
4607 * End:
4608 */