blob: 487a197231fdcae9faef6823afa84a328834a63d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
41#include <linux/slab.h>
42#include <linux/utsname.h>
43#include <linux/errno.h>
44#include <linux/string.h>
45#include <linux/in.h>
46#include <linux/pagemap.h>
47#include <linux/proc_fs.h>
48#include <linux/kdev_t.h>
49#include <linux/sunrpc/clnt.h>
50#include <linux/nfs.h>
51#include <linux/nfs4.h>
52#include <linux/nfs_fs.h>
53#include <linux/nfs_idmap.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000054#include "nfs4_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#define NFSDBG_FACILITY NFSDBG_XDR
57
58/* Mapping from NFS error code to "errno" error code. */
59#define errno_NFSERR_IO EIO
60
David Howells0a8ea432006-08-22 20:06:08 -040061static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
64#ifdef DEBUG
65#define NFS4_MAXTAGLEN 20
66#else
67#define NFS4_MAXTAGLEN 0
68#endif
69
Andy Adamson6c0195a2008-12-23 16:06:15 -050070/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040071 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 */
Trond Myklebust9f958ab2007-07-02 13:58:33 -040073#define open_owner_id_maxsz (1 + 4)
74#define lock_owner_id_maxsz (1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040075#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
77#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
78#define op_encode_hdr_maxsz (1)
79#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040080#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
81#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
82#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
83#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
85 (NFS4_FHSIZE >> 2))
86#define decode_putfh_maxsz (op_decode_hdr_maxsz)
87#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
88#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
89#define encode_getfh_maxsz (op_encode_hdr_maxsz)
90#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
91 ((3+NFS4_FHSIZE) >> 2))
J. Bruce Fields96928202005-06-22 17:16:22 +000092#define nfs4_fattr_bitmap_maxsz 3
93#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
95#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -040096#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
97#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
J. Bruce Fields96928202005-06-22 17:16:22 +000098/* This is based on getfattr, which uses the most attributes: */
99#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400100 3 + 3 + 3 + nfs4_owner_maxsz + nfs4_group_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000101#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
102 nfs4_fattr_value_maxsz)
103#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400104#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
105 1 + 2 + 1 + \
106 nfs4_owner_maxsz + \
107 nfs4_group_maxsz + \
108 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#define encode_savefh_maxsz (op_encode_hdr_maxsz)
110#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400111#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200113#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116#define decode_renew_maxsz (op_decode_hdr_maxsz)
117#define encode_setclientid_maxsz \
118 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500119 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
120 XDR_QUADLEN(NFS4_SETCLIENTID_NAMELEN) + \
121 1 /* sc_prog */ + \
122 XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
123 XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
124 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#define decode_setclientid_maxsz \
126 (op_decode_hdr_maxsz + \
127 2 + \
128 1024) /* large value for CLID_INUSE */
129#define encode_setclientid_confirm_maxsz \
130 (op_encode_hdr_maxsz + \
131 3 + (NFS4_VERIFIER_SIZE >> 2))
132#define decode_setclientid_confirm_maxsz \
133 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400134#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
135#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400136#define encode_share_access_maxsz \
137 (2)
Trond Myklebust9104a552007-07-17 21:52:42 -0400138#define encode_createmode_maxsz (1 + encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400139#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
140#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
141#define encode_open_maxsz (op_encode_hdr_maxsz + \
142 2 + encode_share_access_maxsz + 2 + \
143 open_owner_id_maxsz + \
144 encode_opentype_maxsz + \
145 encode_claim_null_maxsz)
146#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400147#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400148 decode_ace_maxsz)
149#define decode_change_info_maxsz (5)
150#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400151 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400152 decode_change_info_maxsz + 1 + \
153 nfs4_fattr_bitmap_maxsz + \
154 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400155#define encode_open_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 encode_stateid_maxsz + 1)
158#define decode_open_confirm_maxsz \
159 (op_decode_hdr_maxsz + \
160 decode_stateid_maxsz)
161#define encode_open_downgrade_maxsz \
162 (op_encode_hdr_maxsz + \
163 encode_stateid_maxsz + 1 + \
164 encode_share_access_maxsz)
165#define decode_open_downgrade_maxsz \
166 (op_decode_hdr_maxsz + \
167 decode_stateid_maxsz)
168#define encode_close_maxsz (op_encode_hdr_maxsz + \
169 1 + encode_stateid_maxsz)
170#define decode_close_maxsz (op_decode_hdr_maxsz + \
171 decode_stateid_maxsz)
172#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
173 encode_stateid_maxsz + \
174 encode_attrs_maxsz)
175#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
176 nfs4_fattr_bitmap_maxsz)
177#define encode_read_maxsz (op_encode_hdr_maxsz + \
178 encode_stateid_maxsz + 3)
179#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
180#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
181 2 + encode_verifier_maxsz + 5)
182#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
183 decode_verifier_maxsz)
184#define encode_readlink_maxsz (op_encode_hdr_maxsz)
185#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
186#define encode_write_maxsz (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 4)
188#define decode_write_maxsz (op_decode_hdr_maxsz + \
189 2 + decode_verifier_maxsz)
190#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
191#define decode_commit_maxsz (op_decode_hdr_maxsz + \
192 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193#define encode_remove_maxsz (op_encode_hdr_maxsz + \
194 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400195#define decode_remove_maxsz (op_decode_hdr_maxsz + \
196 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#define encode_rename_maxsz (op_encode_hdr_maxsz + \
198 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400199#define decode_rename_maxsz (op_decode_hdr_maxsz + \
200 decode_change_info_maxsz + \
201 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#define encode_link_maxsz (op_encode_hdr_maxsz + \
203 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400204#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400205#define encode_lock_maxsz (op_encode_hdr_maxsz + \
206 7 + \
207 1 + encode_stateid_maxsz + 8)
208#define decode_lock_denied_maxsz \
209 (8 + decode_lockowner_maxsz)
210#define decode_lock_maxsz (op_decode_hdr_maxsz + \
211 decode_lock_denied_maxsz)
212#define encode_lockt_maxsz (op_encode_hdr_maxsz + 12)
213#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
214 decode_lock_denied_maxsz)
215#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
216 encode_stateid_maxsz + \
217 4)
218#define decode_locku_maxsz (op_decode_hdr_maxsz + \
219 decode_stateid_maxsz)
220#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
221#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
223 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400224 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000225 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
227#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400228 1 + 2 + nfs4_name_maxsz + \
229 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400230#define decode_create_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400233#define encode_statfs_maxsz (encode_getattr_maxsz)
234#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
236#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400237#define encode_getacl_maxsz (encode_getattr_maxsz)
238#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
239 nfs4_fattr_bitmap_maxsz + 1)
240#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
241 encode_stateid_maxsz + 3)
242#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400243#define encode_fs_locations_maxsz \
244 (encode_getattr_maxsz)
245#define decode_fs_locations_maxsz \
246 (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
248#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
249#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
250 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400251 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
253 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400254 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
256 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400257 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
259 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400260 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
262 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400263 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
265 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400266 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
268 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400269 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400270 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
272 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400273 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400274 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
276 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400277 encode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400278 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
280 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400281 decode_commit_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400282 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400284 encode_putfh_maxsz + \
285 encode_savefh_maxsz + \
286 encode_open_maxsz + \
287 encode_getfh_maxsz + \
288 encode_getattr_maxsz + \
289 encode_restorefh_maxsz + \
290 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400292 decode_putfh_maxsz + \
293 decode_savefh_maxsz + \
294 decode_open_maxsz + \
295 decode_getfh_maxsz + \
296 decode_getattr_maxsz + \
297 decode_restorefh_maxsz + \
298 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400299#define NFS4_enc_open_confirm_sz \
300 (compound_encode_hdr_maxsz + \
301 encode_putfh_maxsz + \
302 encode_open_confirm_maxsz)
303#define NFS4_dec_open_confirm_sz \
304 (compound_decode_hdr_maxsz + \
305 decode_putfh_maxsz + \
306 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
308 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400309 encode_open_maxsz + \
310 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
312 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400313 decode_open_maxsz + \
314 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#define NFS4_enc_open_downgrade_sz \
316 (compound_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400317 encode_putfh_maxsz + \
318 encode_open_downgrade_maxsz + \
319 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#define NFS4_dec_open_downgrade_sz \
321 (compound_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400322 decode_putfh_maxsz + \
323 decode_open_downgrade_maxsz + \
324 decode_getattr_maxsz)
325#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
326 encode_putfh_maxsz + \
327 encode_close_maxsz + \
328 encode_getattr_maxsz)
329#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
330 decode_putfh_maxsz + \
331 decode_close_maxsz + \
332 decode_getattr_maxsz)
333#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
334 encode_putfh_maxsz + \
335 encode_setattr_maxsz + \
336 encode_getattr_maxsz)
337#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
338 decode_putfh_maxsz + \
339 decode_setattr_maxsz + \
340 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
342 encode_putfh_maxsz + \
343 encode_fsinfo_maxsz)
344#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
345 decode_putfh_maxsz + \
346 decode_fsinfo_maxsz)
347#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
348 encode_renew_maxsz)
349#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
350 decode_renew_maxsz)
351#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
352 encode_setclientid_maxsz)
353#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
354 decode_setclientid_maxsz)
355#define NFS4_enc_setclientid_confirm_sz \
356 (compound_encode_hdr_maxsz + \
357 encode_setclientid_confirm_maxsz + \
358 encode_putrootfh_maxsz + \
359 encode_fsinfo_maxsz)
360#define NFS4_dec_setclientid_confirm_sz \
361 (compound_decode_hdr_maxsz + \
362 decode_setclientid_confirm_maxsz + \
363 decode_putrootfh_maxsz + \
364 decode_fsinfo_maxsz)
365#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
366 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400367 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
369 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400370 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
372 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400373 encode_lockt_maxsz)
374#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
375 decode_putfh_maxsz + \
376 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
378 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400379 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
381 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400382 decode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
384 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400385 encode_access_maxsz + \
386 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
388 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400389 decode_access_maxsz + \
390 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
392 encode_putfh_maxsz + \
393 encode_getattr_maxsz)
394#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
395 decode_putfh_maxsz + \
396 decode_getattr_maxsz)
397#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
398 encode_putfh_maxsz + \
399 encode_lookup_maxsz + \
400 encode_getattr_maxsz + \
401 encode_getfh_maxsz)
402#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
403 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400404 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 decode_getattr_maxsz + \
406 decode_getfh_maxsz)
407#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
408 encode_putrootfh_maxsz + \
409 encode_getattr_maxsz + \
410 encode_getfh_maxsz)
411#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
412 decode_putrootfh_maxsz + \
413 decode_getattr_maxsz + \
414 decode_getfh_maxsz)
415#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
416 encode_putfh_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400417 encode_remove_maxsz + \
418 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
420 decode_putfh_maxsz + \
Benny Halevy6ce18392009-04-01 09:22:06 -0400421 decode_remove_maxsz + \
Trond Myklebust16e42952005-10-27 22:12:44 -0400422 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
424 encode_putfh_maxsz + \
425 encode_savefh_maxsz + \
426 encode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400427 encode_rename_maxsz + \
428 encode_getattr_maxsz + \
429 encode_restorefh_maxsz + \
430 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
432 decode_putfh_maxsz + \
433 decode_savefh_maxsz + \
434 decode_putfh_maxsz + \
Trond Myklebust6caf2c82005-10-27 22:12:43 -0400435 decode_rename_maxsz + \
436 decode_getattr_maxsz + \
437 decode_restorefh_maxsz + \
438 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
440 encode_putfh_maxsz + \
441 encode_savefh_maxsz + \
442 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400443 encode_link_maxsz + \
444 decode_getattr_maxsz + \
445 encode_restorefh_maxsz + \
446 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
448 decode_putfh_maxsz + \
449 decode_savefh_maxsz + \
450 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400451 decode_link_maxsz + \
452 decode_getattr_maxsz + \
453 decode_restorefh_maxsz + \
454 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
456 encode_putfh_maxsz + \
457 encode_symlink_maxsz + \
458 encode_getattr_maxsz + \
459 encode_getfh_maxsz)
460#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
461 decode_putfh_maxsz + \
462 decode_symlink_maxsz + \
463 decode_getattr_maxsz + \
464 decode_getfh_maxsz)
465#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
466 encode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400467 encode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400469 encode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 encode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400471 encode_restorefh_maxsz + \
472 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
474 decode_putfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400475 decode_savefh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400477 decode_getfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 decode_getattr_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400479 decode_restorefh_maxsz + \
480 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
482 encode_putfh_maxsz + \
483 encode_getattr_maxsz)
484#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
485 decode_putfh_maxsz + \
486 decode_getattr_maxsz)
487#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
488 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400489 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
491 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400492 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800494 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 encode_getattr_maxsz)
496#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800497 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 decode_getattr_maxsz)
499#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
500 encode_putfh_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100501 encode_delegreturn_maxsz + \
502 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100504 decode_delegreturn_maxsz + \
505 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000506#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
507 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400508 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000509#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
510 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400511 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000512#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
513 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400514 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000515#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
516 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400517 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400518#define NFS4_enc_fs_locations_sz \
519 (compound_encode_hdr_maxsz + \
520 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400521 encode_lookup_maxsz + \
522 encode_fs_locations_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400523#define NFS4_dec_fs_locations_sz \
524 (compound_decode_hdr_maxsz + \
525 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400526 decode_lookup_maxsz + \
527 decode_fs_locations_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Trond Myklebustbca79472009-03-11 14:10:26 -0400529static const umode_t nfs_type2fmt[] = {
530 [NF4BAD] = 0,
531 [NF4REG] = S_IFREG,
532 [NF4DIR] = S_IFDIR,
533 [NF4BLK] = S_IFBLK,
534 [NF4CHR] = S_IFCHR,
535 [NF4LNK] = S_IFLNK,
536 [NF4SOCK] = S_IFSOCK,
537 [NF4FIFO] = S_IFIFO,
538 [NF4ATTRDIR] = 0,
539 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540};
541
542struct compound_hdr {
543 int32_t status;
544 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500545 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 uint32_t taglen;
547 char * tag;
548};
549
550/*
551 * START OF "GENERIC" ENCODE ROUTINES.
552 * These may look a little ugly since they are imported from a "generic"
553 * set of XDR encode/decode routines which are intended to be shared by
554 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
555 *
556 * If the pain of reading these is too great, it should be a straightforward
557 * task to translate them into Linux-specific versions which are more
558 * consistent with the style used in NFSv2/v3...
559 */
560#define WRITE32(n) *p++ = htonl(n)
561#define WRITE64(n) do { \
562 *p++ = htonl((uint32_t)((n) >> 32)); \
563 *p++ = htonl((uint32_t)(n)); \
564} while (0)
565#define WRITEMEM(ptr,nbytes) do { \
566 p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
567} while (0)
568
569#define RESERVE_SPACE(nbytes) do { \
570 p = xdr_reserve_space(xdr, nbytes); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 BUG_ON(!p); \
572} while (0)
573
574static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
575{
Al Viro8687b632006-10-19 23:28:48 -0700576 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 p = xdr_reserve_space(xdr, 4 + len);
579 BUG_ON(p == NULL);
580 xdr_encode_opaque(p, str, len);
581}
582
Andy Adamsond0179312008-12-23 16:06:17 -0500583static void encode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Al Viro8687b632006-10-19 23:28:48 -0700585 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
588 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
589 RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
590 WRITE32(hdr->taglen);
591 WRITEMEM(hdr->tag, hdr->taglen);
592 WRITE32(NFS4_MINOR_VERSION);
Andy Adamsond0179312008-12-23 16:06:17 -0500593 hdr->nops_p = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 WRITE32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500595}
596
597static void encode_nops(struct compound_hdr *hdr)
598{
599 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
601
602static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
603{
Al Viro8687b632006-10-19 23:28:48 -0700604 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
607 BUG_ON(p == NULL);
608 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
609}
610
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500611static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612{
613 char owner_name[IDMAP_NAMESZ];
614 char owner_group[IDMAP_NAMESZ];
615 int owner_namelen = 0;
616 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -0700617 __be32 *p;
618 __be32 *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 int len;
620 uint32_t bmval0 = 0;
621 uint32_t bmval1 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 /*
624 * We reserve enough space to write the entire attribute buffer at once.
625 * In the worst-case, this would be
626 * 12(bitmap) + 4(attrlen) + 8(size) + 4(mode) + 4(atime) + 4(mtime)
627 * = 36 bytes, plus any contribution from variable-length fields
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000628 * such as owner/group.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 */
630 len = 16;
631
632 /* Sigh */
633 if (iap->ia_valid & ATTR_SIZE)
634 len += 8;
635 if (iap->ia_valid & ATTR_MODE)
636 len += 4;
637 if (iap->ia_valid & ATTR_UID) {
David Howells7539bba2006-08-22 20:06:09 -0400638 owner_namelen = nfs_map_uid_to_name(server->nfs_client, iap->ia_uid, owner_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400640 dprintk("nfs: couldn't resolve uid %d to string\n",
641 iap->ia_uid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 /* XXX */
643 strcpy(owner_name, "nobody");
644 owner_namelen = sizeof("nobody") - 1;
645 /* goto out; */
646 }
647 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
648 }
649 if (iap->ia_valid & ATTR_GID) {
David Howells7539bba2006-08-22 20:06:09 -0400650 owner_grouplen = nfs_map_gid_to_group(server->nfs_client, iap->ia_gid, owner_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400652 dprintk("nfs: couldn't resolve gid %d to string\n",
653 iap->ia_gid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 strcpy(owner_group, "nobody");
655 owner_grouplen = sizeof("nobody") - 1;
656 /* goto out; */
657 }
658 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
659 }
660 if (iap->ia_valid & ATTR_ATIME_SET)
661 len += 16;
662 else if (iap->ia_valid & ATTR_ATIME)
663 len += 4;
664 if (iap->ia_valid & ATTR_MTIME_SET)
665 len += 16;
666 else if (iap->ia_valid & ATTR_MTIME)
667 len += 4;
668 RESERVE_SPACE(len);
669
670 /*
671 * We write the bitmap length now, but leave the bitmap and the attribute
672 * buffer length to be backfilled at the end of this routine.
673 */
674 WRITE32(2);
675 q = p;
676 p += 3;
677
678 if (iap->ia_valid & ATTR_SIZE) {
679 bmval0 |= FATTR4_WORD0_SIZE;
680 WRITE64(iap->ia_size);
681 }
682 if (iap->ia_valid & ATTR_MODE) {
683 bmval1 |= FATTR4_WORD1_MODE;
Trond Myklebustcf3fff52006-01-03 09:55:53 +0100684 WRITE32(iap->ia_mode & S_IALLUGO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 }
686 if (iap->ia_valid & ATTR_UID) {
687 bmval1 |= FATTR4_WORD1_OWNER;
688 WRITE32(owner_namelen);
689 WRITEMEM(owner_name, owner_namelen);
690 }
691 if (iap->ia_valid & ATTR_GID) {
692 bmval1 |= FATTR4_WORD1_OWNER_GROUP;
693 WRITE32(owner_grouplen);
694 WRITEMEM(owner_group, owner_grouplen);
695 }
696 if (iap->ia_valid & ATTR_ATIME_SET) {
697 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
698 WRITE32(NFS4_SET_TO_CLIENT_TIME);
699 WRITE32(0);
700 WRITE32(iap->ia_mtime.tv_sec);
701 WRITE32(iap->ia_mtime.tv_nsec);
702 }
703 else if (iap->ia_valid & ATTR_ATIME) {
704 bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
705 WRITE32(NFS4_SET_TO_SERVER_TIME);
706 }
707 if (iap->ia_valid & ATTR_MTIME_SET) {
708 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
709 WRITE32(NFS4_SET_TO_CLIENT_TIME);
710 WRITE32(0);
711 WRITE32(iap->ia_mtime.tv_sec);
712 WRITE32(iap->ia_mtime.tv_nsec);
713 }
714 else if (iap->ia_valid & ATTR_MTIME) {
715 bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
716 WRITE32(NFS4_SET_TO_SERVER_TIME);
717 }
Andy Adamson6c0195a2008-12-23 16:06:15 -0500718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 /*
720 * Now we backfill the bitmap and the attribute buffer length.
721 */
722 if (len != ((char *)p - (char *)q) + 4) {
Chuck Leverfe82a182007-09-11 18:01:10 -0400723 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 len, ((char *)p - (char *)q) + 4);
725 BUG();
726 }
727 len = (char *)p - (char *)q - 12;
728 *q++ = htonl(bmval0);
729 *q++ = htonl(bmval1);
730 *q++ = htonl(len);
731
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733}
734
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500735static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
Al Viro8687b632006-10-19 23:28:48 -0700737 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 RESERVE_SPACE(8);
740 WRITE32(OP_ACCESS);
741 WRITE32(access);
Andy Adamsond0179312008-12-23 16:06:17 -0500742 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743}
744
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500745static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
Al Viro8687b632006-10-19 23:28:48 -0700747 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400749 RESERVE_SPACE(8+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 WRITE32(OP_CLOSE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700751 WRITE32(arg->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400752 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -0500753 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754}
755
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500756static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Al Viro8687b632006-10-19 23:28:48 -0700758 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500759
Andy Adamson05d564f2008-12-23 16:06:15 -0500760 RESERVE_SPACE(16);
761 WRITE32(OP_COMMIT);
762 WRITE64(args->offset);
763 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -0500764 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765}
766
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500767static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
Al Viro8687b632006-10-19 23:28:48 -0700769 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -0500770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 RESERVE_SPACE(8);
772 WRITE32(OP_CREATE);
773 WRITE32(create->ftype);
774
775 switch (create->ftype) {
776 case NF4LNK:
Chuck Lever94a6d752006-08-22 20:06:23 -0400777 RESERVE_SPACE(4);
778 WRITE32(create->u.symlink.len);
779 xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 break;
781
782 case NF4BLK: case NF4CHR:
783 RESERVE_SPACE(8);
784 WRITE32(create->u.device.specdata1);
785 WRITE32(create->u.device.specdata2);
786 break;
787
788 default:
789 break;
790 }
791
792 RESERVE_SPACE(4 + create->name->len);
793 WRITE32(create->name->len);
794 WRITEMEM(create->name->name, create->name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500795 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500797 encode_attrs(xdr, create->attrs, create->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798}
799
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500800static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801{
Andy Adamson05d564f2008-12-23 16:06:15 -0500802 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Andy Adamson05d564f2008-12-23 16:06:15 -0500804 RESERVE_SPACE(12);
805 WRITE32(OP_GETATTR);
806 WRITE32(1);
807 WRITE32(bitmap);
Andy Adamsond0179312008-12-23 16:06:17 -0500808 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809}
810
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500811static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812{
Andy Adamson05d564f2008-12-23 16:06:15 -0500813 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Andy Adamson05d564f2008-12-23 16:06:15 -0500815 RESERVE_SPACE(16);
816 WRITE32(OP_GETATTR);
817 WRITE32(2);
818 WRITE32(bm0);
819 WRITE32(bm1);
Andy Adamsond0179312008-12-23 16:06:17 -0500820 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821}
822
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500823static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500825 encode_getattr_two(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
826 bitmask[1] & nfs4_fattr_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827}
828
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500829static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500831 encode_getattr_two(xdr, bitmask[0] & nfs4_fsinfo_bitmap[0],
832 bitmask[1] & nfs4_fsinfo_bitmap[1], hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833}
834
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500835static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -0400836{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500837 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
838 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -0400839}
840
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500841static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842{
Al Viro8687b632006-10-19 23:28:48 -0700843 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845 RESERVE_SPACE(4);
846 WRITE32(OP_GETFH);
Andy Adamsond0179312008-12-23 16:06:17 -0500847 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848}
849
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500850static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
Al Viro8687b632006-10-19 23:28:48 -0700852 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 RESERVE_SPACE(8 + name->len);
855 WRITE32(OP_LINK);
856 WRITE32(name->len);
857 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -0500858 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859}
860
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100861static inline int nfs4_lock_type(struct file_lock *fl, int block)
862{
863 if ((fl->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) == F_RDLCK)
864 return block ? NFS4_READW_LT : NFS4_READ_LT;
865 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
866}
867
868static inline uint64_t nfs4_lock_length(struct file_lock *fl)
869{
870 if (fl->fl_end == OFFSET_MAX)
871 return ~(uint64_t)0;
872 return fl->fl_end - fl->fl_start + 1;
873}
874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875/*
876 * opcode,type,reclaim,offset,length,new_lock_owner = 32
877 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
878 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500879static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880{
Al Viro8687b632006-10-19 23:28:48 -0700881 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 RESERVE_SPACE(32);
884 WRITE32(OP_LOCK);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100885 WRITE32(nfs4_lock_type(args->fl, args->block));
886 WRITE32(args->reclaim);
887 WRITE64(args->fl->fl_start);
888 WRITE64(nfs4_lock_length(args->fl));
889 WRITE32(args->new_lock_owner);
890 if (args->new_lock_owner){
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400891 RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100892 WRITE32(args->open_seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400893 WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100894 WRITE32(args->lock_seqid->sequence->counter);
895 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400896 WRITE32(16);
897 WRITEMEM("lock id:", 8);
898 WRITE64(args->lock_owner.id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 }
900 else {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400901 RESERVE_SPACE(NFS4_STATEID_SIZE+4);
902 WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100903 WRITE32(args->lock_seqid->sequence->counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 }
Andy Adamsond0179312008-12-23 16:06:17 -0500905 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906}
907
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500908static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909{
Al Viro8687b632006-10-19 23:28:48 -0700910 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400912 RESERVE_SPACE(52);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 WRITE32(OP_LOCKT);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100914 WRITE32(nfs4_lock_type(args->fl, 0));
915 WRITE64(args->fl->fl_start);
916 WRITE64(nfs4_lock_length(args->fl));
917 WRITE64(args->lock_owner.clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400918 WRITE32(16);
919 WRITEMEM("lock id:", 8);
920 WRITE64(args->lock_owner.id);
Andy Adamsond0179312008-12-23 16:06:17 -0500921 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922}
923
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500924static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925{
Al Viro8687b632006-10-19 23:28:48 -0700926 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400928 RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 WRITE32(OP_LOCKU);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100930 WRITE32(nfs4_lock_type(args->fl, 0));
931 WRITE32(args->seqid->sequence->counter);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -0400932 WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebust911d1aa2006-01-03 09:55:16 +0100933 WRITE64(args->fl->fl_start);
934 WRITE64(nfs4_lock_length(args->fl));
Andy Adamsond0179312008-12-23 16:06:17 -0500935 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -0500938static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939{
940 int len = name->len;
Al Viro8687b632006-10-19 23:28:48 -0700941 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943 RESERVE_SPACE(8 + len);
944 WRITE32(OP_LOOKUP);
945 WRITE32(len);
946 WRITEMEM(name->name, len);
Andy Adamsond0179312008-12-23 16:06:17 -0500947 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948}
949
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500950static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951{
Al Viro8687b632006-10-19 23:28:48 -0700952 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
954 RESERVE_SPACE(8);
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500955 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
Andy Adamson05d564f2008-12-23 16:06:15 -0500956 case FMODE_READ:
957 WRITE32(NFS4_SHARE_ACCESS_READ);
958 break;
959 case FMODE_WRITE:
960 WRITE32(NFS4_SHARE_ACCESS_WRITE);
961 break;
962 case FMODE_READ|FMODE_WRITE:
963 WRITE32(NFS4_SHARE_ACCESS_BOTH);
964 break;
965 default:
966 WRITE32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 }
968 WRITE32(0); /* for linux, share_deny = 0 always */
969}
970
971static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
972{
Al Viro8687b632006-10-19 23:28:48 -0700973 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 /*
975 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
976 * owner 4 = 32
977 */
978 RESERVE_SPACE(8);
979 WRITE32(OP_OPEN);
Trond Myklebustcee54fc2005-10-18 14:20:12 -0700980 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -0500981 encode_share_access(xdr, arg->fmode);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400982 RESERVE_SPACE(28);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 WRITE64(arg->clientid);
Trond Myklebust9f958ab2007-07-02 13:58:33 -0400984 WRITE32(16);
985 WRITEMEM("open id:", 8);
986 WRITE64(arg->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987}
988
989static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
990{
Al Viro8687b632006-10-19 23:28:48 -0700991 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
993 RESERVE_SPACE(4);
994 switch(arg->open_flags & O_EXCL) {
Andy Adamson05d564f2008-12-23 16:06:15 -0500995 case 0:
996 WRITE32(NFS4_CREATE_UNCHECKED);
997 encode_attrs(xdr, arg->u.attrs, arg->server);
998 break;
999 default:
1000 WRITE32(NFS4_CREATE_EXCLUSIVE);
1001 encode_nfs4_verifier(xdr, &arg->u.verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 }
1003}
1004
1005static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1006{
Al Viro8687b632006-10-19 23:28:48 -07001007 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 RESERVE_SPACE(4);
1010 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001011 case 0:
1012 WRITE32(NFS4_OPEN_NOCREATE);
1013 break;
1014 default:
1015 BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
1016 WRITE32(NFS4_OPEN_CREATE);
1017 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 }
1019}
1020
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001021static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022{
Al Viro8687b632006-10-19 23:28:48 -07001023 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
1025 RESERVE_SPACE(4);
1026 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001027 case 0:
1028 WRITE32(NFS4_OPEN_DELEGATE_NONE);
1029 break;
1030 case FMODE_READ:
1031 WRITE32(NFS4_OPEN_DELEGATE_READ);
1032 break;
1033 case FMODE_WRITE|FMODE_READ:
1034 WRITE32(NFS4_OPEN_DELEGATE_WRITE);
1035 break;
1036 default:
1037 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 }
1039}
1040
1041static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1042{
Al Viro8687b632006-10-19 23:28:48 -07001043 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 RESERVE_SPACE(4);
1046 WRITE32(NFS4_OPEN_CLAIM_NULL);
1047 encode_string(xdr, name->len, name->name);
1048}
1049
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001050static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
Al Viro8687b632006-10-19 23:28:48 -07001052 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
1054 RESERVE_SPACE(4);
1055 WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
1056 encode_delegation_type(xdr, type);
1057}
1058
1059static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1060{
Al Viro8687b632006-10-19 23:28:48 -07001061 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001063 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001065 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 encode_string(xdr, name->len, name->name);
1067}
1068
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001069static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070{
1071 encode_openhdr(xdr, arg);
1072 encode_opentype(xdr, arg);
1073 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001074 case NFS4_OPEN_CLAIM_NULL:
1075 encode_claim_null(xdr, arg->name);
1076 break;
1077 case NFS4_OPEN_CLAIM_PREVIOUS:
1078 encode_claim_previous(xdr, arg->u.delegation_type);
1079 break;
1080 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1081 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1082 break;
1083 default:
1084 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 }
Andy Adamsond0179312008-12-23 16:06:17 -05001086 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087}
1088
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001089static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090{
Al Viro8687b632006-10-19 23:28:48 -07001091 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001093 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 WRITE32(OP_OPEN_CONFIRM);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001095 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001096 WRITE32(arg->seqid->sequence->counter);
Andy Adamsond0179312008-12-23 16:06:17 -05001097 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098}
1099
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001100static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101{
Al Viro8687b632006-10-19 23:28:48 -07001102 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001104 RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 WRITE32(OP_OPEN_DOWNGRADE);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001106 WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
Trond Myklebustcee54fc2005-10-18 14:20:12 -07001107 WRITE32(arg->seqid->sequence->counter);
Trond Myklebustdc0b0272008-12-23 15:21:56 -05001108 encode_share_access(xdr, arg->fmode);
Andy Adamsond0179312008-12-23 16:06:17 -05001109 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110}
1111
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001112static void
Andy Adamsond0179312008-12-23 16:06:17 -05001113encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114{
1115 int len = fh->size;
Al Viro8687b632006-10-19 23:28:48 -07001116 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
1118 RESERVE_SPACE(8 + len);
1119 WRITE32(OP_PUTFH);
1120 WRITE32(len);
1121 WRITEMEM(fh->data, len);
Andy Adamsond0179312008-12-23 16:06:17 -05001122 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123}
1124
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001125static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126{
Andy Adamson05d564f2008-12-23 16:06:15 -05001127 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001128
Andy Adamson05d564f2008-12-23 16:06:15 -05001129 RESERVE_SPACE(4);
1130 WRITE32(OP_PUTROOTFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001131 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
1134static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx)
1135{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 nfs4_stateid stateid;
Al Viro8687b632006-10-19 23:28:48 -07001137 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001139 RESERVE_SPACE(NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 if (ctx->state != NULL) {
1141 nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001142 WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 } else
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001144 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145}
1146
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001147static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
Al Viro8687b632006-10-19 23:28:48 -07001149 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151 RESERVE_SPACE(4);
1152 WRITE32(OP_READ);
1153
1154 encode_stateid(xdr, args->context);
1155
1156 RESERVE_SPACE(12);
1157 WRITE64(args->offset);
1158 WRITE32(args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001159 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001162static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163{
Manoj Naik97d312d2005-06-22 17:16:39 +00001164 uint32_t attrs[2] = {
1165 FATTR4_WORD0_RDATTR_ERROR|FATTR4_WORD0_FILEID,
1166 FATTR4_WORD1_MOUNTED_ON_FILEID,
1167 };
Al Viro8687b632006-10-19 23:28:48 -07001168 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001170 RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 WRITE32(OP_READDIR);
1172 WRITE64(readdir->cookie);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001173 WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
1175 WRITE32(readdir->count);
1176 WRITE32(2);
Manoj Naik97d312d2005-06-22 17:16:39 +00001177 /* Switch to mounted_on_fileid if the server supports it */
1178 if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
1179 attrs[0] &= ~FATTR4_WORD0_FILEID;
1180 else
1181 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1182 WRITE32(attrs[0] & readdir->bitmask[0]);
1183 WRITE32(attrs[1] & readdir->bitmask[1]);
Andy Adamsond0179312008-12-23 16:06:17 -05001184 hdr->nops++;
Fred Isaman44109242008-04-02 15:21:15 +03001185 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1186 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001187 (unsigned long long)readdir->cookie,
1188 ((u32 *)readdir->verifier.data)[0],
1189 ((u32 *)readdir->verifier.data)[1],
1190 attrs[0] & readdir->bitmask[0],
1191 attrs[1] & readdir->bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192}
1193
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001194static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195{
Al Viro8687b632006-10-19 23:28:48 -07001196 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
1198 RESERVE_SPACE(4);
1199 WRITE32(OP_READLINK);
Andy Adamsond0179312008-12-23 16:06:17 -05001200 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001203static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
Al Viro8687b632006-10-19 23:28:48 -07001205 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
1207 RESERVE_SPACE(8 + name->len);
1208 WRITE32(OP_REMOVE);
1209 WRITE32(name->len);
1210 WRITEMEM(name->name, name->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001211 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212}
1213
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001214static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215{
Al Viro8687b632006-10-19 23:28:48 -07001216 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
1218 RESERVE_SPACE(8 + oldname->len);
1219 WRITE32(OP_RENAME);
1220 WRITE32(oldname->len);
1221 WRITEMEM(oldname->name, oldname->len);
Andy Adamson6c0195a2008-12-23 16:06:15 -05001222
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 RESERVE_SPACE(4 + newname->len);
1224 WRITE32(newname->len);
1225 WRITEMEM(newname->name, newname->len);
Andy Adamsond0179312008-12-23 16:06:17 -05001226 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227}
1228
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001229static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
Al Viro8687b632006-10-19 23:28:48 -07001231 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
1233 RESERVE_SPACE(12);
1234 WRITE32(OP_RENEW);
1235 WRITE64(client_stateid->cl_clientid);
Andy Adamsond0179312008-12-23 16:06:17 -05001236 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237}
1238
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001239static void
Andy Adamsond0179312008-12-23 16:06:17 -05001240encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001241{
Al Viro8687b632006-10-19 23:28:48 -07001242 __be32 *p;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001243
1244 RESERVE_SPACE(4);
1245 WRITE32(OP_RESTOREFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001246 hdr->nops++;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001247}
1248
1249static int
Andy Adamsond0179312008-12-23 16:06:17 -05001250encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001251{
Al Viro8687b632006-10-19 23:28:48 -07001252 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001253
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001254 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001255 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001256 WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001257 RESERVE_SPACE(2*4);
1258 WRITE32(1);
1259 WRITE32(FATTR4_WORD0_ACL);
1260 if (arg->acl_len % 4)
1261 return -EINVAL;
1262 RESERVE_SPACE(4);
1263 WRITE32(arg->acl_len);
1264 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001265 hdr->nops++;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001266 return 0;
1267}
1268
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001269static void
Andy Adamsond0179312008-12-23 16:06:17 -05001270encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271{
Al Viro8687b632006-10-19 23:28:48 -07001272 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
1274 RESERVE_SPACE(4);
1275 WRITE32(OP_SAVEFH);
Andy Adamsond0179312008-12-23 16:06:17 -05001276 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001279static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280{
Al Viro8687b632006-10-19 23:28:48 -07001281 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001282
Andy Adamson05d564f2008-12-23 16:06:15 -05001283 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
1284 WRITE32(OP_SETATTR);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001285 WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001286 hdr->nops++;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001287 encode_attrs(xdr, arg->iap, server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288}
1289
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001290static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291{
Al Viro8687b632006-10-19 23:28:48 -07001292 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001294 RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 WRITE32(OP_SETCLIENTID);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001296 WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
1298 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1299 RESERVE_SPACE(4);
1300 WRITE32(setclientid->sc_prog);
1301 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1302 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1303 RESERVE_SPACE(4);
1304 WRITE32(setclientid->sc_cb_ident);
Andy Adamsond0179312008-12-23 16:06:17 -05001305 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306}
1307
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001308static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309{
Andy Adamson05d564f2008-12-23 16:06:15 -05001310 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Andy Adamson05d564f2008-12-23 16:06:15 -05001312 RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
1313 WRITE32(OP_SETCLIENTID_CONFIRM);
1314 WRITE64(client_state->cl_clientid);
1315 WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001316 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317}
1318
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001319static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320{
Al Viro8687b632006-10-19 23:28:48 -07001321 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
1323 RESERVE_SPACE(4);
1324 WRITE32(OP_WRITE);
1325
1326 encode_stateid(xdr, args->context);
1327
1328 RESERVE_SPACE(16);
1329 WRITE64(args->offset);
1330 WRITE32(args->stable);
1331 WRITE32(args->count);
1332
1333 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001334 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335}
1336
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001337static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338{
Al Viro8687b632006-10-19 23:28:48 -07001339 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001341 RESERVE_SPACE(4+NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
1343 WRITE32(OP_DELEGRETURN);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04001344 WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05001345 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346}
1347/*
1348 * END OF "GENERIC" ENCODE ROUTINES.
1349 */
1350
1351/*
1352 * Encode an ACCESS request
1353 */
Al Viro8687b632006-10-19 23:28:48 -07001354static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355{
1356 struct xdr_stream xdr;
1357 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001358 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
1361 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1362 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001363 encode_putfh(&xdr, args->fh, &hdr);
1364 encode_access(&xdr, args->access, &hdr);
1365 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001366 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001367 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368}
1369
1370/*
1371 * Encode LOOKUP request
1372 */
Al Viro8687b632006-10-19 23:28:48 -07001373static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374{
1375 struct xdr_stream xdr;
1376 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001377 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
1380 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1381 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001382 encode_putfh(&xdr, args->dir_fh, &hdr);
1383 encode_lookup(&xdr, args->name, &hdr);
1384 encode_getfh(&xdr, &hdr);
1385 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001386 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001387 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388}
1389
1390/*
1391 * Encode LOOKUP_ROOT request
1392 */
Al Viro8687b632006-10-19 23:28:48 -07001393static 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 -07001394{
1395 struct xdr_stream xdr;
1396 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001397 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
1400 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1401 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001402 encode_putrootfh(&xdr, &hdr);
1403 encode_getfh(&xdr, &hdr);
1404 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001405 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001406 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407}
1408
1409/*
1410 * Encode REMOVE request
1411 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04001412static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413{
1414 struct xdr_stream xdr;
1415 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001416 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
1419 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1420 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001421 encode_putfh(&xdr, args->fh, &hdr);
1422 encode_remove(&xdr, &args->name, &hdr);
1423 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001424 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001425 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426}
1427
1428/*
1429 * Encode RENAME request
1430 */
Al Viro8687b632006-10-19 23:28:48 -07001431static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs4_rename_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432{
1433 struct xdr_stream xdr;
1434 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001435 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
1438 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1439 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001440 encode_putfh(&xdr, args->old_dir, &hdr);
1441 encode_savefh(&xdr, &hdr);
1442 encode_putfh(&xdr, args->new_dir, &hdr);
1443 encode_rename(&xdr, args->old_name, args->new_name, &hdr);
1444 encode_getfattr(&xdr, args->bitmask, &hdr);
1445 encode_restorefh(&xdr, &hdr);
1446 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001447 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001448 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449}
1450
1451/*
1452 * Encode LINK request
1453 */
Al Viro8687b632006-10-19 23:28:48 -07001454static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455{
1456 struct xdr_stream xdr;
1457 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001458 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
1461 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1462 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001463 encode_putfh(&xdr, args->fh, &hdr);
1464 encode_savefh(&xdr, &hdr);
1465 encode_putfh(&xdr, args->dir_fh, &hdr);
1466 encode_link(&xdr, args->name, &hdr);
1467 encode_getfattr(&xdr, args->bitmask, &hdr);
1468 encode_restorefh(&xdr, &hdr);
1469 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001470 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001471 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472}
1473
1474/*
1475 * Encode CREATE request
1476 */
Al Viro8687b632006-10-19 23:28:48 -07001477static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478{
1479 struct xdr_stream xdr;
1480 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001481 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
1484 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1485 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001486 encode_putfh(&xdr, args->dir_fh, &hdr);
1487 encode_savefh(&xdr, &hdr);
1488 encode_create(&xdr, args, &hdr);
1489 encode_getfh(&xdr, &hdr);
1490 encode_getfattr(&xdr, args->bitmask, &hdr);
1491 encode_restorefh(&xdr, &hdr);
1492 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001493 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001494 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495}
1496
1497/*
1498 * Encode SYMLINK request
1499 */
Al Viro8687b632006-10-19 23:28:48 -07001500static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501{
1502 return nfs4_xdr_enc_create(req, p, args);
1503}
1504
1505/*
1506 * Encode GETATTR request
1507 */
Al Viro8687b632006-10-19 23:28:48 -07001508static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509{
1510 struct xdr_stream xdr;
1511 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001512 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
1515 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1516 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001517 encode_putfh(&xdr, args->fh, &hdr);
1518 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001519 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001520 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521}
1522
1523/*
1524 * Encode a CLOSE request
1525 */
Al Viro8687b632006-10-19 23:28:48 -07001526static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527{
Andy Adamson05d564f2008-12-23 16:06:15 -05001528 struct xdr_stream xdr;
1529 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001530 .nops = 0,
Andy Adamson05d564f2008-12-23 16:06:15 -05001531 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Andy Adamson05d564f2008-12-23 16:06:15 -05001533 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1534 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001535 encode_putfh(&xdr, args->fh, &hdr);
1536 encode_close(&xdr, args, &hdr);
1537 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001538 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001539 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540}
1541
1542/*
1543 * Encode an OPEN request
1544 */
Al Viro8687b632006-10-19 23:28:48 -07001545static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546{
1547 struct xdr_stream xdr;
1548 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001549 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
1552 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1553 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001554 encode_putfh(&xdr, args->fh, &hdr);
1555 encode_savefh(&xdr, &hdr);
1556 encode_open(&xdr, args, &hdr);
1557 encode_getfh(&xdr, &hdr);
1558 encode_getfattr(&xdr, args->bitmask, &hdr);
1559 encode_restorefh(&xdr, &hdr);
1560 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001561 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001562 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563}
1564
1565/*
1566 * Encode an OPEN_CONFIRM request
1567 */
Al Viro8687b632006-10-19 23:28:48 -07001568static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569{
1570 struct xdr_stream xdr;
1571 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001572 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
1575 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1576 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001577 encode_putfh(&xdr, args->fh, &hdr);
1578 encode_open_confirm(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001579 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001580 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581}
1582
1583/*
1584 * Encode an OPEN request with no attributes.
1585 */
Al Viro8687b632006-10-19 23:28:48 -07001586static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587{
1588 struct xdr_stream xdr;
1589 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001590 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
1593 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1594 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001595 encode_putfh(&xdr, args->fh, &hdr);
1596 encode_open(&xdr, args, &hdr);
1597 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001598 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001599 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601
1602/*
1603 * Encode an OPEN_DOWNGRADE request
1604 */
Al Viro8687b632006-10-19 23:28:48 -07001605static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606{
1607 struct xdr_stream xdr;
1608 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001609 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1613 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001614 encode_putfh(&xdr, args->fh, &hdr);
1615 encode_open_downgrade(&xdr, args, &hdr);
1616 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001617 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001618 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619}
1620
1621/*
1622 * Encode a LOCK request
1623 */
Al Viro8687b632006-10-19 23:28:48 -07001624static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625{
1626 struct xdr_stream xdr;
1627 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001628 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
1631 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1632 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001633 encode_putfh(&xdr, args->fh, &hdr);
1634 encode_lock(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001635 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001636 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637}
1638
1639/*
1640 * Encode a LOCKT request
1641 */
Al Viro8687b632006-10-19 23:28:48 -07001642static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643{
1644 struct xdr_stream xdr;
1645 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001646 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
1649 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1650 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001651 encode_putfh(&xdr, args->fh, &hdr);
1652 encode_lockt(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001653 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001654 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655}
1656
1657/*
1658 * Encode a LOCKU request
1659 */
Al Viro8687b632006-10-19 23:28:48 -07001660static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
1662 struct xdr_stream xdr;
1663 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001664 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1668 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001669 encode_putfh(&xdr, args->fh, &hdr);
1670 encode_locku(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001671 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001672 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673}
1674
1675/*
1676 * Encode a READLINK request
1677 */
Al Viro8687b632006-10-19 23:28:48 -07001678static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679{
1680 struct xdr_stream xdr;
1681 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001682 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 };
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001684 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1685 unsigned int replen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
1687 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1688 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001689 encode_putfh(&xdr, args->fh, &hdr);
1690 encode_readlink(&xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04001691
1692 /* set up reply kvec
1693 * toplevel_status + taglen + rescount + OP_PUTFH + status
1694 * + OP_READLINK + status + string length = 8
1695 */
1696 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readlink_sz) << 2;
1697 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1698 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05001699 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001700 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
1703/*
1704 * Encode a READDIR request
1705 */
Al Viro8687b632006-10-19 23:28:48 -07001706static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707{
1708 struct xdr_stream xdr;
1709 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001710 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 };
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001712 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
1713 int replen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
1715 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1716 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001717 encode_putfh(&xdr, args->fh, &hdr);
1718 encode_readdir(&xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001719
1720 /* set up reply kvec
1721 * toplevel_status + taglen + rescount + OP_PUTFH + status
1722 * + OP_READDIR + status + verifer(2) = 9
1723 */
1724 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_readdir_sz) << 2;
1725 xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages,
1726 args->pgbase, args->count);
1727 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07001728 __func__, replen, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04001729 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05001730 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001731 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
1733
1734/*
1735 * Encode a READ request
1736 */
Al Viro8687b632006-10-19 23:28:48 -07001737static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738{
Trond Myklebust1be27f32007-06-27 14:29:04 -04001739 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 struct xdr_stream xdr;
1741 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001742 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 };
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001744 int replen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
1746 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1747 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001748 encode_putfh(&xdr, args->fh, &hdr);
1749 encode_read(&xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
1751 /* set up reply kvec
1752 * toplevel status + taglen=0 + rescount + OP_PUTFH + status
1753 * + OP_READ + status + eof + datalen = 9
1754 */
1755 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_read_sz) << 2;
1756 xdr_inline_pages(&req->rq_rcv_buf, replen,
1757 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001758 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05001759 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001760 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761}
1762
1763/*
1764 * Encode an SETATTR request
1765 */
Al Viro8687b632006-10-19 23:28:48 -07001766static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767{
Andy Adamson05d564f2008-12-23 16:06:15 -05001768 struct xdr_stream xdr;
1769 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001770 .nops = 0,
Andy Adamson05d564f2008-12-23 16:06:15 -05001771 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
Andy Adamson05d564f2008-12-23 16:06:15 -05001773 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1774 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001775 encode_putfh(&xdr, args->fh, &hdr);
1776 encode_setattr(&xdr, args, args->server, &hdr);
1777 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001778 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001779 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780}
1781
1782/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00001783 * Encode a GETACL request
1784 */
1785static int
Al Viro8687b632006-10-19 23:28:48 -07001786nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001787 struct nfs_getaclargs *args)
1788{
1789 struct xdr_stream xdr;
Trond Myklebust1be27f32007-06-27 14:29:04 -04001790 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001791 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001792 .nops = 0,
J. Bruce Fields029d1052005-06-22 17:16:22 +00001793 };
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001794 int replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001795
1796 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1797 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001798 encode_putfh(&xdr, args->fh, &hdr);
1799 encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr);
1800
J. Bruce Fields029d1052005-06-22 17:16:22 +00001801 /* set up reply buffer: */
1802 replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS4_dec_getacl_sz) << 2;
1803 xdr_inline_pages(&req->rq_rcv_buf, replen,
1804 args->acl_pages, args->acl_pgbase, args->acl_len);
Andy Adamsond0179312008-12-23 16:06:17 -05001805 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001806 return 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00001807}
1808
1809/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 * Encode a WRITE request
1811 */
Al Viro8687b632006-10-19 23:28:48 -07001812static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813{
1814 struct xdr_stream xdr;
1815 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001816 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
1819 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1820 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001821 encode_putfh(&xdr, args->fh, &hdr);
1822 encode_write(&xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04001823 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001824 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001825 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001826 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827}
1828
1829/*
1830 * a COMMIT request
1831 */
Al Viro8687b632006-10-19 23:28:48 -07001832static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833{
1834 struct xdr_stream xdr;
1835 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001836 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
1839 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1840 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001841 encode_putfh(&xdr, args->fh, &hdr);
1842 encode_commit(&xdr, args, &hdr);
1843 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001844 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001845 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846}
1847
1848/*
1849 * FSINFO request
1850 */
Al Viro8687b632006-10-19 23:28:48 -07001851static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852{
1853 struct xdr_stream xdr;
1854 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001855 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
1858 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1859 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001860 encode_putfh(&xdr, args->fh, &hdr);
1861 encode_fsinfo(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001862 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001863 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864}
1865
1866/*
1867 * a PATHCONF request
1868 */
Al Viro8687b632006-10-19 23:28:48 -07001869static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 struct xdr_stream xdr;
1872 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001873 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
1876 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1877 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001878 encode_putfh(&xdr, args->fh, &hdr);
1879 encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
1880 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001881 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001882 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883}
1884
1885/*
1886 * a STATFS request
1887 */
Al Viro8687b632006-10-19 23:28:48 -07001888static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_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 = {
Andy Adamsond0179312008-12-23 16:06:17 -05001892 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894
1895 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1896 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001897 encode_putfh(&xdr, args->fh, &hdr);
1898 encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
1899 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001900 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001901 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902}
1903
1904/*
1905 * GETATTR_BITMAP request
1906 */
Benny Halevy43652ad2009-04-01 09:21:54 -04001907static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p,
1908 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909{
1910 struct xdr_stream xdr;
1911 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001912 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914
1915 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1916 encode_compound_hdr(&xdr, &hdr);
Benny Halevy43652ad2009-04-01 09:21:54 -04001917 encode_putfh(&xdr, args->fhandle, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001918 encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
1919 FATTR4_WORD0_LINK_SUPPORT|
1920 FATTR4_WORD0_SYMLINK_SUPPORT|
1921 FATTR4_WORD0_ACLSUPPORT, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001922 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001923 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924}
1925
1926/*
1927 * a RENEW request
1928 */
Al Viro8687b632006-10-19 23:28:48 -07001929static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930{
1931 struct xdr_stream xdr;
1932 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001933 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 };
1935
1936 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1937 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001938 encode_renew(&xdr, clp, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001939 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001940 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941}
1942
1943/*
1944 * a SETCLIENTID request
1945 */
Al Viro8687b632006-10-19 23:28:48 -07001946static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947{
1948 struct xdr_stream xdr;
1949 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001950 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 };
1952
1953 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1954 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001955 encode_setclientid(&xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001956 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001957 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958}
1959
1960/*
1961 * a SETCLIENTID_CONFIRM request
1962 */
Al Viro8687b632006-10-19 23:28:48 -07001963static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964{
1965 struct xdr_stream xdr;
1966 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001967 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 };
1969 const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970
1971 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1972 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001973 encode_setclientid_confirm(&xdr, clp, &hdr);
1974 encode_putrootfh(&xdr, &hdr);
1975 encode_fsinfo(&xdr, lease_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001976 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001977 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978}
1979
1980/*
1981 * DELEGRETURN request
1982 */
Al Viro8687b632006-10-19 23:28:48 -07001983static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984{
1985 struct xdr_stream xdr;
1986 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05001987 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
1990 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
1991 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001992 encode_putfh(&xdr, args->fhandle, &hdr);
1993 encode_delegreturn(&xdr, args->stateid, &hdr);
1994 encode_getfattr(&xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05001995 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001996 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997}
1998
1999/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002000 * Encode FS_LOCATIONS request
2001 */
Al Viro8687b632006-10-19 23:28:48 -07002002static 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 -04002003{
2004 struct xdr_stream xdr;
2005 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002006 .nops = 0,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002007 };
Trond Myklebust1be27f32007-06-27 14:29:04 -04002008 struct rpc_auth *auth = req->rq_task->tk_msg.rpc_cred->cr_auth;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002009 int replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002010
2011 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
2012 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002013 encode_putfh(&xdr, args->dir_fh, &hdr);
2014 encode_lookup(&xdr, args->name, &hdr);
2015 encode_fs_locations(&xdr, args->bitmask, &hdr);
2016
Trond Myklebust683b57b2006-06-09 09:34:22 -04002017 /* set up reply
Manoj Naik830b8e32006-06-09 09:34:25 -04002018 * toplevel_status + OP_PUTFH + status
Trond Myklebust683b57b2006-06-09 09:34:22 -04002019 * + OP_LOOKUP + status + OP_GETATTR + status = 7
2020 */
2021 replen = (RPC_REPHDRSIZE + auth->au_rslack + 7) << 2;
2022 xdr_inline_pages(&req->rq_rcv_buf, replen, &args->page,
2023 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002024 encode_nops(&hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002025 return 0;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002026}
2027
2028/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 * START OF "GENERIC" DECODE ROUTINES.
2030 * These may look a little ugly since they are imported from a "generic"
2031 * set of XDR encode/decode routines which are intended to be shared by
2032 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
2033 *
2034 * If the pain of reading these is too great, it should be a straightforward
2035 * task to translate them into Linux-specific versions which are more
2036 * consistent with the style used in NFSv2/v3...
2037 */
2038#define READ32(x) (x) = ntohl(*p++)
2039#define READ64(x) do { \
2040 (x) = (u64)ntohl(*p++) << 32; \
2041 (x) |= ntohl(*p++); \
2042} while (0)
2043#define READTIME(x) do { \
2044 p++; \
2045 (x.tv_sec) = ntohl(*p++); \
2046 (x.tv_nsec) = ntohl(*p++); \
2047} while (0)
2048#define COPYMEM(x,nbytes) do { \
2049 memcpy((x), p, nbytes); \
2050 p += XDR_QUADLEN(nbytes); \
2051} while (0)
2052
2053#define READ_BUF(nbytes) do { \
2054 p = xdr_inline_decode(xdr, nbytes); \
Chuck Levere4cc6ee2007-05-08 18:23:28 -04002055 if (unlikely(!p)) { \
Chuck Leverfe82a182007-09-11 18:01:10 -04002056 dprintk("nfs: %s: prematurely hit end of receive" \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002057 " buffer\n", __func__); \
Chuck Leverfe82a182007-09-11 18:01:10 -04002058 dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
Harvey Harrison3110ff82008-05-02 13:42:44 -07002059 __func__, xdr->p, nbytes, xdr->end); \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 return -EIO; \
2061 } \
2062} while (0)
2063
Trond Myklebust683b57b2006-06-09 09:34:22 -04002064static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065{
Al Viro8687b632006-10-19 23:28:48 -07002066 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
2068 READ_BUF(4);
2069 READ32(*len);
2070 READ_BUF(*len);
2071 *string = (char *)p;
2072 return 0;
2073}
2074
2075static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
2076{
Al Viro8687b632006-10-19 23:28:48 -07002077 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
2079 READ_BUF(8);
2080 READ32(hdr->status);
2081 READ32(hdr->taglen);
Andy Adamson6c0195a2008-12-23 16:06:15 -05002082
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 READ_BUF(hdr->taglen + 4);
2084 hdr->tag = (char *)p;
2085 p += XDR_QUADLEN(hdr->taglen);
2086 READ32(hdr->nops);
Benny Halevyaadf6152008-12-23 16:06:13 -05002087 if (unlikely(hdr->nops < 1))
2088 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 return 0;
2090}
2091
2092static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2093{
Al Viro8687b632006-10-19 23:28:48 -07002094 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 uint32_t opnum;
2096 int32_t nfserr;
2097
2098 READ_BUF(8);
2099 READ32(opnum);
2100 if (opnum != expected) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002101 dprintk("nfs: Server returned operation"
2102 " %d but we issued a request for %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 opnum, expected);
2104 return -EIO;
2105 }
2106 READ32(nfserr);
2107 if (nfserr != NFS_OK)
Benny Halevy856dff32008-03-31 17:39:06 +03002108 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 return 0;
2110}
2111
2112/* Dummy routine */
David Howellsadfa6f92006-08-22 20:06:08 -04002113static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114{
Al Viro8687b632006-10-19 23:28:48 -07002115 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002116 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 char *str;
2118
2119 READ_BUF(12);
2120 return decode_opaque_inline(xdr, &strlen, &str);
2121}
2122
2123static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
2124{
Al Viro8687b632006-10-19 23:28:48 -07002125 uint32_t bmlen;
2126 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
2128 READ_BUF(4);
2129 READ32(bmlen);
2130
2131 bitmap[0] = bitmap[1] = 0;
2132 READ_BUF((bmlen << 2));
2133 if (bmlen > 0) {
2134 READ32(bitmap[0]);
2135 if (bmlen > 1)
2136 READ32(bitmap[1]);
2137 }
2138 return 0;
2139}
2140
Al Viro8687b632006-10-19 23:28:48 -07002141static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, __be32 **savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142{
Al Viro8687b632006-10-19 23:28:48 -07002143 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
2145 READ_BUF(4);
2146 READ32(*attrlen);
2147 *savep = xdr->p;
2148 return 0;
2149}
2150
2151static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
2152{
2153 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
2154 decode_attr_bitmap(xdr, bitmask);
2155 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2156 } else
2157 bitmask[0] = bitmask[1] = 0;
Fred Isaman44109242008-04-02 15:21:15 +03002158 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 return 0;
2160}
2161
2162static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
2163{
Al Viro8687b632006-10-19 23:28:48 -07002164 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002165 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
2167 *type = 0;
2168 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
2169 return -EIO;
2170 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
2171 READ_BUF(4);
2172 READ32(*type);
2173 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07002174 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 return -EIO;
2176 }
2177 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002178 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 }
Trond Myklebustbca79472009-03-11 14:10:26 -04002180 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04002181 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182}
2183
2184static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
2185{
Al Viro8687b632006-10-19 23:28:48 -07002186 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002187 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
2189 *change = 0;
2190 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
2191 return -EIO;
2192 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
2193 READ_BUF(8);
2194 READ64(*change);
2195 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002196 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002198 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04002200 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201}
2202
2203static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
2204{
Al Viro8687b632006-10-19 23:28:48 -07002205 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002206 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
2208 *size = 0;
2209 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
2210 return -EIO;
2211 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
2212 READ_BUF(8);
2213 READ64(*size);
2214 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002215 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002217 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04002218 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219}
2220
2221static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2222{
Al Viro8687b632006-10-19 23:28:48 -07002223 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
2225 *res = 0;
2226 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
2227 return -EIO;
2228 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
2229 READ_BUF(4);
2230 READ32(*res);
2231 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
2232 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002233 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 return 0;
2235}
2236
2237static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2238{
Al Viro8687b632006-10-19 23:28:48 -07002239 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
2241 *res = 0;
2242 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
2243 return -EIO;
2244 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
2245 READ_BUF(4);
2246 READ32(*res);
2247 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
2248 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002249 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 return 0;
2251}
2252
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04002253static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254{
Al Viro8687b632006-10-19 23:28:48 -07002255 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002256 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
2258 fsid->major = 0;
2259 fsid->minor = 0;
2260 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
2261 return -EIO;
2262 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
2263 READ_BUF(16);
2264 READ64(fsid->major);
2265 READ64(fsid->minor);
2266 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002267 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002269 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 (unsigned long long)fsid->major,
2271 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002272 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273}
2274
2275static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2276{
Al Viro8687b632006-10-19 23:28:48 -07002277 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278
2279 *res = 60;
2280 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
2281 return -EIO;
2282 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
2283 READ_BUF(4);
2284 READ32(*res);
2285 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
2286 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002287 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 return 0;
2289}
2290
2291static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2292{
Al Viro8687b632006-10-19 23:28:48 -07002293 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
2295 *res = ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL;
2296 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
2297 return -EIO;
2298 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
2299 READ_BUF(4);
2300 READ32(*res);
2301 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
2302 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002303 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 return 0;
2305}
2306
2307static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2308{
Al Viro8687b632006-10-19 23:28:48 -07002309 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002310 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
2312 *fileid = 0;
2313 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
2314 return -EIO;
2315 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
2316 READ_BUF(8);
2317 READ64(*fileid);
2318 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002319 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002321 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002322 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323}
2324
Manoj Naik99baf622006-06-09 09:34:24 -04002325static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
2326{
Al Viro8687b632006-10-19 23:28:48 -07002327 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002328 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04002329
2330 *fileid = 0;
2331 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
2332 return -EIO;
2333 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
2334 READ_BUF(8);
2335 READ64(*fileid);
2336 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04002337 ret = NFS_ATTR_FATTR_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04002338 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002339 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002340 return ret;
Manoj Naik99baf622006-06-09 09:34:24 -04002341}
2342
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2344{
Al Viro8687b632006-10-19 23:28:48 -07002345 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 int status = 0;
2347
2348 *res = 0;
2349 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
2350 return -EIO;
2351 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
2352 READ_BUF(8);
2353 READ64(*res);
2354 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
2355 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002356 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 return status;
2358}
2359
2360static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2361{
Al Viro8687b632006-10-19 23:28:48 -07002362 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 int status = 0;
2364
2365 *res = 0;
2366 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
2367 return -EIO;
2368 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
2369 READ_BUF(8);
2370 READ64(*res);
2371 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
2372 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002373 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 return status;
2375}
2376
2377static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2378{
Al Viro8687b632006-10-19 23:28:48 -07002379 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 int status = 0;
2381
2382 *res = 0;
2383 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
2384 return -EIO;
2385 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
2386 READ_BUF(8);
2387 READ64(*res);
2388 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
2389 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002390 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 return status;
2392}
2393
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002394static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
2395{
Chuck Lever464ad6b2007-10-26 13:32:08 -04002396 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07002397 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002398 int status = 0;
2399
2400 READ_BUF(4);
2401 READ32(n);
Andy Adamson33a43f22006-06-09 09:34:30 -04002402 if (n == 0)
2403 goto root_path;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002404 dprintk("path ");
2405 path->ncomponents = 0;
2406 while (path->ncomponents < n) {
2407 struct nfs4_string *component = &path->components[path->ncomponents];
2408 status = decode_opaque_inline(xdr, &component->len, &component->data);
2409 if (unlikely(status != 0))
2410 goto out_eio;
2411 if (path->ncomponents != n)
2412 dprintk("/");
2413 dprintk("%s", component->data);
2414 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
2415 path->ncomponents++;
2416 else {
2417 dprintk("cannot parse %d components in path\n", n);
2418 goto out_eio;
2419 }
2420 }
2421out:
2422 dprintk("\n");
2423 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04002424root_path:
2425/* a root pathname is sent as a zero component4 */
2426 path->ncomponents = 1;
2427 path->components[0].len=0;
2428 path->components[0].data=NULL;
2429 dprintk("path /\n");
2430 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002431out_eio:
2432 dprintk(" status %d", status);
2433 status = -EIO;
2434 goto out;
2435}
2436
2437static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002438{
2439 int n;
Al Viro8687b632006-10-19 23:28:48 -07002440 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002441 int status = -EIO;
2442
2443 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
2444 goto out;
2445 status = 0;
2446 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
2447 goto out;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002448 dprintk("%s: fsroot ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002449 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002450 if (unlikely(status != 0))
2451 goto out;
2452 READ_BUF(4);
2453 READ32(n);
2454 if (n <= 0)
2455 goto out_eio;
2456 res->nlocations = 0;
2457 while (res->nlocations < n) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002458 u32 m;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002459 struct nfs4_fs_location *loc = &res->locations[res->nlocations];
Trond Myklebust683b57b2006-06-09 09:34:22 -04002460
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002461 READ_BUF(4);
2462 READ32(m);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002463
2464 loc->nservers = 0;
Harvey Harrison3110ff82008-05-02 13:42:44 -07002465 dprintk("%s: servers ", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002466 while (loc->nservers < m) {
2467 struct nfs4_string *server = &loc->servers[loc->nservers];
2468 status = decode_opaque_inline(xdr, &server->len, &server->data);
2469 if (unlikely(status != 0))
2470 goto out_eio;
2471 dprintk("%s ", server->data);
2472 if (loc->nservers < NFS4_FS_LOCATION_MAXSERVERS)
2473 loc->nservers++;
2474 else {
Chuck Lever464ad6b2007-10-26 13:32:08 -04002475 unsigned int i;
2476 dprintk("%s: using first %u of %u servers "
2477 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002478 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04002479 NFS4_FS_LOCATION_MAXSERVERS,
2480 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002481 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002482 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002483 char *data;
2484 status = decode_opaque_inline(xdr, &len, &data);
2485 if (unlikely(status != 0))
2486 goto out_eio;
2487 }
2488 }
2489 }
2490 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002491 if (unlikely(status != 0))
2492 goto out_eio;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04002493 if (res->nlocations < NFS4_FS_LOCATIONS_MAXENTRIES)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002494 res->nlocations++;
2495 }
Trond Myklebust409924e2009-03-11 14:10:27 -04002496 if (res->nlocations != 0)
2497 status = NFS_ATTR_FATTR_V4_REFERRAL;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002498out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002499 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002500 return status;
2501out_eio:
2502 status = -EIO;
2503 goto out;
2504}
2505
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2507{
Al Viro8687b632006-10-19 23:28:48 -07002508 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 int status = 0;
2510
2511 *res = 0;
2512 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
2513 return -EIO;
2514 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
2515 READ_BUF(8);
2516 READ64(*res);
2517 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
2518 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002519 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 return status;
2521}
2522
2523static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
2524{
Al Viro8687b632006-10-19 23:28:48 -07002525 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 int status = 0;
2527
2528 *maxlink = 1;
2529 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
2530 return -EIO;
2531 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
2532 READ_BUF(4);
2533 READ32(*maxlink);
2534 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
2535 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002536 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 return status;
2538}
2539
2540static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
2541{
Al Viro8687b632006-10-19 23:28:48 -07002542 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 int status = 0;
2544
2545 *maxname = 1024;
2546 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
2547 return -EIO;
2548 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
2549 READ_BUF(4);
2550 READ32(*maxname);
2551 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
2552 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002553 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 return status;
2555}
2556
2557static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2558{
Al Viro8687b632006-10-19 23:28:48 -07002559 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 int status = 0;
2561
2562 *res = 1024;
2563 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
2564 return -EIO;
2565 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
2566 uint64_t maxread;
2567 READ_BUF(8);
2568 READ64(maxread);
2569 if (maxread > 0x7FFFFFFF)
2570 maxread = 0x7FFFFFFF;
2571 *res = (uint32_t)maxread;
2572 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
2573 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002574 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 return status;
2576}
2577
2578static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
2579{
Al Viro8687b632006-10-19 23:28:48 -07002580 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 int status = 0;
2582
2583 *res = 1024;
2584 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
2585 return -EIO;
2586 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
2587 uint64_t maxwrite;
2588 READ_BUF(8);
2589 READ64(maxwrite);
2590 if (maxwrite > 0x7FFFFFFF)
2591 maxwrite = 0x7FFFFFFF;
2592 *res = (uint32_t)maxwrite;
2593 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
2594 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002595 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 return status;
2597}
2598
Trond Myklebustbca79472009-03-11 14:10:26 -04002599static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600{
Trond Myklebustbca79472009-03-11 14:10:26 -04002601 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07002602 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002603 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
2605 *mode = 0;
2606 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
2607 return -EIO;
2608 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
2609 READ_BUF(4);
Trond Myklebustbca79472009-03-11 14:10:26 -04002610 READ32(tmp);
2611 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04002613 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002615 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04002616 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617}
2618
2619static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
2620{
Al Viro8687b632006-10-19 23:28:48 -07002621 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002622 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623
2624 *nlink = 1;
2625 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
2626 return -EIO;
2627 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
2628 READ_BUF(4);
2629 READ32(*nlink);
2630 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04002631 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002633 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04002634 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635}
2636
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002637static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638{
Al Viro8687b632006-10-19 23:28:48 -07002639 uint32_t len;
2640 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002641 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642
2643 *uid = -2;
2644 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
2645 return -EIO;
2646 if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
2647 READ_BUF(4);
2648 READ32(len);
2649 READ_BUF(len);
2650 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04002651 if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
2652 ret = NFS_ATTR_FATTR_OWNER;
2653 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 dprintk("%s: nfs_map_name_to_uid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002655 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002657 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002658 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 bitmap[1] &= ~FATTR4_WORD1_OWNER;
2660 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002661 dprintk("%s: uid=%d\n", __func__, (int)*uid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002662 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663}
2664
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04002665static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_client *clp, uint32_t *gid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666{
Al Viro8687b632006-10-19 23:28:48 -07002667 uint32_t len;
2668 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002669 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670
2671 *gid = -2;
2672 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
2673 return -EIO;
2674 if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
2675 READ_BUF(4);
2676 READ32(len);
2677 READ_BUF(len);
2678 if (len < XDR_MAX_NETOBJ) {
Trond Myklebust409924e2009-03-11 14:10:27 -04002679 if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
2680 ret = NFS_ATTR_FATTR_GROUP;
2681 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 dprintk("%s: nfs_map_group_to_gid failed!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002683 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 } else
Chuck Leverfe82a182007-09-11 18:01:10 -04002685 dprintk("%s: name too long (%u)!\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002686 __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
2688 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002689 dprintk("%s: gid=%d\n", __func__, (int)*gid);
Trond Myklebust409924e2009-03-11 14:10:27 -04002690 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691}
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;
Trond Myklebust409924e2009-03-11 14:10:27 -04002697 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
2699 *rdev = MKDEV(0,0);
2700 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
2701 return -EIO;
2702 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
2703 dev_t tmp;
2704
2705 READ_BUF(8);
2706 READ32(major);
2707 READ32(minor);
2708 tmp = MKDEV(major, minor);
2709 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
2710 *rdev = tmp;
2711 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04002712 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002714 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04002715 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716}
2717
2718static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2719{
Al Viro8687b632006-10-19 23:28:48 -07002720 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 int status = 0;
2722
2723 *res = 0;
2724 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
2725 return -EIO;
2726 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
2727 READ_BUF(8);
2728 READ64(*res);
2729 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
2730 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002731 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 return status;
2733}
2734
2735static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2736{
Al Viro8687b632006-10-19 23:28:48 -07002737 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 int status = 0;
2739
2740 *res = 0;
2741 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
2742 return -EIO;
2743 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
2744 READ_BUF(8);
2745 READ64(*res);
2746 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
2747 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002748 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 return status;
2750}
2751
2752static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
2753{
Al Viro8687b632006-10-19 23:28:48 -07002754 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 int status = 0;
2756
2757 *res = 0;
2758 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
2759 return -EIO;
2760 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
2761 READ_BUF(8);
2762 READ64(*res);
2763 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
2764 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002765 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 return status;
2767}
2768
2769static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
2770{
Al Viro8687b632006-10-19 23:28:48 -07002771 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04002772 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773
2774 *used = 0;
2775 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
2776 return -EIO;
2777 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
2778 READ_BUF(8);
2779 READ64(*used);
2780 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04002781 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002783 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04002785 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786}
2787
2788static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
2789{
Al Viro8687b632006-10-19 23:28:48 -07002790 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 uint64_t sec;
2792 uint32_t nsec;
2793
2794 READ_BUF(12);
2795 READ64(sec);
2796 READ32(nsec);
2797 time->tv_sec = (time_t)sec;
2798 time->tv_nsec = (long)nsec;
2799 return 0;
2800}
2801
2802static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2803{
2804 int status = 0;
2805
2806 time->tv_sec = 0;
2807 time->tv_nsec = 0;
2808 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
2809 return -EIO;
2810 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
2811 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002812 if (status == 0)
2813 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
2815 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002816 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 return status;
2818}
2819
2820static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2821{
2822 int status = 0;
2823
2824 time->tv_sec = 0;
2825 time->tv_nsec = 0;
2826 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
2827 return -EIO;
2828 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
2829 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002830 if (status == 0)
2831 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
2833 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002834 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 return status;
2836}
2837
2838static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
2839{
2840 int status = 0;
2841
2842 time->tv_sec = 0;
2843 time->tv_nsec = 0;
2844 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
2845 return -EIO;
2846 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
2847 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04002848 if (status == 0)
2849 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
2851 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07002852 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 return status;
2854}
2855
Al Viro8687b632006-10-19 23:28:48 -07002856static int verify_attr_len(struct xdr_stream *xdr, __be32 *savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857{
2858 unsigned int attrwords = XDR_QUADLEN(attrlen);
2859 unsigned int nwords = xdr->p - savep;
2860
2861 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04002862 dprintk("%s: server returned incorrect attribute length: "
2863 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07002864 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 attrwords << 2,
2866 (attrwords < nwords) ? '<' : '>',
2867 nwords << 2);
2868 return -EIO;
2869 }
2870 return 0;
2871}
2872
2873static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2874{
Al Viro8687b632006-10-19 23:28:48 -07002875 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876
2877 READ_BUF(20);
2878 READ32(cinfo->atomic);
2879 READ64(cinfo->before);
2880 READ64(cinfo->after);
2881 return 0;
2882}
2883
2884static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
2885{
Al Viro8687b632006-10-19 23:28:48 -07002886 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 uint32_t supp, acc;
2888 int status;
2889
2890 status = decode_op_hdr(xdr, OP_ACCESS);
2891 if (status)
2892 return status;
2893 READ_BUF(8);
2894 READ32(supp);
2895 READ32(acc);
2896 access->supported = supp;
2897 access->access = acc;
2898 return 0;
2899}
2900
2901static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
2902{
Al Viro8687b632006-10-19 23:28:48 -07002903 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 int status;
2905
2906 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04002907 if (status != -EIO)
2908 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 if (status)
2910 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04002911 READ_BUF(NFS4_STATEID_SIZE);
2912 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 return 0;
2914}
2915
2916static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
2917{
Al Viro8687b632006-10-19 23:28:48 -07002918 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 int status;
2920
2921 status = decode_op_hdr(xdr, OP_COMMIT);
2922 if (status)
2923 return status;
2924 READ_BUF(8);
2925 COPYMEM(res->verf->verifier, 8);
2926 return 0;
2927}
2928
2929static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
2930{
Al Viro8687b632006-10-19 23:28:48 -07002931 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 uint32_t bmlen;
2933 int status;
2934
2935 status = decode_op_hdr(xdr, OP_CREATE);
2936 if (status)
2937 return status;
2938 if ((status = decode_change_info(xdr, cinfo)))
2939 return status;
2940 READ_BUF(4);
2941 READ32(bmlen);
2942 READ_BUF(bmlen << 2);
2943 return 0;
2944}
2945
2946static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
2947{
Al Viro8687b632006-10-19 23:28:48 -07002948 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002949 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 int status;
2951
2952 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2953 goto xdr_error;
2954 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2955 goto xdr_error;
2956 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2957 goto xdr_error;
2958 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
2959 goto xdr_error;
2960 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
2961 goto xdr_error;
2962 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
2963 goto xdr_error;
2964 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
2965 goto xdr_error;
2966 status = verify_attr_len(xdr, savep, attrlen);
2967xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07002968 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 return status;
2970}
Andy Adamson6c0195a2008-12-23 16:06:15 -05002971
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
2973{
Al Viro8687b632006-10-19 23:28:48 -07002974 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002975 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05002977
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
2979 goto xdr_error;
2980 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
2981 goto xdr_error;
2982 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
2983 goto xdr_error;
2984
2985 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
2986 goto xdr_error;
2987 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
2988 goto xdr_error;
2989 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
2990 goto xdr_error;
2991 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
2992 goto xdr_error;
2993 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
2994 goto xdr_error;
2995 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
2996 goto xdr_error;
2997
2998 status = verify_attr_len(xdr, savep, attrlen);
2999xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003000 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 return status;
3002}
3003
3004static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
3005{
Al Viro8687b632006-10-19 23:28:48 -07003006 __be32 *savep;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003007 uint32_t attrlen, bitmap[2] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003009
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3011 goto xdr_error;
3012 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3013 goto xdr_error;
3014 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3015 goto xdr_error;
3016
3017 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
3018 goto xdr_error;
3019 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
3020 goto xdr_error;
3021
3022 status = verify_attr_len(xdr, savep, attrlen);
3023xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003024 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 return status;
3026}
3027
3028static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, const struct nfs_server *server)
3029{
Al Viro8687b632006-10-19 23:28:48 -07003030 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 uint32_t attrlen,
3032 bitmap[2] = {0},
3033 type;
Trond Myklebustbca79472009-03-11 14:10:26 -04003034 int status;
3035 umode_t fmode = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003036 uint64_t fileid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003038 status = decode_op_hdr(xdr, OP_GETATTR);
3039 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 goto xdr_error;
3041
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003042 status = decode_attr_bitmap(xdr, bitmap);
3043 if (status < 0)
3044 goto xdr_error;
3045
3046 status = decode_attr_length(xdr, &attrlen, &savep);
3047 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 goto xdr_error;
3049
3050
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003051 status = decode_attr_type(xdr, bitmap, &type);
3052 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003054 fattr->mode = 0;
3055 if (status != 0) {
3056 fattr->mode |= nfs_type2fmt[type];
3057 fattr->valid |= status;
3058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003060 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
3061 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003063 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003064
3065 status = decode_attr_size(xdr, bitmap, &fattr->size);
3066 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003068 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003069
3070 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
3071 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003073 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003074
3075 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
3076 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003078 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003079
3080 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr,
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003081 struct nfs4_fs_locations,
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003082 fattr));
3083 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003084 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003085 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003086
3087 status = decode_attr_mode(xdr, bitmap, &fmode);
3088 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003090 if (status != 0) {
3091 fattr->mode |= fmode;
3092 fattr->valid |= status;
3093 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003094
3095 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
3096 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003098 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003099
3100 status = decode_attr_owner(xdr, bitmap, server->nfs_client, &fattr->uid);
3101 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003103 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003104
3105 status = decode_attr_group(xdr, bitmap, server->nfs_client, &fattr->gid);
3106 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003108 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003109
3110 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
3111 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003113 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003114
3115 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
3116 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003118 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003119
3120 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
3121 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003123 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003124
3125 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
3126 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003128 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003129
3130 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
3131 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003133 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003134
3135 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fileid);
3136 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04003137 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04003138 if (status != 0 && !(fattr->valid & status)) {
Manoj Naik99baf622006-06-09 09:34:24 -04003139 fattr->fileid = fileid;
Trond Myklebust409924e2009-03-11 14:10:27 -04003140 fattr->valid |= status;
3141 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04003142
3143 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003145 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 return status;
3147}
3148
3149
3150static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
3151{
Al Viro8687b632006-10-19 23:28:48 -07003152 __be32 *savep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 uint32_t attrlen, bitmap[2];
3154 int status;
3155
3156 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3157 goto xdr_error;
3158 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3159 goto xdr_error;
3160 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3161 goto xdr_error;
3162
3163 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
3164
3165 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
3166 goto xdr_error;
3167 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
3168 goto xdr_error;
3169 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
3170 goto xdr_error;
3171 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
3172 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
3173 goto xdr_error;
3174 fsinfo->wtpref = fsinfo->wtmax;
3175
3176 status = verify_attr_len(xdr, savep, attrlen);
3177xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003178 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 return status;
3180}
3181
3182static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
3183{
Al Viro8687b632006-10-19 23:28:48 -07003184 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 uint32_t len;
3186 int status;
3187
Trond Myklebust99367812007-07-17 21:52:41 -04003188 /* Zero handle first to allow comparisons */
3189 memset(fh, 0, sizeof(*fh));
3190
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 status = decode_op_hdr(xdr, OP_GETFH);
3192 if (status)
3193 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194
3195 READ_BUF(4);
3196 READ32(len);
3197 if (len > NFS4_FHSIZE)
3198 return -EIO;
3199 fh->size = len;
3200 READ_BUF(len);
3201 COPYMEM(fh->data, len);
3202 return 0;
3203}
3204
3205static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3206{
3207 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003208
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 status = decode_op_hdr(xdr, OP_LINK);
3210 if (status)
3211 return status;
3212 return decode_change_info(xdr, cinfo);
3213}
3214
3215/*
3216 * We create the owner, so we know a proper owner.id length is 4.
3217 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003218static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003220 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07003221 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003222 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223
3224 READ_BUF(32);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003225 READ64(offset);
3226 READ64(length);
3227 READ32(type);
3228 if (fl != NULL) {
3229 fl->fl_start = (loff_t)offset;
3230 fl->fl_end = fl->fl_start + (loff_t)length - 1;
3231 if (length == ~(uint64_t)0)
3232 fl->fl_end = OFFSET_MAX;
3233 fl->fl_type = F_WRLCK;
3234 if (type & 1)
3235 fl->fl_type = F_RDLCK;
3236 fl->fl_pid = 0;
3237 }
3238 READ64(clientid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 READ32(namelen);
3240 READ_BUF(namelen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 return -NFS4ERR_DENIED;
3242}
3243
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003244static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245{
Al Viro8687b632006-10-19 23:28:48 -07003246 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 int status;
3248
3249 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003250 if (status == -EIO)
3251 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003253 READ_BUF(NFS4_STATEID_SIZE);
3254 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04003256 status = decode_lock_denied(xdr, NULL);
3257 if (res->open_seqid != NULL)
3258 nfs_increment_open_seqid(status, res->open_seqid);
3259 nfs_increment_lock_seqid(status, res->lock_seqid);
3260out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 return status;
3262}
3263
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003264static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265{
3266 int status;
3267 status = decode_op_hdr(xdr, OP_LOCKT);
3268 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003269 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 return status;
3271}
3272
Trond Myklebust911d1aa2006-01-03 09:55:16 +01003273static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274{
Al Viro8687b632006-10-19 23:28:48 -07003275 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 int status;
3277
3278 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003279 if (status != -EIO)
3280 nfs_increment_lock_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 if (status == 0) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003282 READ_BUF(NFS4_STATEID_SIZE);
3283 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 }
3285 return status;
3286}
3287
3288static int decode_lookup(struct xdr_stream *xdr)
3289{
3290 return decode_op_hdr(xdr, OP_LOOKUP);
3291}
3292
3293/* This is too sick! */
3294static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
3295{
Andy Adamson05d564f2008-12-23 16:06:15 -05003296 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 uint32_t limit_type, nblocks, blocksize;
3298
3299 READ_BUF(12);
3300 READ32(limit_type);
3301 switch (limit_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003302 case 1:
3303 READ64(*maxsize);
3304 break;
3305 case 2:
3306 READ32(nblocks);
3307 READ32(blocksize);
3308 *maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 }
3310 return 0;
3311}
3312
3313static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
3314{
Andy Adamson05d564f2008-12-23 16:06:15 -05003315 __be32 *p;
3316 uint32_t delegation_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317
3318 READ_BUF(4);
3319 READ32(delegation_type);
3320 if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
3321 res->delegation_type = 0;
3322 return 0;
3323 }
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003324 READ_BUF(NFS4_STATEID_SIZE+4);
3325 COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 READ32(res->do_recall);
Andy Adamson05d564f2008-12-23 16:06:15 -05003327
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05003329 case NFS4_OPEN_DELEGATE_READ:
3330 res->delegation_type = FMODE_READ;
3331 break;
3332 case NFS4_OPEN_DELEGATE_WRITE:
3333 res->delegation_type = FMODE_WRITE|FMODE_READ;
3334 if (decode_space_limit(xdr, &res->maxsize) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 return -EIO;
3336 }
David Howells7539bba2006-08-22 20:06:09 -04003337 return decode_ace(xdr, NULL, res->server->nfs_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338}
3339
3340static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3341{
Andy Adamson05d564f2008-12-23 16:06:15 -05003342 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003343 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05003344 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345
Andy Adamson05d564f2008-12-23 16:06:15 -05003346 status = decode_op_hdr(xdr, OP_OPEN);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003347 if (status != -EIO)
3348 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003349 if (status)
3350 return status;
3351 READ_BUF(NFS4_STATEID_SIZE);
3352 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353
Andy Adamson05d564f2008-12-23 16:06:15 -05003354 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355
Andy Adamson05d564f2008-12-23 16:06:15 -05003356 READ_BUF(8);
3357 READ32(res->rflags);
3358 READ32(bmlen);
3359 if (bmlen > 10)
3360 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361
Andy Adamson05d564f2008-12-23 16:06:15 -05003362 READ_BUF(bmlen << 2);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04003363 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
3364 for (i = 0; i < savewords; ++i)
3365 READ32(res->attrset[i]);
3366 for (; i < NFS4_BITMAP_SIZE; i++)
3367 res->attrset[i] = 0;
3368
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 return decode_delegation(xdr, res);
3370xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003371 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 return -EIO;
3373}
3374
3375static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
3376{
Andy Adamson05d564f2008-12-23 16:06:15 -05003377 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 int status;
3379
Andy Adamson05d564f2008-12-23 16:06:15 -05003380 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003381 if (status != -EIO)
3382 nfs_increment_open_seqid(status, res->seqid);
Andy Adamson05d564f2008-12-23 16:06:15 -05003383 if (status)
3384 return status;
3385 READ_BUF(NFS4_STATEID_SIZE);
3386 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3387 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388}
3389
3390static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
3391{
Al Viro8687b632006-10-19 23:28:48 -07003392 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 int status;
3394
3395 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04003396 if (status != -EIO)
3397 nfs_increment_open_seqid(status, res->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 if (status)
3399 return status;
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003400 READ_BUF(NFS4_STATEID_SIZE);
3401 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 return 0;
3403}
3404
3405static int decode_putfh(struct xdr_stream *xdr)
3406{
3407 return decode_op_hdr(xdr, OP_PUTFH);
3408}
3409
3410static int decode_putrootfh(struct xdr_stream *xdr)
3411{
3412 return decode_op_hdr(xdr, OP_PUTROOTFH);
3413}
3414
3415static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_readres *res)
3416{
3417 struct kvec *iov = req->rq_rcv_buf.head;
Al Viro8687b632006-10-19 23:28:48 -07003418 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 uint32_t count, eof, recvd, hdrlen;
3420 int status;
3421
3422 status = decode_op_hdr(xdr, OP_READ);
3423 if (status)
3424 return status;
3425 READ_BUF(8);
3426 READ32(eof);
3427 READ32(count);
3428 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
3429 recvd = req->rq_rcv_buf.len - hdrlen;
3430 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003431 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 "count %u > recvd %u\n", count, recvd);
3433 count = recvd;
3434 eof = 0;
3435 }
3436 xdr_read_pages(xdr, count);
3437 res->eof = eof;
3438 res->count = count;
3439 return 0;
3440}
3441
3442static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
3443{
3444 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3445 struct page *page = *rcvbuf->pages;
3446 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003447 size_t hdrlen;
3448 u32 recvd, pglen = rcvbuf->page_len;
Al Viro8687b632006-10-19 23:28:48 -07003449 __be32 *end, *entry, *p, *kaddr;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003450 unsigned int nr = 0;
Chuck Leverbcecff72007-10-26 13:32:03 -04003451 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452
3453 status = decode_op_hdr(xdr, OP_READDIR);
3454 if (status)
3455 return status;
3456 READ_BUF(8);
3457 COPYMEM(readdir->verifier.data, 8);
Fred Isaman44109242008-04-02 15:21:15 +03003458 dprintk("%s: verifier = %08x:%08x\n",
3459 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00003460 ((u32 *)readdir->verifier.data)[0],
3461 ((u32 *)readdir->verifier.data)[1]);
3462
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463
3464 hdrlen = (char *) p - (char *) iov->iov_base;
3465 recvd = rcvbuf->len - hdrlen;
3466 if (pglen > recvd)
3467 pglen = recvd;
3468 xdr_read_pages(xdr, pglen);
3469
3470 BUG_ON(pglen + readdir->pgbase > PAGE_CACHE_SIZE);
Al Viro8687b632006-10-19 23:28:48 -07003471 kaddr = p = kmap_atomic(page, KM_USER0);
David Howellse8896492006-08-24 15:44:19 -04003472 end = p + ((pglen + readdir->pgbase) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 entry = p;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003474
3475 /* Make sure the packet actually has a value_follows and EOF entry */
3476 if ((entry + 1) > end)
3477 goto short_pkt;
3478
3479 for (; *p++; nr++) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003480 u32 len, attrlen, xlen;
David Howellse8896492006-08-24 15:44:19 -04003481 if (end - p < 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003483 dprintk("cookie = %Lu, ", *((unsigned long long *)p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 p += 2; /* cookie */
3485 len = ntohl(*p++); /* filename length */
3486 if (len > NFS4_MAXNAMLEN) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003487 dprintk("NFS: giant filename in readdir (len 0x%x)\n",
3488 len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 goto err_unmap;
3490 }
David Howellse8896492006-08-24 15:44:19 -04003491 xlen = XDR_QUADLEN(len);
3492 if (end - p < xlen + 1)
3493 goto short_pkt;
Trond Myklebusteadf4592005-06-22 17:16:39 +00003494 dprintk("filename = %*s\n", len, (char *)p);
David Howellse8896492006-08-24 15:44:19 -04003495 p += xlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 len = ntohl(*p++); /* bitmap length */
David Howellse8896492006-08-24 15:44:19 -04003497 if (end - p < len + 1)
3498 goto short_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 p += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 attrlen = XDR_QUADLEN(ntohl(*p++));
David Howellse8896492006-08-24 15:44:19 -04003501 if (end - p < attrlen + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 goto short_pkt;
David Howellse8896492006-08-24 15:44:19 -04003503 p += attrlen; /* attributes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 entry = p;
3505 }
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003506 /*
3507 * Apparently some server sends responses that are a valid size, but
3508 * contain no entries, and have value_follows==0 and EOF==0. For
3509 * those, just set the EOF marker.
3510 */
3511 if (!nr && entry[1] == 0) {
3512 dprintk("NFS: readdir reply truncated!\n");
3513 entry[1] = 1;
3514 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05003515out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 kunmap_atomic(kaddr, KM_USER0);
3517 return 0;
3518short_pkt:
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003519 /*
3520 * When we get a short packet there are 2 possibilities. We can
3521 * return an error, or fix up the response to look like a valid
3522 * response and return what we have so far. If there are no
3523 * entries and the packet was short, then return -EIO. If there
3524 * are valid entries in the response, return them and pretend that
3525 * the call was successful, but incomplete. The caller can retry the
3526 * readdir starting at the last cookie.
3527 */
Harvey Harrison3110ff82008-05-02 13:42:44 -07003528 dprintk("%s: short packet at entry %d\n", __func__, nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 entry[0] = entry[1] = 0;
Jeff Layton7bda2cd2008-02-22 14:50:01 -05003530 if (nr)
3531 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532err_unmap:
3533 kunmap_atomic(kaddr, KM_USER0);
3534 return -errno_NFSERR_IO;
3535}
3536
3537static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
3538{
3539 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
3540 struct kvec *iov = rcvbuf->head;
Chuck Leverbcecff72007-10-26 13:32:03 -04003541 size_t hdrlen;
3542 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07003543 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 char *kaddr;
3545 int status;
3546
3547 status = decode_op_hdr(xdr, OP_READLINK);
3548 if (status)
3549 return status;
3550
3551 /* Convert length of symlink */
3552 READ_BUF(4);
3553 READ32(len);
3554 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003555 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 return -ENAMETOOLONG;
3557 }
3558 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
3559 recvd = req->rq_rcv_buf.len - hdrlen;
3560 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003561 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 "count %u > recvd %u\n", len, recvd);
3563 return -EIO;
3564 }
3565 xdr_read_pages(xdr, len);
3566 /*
3567 * The XDR encode routine has set things up so that
3568 * the link text will be copied directly into the
3569 * buffer. We just have to do overflow-checking,
3570 * and and null-terminate the text (the VFS expects
3571 * null-termination).
3572 */
3573 kaddr = (char *)kmap_atomic(rcvbuf->pages[0], KM_USER0);
3574 kaddr[len+rcvbuf->page_base] = '\0';
3575 kunmap_atomic(kaddr, KM_USER0);
3576 return 0;
3577}
3578
3579static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
3580{
3581 int status;
3582
3583 status = decode_op_hdr(xdr, OP_REMOVE);
3584 if (status)
3585 goto out;
3586 status = decode_change_info(xdr, cinfo);
3587out:
3588 return status;
3589}
3590
3591static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
3592 struct nfs4_change_info *new_cinfo)
3593{
3594 int status;
3595
3596 status = decode_op_hdr(xdr, OP_RENAME);
3597 if (status)
3598 goto out;
3599 if ((status = decode_change_info(xdr, old_cinfo)))
3600 goto out;
3601 status = decode_change_info(xdr, new_cinfo);
3602out:
3603 return status;
3604}
3605
3606static int decode_renew(struct xdr_stream *xdr)
3607{
3608 return decode_op_hdr(xdr, OP_RENEW);
3609}
3610
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003611static int
3612decode_restorefh(struct xdr_stream *xdr)
3613{
3614 return decode_op_hdr(xdr, OP_RESTOREFH);
3615}
3616
J. Bruce Fields029d1052005-06-22 17:16:22 +00003617static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
3618 size_t *acl_len)
3619{
Al Viro8687b632006-10-19 23:28:48 -07003620 __be32 *savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003621 uint32_t attrlen,
3622 bitmap[2] = {0};
3623 struct kvec *iov = req->rq_rcv_buf.head;
3624 int status;
3625
3626 *acl_len = 0;
3627 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
3628 goto out;
3629 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
3630 goto out;
3631 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
3632 goto out;
3633
3634 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
3635 return -EIO;
3636 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
Chuck Leverbcecff72007-10-26 13:32:03 -04003637 size_t hdrlen;
3638 u32 recvd;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003639
3640 /* We ignore &savep and don't do consistency checks on
3641 * the attr length. Let userspace figure it out.... */
3642 hdrlen = (u8 *)xdr->p - (u8 *)iov->iov_base;
3643 recvd = req->rq_rcv_buf.len - hdrlen;
3644 if (attrlen > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003645 dprintk("NFS: server cheating in getattr"
J. Bruce Fields029d1052005-06-22 17:16:22 +00003646 " acl reply: attrlen %u > recvd %u\n",
3647 attrlen, recvd);
3648 return -EINVAL;
3649 }
J. Bruce Fieldsc04871e2006-05-30 16:28:58 -04003650 xdr_read_pages(xdr, attrlen);
J. Bruce Fields029d1052005-06-22 17:16:22 +00003651 *acl_len = attrlen;
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04003652 } else
3653 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00003654
3655out:
3656 return status;
3657}
3658
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659static int
3660decode_savefh(struct xdr_stream *xdr)
3661{
3662 return decode_op_hdr(xdr, OP_SAVEFH);
3663}
3664
Benny Halevy9e9ecc02009-04-01 09:22:00 -04003665static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666{
Al Viro8687b632006-10-19 23:28:48 -07003667 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 uint32_t bmlen;
3669 int status;
3670
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 status = decode_op_hdr(xdr, OP_SETATTR);
3672 if (status)
3673 return status;
3674 READ_BUF(4);
3675 READ32(bmlen);
3676 READ_BUF(bmlen << 2);
3677 return 0;
3678}
3679
David Howellsadfa6f92006-08-22 20:06:08 -04003680static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681{
Al Viro8687b632006-10-19 23:28:48 -07003682 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 uint32_t opnum;
3684 int32_t nfserr;
3685
3686 READ_BUF(8);
3687 READ32(opnum);
3688 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04003689 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05003690 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 return -EIO;
3692 }
3693 READ32(nfserr);
3694 if (nfserr == NFS_OK) {
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003695 READ_BUF(8 + NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 READ64(clp->cl_clientid);
Trond Myklebust8ae20ab2007-05-14 16:50:45 -04003697 COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 } else if (nfserr == NFSERR_CLID_INUSE) {
3699 uint32_t len;
3700
3701 /* skip netid string */
3702 READ_BUF(4);
3703 READ32(len);
3704 READ_BUF(len);
3705
3706 /* skip uaddr string */
3707 READ_BUF(4);
3708 READ32(len);
3709 READ_BUF(len);
3710 return -NFSERR_CLID_INUSE;
3711 } else
Benny Halevy856dff32008-03-31 17:39:06 +03003712 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713
3714 return 0;
3715}
3716
3717static int decode_setclientid_confirm(struct xdr_stream *xdr)
3718{
3719 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
3720}
3721
3722static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
3723{
Al Viro8687b632006-10-19 23:28:48 -07003724 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 int status;
3726
3727 status = decode_op_hdr(xdr, OP_WRITE);
3728 if (status)
3729 return status;
3730
3731 READ_BUF(16);
3732 READ32(res->count);
3733 READ32(res->verf->committed);
3734 COPYMEM(res->verf->verifier, 8);
3735 return 0;
3736}
3737
3738static int decode_delegreturn(struct xdr_stream *xdr)
3739{
3740 return decode_op_hdr(xdr, OP_DELEGRETURN);
3741}
3742
3743/*
Benny Halevy49c25592008-12-23 16:06:16 -05003744 * END OF "GENERIC" DECODE ROUTINES.
3745 */
3746
3747/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 * Decode OPEN_DOWNGRADE response
3749 */
Al Viro8687b632006-10-19 23:28:48 -07003750static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751{
Andy Adamson05d564f2008-12-23 16:06:15 -05003752 struct xdr_stream xdr;
3753 struct compound_hdr hdr;
3754 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755
Andy Adamson05d564f2008-12-23 16:06:15 -05003756 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3757 status = decode_compound_hdr(&xdr, &hdr);
3758 if (status)
3759 goto out;
3760 status = decode_putfh(&xdr);
3761 if (status)
3762 goto out;
3763 status = decode_open_downgrade(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04003764 if (status != 0)
3765 goto out;
3766 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767out:
Andy Adamson05d564f2008-12-23 16:06:15 -05003768 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769}
3770
3771/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 * Decode ACCESS response
3773 */
Al Viro8687b632006-10-19 23:28:48 -07003774static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775{
3776 struct xdr_stream xdr;
3777 struct compound_hdr hdr;
3778 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003779
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3781 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3782 goto out;
Trond Myklebust76b32992007-08-10 17:45:11 -04003783 status = decode_putfh(&xdr);
3784 if (status != 0)
3785 goto out;
3786 status = decode_access(&xdr, res);
3787 if (status != 0)
3788 goto out;
3789 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790out:
3791 return status;
3792}
3793
3794/*
3795 * Decode LOOKUP response
3796 */
Al Viro8687b632006-10-19 23:28:48 -07003797static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798{
3799 struct xdr_stream xdr;
3800 struct compound_hdr hdr;
3801 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003802
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3804 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3805 goto out;
3806 if ((status = decode_putfh(&xdr)) != 0)
3807 goto out;
3808 if ((status = decode_lookup(&xdr)) != 0)
3809 goto out;
3810 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3811 goto out;
3812 status = decode_getfattr(&xdr, res->fattr, res->server);
3813out:
3814 return status;
3815}
3816
3817/*
3818 * Decode LOOKUP_ROOT response
3819 */
Al Viro8687b632006-10-19 23:28:48 -07003820static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821{
3822 struct xdr_stream xdr;
3823 struct compound_hdr hdr;
3824 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003825
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3827 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3828 goto out;
3829 if ((status = decode_putrootfh(&xdr)) != 0)
3830 goto out;
3831 if ((status = decode_getfh(&xdr, res->fh)) == 0)
3832 status = decode_getfattr(&xdr, res->fattr, res->server);
3833out:
3834 return status;
3835}
3836
3837/*
3838 * Decode REMOVE response
3839 */
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04003840static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841{
3842 struct xdr_stream xdr;
3843 struct compound_hdr hdr;
3844 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003845
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3847 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3848 goto out;
Trond Myklebust16e42952005-10-27 22:12:44 -04003849 if ((status = decode_putfh(&xdr)) != 0)
3850 goto out;
3851 if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
3852 goto out;
Trond Myklebust4fdc17b2007-07-14 15:39:57 -04003853 decode_getfattr(&xdr, &res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854out:
3855 return status;
3856}
3857
3858/*
3859 * Decode RENAME response
3860 */
Al Viro8687b632006-10-19 23:28:48 -07003861static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_rename_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862{
3863 struct xdr_stream xdr;
3864 struct compound_hdr hdr;
3865 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003866
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3868 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3869 goto out;
3870 if ((status = decode_putfh(&xdr)) != 0)
3871 goto out;
3872 if ((status = decode_savefh(&xdr)) != 0)
3873 goto out;
3874 if ((status = decode_putfh(&xdr)) != 0)
3875 goto out;
Trond Myklebust6caf2c82005-10-27 22:12:43 -04003876 if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0)
3877 goto out;
3878 /* Current FH is target directory */
3879 if (decode_getfattr(&xdr, res->new_fattr, res->server) != 0)
3880 goto out;
3881 if ((status = decode_restorefh(&xdr)) != 0)
3882 goto out;
3883 decode_getfattr(&xdr, res->old_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884out:
3885 return status;
3886}
3887
3888/*
3889 * Decode LINK response
3890 */
Al Viro8687b632006-10-19 23:28:48 -07003891static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892{
3893 struct xdr_stream xdr;
3894 struct compound_hdr hdr;
3895 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003896
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3898 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3899 goto out;
3900 if ((status = decode_putfh(&xdr)) != 0)
3901 goto out;
3902 if ((status = decode_savefh(&xdr)) != 0)
3903 goto out;
3904 if ((status = decode_putfh(&xdr)) != 0)
3905 goto out;
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04003906 if ((status = decode_link(&xdr, &res->cinfo)) != 0)
3907 goto out;
3908 /*
3909 * Note order: OP_LINK leaves the directory as the current
3910 * filehandle.
3911 */
3912 if (decode_getfattr(&xdr, res->dir_attr, res->server) != 0)
3913 goto out;
3914 if ((status = decode_restorefh(&xdr)) != 0)
3915 goto out;
3916 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917out:
3918 return status;
3919}
3920
3921/*
3922 * Decode CREATE response
3923 */
Al Viro8687b632006-10-19 23:28:48 -07003924static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925{
3926 struct xdr_stream xdr;
3927 struct compound_hdr hdr;
3928 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003929
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3931 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
3932 goto out;
3933 if ((status = decode_putfh(&xdr)) != 0)
3934 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003935 if ((status = decode_savefh(&xdr)) != 0)
3936 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0)
3938 goto out;
3939 if ((status = decode_getfh(&xdr, res->fh)) != 0)
3940 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04003941 if (decode_getfattr(&xdr, res->fattr, res->server) != 0)
3942 goto out;
3943 if ((status = decode_restorefh(&xdr)) != 0)
3944 goto out;
3945 decode_getfattr(&xdr, res->dir_fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946out:
3947 return status;
3948}
3949
3950/*
3951 * Decode SYMLINK response
3952 */
Al Viro8687b632006-10-19 23:28:48 -07003953static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954{
3955 return nfs4_xdr_dec_create(rqstp, p, res);
3956}
3957
3958/*
3959 * Decode GETATTR response
3960 */
Al Viro8687b632006-10-19 23:28:48 -07003961static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962{
3963 struct xdr_stream xdr;
3964 struct compound_hdr hdr;
3965 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05003966
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
3968 status = decode_compound_hdr(&xdr, &hdr);
3969 if (status)
3970 goto out;
3971 status = decode_putfh(&xdr);
3972 if (status)
3973 goto out;
3974 status = decode_getfattr(&xdr, res->fattr, res->server);
3975out:
3976 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977}
3978
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003979/*
3980 * Encode an SETACL request
3981 */
3982static int
Al Viro8687b632006-10-19 23:28:48 -07003983nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003984{
Andy Adamson05d564f2008-12-23 16:06:15 -05003985 struct xdr_stream xdr;
3986 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05003987 .nops = 0,
Andy Adamson05d564f2008-12-23 16:06:15 -05003988 };
3989 int status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003990
Andy Adamson05d564f2008-12-23 16:06:15 -05003991 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
3992 encode_compound_hdr(&xdr, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05003993 encode_putfh(&xdr, args->fh, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05003994 status = encode_setacl(&xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05003995 encode_nops(&hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05003996 return status;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003997}
Andy Adamson05d564f2008-12-23 16:06:15 -05003998
J. Bruce Fields23ec6962005-06-22 17:16:22 +00003999/*
4000 * Decode SETACL response
4001 */
4002static int
Benny Halevy73c403a2009-04-01 09:22:01 -04004003nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p,
4004 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004005{
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;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004017 status = decode_setattr(&xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004018out:
4019 return status;
4020}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021
4022/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00004023 * Decode GETACL response
4024 */
4025static int
Benny Halevy663c79b2009-04-01 09:21:59 -04004026nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p,
4027 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00004028{
4029 struct xdr_stream xdr;
4030 struct compound_hdr hdr;
4031 int status;
4032
4033 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4034 status = decode_compound_hdr(&xdr, &hdr);
4035 if (status)
4036 goto out;
4037 status = decode_putfh(&xdr);
4038 if (status)
4039 goto out;
Benny Halevy663c79b2009-04-01 09:21:59 -04004040 status = decode_getacl(&xdr, rqstp, &res->acl_len);
J. Bruce Fields029d1052005-06-22 17:16:22 +00004041
4042out:
4043 return status;
4044}
4045
4046/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 * Decode CLOSE response
4048 */
Al Viro8687b632006-10-19 23:28:48 -07004049static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050{
Andy Adamson05d564f2008-12-23 16:06:15 -05004051 struct xdr_stream xdr;
4052 struct compound_hdr hdr;
4053 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054
Andy Adamson05d564f2008-12-23 16:06:15 -05004055 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_close(&xdr, res);
Trond Myklebust516a6af2005-10-27 22:12:41 -04004063 if (status != 0)
4064 goto out;
4065 /*
4066 * Note: Server may do delete on close for this file
4067 * in which case the getattr call will fail with
4068 * an ESTALE error. Shouldn't be a problem,
4069 * though, since fattr->valid will remain unset.
4070 */
4071 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004073 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074}
4075
4076/*
4077 * Decode OPEN response
4078 */
Al Viro8687b632006-10-19 23:28:48 -07004079static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080{
Andy Adamson05d564f2008-12-23 16:06:15 -05004081 struct xdr_stream xdr;
4082 struct compound_hdr hdr;
4083 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084
Andy Adamson05d564f2008-12-23 16:06:15 -05004085 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4086 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004087 if (status)
4088 goto out;
Andy Adamson05d564f2008-12-23 16:06:15 -05004089 status = decode_putfh(&xdr);
4090 if (status)
4091 goto out;
4092 status = decode_savefh(&xdr);
4093 if (status)
4094 goto out;
4095 status = decode_open(&xdr, res);
4096 if (status)
4097 goto out;
Trond Myklebust99367812007-07-17 21:52:41 -04004098 if (decode_getfh(&xdr, &res->fh) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 goto out;
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004100 if (decode_getfattr(&xdr, res->f_attr, res->server) != 0)
4101 goto out;
Trond Myklebust365c8f52007-07-17 21:52:37 -04004102 if (decode_restorefh(&xdr) != 0)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04004103 goto out;
4104 decode_getfattr(&xdr, res->dir_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004106 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107}
4108
4109/*
4110 * Decode OPEN_CONFIRM response
4111 */
Al Viro8687b632006-10-19 23:28:48 -07004112static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113{
Andy Adamson05d564f2008-12-23 16:06:15 -05004114 struct xdr_stream xdr;
4115 struct compound_hdr hdr;
4116 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117
Andy Adamson05d564f2008-12-23 16:06:15 -05004118 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4119 status = decode_compound_hdr(&xdr, &hdr);
4120 if (status)
4121 goto out;
4122 status = decode_putfh(&xdr);
4123 if (status)
4124 goto out;
4125 status = decode_open_confirm(&xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004127 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128}
4129
4130/*
4131 * Decode OPEN response
4132 */
Al Viro8687b632006-10-19 23:28:48 -07004133static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134{
Andy Adamson05d564f2008-12-23 16:06:15 -05004135 struct xdr_stream xdr;
4136 struct compound_hdr hdr;
4137 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138
Andy Adamson05d564f2008-12-23 16:06:15 -05004139 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4140 status = decode_compound_hdr(&xdr, &hdr);
4141 if (status)
4142 goto out;
4143 status = decode_putfh(&xdr);
4144 if (status)
4145 goto out;
4146 status = decode_open(&xdr, res);
4147 if (status)
4148 goto out;
Trond Myklebust864472e2006-01-03 09:55:15 +01004149 decode_getfattr(&xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004151 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152}
4153
4154/*
4155 * Decode SETATTR response
4156 */
Al Viro8687b632006-10-19 23:28:48 -07004157static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158{
Andy Adamson05d564f2008-12-23 16:06:15 -05004159 struct xdr_stream xdr;
4160 struct compound_hdr hdr;
4161 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162
Andy Adamson05d564f2008-12-23 16:06:15 -05004163 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4164 status = decode_compound_hdr(&xdr, &hdr);
4165 if (status)
4166 goto out;
4167 status = decode_putfh(&xdr);
4168 if (status)
4169 goto out;
Benny Halevy9e9ecc02009-04-01 09:22:00 -04004170 status = decode_setattr(&xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05004171 if (status)
4172 goto out;
Trond Myklebust78f945f2009-03-11 14:10:23 -04004173 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174out:
Andy Adamson05d564f2008-12-23 16:06:15 -05004175 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176}
4177
4178/*
4179 * Decode LOCK response
4180 */
Al Viro8687b632006-10-19 23:28:48 -07004181static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182{
4183 struct xdr_stream xdr;
4184 struct compound_hdr hdr;
4185 int status;
4186
4187 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4188 status = decode_compound_hdr(&xdr, &hdr);
4189 if (status)
4190 goto out;
4191 status = decode_putfh(&xdr);
4192 if (status)
4193 goto out;
4194 status = decode_lock(&xdr, res);
4195out:
4196 return status;
4197}
4198
4199/*
4200 * Decode LOCKT response
4201 */
Al Viro8687b632006-10-19 23:28:48 -07004202static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203{
4204 struct xdr_stream xdr;
4205 struct compound_hdr hdr;
4206 int status;
4207
4208 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4209 status = decode_compound_hdr(&xdr, &hdr);
4210 if (status)
4211 goto out;
4212 status = decode_putfh(&xdr);
4213 if (status)
4214 goto out;
4215 status = decode_lockt(&xdr, res);
4216out:
4217 return status;
4218}
4219
4220/*
4221 * Decode LOCKU response
4222 */
Al Viro8687b632006-10-19 23:28:48 -07004223static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224{
4225 struct xdr_stream xdr;
4226 struct compound_hdr hdr;
4227 int status;
4228
4229 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4230 status = decode_compound_hdr(&xdr, &hdr);
4231 if (status)
4232 goto out;
4233 status = decode_putfh(&xdr);
4234 if (status)
4235 goto out;
4236 status = decode_locku(&xdr, res);
4237out:
4238 return status;
4239}
4240
4241/*
4242 * Decode READLINK response
4243 */
Benny Halevyf50c7002009-04-01 09:21:55 -04004244static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p,
4245 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246{
4247 struct xdr_stream xdr;
4248 struct compound_hdr hdr;
4249 int status;
4250
4251 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4252 status = decode_compound_hdr(&xdr, &hdr);
4253 if (status)
4254 goto out;
4255 status = decode_putfh(&xdr);
4256 if (status)
4257 goto out;
4258 status = decode_readlink(&xdr, rqstp);
4259out:
4260 return status;
4261}
4262
4263/*
4264 * Decode READDIR response
4265 */
Al Viro8687b632006-10-19 23:28:48 -07004266static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267{
4268 struct xdr_stream xdr;
4269 struct compound_hdr hdr;
4270 int status;
4271
4272 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4273 status = decode_compound_hdr(&xdr, &hdr);
4274 if (status)
4275 goto out;
4276 status = decode_putfh(&xdr);
4277 if (status)
4278 goto out;
4279 status = decode_readdir(&xdr, rqstp, res);
4280out:
4281 return status;
4282}
4283
4284/*
4285 * Decode Read response
4286 */
Al Viro8687b632006-10-19 23:28:48 -07004287static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288{
4289 struct xdr_stream xdr;
4290 struct compound_hdr hdr;
4291 int status;
4292
4293 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4294 status = decode_compound_hdr(&xdr, &hdr);
4295 if (status)
4296 goto out;
4297 status = decode_putfh(&xdr);
4298 if (status)
4299 goto out;
4300 status = decode_read(&xdr, rqstp, res);
4301 if (!status)
4302 status = res->count;
4303out:
4304 return status;
4305}
4306
4307/*
4308 * Decode WRITE response
4309 */
Al Viro8687b632006-10-19 23:28:48 -07004310static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311{
4312 struct xdr_stream xdr;
4313 struct compound_hdr hdr;
4314 int status;
4315
4316 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4317 status = decode_compound_hdr(&xdr, &hdr);
4318 if (status)
4319 goto out;
4320 status = decode_putfh(&xdr);
4321 if (status)
4322 goto out;
4323 status = decode_write(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004324 if (status)
4325 goto out;
4326 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 if (!status)
4328 status = res->count;
4329out:
4330 return status;
4331}
4332
4333/*
4334 * Decode COMMIT response
4335 */
Al Viro8687b632006-10-19 23:28:48 -07004336static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337{
4338 struct xdr_stream xdr;
4339 struct compound_hdr hdr;
4340 int status;
4341
4342 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4343 status = decode_compound_hdr(&xdr, &hdr);
4344 if (status)
4345 goto out;
4346 status = decode_putfh(&xdr);
4347 if (status)
4348 goto out;
4349 status = decode_commit(&xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04004350 if (status)
4351 goto out;
4352 decode_getfattr(&xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353out:
4354 return status;
4355}
4356
4357/*
4358 * FSINFO request
4359 */
Benny Halevy3dda5e42009-04-01 09:21:57 -04004360static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p,
4361 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004362{
4363 struct xdr_stream xdr;
4364 struct compound_hdr hdr;
4365 int status;
4366
4367 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4368 status = decode_compound_hdr(&xdr, &hdr);
4369 if (!status)
4370 status = decode_putfh(&xdr);
4371 if (!status)
Benny Halevy3dda5e42009-04-01 09:21:57 -04004372 status = decode_fsinfo(&xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373 return status;
4374}
4375
4376/*
4377 * PATHCONF request
4378 */
Benny Halevyd45b2982009-04-01 09:21:58 -04004379static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p,
4380 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381{
4382 struct xdr_stream xdr;
4383 struct compound_hdr hdr;
4384 int status;
4385
4386 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4387 status = decode_compound_hdr(&xdr, &hdr);
4388 if (!status)
4389 status = decode_putfh(&xdr);
4390 if (!status)
Benny Halevyd45b2982009-04-01 09:21:58 -04004391 status = decode_pathconf(&xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392 return status;
4393}
4394
4395/*
4396 * STATFS request
4397 */
Benny Halevy24ad1482009-04-01 09:21:56 -04004398static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p,
4399 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400{
4401 struct xdr_stream xdr;
4402 struct compound_hdr hdr;
4403 int status;
4404
4405 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4406 status = decode_compound_hdr(&xdr, &hdr);
4407 if (!status)
4408 status = decode_putfh(&xdr);
4409 if (!status)
Benny Halevy24ad1482009-04-01 09:21:56 -04004410 status = decode_statfs(&xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 return status;
4412}
4413
4414/*
4415 * GETATTR_BITMAP request
4416 */
Al Viro8687b632006-10-19 23:28:48 -07004417static 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 -07004418{
4419 struct xdr_stream xdr;
4420 struct compound_hdr hdr;
4421 int status;
4422
4423 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4424 if ((status = decode_compound_hdr(&xdr, &hdr)) != 0)
4425 goto out;
4426 if ((status = decode_putfh(&xdr)) != 0)
4427 goto out;
4428 status = decode_server_caps(&xdr, res);
4429out:
4430 return status;
4431}
4432
4433/*
4434 * Decode RENEW response
4435 */
Al Viro8687b632006-10-19 23:28:48 -07004436static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437{
4438 struct xdr_stream xdr;
4439 struct compound_hdr hdr;
4440 int status;
4441
4442 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4443 status = decode_compound_hdr(&xdr, &hdr);
4444 if (!status)
4445 status = decode_renew(&xdr);
4446 return status;
4447}
4448
4449/*
4450 * a SETCLIENTID request
4451 */
Al Viro8687b632006-10-19 23:28:48 -07004452static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
David Howellsadfa6f92006-08-22 20:06:08 -04004453 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454{
4455 struct xdr_stream xdr;
4456 struct compound_hdr hdr;
4457 int status;
4458
4459 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4460 status = decode_compound_hdr(&xdr, &hdr);
4461 if (!status)
4462 status = decode_setclientid(&xdr, clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 return status;
4464}
4465
4466/*
4467 * a SETCLIENTID_CONFIRM request
4468 */
Al Viro8687b632006-10-19 23:28:48 -07004469static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470{
4471 struct xdr_stream xdr;
4472 struct compound_hdr hdr;
4473 int status;
4474
4475 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4476 status = decode_compound_hdr(&xdr, &hdr);
4477 if (!status)
4478 status = decode_setclientid_confirm(&xdr);
4479 if (!status)
4480 status = decode_putrootfh(&xdr);
4481 if (!status)
4482 status = decode_fsinfo(&xdr, fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483 return status;
4484}
4485
4486/*
4487 * DELEGRETURN request
4488 */
Al Viro8687b632006-10-19 23:28:48 -07004489static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490{
4491 struct xdr_stream xdr;
4492 struct compound_hdr hdr;
4493 int status;
4494
4495 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
4496 status = decode_compound_hdr(&xdr, &hdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01004497 if (status != 0)
4498 goto out;
4499 status = decode_putfh(&xdr);
4500 if (status != 0)
4501 goto out;
4502 status = decode_delegreturn(&xdr);
4503 decode_getfattr(&xdr, res->fattr, res->server);
4504out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004505 return status;
4506}
4507
Trond Myklebust683b57b2006-06-09 09:34:22 -04004508/*
4509 * FS_LOCATIONS request
4510 */
Benny Halevy22958462009-04-01 09:22:02 -04004511static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p,
4512 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004513{
4514 struct xdr_stream xdr;
4515 struct compound_hdr hdr;
4516 int status;
4517
4518 xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
4519 status = decode_compound_hdr(&xdr, &hdr);
4520 if (status != 0)
4521 goto out;
4522 if ((status = decode_putfh(&xdr)) != 0)
4523 goto out;
4524 if ((status = decode_lookup(&xdr)) != 0)
4525 goto out;
4526 xdr_enter_page(&xdr, PAGE_SIZE);
Benny Halevy22958462009-04-01 09:22:02 -04004527 status = decode_getfattr(&xdr, &res->fs_locations->fattr,
4528 res->fs_locations->server);
Trond Myklebust683b57b2006-06-09 09:34:22 -04004529out:
4530 return status;
4531}
4532
Al Viro0dbb4c62006-10-19 23:28:49 -07004533__be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534{
4535 uint32_t bitmap[2] = {0};
4536 uint32_t len;
4537
4538 if (!*p++) {
4539 if (!*p)
4540 return ERR_PTR(-EAGAIN);
4541 entry->eof = 1;
4542 return ERR_PTR(-EBADCOOKIE);
4543 }
4544
4545 entry->prev_cookie = entry->cookie;
4546 p = xdr_decode_hyper(p, &entry->cookie);
4547 entry->len = ntohl(*p++);
4548 entry->name = (const char *) p;
4549 p += XDR_QUADLEN(entry->len);
4550
4551 /*
4552 * In case the server doesn't return an inode number,
4553 * we fake one here. (We don't use inode number 0,
4554 * since glibc seems to choke on it...)
4555 */
4556 entry->ino = 1;
4557
4558 len = ntohl(*p++); /* bitmap length */
4559 if (len-- > 0) {
4560 bitmap[0] = ntohl(*p++);
4561 if (len-- > 0) {
4562 bitmap[1] = ntohl(*p++);
4563 p += len;
4564 }
4565 }
4566 len = XDR_QUADLEN(ntohl(*p++)); /* attribute buffer length */
4567 if (len > 0) {
Manoj Naik97d312d2005-06-22 17:16:39 +00004568 if (bitmap[0] & FATTR4_WORD0_RDATTR_ERROR) {
4569 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
4570 /* Ignore the return value of rdattr_error for now */
4571 p++;
4572 len--;
4573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574 if (bitmap[0] == 0 && bitmap[1] == FATTR4_WORD1_MOUNTED_ON_FILEID)
4575 xdr_decode_hyper(p, &entry->ino);
4576 else if (bitmap[0] == FATTR4_WORD0_FILEID)
4577 xdr_decode_hyper(p, &entry->ino);
4578 p += len;
4579 }
4580
4581 entry->eof = !p[0] && p[1];
4582 return p;
4583}
4584
4585/*
4586 * We need to translate between nfs status return values and
4587 * the local errno values which may not be the same.
4588 */
4589static struct {
4590 int stat;
4591 int errno;
4592} nfs_errtbl[] = {
4593 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03004594 { NFS4ERR_PERM, -EPERM },
4595 { NFS4ERR_NOENT, -ENOENT },
4596 { NFS4ERR_IO, -errno_NFSERR_IO},
4597 { NFS4ERR_NXIO, -ENXIO },
4598 { NFS4ERR_ACCESS, -EACCES },
4599 { NFS4ERR_EXIST, -EEXIST },
4600 { NFS4ERR_XDEV, -EXDEV },
4601 { NFS4ERR_NOTDIR, -ENOTDIR },
4602 { NFS4ERR_ISDIR, -EISDIR },
4603 { NFS4ERR_INVAL, -EINVAL },
4604 { NFS4ERR_FBIG, -EFBIG },
4605 { NFS4ERR_NOSPC, -ENOSPC },
4606 { NFS4ERR_ROFS, -EROFS },
4607 { NFS4ERR_MLINK, -EMLINK },
4608 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4609 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4610 { NFS4ERR_DQUOT, -EDQUOT },
4611 { NFS4ERR_STALE, -ESTALE },
4612 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4613 { NFS4ERR_BADOWNER, -EINVAL },
4614 { NFS4ERR_BADNAME, -EINVAL },
4615 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4616 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4617 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4618 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4619 { NFS4ERR_BADTYPE, -EBADTYPE },
4620 { NFS4ERR_LOCKED, -EAGAIN },
4621 { NFS4ERR_RESOURCE, -EREMOTEIO },
4622 { NFS4ERR_SYMLINK, -ELOOP },
4623 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
4624 { NFS4ERR_DEADLOCK, -EDEADLK },
4625 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626 * to be handled by a
4627 * middle-layer.
4628 */
Benny Halevy856dff32008-03-31 17:39:06 +03004629 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630};
4631
4632/*
4633 * Convert an NFS error code to a local one.
4634 * This one is used jointly by NFSv2 and NFSv3.
4635 */
4636static int
David Howells0a8ea432006-08-22 20:06:08 -04004637nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638{
4639 int i;
4640 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
4641 if (nfs_errtbl[i].stat == stat)
4642 return nfs_errtbl[i].errno;
4643 }
4644 if (stat <= 10000 || stat > 10100) {
4645 /* The server is looney tunes. */
Benny Halevy856dff32008-03-31 17:39:06 +03004646 return -ESERVERFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647 }
4648 /* If we cannot translate the error, the recovery routines should
4649 * handle it.
4650 * Note: remaining NFSv4 error codes have values > 10000, so should
4651 * not conflict with native Linux error codes.
4652 */
Benny Halevy856dff32008-03-31 17:39:06 +03004653 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654}
4655
Linus Torvalds1da177e2005-04-16 15:20:36 -07004656#define PROC(proc, argtype, restype) \
4657[NFSPROC4_CLNT_##proc] = { \
4658 .p_proc = NFSPROC4_COMPOUND, \
4659 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
4660 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04004661 .p_arglen = NFS4_##argtype##_sz, \
4662 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05004663 .p_statidx = NFSPROC4_CLNT_##proc, \
4664 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05004665}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666
4667struct rpc_procinfo nfs4_procedures[] = {
4668 PROC(READ, enc_read, dec_read),
4669 PROC(WRITE, enc_write, dec_write),
4670 PROC(COMMIT, enc_commit, dec_commit),
4671 PROC(OPEN, enc_open, dec_open),
4672 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
4673 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
4674 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
4675 PROC(CLOSE, enc_close, dec_close),
4676 PROC(SETATTR, enc_setattr, dec_setattr),
4677 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
4678 PROC(RENEW, enc_renew, dec_renew),
4679 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
4680 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
4681 PROC(LOCK, enc_lock, dec_lock),
4682 PROC(LOCKT, enc_lockt, dec_lockt),
4683 PROC(LOCKU, enc_locku, dec_locku),
4684 PROC(ACCESS, enc_access, dec_access),
4685 PROC(GETATTR, enc_getattr, dec_getattr),
4686 PROC(LOOKUP, enc_lookup, dec_lookup),
4687 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
4688 PROC(REMOVE, enc_remove, dec_remove),
4689 PROC(RENAME, enc_rename, dec_rename),
4690 PROC(LINK, enc_link, dec_link),
4691 PROC(SYMLINK, enc_symlink, dec_symlink),
4692 PROC(CREATE, enc_create, dec_create),
4693 PROC(PATHCONF, enc_pathconf, dec_pathconf),
4694 PROC(STATFS, enc_statfs, dec_statfs),
4695 PROC(READLINK, enc_readlink, dec_readlink),
4696 PROC(READDIR, enc_readdir, dec_readdir),
4697 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
4698 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
J. Bruce Fields029d1052005-06-22 17:16:22 +00004699 PROC(GETACL, enc_getacl, dec_getacl),
J. Bruce Fields23ec6962005-06-22 17:16:22 +00004700 PROC(SETACL, enc_setacl, dec_setacl),
Trond Myklebust683b57b2006-06-09 09:34:22 -04004701 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004702};
4703
4704struct rpc_version nfs_version4 = {
4705 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08004706 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707 .procs = nfs4_procedures
4708};
4709
4710/*
4711 * Local variables:
4712 * c-basic-offset: 8
4713 * End:
4714 */